From b46c59e890df8436998cde6aa72339567df81dbc Mon Sep 17 00:00:00 2001 From: Reto Breitenmoser Date: Thu, 5 Oct 2017 10:57:01 +0200 Subject: [PATCH] [Fix] removed check for duplicate keys --- .../utils/objectfilter/ObjectFilter.java | 12 ------------ .../utils/objectfilter/ObjectFilterTest.java | 18 ------------------ 2 files changed, 30 deletions(-) diff --git a/li.strolch.utils/src/main/java/li/strolch/utils/objectfilter/ObjectFilter.java b/li.strolch.utils/src/main/java/li/strolch/utils/objectfilter/ObjectFilter.java index 8331053eb..63f4c0866 100644 --- a/li.strolch.utils/src/main/java/li/strolch/utils/objectfilter/ObjectFilter.java +++ b/li.strolch.utils/src/main/java/li/strolch/utils/objectfilter/ObjectFilter.java @@ -218,18 +218,6 @@ public class ObjectFilter { if (cached == null) { - List allElements = this.cache.getAllElements(); - - // check if the object is already in the cache with an other key - if (allElements.stream().anyMatch(oCache -> oCache.getObject().equals(objectToUpdate))) { - String msg = "Invalid key provided for object with transaction ID {0} and operation {1}: existing key is {2}, new key is {3}. Object may be present in the same filter instance only once, registered using one key only. Object:{4}"; //$NON-NLS-1$ - - Optional duplicateObj = allElements.stream() - .filter(oCache -> oCache.getObject().equals(objectToUpdate)).findFirst(); - throw new IllegalArgumentException(MessageFormat.format(msg, Long.toString(id), - Operation.MODIFY.toString(), duplicateObj.get().getKey(), key, objectToUpdate.toString())); - } - // The object got an ID during this run, but was not added to this cache. // Hence, we add it now, with the current operation. ObjectCache cacheObj = new ObjectCache(dispenseID(), key, objectKey, objectToUpdate, Operation.MODIFY); diff --git a/li.strolch.utils/src/test/java/li/strolch/utils/objectfilter/ObjectFilterTest.java b/li.strolch.utils/src/test/java/li/strolch/utils/objectfilter/ObjectFilterTest.java index 5541c064b..c21e4366b 100644 --- a/li.strolch.utils/src/test/java/li/strolch/utils/objectfilter/ObjectFilterTest.java +++ b/li.strolch.utils/src/test/java/li/strolch/utils/objectfilter/ObjectFilterTest.java @@ -192,24 +192,6 @@ public class ObjectFilterTest { testAssertions(filter, 1, 1, 0, 0, 1); } - @Test - public void shouldNotAcceptDifferentKeyForSameObject() { - Object myObj = new Object(); - - ObjectFilter filter = new ObjectFilter(); - filter.add(myObj, myObj); - - try { - filter.update("different_key", myObj, myObj); - fail("Should have failed because of different key for already registered object"); - } catch (RuntimeException e) { - String msg = "Object may be present in the same filter instance only once, registered using one key only"; - assertTrue("Encountered exception: " + e.getMessage(), e.getMessage().contains(msg)); - } - - testAssertions(filter, 1, 1, 1, 0, 0); - } - @Test public void shouldReplaceOnAddAfterRemove() {