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.
*/
public void remove(T element) {
ConcurrentIterator<T> iter = this.iterator();
while (iter.hasNext()) {
T e = iter.next();
if (e.equals(element)) {
iter.remove();
return;
ConcurrentLinkedListNode<T> currentNode = this.head;
while(element.equals(currentNode.getValue()) == false && currentNode.hasNext()) {
currentNode = currentNode.next();
}
if(currentNode.getValue().equals(element)) {
currentNode.setValue(null);
return;
}
}