|
|
|
@ -115,7 +115,7 @@ public class State implements Comparable<State> |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* |
|
|
|
* Set the {@code i}th value to {@code val}. |
|
|
|
*/ |
|
|
|
public void setValue(int i, Object val) |
|
|
|
{ |
|
|
|
@ -160,40 +160,49 @@ public class State implements Comparable<State> |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public int compareTo(State s) |
|
|
|
{ |
|
|
|
return compareTo(s, 0); |
|
|
|
} |
|
|
|
|
|
|
|
public int compareTo(State s, int variableIndex) |
|
|
|
/** |
|
|
|
* Compare this state to another state {@code s} (in the style of {@link #compareTo(State)}, |
|
|
|
* first comparing variables with index greater than or equal to {@code j}, |
|
|
|
* and then comparing variables with index less than {@code j}. |
|
|
|
*/ |
|
|
|
public int compareTo(State s, int j) |
|
|
|
{ |
|
|
|
int i, j, n; |
|
|
|
int i, c, n; |
|
|
|
Object svv[], o1, o2; |
|
|
|
|
|
|
|
// Can't compare to null |
|
|
|
if (s == null) |
|
|
|
throw new NullPointerException(); |
|
|
|
|
|
|
|
// States of different size are incomparable |
|
|
|
svv = s.varValues; |
|
|
|
n = varValues.length; |
|
|
|
if (n != svv.length) |
|
|
|
throw new ClassCastException("States are different sizes"); |
|
|
|
|
|
|
|
if (variableIndex > n-1) |
|
|
|
if (j > n-1) |
|
|
|
throw new ClassCastException("Variable index is incorrect"); |
|
|
|
// Go through array |
|
|
|
for (i = variableIndex; i < n; i++) { |
|
|
|
|
|
|
|
// Go through variables j...n-1 |
|
|
|
for (i = j; i < n; i++) { |
|
|
|
o1 = varValues[i]; |
|
|
|
o2 = svv[i]; |
|
|
|
if (o1 instanceof Integer && o2 instanceof Integer) { |
|
|
|
j = ((Integer) o1).compareTo((Integer) o2); |
|
|
|
if (j != 0) |
|
|
|
return j; |
|
|
|
c = ((Integer) o1).compareTo((Integer) o2); |
|
|
|
if (c != 0) |
|
|
|
return c; |
|
|
|
else |
|
|
|
continue; |
|
|
|
} else if (o1 instanceof Boolean && o2 instanceof Boolean) { |
|
|
|
j = ((Boolean) o1).compareTo((Boolean) o2); |
|
|
|
if (j != 0) |
|
|
|
return j; |
|
|
|
c = ((Boolean) o1).compareTo((Boolean) o2); |
|
|
|
if (c != 0) |
|
|
|
return c; |
|
|
|
else |
|
|
|
continue; |
|
|
|
} else { |
|
|
|
@ -201,25 +210,27 @@ public class State implements Comparable<State> |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
for (i = 0; i < variableIndex; i++) { |
|
|
|
// Go through variables 0...j |
|
|
|
for (i = 0; i < j; i++) { |
|
|
|
o1 = varValues[i]; |
|
|
|
o2 = svv[i]; |
|
|
|
if (o1 instanceof Integer && o2 instanceof Integer) { |
|
|
|
j = ((Integer) o1).compareTo((Integer) o2); |
|
|
|
if (j != 0) |
|
|
|
return j; |
|
|
|
c = ((Integer) o1).compareTo((Integer) o2); |
|
|
|
if (c != 0) |
|
|
|
return c; |
|
|
|
else |
|
|
|
continue; |
|
|
|
} else if (o1 instanceof Boolean && o2 instanceof Boolean) { |
|
|
|
j = ((Boolean) o1).compareTo((Boolean) o2); |
|
|
|
if (j != 0) |
|
|
|
return j; |
|
|
|
c = ((Boolean) o1).compareTo((Boolean) o2); |
|
|
|
if (c != 0) |
|
|
|
return c; |
|
|
|
else |
|
|
|
continue; |
|
|
|
} else { |
|
|
|
throw new ClassCastException("Can't compare " + o1.getClass() + " and " + o2.getClass()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|
|