Binary configurations are conjunctions (and) or disjunctions
(or) of configurations. The BinaryConfig abstract class has two Config fields c1 and c2.
abstract class BinaryConfig extends Config
{
protected Config c1,c2;
public boolean equals(Config config){
return super.equals(config) &&
c1.equals (((BinaryConfig)config).c1) &&
c2.equals(((BinaryConfig)config).c2);
}
}
A conjunction of the class AndConfig is fixed as soon as one component is fixed and evaluates to false: the other one does not need to be also fixed. Otherwise, the conjunction is fixed when both components are. Evaluation returns the ``and'' of the two components.
public class AndConfig extends BinaryConfig
{
public AndConfig(Config c1, Config c2)
{
this.c1 = c1;
this.c2 = c2;
}
public String toString(){
return "(" + c1 + " and " + c2 + ")";
}
public boolean fixed(Machine machine)
{
boolean b1 = c1.fixed(machine);
boolean b2 = c2.fixed(machine);
if (b1 && !c1.evaluate(machine)) return true;
if (b2 && !c2.evaluate(machine)) return true;
return b1 && b2;
}
public boolean evaluate(Machine machine){
return c1.evaluate(machine) && c2.evaluate(machine);
}
}
We do not present here the class OrConfig of configuration
disjunction as it is very similar to rhe AndConfig class.