Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,7 @@ public void remove() {
throw new IllegalStateException();
}
Element nextElement = indexToElement(head, elements, lastReturned.next());
removeFromList(head, elements, nextElement.prev());
size--;
ImplicitLinkedHashCollection.this.removeElementAtSlot(nextElement.prev());
if (lastReturned == cur) {
// If the element we are removing was cur, set cur to cur->next.
cur = nextElement;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertEquals;
Expand Down Expand Up @@ -103,7 +104,8 @@ public String toString() {

@Override
public int hashCode() {
return key;
long hashCode = 2654435761L * key;
return (int) (hashCode >> 32);
}
}

Expand Down Expand Up @@ -596,4 +598,25 @@ public void testMoveToEnd() {
Assert.assertThrows(RuntimeException.class, () ->
coll.moveToEnd(new TestElement(4, 4)));
}
}

@Test
public void testRemovals() {
ImplicitLinkedHashCollection<TestElement> coll = new ImplicitLinkedHashCollection<>();
List<TestElement> elements = new ArrayList<>();
for (int i = 0; i < 100; i++) {
TestElement element = new TestElement(i, i); //random.nextInt(0x7fff) << 16 | i, i);
elements.add(element);
coll.add(element);
}
assertEquals(100, coll.size());
Iterator<TestElement> iter = coll.iterator();
for (int i = 0; i < 50; i++) {
iter.next();
iter.remove();
}
assertEquals(50, coll.size());
for (int i = 50; i < 100; i++) {
assertNotNull(coll.find(elements.get(i)));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could make this assertion a little stronger:

            assertEquals(new TestElement(i, i), coll.find(elements.get(i)));

}
}
}