scolebourne 2003/12/28 16:38:08
Modified: collections/src/java/org/apache/commons/collections/list
CursorableLinkedList.java AbstractLinkedList.java
collections/src/java/org/apache/commons/collections/bidimap
AbstractDualBidiMap.java DualTreeBidiMap.java
collections/src/java/org/apache/commons/collections/map
AbstractHashedMap.java AbstractLinkedMap.java
Log:
Unify the variable names across implementations
Revision Changes Path
1.2 +6 -274
jakarta-commons/collections/src/java/org/apache/commons/collections/list/CursorableLinkedList.java
Index: CursorableLinkedList.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/list/CursorableLinkedList.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- CursorableLinkedList.java 24 Dec 2003 01:15:40 -0000 1.1
+++ CursorableLinkedList.java 29 Dec 2003 00:38:08 -0000 1.2
@@ -456,11 +456,11 @@
*/
public int nextIndex() {
if (nextIndexValid == false) {
- if (next == list.header) {
- nextIndex = list.size();
+ if (next == parent.header) {
+ nextIndex = parent.size();
} else {
int pos = 0;
- Node temp = list.header.next;
+ Node temp = parent.header.next;
while (temp != next) {
pos++;
temp = temp.next;
@@ -531,277 +531,9 @@
*/
public void close() {
if (valid) {
- ((CursorableLinkedList) list).unregisterCursor(this);
+ ((CursorableLinkedList) parent).unregisterCursor(this);
valid = false;
}
}
}
}
-
-//class CursorableSubList extends CursorableLinkedList implements List {
-//
-// //--- constructors -----------------------------------------------
-//
-// CursorableSubList(CursorableLinkedList list, int from, int to) {
-// if(0 > from || list.size() < to) {
-// throw new IndexOutOfBoundsException();
-// } else if(from > to) {
-// throw new IllegalArgumentException();
-// }
-// _list = list;
-// if(from < list.size()) {
-// _head.setNext(_list.getListableAt(from));
-// _pre = (null == _head.next()) ? null : _head.next().prev();
-// } else {
-// _pre = _list.getListableAt(from-1);
-// }
-// if(from == to) {
-// _head.setNext(null);
-// _head.setPrev(null);
-// if(to < list.size()) {
-// _post = _list.getListableAt(to);
-// } else {
-// _post = null;
-// }
-// } else {
-// _head.setPrev(_list.getListableAt(to-1));
-// _post = _head.prev().next();
-// }
-// _size = to - from;
-// _modCount = _list._modCount;
-// }
-//
-// //--- public methods ------------------------------------------
-//
-// public void clear() {
-// checkForComod();
-// Iterator it = iterator();
-// while(it.hasNext()) {
-// it.next();
-// it.remove();
-// }
-// }
-//
-// public Iterator iterator() {
-// checkForComod();
-// return super.iterator();
-// }
-//
-// public int size() {
-// checkForComod();
-// return super.size();
-// }
-//
-// public boolean isEmpty() {
-// checkForComod();
-// return super.isEmpty();
-// }
-//
-// public Object[] toArray() {
-// checkForComod();
-// return super.toArray();
-// }
-//
-// public Object[] toArray(Object a[]) {
-// checkForComod();
-// return super.toArray(a);
-// }
-//
-// public boolean contains(Object o) {
-// checkForComod();
-// return super.contains(o);
-// }
-//
-// public boolean remove(Object o) {
-// checkForComod();
-// return super.remove(o);
-// }
-//
-// public Object removeFirst() {
-// checkForComod();
-// return super.removeFirst();
-// }
-//
-// public Object removeLast() {
-// checkForComod();
-// return super.removeLast();
-// }
-//
-// public boolean addAll(Collection c) {
-// checkForComod();
-// return super.addAll(c);
-// }
-//
-// public boolean add(Object o) {
-// checkForComod();
-// return super.add(o);
-// }
-//
-// public boolean addFirst(Object o) {
-// checkForComod();
-// return super.addFirst(o);
-// }
-//
-// public boolean addLast(Object o) {
-// checkForComod();
-// return super.addLast(o);
-// }
-//
-// public boolean removeAll(Collection c) {
-// checkForComod();
-// return super.removeAll(c);
-// }
-//
-// public boolean containsAll(Collection c) {
-// checkForComod();
-// return super.containsAll(c);
-// }
-//
-// public boolean addAll(int index, Collection c) {
-// checkForComod();
-// return super.addAll(index,c);
-// }
-//
-// public int hashCode() {
-// checkForComod();
-// return super.hashCode();
-// }
-//
-// public boolean retainAll(Collection c) {
-// checkForComod();
-// return super.retainAll(c);
-// }
-//
-// public Object set(int index, Object element) {
-// checkForComod();
-// return super.set(index,element);
-// }
-//
-// public boolean equals(Object o) {
-// checkForComod();
-// return super.equals(o);
-// }
-//
-// public Object get(int index) {
-// checkForComod();
-// return super.get(index);
-// }
-//
-// public Object getFirst() {
-// checkForComod();
-// return super.getFirst();
-// }
-//
-// public Object getLast() {
-// checkForComod();
-// return super.getLast();
-// }
-//
-// public void add(int index, Object element) {
-// checkForComod();
-// super.add(index,element);
-// }
-//
-// public ListIterator listIterator(int index) {
-// checkForComod();
-// return super.listIterator(index);
-// }
-//
-// public Object remove(int index) {
-// checkForComod();
-// return super.remove(index);
-// }
-//
-// public int indexOf(Object o) {
-// checkForComod();
-// return super.indexOf(o);
-// }
-//
-// public int lastIndexOf(Object o) {
-// checkForComod();
-// return super.lastIndexOf(o);
-// }
-//
-// public ListIterator listIterator() {
-// checkForComod();
-// return super.listIterator();
-// }
-//
-// public List subList(int fromIndex, int toIndex) {
-// checkForComod();
-// return super.subList(fromIndex,toIndex);
-// }
-//
-// //--- protected methods ------------------------------------------
-//
-// /**
-// * Inserts a new <i>value</i> into my
-// * list, after the specified <i>before</i> element, and before the
-// * specified <i>after</i> element
-// *
-// * @return the newly created [EMAIL PROTECTED] CursorableLinkedList.Listable}
-// */
-// protected Listable insertListable(Listable before, Listable after, Object
value) {
-// _modCount++;
-// _size++;
-// Listable elt = _list.insertListable((null == before ? _pre : before),
(null == after ? _post : after),value);
-// if(null == _head.next()) {
-// _head.setNext(elt);
-// _head.setPrev(elt);
-// }
-// if(before == _head.prev()) {
-// _head.setPrev(elt);
-// }
-// if(after == _head.next()) {
-// _head.setNext(elt);
-// }
-// broadcastListableInserted(elt);
-// return elt;
-// }
-//
-// /**
-// * Removes the given [EMAIL PROTECTED] CursorableLinkedList.Listable} from my
list.
-// */
-// protected void removeListable(Listable elt) {
-// _modCount++;
-// _size--;
-// if(_head.next() == elt && _head.prev() == elt) {
-// _head.setNext(null);
-// _head.setPrev(null);
-// }
-// if(_head.next() == elt) {
-// _head.setNext(elt.next());
-// }
-// if(_head.prev() == elt) {
-// _head.setPrev(elt.prev());
-// }
-// _list.removeListable(elt);
-// broadcastListableRemoved(elt);
-// }
-//
-// /**
-// * Test to see if my underlying list has been modified
-// * by some other process. If it has, throws a
-// * [EMAIL PROTECTED] ConcurrentModificationException}, otherwise
-// * quietly returns.
-// *
-// * @throws ConcurrentModificationException
-// */
-// protected void checkForComod() throws ConcurrentModificationException {
-// if(_modCount != _list._modCount) {
-// throw new ConcurrentModificationException();
-// }
-// }
-//
-// //--- protected attributes ---------------------------------------
-//
-// /** My underlying list */
-// protected CursorableLinkedList _list = null;
-//
-// /** The element in my underlying list preceding the first element in my list.
*/
-// protected Listable _pre = null;
-//
-// /** The element in my underlying list following the last element in my list.
*/
-// protected Listable _post = null;
-//
-//}
1.4 +32 -32
jakarta-commons/collections/src/java/org/apache/commons/collections/list/AbstractLinkedList.java
Index: AbstractLinkedList.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/list/AbstractLinkedList.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- AbstractLinkedList.java 28 Dec 2003 17:58:54 -0000 1.3
+++ AbstractLinkedList.java 29 Dec 2003 00:38:08 -0000 1.4
@@ -681,7 +681,7 @@
protected static class LinkedListIterator implements ListIterator,
OrderedIterator {
/** The parent list */
- protected final AbstractLinkedList list;
+ protected final AbstractLinkedList parent;
/**
* The node that will be returned by [EMAIL PROTECTED] #next()}. If this is
equal
@@ -718,11 +718,11 @@
* @param parent the parent list
* @param fromIndex the index to start at
*/
- public LinkedListIterator(AbstractLinkedList parent, int fromIndex) throws
IndexOutOfBoundsException {
+ protected LinkedListIterator(AbstractLinkedList parent, int fromIndex)
throws IndexOutOfBoundsException {
super();
- this.list = parent;
- this.expectedModCount = list.modCount;
- this.next = list.getNode(fromIndex, true);
+ this.parent = parent;
+ this.expectedModCount = parent.modCount;
+ this.next = parent.getNode(fromIndex, true);
this.nextIndex = fromIndex;
}
@@ -734,7 +734,7 @@
* count isn't the value that was expected.
*/
protected void checkModCount() {
- if (list.modCount != expectedModCount) {
+ if (parent.modCount != expectedModCount) {
throw new ConcurrentModificationException();
}
}
@@ -754,7 +754,7 @@
}
public boolean hasNext() {
- return next != list.header;
+ return next != parent.header;
}
public Object next() {
@@ -771,7 +771,7 @@
}
public boolean hasPrevious() {
- return next.previous != list.header;
+ return next.previous != parent.header;
}
public Object previous() {
@@ -797,7 +797,7 @@
public void remove() {
checkModCount();
- list.removeNode(getLastNodeReturned());
+ parent.removeNode(getLastNodeReturned());
current = null;
nextIndex--;
expectedModCount++;
@@ -810,7 +810,7 @@
public void add(Object obj) {
checkModCount();
- list.addNodeBefore(next, obj);
+ parent.addNodeBefore(next, obj);
current = null;
nextIndex++;
expectedModCount++;
@@ -828,7 +828,7 @@
protected final LinkedSubList sub;
protected LinkedSubListIterator(LinkedSubList sub, int startIndex) {
- super(sub.list, startIndex + sub.offset);
+ super(sub.parent, startIndex + sub.offset);
this.sub = sub;
}
@@ -846,13 +846,13 @@
public void add(Object obj) {
super.add(obj);
- sub.expectedModCount = list.modCount;
+ sub.expectedModCount = parent.modCount;
sub.size++;
}
public void remove() {
super.remove();
- sub.expectedModCount = list.modCount;
+ sub.expectedModCount = parent.modCount;
sub.size--;
}
}
@@ -863,7 +863,7 @@
*/
protected static class LinkedSubList extends AbstractList {
/** The main list */
- private AbstractLinkedList list;
+ private AbstractLinkedList parent;
/** Offset from the main list */
private int offset;
/** Sublist size */
@@ -871,20 +871,20 @@
/** Sublist modCount */
private int expectedModCount;
- protected LinkedSubList(AbstractLinkedList list, int fromIndex, int
toIndex) {
+ protected LinkedSubList(AbstractLinkedList parent, int fromIndex, int
toIndex) {
if (fromIndex < 0) {
throw new IndexOutOfBoundsException("fromIndex = " + fromIndex);
}
- if (toIndex > list.size()) {
+ if (toIndex > parent.size()) {
throw new IndexOutOfBoundsException("toIndex = " + toIndex);
}
if (fromIndex > toIndex) {
throw new IllegalArgumentException("fromIndex(" + fromIndex + ") >
toIndex(" + toIndex + ")");
}
- this.list = list;
+ this.parent = parent;
this.offset = fromIndex;
this.size = toIndex - fromIndex;
- this.expectedModCount = list.modCount;
+ this.expectedModCount = parent.modCount;
}
public int size() {
@@ -895,14 +895,14 @@
public Object get(int index) {
rangeCheck(index, size);
checkModCount();
- return list.get(index + offset);
+ return parent.get(index + offset);
}
public void add(int index, Object obj) {
rangeCheck(index, size + 1);
checkModCount();
- list.add(index + offset, obj);
- expectedModCount = list.modCount;
+ parent.add(index + offset, obj);
+ expectedModCount = parent.modCount;
size++;
LinkedSubList.this.modCount++;
}
@@ -910,8 +910,8 @@
public Object remove(int index) {
rangeCheck(index, size);
checkModCount();
- Object result = list.remove(index + offset);
- expectedModCount = list.modCount;
+ Object result = parent.remove(index + offset);
+ expectedModCount = parent.modCount;
size--;
LinkedSubList.this.modCount++;
return result;
@@ -929,8 +929,8 @@
}
checkModCount();
- list.addAll(offset + index, coll);
- expectedModCount = list.modCount;
+ parent.addAll(offset + index, coll);
+ expectedModCount = parent.modCount;
size += cSize;
LinkedSubList.this.modCount++;
return true;
@@ -939,7 +939,7 @@
public Object set(int index, Object obj) {
rangeCheck(index, size);
checkModCount();
- return list.set(index + offset, obj);
+ return parent.set(index + offset, obj);
}
public void clear() {
@@ -953,17 +953,17 @@
public Iterator iterator() {
checkModCount();
- return list.createSubListIterator(this);
+ return parent.createSubListIterator(this);
}
public ListIterator listIterator(final int index) {
rangeCheck(index, size + 1);
checkModCount();
- return list.createSubListListIterator(this, index);
+ return parent.createSubListListIterator(this, index);
}
public List subList(int fromIndexInclusive, int toIndexExclusive) {
- return new LinkedSubList(list, fromIndexInclusive + offset,
toIndexExclusive + offset);
+ return new LinkedSubList(parent, fromIndexInclusive + offset,
toIndexExclusive + offset);
}
protected void rangeCheck(int index, int beyond) {
@@ -973,7 +973,7 @@
}
protected void checkModCount() {
- if (list.modCount != expectedModCount) {
+ if (parent.modCount != expectedModCount) {
throw new ConcurrentModificationException();
}
}
1.6 +82 -67
jakarta-commons/collections/src/java/org/apache/commons/collections/bidimap/AbstractDualBidiMap.java
Index: AbstractDualBidiMap.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/bidimap/AbstractDualBidiMap.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- AbstractDualBidiMap.java 14 Dec 2003 12:59:38 -0000 1.5
+++ AbstractDualBidiMap.java 29 Dec 2003 00:38:08 -0000 1.6
@@ -296,15 +296,16 @@
*/
protected static abstract class View extends AbstractCollectionDecorator {
- protected final AbstractDualBidiMap map;
+ /** The parent map */
+ protected final AbstractDualBidiMap parent;
- protected View(Collection coll, AbstractDualBidiMap map) {
+ protected View(Collection coll, AbstractDualBidiMap parent) {
super(coll);
- this.map = map;
+ this.parent = parent;
}
public boolean removeAll(Collection coll) {
- if (map.isEmpty() || coll.isEmpty()) {
+ if (parent.isEmpty() || coll.isEmpty()) {
return false;
}
boolean modified = false;
@@ -319,11 +320,11 @@
}
public boolean retainAll(Collection coll) {
- if (map.isEmpty()) {
+ if (parent.isEmpty()) {
return false;
}
if (coll.isEmpty()) {
- map.clear();
+ parent.clear();
return true;
}
boolean modified = false;
@@ -338,7 +339,7 @@
}
public void clear() {
- map.clear();
+ parent.clear();
}
}
@@ -348,22 +349,22 @@
*/
protected static class KeySet extends View implements Set {
- protected KeySet(AbstractDualBidiMap map) {
- super(map.maps[0].keySet(), map);
+ protected KeySet(AbstractDualBidiMap parent) {
+ super(parent.maps[0].keySet(), parent);
}
public Iterator iterator() {
- return new KeySetIterator(super.iterator(), map);
+ return new KeySetIterator(super.iterator(), parent);
}
public boolean contains(Object key) {
- return map.maps[0].containsKey(key);
+ return parent.maps[0].containsKey(key);
}
public boolean remove(Object key) {
- if (map.maps[0].containsKey(key)) {
- Object value = map.maps[0].remove(key);
- map.maps[1].remove(value);
+ if (parent.maps[0].containsKey(key)) {
+ Object value = parent.maps[0].remove(key);
+ parent.maps[1].remove(value);
return true;
}
return false;
@@ -375,13 +376,16 @@
*/
protected static class KeySetIterator extends AbstractIteratorDecorator {
- private final AbstractDualBidiMap map;
- private Object lastKey = null;
- private boolean canRemove = false;
+ /** The parent map */
+ protected final AbstractDualBidiMap parent;
+ /** The last returned key */
+ protected Object lastKey = null;
+ /** Whether remove is allowed at present */
+ protected boolean canRemove = false;
- protected KeySetIterator(Iterator iterator, AbstractDualBidiMap map) {
+ protected KeySetIterator(Iterator iterator, AbstractDualBidiMap parent) {
super(iterator);
- this.map = map;
+ this.parent = parent;
}
public Object next() {
@@ -394,9 +398,9 @@
if (canRemove == false) {
throw new IllegalStateException("Iterator remove() can only be
called once after next()");
}
- Object value = map.maps[0].get(lastKey);
+ Object value = parent.maps[0].get(lastKey);
super.remove();
- map.maps[1].remove(value);
+ parent.maps[1].remove(value);
lastKey = null;
canRemove = false;
}
@@ -408,22 +412,22 @@
*/
protected static class Values extends View implements Set {
- protected Values(AbstractDualBidiMap map) {
- super(map.maps[0].values(), map);
+ protected Values(AbstractDualBidiMap parent) {
+ super(parent.maps[0].values(), parent);
}
public Iterator iterator() {
- return new ValuesIterator(super.iterator(), map);
+ return new ValuesIterator(super.iterator(), parent);
}
public boolean contains(Object value) {
- return map.maps[1].containsKey(value);
+ return parent.maps[1].containsKey(value);
}
public boolean remove(Object value) {
- if (map.maps[1].containsKey(value)) {
- Object key = map.maps[1].remove(value);
- map.maps[0].remove(key);
+ if (parent.maps[1].containsKey(value)) {
+ Object key = parent.maps[1].remove(value);
+ parent.maps[0].remove(key);
return true;
}
return false;
@@ -435,13 +439,16 @@
*/
protected static class ValuesIterator extends AbstractIteratorDecorator {
- private final AbstractDualBidiMap map;
- private Object lastValue = null;
- private boolean canRemove = false;
+ /** The parent map */
+ protected final AbstractDualBidiMap parent;
+ /** The last returned value */
+ protected Object lastValue = null;
+ /** Whether remove is allowed at present */
+ protected boolean canRemove = false;
- protected ValuesIterator(Iterator iterator, AbstractDualBidiMap map) {
+ protected ValuesIterator(Iterator iterator, AbstractDualBidiMap parent) {
super(iterator);
- this.map = map;
+ this.parent = parent;
}
public Object next() {
@@ -455,7 +462,7 @@
throw new IllegalStateException("Iterator remove() can only be
called once after next()");
}
super.remove(); // removes from maps[0]
- map.maps[1].remove(lastValue);
+ parent.maps[1].remove(lastValue);
lastValue = null;
canRemove = false;
}
@@ -467,12 +474,12 @@
*/
protected static class EntrySet extends View implements Set {
- protected EntrySet(AbstractDualBidiMap map) {
- super(map.maps[0].entrySet(), map);
+ protected EntrySet(AbstractDualBidiMap parent) {
+ super(parent.maps[0].entrySet(), parent);
}
public Iterator iterator() {
- return new EntrySetIterator(super.iterator(), map);
+ return new EntrySetIterator(super.iterator(), parent);
}
public boolean remove(Object obj) {
@@ -480,9 +487,9 @@
return false;
}
Map.Entry entry = (Map.Entry) obj;
- if (map.containsKey(entry.getKey())) {
- Object value = map.maps[0].remove(entry.getKey());
- map.maps[1].remove(value);
+ if (parent.containsKey(entry.getKey())) {
+ Object value = parent.maps[0].remove(entry.getKey());
+ parent.maps[1].remove(value);
return true;
}
return false;
@@ -494,17 +501,20 @@
*/
protected static class EntrySetIterator extends AbstractIteratorDecorator {
- private final AbstractDualBidiMap map;
- private Map.Entry last = null;
- private boolean canRemove = false;
+ /** The parent map */
+ protected final AbstractDualBidiMap parent;
+ /** The last returned entry */
+ protected Map.Entry last = null;
+ /** Whether remove is allowed at present */
+ protected boolean canRemove = false;
- protected EntrySetIterator(Iterator iterator, AbstractDualBidiMap map) {
+ protected EntrySetIterator(Iterator iterator, AbstractDualBidiMap parent) {
super(iterator);
- this.map = map;
+ this.parent = parent;
}
public Object next() {
- last = new MapEntry((Map.Entry) super.next(), map);
+ last = new MapEntry((Map.Entry) super.next(), parent);
canRemove = true;
return last;
}
@@ -516,7 +526,7 @@
// store value as remove may change the entry in the decorator
(eg.TreeMap)
Object value = last.getValue();
super.remove();
- map.maps[1].remove(value);
+ parent.maps[1].remove(value);
last = null;
canRemove = false;
}
@@ -526,21 +536,22 @@
* Inner class MapEntry.
*/
protected static class MapEntry extends AbstractMapEntryDecorator {
+
+ /** The parent map */
+ protected final AbstractDualBidiMap parent;
- protected final AbstractDualBidiMap map;
-
- protected MapEntry(Map.Entry entry, AbstractDualBidiMap map) {
+ protected MapEntry(Map.Entry entry, AbstractDualBidiMap parent) {
super(entry);
- this.map = map;
+ this.parent = parent;
}
public Object setValue(Object value) {
Object key = MapEntry.this.getKey();
- if (map.maps[1].containsKey(value) &&
- map.maps[1].get(value) != key) {
+ if (parent.maps[1].containsKey(value) &&
+ parent.maps[1].get(value) != key) {
throw new IllegalArgumentException("Cannot use setValue() when the
object being set is already in the map");
}
- map.put(key, value);
+ parent.put(key, value);
final Object oldValue = super.setValue(value);
return oldValue;
}
@@ -551,15 +562,19 @@
*/
protected static class BidiMapIterator implements MapIterator,
ResettableIterator {
- protected final AbstractDualBidiMap map;
+ /** The parent map */
+ protected final AbstractDualBidiMap parent;
+ /** The iterator being wrapped */
protected Iterator iterator;
- private Map.Entry last = null;
- private boolean canRemove = false;
+ /** The last returned entry */
+ protected Map.Entry last = null;
+ /** Whether remove is allowed at present */
+ protected boolean canRemove = false;
- protected BidiMapIterator(AbstractDualBidiMap map) {
+ protected BidiMapIterator(AbstractDualBidiMap parent) {
super();
- this.map = map;
- this.iterator = map.maps[0].entrySet().iterator();
+ this.parent = parent;
+ this.iterator = parent.maps[0].entrySet().iterator();
}
public boolean hasNext() {
@@ -579,7 +594,7 @@
// store value as remove may change the entry in the decorator
(eg.TreeMap)
Object value = last.getValue();
iterator.remove();
- map.maps[1].remove(value);
+ parent.maps[1].remove(value);
last = null;
canRemove = false;
}
@@ -602,15 +617,15 @@
if (last == null) {
throw new IllegalStateException("Iterator setValue() can only be
called after next() and before remove()");
}
- if (map.maps[1].containsKey(value) &&
- map.maps[1].get(value) != last.getKey()) {
+ if (parent.maps[1].containsKey(value) &&
+ parent.maps[1].get(value) != last.getKey()) {
throw new IllegalArgumentException("Cannot use setValue() when the
object being set is already in the map");
}
- return map.put(last.getKey(), value);
+ return parent.put(last.getKey(), value);
}
public void reset() {
- iterator = map.maps[0].entrySet().iterator();
+ iterator = parent.maps[0].entrySet().iterator();
last = null;
canRemove = false;
}
1.7 +14 -11
jakarta-commons/collections/src/java/org/apache/commons/collections/bidimap/DualTreeBidiMap.java
Index: DualTreeBidiMap.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/bidimap/DualTreeBidiMap.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- DualTreeBidiMap.java 25 Dec 2003 00:33:04 -0000 1.6
+++ DualTreeBidiMap.java 29 Dec 2003 00:38:08 -0000 1.7
@@ -289,14 +289,17 @@
*/
protected static class BidiOrderedMapIterator implements OrderedMapIterator,
ResettableIterator {
- protected final AbstractDualBidiMap map;
+ /** The parent map */
+ protected final AbstractDualBidiMap parent;
+ /** The iterator being decorated */
protected ListIterator iterator;
+ /** The last returned entry */
private Map.Entry last = null;
- protected BidiOrderedMapIterator(AbstractDualBidiMap map) {
+ protected BidiOrderedMapIterator(AbstractDualBidiMap parent) {
super();
- this.map = map;
- iterator = new ArrayList(map.entrySet()).listIterator();
+ this.parent = parent;
+ iterator = new ArrayList(parent.entrySet()).listIterator();
}
public boolean hasNext() {
@@ -319,7 +322,7 @@
public void remove() {
iterator.remove();
- map.remove(last.getKey());
+ parent.remove(last.getKey());
last = null;
}
@@ -341,15 +344,15 @@
if (last == null) {
throw new IllegalStateException("Iterator setValue() can only be
called after next() and before remove()");
}
- if (map.maps[1].containsKey(value) &&
- map.maps[1].get(value) != last.getKey()) {
+ if (parent.maps[1].containsKey(value) &&
+ parent.maps[1].get(value) != last.getKey()) {
throw new IllegalArgumentException("Cannot use setValue() when the
object being set is already in the map");
}
- return map.put(last.getKey(), value);
+ return parent.put(last.getKey(), value);
}
public void reset() {
- iterator = new ArrayList(map.entrySet()).listIterator();
+ iterator = new ArrayList(parent.entrySet()).listIterator();
last = null;
}
1.4 +61 -52
jakarta-commons/collections/src/java/org/apache/commons/collections/map/AbstractHashedMap.java
Index: AbstractHashedMap.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/map/AbstractHashedMap.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- AbstractHashedMap.java 28 Dec 2003 22:44:18 -0000 1.3
+++ AbstractHashedMap.java 29 Dec 2003 00:38:08 -0000 1.4
@@ -714,8 +714,8 @@
*/
protected static class HashMapIterator extends HashIterator implements
MapIterator {
- HashMapIterator(AbstractHashedMap map) {
- super(map);
+ protected HashMapIterator(AbstractHashedMap parent) {
+ super(parent);
}
public Object next() {
@@ -781,24 +781,25 @@
* EntrySet implementation.
*/
protected static class EntrySet extends AbstractSet {
- private final AbstractHashedMap map;
+ /** The parent map */
+ protected final AbstractHashedMap parent;
- EntrySet(AbstractHashedMap map) {
+ protected EntrySet(AbstractHashedMap parent) {
super();
- this.map = map;
+ this.parent = parent;
}
public int size() {
- return map.size();
+ return parent.size();
}
public void clear() {
- map.clear();
+ parent.clear();
}
public boolean contains(Object entry) {
if (entry instanceof Map.Entry) {
- return map.containsKey(((Map.Entry) entry).getKey());
+ return parent.containsKey(((Map.Entry) entry).getKey());
}
return false;
}
@@ -809,13 +810,13 @@
}
Map.Entry entry = (Map.Entry) obj;
Object key = entry.getKey();
- boolean result = map.containsKey(key);
- map.remove(key);
+ boolean result = parent.containsKey(key);
+ parent.remove(key);
return result;
}
public Iterator iterator() {
- return map.createEntrySetIterator();
+ return parent.createEntrySetIterator();
}
}
@@ -824,8 +825,8 @@
*/
protected static class EntrySetIterator extends HashIterator {
- EntrySetIterator(AbstractHashedMap map) {
- super(map);
+ protected EntrySetIterator(AbstractHashedMap parent) {
+ super(parent);
}
public Object next() {
@@ -865,33 +866,34 @@
* KeySet implementation.
*/
protected static class KeySet extends AbstractSet {
- private final AbstractHashedMap map;
+ /** The parent map */
+ protected final AbstractHashedMap parent;
- KeySet(AbstractHashedMap map) {
+ protected KeySet(AbstractHashedMap parent) {
super();
- this.map = map;
+ this.parent = parent;
}
public int size() {
- return map.size();
+ return parent.size();
}
public void clear() {
- map.clear();
+ parent.clear();
}
public boolean contains(Object key) {
- return map.containsKey(key);
+ return parent.containsKey(key);
}
public boolean remove(Object key) {
- boolean result = map.containsKey(key);
- map.remove(key);
+ boolean result = parent.containsKey(key);
+ parent.remove(key);
return result;
}
public Iterator iterator() {
- return map.createKeySetIterator();
+ return parent.createKeySetIterator();
}
}
@@ -900,8 +902,8 @@
*/
protected static class KeySetIterator extends EntrySetIterator {
- KeySetIterator(AbstractHashedMap map) {
- super(map);
+ protected KeySetIterator(AbstractHashedMap parent) {
+ super(parent);
}
public Object next() {
@@ -941,27 +943,28 @@
* Values implementation.
*/
protected static class Values extends AbstractCollection {
- private final AbstractHashedMap map;
+ /** The parent map */
+ protected final AbstractHashedMap parent;
- Values(AbstractHashedMap map) {
+ protected Values(AbstractHashedMap parent) {
super();
- this.map = map;
+ this.parent = parent;
}
public int size() {
- return map.size();
+ return parent.size();
}
public void clear() {
- map.clear();
+ parent.clear();
}
public boolean contains(Object value) {
- return map.containsValue(value);
+ return parent.containsValue(value);
}
public Iterator iterator() {
- return map.createValuesIterator();
+ return parent.createValuesIterator();
}
}
@@ -970,8 +973,8 @@
*/
protected static class ValuesIterator extends HashIterator {
- ValuesIterator(AbstractHashedMap map) {
- super(map);
+ protected ValuesIterator(AbstractHashedMap parent) {
+ super(parent);
}
public Object next() {
@@ -1042,16 +1045,22 @@
* Base Iterator
*/
protected static abstract class HashIterator implements Iterator {
- protected final AbstractHashedMap map;
+
+ /** The parent map */
+ protected final AbstractHashedMap parent;
+ /** The current index into the array of buckets */
protected int hashIndex;
- protected HashEntry current;
+ /** The last returned entry */
+ protected HashEntry last;
+ /** The next entry */
protected HashEntry next;
+ /** The modification count expected */
protected int expectedModCount;
- protected HashIterator(AbstractHashedMap map) {
+ protected HashIterator(AbstractHashedMap parent) {
super();
- this.map = map;
- HashEntry[] data = map.data;
+ this.parent = parent;
+ HashEntry[] data = parent.data;
int i = data.length;
HashEntry next = null;
while (i > 0 && next == null) {
@@ -1059,7 +1068,7 @@
}
this.next = next;
this.hashIndex = i;
- this.expectedModCount = map.modCount;
+ this.expectedModCount = parent.modCount;
}
public boolean hasNext() {
@@ -1067,14 +1076,14 @@
}
protected HashEntry nextEntry() {
- if (map.modCount != expectedModCount) {
+ if (parent.modCount != expectedModCount) {
throw new ConcurrentModificationException();
}
HashEntry newCurrent = next;
if (newCurrent == null) {
throw new NoSuchElementException(AbstractHashedMap.NO_NEXT_ENTRY);
}
- HashEntry[] data = map.data;
+ HashEntry[] data = parent.data;
int i = hashIndex;
HashEntry n = newCurrent.next;
while (n == null && i > 0) {
@@ -1082,29 +1091,29 @@
}
next = n;
hashIndex = i;
- current = newCurrent;
+ last = newCurrent;
return newCurrent;
}
protected HashEntry currentEntry() {
- return current;
+ return last;
}
public void remove() {
- if (current == null) {
+ if (last == null) {
throw new IllegalStateException(AbstractHashedMap.REMOVE_INVALID);
}
- if (map.modCount != expectedModCount) {
+ if (parent.modCount != expectedModCount) {
throw new ConcurrentModificationException();
}
- map.remove(current.getKey());
- current = null;
- expectedModCount = map.modCount;
+ parent.remove(last.getKey());
+ last = null;
+ expectedModCount = parent.modCount;
}
public String toString() {
- if (current != null) {
- return "Iterator[" + current.getKey() + "=" + current.getValue() +
"]";
+ if (last != null) {
+ return "Iterator[" + last.getKey() + "=" + last.getValue() + "]";
} else {
return "Iterator[]";
}
1.5 +36 -36
jakarta-commons/collections/src/java/org/apache/commons/collections/map/AbstractLinkedMap.java
Index: AbstractLinkedMap.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/map/AbstractLinkedMap.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- AbstractLinkedMap.java 28 Dec 2003 22:53:28 -0000 1.4
+++ AbstractLinkedMap.java 29 Dec 2003 00:38:08 -0000 1.5
@@ -375,8 +375,8 @@
*/
protected static class LinkMapIterator extends LinkIterator implements
OrderedMapIterator {
- LinkMapIterator(AbstractLinkedMap map) {
- super(map);
+ protected LinkMapIterator(AbstractLinkedMap parent) {
+ super(parent);
}
public Object next() {
@@ -431,8 +431,8 @@
*/
protected static class EntrySetIterator extends LinkIterator {
- EntrySetIterator(AbstractLinkedMap map) {
- super(map);
+ protected EntrySetIterator(AbstractLinkedMap parent) {
+ super(parent);
}
public Object next() {
@@ -463,8 +463,8 @@
*/
protected static class KeySetIterator extends EntrySetIterator {
- KeySetIterator(AbstractLinkedMap map) {
- super(map);
+ protected KeySetIterator(AbstractLinkedMap parent) {
+ super(parent);
}
public Object next() {
@@ -495,8 +495,8 @@
*/
protected static class ValuesIterator extends LinkIterator {
- ValuesIterator(AbstractLinkedMap map) {
- super(map);
+ protected ValuesIterator(AbstractLinkedMap parent) {
+ super(parent);
}
public Object next() {
@@ -539,78 +539,78 @@
implements OrderedIterator, ResettableIterator {
/** The parent map */
- protected final AbstractLinkedMap map;
+ protected final AbstractLinkedMap parent;
/** The current (last returned) entry */
- protected LinkEntry current;
+ protected LinkEntry last;
/** The next entry */
protected LinkEntry next;
/** The modification count expected */
protected int expectedModCount;
- protected LinkIterator(AbstractLinkedMap map) {
+ protected LinkIterator(AbstractLinkedMap parent) {
super();
- this.map = map;
- this.next = map.header.after;
- this.expectedModCount = map.modCount;
+ this.parent = parent;
+ this.next = parent.header.after;
+ this.expectedModCount = parent.modCount;
}
public boolean hasNext() {
- return (next != map.header);
+ return (next != parent.header);
}
public boolean hasPrevious() {
- return (next.before != map.header);
+ return (next.before != parent.header);
}
protected LinkEntry nextEntry() {
- if (map.modCount != expectedModCount) {
+ if (parent.modCount != expectedModCount) {
throw new ConcurrentModificationException();
}
- if (next == map.header) {
+ if (next == parent.header) {
throw new NoSuchElementException(AbstractHashedMap.NO_NEXT_ENTRY);
}
- current = next;
+ last = next;
next = next.after;
- return current;
+ return last;
}
protected LinkEntry previousEntry() {
- if (map.modCount != expectedModCount) {
+ if (parent.modCount != expectedModCount) {
throw new ConcurrentModificationException();
}
LinkEntry previous = next.before;
- if (previous == map.header) {
+ if (previous == parent.header) {
throw new
NoSuchElementException(AbstractHashedMap.NO_PREVIOUS_ENTRY);
}
next = previous;
- current = previous;
- return current;
+ last = previous;
+ return last;
}
protected LinkEntry currentEntry() {
- return current;
+ return last;
}
public void remove() {
- if (current == null) {
+ if (last == null) {
throw new IllegalStateException(AbstractHashedMap.REMOVE_INVALID);
}
- if (map.modCount != expectedModCount) {
+ if (parent.modCount != expectedModCount) {
throw new ConcurrentModificationException();
}
- map.remove(current.getKey());
- current = null;
- expectedModCount = map.modCount;
+ parent.remove(last.getKey());
+ last = null;
+ expectedModCount = parent.modCount;
}
public void reset() {
- current = null;
- next = map.header.after;
+ last = null;
+ next = parent.header.after;
}
public String toString() {
- if (current != null) {
- return "Iterator[" + current.getKey() + "=" + current.getValue() +
"]";
+ if (last != null) {
+ return "Iterator[" + last.getKey() + "=" + last.getValue() + "]";
} else {
return "Iterator[]";
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]