summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Tromey <tromey@redhat.com>2006-07-21 22:41:52 +0000
committerTom Tromey <tromey@redhat.com>2006-07-21 22:41:52 +0000
commitee82dd6eae151a860dff851492809c46b3818796 (patch)
tree99c43bf9af5fcd7ac50d072b46604509c7277418
parent70d3ca5f03432c9893f4231b9037138e2c5f79d4 (diff)
downloadclasspath-ee82dd6eae151a860dff851492809c46b3818796.tar.gz
2006-07-21 Carsten Neumann <cn-develop@gmx.net>
* java/util/CopyOnWriteArrayList.java (indexOf(E, int)): New method. (lastIndexOf(E, int)): Likewise. (add(E)): Increase the size of newData array by one. (add(int, E)): Likewise.
-rw-r--r--ChangeLog7
-rw-r--r--java/util/concurrent/CopyOnWriteArrayList.java42
2 files changed, 47 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index f84cf6c06..0bdf06ee4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2006-07-21 Carsten Neumann <cn-develop@gmx.net>
+
+ * java/util/CopyOnWriteArrayList.java (indexOf(E, int)): New method.
+ (lastIndexOf(E, int)): Likewise.
+ (add(E)): Increase the size of newData array by one.
+ (add(int, E)): Likewise.
+
2006-07-16 Andrew John Hughes <gnu_andrew@member.fsf.org>
* javax/management/MBeanInfo.java:
diff --git a/java/util/concurrent/CopyOnWriteArrayList.java b/java/util/concurrent/CopyOnWriteArrayList.java
index ee9f7ac3a..d116a0edc 100644
--- a/java/util/concurrent/CopyOnWriteArrayList.java
+++ b/java/util/concurrent/CopyOnWriteArrayList.java
@@ -133,6 +133,25 @@ public class CopyOnWriteArrayList<E> extends AbstractList<E> implements
}
/**
+ * Return the lowest index greater equal <code>index</code> at which
+ * <code>e</code> appears in this List, or -1 if it does not
+ * appear.
+ *
+ * @param e the element whose inclusion in the list is being tested
+ * @param index the index at which the search begins
+ * @return the index where <code>e</code> was found
+ */
+ public int indexOf(E e, int index)
+ {
+ E[] data = this.data;
+
+ for (int i = index; i < data.length; i++)
+ if (equals(e, data[i]))
+ return i;
+ return -1;
+ }
+
+ /**
* Returns the highest index at which element appears in this List, or -1 if
* it does not appear.
*
@@ -150,6 +169,25 @@ public class CopyOnWriteArrayList<E> extends AbstractList<E> implements
}
/**
+ * Returns the highest index lesser equal <code>index</code> at
+ * which <code>e</code> appears in this List, or -1 if it does not
+ * appear.
+ *
+ * @param e the element whose inclusion in the list is being tested
+ * @param index the index at which the search begins
+ * @return the index where <code>e</code> was found
+ */
+ public int lastIndexOf(E e, int index)
+ {
+ E[] data = this.data;
+
+ for (int i = index; i >= 0; i--)
+ if (equals(e, data[i]))
+ return i;
+ return -1;
+ }
+
+ /**
* Creates a shallow copy of this ArrayList (elements are not cloned).
*
* @return the cloned object
@@ -255,7 +293,7 @@ public class CopyOnWriteArrayList<E> extends AbstractList<E> implements
public synchronized boolean add(E e)
{
E[] data = this.data;
- E[] newData = (E[]) new Object[data.length];
+ E[] newData = (E[]) new Object[data.length + 1];
System.arraycopy(data, 0, newData, 0, data.length);
newData[data.length] = e;
this.data = newData;
@@ -277,7 +315,7 @@ public class CopyOnWriteArrayList<E> extends AbstractList<E> implements
public synchronized void add(int index, E e)
{
E[] data = this.data;
- E[] newData = (E[]) new Object[data.length];
+ E[] newData = (E[]) new Object[data.length + 1];
System.arraycopy(data, 0, newData, 0, index);
newData[index] = e;
System.arraycopy(data, index, newData, index + 1, data.length - index);