Fix for bug 9719.
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130709 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
bde0d09c4c
commit
c1cdfa611c
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/SequencedHashMap.java,v 1.10 2002/05/24 04:00:30 mas Exp $
|
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/SequencedHashMap.java,v 1.11 2002/06/09 07:14:14 mas Exp $
|
||||||
* $Revision: 1.10 $
|
* $Revision: 1.11 $
|
||||||
* $Date: 2002/05/24 04:00:30 $
|
* $Date: 2002/06/09 07:14:14 $
|
||||||
*
|
*
|
||||||
* ====================================================================
|
* ====================================================================
|
||||||
*
|
*
|
||||||
|
@ -478,19 +478,20 @@ public class SequencedHashMap implements Map, Cloneable, Externalizable {
|
||||||
|
|
||||||
// per Map.remove(Object)
|
// per Map.remove(Object)
|
||||||
public Object remove(Object key) {
|
public Object remove(Object key) {
|
||||||
modCount++;
|
Entry e = removeImpl(key);
|
||||||
return removeImpl(key);
|
return (e == null) ? null : e.getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removed an entry without changing the map's modification count. This
|
* Fully remove an entry from the map, returning the old entry or null if
|
||||||
* method should only be called from a collection view's iterator
|
* there was no such entry with the specified key.
|
||||||
**/
|
**/
|
||||||
private Object removeImpl(Object key) {
|
private Entry removeImpl(Object key) {
|
||||||
Entry e = (Entry)entries.remove(key);
|
Entry e = (Entry)entries.remove(key);
|
||||||
if(e == null) return null;
|
if(e == null) return null;
|
||||||
|
modCount++;
|
||||||
removeEntry(e);
|
removeEntry(e);
|
||||||
return e.getValue();
|
return e;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -568,7 +569,8 @@ public class SequencedHashMap implements Map, Cloneable, Externalizable {
|
||||||
// required impls
|
// required impls
|
||||||
public Iterator iterator() { return new OrderedIterator(KEY); }
|
public Iterator iterator() { return new OrderedIterator(KEY); }
|
||||||
public boolean remove(Object o) {
|
public boolean remove(Object o) {
|
||||||
return SequencedHashMap.this.remove(o) != null;
|
Entry e = SequencedHashMap.this.removeImpl(o);
|
||||||
|
return (e != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// more efficient impls than abstract set
|
// more efficient impls than abstract set
|
||||||
|
@ -600,14 +602,14 @@ public class SequencedHashMap implements Map, Cloneable, Externalizable {
|
||||||
if(value == null) {
|
if(value == null) {
|
||||||
for(Entry pos = sentinel.next; pos != sentinel; pos = pos.next) {
|
for(Entry pos = sentinel.next; pos != sentinel; pos = pos.next) {
|
||||||
if(pos.getValue() == null) {
|
if(pos.getValue() == null) {
|
||||||
SequencedHashMap.this.remove(pos.getKey());
|
SequencedHashMap.this.removeImpl(pos.getKey());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for(Entry pos = sentinel.next; pos != sentinel; pos = pos.next) {
|
for(Entry pos = sentinel.next; pos != sentinel; pos = pos.next) {
|
||||||
if(value.equals(pos.getValue())) {
|
if(value.equals(pos.getValue())) {
|
||||||
SequencedHashMap.this.remove(pos.getKey());
|
SequencedHashMap.this.removeImpl(pos.getKey());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -654,7 +656,7 @@ public class SequencedHashMap implements Map, Cloneable, Externalizable {
|
||||||
Entry e = findEntry(o);
|
Entry e = findEntry(o);
|
||||||
if(e == null) return false;
|
if(e == null) return false;
|
||||||
|
|
||||||
return SequencedHashMap.this.remove(e.getKey()) != null;
|
return SequencedHashMap.this.removeImpl(e.getKey()) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// more efficient impls than abstract collection
|
// more efficient impls than abstract collection
|
||||||
|
@ -791,10 +793,11 @@ public class SequencedHashMap implements Map, Cloneable, Externalizable {
|
||||||
throw new ConcurrentModificationException();
|
throw new ConcurrentModificationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove the entry by calling the removeImpl method which does not
|
|
||||||
// update the mod count. This allows the iterator to remain valid.
|
|
||||||
SequencedHashMap.this.removeImpl(pos.getKey());
|
SequencedHashMap.this.removeImpl(pos.getKey());
|
||||||
|
|
||||||
|
// update the expected mod count for the remove operation
|
||||||
|
expectedModCount++;
|
||||||
|
|
||||||
// set the removed flag
|
// set the removed flag
|
||||||
returnType = returnType | REMOVED_MASK;
|
returnType = returnType | REMOVED_MASK;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue