Class ConditionalRule

java.lang.Object
com.tnsai.invariants.rules.ConditionalRule

public class ConditionalRule extends Object
Represents a conditional transition rule like "DEAD if neighbors invalid input: '<' 2".

A ConditionalRule has:

  • effect - The target state/value when condition is true (e.g., "DEAD")
  • condition - The boolean condition (e.g., "neighbors invalid input: '<' 2")
  • currentStateCondition - Optional condition on current state (e.g., "state == ALIVE")
  • description - Optional human-readable description (e.g., "underpopulation")

Rule Semantics

The rule "DEAD if neighbors invalid input: '<' 2 (underpopulation)" means:

 IF neighbors invalid input: '<' 2 THEN result should be DEAD
 

For state transition rules (Game of Life), the implicit semantics are:

 IF current state matches precondition AND condition is true
 THEN new state should be effect
 
Author:
TnsAI Team
  • Constructor Details

    • ConditionalRule

      public ConditionalRule(String effect, String condition, String currentStateCondition, String description, String originalRule)
      Creates a ConditionalRule.
      Parameters:
      effect - the target state/value when condition is true
      condition - the boolean condition expression
      currentStateCondition - optional condition on current state
      description - optional human-readable description
      originalRule - the original rule string
    • ConditionalRule

      public ConditionalRule(String effect, String condition)
      Creates a simple rule without current state condition.
  • Method Details

    • getEffect

      public String getEffect()
    • getCondition

      public String getCondition()
    • getCurrentStateCondition

      public String getCurrentStateCondition()
    • getDescription

      public String getDescription()
    • getOriginalRule

      public String getOriginalRule()
    • hasCurrentStateCondition

      public boolean hasCurrentStateCondition()
    • hasDescription

      public boolean hasDescription()
    • isStateTransitionRule

      public boolean isStateTransitionRule()
      Checks if this is a state transition rule (effect is an enum-like value). State transitions are typically UPPER_CASE identifiers.
    • isUnchangedRule

      public boolean isUnchangedRule()
      Checks if this rule represents "no change" (e.g., "unchanged").
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object