fixes for java.util.Vector

Patrick Tullmann tullmann at cs.utah.edu
Mon May 8 16:33:55 PDT 2000


Here are some fixes for java.util.Vector so that a Vector can be used
through the AbstractList interface.  I just added add() and set(),
which was enough to get an app I'm using to work on Kaffe.  

(I didn't realize how gross Vector had become when they retrofitted
java.util.AbstractList onto it... most methods are duplicated in the
new Vector.)

-Pat

----- ----- ---- ---  ---  --   -    -      -         -               -
Pat Tullmann                                       tullmann at cs.utah.edu
	    He who dies with the most toys is still dead.

Index: libraries/javalib/java/util/Vector.java
===================================================================
RCS file: /cvs/kaffe/kaffe/libraries/javalib/java/util/Vector.java,v
retrieving revision 1.15
diff -u -r1.15 Vector.java
--- libraries/javalib/java/util/Vector.java	1999/09/23 18:15:38	1.15
+++ libraries/javalib/java/util/Vector.java	2000/05/08 23:31:53
@@ -172,6 +172,15 @@
 	return (-1);
 }
 
+public void add ( Object obj, int index) {
+	insertElementAt(obj, index);
+}
+
+public boolean add ( Object obj ) {
+	insertElementAt(obj, size());
+	return true;
+}
+
 public synchronized void insertElementAt ( Object obj, int index ) {
 
 	if ( elementCount == elementData.length ) {
@@ -248,12 +257,20 @@
 	elementData[elementCount] = null;
 }
 
-public synchronized void setElementAt(Object obj, int index)
-	{
-	if (index >= elementCount) {
+public Object set ( int index, Object obj ) {
+	Object old;
+
+	if ((index >= elementCount) || (index < 0)) {
 		throw new ArrayIndexOutOfBoundsException();
 	}
+	old = elementData[index];
 	elementData[index] = obj;
+
+	return old;
+}
+	
+public synchronized void setElementAt(Object obj, int index) {
+	set(index, obj);
 }
 
 public synchronized void setSize(int newSize) {


More information about the kaffe mailing list