diff --git a/src/java/com/samskivert/util/ObserverList.java b/src/java/com/samskivert/util/ObserverList.java index deb8d593..bd6a89ec 100644 --- a/src/java/com/samskivert/util/ObserverList.java +++ b/src/java/com/samskivert/util/ObserverList.java @@ -136,13 +136,13 @@ public class ObserverList extends ArrayList _allowDups = allowDups; } - // documentation inherited + @Override public void add (int index, T element) { throw new UnsupportedOperationException(UNSUPPORTED_ADD_MESSAGE); } - // documentation inherited + @Override public boolean add (T o) { // make sure we're not violating the list constraints @@ -158,18 +158,44 @@ public class ObserverList extends ArrayList } } - // documentation inherited + @Override public boolean addAll (Collection c) { throw new UnsupportedOperationException(UNSUPPORTED_ADD_MESSAGE); } - // documentation inherited + @Override public boolean addAll (int index, Collection c) { throw new UnsupportedOperationException(UNSUPPORTED_ADD_MESSAGE); } + @Override + public int indexOf (Object element) + { + // indexOf and lastIndexOf are implemented using reference equality + // so that contains() also uses reference equality. + for (int ii = 0, nn = size(); ii < nn; ii++) { + if (element == get(ii)) { + return ii; + } + } + return -1; + } + + @Override + public int lastIndexOf (Object element) + { + // indexOf and lastIndexOf are implemented using reference equality + // so that contains() also uses reference equality. + for (int ii = size() - 1; ii >= 0; ii--) { + if (element == get(ii)) { + return ii; + } + } + return -1; + } + /** * Applies the supplied observer operation to all observers in the * list in a manner conforming to the notification ordering policy