Commit 6f09c307 by Anthony Green Committed by Anthony Green

ArrayList.java, [...]: Imported from GNU Classpath.

2000-08-27  Anthony Green  <green@redhat.com>

	* java/util/ArrayList.java, java/util/Timer.java,
	java/util/LinkedList.java, java/util/TimerTask.java,
	java/util/HashMap.java, java/util/AbstractMap.java,
	java/util/SortedMap.java, java/util/AbstractSequentialList.java,
	java/util/SortedSet.java: Imported from GNU Classpath.
	* Makefile.in: Rebuilt.
	* Makefile.am: Added new files.

From-SVN: r36006
parent e53ca51f
2000-08-27 Anthony Green <green@redhat.com>
* java/util/ArrayList.java, java/util/Timer.java,
java/util/LinkedList.java, java/util/TimerTask.java,
java/util/HashMap.java, java/util/AbstractMap.java,
java/util/SortedMap.java, java/util/AbstractSequentialList.java,
java/util/SortedSet.java: Imported from GNU Classpath.
* Makefile.in: Rebuilt.
* Makefile.am: Added new files.
2000-08-26 Anthony Green <green@redhat.com>
* Makefile.in: Rebuilt.
......
......@@ -1030,7 +1030,10 @@ java/text/SimpleDateFormat.java \
java/text/StringCharacterIterator.java \
java/util/AbstractCollection.java \
java/util/AbstractList.java \
java/util/AbstractMap.java \
java/util/AbstractSequentialList.java \
java/util/AbstractSet.java \
java/util/ArrayList.java \
java/util/Arrays.java \
java/util/BasicMapEntry.java \
java/util/BitSet.java \
......@@ -1046,6 +1049,7 @@ java/util/Enumeration.java \
java/util/EventListener.java \
java/util/EventObject.java \
java/util/GregorianCalendar.java \
java/util/HashMap.java \
java/util/Hashtable.java \
java/util/Iterator.java \
java/util/List.java \
......@@ -1064,9 +1068,13 @@ java/util/Random.java \
java/util/ResourceBundle.java \
java/util/Set.java \
java/util/SimpleTimeZone.java \
java/util/SortedMap.java \
java/util/SortedSet.java \
java/util/Stack.java \
java/util/StringTokenizer.java \
java/util/TimeZone.java \
java/util/Timer.java \
java/util/TimerTask.java \
java/util/TooManyListenersException.java \
java/util/Vector.java \
java/util/jar/Attributes.java \
......
......@@ -799,7 +799,10 @@ java/text/SimpleDateFormat.java \
java/text/StringCharacterIterator.java \
java/util/AbstractCollection.java \
java/util/AbstractList.java \
java/util/AbstractMap.java \
java/util/AbstractSequentialList.java \
java/util/AbstractSet.java \
java/util/ArrayList.java \
java/util/Arrays.java \
java/util/BasicMapEntry.java \
java/util/BitSet.java \
......@@ -815,6 +818,7 @@ java/util/Enumeration.java \
java/util/EventListener.java \
java/util/EventObject.java \
java/util/GregorianCalendar.java \
java/util/HashMap.java \
java/util/Hashtable.java \
java/util/Iterator.java \
java/util/List.java \
......@@ -833,9 +837,13 @@ java/util/Random.java \
java/util/ResourceBundle.java \
java/util/Set.java \
java/util/SimpleTimeZone.java \
java/util/SortedMap.java \
java/util/SortedSet.java \
java/util/Stack.java \
java/util/StringTokenizer.java \
java/util/TimeZone.java \
java/util/Timer.java \
java/util/TimerTask.java \
java/util/TooManyListenersException.java \
java/util/Vector.java \
java/util/jar/Attributes.java \
......@@ -1429,26 +1437,30 @@ DEP_FILES = .deps/$(srcdir)/$(CONVERT_DIR)/gen-from-JIS.P \
.deps/java/text/RuleBasedCollator.P .deps/java/text/SimpleDateFormat.P \
.deps/java/text/StringCharacterIterator.P \
.deps/java/util/AbstractCollection.P .deps/java/util/AbstractList.P \
.deps/java/util/AbstractSet.P .deps/java/util/Arrays.P \
.deps/java/util/BasicMapEntry.P .deps/java/util/BitSet.P \
.deps/java/util/Bucket.P .deps/java/util/Calendar.P \
.deps/java/util/Collection.P .deps/java/util/Comparator.P \
.deps/java/util/AbstractMap.P .deps/java/util/AbstractSequentialList.P \
.deps/java/util/AbstractSet.P .deps/java/util/ArrayList.P \
.deps/java/util/Arrays.P .deps/java/util/BasicMapEntry.P \
.deps/java/util/BitSet.P .deps/java/util/Bucket.P \
.deps/java/util/Calendar.P .deps/java/util/Collection.P \
.deps/java/util/Comparator.P \
.deps/java/util/ConcurrentModificationException.P \
.deps/java/util/Date.P .deps/java/util/Dictionary.P \
.deps/java/util/EmptyStackException.P .deps/java/util/Enumeration.P \
.deps/java/util/EventListener.P .deps/java/util/EventObject.P \
.deps/java/util/GregorianCalendar.P .deps/java/util/Hashtable.P \
.deps/java/util/Iterator.P .deps/java/util/List.P \
.deps/java/util/ListIterator.P .deps/java/util/ListResourceBundle.P \
.deps/java/util/Locale.P .deps/java/util/Map.P \
.deps/java/util/MissingResourceException.P \
.deps/java/util/GregorianCalendar.P .deps/java/util/HashMap.P \
.deps/java/util/Hashtable.P .deps/java/util/Iterator.P \
.deps/java/util/List.P .deps/java/util/ListIterator.P \
.deps/java/util/ListResourceBundle.P .deps/java/util/Locale.P \
.deps/java/util/Map.P .deps/java/util/MissingResourceException.P \
.deps/java/util/NoSuchElementException.P .deps/java/util/Observable.P \
.deps/java/util/Observer.P .deps/java/util/Properties.P \
.deps/java/util/PropertyPermission.P \
.deps/java/util/PropertyResourceBundle.P .deps/java/util/Random.P \
.deps/java/util/ResourceBundle.P .deps/java/util/Set.P \
.deps/java/util/SimpleTimeZone.P .deps/java/util/Stack.P \
.deps/java/util/SimpleTimeZone.P .deps/java/util/SortedMap.P \
.deps/java/util/SortedSet.P .deps/java/util/Stack.P \
.deps/java/util/StringTokenizer.P .deps/java/util/TimeZone.P \
.deps/java/util/Timer.P .deps/java/util/TimerTask.P \
.deps/java/util/TooManyListenersException.P .deps/java/util/Vector.P \
.deps/java/util/jar/Attributes.P .deps/java/util/jar/JarEntry.P \
.deps/java/util/jar/JarException.P .deps/java/util/jar/JarFile.P \
......
/* AbstractMap.java -- Abstract implementation of most of Map
Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
As a special exception, if you link this library with other files to
produce an executable, this library does not by itself cause the
resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why the
executable file might be covered by the GNU General Public License. */
// TO DO:
// comments
// test suite
package java.util;
public abstract class AbstractMap implements Map {
public void clear()
{
entrySet().clear();
}
public boolean containsKey( Object key )
{
Object k;
Iterator entries = entrySet().iterator();
while( entries.hasNext() )
{
k = ((Map.Entry)entries.next()).getKey();
if( key == null ? k == null : key.equals( k ) )
return true;
}
return false;
}
public boolean containsValue( Object value )
{
Object v;
Iterator entries = entrySet().iterator();
while( entries.hasNext() )
{
v = ((Map.Entry)entries.next()).getValue();
if( value == null ? v == null : value.equals( v ) )
return true;
}
return false;
}
public abstract Set entrySet();
public boolean equals( Object o )
{
if( this == o )
return true;
if( o == null || !( o instanceof Map ) )
return false;
Map m = (Map)o;
if( m.size() != size() )
return false;
Object key, value1, value2;
Map.Entry entry;
Iterator entries = entrySet().iterator();
while( entries.hasNext() )
{
entry = (Map.Entry)entries.next();
key = entry.getKey();
value1 = entry.getValue();
value2 = m.get( key );
if( !( ( value1 == null && value2 == null )
|| value1.equals( value2 ) ) )
return false;
}
return true;
}
public Object get( Object key )
{
Object k;
Map.Entry entry;
Iterator entries = entrySet().iterator();
while( entries.hasNext() )
{
entry = (Map.Entry)entries.next();
k = entry.getKey();
if( key == null ? k == null : key.equals( k ) )
return entry.getValue();
}
return null;
}
public int hashCode()
{
int hashcode = 0;
Iterator entries = entrySet().iterator();
while( entries.hasNext() )
hashcode += entries.next().hashCode();
return hashcode;
}
public boolean isEmpty()
{
return size() == 0;
}
public Set keySet()
{
if( this.keySet == null )
{
this.keySet =
new AbstractSet()
{
public int size()
{
return AbstractMap.this.size();
}
public boolean contains(Object key)
{
return AbstractMap.this.containsKey(key);
}
public Iterator iterator()
{
return new Iterator()
{
Iterator map_iterator = AbstractMap.this.entrySet().iterator();
public boolean hasNext()
{
return map_iterator.hasNext();
}
public Object next()
{
return ((Map.Entry)map_iterator.next()).getKey();
}
public void remove()
{
map_iterator.remove();
}
};
}
};
}
return this.keySet;
}
public Object put( Object key, Object value )
{
throw new UnsupportedOperationException();
}
public void putAll( Map m )
{
Map.Entry entry;
Iterator entries = m.entrySet().iterator();
while( entries.hasNext() )
{
entry = (Map.Entry)entries.next();
put( entry.getKey(), entry.getValue() );
}
}
public Object remove( Object key )
{
Object k, value;
Map.Entry entry;
Iterator entries = entrySet().iterator();
while( entries.hasNext() )
{
entry = (Map.Entry)entries.next();
k = entry.getKey();
if( key == null ? k == null : key.equals( k ) )
{
value = entry.getValue();
entries.remove();
return value;
}
}
return null;
}
public int size()
{
return entrySet().size();
}
public String toString()
{
StringBuffer sb = new StringBuffer("{");
String comma = "";
Iterator entries = entrySet().iterator();
while( entries.hasNext() )
{
Map.Entry entry = (Map.Entry)entries.next();
sb.append(comma).append(entry.getKey())
.append('=').append(entry.getValue());
comma = ", ";
}
return sb.append('}').toString();
}
public Collection values()
{
if( this.valueCollection == null )
{
this.valueCollection =
new AbstractCollection()
{
public int size()
{
return AbstractMap.this.size();
}
public Iterator iterator()
{
return new Iterator()
{
Iterator map_iterator = AbstractMap.this.entrySet().iterator();
public boolean hasNext()
{
return map_iterator.hasNext();
}
public Object next()
{
return ((Map.Entry)map_iterator.next()).getValue();
}
public void remove()
{
map_iterator.remove();
}
};
}
};
}
return this.valueCollection;
}
private Collection valueCollection = null;
private Set keySet = null;
}
/* AbstractSequentialList.java -- List implementation for sequential access
Copyright (C) 1998, 1999 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
As a special exception, if you link this library with other files to
produce an executable, this library does not by itself cause the
resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why the
executable file might be covered by the GNU General Public License. */
// TO DO:
// ~ Lots of doc comments still missing.
// ~ The class comment should include a description of what should be overridden
// to provide what features, as should the listIterator comment.
package java.util;
/**
* Abstract superclass to make it easier to implement the List interface when
* backed by a sequential-access store, such as a linked list.
*/
public abstract class AbstractSequentialList extends AbstractList {
/**
* Returns a ListIterator over the list, starting from position index.
* Subclasses must provide an implementation of this method.
*
* @exception IndexOutOfBoundsException if index < 0 || index > size()
*/
public abstract ListIterator listIterator(int index);
/**
* Add an element to the list at a given index. This implementation obtains a
* ListIterator positioned at the specified index, and then adds the element
* using the ListIterator's add method.
*
* @param index the position to add the element
* @param o the element to insert
* @exception IndexOutOfBoundsException if index < 0 || index > size()
* @exception UnsupportedOperationException if the iterator returned by
* listIterator(index) does not support the add method.
*/
public void add(int index, Object o) {
ListIterator i = listIterator(index);
i.add(o);
}
public boolean addAll(int index, Collection c) {
boolean changed = false;
Iterator ci = c.iterator();
ListIterator i = listIterator(index);
while (ci.hasNext()) {
i.add(ci.next());
changed = true;
}
return changed;
}
public Object get(int index) {
ListIterator i = listIterator(index);
if (!i.hasNext()) {
throw new IndexOutOfBoundsException();
}
return i.next();
}
/**
* Return an Iterator over this List. This implementation returns
* listIterator().
*
* @return an Iterator over this List
*/
public Iterator iterator() {
return listIterator();
}
public Object remove(int index) {
ListIterator i = listIterator(index);
if (!i.hasNext()) {
throw new IndexOutOfBoundsException();
}
Object removed = i.next();
i.remove();
return removed;
}
public Object set(int index, Object o) {
ListIterator i = listIterator(index);
if (!i.hasNext()) {
throw new IndexOutOfBoundsException();
}
Object old = i.next();
i.set(o);
return old;
}
}
/* SortedMap.java -- A map that makes guarantees about the order of its keys
Copyright (C) 1998 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
As a special exception, if you link this library with other files to
produce an executable, this library does not by itself cause the
resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why the
executable file might be covered by the GNU General Public License. */
// TO DO:
// ~ Doc comments for everything.
package java.util;
public interface SortedMap extends Map {
Comparator comparator();
Object firstKey();
SortedMap headMap(Object toKey);
Object lastKey();
SortedMap subMap(Object fromKey, Object toKey);
SortedMap tailMap(Object fromKey);
}
/* SortedSet.java -- A set that makes guarantees about the order of its
elements
Copyright (C) 1998 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
As a special exception, if you link this library with other files to
produce an executable, this library does not by itself cause the
resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why the
executable file might be covered by the GNU General Public License. */
// TO DO:
// ~ Doc comments for everything.
package java.util;
public interface SortedSet extends Set {
Comparator comparator();
Object first();
SortedSet headSet(Object toElement);
Object last();
SortedSet subSet(Object fromElement, Object toElement);
SortedSet tailSet(Object fromElement);
}
/* TimerTask.java -- Task that can be run at a later time if given to a Timer.
Copyright (C) 2000 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
As a special exception, if you link this library with other files to
produce an executable, this library does not by itself cause the
resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why the
executable file might be covered by the GNU General Public License. */
package java.util;
/**
* Task that can be run at a later time if given to a Timer.
* The TimerTask must implement a run method that will be called by the
* Timer when the task is scheduled for execution. The task can check when
* it should have been scheduled and cancel itself when no longer needed.
* <p>
* Example:
* <code>
* Timer timer = new Timer();
* TimerTask task = new TimerTask() {
* public void run() {
* if (this.scheduledExecutionTime() < System.currentTimeMillis() + 500)
* // Do something
* else
* // Complain: We are more then half a second late!
* if (someStopCondition)
* this.cancel(); // This was our last execution
* };
* timer.scheduleAtFixedRate(task, 1000, 1000); // schedule every second
* </code>
* <p>
* Note that a TimerTask object is a one shot object and can only given once
* to a Timer. (The Timer will use the TimerTask object for bookkeeping,
* in this implementation).
* <p>
* This class also implements <code>Runnable</code> to make it possible to
* give a TimerTask directly as a target to a <code>Thread</code>.
*
* @see Timer
* @since 1.3
* @author Mark Wielaard (mark@klomp.org)
*/
public abstract class TimerTask implements Runnable {
/**
* If positive the next time this task should be run.
* If negative this TimerTask is canceled or executed for the last time.
*/
long scheduled;
/**
* If positive the last time this task was run.
* If negative this TimerTask has not yet been scheduled.
*/
long lastExecutionTime;
/**
* If positive the number of milliseconds between runs of this task.
* If -1 this task doesn't have to be run more then once.
*/
long period;
/**
* If true the next time this task should be run is relative to
* the last scheduled time, otherwise it can drift in time.
*/
boolean fixed;
/**
* Creates a TimerTask and marks it as not yet scheduled.
*/
protected TimerTask() {
this.scheduled = 0;
this.lastExecutionTime = -1;
}
/**
* Marks the task as canceled and prevents any further execution.
* Returns true if the task was scheduled for any execution in the future
* and this cancel operation prevents that execution from happening.
* <p>
* A task that has been canceled can never be scheduled again.
* <p>
* In this implementation the TimerTask it is possible that the Timer does
* keep a reference to the TimerTask until the first time the TimerTask
* is actually scheduled. But the reference will disappear immediatly when
* cancel is called from within the TimerTask run method.
*/
public boolean cancel() {
boolean prevented_execution = (this.scheduled >= 0);
this.scheduled = -1;
return prevented_execution;
}
/**
* Method that is called when this task is scheduled for execution.
*/
public abstract void run();
/**
* Returns the last time this task was scheduled or (when called by the
* task from the run method) the time the current execution of the task
* was scheduled. When the task has not yet run the return value is
* undefined.
* <p>
* Can be used (when the task is scheduled at fixed rate) to see the
* difference between the requested schedule time and the actual time
* that can be found with <code>System.currentTimeMillis()</code>.
*/
public long scheduledExecutionTime() {
return lastExecutionTime;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment