From ac914c719d401c44cb2633127952b022bf563ff3 Mon Sep 17 00:00:00 2001 From: René den Hertog Date: Thu, 26 Oct 2017 17:34:51 +0200 Subject: 'Bounded Retransmission Protocol' Blob --- .../basiclearner/CacheInconsistencyException.java | 60 ++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 assignments/assignment2/Bounded Retransmission Protocol Tester/Source/basiclearner/CacheInconsistencyException.java (limited to 'assignments/assignment2/Bounded Retransmission Protocol Tester/Source/basiclearner/CacheInconsistencyException.java') 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; + } +} -- cgit v1.2.3