diff --git a/prism/src/explicit/StateStorage.java b/prism/src/explicit/StateStorage.java index c92c5565..fdfcaf09 100644 --- a/prism/src/explicit/StateStorage.java +++ b/prism/src/explicit/StateStorage.java @@ -2,9 +2,8 @@ // // Copyright (c) 2002- // Authors: -// * Dave Parker (University of Oxford) -// * Mateusz Ujma (University of Oxford) - +// * Mateusz Ujma (University of Oxford) +// * Dave Parker (University of Birmingham/Oxford) // //------------------------------------------------------------------------------ // @@ -31,8 +30,8 @@ package explicit; import java.util.*; /** - * Interface for storing an set of objects of type T. - * Typically used for storing state space during reachability. + * Interface for storing a set of objects of type T. + * Typically used for storing states during reachability. */ public interface StateStorage { @@ -90,5 +89,4 @@ public interface StateStorage * to new indices under the sorting order. */ public int[] buildSortingPermutation(); - } diff --git a/prism/src/parser/State.java b/prism/src/parser/State.java index 52462c63..668905ec 100644 --- a/prism/src/parser/State.java +++ b/prism/src/parser/State.java @@ -115,7 +115,7 @@ public class State implements Comparable } /** - * + * 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 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 } } - 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; } diff --git a/prism/src/pta/DBMList.java b/prism/src/pta/DBMList.java index 4e860360..026c5665 100644 --- a/prism/src/pta/DBMList.java +++ b/prism/src/pta/DBMList.java @@ -121,6 +121,14 @@ public class DBMList extends NCZone addDBM(dbm); } + /** + * Get the {@code i}th DBM in the list. + */ + public DBM getDBM(int i) + { + return list.get(i); + } + // Methods required for Zone interface /** @@ -131,14 +139,6 @@ public class DBMList extends NCZone return pta; } - /** - * Get DBM - */ - public DBM getDBM(int i) - { - return list.get(i); - } - // Zone operations (modify the zone) /**