Class Rules

java.lang.Object
  extended byAbstract1DGrid
      extended byRules

public class Rules
extends Abstract1DGrid

The 1 dimensional grid of rules with some utilities.

Since:
1.0
Version:
1.1, 2007-05-30
Author:
TineL

Field Summary
private  Rule[] rules
          Array of rules.
 
Fields inherited from class Abstract1DGrid
 
Constructor Summary
Rules(int size)
          Creates Rules with the specified size.
Rules(Rules rules)
          Creates Rules from the specified rules.
 
Method Summary
static Rules generateRandomRules(int size)
          Generates a grid of random rules.
static Rules generateRules(int size, int ruleCode)
          Generates a grid of specific rules defined by the ruleCode.
 Rule get(int index)
           
 Rule getLeft(int index)
           
 Rule getRight(int index)
           
 void set(int index, Rule rule)
          Replaces the old rule with the given rule at the specified index.
 java.lang.String toString()
           
 
Methods inherited from class Abstract1DGrid
getLeftIndex, getRightIndex, size
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

rules

private Rule[] rules
Array of rules.

Constructor Detail

Rules

public Rules(int size)
Creates Rules with the specified size. All rules are set to 0 code.

Parameters:
size - the grid size (number of rules).
Since:
1.0

Rules

public Rules(Rules rules)
Creates Rules from the specified rules.

Parameters:
rules - the rules (null not permitted).
Since:
1.1
Method Detail

generateRandomRules

public static Rules generateRandomRules(int size)
Generates a grid of random rules.

Parameters:
size - the grid size (number of rules).
Returns:
a grid of random rules (null not possible).
Since:
1.0

generateRules

public static Rules generateRules(int size,
                                  int ruleCode)
Generates a grid of specific rules defined by the ruleCode. All generated rules are the same.

Parameters:
size - the grid size (number of rules).
ruleCode - the rule code for all rules.
Returns:
a grid of rules (null not possible).
Since:
1.0

get

public Rule get(int index)
Parameters:
index - the rule index.
Returns:
the rule (null not possible).
Since:
1.0

set

public void set(int index,
                Rule rule)
Replaces the old rule with the given rule at the specified index.

Parameters:
index - the rule index.
rule - the new rule (null not permitted).
Since:
1.0

getLeft

public Rule getLeft(int index)
Parameters:
index - the rule index.
Returns:
the rule on the left (neighbour) (null not possible).
Since:
1.0

getRight

public Rule getRight(int index)
Parameters:
index - the rule index.
Returns:
the rule on the right (neighbour) (null not possible).
Since:
1.0

toString

public java.lang.String toString()