Record Class DirectionConfig

java.lang.Object
java.lang.Record
org.ek9lang.compiler.phase7.support.DirectionConfig
Record Components:
directionOperator - Operator for runtime direction detection ("<" or ">")
conditionOperator - Operator for loop continuation check ("<=" or ">=")
incrementOperator - Operator for loop counter update ("++" or "--")

public record DirectionConfig(String directionOperator, String conditionOperator, String incrementOperator) extends Record
Configuration for for-range loop direction (ascending vs descending).

CONCERN: Explicit operator triplet configuration for symmetric for-range cases. RESPONSIBILITY: Encapsulate the ONLY differences between ascending/descending loops. REUSABILITY: FOR_RANGE_POLYMORPHIC case generation.

The ascending and descending cases in for-range loops differ ONLY in 3 operators:

  • Direction check: "<" (ascending) vs ">" (descending)
  • Loop condition: "<=" (ascending) vs ">=" (descending)
  • Increment: "++" (ascending) vs "--" (descending)

This record makes the symmetric relationship explicit in the type system instead of implicit in duplicated code.

Example:

for i in 1 ... 10:    // Ascending: 1 < 10, use <=, ++
for i in 10 ... 1:    // Descending: 10 > 1, use >=, --
  • Constructor Details

    • DirectionConfig

      public DirectionConfig(String directionOperator, String conditionOperator, String incrementOperator)
      Creates an instance of a DirectionConfig record class.
      Parameters:
      directionOperator - the value for the directionOperator record component
      conditionOperator - the value for the conditionOperator record component
      incrementOperator - the value for the incrementOperator record component
  • Method Details

    • ascending

      public static DirectionConfig ascending()
      Configuration for ascending for-range loops.

      Example: for i in 1 ... 10

      • Direction: start < end → direction < 0
      • Condition: current <= end
      • Increment: current++
    • descending

      public static DirectionConfig descending()
      Configuration for descending for-range loops.

      Example: for i in 10 ... 1

      • Direction: start > end → direction > 0
      • Condition: current >= end
      • Increment: current--
    • 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.
    • directionOperator

      public String directionOperator()
      Returns the value of the directionOperator record component.
      Returns:
      the value of the directionOperator record component
    • conditionOperator

      public String conditionOperator()
      Returns the value of the conditionOperator record component.
      Returns:
      the value of the conditionOperator record component
    • incrementOperator

      public String incrementOperator()
      Returns the value of the incrementOperator record component.
      Returns:
      the value of the incrementOperator record component