I have a class that needs to return a set of values e.gpublic abstract class AbstractRule {   public abstract String getName();   //Property is an example here.   public abstract Set<Property> getApplicability();}public class ConstrainedRule extends AbstractRule {  @Override  public String getName() {    return ConstrainedRule;  }  @Override  public Set<Property> getApplicability() {    return ImmutableSet.of(propertyA,propertyB);  }}public class GlobalRule extends AbstractRule {  @Override  public String getName() {    return GlobalRule;  }  @Override  public Set<Property> getApplicability() {    // This Rule is applicable on all properties.    return ImmutableSet.of(propertyA, propertyB, ...);  }}Here I wish to define a Rule which is applicable on all Properties,which would have been easy if I knew the universe of properties that exist, which I don't. What would be a good way to represent such an Applicability ?One option would be to model the Set of Property as a class say:class PropertyApplicability {   public static final PropertyApplicability ALL = new PropertyApplicability(true, ImmutableSet.of());   private final Set<Property> applicables;   private final boolean applicableToAll;   private Applicability(boolean applicableToAll, Set<Property> applicables) {       Preconditions.checkNotNull(applicables);       this.applicables = ImmutableSet.copyOf(applicables);       this.applicableToAll = applicableToAll;}   //Only way to create applicability with a set of properties   public Applicability(Set<Property> applicables) {     Preconditions.checkArgument(applicables.size() > 0);     this(false, applicables);         }   //Getters}But I wondered if there is a more elegant solution.
Representing all possible values or a subset of values
java;object oriented design