Remove the need for an Iterator within the lists remove method.

This commit is contained in:
Jan Philipp Timme 2014-11-09 11:33:50 +01:00
parent 64039fdee7
commit eccc317bea
1 changed files with 7 additions and 7 deletions

View File

@ -43,13 +43,13 @@ public class ConcurrentLinkedList<T> {
* Remove an element from the list. * Remove an element from the list.
*/ */
public void remove(T element) { public void remove(T element) {
ConcurrentIterator<T> iter = this.iterator(); ConcurrentLinkedListNode<T> currentNode = this.head;
while (iter.hasNext()) { while(element.equals(currentNode.getValue()) == false && currentNode.hasNext()) {
T e = iter.next(); currentNode = currentNode.next();
if (e.equals(element)) { }
iter.remove(); if(currentNode.getValue().equals(element)) {
return; currentNode.setValue(null);
} return;
} }
} }