Class RuleFamily

java.lang.Object
application.model.rules.Rule
application.model.rules.RuleFamily
All Implemented Interfaces:
java.lang.Cloneable
Direct Known Subclasses:
AlternatingRule, BaseHROT, BaseINT, Euclidean, Margolus, OneDimensional, RuleLoader, Turmites

public abstract class RuleFamily
extends Rule
implements java.lang.Cloneable
Represents a family of rules or a rulespace
  • Field Summary

    Fields 
    Modifier and Type Field Description
    protected java.lang.String name
    Name of the Rule Family (displayed in the RuleDialog)
    protected java.lang.String rulestring
    Rulestring of the Rule Family

    Fields inherited from class application.model.rules.Rule

    alternatingPeriod, background, boundedGrid, numStates, readingOrder, tiling
  • Constructor Summary

    Constructors 
    Constructor Description
    RuleFamily()  
  • Method Summary

    Modifier and Type Method Description
    abstract java.lang.String canonise​(java.lang.String rulestring)
    Canonises the inputted rulestring with the currently loaded parameters.
    abstract java.lang.Object clone()
    Clones the object
    boolean equals​(java.lang.Object o)  
    protected abstract void fromRulestring​(java.lang.String rulestring)
    Loads the rule's parameters from a rulestring
    java.lang.String[] generateComments()
    Generates comments that will be placed in the RLE.
    abstract java.lang.String getDescription()
    Returns a plain text description of the rule family to be displayed in the Rule Dialog
    java.lang.String getName()
    Gets the name of the rule
    protected java.util.ArrayList<int[]> getNeighbourList​(Grid[] grids)
    Gets the list of neighbours with the input state and output state at the first and last index respectively when provided with an evolutionary sequence.
    abstract java.lang.String[] getRegex()
    The regexes that will match a valid rulestring
    java.util.Map<java.lang.String,​java.lang.String> getRuleInfo()
    Gets information about the rule
    java.lang.String getRulestring()
    Gets the rulestring of the rule
    int hashCode()  
    void loadComments​(java.lang.String[] comments)
    Loads the additional information stored in the comments generated by generateComments An empty array maybe passed in (meaning no comments)
    void setRulestring​(java.lang.String rulestring)
    Sets the rulestring of the rule family to the inputted value
    java.lang.String toString()  
    void updateBackground()
    Updates the background of the rule based on the loaded parameters.

    Methods inherited from class java.lang.Object

    finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • name

      protected java.lang.String name
      Name of the Rule Family (displayed in the RuleDialog)
    • rulestring

      protected java.lang.String rulestring
      Rulestring of the Rule Family
  • Constructor Details

  • Method Details

    • fromRulestring

      protected abstract void fromRulestring​(java.lang.String rulestring)
      Loads the rule's parameters from a rulestring
      Parameters:
      rulestring - The rulestring of the rule (eg. B3/S23, R2,C2,S5-9,B7-8,NM)
      Throws:
      java.lang.IllegalArgumentException - Thrown if an invalid rulestring is passed in
    • canonise

      public abstract java.lang.String canonise​(java.lang.String rulestring)
      Canonises the inputted rulestring with the currently loaded parameters. This method should be called whenever the parameters of a rule are updated.
      Parameters:
      rulestring - The rulestring to canonised
      Returns:
      Canonised rulestring
    • setRulestring

      public void setRulestring​(java.lang.String rulestring)
      Sets the rulestring of the rule family to the inputted value
      Parameters:
      rulestring - Rulestring of the rule
    • updateBackground

      public void updateBackground()
      Updates the background of the rule based on the loaded parameters. This method should be called whenever the parameters of a rule are updated. For non-strobing rules, the background is {0}.
    • getRegex

      public abstract java.lang.String[] getRegex()
      The regexes that will match a valid rulestring
      Returns:
      An array of regexes that will match a valid rulestring
    • getDescription

      public abstract java.lang.String getDescription()
      Returns a plain text description of the rule family to be displayed in the Rule Dialog
      Returns:
      Description of the rule family
    • getRuleInfo

      public java.util.Map<java.lang.String,​java.lang.String> getRuleInfo()
      Gets information about the rule
      Returns:
      Returns information about the rule in a map
    • generateComments

      public java.lang.String[] generateComments()
      Generates comments that will be placed in the RLE. These comments represent additional information that is not stored in the rulestring (e.g. weights)
      Returns:
      An array of comments each starting with "#R" (eg. {"#R 1 2 3 2 1", "#R 2 4 6 4 2"}). If no additional information needs to be added return null or an empty string array.
    • loadComments

      public void loadComments​(java.lang.String[] comments)
      Loads the additional information stored in the comments generated by generateComments An empty array maybe passed in (meaning no comments)
      Parameters:
      comments - The comments from the RLE (all starting with #R)
    • clone

      public abstract java.lang.Object clone()
      Clones the object
      Overrides:
      clone in class java.lang.Object
      Returns:
      A deepcopy of the object
    • getName

      public java.lang.String getName()
      Gets the name of the rule
      Returns:
      Name of the rule
    • getRulestring

      public java.lang.String getRulestring()
      Gets the rulestring of the rule
      Returns:
      Rulestring of the rule
    • toString

      public java.lang.String toString()
      Overrides:
      toString in class java.lang.Object
    • getNeighbourList

      protected java.util.ArrayList<int[]> getNeighbourList​(Grid[] grids)
      Gets the list of neighbours with the input state and output state at the first and last index respectively when provided with an evolutionary sequence. Should be used in conjuction with getMinMaxRule.
      Parameters:
      grids - An array of grids representing an evolutionary sequence
      Returns:
      Returns the list of neighbours
    • equals

      public boolean equals​(java.lang.Object o)
      Overrides:
      equals in class java.lang.Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class java.lang.Object