Unify the variable names across implementations

git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@131470 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Stephen Colebourne 2003-12-29 00:38:08 +00:00
parent 9fea39c078
commit 5f7c041ae0
6 changed files with 231 additions and 472 deletions

View File

@ -1,5 +1,5 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/bidimap/AbstractDualBidiMap.java,v 1.5 2003/12/14 12:59:38 scolebourne Exp $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/bidimap/AbstractDualBidiMap.java,v 1.6 2003/12/29 00:38:08 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@ -76,7 +76,7 @@ import org.apache.commons.collections.keyvalue.AbstractMapEntryDecorator;
* <code>createMap</code> method.
*
* @since Commons Collections 3.0
* @version $Id: AbstractDualBidiMap.java,v 1.5 2003/12/14 12:59:38 scolebourne Exp $
* @version $Id: AbstractDualBidiMap.java,v 1.6 2003/12/29 00:38:08 scolebourne Exp $
*
* @author Matthew Hawthorne
* @author Stephen Colebourne
@ -296,15 +296,16 @@ public abstract class AbstractDualBidiMap implements BidiMap {
*/
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 abstract class AbstractDualBidiMap implements BidiMap {
}
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 abstract class AbstractDualBidiMap implements BidiMap {
}
public void clear() {
map.clear();
parent.clear();
}
}
@ -348,22 +349,22 @@ public abstract class AbstractDualBidiMap implements BidiMap {
*/
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 @@ public abstract class AbstractDualBidiMap implements BidiMap {
*/
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 @@ public abstract class AbstractDualBidiMap implements BidiMap {
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 @@ public abstract class AbstractDualBidiMap implements BidiMap {
*/
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 @@ public abstract class AbstractDualBidiMap implements BidiMap {
*/
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 @@ public abstract class AbstractDualBidiMap implements BidiMap {
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 @@ public abstract class AbstractDualBidiMap implements BidiMap {
*/
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 @@ public abstract class AbstractDualBidiMap implements BidiMap {
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 @@ public abstract class AbstractDualBidiMap implements BidiMap {
*/
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 @@ public abstract class AbstractDualBidiMap implements BidiMap {
// 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 @@ public abstract class AbstractDualBidiMap implements BidiMap {
* 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 @@ public abstract class AbstractDualBidiMap implements BidiMap {
*/
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 @@ public abstract class AbstractDualBidiMap implements BidiMap {
// 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 @@ public abstract class AbstractDualBidiMap implements BidiMap {
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;
}

View File

@ -1,5 +1,5 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/bidimap/DualTreeBidiMap.java,v 1.6 2003/12/25 00:33:04 scolebourne Exp $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/bidimap/DualTreeBidiMap.java,v 1.7 2003/12/29 00:38:08 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@ -88,7 +88,7 @@ import org.apache.commons.collections.map.AbstractSortedMapDecorator;
* not store each object twice, which can save on memory use.
*
* @since Commons Collections 3.0
* @version $Id: DualTreeBidiMap.java,v 1.6 2003/12/25 00:33:04 scolebourne Exp $
* @version $Id: DualTreeBidiMap.java,v 1.7 2003/12/29 00:38:08 scolebourne Exp $
*
* @author Matthew Hawthorne
* @author Stephen Colebourne
@ -289,14 +289,17 @@ public class DualTreeBidiMap extends AbstractDualBidiMap implements SortedBidiMa
*/
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 class DualTreeBidiMap extends AbstractDualBidiMap implements SortedBidiMa
public void remove() {
iterator.remove();
map.remove(last.getKey());
parent.remove(last.getKey());
last = null;
}
@ -341,15 +344,15 @@ public class DualTreeBidiMap extends AbstractDualBidiMap implements SortedBidiMa
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;
}

View File

@ -1,5 +1,5 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/list/AbstractLinkedList.java,v 1.3 2003/12/28 17:58:54 scolebourne Exp $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/list/AbstractLinkedList.java,v 1.4 2003/12/29 00:38:08 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@ -80,7 +80,7 @@ import org.apache.commons.collections.OrderedIterator;
* is here.
*
* @since Commons Collections 3.0
* @version $Revision: 1.3 $ $Date: 2003/12/28 17:58:54 $
* @version $Revision: 1.4 $ $Date: 2003/12/29 00:38:08 $
*
* @author Rich Dougherty
* @author Phil Steitz
@ -681,7 +681,7 @@ public abstract class AbstractLinkedList implements List {
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 {@link #next()}. If this is equal
@ -718,11 +718,11 @@ public abstract class AbstractLinkedList implements List {
* @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 @@ public abstract class AbstractLinkedList implements List {
* 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 abstract class AbstractLinkedList implements List {
}
public boolean hasNext() {
return next != list.header;
return next != parent.header;
}
public Object next() {
@ -771,7 +771,7 @@ public abstract class AbstractLinkedList implements List {
}
public boolean hasPrevious() {
return next.previous != list.header;
return next.previous != parent.header;
}
public Object previous() {
@ -797,7 +797,7 @@ public abstract class AbstractLinkedList implements List {
public void remove() {
checkModCount();
list.removeNode(getLastNodeReturned());
parent.removeNode(getLastNodeReturned());
current = null;
nextIndex--;
expectedModCount++;
@ -810,7 +810,7 @@ public abstract class AbstractLinkedList implements List {
public void add(Object obj) {
checkModCount();
list.addNodeBefore(next, obj);
parent.addNodeBefore(next, obj);
current = null;
nextIndex++;
expectedModCount++;
@ -828,7 +828,7 @@ public abstract class AbstractLinkedList implements List {
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 abstract class AbstractLinkedList implements List {
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 @@ public abstract class AbstractLinkedList implements List {
*/
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 @@ public abstract class AbstractLinkedList implements List {
/** 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 abstract class AbstractLinkedList implements List {
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 abstract class AbstractLinkedList implements List {
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 @@ public abstract class AbstractLinkedList implements List {
}
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 abstract class AbstractLinkedList implements List {
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 abstract class AbstractLinkedList implements List {
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 @@ public abstract class AbstractLinkedList implements List {
}
protected void checkModCount() {
if (list.modCount != expectedModCount) {
if (parent.modCount != expectedModCount) {
throw new ConcurrentModificationException();
}
}

View File

@ -1,5 +1,5 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/list/CursorableLinkedList.java,v 1.1 2003/12/24 01:15:40 scolebourne Exp $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/list/CursorableLinkedList.java,v 1.2 2003/12/29 00:38:08 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@ -94,7 +94,7 @@ import java.util.ListIterator;
*
* @see java.util.LinkedList
* @since Commons Collections 1.0
* @version $Revision: 1.1 $ $Date: 2003/12/24 01:15:40 $
* @version $Revision: 1.2 $ $Date: 2003/12/29 00:38:08 $
*
* @author Rodney Waldhoff
* @author Janek Bogucki
@ -456,11 +456,11 @@ public class CursorableLinkedList extends AbstractLinkedList implements Serializ
*/
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 class CursorableLinkedList extends AbstractLinkedList implements Serializ
*/
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 {@link 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 {@link 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
// * {@link 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;
//
//}

View File

@ -1,5 +1,5 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/map/AbstractHashedMap.java,v 1.3 2003/12/28 22:44:18 scolebourne Exp $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/map/AbstractHashedMap.java,v 1.4 2003/12/29 00:38:08 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@ -88,7 +88,7 @@ import org.apache.commons.collections.MapIterator;
* need for unusual subclasses is here.
*
* @since Commons Collections 3.0
* @version $Revision: 1.3 $ $Date: 2003/12/28 22:44:18 $
* @version $Revision: 1.4 $ $Date: 2003/12/29 00:38:08 $
*
* @author java util HashMap
* @author Stephen Colebourne
@ -714,8 +714,8 @@ public class AbstractHashedMap implements IterableMap {
*/
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 @@ public class AbstractHashedMap implements IterableMap {
* 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 @@ public class AbstractHashedMap implements IterableMap {
}
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 @@ public class AbstractHashedMap implements IterableMap {
*/
protected static class EntrySetIterator extends HashIterator {
EntrySetIterator(AbstractHashedMap map) {
super(map);
protected EntrySetIterator(AbstractHashedMap parent) {
super(parent);
}
public Object next() {
@ -865,33 +866,34 @@ public class AbstractHashedMap implements IterableMap {
* 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 @@ public class AbstractHashedMap implements IterableMap {
*/
protected static class KeySetIterator extends EntrySetIterator {
KeySetIterator(AbstractHashedMap map) {
super(map);
protected KeySetIterator(AbstractHashedMap parent) {
super(parent);
}
public Object next() {
@ -941,27 +943,28 @@ public class AbstractHashedMap implements IterableMap {
* 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 @@ public class AbstractHashedMap implements IterableMap {
*/
protected static class ValuesIterator extends HashIterator {
ValuesIterator(AbstractHashedMap map) {
super(map);
protected ValuesIterator(AbstractHashedMap parent) {
super(parent);
}
public Object next() {
@ -1042,16 +1045,22 @@ public class AbstractHashedMap implements IterableMap {
* 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 @@ public class AbstractHashedMap implements IterableMap {
}
this.next = next;
this.hashIndex = i;
this.expectedModCount = map.modCount;
this.expectedModCount = parent.modCount;
}
public boolean hasNext() {
@ -1067,14 +1076,14 @@ public class AbstractHashedMap implements IterableMap {
}
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 @@ public class AbstractHashedMap implements IterableMap {
}
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[]";
}

View File

@ -1,5 +1,5 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/map/AbstractLinkedMap.java,v 1.4 2003/12/28 22:53:28 scolebourne Exp $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/map/AbstractLinkedMap.java,v 1.5 2003/12/29 00:38:08 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@ -98,7 +98,7 @@ import org.apache.commons.collections.ResettableIterator;
* methods exposed.
*
* @since Commons Collections 3.0
* @version $Revision: 1.4 $ $Date: 2003/12/28 22:53:28 $
* @version $Revision: 1.5 $ $Date: 2003/12/29 00:38:08 $
*
* @author java util LinkedHashMap
* @author Stephen Colebourne
@ -375,8 +375,8 @@ public class AbstractLinkedMap extends AbstractHashedMap implements OrderedMap {
*/
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 @@ public class AbstractLinkedMap extends AbstractHashedMap implements OrderedMap {
*/
protected static class EntrySetIterator extends LinkIterator {
EntrySetIterator(AbstractLinkedMap map) {
super(map);
protected EntrySetIterator(AbstractLinkedMap parent) {
super(parent);
}
public Object next() {
@ -463,8 +463,8 @@ public class AbstractLinkedMap extends AbstractHashedMap implements OrderedMap {
*/
protected static class KeySetIterator extends EntrySetIterator {
KeySetIterator(AbstractLinkedMap map) {
super(map);
protected KeySetIterator(AbstractLinkedMap parent) {
super(parent);
}
public Object next() {
@ -495,8 +495,8 @@ public class AbstractLinkedMap extends AbstractHashedMap implements OrderedMap {
*/
protected static class ValuesIterator extends LinkIterator {
ValuesIterator(AbstractLinkedMap map) {
super(map);
protected ValuesIterator(AbstractLinkedMap parent) {
super(parent);
}
public Object next() {
@ -539,78 +539,78 @@ public class AbstractLinkedMap extends AbstractHashedMap implements OrderedMap {
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[]";
}