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 Summary
ConstructorsConstructorDescriptionDirectionConfig(String directionOperator, String conditionOperator, String incrementOperator) Creates an instance of aDirectionConfigrecord class. -
Method Summary
Modifier and TypeMethodDescriptionstatic DirectionConfigConfiguration for ascending for-range loops.Returns the value of theconditionOperatorrecord component.static DirectionConfigConfiguration for descending for-range loops.Returns the value of thedirectionOperatorrecord component.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.Returns the value of theincrementOperatorrecord component.final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
DirectionConfig
public DirectionConfig(String directionOperator, String conditionOperator, String incrementOperator) Creates an instance of aDirectionConfigrecord class.- Parameters:
directionOperator- the value for thedirectionOperatorrecord componentconditionOperator- the value for theconditionOperatorrecord componentincrementOperator- the value for theincrementOperatorrecord component
-
-
Method Details
-
ascending
Configuration for ascending for-range loops.Example:
for i in 1 ... 10- Direction: start < end → direction < 0
- Condition: current <= end
- Increment: current++
-
descending
Configuration for descending for-range loops.Example:
for i in 10 ... 1- Direction: start > end → direction > 0
- Condition: current >= end
- Increment: current--
-
toString
-
hashCode
-
equals
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 withObjects::equals(Object,Object). -
directionOperator
Returns the value of thedirectionOperatorrecord component.- Returns:
- the value of the
directionOperatorrecord component
-
conditionOperator
Returns the value of theconditionOperatorrecord component.- Returns:
- the value of the
conditionOperatorrecord component
-
incrementOperator
Returns the value of theincrementOperatorrecord component.- Returns:
- the value of the
incrementOperatorrecord component
-