Yeah, I was looking through the online stuff and the java.util package is
very close.  There a few classes that are missing.  I hacked out the
remaining interfaces, and also one of the classes.  I've got
java.util.ArrayList in progress now.  I don't know what to do with these, so
I'll post them to the list for now.  And I'll join the list.

Nice to be developing with you.

Daniel ([EMAIL PROTECTED])

> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On Behalf Of Aaron
> M. Renn
> Sent: Saturday, January 30, 1999 1:52 PM
> To: [EMAIL PROTECTED]
> Cc: [EMAIL PROTECTED]
> Subject: Re: classpath dev
>
>
> Daniel Rall wrote:
> > How can I get todo lists for each package?
>
> Hmm, we don't seem to be keeping those.  Brian Jones wrote up a couple
> emails of relevance for java.util.  If he sees this, maybe he can
> point you
> at them.  But I believe that package is almost complete.
>
> Writing up todo's is something we will need to get better at
> going forward.
>
> --
> Aaron M. Renn ([EMAIL PROTECTED]) http://www.urbanophile.com/arenn/
>
/**
*ArrayList.java
*
*@author Daniel Rall (<a href="mailto:[EMAIL PROTECTED]">[EMAIL PROTECTED]</a>, <a href="http://209.146.23.49/">Fine Malt Coding</a>)
*@version 1.0b
*/

/////////////////////////////////////////////////////////////////////////////
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU Library General Public License as published
// by the Free Software Foundation, version 2. (see COPYING.LIB)
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public License
// along with this program; if not, write to the Free Software Foundation
// Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307 USA
/////////////////////////////////////////////////////////////////////////////

package java.util;

import java.io.Serializable;

public class ArrayList extends AbstractList implements List, Cloneable, Serializable
{
	private Object[] data;
	private int length;
	
	/**
	*Constructs an ArrayList with a length of 0.
	*/
	public ArrayList()
	{
		length = 0;
		data = null;
	}

	/**
	*Constructs a list containing the elements of the specified collection, 
	*in the order they are returned by the collection's iterator.
	*
	*@param collection Initial capacity.
	*/
	public ArrayList( Collection collection )
	{
		length = collection.size();
		data = new Object[length];
		
		Iterator iter = collection.iterator();
		int index = 0;
		
		while ( iter.hasNext() )
		{
			data[index++] = iter.next();
		}
	}

	/**
	*Constructs an ArrayList with the specified initial capacity.
	*
	*@param capacity Initial capacity.
	*/
	public ArrayList( int capacity )
	{
		data = new Object[capacity];
	}

	/**
	*Adds an Object at the specified index.  Does not allow duplicates.
	*
	*@para index Index at which to insert the element.
	*@param obj Object to add.
	*@throw IndexOutOfBoundsException
	*/
	public void add( int index, Object obj ) throws IndexOutOfBoundsException
	{
		if ( !contains(obj) )
		{
			ensureCapacity(++length);
			
			for (int n = length - 1; n > index; n--)
				swap( data[n], data[n - 1] );
			data[index] = obj;
		}
	}
	
	/**
	*Adds one Object to the end of this List.  Does not allow duplicates.
	*
	*@param obj Object to add.
	*/
	public boolean add( Object obj )
	{
		if ( !contains(obj) )
		{
			ensureCapacity(++length);
			data[length - 1] = obj;
			
			return true;
		}
		else
			return false;
	}

	/**
	*Adds Objects to the end of this List.  Does not allow duplicates.
	*
	*@param collection Collection to add.
	*/
	public boolean addAll( Collection collection )
	{
		if ( !contains(obj) )
		{
			length += collection.size();
			ensureCapacity(length);
			Iterator iter = collection.iterator();
			
			while ( iter.hasNext() )
				add( iter.next() );
			
			return true;
		}
		else
			return false;
	}
	
	/**
	*Adds Objects to this List at the specified index.  Does not allow duplicates.
	*
	*@param index Index at which to add.
	*@param collection Collection to add.
	*/
	public boolean addAll( int index, Collection collection )
	{
		// TODO
	}
	
	/**
	*Removes all elements from this collection.
	*/
	public void clear()
	{
		for (int n = 0; n < length; n++)
			data[n] = null;
		System.gc();
	}
	
	public Object clone()
	{
		// TODO: Implement last.
		//return new ArrayList();
		return null;
	}
	
	/**
	*Tests to see if an Object is in the List.
	*
	*@param obj Object to seek.
	*/
	public boolean contains( Object obj )
	{
		for (int n = 0; n < data.length; n++)
		{
			if ( data[n] == obj ) return true;
		}
		return false;
	}
	
	/**
	*Makes certain the size of the List is greater than or equal to
	*the specified size.
	*
	*@param min New minimum size.
	*/
	public void ensureCapacity( int min )
	{
		if (min > data.length)
			incrementCapacity(min - data.length);
	}
	
	/**
	*Returns the Object at the specified index.
	*
	*@param index Index of Object to return.
	*@throw IndexOutOfBoundsException
	*/
	public Object get( int index ) throws IndexOutOfBoundsException
	{
		return data[index];
	}
	
	/**
	*Returns the first index of the specified Object (comparison uses equals method).
	*
	*@param obj Object to seek.
	*@return Index of Object or -1 if not found.
	*/
	public int indexOf( Object obj )
	{
		for (int n = 0; n < length; n++)
		{
			if ( obj.equals(data[n]) ) return n;
		}
		return -1;
	}
	
