From 831876fc85b325d228da63d04259d9841f60172c Mon Sep 17 00:00:00 2001 From: Mateusz Ujma Date: Mon, 5 Aug 2013 00:18:03 +0000 Subject: [PATCH] Added compare by variable to the State class git-svn-id: https://www.prismmodelchecker.org/svn/prism/prism/trunk@7218 bbc10eb1-c90d-0410-af57-cb519fbb1720 --- prism/src/parser/State.java | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/prism/src/parser/State.java b/prism/src/parser/State.java index e46da4dc..4751f2da 100644 --- a/prism/src/parser/State.java +++ b/prism/src/parser/State.java @@ -162,6 +162,11 @@ public class State implements Comparable } public int compareTo(State s) + { + return compareTo(s, 0); + } + + public int compareTo(State s, int variableIndex) { int i, j, n; Object svv[], o1, o2; @@ -173,8 +178,31 @@ public class State implements Comparable n = varValues.length; if (n != svv.length) throw new ClassCastException("States are different sizes"); + + if (variableIndex > n-1) + throw new ClassCastException("Variable index is incorrect"); // Go through array - for (i = 0; i < n; i++) { + for (i = variableIndex; 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; + else + continue; + } else if (o1 instanceof Boolean && o2 instanceof Boolean) { + j = ((Boolean) o1).compareTo((Boolean) o2); + if (j != 0) + return j; + else + continue; + } else { + throw new ClassCastException("Can't compare " + o1.getClass() + " and " + o2.getClass()); + } + } + + for (i = 0; i < variableIndex; i++) { o1 = varValues[i]; o2 = svv[i]; if (o1 instanceof Integer && o2 instanceof Integer) {