Unify exception messages across map implementations

git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@131414 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Stephen Colebourne 2003-12-06 14:02:11 +00:00
parent 5f8fc2f974
commit 570ddedd98
4 changed files with 44 additions and 37 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/map/Flat3Map.java,v 1.6 2003/12/03 19:03:50 scolebourne Exp $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/map/Flat3Map.java,v 1.7 2003/12/06 14:02:11 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@ -98,7 +98,7 @@ import org.apache.commons.collections.ResettableIterator;
* Do not use <code>Flat3Map</code> if the size is likely to grow beyond 3.
*
* @since Commons Collections 3.0
* @version $Revision: 1.6 $ $Date: 2003/12/03 19:03:50 $
* @version $Revision: 1.7 $ $Date: 2003/12/06 14:02:11 $
*
* @author Stephen Colebourne
*/
@ -609,7 +609,7 @@ public class Flat3Map implements IterableMap {
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 class Flat3Map implements IterableMap {
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 class Flat3Map implements IterableMap {
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 class Flat3Map implements IterableMap {
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 class Flat3Map implements IterableMap {
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 class Flat3Map implements IterableMap {
public String toString() {
if (iCanRemove) {
return "MapIterator[" + getKey() + "=" + getValue() + "]";
return "Iterator[" + getKey() + "=" + getValue() + "]";
} else {
return "MapIterator[]";
return "Iterator[]";
}
}
}
@ -761,7 +761,7 @@ public class Flat3Map implements IterableMap {
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 class Flat3Map implements IterableMap {
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 class Flat3Map implements IterableMap {
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 class Flat3Map implements IterableMap {
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 class Flat3Map implements IterableMap {
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) {

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/HashedMap.java,v 1.6 2003/12/06 13:03:15 scolebourne Exp $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/map/HashedMap.java,v 1.7 2003/12/06 14:02:11 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@ -87,13 +87,20 @@ import org.apache.commons.collections.MapIterator;
* methods exposed.
*
* @since Commons Collections 3.0
* @version $Revision: 1.6 $ $Date: 2003/12/06 13:03:15 $
* @version $Revision: 1.7 $ $Date: 2003/12/06 14:02:11 $
*
* @author java util HashMap
* @author Stephen Colebourne
*/
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 class HashedMap implements IterableMap, Serializable, Cloneable {
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 class HashedMap implements IterableMap, Serializable, Cloneable {
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 class HashedMap implements IterableMap, Serializable, Cloneable {
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 @@ public class HashedMap implements IterableMap, Serializable, Cloneable {
}
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 class HashedMap implements IterableMap, Serializable, Cloneable {
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();

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/LinkedMap.java,v 1.1 2003/12/03 19:04:41 scolebourne Exp $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/map/LinkedMap.java,v 1.2 2003/12/06 14:02:11 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@ -86,7 +86,7 @@ import org.apache.commons.collections.ResettableIterator;
* <code>ResettableIterator</code> and calling <code>reset()</code>.
*
* @since Commons Collections 3.0
* @version $Revision: 1.1 $ $Date: 2003/12/03 19:04:41 $
* @version $Revision: 1.2 $ $Date: 2003/12/06 14:02:11 $
*
* @author java util LinkedHashMap
* @author Stephen Colebourne
@ -324,7 +324,7 @@ public class LinkedMap extends HashedMap implements OrderedMap {
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 class LinkedMap extends HashedMap implements OrderedMap {
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 class LinkedMap extends HashedMap implements OrderedMap {
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 @@ public class LinkedMap extends HashedMap implements OrderedMap {
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 @@ public class LinkedMap extends HashedMap implements OrderedMap {
}
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 class LinkedMap extends HashedMap implements OrderedMap {
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();

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/ListOrderedMap.java,v 1.6 2003/12/05 20:23:57 scolebourne Exp $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/map/ListOrderedMap.java,v 1.7 2003/12/06 14:02:11 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@ -87,7 +87,7 @@ import org.apache.commons.collections.keyvalue.AbstractMapEntry;
* original position in the iteration.
*
* @since Commons Collections 3.0
* @version $Revision: 1.6 $ $Date: 2003/12/05 20:23:57 $
* @version $Revision: 1.7 $ $Date: 2003/12/06 14:02:11 $
*
* @author Henri Yandell
* @author Stephen Colebourne
@ -466,7 +466,7 @@ public class ListOrderedMap extends AbstractMapDecorator implements OrderedMap {
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 class ListOrderedMap extends AbstractMapDecorator implements OrderedMap {
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 class ListOrderedMap extends AbstractMapDecorator implements OrderedMap {
public String toString() {
if (readable == true) {
return "MapIterator[" + getKey() + "=" + getValue() + "]";
return "Iterator[" + getKey() + "=" + getValue() + "]";
} else {
return "MapIterator[]";
return "Iterator[]";
}
}
}