scolebourne 2003/12/06 06:02:11 Modified: collections/src/java/org/apache/commons/collections/map HashedMap.java ListOrderedMap.java LinkedMap.java Flat3Map.java Log: Unify exception messages across map implementations Revision Changes Path 1.7 +14 -7 jakarta-commons/collections/src/java/org/apache/commons/collections/map/HashedMap.java Index: HashedMap.java =================================================================== RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/map/HashedMap.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- HashedMap.java 6 Dec 2003 13:03:15 -0000 1.6 +++ HashedMap.java 6 Dec 2003 14:02:11 -0000 1.7 @@ -94,6 +94,13 @@ */ public class HashedMap implements IterableMap, Serializable, Cloneable { + protected static final String NO_NEXT_ENTRY = "No next() entry in the iteration"; + protected static final String NO_PREVIOUS_ENTRY = "No previous() entry in the iteration"; + protected static final String REMOVE_INVALID = "remove() can only be called once after next()"; + protected static final String GETKEY_INVALID = "getKey() can only be called after next() and before remove()"; + protected static final String GETVALUE_INVALID = "getValue() can only be called after next() and before remove()"; + protected static final String SETVALUE_INVALID = "setValue() can only be called after next() and before remove()"; + /** Serialisation version */ static final long serialVersionUID = -1593250834999590599L; /** The default capacity to use */ @@ -596,7 +603,7 @@ public Object getKey() { HashEntry current = currentEntry(); if (current == null) { - throw new IllegalStateException("Iterator remove() can only be called once after next()"); + throw new IllegalStateException(HashedMap.GETKEY_INVALID); } return current.getKey(); } @@ -604,7 +611,7 @@ public Object getValue() { HashEntry current = currentEntry(); if (current == null) { - throw new IllegalStateException("Iterator remove() can only be called once after next()"); + throw new IllegalStateException(HashedMap.GETVALUE_INVALID); } return current.getValue(); } @@ -612,7 +619,7 @@ public Object setValue(Object value) { HashEntry current = currentEntry(); if (current == null) { - throw new IllegalStateException("Iterator remove() can only be called once after next()"); + throw new IllegalStateException(HashedMap.SETVALUE_INVALID); } return current.setValue(value); } @@ -933,7 +940,7 @@ } HashEntry newCurrent = next; if (newCurrent == null) { - throw new NoSuchElementException("No more elements in the iteration"); + throw new NoSuchElementException(HashedMap.NO_NEXT_ENTRY); } HashEntry[] data = map.data; int i = hashIndex; @@ -953,7 +960,7 @@ public void remove() { if (current == null) { - throw new IllegalStateException("Iterator remove() can only be called once after next()"); + throw new IllegalStateException(HashedMap.REMOVE_INVALID); } if (map.modCount != expectedModCount) { throw new ConcurrentModificationException(); 1.7 +8 -8 jakarta-commons/collections/src/java/org/apache/commons/collections/map/ListOrderedMap.java Index: ListOrderedMap.java =================================================================== RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/map/ListOrderedMap.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- ListOrderedMap.java 5 Dec 2003 20:23:57 -0000 1.6 +++ ListOrderedMap.java 6 Dec 2003 14:02:11 -0000 1.7 @@ -466,7 +466,7 @@ public void remove() { if (readable == false) { - throw new IllegalStateException("Iterator remove() can only be called after next() and before remove()"); + throw new IllegalStateException(HashedMap.REMOVE_INVALID); } iterator.remove(); parent.map.remove(last); @@ -475,21 +475,21 @@ public Object getKey() { if (readable == false) { - throw new IllegalStateException("Iterator getKey() can only be called after next() and before remove()"); + throw new IllegalStateException(HashedMap.GETKEY_INVALID); } return last; } public Object getValue() { if (readable == false) { - throw new IllegalStateException("Iterator getValue() can only be called after next() and before remove()"); + throw new IllegalStateException(HashedMap.GETVALUE_INVALID); } return parent.get(last); } public Object setValue(Object value) { if (readable == false) { - throw new IllegalStateException("Iterator setValue() can only be called after next() and before remove()"); + throw new IllegalStateException(HashedMap.SETVALUE_INVALID); } return parent.map.put(last, value); } @@ -502,9 +502,9 @@ public String toString() { if (readable == true) { - return "MapIterator[" + getKey() + "=" + getValue() + "]"; + return "Iterator[" + getKey() + "=" + getValue() + "]"; } else { - return "MapIterator[]"; + return "Iterator[]"; } } } 1.2 +8 -8 jakarta-commons/collections/src/java/org/apache/commons/collections/map/LinkedMap.java Index: LinkedMap.java =================================================================== RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/map/LinkedMap.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- LinkedMap.java 3 Dec 2003 19:04:41 -0000 1.1 +++ LinkedMap.java 6 Dec 2003 14:02:11 -0000 1.2 @@ -324,7 +324,7 @@ public Object getKey() { HashEntry current = currentEntry(); if (current == null) { - throw new IllegalStateException("Iterator remove() can only be called once after next()"); + throw new IllegalStateException(HashedMap.GETKEY_INVALID); } return current.getKey(); } @@ -332,7 +332,7 @@ public Object getValue() { HashEntry current = currentEntry(); if (current == null) { - throw new IllegalStateException("Iterator remove() can only be called once after next()"); + throw new IllegalStateException(HashedMap.GETVALUE_INVALID); } return current.getValue(); } @@ -340,7 +340,7 @@ public Object setValue(Object value) { HashEntry current = currentEntry(); if (current == null) { - throw new IllegalStateException("Iterator remove() can only be called once after next()"); + throw new IllegalStateException(HashedMap.SETVALUE_INVALID); } return current.setValue(value); } @@ -487,7 +487,7 @@ throw new ConcurrentModificationException(); } if (next == map.header) { - throw new NoSuchElementException("No more elements in the iteration"); + throw new NoSuchElementException(HashedMap.NO_NEXT_ENTRY); } current = next; next = next.after; @@ -500,7 +500,7 @@ } LinkedEntry previous = next.before; if (previous == map.header) { - throw new NoSuchElementException("No more elements in the iteration"); + throw new NoSuchElementException(HashedMap.NO_PREVIOUS_ENTRY); } next = previous; current = previous; @@ -513,7 +513,7 @@ public void remove() { if (current == null) { - throw new IllegalStateException("Iterator remove() can only be called once after next()"); + throw new IllegalStateException(HashedMap.REMOVE_INVALID); } if (map.modCount != expectedModCount) { throw new ConcurrentModificationException(); 1.7 +14 -14 jakarta-commons/collections/src/java/org/apache/commons/collections/map/Flat3Map.java Index: Flat3Map.java =================================================================== RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/map/Flat3Map.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- Flat3Map.java 3 Dec 2003 19:03:50 -0000 1.6 +++ Flat3Map.java 6 Dec 2003 14:02:11 -0000 1.7 @@ -609,7 +609,7 @@ public Object next() { if (hasNext() == false) { - throw new NoSuchElementException("No more elements in the iteration"); + throw new NoSuchElementException(HashedMap.NO_NEXT_ENTRY); } iCanRemove = true; iIndex++; @@ -618,7 +618,7 @@ public void remove() { if (iCanRemove == false) { - throw new IllegalStateException("Iterator remove() can only be called once after next()"); + throw new IllegalStateException(HashedMap.REMOVE_INVALID); } iFlatMap.remove(getKey()); iIndex--; @@ -627,7 +627,7 @@ public Object getKey() { if (iCanRemove == false) { - throw new IllegalStateException("Map Entry cannot be queried"); + throw new IllegalStateException(HashedMap.GETKEY_INVALID); } switch (iIndex) { case 3: @@ -642,7 +642,7 @@ public Object getValue() { if (iCanRemove == false) { - throw new IllegalStateException("Map Entry cannot be queried"); + throw new IllegalStateException(HashedMap.GETVALUE_INVALID); } switch (iIndex) { case 3: @@ -657,7 +657,7 @@ public Object setValue(Object value) { if (iCanRemove == false) { - throw new IllegalStateException("Map Entry cannot be changed"); + throw new IllegalStateException(HashedMap.SETVALUE_INVALID); } Object old = getValue(); switch (iIndex) { @@ -678,9 +678,9 @@ public String toString() { if (iCanRemove) { - return "MapIterator[" + getKey() + "=" + getValue() + "]"; + return "Iterator[" + getKey() + "=" + getValue() + "]"; } else { - return "MapIterator[]"; + return "Iterator[]"; } } } @@ -761,7 +761,7 @@ public Object next() { if (hasNext() == false) { - throw new NoSuchElementException("No more elements in the iteration"); + throw new NoSuchElementException(HashedMap.NO_NEXT_ENTRY); } iCanRemove = true; iIndex++; @@ -770,7 +770,7 @@ public void remove() { if (iCanRemove == false) { - throw new IllegalStateException("Iterator remove() can only be called once after next()"); + throw new IllegalStateException(HashedMap.REMOVE_INVALID); } iFlatMap.remove(getKey()); iIndex--; @@ -779,7 +779,7 @@ public Object getKey() { if (iCanRemove == false) { - throw new IllegalStateException("Map Entry cannot be queried"); + throw new IllegalStateException(HashedMap.GETKEY_INVALID); } switch (iIndex) { case 3: @@ -794,7 +794,7 @@ public Object getValue() { if (iCanRemove == false) { - throw new IllegalStateException("Map Entry cannot be queried"); + throw new IllegalStateException(HashedMap.GETVALUE_INVALID); } switch (iIndex) { case 3: @@ -809,7 +809,7 @@ public Object setValue(Object value) { if (iCanRemove == false) { - throw new IllegalStateException("Map Entry cannot be changed"); + throw new IllegalStateException(HashedMap.SETVALUE_INVALID); } Object old = getValue(); switch (iIndex) {
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]