Record Class ConstrainedEnumSubset

java.lang.Object
java.lang.Record
org.ek9lang.compiler.phase7.support.ConstrainedEnumSubset
Record Components:
names - the subset's value names, in declaration order
baseOrdinals - the base enum ordinal of each name (same index)

public record ConstrainedEnumSubset(List<String> names, List<Integer> baseOrdinals) extends Record
THE members of a constrained enumeration (RedSuit as CardSuit constrain as "Hearts" or "Diamonds"): the base enum's values, in declaration order, whose name satisfies the constraint - each with its BASE ordinal. Use this wherever a constrained enum must answer over its own subset rather than delegate to the base enum (iteration, first #<, last #>); never re-derive the filter.

The constraint literals are the value names, so each name is evaluated as a String subject. When the constraint cannot be modelled at compile time, every base value is kept rather than silently yielding nothing.

  • Constructor Details

    • ConstrainedEnumSubset

      public ConstrainedEnumSubset(List<String> names, List<Integer> baseOrdinals)
      Creates an instance of a ConstrainedEnumSubset record class.
      Parameters:
      names - the value for the names record component
      baseOrdinals - the value for the baseOrdinals record component
  • Method Details

    • of

      public static ConstrainedEnumSubset of(AggregateSymbol constrainedType, IAggregateSymbol baseEnum)
      The subset of baseEnum admitted by constrainedType's constraint.
    • isEmpty

      public boolean isEmpty()
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • names

      public List<String> names()
      Returns the value of the names record component.
      Returns:
      the value of the names record component
    • baseOrdinals

      public List<Integer> baseOrdinals()
      Returns the value of the baseOrdinals record component.
      Returns:
      the value of the baseOrdinals record component