|
From: <ls...@us...> - 2006-12-12 21:12:31
|
Revision: 2897
http://jnode.svn.sourceforge.net/jnode/?rev=2897&view=rev
Author: lsantha
Date: 2006-12-12 13:12:29 -0800 (Tue, 12 Dec 2006)
Log Message:
-----------
Migrating to Java 5 level classpath.
Added Paths:
-----------
trunk/core/src/classpath/java/java/util/AbstractCollection.java
trunk/core/src/classpath/java/java/util/AbstractList.java
trunk/core/src/classpath/java/java/util/AbstractMap.java
trunk/core/src/classpath/java/java/util/AbstractQueue.java
trunk/core/src/classpath/java/java/util/AbstractSequentialList.java
trunk/core/src/classpath/java/java/util/AbstractSet.java
trunk/core/src/classpath/java/java/util/ArrayList.java
trunk/core/src/classpath/java/java/util/Arrays.java
trunk/core/src/classpath/java/java/util/BitSet.java
trunk/core/src/classpath/java/java/util/Collection.java
trunk/core/src/classpath/java/java/util/Collections.java
trunk/core/src/classpath/java/java/util/Comparator.java
trunk/core/src/classpath/java/java/util/Dictionary.java
trunk/core/src/classpath/java/java/util/DuplicateFormatFlagsException.java
trunk/core/src/classpath/java/java/util/EnumMap.java
trunk/core/src/classpath/java/java/util/EnumSet.java
trunk/core/src/classpath/java/java/util/Enumeration.java
trunk/core/src/classpath/java/java/util/FormatFlagsConversionMismatchException.java
trunk/core/src/classpath/java/java/util/Formattable.java
trunk/core/src/classpath/java/java/util/FormattableFlags.java
trunk/core/src/classpath/java/java/util/Formatter.java
trunk/core/src/classpath/java/java/util/FormatterClosedException.java
trunk/core/src/classpath/java/java/util/HashMap.java
trunk/core/src/classpath/java/java/util/HashSet.java
trunk/core/src/classpath/java/java/util/Hashtable.java
trunk/core/src/classpath/java/java/util/IdentityHashMap.java
trunk/core/src/classpath/java/java/util/IllegalFormatCodePointException.java
trunk/core/src/classpath/java/java/util/IllegalFormatConversionException.java
trunk/core/src/classpath/java/java/util/IllegalFormatException.java
trunk/core/src/classpath/java/java/util/IllegalFormatFlagsException.java
trunk/core/src/classpath/java/java/util/IllegalFormatPrecisionException.java
trunk/core/src/classpath/java/java/util/IllegalFormatWidthException.java
trunk/core/src/classpath/java/java/util/Iterator.java
trunk/core/src/classpath/java/java/util/LinkedHashMap.java
trunk/core/src/classpath/java/java/util/LinkedHashSet.java
trunk/core/src/classpath/java/java/util/LinkedList.java
trunk/core/src/classpath/java/java/util/List.java
trunk/core/src/classpath/java/java/util/ListIterator.java
trunk/core/src/classpath/java/java/util/Map.java
trunk/core/src/classpath/java/java/util/MissingFormatArgumentException.java
trunk/core/src/classpath/java/java/util/MissingFormatWidthException.java
trunk/core/src/classpath/java/java/util/PriorityQueue.java
trunk/core/src/classpath/java/java/util/Properties.java
trunk/core/src/classpath/java/java/util/Queue.java
trunk/core/src/classpath/java/java/util/Set.java
trunk/core/src/classpath/java/java/util/SortedMap.java
trunk/core/src/classpath/java/java/util/SortedSet.java
trunk/core/src/classpath/java/java/util/Stack.java
trunk/core/src/classpath/java/java/util/TreeMap.java
trunk/core/src/classpath/java/java/util/TreeSet.java
trunk/core/src/classpath/java/java/util/UnknownFormatConversionException.java
trunk/core/src/classpath/java/java/util/UnknownFormatFlagsException.java
trunk/core/src/classpath/java/java/util/Vector.java
trunk/core/src/classpath/java/java/util/WeakHashMap.java
Added: trunk/core/src/classpath/java/java/util/AbstractCollection.java
===================================================================
--- trunk/core/src/classpath/java/java/util/AbstractCollection.java (rev 0)
+++ trunk/core/src/classpath/java/java/util/AbstractCollection.java 2006-12-12 21:12:29 UTC (rev 2897)
@@ -0,0 +1,490 @@
+/* AbstractCollection.java -- Abstract implementation of most of Collection
+ Copyright (C) 1998, 2000, 2001, 2004, 2005 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., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package java.util;
+
+import java.lang.reflect.Array;
+
+/**
+ * A basic implementation of most of the methods in the Collection interface to
+ * make it easier to create a collection. To create an unmodifiable Collection,
+ * just subclass AbstractCollection and provide implementations of the
+ * iterator() and size() methods. The Iterator returned by iterator() need only
+ * provide implementations of hasNext() and next() (that is, it may throw an
+ * UnsupportedOperationException if remove() is called). To create a modifiable
+ * Collection, you must in addition provide an implementation of the
+ * add(Object) method and the Iterator returned by iterator() must provide an
+ * implementation of remove(). Other methods should be overridden if the
+ * backing data structure allows for a more efficient implementation. The
+ * precise implementation used by AbstractCollection is documented, so that
+ * subclasses can tell which methods could be implemented more efficiently.
+ * <p>
+ *
+ * The programmer should provide a no-argument constructor, and one that
+ * accepts another Collection, as recommended by the Collection interface.
+ * Unfortunately, there is no way to enforce this in Java.
+ *
+ * @author Original author unknown
+ * @author Bryce McKinlay
+ * @author Eric Blake (eb...@em...)
+ * @author Tom Tromey (tr...@re...)
+ * @author Andrew John Hughes (gnu...@me...)
+ * @see Collection
+ * @see AbstractSet
+ * @see AbstractList
+ * @since 1.2
+ * @status updated to 1.4
+ */
+public abstract class AbstractCollection<E>
+ implements Collection<E>, Iterable<E>
+{
+ /**
+ * The main constructor, for use by subclasses.
+ */
+ protected AbstractCollection()
+ {
+ }
+
+ /**
+ * Return an Iterator over this collection. The iterator must provide the
+ * hasNext and next methods and should in addition provide remove if the
+ * collection is modifiable.
+ *
+ * @return an iterator
+ */
+ public abstract Iterator<E> iterator();
+
+ /**
+ * Return the number of elements in this collection. If there are more than
+ * Integer.MAX_VALUE elements, return Integer.MAX_VALUE.
+ *
+ * @return the size
+ */
+ public abstract int size();
+
+ /**
+ * Add an object to the collection (optional operation). This implementation
+ * always throws an UnsupportedOperationException - it should be
+ * overridden if the collection is to be modifiable. If the collection
+ * does not accept duplicates, simply return false. Collections may specify
+ * limitations on what may be added.
+ *
+ * @param o the object to add
+ * @return true if the add operation caused the Collection to change
+ * @throws UnsupportedOperationException if the add operation is not
+ * supported on this collection
+ * @throws NullPointerException if the collection does not support null
+ * @throws ClassCastException if the object is of the wrong type
+ * @throws IllegalArgumentException if some aspect of the object prevents
+ * it from being added
+ */
+ public boolean add(E o)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * Add all the elements of a given collection to this collection (optional
+ * operation). This implementation obtains an Iterator over the given
+ * collection and iterates over it, adding each element with the
+ * add(Object) method (thus this method will fail with an
+ * UnsupportedOperationException if the add method does). The behavior is
+ * unspecified if the specified collection is modified during the iteration,
+ * including the special case of trying addAll(this) on a non-empty
+ * collection.
+ *
+ * @param c the collection to add the elements of to this collection
+ * @return true if the add operation caused the Collection to change
+ * @throws UnsupportedOperationException if the add operation is not
+ * supported on this collection
+ * @throws NullPointerException if the specified collection is null
+ * @throws ClassCastException if the type of any element in c is
+ * not a valid type for addition.
+ * @throws IllegalArgumentException if some aspect of any element
+ * in c prevents it being added.
+ * @throws NullPointerException if any element in c is null and this
+ * collection doesn't allow null values.
+ * @see #add(Object)
+ */
+ public boolean addAll(Collection<? extends E> c)
+ {
+ Iterator<? extends E> itr = c.iterator();
+ boolean modified = false;
+ int pos = c.size();
+ while (--pos >= 0)
+ modified |= add(itr.next());
+ return modified;
+ }
+
+ /**
+ * Remove all elements from the collection (optional operation). This
+ * implementation obtains an iterator over the collection and calls next
+ * and remove on it repeatedly (thus this method will fail with an
+ * UnsupportedOperationException if the Iterator's remove method does)
+ * until there are no more elements to remove.
+ * Many implementations will have a faster way of doing this.
+ *
+ * @throws UnsupportedOperationException if the Iterator returned by
+ * iterator does not provide an implementation of remove
+ * @see Iterator#remove()
+ */
+ public void clear()
+ {
+ Iterator<E> itr = iterator();
+ int pos = size();
+ while (--pos >= 0)
+ {
+ itr.next();
+ itr.remove();
+ }
+ }
+
+ /**
+ * Test whether this collection contains a given object. That is, if the
+ * collection has an element e such that (o == null ? e == null :
+ * o.equals(e)). This implementation obtains an iterator over the collection
+ * and iterates over it, testing each element for equality with the given
+ * object. If it is equal, true is returned. Otherwise false is returned when
+ * the end of the collection is reached.
+ *
+ * @param o the object to remove from this collection
+ * @return true if this collection contains an object equal to o
+ */
+ public boolean contains(Object o)
+ {
+ Iterator<E> itr = iterator();
+ int pos = size();
+ while (--pos >= 0)
+ if (equals(o, itr.next()))
+ return true;
+ return false;
+ }
+
+ /**
+ * Tests whether this collection contains all the elements in a given
+ * collection. This implementation iterates over the given collection,
+ * testing whether each element is contained in this collection. If any one
+ * is not, false is returned. Otherwise true is returned.
+ *
+ * @param c the collection to test against
+ * @return true if this collection contains all the elements in the given
+ * collection
+ * @throws NullPointerException if the given collection is null
+ * @see #contains(Object)
+ */
+ public boolean containsAll(Collection<?> c)
+ {
+ Iterator<?> itr = c.iterator();
+ int pos = c.size();
+ while (--pos >= 0)
+ if (!contains(itr.next()))
+ return false;
+ return true;
+ }
+
+ /**
+ * Test whether this collection is empty. This implementation returns
+ * size() == 0.
+ *
+ * @return true if this collection is empty.
+ * @see #size()
+ */
+ public boolean isEmpty()
+ {
+ return size() == 0;
+ }
+
+ /**
+ * Remove a single instance of an object from this collection (optional
+ * operation). That is, remove one element e such that
+ * <code>(o == null ? e == null : o.equals(e))</code>, if such an element
+ * exists. This implementation obtains an iterator over the collection
+ * and iterates over it, testing each element for equality with the given
+ * object. If it is equal, it is removed by the iterator's remove method
+ * (thus this method will fail with an UnsupportedOperationException if
+ * the Iterator's remove method does). After the first element has been
+ * removed, true is returned; if the end of the collection is reached, false
+ * is returned.
+ *
+ * @param o the object to remove from this collection
+ * @return true if the remove operation caused the Collection to change, or
+ * equivalently if the collection did contain o.
+ * @throws UnsupportedOperationException if this collection's Iterator
+ * does not support the remove method
+ * @see Iterator#remove()
+ */
+ public boolean remove(Object o)
+ {
+ Iterator<E> itr = iterator();
+ int pos = size();
+ while (--pos >= 0)
+ if (equals(o, itr.next()))
+ {
+ itr.remove();
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Remove from this collection all its elements that are contained in a given
+ * collection (optional operation). This implementation iterates over this
+ * collection, and for each element tests if it is contained in the given
+ * collection. If so, it is removed by the Iterator's remove method (thus
+ * this method will fail with an UnsupportedOperationException if the
+ * Iterator's remove method does).
+ *
+ * @param c the collection to remove the elements of
+ * @return true if the remove operation caused the Collection to change
+ * @throws UnsupportedOperationException if this collection's Iterator
+ * does not support the remove method
+ * @throws NullPointerException if the collection, c, is null.
+ * @see Iterator#remove()
+ */
+ public boolean removeAll(Collection<?> c)
+ {
+ return removeAllInternal(c);
+ }
+
+ /**
+ * Remove from this collection all its elements that are contained in a given
+ * collection (optional operation). This implementation iterates over this
+ * collection, and for each element tests if it is contained in the given
+ * collection. If so, it is removed by the Iterator's remove method (thus
+ * this method will fail with an UnsupportedOperationException if the
+ * Iterator's remove method does). This method is necessary for ArrayList,
+ * which cannot publicly override removeAll but can optimize this call.
+ *
+ * @param c the collection to remove the elements of
+ * @return true if the remove operation caused the Collection to change
+ * @throws UnsupportedOperationException if this collection's Iterator
+ * does not support the remove method
+ * @throws NullPointerException if the collection, c, is null.
+ * @see Iterator#remove()
+ */
+ // Package visible for use throughout java.util.
+ boolean removeAllInternal(Collection<?> c)
+ {
+ Iterator<E> itr = iterator();
+ boolean modified = false;
+ int pos = size();
+ while (--pos >= 0)
+ if (c.contains(itr.next()))
+ {
+ itr.remove();
+ modified = true;
+ }
+ return modified;
+ }
+
+ /**
+ * Remove from this collection all its elements that are not contained in a
+ * given collection (optional operation). This implementation iterates over
+ * this collection, and for each element tests if it is contained in the
+ * given collection. If not, it is removed by the Iterator's remove method
+ * (thus this method will fail with an UnsupportedOperationException if
+ * the Iterator's remove method does).
+ *
+ * @param c the collection to retain the elements of
+ * @return true if the remove operation caused the Collection to change
+ * @throws UnsupportedOperationException if this collection's Iterator
+ * does not support the remove method
+ * @throws NullPointerException if the collection, c, is null.
+ * @see Iterator#remove()
+ */
+ public boolean retainAll(Collection<?> c)
+ {
+ return retainAllInternal(c);
+ }
+
+ /**
+ * Remove from this collection all its elements that are not contained in a
+ * given collection (optional operation). This implementation iterates over
+ * this collection, and for each element tests if it is contained in the
+ * given collection. If not, it is removed by the Iterator's remove method
+ * (thus this method will fail with an UnsupportedOperationException if
+ * the Iterator's remove method does). This method is necessary for
+ * ArrayList, which cannot publicly override retainAll but can optimize
+ * this call.
+ *
+ * @param c the collection to retain the elements of
+ * @return true if the remove operation caused the Collection to change
+ * @throws UnsupportedOperationException if this collection's Iterator
+ * does not support the remove method
+ * @throws NullPointerException if the collection, c, is null.
+ * @see Iterator#remove()
+ */
+ // Package visible for use throughout java.util.
+ boolean retainAllInternal(Collection<?> c)
+ {
+ Iterator<E> itr = iterator();
+ boolean modified = false;
+ int pos = size();
+ while (--pos >= 0)
+ if (!c.contains(itr.next()))
+ {
+ itr.remove();
+ modified = true;
+ }
+ return modified;
+ }
+
+ /**
+ * Return an array containing the elements of this collection. This
+ * implementation creates an Object array of size size() and then iterates
+ * over the collection, setting each element of the array from the value
+ * returned by the iterator. The returned array is safe, and is not backed
+ * by the collection.
+ *
+ * @return an array containing the elements of this collection
+ */
+ public Object[] toArray()
+ {
+ Iterator<E> itr = iterator();
+ int size = size();
+ Object[] a = new Object[size];
+ for (int pos = 0; pos < size; pos++)
+ a[pos] = itr.next();
+ return a;
+ }
+
+ /**
+ * Copy the collection into a given array if it will fit, or into a
+ * dynamically created array of the same run-time type as the given array if
+ * not. If there is space remaining in the array, the first element after the
+ * end of the collection is set to null (this is only useful if the
+ * collection is known to contain no null elements, however). This
+ * implementation first tests whether the given array is large enough to hold
+ * all the elements of the collection. If not, the reflection API is used to
+ * allocate a new array of the same run-time type. Next an iterator is
+ * obtained over the collection and the elements are placed in the array as
+ * they are returned by the iterator. Finally the first spare element, if
+ * any, of the array is set to null, and the created array is returned.
+ * The returned array is safe; it is not backed by the collection. Note that
+ * null may not mark the last element, if the collection allows null
+ * elements.
+ *
+ * @param a the array to copy into, or of the correct run-time type
+ * @return the array that was produced
+ * @throws NullPointerException if the given array is null
+ * @throws ArrayStoreException if the type of the array precludes holding
+ * one of the elements of the Collection
+ */
+ public <T> T[] toArray(T[] a)
+ {
+ int size = size();
+ if (a.length < size)
+ a = (T[]) Array.newInstance(a.getClass().getComponentType(),
+ size);
+ else if (a.length > size)
+ a[size] = null;
+
+ Iterator<E> itr = iterator();
+ for (int pos = 0; pos < size; pos++)
+ {
+ try
+ {
+ a[pos] = (T) (itr.next());
+ }
+ catch (ClassCastException exception)
+ {
+ throw new ArrayStoreException("The element is of the wrong type "+
+ "for storing in this array.");
+ }
+ }
+ return a;
+ }
+
+ /**
+ * Creates a String representation of the Collection. The string returned is
+ * of the form "[a, b, ...]" where a and b etc are the results of calling
+ * toString on the elements of the collection. This implementation obtains an
+ * Iterator over the Collection and adds each element to a StringBuffer as it
+ * is returned by the iterator. "<this>" is inserted when the collection
+ * contains itself (only works for direct containment, not for collections
+ * inside collections).
+ *
+ * @return a String representation of the Collection
+ */
+ public String toString()
+ {
+ Iterator itr = iterator();
+ StringBuffer r = new StringBuffer("[");
+ boolean hasNext = itr.hasNext();
+ while (hasNext)
+ {
+ Object o = itr.next();
+ if (o == this)
+ r.append("<this>");
+ else
+ r.append(o);
+ hasNext = itr.hasNext();
+ if (hasNext)
+ r.append(", ");
+ }
+ r.append("]");
+ return r.toString();
+ }
+
+ /**
+ * Compare two objects according to Collection semantics.
+ *
+ * @param o1 the first object
+ * @param o2 the second object
+ * @return o1 == null ? o2 == null : o1.equals(o2)
+ */
+ // Package visible for use throughout java.util.
+ // It may be inlined since it is final.
+ static final boolean equals(Object o1, Object o2)
+ {
+ return o1 == null ? o2 == null : o1.equals(o2);
+ }
+
+ /**
+ * Hash an object according to Collection semantics.
+ *
+ * @param o the object to hash
+ * @return o1 == null ? 0 : o1.hashCode()
+ */
+ // Package visible for use throughout java.util.
+ // It may be inlined since it is final.
+ static final int hashCode(Object o)
+ {
+ return o == null ? 0 : o.hashCode();
+ }
+}
Added: trunk/core/src/classpath/java/java/util/AbstractList.java
===================================================================
--- trunk/core/src/classpath/java/java/util/AbstractList.java (rev 0)
+++ trunk/core/src/classpath/java/java/util/AbstractList.java 2006-12-12 21:12:29 UTC (rev 2897)
@@ -0,0 +1,1204 @@
+/* AbstractList.java -- Abstract implementation of most of List
+ Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004, 2005
+ 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., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package java.util;
+
+/**
+ * A basic implementation of most of the methods in the List interface to make
+ * it easier to create a List based on a random-access data structure. If
+ * the list is sequential (such as a linked list), use AbstractSequentialList.
+ * To create an unmodifiable list, it is only necessary to override the
+ * size() and get(int) methods (this contrasts with all other abstract
+ * collection classes which require an iterator to be provided). To make the
+ * list modifiable, the set(int, Object) method should also be overridden, and
+ * to make the list resizable, the add(int, Object) and remove(int) methods
+ * should be overridden too. Other methods should be overridden if the
+ * backing data structure allows for a more efficient implementation.
+ * The precise implementation used by AbstractList is documented, so that
+ * subclasses can tell which methods could be implemented more efficiently.
+ * <p>
+ *
+ * As recommended by Collection and List, the subclass should provide at
+ * least a no-argument and a Collection constructor. This class is not
+ * synchronized.
+ *
+ * @author Original author unknown
+ * @author Bryce McKinlay
+ * @author Eric Blake (eb...@em...)
+ * @see Collection
+ * @see List
+ * @see AbstractSequentialList
+ * @see AbstractCollection
+ * @see ListIterator
+ * @since 1.2
+ * @status updated to 1.4
+ */
+public abstract class AbstractList<E>
+ extends AbstractCollection<E>
+ implements List<E>
+{
+ /**
+ * A count of the number of structural modifications that have been made to
+ * the list (that is, insertions and removals). Structural modifications
+ * are ones which change the list size or affect how iterations would
+ * behave. This field is available for use by Iterator and ListIterator,
+ * in order to throw a {@link ConcurrentModificationException} in response
+ * to the next operation on the iterator. This <i>fail-fast</i> behavior
+ * saves the user from many subtle bugs otherwise possible from concurrent
+ * modification during iteration.
+ * <p>
+ *
+ * To make lists fail-fast, increment this field by just 1 in the
+ * <code>add(int, Object)</code> and <code>remove(int)</code> methods.
+ * Otherwise, this field may be ignored.
+ */
+ protected transient int modCount;
+
+ /**
+ * The main constructor, for use by subclasses.
+ */
+ protected AbstractList()
+ {
+ }
+
+ /**
+ * Returns the elements at the specified position in the list.
+ *
+ * @param index the element to return
+ * @return the element at that position
+ * @throws IndexOutOfBoundsException if index < 0 || index >= size()
+ */
+ public abstract E get(int index);
+
+ /**
+ * Insert an element into the list at a given position (optional operation).
+ * This shifts all existing elements from that position to the end one
+ * index to the right. This version of add has no return, since it is
+ * assumed to always succeed if there is no exception. This implementation
+ * always throws UnsupportedOperationException, and must be overridden to
+ * make a modifiable List. If you want fail-fast iterators, be sure to
+ * increment modCount when overriding this.
+ *
+ * @param index the location to insert the item
+ * @param o the object to insert
+ * @throws UnsupportedOperationException if this list does not support the
+ * add operation
+ * @throws IndexOutOfBoundsException if index < 0 || index > size()
+ * @throws ClassCastException if o cannot be added to this list due to its
+ * type
+ * @throws IllegalArgumentException if o cannot be added to this list for
+ * some other reason
+ * @see #modCount
+ */
+ public void add(int index, E o)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * Add an element to the end of the list (optional operation). If the list
+ * imposes restraints on what can be inserted, such as no null elements,
+ * this should be documented. This implementation calls
+ * <code>add(size(), o);</code>, and will fail if that version does.
+ *
+ * @param o the object to add
+ * @return true, as defined by Collection for a modified list
+ * @throws UnsupportedOperationException if this list does not support the
+ * add operation
+ * @throws ClassCastException if o cannot be added to this list due to its
+ * type
+ * @throws IllegalArgumentException if o cannot be added to this list for
+ * some other reason
+ * @see #add(int, Object)
+ */
+ public boolean add(E o)
+ {
+ add(size(), o);
+ return true;
+ }
+
+ /**
+ * Insert the contents of a collection into the list at a given position
+ * (optional operation). Shift all elements at that position to the right
+ * by the number of elements inserted. This operation is undefined if
+ * this list is modified during the operation (for example, if you try
+ * to insert a list into itself). This implementation uses the iterator of
+ * the collection, repeatedly calling add(int, Object); this will f...
[truncated message content] |
|
From: <ls...@us...> - 2007-01-07 05:38:17
|
Revision: 2991
http://jnode.svn.sourceforge.net/jnode/?rev=2991&view=rev
Author: lsantha
Date: 2007-01-06 21:38:13 -0800 (Sat, 06 Jan 2007)
Log Message:
-----------
Classpath patches.
Added Paths:
-----------
trunk/core/src/classpath/java/java/util/ArrayDeque.java
trunk/core/src/classpath/java/java/util/Deque.java
trunk/core/src/classpath/java/java/util/NavigableMap.java
trunk/core/src/classpath/java/java/util/NavigableSet.java
trunk/core/src/classpath/java/java/util/concurrent/
trunk/core/src/classpath/java/java/util/concurrent/AbstractExecutorService.java
trunk/core/src/classpath/java/java/util/concurrent/ArrayBlockingQueue.java
trunk/core/src/classpath/java/java/util/concurrent/BlockingDeque.java
trunk/core/src/classpath/java/java/util/concurrent/BlockingQueue.java
trunk/core/src/classpath/java/java/util/concurrent/BrokenBarrierException.java
trunk/core/src/classpath/java/java/util/concurrent/Callable.java
trunk/core/src/classpath/java/java/util/concurrent/CancellationException.java
trunk/core/src/classpath/java/java/util/concurrent/CompletionService.java
trunk/core/src/classpath/java/java/util/concurrent/ConcurrentHashMap.java
trunk/core/src/classpath/java/java/util/concurrent/ConcurrentLinkedQueue.java
trunk/core/src/classpath/java/java/util/concurrent/ConcurrentMap.java
trunk/core/src/classpath/java/java/util/concurrent/ConcurrentNavigableMap.java
trunk/core/src/classpath/java/java/util/concurrent/ConcurrentSkipListMap.java
trunk/core/src/classpath/java/java/util/concurrent/ConcurrentSkipListSet.java
trunk/core/src/classpath/java/java/util/concurrent/CopyOnWriteArrayList.java
trunk/core/src/classpath/java/java/util/concurrent/CopyOnWriteArraySet.java
trunk/core/src/classpath/java/java/util/concurrent/CountDownLatch.java
trunk/core/src/classpath/java/java/util/concurrent/CyclicBarrier.java
trunk/core/src/classpath/java/java/util/concurrent/DelayQueue.java
trunk/core/src/classpath/java/java/util/concurrent/Delayed.java
trunk/core/src/classpath/java/java/util/concurrent/Exchanger.java
trunk/core/src/classpath/java/java/util/concurrent/ExecutionException.java
trunk/core/src/classpath/java/java/util/concurrent/Executor.java
trunk/core/src/classpath/java/java/util/concurrent/ExecutorCompletionService.java
trunk/core/src/classpath/java/java/util/concurrent/ExecutorService.java
trunk/core/src/classpath/java/java/util/concurrent/Executors.java
trunk/core/src/classpath/java/java/util/concurrent/Future.java
trunk/core/src/classpath/java/java/util/concurrent/FutureTask.java
trunk/core/src/classpath/java/java/util/concurrent/LinkedBlockingDeque.java
trunk/core/src/classpath/java/java/util/concurrent/LinkedBlockingQueue.java
trunk/core/src/classpath/java/java/util/concurrent/PriorityBlockingQueue.java
trunk/core/src/classpath/java/java/util/concurrent/RejectedExecutionException.java
trunk/core/src/classpath/java/java/util/concurrent/RejectedExecutionHandler.java
trunk/core/src/classpath/java/java/util/concurrent/RunnableFuture.java
trunk/core/src/classpath/java/java/util/concurrent/RunnableScheduledFuture.java
trunk/core/src/classpath/java/java/util/concurrent/ScheduledExecutorService.java
trunk/core/src/classpath/java/java/util/concurrent/ScheduledFuture.java
trunk/core/src/classpath/java/java/util/concurrent/ScheduledThreadPoolExecutor.java
trunk/core/src/classpath/java/java/util/concurrent/Semaphore.java
trunk/core/src/classpath/java/java/util/concurrent/SynchronousQueue.java
trunk/core/src/classpath/java/java/util/concurrent/ThreadFactory.java
trunk/core/src/classpath/java/java/util/concurrent/ThreadPoolExecutor.java
trunk/core/src/classpath/java/java/util/concurrent/TimeUnit.java
trunk/core/src/classpath/java/java/util/concurrent/TimeoutException.java
trunk/core/src/classpath/java/java/util/concurrent/atomic/
trunk/core/src/classpath/java/java/util/concurrent/atomic/AtomicBoolean.java
trunk/core/src/classpath/java/java/util/concurrent/atomic/AtomicInteger.java
trunk/core/src/classpath/java/java/util/concurrent/atomic/AtomicIntegerArray.java
trunk/core/src/classpath/java/java/util/concurrent/atomic/AtomicIntegerFieldUpdater.java
trunk/core/src/classpath/java/java/util/concurrent/atomic/AtomicLong.java
trunk/core/src/classpath/java/java/util/concurrent/atomic/AtomicLongArray.java
trunk/core/src/classpath/java/java/util/concurrent/atomic/AtomicLongFieldUpdater.java
trunk/core/src/classpath/java/java/util/concurrent/atomic/AtomicMarkableReference.java
trunk/core/src/classpath/java/java/util/concurrent/atomic/AtomicReference.java
trunk/core/src/classpath/java/java/util/concurrent/atomic/AtomicReferenceArray.java
trunk/core/src/classpath/java/java/util/concurrent/atomic/AtomicReferenceFieldUpdater.java
trunk/core/src/classpath/java/java/util/concurrent/atomic/AtomicStampedReference.java
trunk/core/src/classpath/java/java/util/concurrent/atomic/package.html
trunk/core/src/classpath/java/java/util/concurrent/locks/
trunk/core/src/classpath/java/java/util/concurrent/locks/AbstractOwnableSynchronizer.java
trunk/core/src/classpath/java/java/util/concurrent/locks/AbstractQueuedLongSynchronizer.java
trunk/core/src/classpath/java/java/util/concurrent/locks/AbstractQueuedSynchronizer.java
trunk/core/src/classpath/java/java/util/concurrent/locks/Condition.java
trunk/core/src/classpath/java/java/util/concurrent/locks/Lock.java
trunk/core/src/classpath/java/java/util/concurrent/locks/LockSupport.java
trunk/core/src/classpath/java/java/util/concurrent/locks/ReadWriteLock.java
trunk/core/src/classpath/java/java/util/concurrent/locks/ReentrantLock.java
trunk/core/src/classpath/java/java/util/concurrent/locks/package.html
trunk/core/src/classpath/java/java/util/concurrent/package.html
trunk/core/src/classpath/java/java/util/spi/
trunk/core/src/classpath/java/java/util/spi/CurrencyNameProvider.java
trunk/core/src/classpath/java/java/util/spi/LocaleNameProvider.java
trunk/core/src/classpath/java/java/util/spi/LocaleServiceProvider.java
trunk/core/src/classpath/java/java/util/spi/TimeZoneNameProvider.java
trunk/core/src/classpath/java/java/util/spi/package.html
Added: trunk/core/src/classpath/java/java/util/ArrayDeque.java
===================================================================
--- trunk/core/src/classpath/java/java/util/ArrayDeque.java (rev 0)
+++ trunk/core/src/classpath/java/java/util/ArrayDeque.java 2007-01-07 05:38:13 UTC (rev 2991)
@@ -0,0 +1,839 @@
+/*
+ * Written by Josh Bloch of Google Inc. and released to the public domain,
+ * as explained at http://creativecommons.org/licenses/publicdomain.
+ */
+
+package java.util;
+import java.io.*;
+
+/**
+ * Resizable-array implementation of the {@link Deque} interface. Array
+ * deques have no capacity restrictions; they grow as necessary to support
+ * usage. They are not thread-safe; in the absence of external
+ * synchronization, they do not support concurrent access by multiple threads.
+ * Null elements are prohibited. This class is likely to be faster than
+ * {@link Stack} when used as a stack, and faster than {@link LinkedList}
+ * when used as a queue.
+ *
+ * <p>Most <tt>ArrayDeque</tt> operations run in amortized constant time.
+ * Exceptions include {@link #remove(Object) remove}, {@link
+ * #removeFirstOccurrence removeFirstOccurrence}, {@link #removeLastOccurrence
+ * removeLastOccurrence}, {@link #contains contains}, {@link #iterator
+ * iterator.remove()}, and the bulk operations, all of which run in linear
+ * time.
+ *
+ * <p>The iterators returned by this class's <tt>iterator</tt> method are
+ * <i>fail-fast</i>: If the deque is modified at any time after the iterator
+ * is created, in any way except through the iterator's own <tt>remove</tt>
+ * method, the iterator will generally throw a {@link
+ * ConcurrentModificationException}. Thus, in the face of concurrent
+ * modification, the iterator fails quickly and cleanly, rather than risking
+ * arbitrary, non-deterministic behavior at an undetermined time in the
+ * future.
+ *
+ * <p>Note that the fail-fast behavior of an iterator cannot be guaranteed
+ * as it is, generally speaking, impossible to make any hard guarantees in the
+ * presence of unsynchronized concurrent modification. Fail-fast iterators
+ * throw <tt>ConcurrentModificationException</tt> on a best-effort basis.
+ * Therefore, it would be wrong to write a program that depended on this
+ * exception for its correctness: <i>the fail-fast behavior of iterators
+ * should be used only to detect bugs.</i>
+ *
+ * <p>This class and its iterator implement all of the
+ * <em>optional</em> methods of the {@link Collection} and {@link
+ * Iterator} interfaces.
+ *
+ * <p>This class is a member of the
+ * <a href="{@docRoot}/../technotes/guides/collections/index.html">
+ * Java Collections Framework</a>.
+ *
+ * @author Josh Bloch and Doug Lea
+ * @since 1.6
+ * @param <E> the type of elements held in this collection
+ */
+public class ArrayDeque<E> extends AbstractCollection<E>
+ implements Deque<E>, Cloneable, Serializable
+{
+ /**
+ * The array in which the elements of the deque are stored.
+ * The capacity of the deque is the length of this array, which is
+ * always a power of two. The array is never allowed to become
+ * full, except transiently within an addX method where it is
+ * resized (see doubleCapacity) immediately upon becoming full,
+ * thus avoiding head and tail wrapping around to equal each
+ * other. We also guarantee that all array cells not holding
+ * deque elements are always null.
+ */
+ private transient E[] elements;
+
+ /**
+ * The index of the element at the head of the deque (which is the
+ * element that would be removed by remove() or pop()); or an
+ * arbitrary number equal to tail if the deque is empty.
+ */
+ private transient int head;
+
+ /**
+ * The index at which the next element would be added to the tail
+ * of the deque (via addLast(E), add(E), or push(E)).
+ */
+ private transient int tail;
+
+ /**
+ * The minimum capacity that we'll use for a newly created deque.
+ * Must be a power of 2.
+ */
+ private static final int MIN_INITIAL_CAPACITY = 8;
+
+ // ****** Array allocation and resizing utilities ******
+
+ /**
+ * Allocate empty array to hold the given number of elements.
+ *
+ * @param numElements the number of elements to hold
+ */
+ private void allocateElements(int numElements) {
+ int initialCapacity = MIN_INITIAL_CAPACITY;
+ // Find the best power of two to hold elements.
+ // Tests "<=" because arrays aren't kept full.
+ if (numElements >= initialCapacity) {
+ initialCapacity = numElements;
+ initialCapacity |= (initialCapacity >>> 1);
+ initialCapacity |= (initialCapacity >>> 2);
+ initialCapacity |= (initialCapacity >>> 4);
+ initialCapacity |= (initialCapacity >>> 8);
+ initialCapacity |= (initialCapacity >>> 16);
+ initialCapacity++;
+
+ if (initialCapacity < 0) // Too many elements, must back off
+ initialCapacity >>>= 1;// Good luck allocating 2 ^ 30 elements
+ }
+ elements = (E[]) new Object[initialCapacity];
+ }
+
+ /**
+ * Double the capacity of this deque. Call only when full, i.e.,
+ * when head and tail have wrapped around to become equal.
+ */
+ private void doubleCapacity() {
+ assert head == tail;
+ int p = head;
+ int n = elements.length;
+ int r = n - p; // number of elements to the right of p
+ int newCapacity = n << 1;
+ if (newCapacity < 0)
+ throw new IllegalStateException("Sorry, deque too big");
+ Object[] a = new Object[newCapacity];
+ System.arraycopy(elements, p, a, 0, r);
+ System.arraycopy(elements, 0, a, r, p);
+ elements = (E[])a;
+ head = 0;
+ tail = n;
+ }
+
+ /**
+ * Copies the elements from our element array into the specified array,
+ * in order (from first to last element in the deque). It is assumed
+ * that the array is large enough to hold all elements in the deque.
+ *
+ * @return its argument
+ */
+ private <T> T[] copyElements(T[] a) {
+ if (head < tail) {
+ System.arraycopy(elements, head, a, 0, size());
+ } else if (head > tail) {
+ int headPortionLen = elements.length - head;
+ System.arraycopy(elements, head, a, 0, headPortionLen);
+ System.arraycopy(elements, 0, a, headPortionLen, tail);
+ }
+ return a;
+ }
+
+ /**
+ * Constructs an empty array deque with an initial capacity
+ * sufficient to hold 16 elements.
+ */
+ public ArrayDeque() {
+ elements = (E[]) new Object[16];
+ }
+
+ /**
+ * Constructs an empty array deque with an initial capacity
+ * sufficient to hold the specified number of elements.
+ *
+ * @param numElements lower bound on initial capacity of the deque
+ */
+ public ArrayDeque(int numElements) {
+ allocateElements(numElements);
+ }
+
+ /**
+ * Constructs a deque containing the elements of the specified
+ * collection, in the order they are returned by the collection's
+ * iterator. (The first element returned by the collection's
+ * iterator becomes the first element, or <i>front</i> of the
+ * deque.)
+ *
+ * @param c the collection whose elements are to be placed into the deque
+ * @throws NullPointerException if the specified collection is null
+ */
+ public ArrayDeque(Collection<? extends E> c) {
+ allocateElements(c.size());
+ addAll(c);
+ }
+
+ // The main insertion and extraction methods are addFirst,
+ // addLast, pollFirst, pollLast. The other methods are defined in
+ // terms of these.
+
+ /**
+ * Inserts the specified element at the front of this deque.
+ *
+ * @param e the element to add
+ * @throws NullPointerException if the specified element is null
+ */
+ public void addFirst(E e) {
+ if (e == null)
+ throw new NullPointerException();
+ elements[head = (head - 1) & (elements.length - 1)] = e;
+ if (head == tail)
+ doubleCapacity();
+ }
+
+ /**
+ * Inserts the specified element at the end of this deque.
+ *
+ * <p>This method is equivalent to {@link #add}.
+ *
+ * @param e the element to add
+ * @throws NullPointerException if the specified element is null
+ */
+ public void addLast(E e) {
+ if (e == null)
+ throw new NullPointerException();
+ elements[tail] = e;
+ if ( (tail = (tail + 1) & (elements.length - 1)) == head)
+ doubleCapacity();
+ }
+
+ /**
+ * Inserts the specified element at the front of this deque.
+ *
+ * @param e the element to add
+ * @return <tt>true</tt> (as specified by {@link Deque#offerFirst})
+ * @throws NullPointerException if the specified element is null
+ */
+ public boolean offerFirst(E e) {
+ addFirst(e);
+ return true;
+ }
+
+ /**
+ * Inserts the specified element at the end of this deque.
+ *
+ * @param e the element to add
+ * @return <tt>true</tt> (as specified by {@link Deque#offerLast})
+ * @throws NullPointerException if the specified element is null
+ */
+ public boolean offerLast(E e) {
+ addLast(e);
+ return true;
+ }
+
+ /**
+ * @throws NoSuchElementException {@inheritDoc}
+ */
+ public E removeFirst() {
+ E x = pollFirst();
+ if (x == null)
+ throw new NoSuchElementException();
+ return x;
+ }
+
+ /**
+ * @throws NoSuchElementException {@inheritDoc}
+ */
+ public E removeLast() {
+ E x = pollLast();
+ if (x == null)
+ throw new NoSuchElementException();
+ return x;
+ }
+
+ public E pollFirst() {
+ int h = head;
+ E result = elements[h]; // Element is null if deque empty
+ if (result == null)
+ return null;
+ elements[h] = null; // Must null out slot
+ head = (h + 1) & (elements.length - 1);
+ return result;
+ }
+
+ public E pollLast() {
+ int t = (tail - 1) & (elements.length - 1);
+ E result = elements[t];
+ if (result == null)
+ return null;
+ elements[t] = null;
+ tail = t;
+ return result;
+ }
+
+ /**
+ * @throws NoSuchElementException {@inheritDoc}
+ */
+ public E getFirst() {
+ E x = elements[head];
+ if (x == null)
+ throw new NoSuchElementException();
+ return x;
+ }
+
+ /**
+ * @throws NoSuchElementException {@inheritDoc}
+ */
+ public E getLast() {
+ E x = elements[(tail - 1) & (elements.length - 1)];
+ if (x == null)
+ throw new NoSuchElementException();
+ return x;
+ }
+
+ public E peekFirst() {
+ return elements[head]; // elements[head] is null if deque empty
+ }
+
+ public E peekLast() {
+ return elements[(tail - 1) & (elements.length - 1)];
+ }
+
+ /**
+ * Removes the first occurrence of the specified element in this
+ * deque (when traversing the deque from head to tail).
+ * If the deque does not contain the element, it is unchanged.
+ * More formally, removes the first element <tt>e</tt> such that
+ * <tt>o.equals(e)</tt> (if such an element exists).
+ * Returns <tt>true</tt> if this deque contained the specified element
+ * (or equivalently, if this deque changed as a result of the call).
+ *
+ * @param o element to be removed from this deque, if present
+ * @return <tt>true</tt> if the deque contained the specified element
+ */
+ public boolean removeFirstOccurrence(Object o) {
+ if (o == null)
+ return false;
+ int mask = elements.length - 1;
+ int i = head;
+ E x;
+ while ( (x = elements[i]) != null) {
+ if (o.equals(x)) {
+ delete(i);
+ return true;
+ }
+ i = (i + 1) & mask;
+ }
+ return false;
+ }
+
+ /**
+ * Removes the last occurrence of the specified element in this
+ * deque (when traversing the deque from head to tail).
+ * If the deque does not contain the element, it is unchanged.
+ * More formally, removes the last element <tt>e</tt> such that
+ * <tt>o.equals(e)</tt> (if such an element exists).
+ * Returns <tt>true</tt> if this deque contained the specified element
+ * (or equivalently, if this deque changed as a result of the call).
+ *
+ * @param o element to be removed from this deque, if present
+ * @return <tt>true</tt> if the deque contained the specified element
+ */
+ public boolean removeLastOccurrence(Object o) {
+ if (o == null)
+ return false;
+ int mask = elements.length - 1;
+ int i = (tail - 1) & mask;
+ E x;
+ while ( (x = elements[i]) != null) {
+ if (o.equals(x)) {
+ delete(i);
+ return true;
+ }
+ i = (i - 1) & mask;
+ }
+ return false;
+ }
+
+ // *** Queue methods ***
+
+ /**
+ * Inserts the specified element at the end of this deque.
+ *
+ * <p>This method is equivalent to {@link #addLast}.
+ *
+ * @param e the element to add
+ * @return <tt>true</tt> (as specified by {@link Collection#add})
+ * @throws NullPointerException if the specified element is null
+ */
+ public boolean add(E e) {
+ addLast(e);
+ return true;
+ }
+
+ /**
+ * Inserts the specified element at the end of this deque.
+ *
+ * <p>This method is equivalent to {@link #offerLast}.
+ *
+ * @param e the element to add
+ * @return <tt>true</tt> (as specified by {@link Queue#offer})
+ * @throws NullPointerException if the specified element is null
+ */
+ public boolean offer(E e) {
+ return offerLast(e);
+ }
+
+ /**
+ * Retrieves and removes the head of the queue represented by this deque.
+ *
+ * This method differs from {@link #poll poll} only in that it throws an
+ * exception if this deque is empty.
+ *
+ * <p>This method is equivalent to {@link #removeFirst}.
+ *
+ * @return the head of the queue represented by this deque
+ * @throws NoSuchElementException {@inheritDoc}
+ */
+ public E remove() {
+ return removeFirst();
+ }
+
+ /**
+ * Retrieves and removes the head of the queue represented by this deque
+ * (in other words, the first element of this deque), or returns
+ * <tt>null</tt> if this deque is empty.
+ *
+ * <p>This method is equivalent to {@link #pollFirst}.
+ *
+ * @return the head of the queue represented by this deque, or
+ * <tt>null</tt> if this deque is empty
+ */
+ public E poll() {
+ return pollFirst();
+ }
+
+ /**
+ * Retrieves, but does not remove, the head of the queue represented by
+ * this deque. This method differs from {@link #peek peek} only in
+ * that it throws an exception if this deque is empty.
+ *
+ * <p>This method is equivalent to {@link #getFirst}.
+ *
+ * @return the head of the queue represented by this deque
+ * @throws NoSuchElementException {@inheritDoc}
+ */
+ public E element() {
+ return getFirst();
+ }
+
+ /**
+ * Retrieves, but does not remove, the head of the queue represented by
+ * this deque, or returns <tt>null</tt> if this deque is empty.
+ *
+ * <p>This method is equivalent to {@link #peekFirst}.
+ *
+ * @return the head of the queue represented by this deque, or
+ * <tt>null</tt> if this deque is empty
+ */
+ public E peek() {
+ return peekFirst();
+ }
+
+ // *** Stack methods ***
+
+ /**
+ * Pushes an element onto the stack represented by this deque. In other
+ * words, inserts the element at the front of this deque.
+ *
+ * <p>This method is equivalent to {@link #addFirst}.
+ *
+ * @param e the element to push
+ * @throws NullPointerException if the specified element is null
+ */
+ public void push(E e) {
+ addFirst(e);
+ }
+
+ /**
+ * Pops an element from the stack represented by this deque. In other
+ * words, removes and returns the first element of this deque.
+ *
+ * <p>This method is equivalent to {@link #removeFirst()}.
+ *
+ * @return the element at the front of this deque (which is the top
+ * of the stack represented by this deque)
+ * @throws NoSuchElementException {@inheritDoc}
+ */
+ public E pop() {
+ return removeFirst();
+ }
+
+ private void checkInvariants() {
+ assert elements[tail] == null;
+ assert head == tail ? elements[head] == null :
+ (elements[head] != null &&
+ elements[(tail - 1) & (elements.length - 1)] != null);
+ assert elements[(head - 1) & (elements.length - 1)] == null;
+ }
+
+ /**
+ * Removes the element at the specified position in the elements array,
+ * adjusting head and tail as necessary. This can result in motion of
+ * elements backwards or forwards in the array.
+ *
+ * <p>This method is called delete rather than remove to emphasize
+ * that its semantics differ from those of {@link List#remove(int)}.
+ *
+ * @return true if elements moved backwards
+ */
+ private boolean delete(int i) {
+ checkInvariants();
+ final E[] elements = this.elements;
+ final int mask = elements.length - 1;
+ final int h = head;
+ final int t = tail;
+ final int front = (i - h) & mask;
+ final int back = (t - i) & mask;
+
+ // Invariant: head <= i < tail mod circularity
+ if (front >= ((t - h) & mask))
+ throw new ConcurrentModificationException();
+
+ // Optimize for least element motion
+ if (front < back) {
+ if (h <= i) {
+ System.arraycopy(elements, h, elements, h + 1, front);
+ } else { // Wrap around
+ System.arraycopy(elements, 0, elements, 1, i);
+ elements[0] = elements[mask];
+ System.arraycopy(elements, h, elements, h + 1, mask - h);
+ }
+ elements[h] = null;
+ head = (h + 1) & mask;
+ return false;
+ } else {
+ if (i < t) { // Copy the null tail as well
+ System.arraycopy(elements, i + 1, elements, i, back);
+ tail = t - 1;
+ } else { // Wrap around
+ System.arraycopy(elements, i + 1, elements, i, mask - i);
+ elements[mask] = elements[0];
+ System.arraycopy(elements, 1, elements, 0, t);
+ tail = (t - 1) & mask;
+ }
+ return true;
+ }
+ }
+
+ // *** Collection Methods ***
+
+ /**
+ * Returns the number of elements in this deque.
+ *
+ * @return the number of elements in this deque
+ */
+ public int size() {
+ return (tail - head) & (elements.length - 1);
+ }
+
+ /**
+ * Returns <tt>true</tt> if this deque contains no elements.
+ *
+ * @return <tt>true</tt> if this deque contains no elements
+ */
+ public boolean isEmpty() {
+ return head == tail;
+ }
+
+ /**
+ * Returns an iterator over the elements in this deque. The elements
+ * will be ordered from first (head) to last (tail). This is the same
+ * order that elements would be dequeued (via successive calls to
+ * {@link #remove} or popped (via successive calls to {@link #pop}).
+ *
+ * @return an iterator over the elements in this deque
+ */
+ public Iterator<E> iterator() {
+ return new DeqIterator();
+ }
+
+ public Iterator<E> descendingIterator() {
+ return new DescendingIterator();
+ }
+
+ private class DeqIterator implements Iterator<E> {
+ /**
+ * Index of element to be returned by subsequent call to next.
+ */
+ private int cursor = head;
+
+ /**
+ * Tail recorded at construction (also in remove), to stop
+ * iterator and also to check for comodification.
+ */
+ private int fence = tail;
+
+ /**
+ * Index of element returned by most recent call to next.
+ * Reset to -1 if element is deleted by a call to remove.
+ */
+ private int lastRet = -1;
+
+ public boolean hasNext() {
+ return cursor != fence;
+ }
+
+ public E next() {
+ if (cursor == fence)
+ throw new NoSuchElementException();
+ E result = elements[cursor];
+ // This check doesn't catch all possible comodifications,
+ // but does catch the ones that corrupt traversal
+ if (tail != fence || result == null)
+ throw new ConcurrentModificationException();
+ lastRet = cursor;
+ cursor = (cursor + 1) & (elements.length - 1);
+ return result;
+ }
+
+ public void remove() {
+ if (lastRet < 0)
+ throw new IllegalStateException();
+ if (delete(lastRet)) { // if left-shifted, undo increment in next()
+ cursor = (cursor - 1) & (elements.length - 1);
+ fence = tail;
+ }
+ lastRet = -1;
+ }
+ }
+
+ private class DescendingIterator implements Iterator<E> {
+ /*
+ * This class is nearly a mirror-image of DeqIterator, using
+ * tail instead of head for initial cursor, and head instead of
+ * tail for fence.
+ */
+ private int cursor = tail;
+ private int fence = head;
+ private int lastRet = -1;
+
+ public boolean hasNext() {
+ return cursor != fence;
+ }
+
+ public E next() {
+ if (cursor == fence)
+ throw new NoSuchElementException();
+ cursor = (cursor - 1) & (elements.length - 1);
+ E result = elements[cursor];
+ if (head != fence || result == null)
+ throw new ConcurrentModificationException();
+ lastRet = cursor;
+ return result;
+ }
+
+ public void remove() {
+ if (lastRet < 0)
+ throw new IllegalStateException();
+ if (!delete(lastRet)) {
+ cursor = (cursor + 1) & (elements.length - 1);
+ fence = head;
+ }
+ lastRet = -1;
+ }
+ }
+
+ /**
+ * Returns <tt>true</tt> if this deque contains the specified element.
+ * More formally, returns <tt>true</tt> if and only if this deque contains
+ * at least one element <tt>e</tt> such that <tt>o.equals(e)</tt>.
+ *
+ * @param o object to be checked for containment in this deque
+ * @return <tt>true</tt> if this deque contains the specified element
+ */
+ public boolean contains(Object o) {
+ if (o == null)
+ return false;
+ int mask = elements.length - 1;
+ int i = head;
+ E x;
+ while ( (x = elements[i]) != null) {
+ if (o.equals(x))
+ return true;
+ i = (i + 1) & mask;
+ }
+ return false;
+ }
+
+ /**
+ * Removes a single instance of the specified element from this deque.
+ * If the deque does not contain the element, it is unchanged.
+ * More formally, removes the first element <tt>e</tt> such that
+ * <tt>o.equals(e)</tt> (if such an element exists).
+ * Returns <tt>true</tt> if this deque contained the specified element
+ * (or equivalently, if this deque changed as a result of the call).
+ *
+ * <p>This method is equivalent to {@link #removeFirstOccurrence}.
+ *
+ * @param o element to be removed from this deque, if present
+ * @return <tt>true</tt> if this deque cont...
[truncated message content] |
|
From: <ls...@us...> - 2007-06-17 07:16:57
|
Revision: 3267
http://jnode.svn.sourceforge.net/jnode/?rev=3267&view=rev
Author: lsantha
Date: 2007-06-17 00:16:55 -0700 (Sun, 17 Jun 2007)
Log Message:
-----------
Openjdk integration.
Modified Paths:
--------------
trunk/core/src/classpath/java/java/util/jar/JarEntry.java
trunk/core/src/classpath/java/java/util/jar/JarFile.java
Removed Paths:
-------------
trunk/core/src/classpath/java/java/util/Properties.java
Deleted: trunk/core/src/classpath/java/java/util/Properties.java
===================================================================
--- trunk/core/src/classpath/java/java/util/Properties.java 2007-06-17 07:14:11 UTC (rev 3266)
+++ trunk/core/src/classpath/java/java/util/Properties.java 2007-06-17 07:16:55 UTC (rev 3267)
@@ -1,802 +0,0 @@
-/* Properties.java -- a set of persistent properties
- Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 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., 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this
-exception statement from your version. */
-
-
-package java.util;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.OutputStream;
-import java.io.OutputStreamWriter;
-import java.io.PrintStream;
-import java.io.PrintWriter;
-
-import javax.xml.stream.XMLInputFactory;
-import javax.xml.stream.XMLStreamConstants;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
-
-import org.w3c.dom.Document;
-import org.w3c.dom.DocumentType;
-import org.w3c.dom.DOMImplementation;
-import org.w3c.dom.Element;
-import org.w3c.dom.bootstrap.DOMImplementationRegistry;
-import org.w3c.dom.ls.DOMImplementationLS;
-import org.w3c.dom.ls.LSOutput;
-import org.w3c.dom.ls.LSSerializer;
-
-/**
- * A set of persistent properties, which can be saved or loaded from a stream.
- * A property list may also contain defaults, searched if the main list
- * does not contain a property for a given key.
- *
- * An example of a properties file for the german language is given
- * here. This extends the example given in ListResourceBundle.
- * Create a file MyResource_de.properties with the following contents
- * and put it in the CLASSPATH. (The character
- * <code>\</code><code>u00e4</code> is the german umlaut)
- *
- *
-<pre>s1=3
-s2=MeineDisk
-s3=3. M\<code></code>u00e4rz 96
-s4=Die Diskette ''{1}'' enth\<code></code>u00e4lt {0} in {2}.
-s5=0
-s6=keine Dateien
-s7=1
-s8=eine Datei
-s9=2
-s10={0,number} Dateien
-s11=Das Formatieren schlug fehl mit folgender Exception: {0}
-s12=FEHLER
-s13=Ergebnis
-s14=Dialog
-s15=Auswahlkriterium
-s16=1,3</pre>
- *
- * <p>Although this is a sub class of a hash table, you should never
- * insert anything other than strings to this property, or several
- * methods, that need string keys and values, will fail. To ensure
- * this, you should use the <code>get/setProperty</code> method instead
- * of <code>get/put</code>.
- *
- * Properties are saved in ISO 8859-1 encoding, using Unicode escapes with
- * a single <code>u</code> for any character which cannot be represented.
- *
- * @author Jochen Hoenicke
- * @author Eric Blake (eb...@em...)
- * @see PropertyResourceBundle
- * @status updated to 1.4
- */
-public class Properties extends Hashtable<Object, Object>
-{
- // WARNING: Properties is a CORE class in the bootstrap cycle. See the
- // comments in vm/reference/java/lang/Runtime for implications of this fact.
-
- /**
- * The property list that contains default values for any keys not
- * in this property list.
- *
- * @serial the default properties
- */
- protected Properties defaults;
-
- /**
- * Compatible with JDK 1.0+.
- */
- private static final long serialVersionUID = 4112578634029874840L;
-
- /**
- * Creates a new empty property list with no default values.
- */
- public Properties()
- {
- }
-
- /**
- * Create a new empty property list with the specified default values.
- *
- * @param defaults a Properties object containing the default values
- */
- public Properties(Properties defaults)
- {
- this.defaults = defaults;
- }
-
- /**
- * Adds the given key/value pair to this properties. This calls
- * the hashtable method put.
- *
- * @param key the key for this property
- * @param value the value for this property
- * @return The old value for the given key
- * @see #getProperty(String)
- * @since 1.2
- */
- public Object setProperty(String key, String value)
- {
- return put(key, value);
- }
-
- /**
- * Reads a property list from an input stream. The stream should
- * have the following format: <br>
- *
- * An empty line or a line starting with <code>#</code> or
- * <code>!</code> is ignored. An backslash (<code>\</code>) at the
- * end of the line makes the line continueing on the next line
- * (but make sure there is no whitespace after the backslash).
- * Otherwise, each line describes a key/value pair. <br>
- *
- * The chars up to the first whitespace, = or : are the key. You
- * can include this caracters in the key, if you precede them with
- * a backslash (<code>\</code>). The key is followed by optional
- * whitespaces, optionally one <code>=</code> or <code>:</code>,
- * and optionally some more whitespaces. The rest of the line is
- * the resource belonging to the key. <br>
- *
- * Escape sequences <code>\t, \n, \r, \\, \", \', \!, \#, \ </code>(a
- * space), and unicode characters with the
- * <code>\\u</code><em>xxxx</em> notation are detected, and
- * converted to the corresponding single character. <br>
- *
- *
-<pre># This is a comment
-key = value
-k\:5 \ a string starting with space and ending with newline\n
-# This is a multiline specification; note that the value contains
-# no white space.
-weekdays: Sunday,Monday,Tuesday,Wednesday,\\
- Thursday,Friday,Saturday
-# The safest way to include a space at the end of a value:
-label = Name:\\u0020</pre>
- *
- * @param inStream the input stream
- * @throws IOException if an error occurred when reading the input
- * @throws NullPointerException if in is null
- */
- public void load(InputStream inStream) throws IOException
- {
- // The spec says that the file must be encoded using ISO-8859-1.
- BufferedReader reader =
- new BufferedReader(new InputStreamReader(inStream, "ISO-8859-1"));
- String line;
-
- while ((line = reader.readLine()) != null)
- {
- char c = 0;
- int pos = 0;
- // Leading whitespaces must be deleted first.
- while (pos < line.length()
- && Character.isWhitespace(c = line.charAt(pos)))
- pos++;
-
- // If empty line or begins with a comment character, skip this line.
- if ((line.length() - pos) == 0
- || line.charAt(pos) == '#' || line.charAt(pos) == '!')
- continue;
-
- // The characters up to the next Whitespace, ':', or '='
- // describe the key. But look for escape sequences.
- // Try to short-circuit when there is no escape char.
- int start = pos;
- boolean needsEscape = line.indexOf('\\', pos) != -1;
- StringBuilder key = needsEscape ? new StringBuilder() : null;
- while (pos < line.length()
- && ! Character.isWhitespace(c = line.charAt(pos++))
- && c != '=' && c != ':')
- {
- if (needsEscape && c == '\\')
- {
- if (pos == line.length())
- {
- // The line continues on the next line. If there
- // is no next line, just treat it as a key with an
- // empty value.
- line = reader.readLine();
- if (line == null)
- line = "";
- pos = 0;
- while (pos < line.length()
- && Character.isWhitespace(c = line.charAt(pos)))
- pos++;
- }
- else
- {
- c = line.charAt(pos++);
- switch (c)
- {
- case 'n':
- key.append('\n');
- break;
- case 't':
- key.append('\t');
- break;
- case 'r':
- key.append('\r');
- break;
- case 'u':
- if (pos + 4 <= line.length())
- {
- char uni = (char) Integer.parseInt
- (line.substring(pos, pos + 4), 16);
- key.append(uni);
- pos += 4;
- } // else throw exception?
- break;
- default:
- key.append(c);
- break;
- }
- }
- }
- else if (needsEscape)
- key.append(c);
- }
-
- boolean isDelim = (c == ':' || c == '=');
-
- String keyString;
- if (needsEscape)
- keyString = key.toString();
- else if (isDelim || Character.isWhitespace(c))
- keyString = line.substring(start, pos - 1);
- else
- keyString = line.substring(start, pos);
-
- while (pos < line.length()
- && Character.isWhitespace(c = line.charAt(pos)))
- pos++;
-
- if (! isDelim && (c == ':' || c == '='))
- {
- pos++;
- while (pos < line.length()
- && Character.isWhitespace(c = line.charAt(pos)))
- pos++;
- }
-
- // Short-circuit if no escape chars found.
- if (!needsEscape)
- {
- put(keyString, line.substring(pos));
- continue;
- }
-
- // Escape char found so iterate through the rest of the line.
- StringBuilder element = new StringBuilder(line.length() - pos);
- while (pos < line.length())
- {
- c = line.charAt(pos++);
- if (c == '\\')
- {
- if (pos == line.length())
- {
- // The line continues on the next line.
- line = reader.readLine();
-
- // We might have seen a backslash at the end of
- // the file. The JDK ignores the backslash in
- // this case, so we follow for compatibility.
- if (line == null)
- break;
-
- pos = 0;
- while (pos < line.length()
- && Character.isWhitespace(c = line.charAt(pos)))
- pos++;
- element.ensureCapacity(line.length() - pos +
- element.length());
- }
- else
- {
- c = line.charAt(pos++);
- switch (c)
- {
- case 'n':
- element.append('\n');
- break;
- case 't':
- element.append('\t');
- break;
- case 'r':
- element.append('\r');
- break;
- case 'u':
- if (pos + 4 <= line.length())
- {
- char uni = (char) Integer.parseInt
- (line.substring(pos, pos + 4), 16);
- element.append(uni);
- pos += 4;
- } // else throw exception?
- break;
- default:
- element.append(c);
- break;
- }
- }
- }
- else
- element.append(c);
- }
- put(keyString, element.toString());
- }
- }
-
- /**
- * Calls <code>store(OutputStream out, String header)</code> and
- * ignores the IOException that may be thrown.
- *
- * @param out the stream to write to
- * @param header a description of the property list
- * @throws ClassCastException if this property contains any key or
- * value that are not strings
- * @deprecated use {@link #store(OutputStream, String)} instead
- */
- @Deprecated
- public void save(OutputStream out, String header)
- {
- try
- {
- store(out, header);
- }
- catch (IOException ex)
- {
- }
- }
-
- /**
- * Writes the key/value pairs to the given output stream, in a format
- * suitable for <code>load</code>.<br>
- *
- * If header is not null, this method writes a comment containing
- * the header as first line to the stream. The next line (or first
- * line if header is null) contains a comment with the current date.
- * Afterwards the key/value pairs are written to the stream in the
- * following format.<br>
- *
- * Each line has the form <code>key = value</code>. Newlines,
- * Returns and tabs are written as <code>\n,\t,\r</code> resp.
- * The characters <code>\, !, #, =</code> and <code>:</code> are
- * preceeded by a backslash. Spaces are preceded with a backslash,
- * if and only if they are at the beginning of the key. Characters
- * that are not in the ascii range 33 to 127 are written in the
- * <code>\</code><code>u</code>xxxx Form.<br>
- *
- * Following the listing, the output stream is flushed but left open.
- *
- * @param out the output stream
- * @param header the header written in the first line, may be null
- * @throws ClassCastException if this property contains any key or
- * value that isn't a string
- * @throws IOException if writing to the stream fails
- * @throws NullPointerException if out is null
- * @since 1.2
- */
- public void store(OutputStream out, String header) throws IOException
- {
- // The spec says that the file must be encoded using ISO-8859-1.
- PrintWriter writer
- = new PrintWriter(new OutputStreamWriter(out, "ISO-8859-1"));
- if (header != null)
- writer.println("#" + header);
- writer.println ("#" + Calendar.getInstance ().getTime ());
-
- Iterator iter = entrySet ().iterator ();
- int i = size ();
- StringBuilder s = new StringBuilder (); // Reuse the same buffer.
- while (--i >= 0)
- {
- Map.Entry entry = (Map.Entry) iter.next ();
- formatForOutput ((String) entry.getKey (), s, true);
- s.append ('=');
- formatForOutput ((String) entry.getValue (), s, false);
- writer.println (s);
- }
-
- writer.flush ();
- }
-
- /**
- * Gets the property with the specified key in this property list.
- * If the key is not found, the default property list is searched.
- * If the property is not found in the default, null is returned.
- *
- * @param key The key for this property
- * @return the value for the given key, or null if not found
- * @throws ClassCastException if this property contains any key or
- * value that isn't a string
- * @see #defaults
- * @see #setProperty(String, String)
- * @see #getProperty(String, String)
- */
- public String getProperty(String key)
- {
- Properties prop = this;
- // Eliminate tail recursion.
- do
- {
- String value = (String) prop.get(key);
- if (value != null)
- return value;
- prop = prop.defaults;
- }
- while (prop != null);
- return null;
- }
-
- /**
- * Gets the property with the specified key in this property list. If
- * the key is not found, the default property list is searched. If the
- * property is not found in the default, the specified defaultValue is
- * returned.
- *
- * @param key The key for this property
- * @param defaultValue A default value
- * @return The value for the given key
- * @throws ClassCastException if this property contains any key or
- * value that isn't a string
- * @see #defaults
- * @see #setProperty(String, String)
- */
- public String getProperty(String key, String defaultValue)
- {
- String prop = getProperty(key);
- if (prop == null)
- prop = defaultValue;
- return prop;
- }
-
- /**
- * Returns an enumeration of all keys in this property list, including
- * the keys in the default property list.
- *
- * @return an Enumeration of all defined keys
- */
- public Enumeration<?> propertyNames()
- {
- // We make a new Set that holds all the keys, then return an enumeration
- // for that. This prevents modifications from ruining the enumeration,
- // as well as ignoring duplicates.
- Properties prop = this;
- Set s = new HashSet();
- // Eliminate tail recursion.
- do
- {
- s.addAll(prop.keySet());
- prop = prop.defaults;
- }
- while (prop != null);
- return Collections.enumeration(s);
- }
-
- /**
- * Prints the key/value pairs to the given print stream. This is
- * mainly useful for debugging purposes.
- *
- * @param out the print stream, where the key/value pairs are written to
- * @throws ClassCastException if this property contains a key or a
- * value that isn't a string
- * @see #list(PrintWriter)
- */
- public void list(PrintStream out)
- {
- PrintWriter writer = new PrintWriter (out);
- list (writer);
- }
-
- /**
- * Prints the key/value pairs to the given print writer. This is
- * mainly useful for debugging purposes.
- *
- * @param out the print writer where the key/value pairs are written to
- * @throws ClassCastException if this property contains a key or a
- * value that isn't a string
- * @see #list(PrintStream)
- * @since 1.1
- */
- public void list(PrintWriter out)
- {
- out.println ("-- listing properties --");
-
- Iterator iter = entrySet ().iterator ();
- int i = size ();
- while (--i >= 0)
- {
- Map.Entry entry = (Map.Entry) iter.next ();
- out.print ((String) entry.getKey () + "=");
-
- // JDK 1.3/1.4 restrict the printed value, but not the key,
- // to 40 characters, including the truncating ellipsis.
- String s = (String ) entry.getValue ();
- if (s != null && s.length () > 40)
- out.println (s.substring (0, 37) + "...");
- else
- out.println (s);
- }
- out.flush ();
- }
-
- /**
- * Formats a key or value for output in a properties file.
- * See store for a description of the format.
- *
- * @param str the string to format
- * @param buffer the buffer to add it to
- * @param key true if all ' ' must be escaped for the key, false if only
- * leading spaces must be escaped for the value
- * @see #store(OutputStream, String)
- */
- private void formatForOutput(String str, StringBuilder buffer, boolean key)
- {
- if (key)
- {
- buffer.setLength(0);
- buffer.ensureCapacity(str.length());
- }
- else
- buffer.ensureCapacity(buffer.length() + str.length());
- boolean head = true;
- int size = str.length();
- for (int i = 0; i < size; i++)
- {
- char c = str.charAt(i);
- switch (c)
- {
- case '\n':
- buffer.append("\\n");
- break;
- case '\r':
- buffer.append("\\r");
- break;
- case '\t':
- buffer.append("\\t");
- break;
- case ' ':
- buffer.append(head ? "\\ " : " ");
- break;
- case '\\':
- case '!':
- case '#':
- case '=':
- case ':':
- buffer.append('\\').append(c);
- break;
- default:
- if (c < ' ' || c > '~')
- {
- String hex = Integer.toHexString(c);
- buffer.append("\\u0000".substring(0, 6 - hex.length()));
- buffer.append(hex);
- }
- else
- buffer.append(c);
- }
- if (c != ' ')
- head = key;
- }
- }
-
- /**
- * <p>
- * Encodes the properties as an XML file using the UTF-8 encoding.
- * The format of the XML file matches the DTD
- * <a href="http://java.sun.com/dtd/properties.dtd">
- * http://java.sun.com/dtd/properties.dtd</a>.
- * </p>
- * <p>
- * Invoking this method provides the same behaviour as invoking
- * <code>storeToXML(os, comment, "UTF-8")</code>.
- * </p>
- *
- * @param os the stream to output to.
- * @param comment a comment to include at the top of the XML file, or
- * <code>null</code> if one is not required.
- * @throws IOException if the serialization fails.
- * @throws NullPointerException if <code>os</code> is null.
- * @since 1.5
- */
- public void storeToXML(OutputStream os, String comment)
- throws IOException
- {
- storeToXML(os, comment, "UTF-8");
- }
-
- /**
- * <p>
- * Encodes the properties as an XML file using the supplied encoding.
- * The format of the XML file matches the DTD
- * <a href="http://java.sun.com/dtd/properties.dtd">
- * http://java.sun.com/dtd/properties.dtd</a>.
- * </p>
- *
- * @param os the stream to output to.
- * @param comment a comment to include at the top of the XML file, or
- * <code>null</code> if one is not required.
- * @param encoding the encoding to use for the XML output.
- * @throws IOException if the serialization fails.
- * @throws NullPointerException if <code>os</code> or <code>encoding</code>
- * is null.
- * @since 1.5
- */
- public void storeToXML(OutputStream os, String comment, String encoding)
- throws IOException
- {
- if (os == null)
- throw new NullPointerException("Null output stream supplied.");
- if (encoding == null)
- throw new NullPointerException("Null encoding supplied.");
- try
- {
- DOMImplementationRegistry registry =
- DOMImplementationRegistry.newInstance();
- DOMImplementation domImpl = registry.getDOMImplementation("LS 3.0");
- DocumentType doctype =
- domImpl.createDocumentType("properties", null,
- "http://java.sun.com/dtd/properties.dtd");
- Document doc = domImpl.createDocument(null, "properties", doctype);
- Element root = doc.getDocumentElement();
- if (comment != null)
- {
- Element commentElement = doc.createElement("comment");
- commentElement.appendChild(doc.createTextNode(comment));
- root.appendChild(commentElement);
- }
- Iterator iterator = entrySet().iterator();
- while (iterator.hasNext())
- {
- Map.Entry entry = (Map.Entry) iterator.next();
- Element entryElement = doc.createElement("entry");
- entryElement.setAttribute("key", (String) entry.getKey());
- entryElement.appendChild(doc.createTextNode((String)
- entry.getValue()));
- root.appendChild(entryElement);
- }
- DOMImplementationLS loadAndSave = (DOMImplementationLS) domImpl;
- LSSerializer serializer = loadAndSave.createLSSerializer();
- LSOutput output = loadAndSave.createLSOutput();
- output.setByteStream(os);
- output.setEncoding(encoding);
- serializer.write(doc, output);
- }
- catch (ClassNotFoundException e)
- {
- throw (IOException)
- new IOException("The XML classes could not be found.").initCause(e);
- }
- catch (InstantiationException e)
- {
- throw (IOException)
- new IOException("The XML classes could not be instantiated.")
- .initCause(e);
- }
- catch (IllegalAccessException e)
- {
- throw (IOException)
- new IOException("The XML classes could not be accessed.")
- .initCause(e);
- }
- }
-
- /**
- * <p>
- * Decodes the contents of the supplied <code>InputStream</code> as
- * an XML file, which represents a set of properties. The format of
- * the XML file must match the DTD
- * <a href="http://java.sun.com/dtd/properties.dtd">
- * http://java.sun.com/dtd/properties.dtd</a>.
- * </p>
- *
- * @param in the input stream from which to receive the XML data.
- * @throws IOException if an I/O error occurs in reading the input data.
- * @throws InvalidPropertiesFormatException if the input data does not
- * constitute an XML properties
- * file.
- * @throws NullPointerException if <code>in</code> is null.
- * @since 1.5
- */
- public void loadFromXML(InputStream in)
- throws IOException, InvalidPropertiesFormatException
- {
- if (in == null)
- throw new NullPointerException("Null input stream supplied.");
- try
- {
- XMLInputFactory factory = XMLInputFactory.newInstance();
- // Don't resolve external entity references
- factory.setProperty("javax.xml.stream.isSupportingExternalEntities",
- Boolean.FALSE);
- XMLStreamReader reader = factory.createXMLStreamReader(in);
- String name, key = null;
- StringBuffer buf = null;
- while (reader.hasNext())
- {
- switch (reader.next())
- {
- case XMLStreamConstants.START_ELEMENT:
- name = reader.getLocalName();
- if (buf == null && "entry".equals(name))
- {
- key = reader.getAttributeValue(null, "key");
- if (key == null)
- {
- String msg = "missing 'key' attribute";
- throw new InvalidPropertiesFormatException(msg);
- }
- buf = new StringBuffer();
- }
- else if (!"properties".equals(name) && !"comment".equals(name))
- {
- String msg = "unexpected element name '" + name + "'";
- throw new InvalidPropertiesFormatException(msg);
- }
- break;
- case XMLStreamConstants.END_ELEMENT:
- name = reader.getLocalName();
- if (buf != null && "entry".equals(name))
- {
- put(key, buf.toString());
- buf = null;
- }
- else if (!"properties".equals(name) && !"comment".equals(name))
- {
- String msg = "unexpected element name '" + name + "'";
- throw new InvalidPropertiesFormatException(msg);
- }
- break;
- case XMLStreamConstants.CHARACTERS:
- case XMLStreamConstants.SPACE:
- case XMLStreamConstants.CDATA:
- if (buf != null)
- buf.append(reader.getText());
- break;
- }
- }
- reader.close();
- }
- catch (XMLStreamException e)
- {
- throw (InvalidPropertiesFormatException)
- new InvalidPropertiesFormatException("Error in parsing XML.").
- initCause(e);
- }
- }
-
-} // class Properties
Modified: trunk/core/src/classpath/java/java/util/jar/JarEntry.java
===================================================================
--- trunk/core/src/classpath/java/java/util/jar/JarEntry.java 2007-06-17 07:14:11 UTC (rev 3266)
+++ trunk/core/src/classpath/java/java/util/jar/JarEntry.java 2007-06-17 07:16:55 UTC (rev 3267)
@@ -39,6 +39,7 @@
import java.io.IOException;
import java.security.cert.Certificate;
+import java.security.CodeSigner;
import java.util.Set;
import java.util.zip.ZipEntry;
@@ -169,4 +170,9 @@
}
return null;
}
+ //@jnode
+ public CodeSigner[] getCodeSigners() {
+ //todo implement
+ return null;
+ }
}
Modified: trunk/core/src/classpath/java/java/util/jar/JarFile.java
===================================================================
--- trunk/core/src/classpath/java/java/util/jar/JarFile.java 2007-06-17 07:14:11 UTC (rev 3266)
+++ trunk/core/src/classpath/java/java/util/jar/JarFile.java 2007-06-17 07:16:55 UTC (rev 3267)
@@ -806,6 +806,15 @@
return verified > 0;
}
+ //openjdk feature
+ // attribute. Returns false if there is no manifest or the manifest
+ // does not contain a "Class-Path" attribute. Currently exported to
+ // core libraries via sun.misc.SharedSecrets.
+ boolean hasClassPathAttribute() throws IOException {
+ //todo IMPLEMENT
+ return false;
+ }
+
/**
* A utility class that verifies jar entrie...
[truncated message content] |
|
From: <ls...@us...> - 2007-08-11 19:58:16
|
Revision: 3392
http://jnode.svn.sourceforge.net/jnode/?rev=3392&view=rev
Author: lsantha
Date: 2007-08-11 12:58:14 -0700 (Sat, 11 Aug 2007)
Log Message:
-----------
Openjdk integration.
Removed Paths:
-------------
trunk/core/src/classpath/java/java/util/Collection.java
trunk/core/src/classpath/java/java/util/Comparator.java
trunk/core/src/classpath/java/java/util/ConcurrentModificationException.java
trunk/core/src/classpath/java/java/util/Deque.java
trunk/core/src/classpath/java/java/util/DuplicateFormatFlagsException.java
trunk/core/src/classpath/java/java/util/EmptyStackException.java
trunk/core/src/classpath/java/java/util/Enumeration.java
trunk/core/src/classpath/java/java/util/Iterator.java
trunk/core/src/classpath/java/java/util/List.java
trunk/core/src/classpath/java/java/util/Map.java
trunk/core/src/classpath/java/java/util/Queue.java
trunk/core/src/classpath/java/java/util/RandomAccess.java
trunk/core/src/classpath/java/java/util/Set.java
trunk/core/src/classpath/java/java/util/SortedMap.java
trunk/core/src/classpath/java/java/util/SortedSet.java
trunk/core/src/classpath/java/java/util/package.html
Deleted: trunk/core/src/classpath/java/java/util/Collection.java
===================================================================
--- trunk/core/src/classpath/java/java/util/Collection.java 2007-08-11 19:55:49 UTC (rev 3391)
+++ trunk/core/src/classpath/java/java/util/Collection.java 2007-08-11 19:58:14 UTC (rev 3392)
@@ -1,290 +0,0 @@
-/* Collection.java -- Interface that represents a collection of objects
- Copyright (C) 1998, 2001, 2004, 2005 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., 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this
-exception statement from your version. */
-
-
-package java.util;
-
-/**
- * Interface that represents a collection of objects. This interface is the
- * root of the collection hierarchy, and does not provide any guarantees about
- * the order of its elements or whether or not duplicate elements are
- * permitted.
- * <p>
- * All methods of this interface that are defined to modify the collection are
- * defined as <dfn>optional</dfn>. An optional operation may throw an
- * UnsupportedOperationException if the data backing this collection does not
- * support such a modification. This may mean that the data structure is
- * immutable, or that it is read-only but may change ("unmodifiable"), or
- * that it is modifiable but of fixed size (such as an array), or any number
- * of other combinations.
- * <p>
- * A class that wishes to implement this interface should consider subclassing
- * AbstractCollection, which provides basic implementations of most of the
- * methods of this interface. Classes that are prepared to make guarantees
- * about ordering or about absence of duplicate elements should consider
- * implementing List or Set respectively, both of which are subinterfaces of
- * Collection.
- * <p>
- * A general-purpose implementation of the Collection interface should in most
- * cases provide at least two constructors: One which takes no arguments and
- * creates an empty collection, and one which takes a Collection as an argument
- * and returns a collection containing the same elements (that is, creates a
- * copy of the argument using its own implementation).
- *
- * @author Original author unknown
- * @author Eric Blake (eb...@em...)
- * @author Tom Tromey (tr...@re...)
- * @author Andrew John Hughes (gnu...@me...)
- * @see List
- * @see Set
- * @see Map
- * @see SortedSet
- * @see SortedMap
- * @see HashSet
- * @see TreeSet
- * @see ArrayList
- * @see LinkedList
- * @see Vector
- * @see Collections
- * @see Arrays
- * @see AbstractCollection
- * @since 1.2
- * @status updated to 1.4
- */
-public interface Collection<E> extends Iterable<E>
-{
- /**
- * Add an element to this collection.
- *
- * @param o the object to add.
- * @return true if the collection was modified as a result of this action.
- * @throws UnsupportedOperationException if this collection does not
- * support the add operation.
- * @throws ClassCastException if o cannot be added to this collection due
- * to its type.
- * @throws NullPointerException if o is null and this collection doesn't
- * support the addition of null values.
- * @throws IllegalArgumentException if o cannot be added to this
- * collection for some other reason.
- */
- boolean add(E o);
-
- /**
- * Add the contents of a given collection to this collection.
- *
- * @param c the collection to add.
- * @return true if the collection was modified as a result of this action.
- * @throws UnsupportedOperationException if this collection does not
- * support the addAll operation.
- * @throws ClassCastException if some element of c cannot be added to this
- * collection due to its type.
- * @throws NullPointerException if some element of c is null and this
- * collection does not support the addition of null values.
- * @throws NullPointerException if c itself is null.
- * @throws IllegalArgumentException if some element of c cannot be added
- * to this collection for some other reason.
- */
- boolean addAll(Collection<? extends E> c);
-
- /**
- * Clear the collection, such that a subsequent call to isEmpty() would
- * return true.
- *
- * @throws UnsupportedOperationException if this collection does not
- * support the clear operation.
- */
- void clear();
-
- /**
- * Test whether this collection contains a given object as one of its
- * elements.
- *
- * @param o the element to look for.
- * @return true if this collection contains at least one element e such that
- * <code>o == null ? e == null : o.equals(e)</code>.
- * @throws ClassCastException if the type of o is not a valid type for this
- * collection.
- * @throws NullPointerException if o is null and this collection doesn't
- * support null values.
- */
- boolean contains(Object o);
-
- /**
- * Test whether this collection contains every element in a given collection.
- *
- * @param c the collection to test for.
- * @return true if for every element o in c, contains(o) would return true.
- * @throws ClassCastException if the type of any element in c is not a valid
- * type for this collection.
- * @throws NullPointerException if some element of c is null and this
- * collection does not support null values.
- * @throws NullPointerException if c itself is null.
- */
- boolean containsAll(Collection<?> c);
-
- /**
- * Test whether this collection is equal to some object. The Collection
- * interface does not explicitly require any behaviour from this method, and
- * it may be left to the default implementation provided by Object. The Set
- * and List interfaces do, however, require specific behaviour from this
- * method.
- * <p>
- * If an implementation of Collection, which is not also an implementation of
- * Set or List, should choose to implement this method, it should take care
- * to obey the contract of the equals method of Object. In particular, care
- * should be taken to return false when o is a Set or a List, in order to
- * preserve the symmetry of the relation.
- *
- * @param o the object to compare to this collection.
- * @return true if the o is equal to this collection.
- */
- boolean equals(Object o);
-
- /**
- * Obtain a hash code for this collection. The Collection interface does not
- * explicitly require any behaviour from this method, and it may be left to
- * the default implementation provided by Object. The Set and List interfaces
- * do, however, require specific behaviour from this method.
- * <p>
- * If an implementation of Collection, which is not also an implementation of
- * Set or List, should choose to implement this method, it should take care
- * to obey the contract of the hashCode method of Object. Note that this
- * method renders it impossible to correctly implement both Set and List, as
- * the required implementations are mutually exclusive.
- *
- * @return a hash code for this collection.
- */
- int hashCode();
-
- /**
- * Test whether this collection is empty, that is, if size() == 0.
- *
- * @return true if this collection contains no elements.
- */
- boolean isEmpty();
-
- /**
- * Obtain an Iterator over this collection.
- *
- * @return an Iterator over the elements of this collection, in any order.
- */
- Iterator<E> iterator();
-
- /**
- * Remove a single occurrence of an object from this collection. That is,
- * remove an element e, if one exists, such that <code>o == null ? e == null
- * : o.equals(e)</code>.
- *
- * @param o the object to remove.
- * @return true if the collection changed as a result of this call, that is,
- * if the collection contained at least one occurrence of o.
- * @throws UnsupportedOperationException if this collection does not
- * support the remove operation.
- * @throws ClassCastException if the type of o is not a valid type
- * for this collection.
- * @throws NullPointerException if o is null and the collection doesn't
- * support null values.
- */
- boolean remove(Object o);
-
- /**
- * Remove all elements of a given collection from this collection. That is,
- * remove every element e such that c.contains(e).
- *
- * @param c The collection of objects to be removed.
- * @return true if this collection was modified as a result of this call.
- * @throws UnsupportedOperationException if this collection does not
- * support the removeAll operation.
- * @throws ClassCastException if the type of any element in c is not a valid
- * type for this collection.
- * @throws NullPointerException if some element of c is null and this
- * collection does not support removing null values.
- * @throws NullPointerException if c itself is null.
- */
- boolean removeAll(Collection<?> c);
-
- /**
- * Remove all elements of this collection that are not contained in a given
- * collection. That is, remove every element e such that !c.contains(e).
- *
- * @param c The collection of objects to be retained.
- * @return true if this collection was modified as a result of this call.
- * @throws UnsupportedOperationException if this collection does not
- * support the retainAll operation.
- * @throws ClassCastException if the type of any element in c is not a valid
- * type for this collection.
- * @throws NullPointerException if some element of c is null and this
- * collection does not support retaining null values.
- * @throws NullPointerException if c itself is null.
- */
- boolean retainAll(Collection<?> c);
-
- /**
- * Get the number of elements in this collection.
- *
- * @return the number of elements in the collection.
- */
- int size();
-
- /**
- * Copy the current contents of this collection into an array.
- *
- * @return an array of type Object[] and length equal to the size of this
- * collection, containing the elements currently in this collection, in
- * any order.
- */
- Object[] toArray();
-
- /**
- * Copy the current contents of this collection into an array. If the array
- * passed as an argument has length less than the size of this collection, an
- * array of the same run-time type as a, and length equal to the size of this
- * collection, is allocated using Reflection. Otherwise, a itself is used.
- * The elements of this collection are copied into it, and if there is space
- * in the array, the following element is set to null. The resultant array is
- * returned.
- * Note: The fact that the following element is set to null is only useful
- * if it is known that this collection does not contain any null elements.
- *
- * @param a the array to copy this collection into.
- * @return an array containing the elements currently in this collection, in
- * any order.
- * @throws ArrayStoreException if the type of any element of the
- * collection is not a subtype of the element type of a.
- */
- <T> T[] toArray(T[] a);
-}
Deleted: trunk/core/src/classpath/java/java/util/Comparator.java
===================================================================
--- trunk/core/src/classpath/java/java/util/Comparator.java 2007-08-11 19:55:49 UTC (rev 3391)
+++ trunk/core/src/classpath/java/java/util/Comparator.java 2007-08-11 19:58:14 UTC (rev 3392)
@@ -1,119 +0,0 @@
-/* Comparator.java -- Interface for objects that specify an ordering
- Copyright (C) 1998, 2001, 2004, 2005 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., 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this
-exception statement from your version. */
-
-
-package java.util;
-
-/**
- * Interface for objects that specify an ordering between objects. The ordering
- * should be <em>total</em>, such that any two objects of the correct type
- * can be compared, and the comparison is reflexive, anti-symmetric, and
- * transitive. It is also recommended that the comparator be <em>consistent
- * with equals</em>, although this is not a strict requirement. A relation
- * is consistent with equals if these two statements always have the same
- * results (if no exceptions occur):<br>
- * <code>compare((Object) e1, (Object) e2) == 0</code> and
- * <code>e1.equals((Object) e2)</code><br>
- * Comparators that violate consistency with equals may cause strange behavior
- * in sorted lists and sets. For example, a case-sensitive dictionary order
- * comparison of Strings is consistent with equals, but if it is
- * case-insensitive it is not, because "abc" and "ABC" compare as equal even
- * though "abc".equals("ABC") returns false.
- * <P>
- * In general, Comparators should be Serializable, because when they are passed
- * to Serializable data structures such as SortedMap or SortedSet, the entire
- * data structure will only serialize correctly if the comparator is
- * Serializable.
- *
- * @author Original author unknown
- * @author Eric Blake (eb...@em...)
- * @see Comparable
- * @see TreeMap
- * @see TreeSet
- * @see SortedMap
- * @see SortedSet
- * @see Arrays#sort(Object[], Comparator)
- * @see java.io.Serializable
- * @since 1.2
- * @status updated to 1.4
- */
-public interface Comparator<T>
-{
- /**
- * Return an integer that is negative, zero or positive depending on whether
- * the first argument is less than, equal to or greater than the second
- * according to this ordering. This method should obey the following
- * contract:
- * <ul>
- * <li>if compare(a, b) < 0 then compare(b, a) > 0</li>
- * <li>if compare(a, b) throws an exception, so does compare(b, a)</li>
- * <li>if compare(a, b) < 0 and compare(b, c) < 0 then compare(a, c)
- * < 0</li>
- * <li>if compare(a, b) == 0 then compare(a, c) and compare(b, c) must
- * have the same sign</li>
- * </ul>
- * To be consistent with equals, the following additional constraint is
- * in place:
- * <ul>
- * <li>if a.equals(b) or both a and b are null, then
- * compare(a, b) == 0.</li>
- * </ul><p>
- *
- * Although it is permissible for a comparator to provide an order
- * inconsistent with equals, that should be documented.
- *
- * @param o1 the first object
- * @param o2 the second object
- * @return the comparison
- * @throws ClassCastException if the elements are not of types that can be
- * compared by this ordering.
- */
- int compare(T o1, T o2);
-
- /**
- * Return true if the object is equal to this object. To be
- * considered equal, the argument object must satisfy the constraints
- * of <code>Object.equals()</code>, be a Comparator, and impose the
- * same ordering as this Comparator. The default implementation
- * inherited from Object is usually adequate.
- *
- * @param obj The object
- * @return true if it is a Comparator that imposes the same order
- * @see Object#equals(Object)
- */
- boolean equals(Object obj);
-}
Deleted: trunk/core/src/classpath/java/java/util/ConcurrentModificationException.java
===================================================================
--- trunk/core/src/classpath/java/java/util/ConcurrentModificationException.java 2007-08-11 19:55:49 UTC (rev 3391)
+++ trunk/core/src/classpath/java/java/util/ConcurrentModificationException.java 2007-08-11 19:58:14 UTC (rev 3392)
@@ -1,92 +0,0 @@
-/* ConcurrentModificationException.java -- Data structure concurrently modified
- Copyright (C) 1998, 1999, 2001, 2005 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., 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this
-exception statement from your version. */
-
-
-package java.util;
-
-/* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3
- * "The Java Language Specification", ISBN 0-201-63451-1
- * plus online API docs for JDK 1.2 beta from http://www.javasoft.com.
- */
-
-/**
- * Exception that is thrown by the collections classes when it is detected that
- * a modification has been made to a data structure when this is not allowed,
- * such as when a collection is structurally modified while an Iterator is
- * operating over it. In cases where this can be detected, a
- * ConcurrentModificationException will be thrown. An Iterator that detects
- * this condition is referred to as fail-fast. Notice that this can occur
- * even in single-threaded designs, if you call methods out of order.
- *
- * @author Warren Levy (wa...@cy...)
- * @author Eric Blake (eb...@em...)
- * @see Collection
- * @see Iterator
- * @see ListIterator
- * @see Vector
- * @see LinkedList
- * @see HashSet
- * @see Hashtable
- * @see TreeMap
- * @see AbstractList
- * @since 1.2
- * @status updated to 1.4
- */
-public class ConcurrentModificationException extends RuntimeException
-{
- /**
- * Compatible with JDK 1.2.
- */
- private static final long serialVersionUID = -3666751008965953603L;
-
- /**
- * Constructs a ConcurrentModificationException with no detail message.
- */
- public ConcurrentModificationException()
- {
- }
-
- /**
- * Constructs a ConcurrentModificationException with a detail message.
- *
- * @param detail the detail message for the exception
- */
- public ConcurrentModificationException(String detail)
- {
- super(detail);
- }
-}
Deleted: trunk/core/src/classpath/java/java/util/Deque.java
===================================================================
--- trunk/core/src/classpath/java/java/util/Deque.java 2007-08-11 19:55:49 UTC (rev 3391)
+++ trunk/core/src/classpath/java/java/util/Deque.java 2007-08-11 19:58:14 UTC (rev 3392)
@@ -1,547 +0,0 @@
-/*
- * Written by Doug Lea and Josh Bloch with assistance from members of
- * JCP JSR-166 Expert Group and released to the public domain, as explained
- * at http://creativecommons.org/licenses/publicdomain
- */
-
-package java.util;
-
-/**
- * A linear collection that supports element insertion and removal at
- * both ends. The name <i>deque</i> is short for "double ended queue"
- * and is usually pronounced "deck". Most <tt>Deque</tt>
- * implementations place no fixed limits on the number of elements
- * they may contain, but this interface supports capacity-restricted
- * deques as well as those with no fixed size limit.
- *
- * <p>This interface defines methods to access the elements at both
- * ends of the deque. Methods are provided to insert, remove, and
- * examine the element. Each of these methods exists in two forms:
- * one throws an exception if the operation fails, the other returns a
- * special value (either <tt>null</tt> or <tt>false</tt>, depending on
- * the operation). The latter form of the insert operation is
- * designed specifically for use with capacity-restricted
- * <tt>Deque</tt> implementations; in most implementations, insert
- * operations cannot fail.
- *
- * <p>The twelve methods described above are summarized in the
- * following table:
- *
- * <p>
- * <table BORDER CELLPADDING=3 CELLSPACING=1>
- * <tr>
- * <td></td>
- * <td ALIGN=CENTER COLSPAN = 2> <b>First Element (Head)</b></td>
- * <td ALIGN=CENTER COLSPAN = 2> <b>Last Element (Tail)</b></td>
- * </tr>
- * <tr>
- * <td></td>
- * <td ALIGN=CENTER><em>Throws exception</em></td>
- * <td ALIGN=CENTER><em>Special value</em></td>
- * <td ALIGN=CENTER><em>Throws exception</em></td>
- * <td ALIGN=CENTER><em>Special value</em></td>
- * </tr>
- * <tr>
- * <td><b>Insert</b></td>
- * <td>{@link #addFirst addFirst(e)}</td>
- * <td>{@link #offerFirst offerFirst(e)}</td>
- * <td>{@link #addLast addLast(e)}</td>
- * <td>{@link #offerLast offerLast(e)}</td>
- * </tr>
- * <tr>
- * <td><b>Remove</b></td>
- * <td>{@link #removeFirst removeFirst()}</td>
- * <td>{@link #pollFirst pollFirst()}</td>
- * <td>{@link #removeLast removeLast()}</td>
- * <td>{@link #pollLast pollLast()}</td>
- * </tr>
- * <tr>
- * <td><b>Examine</b></td>
- * <td>{@link #getFirst getFirst()}</td>
- * <td>{@link #peekFirst peekFirst()}</td>
- * <td>{@link #getLast getLast()}</td>
- * <td>{@link #peekLast peekLast()}</td>
- * </tr>
- * </table>
- *
- * <p>This interface extends the {@link Queue} interface. When a deque is
- * used as a queue, FIFO (First-In-First-Out) behavior results. Elements are
- * added at the end of the deque and removed from the beginning. The methods
- * inherited from the <tt>Queue</tt> interface are precisely equivalent to
- * <tt>Deque</tt> methods as indicated in the following table:
- *
- * <p>
- * <table BORDER CELLPADDING=3 CELLSPACING=1>
- * <tr>
- * <td ALIGN=CENTER> <b><tt>Queue</tt> Method</b></td>
- * <td ALIGN=CENTER> <b>Equivalent <tt>Deque</tt> Method</b></td>
- * </tr>
- * <tr>
- * <td>{@link java.util.Queue#add add(e)}</td>
- * <td>{@link #addLast addLast(e)}</td>
- * </tr>
- * <tr>
- * <td>{@link java.util.Queue#offer offer(e)}</td>
- * <td>{@link #offerLast offerLast(e)}</td>
- * </tr>
- * <tr>
- * <td>{@link java.util.Queue#remove remove()}</td>
- * <td>{@link #removeFirst removeFirst()}</td>
- * </tr>
- * <tr>
- * <td>{@link java.util.Queue#poll poll()}</td>
- * <td>{@link #pollFirst pollFirst()}</td>
- * </tr>
- * <tr>
- * <td>{@link java.util.Queue#element element()}</td>
- * <td>{@link #getFirst getFirst()}</td>
- * </tr>
- * <tr>
- * <td>{@link java.util.Queue#peek peek()}</td>
- * <td>{@link #peek peekFirst()}</td>
- * </tr>
- * </table>
- *
- * <p>Deques can also be used as LIFO (Last-In-First-Out) stacks. This
- * interface should be used in preference to the legacy {@link Stack} class.
- * When a deque is used as a stack, elements are pushed and popped from the
- * beginning of the deque. Stack methods are precisely equivalent to
- * <tt>Deque</tt> methods as indicated in the table below:
- *
- * <p>
- * <table BORDER CELLPADDING=3 CELLSPACING=1>
- * <tr>
- * <td ALIGN=CENTER> <b>Stack Method</b></td>
- * <td ALIGN=CENTER> <b>Equivalent <tt>Deque</tt> Method</b></td>
- * </tr>
- * <tr>
- * <td>{@link #push push(e)}</td>
- * <td>{@link #addFirst addFirst(e)}</td>
- * </tr>
- * <tr>
- * <td>{@link #pop pop()}</td>
- * <td>{@link #removeFirst removeFirst()}</td>
- * </tr>
- * <tr>
- * <td>{@link #peek peek()}</td>
- * <td>{@link #peekFirst peekFirst()}</td>
- * </tr>
- * </table>
- *
- * <p>Note that the {@link #peek peek} method works equally well when
- * a deque is used as a queue or a stack; in either case, elements are
- * drawn from the beginning of the deque.
- *
- * <p>This interface provides two methods to remove interior
- * elements, {@link #removeFirstOccurrence removeFirstOccurrence} and
- * {@link #removeLastOccurrence removeLastOccurrence}.
- *
- * <p>Unlike the {@link List} interface, this interface does not
- * provide support for indexed access to elements.
- *
- * <p>While <tt>Deque</tt> implementations are not strictly required
- * to prohibit the insertion of null elements, they are strongly
- * encouraged to do so. Users of any <tt>Deque</tt> implementations
- * that do allow null elements are strongly encouraged <i>not</i> to
- * take advantage of the ability to insert nulls. This is so because
- * <tt>null</tt> is used as a special return value by various methods
- * to indicated that the deque is empty.
- *
- * <p><tt>Deque</tt> implementations generally do not define
- * element-based versions of the <tt>equals</tt> and <tt>hashCode</tt>
- * methods, but instead inherit the identity-based versions from class
- * <tt>Object</tt>.
- *
- * <p>This interface is a member of the <a
- * href="{@docRoot}/../technotes/guides/collections/index.html"> Java Collections
- * Framework</a>.
- *
- * @author Doug Lea
- * @author Josh Bloch
- * @since 1.6
- * @param <E> the type of elements held in this collection
- */
-
-public interface Deque<E> extends Queue<E> {
- /**
- * Inserts the specified element at the front of this deque if it is
- * possible to do so immediately without violating capacity restrictions.
- * When using a capacity-restricted deque, it is generally preferable to
- * use method {@link #offerFirst}.
- *
- * @param e the element to add
- * @throws IllegalStateException if the element cannot be added at this
- * time due to capacity restrictions
- * @throws ClassCastException if the class of the specified element
- *...
[truncated message content] |
|
From: <ls...@us...> - 2007-10-06 20:33:18
|
Revision: 3539
http://jnode.svn.sourceforge.net/jnode/?rev=3539&view=rev
Author: lsantha
Date: 2007-10-06 13:33:17 -0700 (Sat, 06 Oct 2007)
Log Message:
-----------
Openjdk integration of the Collections framework.
Removed Paths:
-------------
trunk/core/src/classpath/java/java/util/AbstractCollection.java
trunk/core/src/classpath/java/java/util/AbstractList.java
trunk/core/src/classpath/java/java/util/AbstractMap.java
trunk/core/src/classpath/java/java/util/AbstractQueue.java
trunk/core/src/classpath/java/java/util/AbstractSequentialList.java
trunk/core/src/classpath/java/java/util/AbstractSet.java
trunk/core/src/classpath/java/java/util/ArrayDeque.java
trunk/core/src/classpath/java/java/util/ArrayList.java
trunk/core/src/classpath/java/java/util/Collections.java
trunk/core/src/classpath/java/java/util/Dictionary.java
trunk/core/src/classpath/java/java/util/EnumMap.java
trunk/core/src/classpath/java/java/util/HashMap.java
trunk/core/src/classpath/java/java/util/HashSet.java
trunk/core/src/classpath/java/java/util/Hashtable.java
trunk/core/src/classpath/java/java/util/IdentityHashMap.java
trunk/core/src/classpath/java/java/util/LinkedHashMap.java
trunk/core/src/classpath/java/java/util/LinkedHashSet.java
trunk/core/src/classpath/java/java/util/LinkedList.java
trunk/core/src/classpath/java/java/util/PriorityQueue.java
trunk/core/src/classpath/java/java/util/Stack.java
trunk/core/src/classpath/java/java/util/TreeMap.java
trunk/core/src/classpath/java/java/util/TreeSet.java
trunk/core/src/classpath/java/java/util/Vector.java
trunk/core/src/classpath/java/java/util/WeakHashMap.java
Deleted: trunk/core/src/classpath/java/java/util/AbstractCollection.java
===================================================================
--- trunk/core/src/classpath/java/java/util/AbstractCollection.java 2007-10-06 20:30:32 UTC (rev 3538)
+++ trunk/core/src/classpath/java/java/util/AbstractCollection.java 2007-10-06 20:33:17 UTC (rev 3539)
@@ -1,480 +0,0 @@
-/* AbstractCollection.java -- Abstract implementation of most of Collection
- Copyright (C) 1998, 2000, 2001, 2004, 2005 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., 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this
-exception statement from your version. */
-
-
-package java.util;
-
-import java.lang.reflect.Array;
-
-/**
- * A basic implementation of most of the methods in the Collection interface to
- * make it easier to create a collection. To create an unmodifiable Collection,
- * just subclass AbstractCollection and provide implementations of the
- * iterator() and size() methods. The Iterator returned by iterator() need only
- * provide implementations of hasNext() and next() (that is, it may throw an
- * UnsupportedOperationException if remove() is called). To create a modifiable
- * Collection, you must in addition provide an implementation of the
- * add(Object) method and the Iterator returned by iterator() must provide an
- * implementation of remove(). Other methods should be overridden if the
- * backing data structure allows for a more efficient implementation. The
- * precise implementation used by AbstractCollection is documented, so that
- * subclasses can tell which methods could be implemented more efficiently.
- * <p>
- *
- * The programmer should provide a no-argument constructor, and one that
- * accepts another Collection, as recommended by the Collection interface.
- * Unfortunately, there is no way to enforce this in Java.
- *
- * @author Original author unknown
- * @author Bryce McKinlay
- * @author Eric Blake (eb...@em...)
- * @author Tom Tromey (tr...@re...)
- * @author Andrew John Hughes (gnu...@me...)
- * @see Collection
- * @see AbstractSet
- * @see AbstractList
- * @since 1.2
- * @status updated to 1.4
- */
-public abstract class AbstractCollection<E>
- implements Collection<E>, Iterable<E>
-{
- /**
- * The main constructor, for use by subclasses.
- */
- protected AbstractCollection()
- {
- }
-
- /**
- * Return an Iterator over this collection. The iterator must provide the
- * hasNext and next methods and should in addition provide remove if the
- * collection is modifiable.
- *
- * @return an iterator
- */
- public abstract Iterator<E> iterator();
-
- /**
- * Return the number of elements in this collection. If there are more than
- * Integer.MAX_VALUE elements, return Integer.MAX_VALUE.
- *
- * @return the size
- */
- public abstract int size();
-
- /**
- * Add an object to the collection (optional operation). This implementation
- * always throws an UnsupportedOperationException - it should be
- * overridden if the collection is to be modifiable. If the collection
- * does not accept duplicates, simply return false. Collections may specify
- * limitations on what may be added.
- *
- * @param o the object to add
- * @return true if the add operation caused the Collection to change
- * @throws UnsupportedOperationException if the add operation is not
- * supported on this collection
- * @throws NullPointerException if the collection does not support null
- * @throws ClassCastException if the object is of the wrong type
- * @throws IllegalArgumentException if some aspect of the object prevents
- * it from being added
- */
- public boolean add(E o)
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * Add all the elements of a given collection to this collection (optional
- * operation). This implementation obtains an Iterator over the given
- * collection and iterates over it, adding each element with the
- * add(Object) method (thus this method will fail with an
- * UnsupportedOperationException if the add method does). The behavior is
- * unspecified if the specified collection is modified during the iteration,
- * including the special case of trying addAll(this) on a non-empty
- * collection.
- *
- * @param c the collection to add the elements of to this collection
- * @return true if the add operation caused the Collection to change
- * @throws UnsupportedOperationException if the add operation is not
- * supported on this collection
- * @throws NullPointerException if the specified collection is null
- * @throws ClassCastException if the type of any element in c is
- * not a valid type for addition.
- * @throws IllegalArgumentException if some aspect of any element
- * in c prevents it being added.
- * @throws NullPointerException if any element in c is null and this
- * collection doesn't allow null values.
- * @see #add(Object)
- */
- public boolean addAll(Collection<? extends E> c)
- {
- Iterator<? extends E> itr = c.iterator();
- boolean modified = false;
- int pos = c.size();
- while (--pos >= 0)
- modified |= add(itr.next());
- return modified;
- }
-
- /**
- * Remove all elements from the collection (optional operation). This
- * implementation obtains an iterator over the collection and calls next
- * and remove on it repeatedly (thus this method will fail with an
- * UnsupportedOperationException if the Iterator's remove method does)
- * until there are no more elements to remove.
- * Many implementations will have a faster way of doing this.
- *
- * @throws UnsupportedOperationException if the Iterator returned by
- * iterator does not provide an implementation of remove
- * @see Iterator#remove()
- */
- public void clear()
- {
- Iterator<E> itr = iterator();
- int pos = size();
- while (--pos >= 0)
- {
- itr.next();
- itr.remove();
- }
- }
-
- /**
- * Test whether this collection contains a given object. That is, if the
- * collection has an element e such that (o == null ? e == null :
- * o.equals(e)). This implementation obtains an iterator over the collection
- * and iterates over it, testing each element for equality with the given
- * object. If it is equal, true is returned. Otherwise false is returned when
- * the end of the collection is reached.
- *
- * @param o the object to remove from this collection
- * @return true if this collection contains an object equal to o
- */
- public boolean contains(Object o)
- {
- Iterator<E> itr = iterator();
- int pos = size();
- while (--pos >= 0)
- if (equals(o, itr.next()))
- return true;
- return false;
- }
-
- /**
- * Tests whether this collection contains all the elements in a given
- * collection. This implementation iterates over the given collection,
- * testing whether each element is contained in this collection. If any one
- * is not, false is returned. Otherwise true is returned.
- *
- * @param c the collection to test against
- * @return true if this collection contains all the elements in the given
- * collection
- * @throws NullPointerException if the given collection is null
- * @see #contains(Object)
- */
- public boolean containsAll(Collection<?> c)
- {
- Iterator<?> itr = c.iterator();
- int pos = c.size();
- while (--pos >= 0)
- if (!contains(itr.next()))
- return false;
- return true;
- }
-
- /**
- * Test whether this collection is empty. This implementation returns
- * size() == 0.
- *
- * @return true if this collection is empty.
- * @see #size()
- */
- public boolean isEmpty()
- {
- return size() == 0;
- }
-
- /**
- * Remove a single instance of an object from this collection (optional
- * operation). That is, remove one element e such that
- * <code>(o == null ? e == null : o.equals(e))</code>, if such an element
- * exists. This implementation obtains an iterator over the collection
- * and iterates over it, testing each element for equality with the given
- * object. If it is equal, it is removed by the iterator's remove method
- * (thus this method will fail with an UnsupportedOperationException if
- * the Iterator's remove method does). After the first element has been
- * removed, true is returned; if the end of the collection is reached, false
- * is returned.
- *
- * @param o the object to remove from this collection
- * @return true if the remove operation caused the Collection to change, or
- * equivalently if the collection did contain o.
- * @throws UnsupportedOperationException if this collection's Iterator
- * does not support the remove method
- * @see Iterator#remove()
- */
- public boolean remove(Object o)
- {
- Iterator<E> itr = iterator();
- int pos = size();
- while (--pos >= 0)
- if (equals(o, itr.next()))
- {
- itr.remove();
- return true;
- }
- return false;
- }
-
- /**
- * Remove from this collection all its elements that are contained in a given
- * collection (optional operation). This implementation iterates over this
- * collection, and for each element tests if it is contained in the given
- * collection. If so, it is removed by the Iterator's remove method (thus
- * this method will fail with an UnsupportedOperationException if the
- * Iterator's remove method does).
- *
- * @param c the collection to remove the elements of
- * @return true if the remove operation caused the Collection to change
- * @throws UnsupportedOperationException if this collection's Iterator
- * does not support the remove method
- * @throws NullPointerException if the collection, c, is null.
- * @see Iterator#remove()
- */
- public boolean removeAll(Collection<?> c)
- {
- return removeAllInternal(c);
- }
-
- /**
- * Remove from this collection all its elements that are contained in a given
- * collection (optional operation). This implementation iterates over this
- * collection, and for each element tests if it is contained in the given
- * collection. If so, it is removed by the Iterator's remove method (thus
- * this method will fail with an UnsupportedOperationException if the
- * Iterator's remove method does). This method is necessary for ArrayList,
- * which cannot publicly override removeAll but can optimize this call.
- *
- * @param c the collection to remove the elements of
- * @return true if the remove operation caused the Collection to change
- * @throws UnsupportedOperationException if this collection's Iterator
- * does not support the remove method
- * @throws NullPointerException if the collection, c, is null.
- * @see Iterator#remove()
- */
- // Package visible for use throughout java.util.
- boolean removeAllInternal(Collection<?> c)
- {
- Iterator<E> itr = iterator();
- boolean modified = false;
- int pos = size();
- while (--pos >= 0)
- if (c.contains(itr.next()))
- {
- itr.remove();
- modified = true;
- }
- return modified;
- }
-
- /**
- * Remove from this collection all its elements that are not contained in a
- * given collection (optional operation). This implementation iterates over
- * this collection, and for each element tests if it is contained in the
- * given collection. If not, it is removed by the Iterator's remove method
- * (thus this method will fail with an UnsupportedOperationException if
- * the Iterator's remove method does).
- *
- * @param c the collection to retain the elements of
- * @return true if the remove operation caused the Collection to change
- * @throws UnsupportedOperationException if this collection's Iterator
- * does not support the remove method
- * @throws NullPointerException if the collection, c, is null.
- * @see Iterator#remove()
- */
- public boolean retainAll(Collection<?> c)
- {
- return retainAllInternal(c);
- }
-
- /**
- * Remove from this collection all its elements that are not contained in a
- * given collection (optional operation). This implementation iterates over
- * this collection, and for each element tests if it is contained in the
- * given collection. If not, it is removed by the Iterator's remove method
- * (thus this method will fail with an UnsupportedOperationException if
- * the Iterator's remove method does). This method is necessary for
- * ArrayList, which cannot publicly override retainAll but can optimize
- * this call.
- *
- * @param c the collection to retain the elements of
- * @return true if the remove operation caused the Collection to change
- * @throws UnsupportedOperationException if this collection's Iterator
- * does not support the remove method
- * @throws NullPointerException if the collection, c, is null.
- * @see Iterator#remove()
- */
- // Package visible for use throughout java.util.
- boolean retainAllInternal(Collection<?> c)
- {
- Iterator<E> itr = iterator();
- boolean modified = false;
- int pos = size();
- while (--pos >= 0)
- if (!c.contains(itr.next()))
- {
- itr.remove();
- modified = true;
- }
- return modified;
- }
-
- /**
- * Return an array containing the elements of this collection. This
- * implementation creates an Object array of size size() and then iterates
- * over the collection, setting each element of the array from the value
- * returned by the iterator. The returned array is safe, and is not backed
- * by the collection.
- *
- * @return an array containing the elements of this collection
- */
- public Object[] toArray()
- {
- Iterator<E> itr = iterator();
- int size = size();
- Object[] a = new Object[size];
- for (int pos = 0; pos < size; pos++)
- a[pos] = itr.next();
- return a;
- }
-
- /**
- * Copy the collection into a given array if it will fit, or into a
- * dynamically created array of the same run-time type as the given array if
- * not. If there is space remaining in the array, the first element after the
- * end of the collection is set to null (this is only useful if the
- * collection is known to contain no null elements, however). This
- * implementation first tests whether the given array is large enough to hold
- * all the elements of the collection. If not, the reflection API is used to
- * allocate a new array of the same run-time type. Next an iterator is
- * obtained over the collection and the elements are placed in the array as
- * they are returned by the iterator. Finally the first spare element, if
- * any, of the array is set to null, and the created array is returned.
- * The returned array is safe; it is not backed by the collection. Note that
- * null may not mark the last element, if the collection allows null
- * elements.
- *
- * @param a the array to copy into, or of the correct run-time type
- * @return the array that was produced
- * @throws NullPointerException if the given array is null
- * @throws ArrayStoreException if the type of the array precludes holding
- * one of the elements of the Collection
- */
- public <T> T[] toArray(T[] a)
- {
- int size = size();
- if (a.length < size)
- a = (T[]) Array.newInstance(a.getClass().getComponentType(),
- size);
- else if (a.length > size)
- a[size] = null;
-
- Iterator<E> itr = iterator();
- for (int pos = 0; pos < size; pos++)
- a[pos] = (T) (itr.next());
- return a;
- }
-
- /**
- * Creates a String representation of the Collection. The string returned is
- * of the form "[a, b, ...]" where a and b etc are the results of calling
- * toString on the elements of the collection. This implementation obtains an
- * Iterator over the Collection and adds each element to a StringBuffer as it
- * is returned by the iterator. "<this>" is inserted when the collection
- * contains itself (only works for direct containment, not for collections
- * inside collections).
- *
- * @return a String representation of the Collection
- */
- public String toString()
- {
- Iterator itr = iterator();
- StringBuffer r = new StringBuffer("[");
- boolean hasNext = itr.hasNext();
- while (hasNext)
- {
- Object o = itr.next();
- if (o == this)
- r.append("<this>");
- else
- r.append(o);
- hasNext = itr.hasNext();
- if (hasNext)
- r.append(", ");
- }
- r.append("]");
- return r.toString();
- }
-
- /**
- * Compare two objects according to Collection semantics.
- *
- * @param o1 the first object
- * @param o2 the second object
- * @return o1 == null ? o2 == null : o1.equals(o2)
- */
- // Package visible for use throughout java.util.
- // It may be inlined since it is final.
- static final boolean equals(Object o1, Object o2)
- {
- return o1 == null ? o2 == null : o1.equals(o2);
- }
-
- /**
- * Hash an object according to Collection semantics.
- *
- * @param o the object to hash
- * @return o1 == null ? 0 : o1.hashCode()
- */
- // Package visible for use throughout java.util.
- // It may be inlined since it is final.
- static final int hashCode(Object o)
- {
- return o == null ? 0 : o.hashCode();
- }
-}
Deleted: trunk/core/src/classpath/java/java/util/AbstractList.java
===================================================================
--- trunk/core/src/classpath/java/java/util/AbstractList.java 2007-10-06 20:30:32 UTC (rev 3538)
+++ trunk/core/src/classpath/java/java/util/AbstractList.java 2007-10-06 20:33:17 UTC (rev 3539)
@@ -1,1204 +0,0 @@
-/* AbstractList.java -- Abstract implementation of most of List
- Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004, 2005
- 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., 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this
-exception statement from your version. */
-
-
-package java.util;
-
-/**
- * A basic implementation of most of the methods in the List interface to make
- * it easier to create a List based on a random-access data structure. If
- * the list is sequential (such as a linked list), use AbstractSequentialList.
- * To create an unmodifiable list, it is only necessary to override the
- * size() and get(int) methods (this contrasts with all other abstract
- * collection classes which require an iterator to be provided). To make the
- * list modifiable, the set(int, Object) method should also be overridden, and
- * to make the list resizable, the add(int, Object) and remove(int) methods
- * should be overridden too. Other methods should be overridden if the
- * backing data structure allows for a more efficient implementation.
- * The precise implementation used by AbstractList is documented, so that
- * subclasses can tell which methods could be implemented more efficiently.
- * <p>
- *
- * As recommended by Collection and List, the subclass should provide at
- * least a no-argument and a Collection constructor. This class is not
- * synchronized.
- *
- * @author Original author unknown
- * @author Bryce McKinlay
- * @author Eric Blake (eb...@em...)
- * @see Collection
- * @see List
- * @see AbstractSequentialList
- * @see AbstractCollection
- * @see ListIterator
- * @since 1.2
- * @status updated to 1.4
- */
-public abstract class AbstractList<E>
- extends AbstractCollection<E>
- implements List<E>
-{
- /**
- * A count of the number of structural modifications that have been made to
- * the list (that is, insertions and removals). Structural modifications
- * are ones which change the list size or affect how iterations would
- * behave. This field is available for use by Iterator and ListIterator,
- * in order to throw a {@link ConcurrentModificationException} in response
- * to the next operation on the iterator. This <i>fail-fast</i> behavior
- * saves the user from many subtle bugs otherwise possible from concurrent
- * modification during iteration.
- * <p>
- *
- * To make lists fail-fast, increment this field by just 1 in the
- * <code>add(int, Object)</code> and <code>remove(int)</code> methods.
- * Otherwise, this field may be ignored.
- */
- protected transient int modCount;
-
- /**
- * The main constructor, for use by subclasses.
- */
- protected AbstractList()
- {
- }
-
- /**
- * Returns the elements at the specified position in the list.
- *
- * @param index the element to return
- * @return the element at that position
- * @throws IndexOutOfBoundsException if index < 0 || index >= size()
- */
- public abstract E get(int index);
-
- /**
- * Insert an element into the list at a given position (optional operation).
- * This shifts all existing elements from that position to the end one
- * index to the right. This version of add has no return, since it is
- * assumed to always succeed if there is no exception. This implementation
- * always throws UnsupportedOperationException, and must be overridden to
- * make a modifiable List. If you want fail-fast iterators, be sure to
- * increment modCount when overriding this.
- *
- * @param index the location to insert the item
- * @param o the object to insert
- * @throws UnsupportedOperationException if this list does not support the
- * add operation
- * @throws IndexOutOfBoundsException if index < 0 || index > size()
- * @throws ClassCastException if o cannot be added to this list due to its
- * type
- * @throws IllegalArgumentException if o cannot be added to this list for
- * some other reason
- * @see #modCount
- */
- public void add(int index, E o)
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * Add an element to the end of the list (optional operation). If the list
- * imposes restraints on what can be inserted, such as no null elements,
- * this should be documented. This implementation calls
- * <code>add(size(), o);</code>, and will fail if that version does.
- *
- * @param o the object to add
- * @return true, as defined by Collection for a modified list
- * @throws UnsupportedOperationException if this list does not support the
- * add operation
- * @throws ClassCastException if o cannot be added to this list due to its
- * type
- * @throws IllegalArgumentException if o cannot be added to this list for
- * some other reason
- * @see #add(int, Object)
- */
- public boolean add(E o)
- {
- add(size(), o);
- return true;
- }
-
- /**
- * Insert the contents of a collection into the list at a given position
- * (optional operation). Shift all elements at that position to the right
- * by the number of elements inserted. This operation is undefined if
- * this list is modified during the operation (for example, if you try
- * to insert a list into itself). This implementation uses the iterator of
- * the collection, repeatedly calling add(int, Object); this will fail
- * if add does. This can often be made more efficient.
- *
- * @param index the location to insert the collection
- * @param c the collection to insert
- * @return true if the list was modified by this action, that is, if c is
- * non-empty
- * @throws UnsupportedOperationException if this list does not support the
- * addAll operation
- * @throws IndexOutOfBoundsException if index < 0 || index > size()
- * @throws ClassCastException if some element of c cannot be added to this
- * list due to its type
- * @throws IllegalArgumentException if some element of c cannot be added
- * to this list for some other reason
- * @throws NullPointerException if the specified collection is null
- * @see #add(int, Object)
- */
- public boolean addAll(int index, Collection<? extends E> c)
- {
- Iterator<? extends E> itr = c.iterator();
- int size = c.size();
- for (int pos = size; pos > 0; pos--)
- add(index++, itr.next());
- return size > 0;
- }
-
- /**
- * Clear the list, such that a subsequent call to isEmpty() would return
- * true (optional operation). This implementation calls
- * <code>removeRange(0, size())</code>, so it will fail unless remove
- * or removeRange is overridden.
- *
- * @throws UnsupportedOperationException if this list does not support the
- * clear operation
- * @see #remove(int)
- * @see #removeRange(int, int)
- */
- public void clear()
- {
- removeRange(0, size());
- }
-
- /**
- * Test whether this list is equal to another object. A List is defined to be
- * equal to an object if and only if that object is also a List, and the two
- * lists have the same sequence. Two lists l1 and l2 are equal if and only
- * if <code>l1.size() == l2.size()</code>, and for every integer n between 0
- * and <code>l1.size() - 1</code> inclusive, <code>l1.get(n) == null ?
- * l2.get(n) == null : l1.get(n).equals(l2.get(n))</code>.
- * <p>
- *
- * This implementation returns true if the object is this, or false if the
- * object is not a List. Otherwise, it iterates over both lists (with
- * iterator()), ret...
[truncated message content] |