summaryrefslogtreecommitdiff
path: root/assignments/assignment2/Bounded Retransmission Protocol Tester/Source/basiclearner/CacheInconsistencyException.java
diff options
context:
space:
mode:
authorRené den Hertog2017-10-26 17:34:51 +0200
committerRené den Hertog2017-10-26 17:34:51 +0200
commitac914c719d401c44cb2633127952b022bf563ff3 (patch)
treef7d2399b2ab6cddb86aa996096581a397ff407b9 /assignments/assignment2/Bounded Retransmission Protocol Tester/Source/basiclearner/CacheInconsistencyException.java
parentFinish assignment 2, part 1 (diff)
'Bounded Retransmission Protocol' Blob
Diffstat (limited to 'assignments/assignment2/Bounded Retransmission Protocol Tester/Source/basiclearner/CacheInconsistencyException.java')
-rw-r--r--assignments/assignment2/Bounded Retransmission Protocol Tester/Source/basiclearner/CacheInconsistencyException.java60
1 files changed, 60 insertions, 0 deletions
diff --git a/assignments/assignment2/Bounded Retransmission Protocol Tester/Source/basiclearner/CacheInconsistencyException.java b/assignments/assignment2/Bounded Retransmission Protocol Tester/Source/basiclearner/CacheInconsistencyException.java
new file mode 100644
index 0000000..67c2e73
--- /dev/null
+++ b/assignments/assignment2/Bounded Retransmission Protocol Tester/Source/basiclearner/CacheInconsistencyException.java
@@ -0,0 +1,60 @@
+package basiclearner;
+
+import net.automatalib.words.Word;
+
+/**
+ * Contains the full input for which non-determinism was observed, as well as the full new output
+ * and the (possibly shorter) old output with which it disagrees
+ *
+ * @author Ramon Janssen
+ */
+public class CacheInconsistencyException extends RuntimeException {
+ private final Word oldOutput, newOutput, input;
+
+ public CacheInconsistencyException(Word input, Word oldOutput, Word newOutput) {
+ this.input = input;
+ this.oldOutput = oldOutput;
+ this.newOutput = newOutput;
+ }
+
+ public CacheInconsistencyException(String message, Word input, Word oldOutput, Word newOutput) {
+ super(message);
+ this.input = input;
+ this.oldOutput = oldOutput;
+ this.newOutput = newOutput;
+ }
+
+
+ /**
+ * The shortest cached output word which does not correspond with the new output
+ * @return
+ */
+ public Word getOldOutput() {
+ return this.oldOutput;
+ }
+
+ /**
+ * The full new output word
+ * @return
+ */
+ public Word getNewOutput() {
+ return this.newOutput;
+ }
+
+ /**
+ * The shortest sublist of the input word which still shows non-determinism
+ * @return
+ */
+ public Word getShortestInconsistentInput() {
+ int indexOfInconsistency = 0;
+ while (oldOutput.getSymbol(indexOfInconsistency).equals(newOutput.getSymbol(indexOfInconsistency))) {
+ indexOfInconsistency ++;
+ }
+ return this.input.subWord(0, indexOfInconsistency);
+ }
+
+ @Override
+ public String toString() {
+ return "Non-determinism detected\nfull input:\n" + this.input + "\nfull new output:\n" + this.newOutput + "\nold output:\n" + this.oldOutput;
+ }
+}