diff --git a/li.strolch.model/src/main/java/li/strolch/model/timevalue/ITimeVariable.java b/li.strolch.model/src/main/java/li/strolch/model/timevalue/ITimeVariable.java index 2aec59217..692186a27 100644 --- a/li.strolch.model/src/main/java/li/strolch/model/timevalue/ITimeVariable.java +++ b/li.strolch.model/src/main/java/li/strolch/model/timevalue/ITimeVariable.java @@ -60,7 +60,7 @@ public interface ITimeVariable { * @param time * the time the sequence starts with * - * Note: The returned result is unmodifiable + * Note: The returned result is unmodifiable * * @return the sequence of {@link ITimeValue} objects in the future */ @@ -82,7 +82,7 @@ public interface ITimeVariable { * @param time * the time the sequence starts with * - * Note: The returned result is unmodifiable + * Note: The returned result is unmodifiable * * @return the sequence of {@link ITimeValue} objects in the future */ @@ -144,4 +144,10 @@ public interface ITimeVariable { * parent */ void setReadonly(); + + /** + * Returns true if the given {@link ITimeVariable} is equal to this {@link ITimeVariable} by validating that the + * values {@link IValue IValues} have the same time and actual value + */ + boolean equals(ITimeVariable other); } diff --git a/li.strolch.model/src/main/java/li/strolch/model/timevalue/impl/TimeVariable.java b/li.strolch.model/src/main/java/li/strolch/model/timevalue/impl/TimeVariable.java index 9b15cdb75..19ed65b33 100644 --- a/li.strolch.model/src/main/java/li/strolch/model/timevalue/impl/TimeVariable.java +++ b/li.strolch.model/src/main/java/li/strolch/model/timevalue/impl/TimeVariable.java @@ -18,10 +18,7 @@ package li.strolch.model.timevalue.impl; import static java.util.Collections.unmodifiableNavigableSet; import java.io.Serializable; -import java.util.Iterator; -import java.util.NavigableSet; -import java.util.SortedSet; -import java.util.TreeSet; +import java.util.*; import java.util.stream.Stream; import li.strolch.exception.StrolchModelException; @@ -170,4 +167,36 @@ public class TimeVariable implements ITimeVariable, Seriali + " is currently readOnly, to modify clone first!"); } } + + @Override + public boolean equals(ITimeVariable o) { + return equals((Object) o); + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + @SuppressWarnings("unchecked") + TimeVariable other = (TimeVariable) o; + if (this.container.size() != other.container.size()) + return false; + Iterator> thisIter = this.container.iterator(); + Iterator> thatIter = other.container.iterator(); + while (thisIter.hasNext()) { + ITimeValue thisNext = thisIter.next(); + ITimeValue thatNext = thatIter.next(); + if (!thisNext.equals(thatNext)) + return false; + } + + return true; + } + + @Override + public int hashCode() { + return Objects.hash(this.container); + } } diff --git a/li.strolch.model/src/main/java/li/strolch/model/visitor/StrolchElementDeepEqualsVisitor.java b/li.strolch.model/src/main/java/li/strolch/model/visitor/StrolchElementDeepEqualsVisitor.java index 3b16a1c6a..359def121 100644 --- a/li.strolch.model/src/main/java/li/strolch/model/visitor/StrolchElementDeepEqualsVisitor.java +++ b/li.strolch.model/src/main/java/li/strolch/model/visitor/StrolchElementDeepEqualsVisitor.java @@ -33,8 +33,8 @@ import li.strolch.model.timevalue.ITimeVariable; import li.strolch.utils.dbc.DBC; /** - * Visitor of {@link StrolchRootElement} to check if they are equal. This implementations stores a list of {@link - * Locator} for every element of an object which is not equal, thus making it easy to find the inconsistencies in + * Visitor of {@link StrolchRootElement} to check if they are equal. This implementations stores a list of + * {@link Locator} for every element of an object which is not equal, thus making it easy to find the inconsistencies in * objects. * * @author Robert von Burg @@ -175,7 +175,7 @@ public class StrolchElementDeepEqualsVisitor implements StrolchElementVisitor
  • srcParam, Parameter dstParam) { deepEquals((StrolchElement) srcParam, (StrolchElement) dstParam); if (!srcParam.getUom().equals(dstParam.getUom())) - addLocator(dstParam.getLocator()); + addLocator(dstParam.getLocator().append(Tags.UOM)); if (!srcParam.getInterpretation().equals(dstParam.getInterpretation())) - addLocator(dstParam.getLocator()); + addLocator(dstParam.getLocator().append(Tags.INTERPRETATION)); if (srcParam.isHidden() != dstParam.isHidden()) - addLocator(dstParam.getLocator()); + addLocator(dstParam.getLocator().append(Tags.HIDDEN)); if (srcParam.getIndex() != dstParam.getIndex()) - addLocator(dstParam.getLocator()); + addLocator(dstParam.getLocator().append(Tags.INDEX)); if (!srcParam.getValue().equals(dstParam.getValue())) - addLocator(dstParam.getLocator()); + addLocator(dstParam.getLocator().append(Tags.VALUE)); } private void deepEquals(StrolchTimedState srcState, StrolchTimedState dstState) { @@ -322,7 +322,7 @@ public class StrolchElementDeepEqualsVisitor implements StrolchElementVisitor
  • srcTimeEvolution = srcState.getTimeEvolution(); final ITimeVariable dstTimeEvolution = dstState.getTimeEvolution(); - if (!srcTimeEvolution.getValues().equals(dstTimeEvolution.getValues())) + if (!srcTimeEvolution.equals(dstTimeEvolution)) addLocator(dstState.getLocator().append(Tags.VALUES)); } diff --git a/li.strolch.model/src/test/java/li/strolch/model/ModelTest.java b/li.strolch.model/src/test/java/li/strolch/model/ModelTest.java index d6136faf3..7c3fe3771 100644 --- a/li.strolch.model/src/test/java/li/strolch/model/ModelTest.java +++ b/li.strolch.model/src/test/java/li/strolch/model/ModelTest.java @@ -274,10 +274,20 @@ public class ModelTest { FloatParameter fParam = bag.getParameter(PARAM_FLOAT_ID); fParam.setValue(23434234.234); fParam.setName("Ohla"); + FloatTimedState floatState = dstRes.getTimedState(STATE_FLOAT_ID, true); + floatState.setStateFromStringAt(STATE_TIME_30, "3453451.0"); StrolchElementDeepEqualsVisitor visitor = new StrolchElementDeepEqualsVisitor(srcRes); List mismatches = dstRes.accept(visitor); assertFalse("Resource should not be same if param is changed!", mismatches.isEmpty()); - assertEquals("Multiple changes should be registered", 3, mismatches.size()); + assertEquals("Multiple changes should be registered", 4, mismatches.size()); + assertTrue("Should contain locator", + mismatches.contains(Locator.valueOf("Resource/MyType/@res01/Bag/@bag01/Name"))); + assertTrue("Should contain locator", + mismatches.contains(Locator.valueOf("Resource/MyType/@res01/Bag/@bag01/@param2/Name"))); + assertTrue("Should contain locator", + mismatches.contains(Locator.valueOf("Resource/MyType/@res01/Bag/@bag01/@param2/Value"))); + assertTrue("Should contain locator", + mismatches.contains(Locator.valueOf("Resource/MyType/@res01/State/@state1/Values"))); } @Test