	/**
	*Tests to see if the List is empty.
	*
	*@return Whether or not the List is empty.
	*/
	public boolean isEmpty()
	{
		// Test for emptiness.
		if (data == null) return true;
		if (length == 0) return true;
		
		// Not empty.
		return false;
	}
	
	public int lastIndexOf( Object obj )
	{
		// TODO
		return -1;
	}
	
	public Object remove( int index )
	{
		// TODO
		return null;
	}
	
	protected void removeRange( int indexFrom, int indexTo )
	{
		// TODO
	}
	
	public Object set( int index, Object obj )
	{
		// TODO
		return null;
	}
	
	/**
	*@return The number of elements in the List.
	*/
	public int size() { return length; }
	
	public Object[] toArray()
	{
		// TODO
		return null;
	}
	
	public Object[] toArray( Object[] objects )
	{
		// TODO
		return null;
	}
	
	public void trimToSize()
	{
		// TODO
	}
	
	/**
	*Increases the size of this ArrayList.
	*
	*@param inc Amount to increment.  Defaults is 1.
	*/
	private void incrementCapacity() { incrementCapacity(1); }
	
	private void incrementCapacity( int inc )
	{
		Object[] oldData = data;
		Object[] data = new Object[ oldData.length + inc ];
		
		for (int n = 0; n < data.length; n++)
			data[n] = oldData[n];
		
		// Cleanup old array.
		oldData.finalize();
		System.gc();
	}
	
	private final void swap( Object obj1, Object obj2 )
	{
		Object temp = obj1;
		obj1 = obj2;
		obj2 = temp;
	}
}
/**
*EventListener.java
*
*An interface that all event listener interfaces must extend
*
*@author Daniel Rall (<a href="mailto:[EMAIL PROTECTED]">[EMAIL PROTECTED]</a>)
*@version 1.0b
*/

/////////////////////////////////////////////////////////////////////////////
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU Library General Public License as published
// by the Free Software Foundation, version 2. (see COPYING.LIB)
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public License
// along with this program; if not, write to the Free Software Foundation
// Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307 USA
/////////////////////////////////////////////////////////////////////////////

package java.util;

public abstract interface EventListener {}
/**
*Observable.java
*
*Extended when an object wants to be Observable.
*
*@author Daniel Rall (<a href="mailto:[EMAIL PROTECTED]">[EMAIL PROTECTED]</a>, <a href="http://209.146.23.49/">Fine Malt Coding</a>)
*@version 1.0b
*/

/////////////////////////////////////////////////////////////////////////////
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU Library General Public License as published
// by the Free Software Foundation, version 2. (see COPYING.LIB)
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public License
// along with this program; if not, write to the Free Software Foundation
// Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307 USA
/////////////////////////////////////////////////////////////////////////////

package java.util;

public class Observable
{
	private static final short INITIAL_SIZE = 4;
	
	private boolean changed;
	private Vector observers;
	
	/**
	*Constructs an Observable with 0 Observers.  A resizable buffer is used to
	*store Observer references, and is initialized to a small capacity.
	*/
	public Observable()
	{
		changed = false;
		observers = new Vector(INITIAL_SIZE);
	}
	
	/**
	*Adds an Observer. Does not allow duplicates.
	*
	*@param observer Observer to add.
	*/
	public void addObserver( Observer observer )
	{
		if ( !observers.contains(observer) ) { observers.add(observer); }
	}
	
	/**
	*Reset this Observable's state to unchanged.
	*/
	protected void clearChanged() { changed = false; }
	
	/**
	*@return Number of Observers for this Observable.
	*/
	public int countObservers() { return observers.size(); }
	
	/**
	*Deletes an Observer of this Observable.
	*
	*@param victim Observer to delete.
	*/
	public void deleteObserver( Observer victim ) { observers.remove(victim); }
	
	/**
	*Deletes all Observers of this Observable.
	*/
	public void deleteObservers()
	{
		Enumeration enum = observers.elements();
		
		while ( enum.hasMoreElements() )
		{
			deleteObserver( (Observer)enum.nextElement() );
		}
	}

	/**
	*@return Whether or not this Observable has changed.
	*/
	public boolean hasChanged() { return changed; }
	
	/**
	*Tell Observers that this Observable has changed, then
	*resets state to unchanged.
	*/
	public void notifyObservers() { notifyObservers(null); }
	
	/**
	*@param obj Arguement to Observer's update method.
	*/
	public void notifyObservers( Object obj )
	{
		if ( hasChanged() )
		{
			Enumeration enum = observers.elements();
			
			while ( enum.hasMoreElements() )
			{
				( (Observer)enum.nextElement() ).update(this, obj);;
			}
			
			clearChanged();
		}
	}
	
	/**
	*Marks this Observable as having changed.
	*/
	protected void setChanged() { changed = true; }
}
/**
*Observer.java
*
*Implemented when a class wants to be informed of changes in observable
*objects.
*
*@author Daniel Rall (<a href="mailto:[EMAIL PROTECTED]">[EMAIL PROTECTED]</a>)
*@version 1.0b
*/

/////////////////////////////////////////////////////////////////////////////
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU Library General Public License as published
// by the Free Software Foundation, version 2. (see COPYING.LIB)
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public License
// along with this program; if not, write to the Free Software Foundation
// Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307 USA
/////////////////////////////////////////////////////////////////////////////

package java.util;

public abstract interface Observer
{
	public void update( Observable observ, Object obj );
}

Reply via email to