working setup for a4
[tt2015.git] / a4 / tcp / tester / learner / CacheInconsistencyException.java
1 package learner;
2
3 import net.automatalib.words.Word;
4
5 /**
6 * Contains the full input for which non-determinism was observed, as well as the full new output
7 * and the (possibly shorter) old output with which it disagrees
8 *
9 * @author Ramon Janssen
10 */
11 public class CacheInconsistencyException extends RuntimeException {
12 private final Word oldOutput, newOutput, input;
13
14 public CacheInconsistencyException(Word input, Word oldOutput, Word newOutput) {
15 this.input = input;
16 this.oldOutput = oldOutput;
17 this.newOutput = newOutput;
18 }
19
20 public CacheInconsistencyException(String message, Word input, Word oldOutput, Word newOutput) {
21 super(message);
22 this.input = input;
23 this.oldOutput = oldOutput;
24 this.newOutput = newOutput;
25 }
26
27
28 /**
29 * The shortest cached output word which does not correspond with the new output
30 * @return
31 */
32 public Word getOldOutput() {
33 return this.oldOutput;
34 }
35
36 /**
37 * The full new output word
38 * @return
39 */
40 public Word getNewOutput() {
41 return this.newOutput;
42 }
43
44 /**
45 * The shortest sublist of the input word which still shows non-determinism
46 * @return
47 */
48 public Word getShortestInconsistentInput() {
49 int indexOfInconsistency = 0;
50 while (oldOutput.getSymbol(indexOfInconsistency).equals(newOutput.getSymbol(indexOfInconsistency))) {
51 indexOfInconsistency ++;
52 }
53 return this.input.subWord(0, indexOfInconsistency);
54 }
55
56 @Override
57 public String toString() {
58 return "Non-determinism detected\nfull input:\n" + this.input + "\nfull new output:\n" + this.newOutput + "\nold output:\n" + this.oldOutput;
59 }
60 }