From d87d269a8452ff4629285cd935252430a1c9de13 Mon Sep 17 00:00:00 2001 From: Daniel Kirschten Date: Wed, 17 Jul 2019 16:13:07 +0200 Subject: [PATCH] Added sanity check; improved comments --- .../mograsim/logic/model/model/ViewModelModifiable.java | 4 ++-- .../BitVectorSplittingAtomicHighLevelStateHandler.java | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/ViewModelModifiable.java b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/ViewModelModifiable.java index d9dbdc4a..b4062288 100644 --- a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/ViewModelModifiable.java +++ b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/ViewModelModifiable.java @@ -10,8 +10,8 @@ public class ViewModelModifiable extends ViewModel public String getDefaultComponentName(GUIComponent component) { Set componentNames = getComponentsByName().keySet(); - // TODO get the ID of component^^ - // The following does not work because this code is called in the constructor of DeserializedSubmodelComponent at a time where + // TODO get the ID of component + // The following does not work because this method is called in the constructor of DeserializedSubmodelComponent at a time where // idForSerializingOverride is not yet set // String componentID = null; // if (component instanceof DeserializedSubmodelComponent) diff --git a/net.mograsim.logic.model/src/net/mograsim/logic/model/snippets/highlevelstatehandlers/standard/atomic/BitVectorSplittingAtomicHighLevelStateHandler.java b/net.mograsim.logic.model/src/net/mograsim/logic/model/snippets/highlevelstatehandlers/standard/atomic/BitVectorSplittingAtomicHighLevelStateHandler.java index dd7af34e..0e2328aa 100644 --- a/net.mograsim.logic.model/src/net/mograsim/logic/model/snippets/highlevelstatehandlers/standard/atomic/BitVectorSplittingAtomicHighLevelStateHandler.java +++ b/net.mograsim.logic.model/src/net/mograsim/logic/model/snippets/highlevelstatehandlers/standard/atomic/BitVectorSplittingAtomicHighLevelStateHandler.java @@ -16,6 +16,7 @@ public class BitVectorSplittingAtomicHighLevelStateHandler implements AtomicHigh private SubmodelComponent component; private final List vectorPartTargets; private final List vectorPartLengthes; + private int length; public BitVectorSplittingAtomicHighLevelStateHandler(HighLevelStateHandlerContext context) { @@ -41,12 +42,14 @@ public class BitVectorSplittingAtomicHighLevelStateHandler implements AtomicHigh { vectorPartTargets.add(target); vectorPartLengthes.add(length); + this.length += length; } public void clearVectorParts() { vectorPartTargets.clear(); vectorPartLengthes.clear(); + length = 0; } private void setVectorParts(List targets, List lengthes) @@ -56,6 +59,7 @@ public class BitVectorSplittingAtomicHighLevelStateHandler implements AtomicHigh throw new IllegalArgumentException("Targets list and lenghtes list have different sizes"); vectorPartTargets.addAll(targets); vectorPartLengthes.addAll(lengthes); + length += lengthes.stream().mapToInt(Integer::intValue).sum(); } @Override @@ -72,7 +76,7 @@ public class BitVectorSplittingAtomicHighLevelStateHandler implements AtomicHigh vectorPart = (BitVector) subStateUncasted; if (vectorPart.length() != vectorPartLengthes.get(partIndex)) throw new IllegalArgumentException( - "Illegal vector part length: " + vectorPart.length() + "; expected " + vectorPartLengthes.get(partIndex)); + "Incorrect vector part length: " + vectorPart.length() + "; expected " + vectorPartLengthes.get(partIndex)); result = vectorPart.concat(result); } return result; @@ -82,6 +86,8 @@ public class BitVectorSplittingAtomicHighLevelStateHandler implements AtomicHigh public void setHighLevelState(Object newState) { BitVector newStateCasted = (BitVector) newState; + if (newStateCasted.length() != length) + throw new IllegalArgumentException("Incorrect vector length: " + newStateCasted.length() + "; expected " + length); for (int partIndex = vectorPartTargets.size() - 1, bitIndex = 0; partIndex >= 0; partIndex--) { int vectorPartLength = vectorPartLengthes.get(partIndex); -- 2.17.1