aboutsummaryrefslogtreecommitdiff
path: root/libjava/java/util/Collections.java
diff options
context:
space:
mode:
authorTom Tromey <tromey@redhat.com>2002-06-18 15:40:16 +0000
committerTom Tromey <tromey@gcc.gnu.org>2002-06-18 15:40:16 +0000
commit3831381763ca5f41d6f7406d590e1e38a8531e1c (patch)
tree6b8dcd38b7dbb7c4c618080eb1958b6f042d581c /libjava/java/util/Collections.java
parent0fd534ed06e92a7232b2373321f113ee8dd482c4 (diff)
downloadgcc-3831381763ca5f41d6f7406d590e1e38a8531e1c.zip
gcc-3831381763ca5f41d6f7406d590e1e38a8531e1c.tar.gz
gcc-3831381763ca5f41d6f7406d590e1e38a8531e1c.tar.bz2
javaprims.h: Updated class declaration list.
* gcj/javaprims.h: Updated class declaration list. * Makefile.in: Rebuilt. * Makefile.am (core_java_source_files): Added PropertyPermissionCollection.java. * java/lang/Thread.java (group, name): Now package-private. * java/lang/ThreadGroup.java: Re-merge with Classpath. * java/util/AbstractList.java: Likewise. * java/util/AbstractMap.java: Likewise. * java/util/Calendar.java: Likewise. * java/util/Collections.java: Likewise. * java/util/HashMap.java: Likewise. * java/util/Hashtable.java: Likewise. * java/util/LinkedHashMap.java: Likewise. * java/util/LinkedList.java: Likewise. * java/util/List.java: Likewise. * java/util/ListResourceBundle.java: Likewise. * java/util/Map.java: Likewise. * java/util/Observable.java: Likewise. * java/util/Properties.java: Likewise. * java/util/PropertyPermission.java: Likewise. * java/util/PropertyPermissionCollection.java: Likewise. * java/util/PropertyResourceBundle.java: Likewise. * java/util/Random.java: Likewise. * java/util/SimpleTimeZone.java: Likewise. * java/util/StringTokenizer.java: Likewise. * java/util/TimerTask.java: Likewise. * java/util/TreeMap.java: Likewise. * java/util/WeakHashMap.java: Likewise. * java/util/jar/Attributes.java: Likewise. * java/util/jar/JarException.java: Likewise. * java/util/jar/Manifest.java: Likewise. From-SVN: r54743
Diffstat (limited to 'libjava/java/util/Collections.java')
-rw-r--r--libjava/java/util/Collections.java288
1 files changed, 257 insertions, 31 deletions
diff --git a/libjava/java/util/Collections.java b/libjava/java/util/Collections.java
index 9c10a4b..815afcc 100644
--- a/libjava/java/util/Collections.java
+++ b/libjava/java/util/Collections.java
@@ -1,5 +1,5 @@
/* Collections.java -- Utility class with methods to operate on collections
- Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
+ Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -60,7 +60,6 @@ import java.io.Serializable;
* modify the set.
*
* @author Original author unknown
- * @author Bryce McKinlay
* @author Eric Blake <ebb9@email.byu.edu>
* @see Collection
* @see Set
@@ -108,24 +107,6 @@ public class Collections
*/
public static final Set EMPTY_SET = new EmptySet();
- private static final Iterator EMPTY_ITERATOR = new Iterator()
- {
- public boolean hasNext()
- {
- return false;
- }
-
- public Object next()
- {
- throw new NoSuchElementException();
- }
-
- public void remove()
- {
- throw new UnsupportedOperationException();
- }
- };
-
/**
* The implementation of {@link #EMPTY_SET}. This class name is required
* for compatibility with Sun's JDK serializability.
@@ -158,9 +139,94 @@ public class Collections
/**
* Returns an iterator that does not iterate.
*/
+ // This is really cheating! I think it's perfectly valid, though.
public Iterator iterator()
{
- return EMPTY_ITERATOR;
+ return EMPTY_LIST.iterator();
+ }
+
+ // The remaining methods are optional, but provide a performance
+ // advantage by not allocating unnecessary iterators in AbstractSet.
+ /**
+ * The empty set never contains anything.
+ */
+ public boolean contains(Object o)
+ {
+ return false;
+ }
+
+ /**
+ * This is true only if the given collection is also empty.
+ */
+ public boolean containsAll(Collection c)
+ {
+ return c.isEmpty();
+ }
+
+ /**
+ * Equal only if the other set is empty.
+ */
+ public boolean equals(Object o)
+ {
+ return o instanceof Set && ((Set) o).isEmpty();
+ }
+
+ /**
+ * The hashcode is always 0.
+ */
+ public int hashCode()
+ {
+ return 0;
+ }
+
+ /**
+ * Always succeeds with false result.
+ */
+ public boolean remove(Object o)
+ {
+ return false;
+ }
+
+ /**
+ * Always succeeds with false result.
+ */
+ public boolean removeAll(Collection c)
+ {
+ return false;
+ }
+
+ /**
+ * Always succeeds with false result.
+ */
+ public boolean retainAll(Collection c)
+ {
+ return false;
+ }
+
+ /**
+ * The array is always empty.
+ */
+ public Object[] toArray()
+ {
+ return new Object[0];
+ }
+
+ /**
+ * We don't even need to use reflection!
+ */
+ public Object[] toArray(Object[] a)
+ {
+ if (a.length > 0)
+ a[0] = null;
+ return a;
+ }
+
+ /**
+ * The string never changes.
+ */
+ public String toString()
+ {
+ return "[]";
}
} // class EmptySet
@@ -207,15 +273,106 @@ public class Collections
{
throw new IndexOutOfBoundsException();
}
-
+
+ // The remaining methods are optional, but provide a performance
+ // advantage by not allocating unnecessary iterators in AbstractList.
/**
- * Returns an iterator that does not iterate. Optional, but avoids
- * allocation of an iterator in AbstractList.
+ * Never contains anything.
*/
- public Iterator iterator()
+ public boolean contains(Object o)
{
- return EMPTY_ITERATOR;
- }
+ return false;
+ }
+
+ /**
+ * This is true only if the given collection is also empty.
+ */
+ public boolean containsAll(Collection c)
+ {
+ return c.isEmpty();
+ }
+
+ /**
+ * Equal only if the other set is empty.
+ */
+ public boolean equals(Object o)
+ {
+ return o instanceof List && ((List) o).isEmpty();
+ }
+
+ /**
+ * The hashcode is always 1.
+ */
+ public int hashCode()
+ {
+ return 1;
+ }
+
+ /**
+ * Returns -1.
+ */
+ public int indexOf(Object o)
+ {
+ return -1;
+ }
+
+ /**
+ * Returns -1.
+ */
+ public int lastIndexOf(Object o)
+ {
+ return -1;
+ }
+
+ /**
+ * Always succeeds with false result.
+ */
+ public boolean remove(Object o)
+ {
+ return false;
+ }
+
+ /**
+ * Always succeeds with false result.
+ */
+ public boolean removeAll(Collection c)
+ {
+ return false;
+ }
+
+ /**
+ * Always succeeds with false result.
+ */
+ public boolean retainAll(Collection c)
+ {
+ return false;
+ }
+
+ /**
+ * The array is always empty.
+ */
+ public Object[] toArray()
+ {
+ return new Object[0];
+ }
+
+ /**
+ * We don't even need to use reflection!
+ */
+ public Object[] toArray(Object[] a)
+ {
+ if (a.length > 0)
+ a[0] = null;
+ return a;
+ }
+
+ /**
+ * The string never changes.
+ */
+ public String toString()
+ {
+ return "[]";
+ }
} // class EmptyList
/**
@@ -253,6 +410,64 @@ public class Collections
return EMPTY_SET;
}
+ // The remaining methods are optional, but provide a performance
+ // advantage by not allocating unnecessary iterators in AbstractMap.
+ /**
+ * No entries!
+ */
+ public boolean containsKey(Object key)
+ {
+ return false;
+ }
+
+ /**
+ * No entries!
+ */
+ public boolean containsValue(Object value)
+ {
+ return false;
+ }
+
+ /**
+ * Equal to all empty maps.
+ */
+ public boolean equals(Object o)
+ {
+ return o instanceof Map && ((Map) o).isEmpty();
+ }
+
+ /**
+ * No mappings, so this returns null.
+ */
+ public Object get(Object o)
+ {
+ return null;
+ }
+
+ /**
+ * The hashcode is always 0.
+ */
+ public int hashCode()
+ {
+ return 0;
+ }
+
+ /**
+ * No entries.
+ */
+ public Set keySet()
+ {
+ return EMPTY_SET;
+ }
+
+ /**
+ * Remove always succeeds, with null result.
+ */
+ public Object remove(Object o)
+ {
+ return null;
+ }
+
/**
* Size is always 0.
*/
@@ -269,8 +484,17 @@ public class Collections
{
return EMPTY_SET;
}
+
+ /**
+ * The string never changes.
+ */
+ public String toString()
+ {
+ return "[]";
+ }
} // class EmptyMap
+
/**
* Compare two objects with or without a Comparator. If c is null, uses the
* natural ordering. Slightly slower than doing it inline if the JVM isn't
@@ -502,7 +726,7 @@ public class Collections
}
/**
- * Returns an array list holding the elements visited by a given
+ * Returns an ArrayList holding the elements visited by a given
* Enumeration. This method exists for interoperability between legacy
* APIs and the new Collection API.
*
@@ -511,9 +735,9 @@ public class Collections
* @see ArrayList
* @since 1.4
*/
- public static List list(Enumeration e)
+ public static ArrayList list(Enumeration e)
{
- List l = new ArrayList();
+ ArrayList l = new ArrayList();
while (e.hasMoreElements())
l.add(e.nextElement());
return l;
@@ -1353,7 +1577,7 @@ public class Collections
public Set entrySet()
{
if (entries == null)
- entries = singleton(new BasicMapEntry(k, v)
+ entries = singleton(new AbstractMap.BasicMapEntry(k, v)
{
public Object setValue(Object o)
{
@@ -1500,6 +1724,7 @@ public class Collections
l.set(i, l.set(j, l.get(i)));
}
+
/**
* Returns a synchronized (thread-safe) collection wrapper backed by the
* given collection. Notice that element access through the iterators
@@ -2682,6 +2907,7 @@ public class Collections
}
} // class SynchronizedSortedSet
+
/**
* Returns an unmodifiable view of the given collection. This allows
* "read-only" access, although changes in the backing collection show up