Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/changes/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
<action type="fix" dev="ggregory" due-to="Dexter.k, Gary Gregory">Re-validate entries in PredicatedMap/PredicatedCollection readObject (#682).</action>
<action type="fix" dev="ggregory" due-to="Ruiqi Dong, Gary Gregory" issue="COLLECTIONS-889">IndexedCollection.remove(Object) removes all values for a non-unique index key.</action>
<action type="fix" dev="ggregory" due-to="Ruiqi Dong, Gary Gregory" issue="COLLECTIONS-890">TransformIterator throws NullPointerException when its transformer is null.</action>
<action type="fix" dev="ggregory" due-to="Ruiqi Dong, Gary Gregory" issue="COLLECTIONS-891">IndexedCollection.contains(Object) can return true for objects that were never added.</action>
<action type="fix" dev="ggregory" due-to="Ruiqi Dong, Gary Gregory" issue="COLLECTIONS-892">IndexedCollection.add(Object) mutates unique indexed collections before rejecting duplicate keys.</action>
<action type="fix" dev="ggregory" due-to="Maxim Safronov, Gary Gregory" issue="COLLECTIONS-878">MapUtils.invertMap() improves HashMap construction (#652).</action>
<action type="fix" dev="ggregory" due-to="Dexter.k, Gary Gregory">Validate order and uniqueness invariants in decorator readObject() (#684).</action>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ public void clear() {
@SuppressWarnings("unchecked")
@Override
public boolean contains(final Object object) {
return index.containsKey(keyTransformer.apply((C) object));
final Collection<C> values = (Collection<C>) index.get(keyTransformer.apply((C) object));
return values != null && values.contains(object);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import static java.util.Arrays.asList;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
Expand Down Expand Up @@ -116,6 +117,22 @@ void testAddedObjectsCanBeRetrievedByKey() throws Exception {
assertEquals("4", indexed.get(4));
}

@Test
void testContainsUsesObjectEqualityNotOnlyTransformedKey() {
final Collection<String> coll = makeUniqueTestCollection();
coll.add("01");

assertFalse(coll.contains("1"));
}

@Test
void testContainsUsesObjectEqualityWithNonUniqueIndex() {
final Collection<String> coll = makeTestCollection();
coll.add("01");

assertFalse(coll.contains("1"));
}

@Test
void testDecoratedCollectionIsIndexedOnCreation() throws Exception {
final Collection<String> original = makeFullCollection();
Expand Down
Loading