diff --git a/classpath/java/util/ArrayList.java b/classpath/java/util/ArrayList.java index 31e3dd5f58..faabdebb5c 100644 --- a/classpath/java/util/ArrayList.java +++ b/classpath/java/util/ArrayList.java @@ -94,7 +94,7 @@ public class ArrayList extends AbstractList { return true; } - public int indexOf(T element) { + public int indexOf(Object element) { for (int i = 0; i < size; ++i) { if (equal(element, array[i])) { return i; @@ -103,8 +103,8 @@ public class ArrayList extends AbstractList { return -1; } - public int lastIndexOf(T element) { - for (int i = size; i >= 0; --i) { + public int lastIndexOf(Object element) { + for (int i = size - 1; i >= 0; --i) { if (equal(element, array[i])) { return i; } diff --git a/classpath/java/util/Arrays.java b/classpath/java/util/Arrays.java index 129b5f5528..2fe49fbc67 100644 --- a/classpath/java/util/Arrays.java +++ b/classpath/java/util/Arrays.java @@ -73,6 +73,24 @@ public class Arrays { return false; } + public int indexOf(Object element) { + for (int i = 0; i < array.length; ++i) { + if (equal(element, array[i])) { + return i; + } + } + return -1; + } + + public int lastIndexOf(Object element) { + for (int i = array.length - 1; i >= 0; --i) { + if (equal(element, array[i])) { + return i; + } + } + return -1; + } + public T get(int index) { return array[index]; } diff --git a/classpath/java/util/LinkedList.java b/classpath/java/util/LinkedList.java index a437534363..55bc80fed9 100644 --- a/classpath/java/util/LinkedList.java +++ b/classpath/java/util/LinkedList.java @@ -93,6 +93,28 @@ public class LinkedList extends AbstractSequentialList { return find(element) != null; } + public int indexOf(Object element) { + int i = 0; + for (Cell c = front; c != null; c = c.next) { + if (equal(c.value, element)) { + return i; + } + ++ i; + } + return -1; + } + + public int lastIndexOf(Object element) { + int i = size; + for (Cell c = rear; c != null; c = c.prev) { + -- i; + if (equal(c.value, element)) { + return i; + } + } + return -1; + } + public boolean add(T element) { addLast(element); return true; diff --git a/classpath/java/util/List.java b/classpath/java/util/List.java index b9e5735edb..487ebc18d1 100644 --- a/classpath/java/util/List.java +++ b/classpath/java/util/List.java @@ -21,6 +21,10 @@ public interface List extends Collection { public void add(int index, T element); + public int indexOf(Object value); + + public int lastIndexOf(Object value); + public boolean isEmpty(); public ListIterator listIterator(int index); diff --git a/classpath/java/util/Vector.java b/classpath/java/util/Vector.java index 4364c58281..c23a4d59fd 100644 --- a/classpath/java/util/Vector.java +++ b/classpath/java/util/Vector.java @@ -93,11 +93,11 @@ public class Vector extends AbstractList { list.clear(); } - public synchronized int indexOf(T element) { + public synchronized int indexOf(Object element) { return list.indexOf(element); } - public synchronized int lastIndexOf(T element) { + public synchronized int lastIndexOf(Object element) { return list.lastIndexOf(element); }