Commit 38313817 by Tom Tromey Committed by Tom Tromey

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
parent 0fd534ed
2002-06-18 Tom Tromey <tromey@redhat.com>
* 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.
2002-06-17 Tom Tromey <tromey@redhat.com>
* gcj/javaprims.h: Updated class declaration list.
......
......@@ -1220,6 +1220,7 @@ java/util/Observable.java \
java/util/Observer.java \
java/util/Properties.java \
java/util/PropertyPermission.java \
java/util/PropertyPermissionCollection.java \
java/util/PropertyResourceBundle.java \
java/util/Random.java \
java/util/RandomAccess.java \
......
......@@ -987,6 +987,7 @@ java/util/Observable.java \
java/util/Observer.java \
java/util/Properties.java \
java/util/PropertyPermission.java \
java/util/PropertyPermissionCollection.java \
java/util/PropertyResourceBundle.java \
java/util/Random.java \
java/util/RandomAccess.java \
......@@ -2550,6 +2551,7 @@ DEP_FILES = .deps/$(srcdir)/$(CONVERT_DIR)/gen-from-JIS.P \
.deps/java/util/NoSuchElementException.P .deps/java/util/Observable.P \
.deps/java/util/Observer.P .deps/java/util/Properties.P \
.deps/java/util/PropertyPermission.P \
.deps/java/util/PropertyPermissionCollection.P \
.deps/java/util/PropertyResourceBundle.P .deps/java/util/Random.P \
.deps/java/util/RandomAccess.P .deps/java/util/ResourceBundle.P \
.deps/java/util/Set.P .deps/java/util/SimpleTimeZone.P \
......
......@@ -243,6 +243,7 @@ extern "Java"
class AbstractCollection;
class AbstractList;
class AbstractMap;
class AbstractMap$BasicMapEntry;
class AbstractSequentialList;
class AbstractSet;
class ArrayList;
......@@ -317,11 +318,13 @@ extern "Java"
class Map$Entry;
class Map$Map;
class MissingResourceException;
class MyResources;
class NoSuchElementException;
class Observable;
class Observer;
class Properties;
class PropertyPermission;
class PropertyPermissionCollection;
class PropertyResourceBundle;
class Random;
class RandomAccess;
......
......@@ -301,8 +301,8 @@ public class Thread implements Runnable
public static native void yield ();
// Private data.
private ThreadGroup group;
private String name;
ThreadGroup group;
String name;
private Runnable runnable;
private int priority;
private boolean daemon_flag;
......
/* AbstractList.java -- Abstract implementation of most of List
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.
......@@ -237,20 +237,22 @@ public abstract class AbstractList extends AbstractCollection implements List
}
/**
* Obtain a hash code for this list. In order to obey the general contract of
* the hashCode method of class Object, this value is calculated as follows:
* <pre>
* hashCode = 1;
* Iterator i = list.iterator();
* while (i.hasNext())
* {
* Object obj = i.next();
* hashCode = 31 * hashCode + (obj == null ? 0 : obj.hashCode());
* }
* </pre>
* Obtains a hash code for this list. In order to obey the general
* contract of the hashCode method of class Object, this value is
* calculated as follows:
*
<pre>hashCode = 1;
Iterator i = list.iterator();
while (i.hasNext())
{
Object obj = i.next();
hashCode = 31 * hashCode + (obj == null ? 0 : obj.hashCode());
}</pre>
*
* This ensures that the general contract of Object.hashCode() is adhered to.
*
* @return the hash code of this list
*
* @see Object#hashCode()
* @see #equals(Object)
*/
......@@ -611,19 +613,21 @@ public abstract class AbstractList extends AbstractCollection implements List
/**
* This class follows the implementation requirements set forth in
* {@link AbstractList#subList(int, int)}. Some compilers have problems
* with AbstractList.this.modCount if this class is nested in AbstractList,
* even though the JLS defines that to be legal, so we make it a top-level
* class.
* {@link AbstractList#subList(int, int)}. It matches Sun's implementation
* by using a non-public top-level class in the same package.
*
* @author Original author unknown
* @author Eric Blake <ebb9@email.byu.edu>
*/
class SubList extends AbstractList
{
private final AbstractList backingList;
private final int offset;
private int size;
// Package visible, for use by iterator.
/** The original list. */
final AbstractList backingList;
/** The index of the first element of the sublist. */
final int offset;
/** The size of the sublist. */
int size;
/**
* Construct the sublist.
......@@ -647,8 +651,8 @@ class SubList extends AbstractList
* @throws ConcurrentModificationException if the backing list has been
* modified externally to this sublist
*/
// This will get inlined, since it is private.
private void checkMod()
// This can be inlined. Package visible, for use by iterator.
void checkMod()
{
if (modCount != backingList.modCount)
throw new ConcurrentModificationException();
......
/* AbstractMap.java -- Abstract implementation of most of Map
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.
......@@ -518,4 +518,130 @@ public abstract class AbstractMap implements Map
{
return o == null ? 0 : o.hashCode();
}
/**
* A class which implements Map.Entry. It is shared by HashMap, TreeMap,
* Hashtable, and Collections. It is not specified by the JDK, but makes
* life much easier.
*
* @author Jon Zeppieri
* @author Eric Blake <ebb9@email.byu.edu>
*/
static class BasicMapEntry implements Map.Entry
{ // XXX - FIXME Use fully qualified implements as gcj 3.1 workaround.
/**
* The key. Package visible for direct manipulation.
*/
Object key;
/**
* The value. Package visible for direct manipulation.
*/
Object value;
/**
* Basic constructor initializes the fields.
* @param newKey the key
* @param newValue the value
*/
BasicMapEntry(Object newKey, Object newValue)
{
key = newKey;
value = newValue;
}
/**
* Compares the specified object with this entry. Returns true only if
* the object is a mapping of identical key and value. In other words,
* this must be:
*
<pre>(o instanceof Map.Entry) &&
(getKey() == null ? ((HashMap) o).getKey() == null
: getKey().equals(((HashMap) o).getKey())) &&
(getValue() == null ? ((HashMap) o).getValue() == null
: getValue().equals(((HashMap) o).getValue()))</pre>
*
* @param o the object to compare
*
* @return <code>true</code> if it is equal
*/
public final boolean equals(Object o)
{
if (! (o instanceof Map.Entry))
return false;
// Optimize for our own entries.
if (o instanceof BasicMapEntry)
{
BasicMapEntry e = (BasicMapEntry) o;
return (AbstractMap.equals(key, e.key)
&& AbstractMap.equals(value, e.value));
}
Map.Entry e = (Map.Entry) o;
return (AbstractMap.equals(key, e.getKey())
&& AbstractMap.equals(value, e.getValue()));
}
/**
* Get the key corresponding to this entry.
*
* @return the key
*/
public final Object getKey()
{
return key;
}
/**
* Get the value corresponding to this entry. If you already called
* Iterator.remove(), the behavior undefined, but in this case it works.
*
* @return the value
*/
public final Object getValue()
{
return value;
}
/**
* Returns the hash code of the entry. This is defined as the exclusive-or
* of the hashcodes of the key and value (using 0 for null). In other
* words, this must be:
*
<pre>(getKey() == null ? 0 : getKey().hashCode())
^ (getValue() == null ? 0 : getValue().hashCode())</pre>
*
* @return the hash code
*/
public final int hashCode()
{
return (AbstractMap.hashCode(key) ^ AbstractMap.hashCode(value));
}
/**
* Replaces the value with the specified object. This writes through
* to the map, unless you have already called Iterator.remove(). It
* may be overridden to restrict a null value.
*
* @param newVal the new value to store
* @return the old value
* @throws NullPointerException if the map forbids null values
*/
public Object setValue(Object newVal)
{
Object r = value;
value = newVal;
return r;
}
/**
* This provides a string representation of the entry. It is of the form
* "key=value", where string concatenation is used on key and value.
*
* @return the string representation
*/
public final String toString()
{
return key + "=" + value;
}
} // class BasicMapEntry
}
......@@ -73,13 +73,12 @@ import java.io.*;
* and for the first line all fields are set, that line is used to
* compute the day. <br>
*
* <pre>
* month + day_of_month
* month + week_of_month + day_of_week
* month + day_of_week_of_month + day_of_week
* day_of_year
* day_of_week + week_of_year
* </pre>
*
<pre>month + day_of_month
month + week_of_month + day_of_week
month + day_of_week_of_month + day_of_week
day_of_year
day_of_week + week_of_year</pre>
*
* The hour_of_day-field takes precedence over the ampm and
* hour_of_ampm fields. <br>
......
/* 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
......
/* HashMap.java -- a class providing a basic hashtable data structure,
mapping Object --> Object
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.
......@@ -162,7 +162,7 @@ public class HashMap extends AbstractMap
*
* @author Eric Blake <ebb9@email.byu.edu>
*/
static class HashEntry extends BasicMapEntry
static class HashEntry extends AbstractMap.BasicMapEntry
{
/**
* The next entry in the linked list. Package visible for use by subclass.
......@@ -373,9 +373,9 @@ public class HashMap extends AbstractMap
{
Map.Entry e = (Map.Entry) itr.next();
// Optimize in case the Entry is one of our own.
if (e instanceof BasicMapEntry)
if (e instanceof AbstractMap.BasicMapEntry)
{
BasicMapEntry entry = (BasicMapEntry) e;
AbstractMap.BasicMapEntry entry = (AbstractMap.BasicMapEntry) e;
put(entry.key, entry.value);
}
else
......@@ -647,7 +647,8 @@ public class HashMap extends AbstractMap
* @return the matching entry, if found, or null
* @see #entrySet()
*/
private HashEntry getEntry(Object o)
// Package visible, for use in nested classes.
HashEntry getEntry(Object o)
{
if (!(o instanceof Map.Entry))
return null;
......@@ -710,14 +711,13 @@ public class HashMap extends AbstractMap
}
/**
* Increases the size of the HashMap and rehashes all keys to new array
* indices; this is called when the addition of a new value would cause
* size() > threshold. Note that the existing Entry objects are reused in
* the new hash table.
* <p>
* Increases the size of the HashMap and rehashes all keys to new
* array indices; this is called when the addition of a new value
* would cause size() &gt; threshold. Note that the existing Entry
* objects are reused in the new hash table.
*
* This is not specified, but the new size is twice the current size plus
* one; this number is not always prime, unfortunately.
* <p>This is not specified, but the new size is twice the current size
* plus one; this number is not always prime, unfortunately.
*/
private void rehash()
{
......
/* Hashtable.java -- a class providing a basic hashtable data structure,
mapping Object --> Object
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.
......@@ -102,6 +102,9 @@ import java.io.ObjectOutputStream;
public class Hashtable extends Dictionary
implements Map, Cloneable, Serializable
{
// WARNING: Hashtable is a CORE class in the bootstrap cycle. See the
// comments in vm/reference/java/lang/Runtime for implications of this fact.
/** Default number of buckets. This is the value the JDK 1.3 uses. Some
* early documentation specified this value as 101. That is incorrect.
*/
......@@ -176,7 +179,7 @@ public class Hashtable extends Dictionary
* pair. A Hashtable Entry is identical to a HashMap Entry, except that
* `null' is not allowed for keys and values.
*/
private static final class HashEntry extends BasicMapEntry
private static final class HashEntry extends AbstractMap.BasicMapEntry
{
/** The next entry in the linked list. */
HashEntry next;
......@@ -340,9 +343,9 @@ public class Hashtable extends Dictionary
*
* @param value the value to search for in this Hashtable
* @return true if at least one key maps to the value
* @throws NullPointerException if <code>value</code> is null
* @see #contains(Object)
* @see #containsKey(Object)
* @throws NullPointerException if <code>value</code> is null
* @since 1.2
*/
public boolean containsValue(Object value)
......@@ -361,7 +364,7 @@ public class Hashtable extends Dictionary
// Must throw on null argument even if the table is empty
if (value == null)
throw new NullPointerException();
return false;
}
......@@ -511,9 +514,9 @@ public class Hashtable extends Dictionary
{
Map.Entry e = (Map.Entry) itr.next();
// Optimize in case the Entry is one of our own.
if (e instanceof BasicMapEntry)
if (e instanceof AbstractMap.BasicMapEntry)
{
BasicMapEntry entry = (BasicMapEntry) e;
AbstractMap.BasicMapEntry entry = (AbstractMap.BasicMapEntry) e;
put(entry.key, entry.value);
}
else
......@@ -763,9 +766,9 @@ public class Hashtable extends Dictionary
/**
* Returns true if this Hashtable equals the supplied Object <code>o</code>.
* As specified by Map, this is:
* <pre>
* <code>
* (o instanceof Map) && entrySet().equals(((Map) o).entrySet());
* </pre>
* </code>
*
* @param o the object to compare to
* @return true if o is an equal map
......@@ -812,7 +815,10 @@ public class Hashtable extends Dictionary
*/
private int hash(Object key)
{
return Math.abs(key.hashCode() % buckets.length);
// Note: Inline Math.abs here, for less method overhead, and to avoid
// a bootstrap dependency, since Math relies on native methods.
int hash = key.hashCode() % buckets.length;
return hash < 0 ? -hash : hash;
}
/**
......@@ -823,7 +829,8 @@ public class Hashtable extends Dictionary
* @return the matching entry, if found, or null
* @see #entrySet()
*/
private HashEntry getEntry(Object o)
// Package visible, for use in nested classes.
HashEntry getEntry(Object o)
{
if (! (o instanceof Map.Entry))
return null;
......@@ -869,7 +876,7 @@ public class Hashtable extends Dictionary
/**
* Increases the size of the Hashtable and rehashes all keys to new array
* indices; this is called when the addition of a new value would cause
* size() > threshold. Note that the existing Entry objects are reused in
* size() &gt; threshold. Note that the existing Entry objects are reused in
* the new hash table.
* <p>
*
......@@ -1139,4 +1146,4 @@ public class Hashtable extends Dictionary
return type == VALUES ? e.value : e.key;
}
} // class Enumerator
}
} // class Hashtable
......@@ -71,7 +71,7 @@ package java.util;
* <p>
*
* Under ideal circumstances (no collisions), LinkedHashMap offers O(1)
* performance on most operations (<pre>containsValue()</pre> is,
* performance on most operations (<code>containsValue()</code> is,
* of course, O(n)). In the worst case (all keys map to the same
* hash code -- very unlikely), most operations are O(n).
* <p>
......@@ -87,7 +87,7 @@ package java.util;
* {@link ConcurrentModificationException} rather than exhibit
* non-deterministic behavior.
*
* @author Eric Blake <ebb9@email.byu.edu>
* @author Eric Blake (ebb9@email.byu.edu)
* @see Object#hashCode()
* @see Collection
* @see Map
......@@ -256,8 +256,9 @@ public class LinkedHashMap extends HashMap
* @param initialCapacity the initial capacity (>=0)
* @param loadFactor the load factor (>0, not NaN)
* @param accessOrder true for access-order, false for insertion-order
* @throws IllegalArgumentException if (initialCapacity < 0) ||
* ! (loadFactor > 0.0)
*
* @throws IllegalArgumentException if (initialCapacity &lt; 0) ||
* ! (loadFactor &gt; 0.0)
*/
public LinkedHashMap(int initialCapacity, float loadFactor,
boolean accessOrder)
......@@ -277,11 +278,12 @@ public class LinkedHashMap extends HashMap
}
/**
* Returns true if this HashMap contains a value <pre>o</pre>, such that
* <pre>o.equals(value)</pre>.
* Returns <code>true</code> if this HashMap contains a value
* <code>o</code>, such that <code>o.equals(value)</code>.
*
* @param value the value to search for in this HashMap
* @return true if at least one key maps to the value
*
* @return <code>true</code> if at least one key maps to the value
*/
public boolean containsValue(Object value)
{
......@@ -297,7 +299,7 @@ public class LinkedHashMap extends HashMap
/**
* Return the value in this Map associated with the supplied key,
* or <pre>null</pre> if the key maps to nothing. If this is an
* or <code>null</code> if the key maps to nothing. If this is an
* access-ordered Map and the key is found, this performs structural
* modification, moving the key to the newest end of the list. NOTE:
* Since the value could also be null, you must use containsKey to
......@@ -350,14 +352,14 @@ public class LinkedHashMap extends HashMap
* <p>
*
* For example, to keep the Map limited to 100 entries, override as follows:
* <pre>
* private static final int MAX_ENTRIES = 100;
*
* protected boolean removeEldestEntry(Map.Entry eldest)
* {
* return size() > MAX_ENTRIES;
* }
* </pre><p>
*
<pre>private static final int MAX_ENTRIES = 100;
protected boolean removeEldestEntry(Map.Entry eldest)
{
return size() &gt; MAX_ENTRIES;
}
</pre><p>
*
* Typically, this method does not modify the map, but just uses the
* return value as an indication to <code>put</code> whether to proceed.
......@@ -376,6 +378,7 @@ public class LinkedHashMap extends HashMap
* returns true. For an access-order map, this is the least
* recently accessed; for an insertion-order map, this is the
* earliest element inserted.
*
* @return true if <code>eldest</code> should be removed
*/
protected boolean removeEldestEntry(Map.Entry eldest)
......@@ -467,8 +470,10 @@ public class LinkedHashMap extends HashMap
/**
* Removes from the backing HashMap the last element which was fetched
* with the <pre>next()</pre> method.
* with the <code>next()</code> method.
*
* @throws ConcurrentModificationException if the HashMap was modified
*
* @throws IllegalStateException if called when there is no last element
*/
public void remove()
......
/* LinkedList.java -- Linked list implementation of the List interface
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.
......@@ -125,12 +125,13 @@ public class LinkedList extends AbstractSequentialList
* entry in the list is obtained in constant time, which is a very desirable
* property.
* For speed and flexibility, range checking is not done in this method:
* Incorrect values will be returned if (n < 0) or (n >= size).
* Incorrect values will be returned if (n &lt; 0) or (n &gt;= size).
*
* @param n the number of the entry to get
* @return the entry at position n
*/
private Entry getEntry(int n)
// Package visible for use in nested classes.
Entry getEntry(int n)
{
Entry e;
if (n < size / 2)
......@@ -156,7 +157,8 @@ public class LinkedList extends AbstractSequentialList
*
* @param e the entry to remove
*/
private void removeEntry(Entry e)
// Package visible for use in nested classes.
void removeEntry(Entry e)
{
modCount++;
size--;
......
......@@ -201,7 +201,7 @@ public interface List extends Collection
* @see Object#equals(Object)
* @see #hashCode()
*/
/* boolean equals(Object o);*/
boolean equals(Object o);
/**
* Get the element at a given index in this list.
......@@ -213,18 +213,20 @@ public interface List extends Collection
Object get(int index);
/**
* Obtain a hash code for this list. In order to obey the general contract of
* the hashCode method of class Object, this value is calculated as follows:
* <pre>
* hashCode = 1;
* Iterator i = list.iterator();
* while (i.hasNext())
* {
* Object obj = i.next();
* hashCode = 31 * hashCode + (obj == null ? 0 : obj.hashCode());
* }
* </pre>
* This ensures that the general contract of Object.hashCode() is adhered to.
* Obtains a hash code for this list. In order to obey the general
* contract of the hashCode method of class Object, this value is
* calculated as follows:
*
<p><pre>hashCode = 1;
Iterator i = list.iterator();
while (i.hasNext())
{
Object obj = i.next();
hashCode = 31 * hashCode + (obj == null ? 0 : obj.hashCode());
}</pre>
*
* <p>This ensures that the general contract of Object.hashCode()
* is adhered to.
*
* @return the hash code of this list
* @see Object#hashCode()
......
/* java.util.ListResourceBundle
Copyright (C) 1998, 1999, 2001 Free Software Foundation, Inc.
/* ListResourceBundle -- a resource bundle build around a list
Copyright (C) 1998, 1999, 2001, 2002 Free Software Foundation, Inc.
This file is part of GNU Classpath.
......@@ -39,73 +39,102 @@ exception statement from your version. */
package java.util;
/**
* A <code>ListResouceBundle</code> provides an easy way, to create
* your own resource bundle. It is an abstract class that you can
* subclass. You should then overwrite the getContents method, that
* provides a key/value list.
* <br>
* The key/value list is a two dimensional list of Object. The first
* dimension ranges over the resources. The second dimension ranges
* from zero (key) to one (value). The keys must be of type String.
* <br>
* XXX Example!
* A <code>ListResouceBundle</code> provides an easy way, to create your own
* resource bundle. It is an abstract class that you can subclass. You should
* then overwrite the getContents method, that provides a key/value list.
*
* <p>The key/value list is a two dimensional list of Object. The first
* dimension ranges over the resources. The second dimension ranges from
* zero (key) to one (value). The keys must be of type String, and they are
* case-sensitive. For example:
*
<br><pre>public class MyResources
extends ListResourceBundle
{
public Object[][] getContents()
{
return contents;
}
static final Object[][] contents =
{
// LOCALIZED STRINGS
{"s1", "The disk \"{1}\" contains {0}."}, // MessageFormat pattern
{"s2", "1"}, // location of {0} in pattern
{"s3", "My Disk"}, // sample disk name
{"s4", "no files"}, // first ChoiceFormat choice
{"s5", "one file"}, // second ChoiceFormat choice
{"s6", "{0,number} files"} // third ChoiceFormat choice
{"s7", "3 Mar 96"}, // sample date
{"s8", new Dimension(1,5)} // real object, not just string
// END OF LOCALIZED MATERIAL
};
}</pre>
*
* @author Jochen Hoenicke
* @author Eric Blake <ebb9@email.byu.edu>
* @see Locale
* @see PropertyResourceBundle
* @author Jochen Hoenicke */
* @since 1.1
* @status updated to 1.4
*/
public abstract class ListResourceBundle extends ResourceBundle
{
/**
* The constructor. It does nothing special.
* The constructor. It does nothing special.
*/
public ListResourceBundle()
{
}
/**
* Gets the key/value list. You must override this method.
* @return a two dimensional list of Objects. The first dimension
* ranges over the objects, and the second dimension ranges from
* zero (key) to one (value).
*/
protected abstract Object[][] getContents();
/**
* Override this method to provide the resource for a keys. This gets
* called by <code>getObject</code>.
* @param key The key of the resource.
* @return The resource for the key or null if it doesn't exists.
* Gets a resource for a given key. This is called by <code>getObject</code>.
*
* @param key the key of the resource
* @return the resource for the key, or null if it doesn't exist
*/
public final Object handleGetObject(String key)
{
Object[][] contents = getContents();
for (int i = 0; i < contents.length; i++)
{
if (key.equals(contents[i][0]))
return contents[i][1];
}
int i = contents.length;
while (--i >= 0)
if (key.equals(contents[i][0]))
return contents[i][1];
return null;
}
/**
* This method should return all keys for which a resource exists.
* @return An enumeration of the keys.
*
* @return an enumeration of the keys
*/
public Enumeration getKeys()
{
// 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.
final Object[][] contents = getContents();
return new Enumeration()
{
int i = 0;
public boolean hasMoreElements()
{
return i < contents.length;
}
public Object nextElement()
Set s = new HashSet();
int i = contents.length;
while (--i >= 0)
s.add(contents[i][0]);
ResourceBundle bundle = parent;
// Eliminate tail recursion.
while (bundle != null)
{
return contents[i++][0];
Enumeration e = bundle.getKeys();
while (e.hasMoreElements())
s.add(e.nextElement());
bundle = bundle.parent;
}
};
return Collections.enumeration(s);
}
}
/**
* Gets the key/value list. You must override this method, and should not
* provide duplicate keys or null entries.
*
* @return a two dimensional list of String key / Object resouce pairs
*/
protected abstract Object[][] getContents();
} // class ListResourceBundle
......@@ -296,14 +296,14 @@ public interface Map
*/
public Object setValue(Object value);
/**
* Returns the hash code of the entry. This is defined as the exclusive-or
* of the hashcodes of the key and value (using 0 for null). In other
* words, this must be:
* <pre>
* (getKey() == null ? 0 : getKey().hashCode()) ^
* (getValue() == null ? 0 : getValue().hashCode())
* </pre>
* Returns the hash code of the entry. This is defined as the
* exclusive-or of the hashcodes of the key and value (using 0 for
* <code>null</code>). In other words, this must be:
*
<p><pre>(getKey() == null ? 0 : getKey().hashCode())
^ (getValue() == null ? 0 : getValue().hashCode())</pre>
*
* @return the hash code
*/
......@@ -313,16 +313,16 @@ public interface Map
* Compares the specified object with this entry. Returns true only if
* the object is a mapping of identical key and value. In other words,
* this must be:
* <pre>
* (o instanceof Map.Entry)
* && (getKey() == null ? ((HashMap) o).getKey() == null
* : getKey().equals(((HashMap) o).getKey()))
* && (getValue() == null ? ((HashMap) o).getValue() == null
* : getValue().equals(((HashMap) o).getValue()))
* </pre>
*
<p><pre>(o instanceof Map.Entry)
&& (getKey() == null ? ((HashMap) o).getKey() == null
: getKey().equals(((HashMap) o).getKey()))
&& (getValue() == null ? ((HashMap) o).getValue() == null
: getValue().equals(((HashMap) o).getValue()))</pre>
*
* @param o the object to compare
* @return true if it is equal
*
* @return <code>true</code> if it is equal
*/
public boolean equals(Object o);
}
......
/* java.util.Observable
Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
/* Observable.java -- an object to be observed
Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
This file is part of GNU Classpath.
......@@ -38,55 +38,53 @@ 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.
* Status: Believed complete and correct.
*/
/**
* This class represents an object which is observable. Other objects may
* register their intent to be notified when this object changes; and when
* this object does change, it will trigger the <code>update</code> method
* of each observer.
*
* Note that the <code>notifyObservers()</code> method of this class is
* unrelated to the <code>notify()</code> of Object.
*
* @author Warren Levy <warrenl@cygnus.com>
* @date September 2, 1998.
* @author Eric Blake <ebb9@email.byu.edu>
* @see Observer
* @status updated to 1.4
*/
public class Observable
{
/** tracks whether this object has changed */
/** Tracks whether this object has changed. */
private boolean changed;
/* list of the Observers registered as interested in this Observable */
private Vector observers;
/* TBD: This might be better implemented as an Observer[]
* but that would mean writing more code rather than making use of
* the existing Vector class (this also implies a larger text code
* space in resulting executables). The tradeoff is one of speed
* (manipulating the Observer[] directly) vs. size/reuse. In the future,
* we may decide to make the tradeoff and reimplement with an Observer[].
*/
/* List of the Observers registered as interested in this Observable. */
private LinkedHashSet observers;
/**
* Constructs an Observable with zero Observers.
*/
public Observable()
{
changed = false;
observers = new Vector();
observers = new LinkedHashSet();
}
/**
* Adds an Observer. If the observer was already added this method does
* nothing.
*
* @param observer Observer to add.
* @param observer Observer to add
* @throws NullPointerException if observer is null
*/
public synchronized void addObserver(Observer observer)
{
if (!observers.contains(observer))
observers.addElement(observer);
observers.add(observer);
}
/**
* Reset this Observable's state to unchanged.
* Reset this Observable's state to unchanged. This is called automatically
* by <code>notifyObservers</code> once all observers have been notified.
*
* @see #notifyObservers()
*/
protected synchronized void clearChanged()
{
......@@ -94,7 +92,9 @@ public class Observable
}
/**
* @return Number of Observers for this Observable.
* Returns the number of observers for this object.
*
* @return number of Observers for this
*/
public synchronized int countObservers()
{
......@@ -104,11 +104,11 @@ public class Observable
/**
* Deletes an Observer of this Observable.
*
* @param victim Observer to delete.
* @param victim Observer to delete
*/
public synchronized void deleteObserver(Observer victim)
{
observers.removeElement(victim);
observers.remove(victim);
}
/**
......@@ -116,11 +116,14 @@ public class Observable
*/
public synchronized void deleteObservers()
{
observers.removeAllElements();
observers.clear();
}
/**
* @return Whether or not this Observable has changed.
* True if <code>setChanged</code> has been called more recently than
* <code>clearChanged</code>.
*
* @return whether or not this Observable has changed
*/
public synchronized boolean hasChanged()
{
......@@ -129,7 +132,10 @@ public class Observable
/**
* If the Observable has actually changed then tell all Observers about it,
* then resets state to unchanged.
* then reset state to unchanged.
*
* @see #notifyObservers(Object)
* @see Observer#update(Observable, Object)
*/
public void notifyObservers()
{
......@@ -138,21 +144,29 @@ public class Observable
/**
* If the Observable has actually changed then tell all Observers about it,
* then resets state to unchanged.
* Note that though the order of notification is unspecified in subclasses,
* in Observable it is in the order of registration.
* then reset state to unchanged. Note that though the order of
* notification is unspecified in subclasses, in Observable it is in the
* order of registration.
*
* @param obj Arguement to Observer's update method.
* @param obj argument to Observer's update method
* @see Observer#update(Observable, Object)
*/
public void notifyObservers(Object obj)
{
if (!hasChanged())
if (! hasChanged())
return;
Vector ob1 = (Vector) observers.clone();
for (int i = 0; i < ob1.size(); i++)
((Observer) ob1.elementAt(i)).update(this, obj);
// Create clone inside monitor, as that is relatively fast and still
// important to keep threadsafe, but update observers outside of the
// lock since update() can call arbitrary code.
Set s;
synchronized (this)
{
s = (Set) observers.clone();
}
int i = s.size();
Iterator iter = s.iterator();
while (--i >= 0)
((Observer) iter.next()).update(this, obj);
clearChanged();
}
......
/* PropertyPermissionCollection.java -- a collection of PropertyPermissions
Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
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.security.Permission;
import java.security.PermissionCollection;
/**
* This class provides the implementation for
* <code>PropertyPermission.newPermissionCollection()</code>. It only accepts
* PropertyPermissions, and correctly implements <code>implies</code>. It
* is synchronized, as specified in the superclass.
*
* @author Eric Blake <ebb9@email.byu.edu>
* @status an undocumented class, but this matches Sun's serialization
*/
class PropertyPermissionCollection extends PermissionCollection
{
/**
* Compatible with JDK 1.4.
*/
private static final long serialVersionUID = 7015263904581634791L;
/**
* The permissions.
*
* @serial the table of permissions in the collection
*/
private final Hashtable permissions = new Hashtable();
/**
* A flag to detect if "*" is in the collection.
*
* @serial true if "*" is in the collection
*/
private boolean all_allowed;
/**
* Adds a PropertyPermission to this collection.
*
* @param permission the permission to add
* @throws IllegalArgumentException if permission is not a PropertyPermission
* @throws SecurityException if collection is read-only
*/
public void add(Permission permission)
{
if (isReadOnly())
throw new SecurityException("readonly");
if (! (permission instanceof PropertyPermission))
throw new IllegalArgumentException();
PropertyPermission pp = (PropertyPermission) permission;
String name = pp.getName();
if (name.equals("*"))
all_allowed = true;
PropertyPermission old = (PropertyPermission) permissions.get(name);
if (old != null)
{
if ((pp.actions | old.actions) == old.actions)
pp = old; // Old implies pp.
else if ((pp.actions | old.actions) != pp.actions)
// Here pp doesn't imply old; the only case left is both actions.
pp = new PropertyPermission(name, "read,write");
}
permissions.put(name, pp);
}
/**
* Returns true if this collection implies the given permission. This even
* returns true for this case:
* <p>
<pre>collection.add(new PropertyPermission("a.*", "read"));
collection.add(new PropertyPermission("a.b.*", "write"));
collection.implies(new PropertyPermission("a.b.c", "read,write"));</pre>
*
* @param permission the permission to check
* @return true if it is implied by this
*/
public boolean implies(Permission permission)
{
if (! (permission instanceof PropertyPermission))
return false;
PropertyPermission toImply = (PropertyPermission) permission;
int actions = toImply.actions;
if (all_allowed)
{
int all_actions = ((PropertyPermission) permissions.get("*")).actions;
actions &= ~all_actions;
if (actions == 0)
return true;
}
String name = toImply.getName();
if (name.equals("*"))
return false;
int prefixLength = name.length();
if (name.endsWith("*"))
prefixLength -= 2;
while (true)
{
PropertyPermission forName =
(PropertyPermission) permissions.get(name);
if (forName != null)
{
actions &= ~forName.actions;
if (actions == 0)
return true;
}
prefixLength = name.lastIndexOf('.', prefixLength);
if (prefixLength < 0)
return false;
name = name.substring(0, prefixLength + 1) + '*';
}
}
/**
* Enumerate over the collection.
*
* @return an enumeration of the collection contents
*/
public Enumeration elements()
{
return permissions.elements();
}
}
/* java.util.PropertyResourceBundle
Copyright (C) 1998, 1999, 2001 Free Software Foundation, Inc.
/* PropertyResourceBundle -- a resource bundle built from a Property file
Copyright (C) 1998, 1999, 2001, 2002 Free Software Foundation, Inc.
This file is part of GNU Classpath.
......@@ -38,11 +38,13 @@ exception statement from your version. */
package java.util;
import java.io.IOException;
import java.io.InputStream;
import gnu.java.util.DoubleEnumeration;
/**
* This class is a concrete <code>ResourceBundle</code> that gets it
* resources from a property file. This implies that the resources are
* resources from a property file. This implies that the resources are
* strings. For more information about resource bundles see the class
* <code>ResourceBundle</code>.
*
......@@ -52,75 +54,68 @@ import gnu.java.util.DoubleEnumeration;
* file.
*
* If there is also a class for this resource and the same locale, the
* class does win.
*
* The properties file should have the name of the resource bundle,
* appended with the locale (e.g. <code>_de</code) and the extension
* <code>.properties</code>. The file should have the same format
* class will be chosen. The properties file should have the name of the
* resource bundle, appended with the locale (e.g. <code>_de</code) and the
* extension <code>.properties</code>. The file should have the same format
* as for <code>Properties.load()</code>
*
* XXX- move this to properties.
* The file should have the following
* format: An empty line or a line starting with <code>#</code> is
* ignored. An backslash (<code>\</code>) at the end of the line
* makes the line continueing on the next line. Otherwise, each line
* describes a key/value pair. The chars up to the first whitespace,
* = or : are the key. The key is followed by one or more
* whitespaces, <code>=</code> or <code>:</code>. The rest of the
* line is the resource belonging to the key. You can give unicode
* characters with the <code>\\uxxxx</code> notation, where
* <code>xxxx</code> is the hex encoding of the 16 bit unicode char
* number.
*
* An example of a properties file for the german language is given
* here. This extends the example given in ListResourceBundle.
* 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 char <code>\u00e4<char> is the
* and put it in the CLASSPATH. (The char <code>\u00e4<char> is the
* german &auml;)
*
* <pre>
* s1=3
* s2=MeineDisk
* s3=3. M\u00e4rz 96
* s4=Die Diskette ''{1}'' enth\u00e4lt {0} in {2}.
* s5=0
* s6=keine Dateien
* s7=1
* s8=eine Datei
* s9=2
* s10={0,number} Dateien
* s11=Die Formatierung warf eine Exception: {0}
* s12=FEHLER
* s13=Ergebnis
* s14=Dialog
* s15=Auswahlkriterium
* s16=1,3
* </pre>
*
*
<pre>
s1=3
s2=MeineDisk
s3=3. M\u00e4rz 96
s4=Die Diskette ''{1}'' enth\u00e4lt {0} in {2}.
s5=0
s6=keine Dateien
s7=1
s8=eine Datei
s9=2
s10={0,number} Dateien
s11=Die Formatierung warf eine Exception: {0}
s12=FEHLER
s13=Ergebnis
s14=Dialog
s15=Auswahlkriterium
s16=1,3
</pre>
*
* @author Jochen Hoenicke
* @see ResourceBundle
* @see ListResourceBundle
* @see Properties#load()
* @author Jochen Hoenicke */
* @since 1.1
* @status updated to 1.4
*/
public class PropertyResourceBundle extends ResourceBundle
{
Properties properties;
/** The properties file this bundle is based on. */
private Properties properties;
/**
* Creates a new property resource bundle.
* @param stream An input stream, where the resources are read from.
*
* @param stream an input stream, where the resources are read from
* @throws NullPointerException if stream is null
* @throws IOException if reading the stream fails
*/
public PropertyResourceBundle(java.io.InputStream stream)
throws java.io.IOException
public PropertyResourceBundle(InputStream stream) throws IOException
{
properties = new Properties();
properties.load(stream);
}
/**
* Called by <code>getObject</code> when a resource is needed. This
* Called by <code>getObject</code> when a resource is needed. This
* returns the resource given by the key.
* @param key The key of the resource.
* @return The resource for the key or null if it doesn't exists.
*
* @param key the key of the resource
* @return the resource for the key, or null if it doesn't exist
*/
public Object handleGetObject(String key)
{
......@@ -129,16 +124,30 @@ public class PropertyResourceBundle extends ResourceBundle
/**
* This method should return all keys for which a resource exists.
* @return An enumeration of the keys.
*
* @return an enumeration of the keys
*/
public Enumeration getKeys()
{
// We must also return the keys of our parent.
if (parent != null)
if (parent == null)
return properties.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.
Set s = new HashSet();
Enumeration e = properties.propertyNames();
while (e.hasMoreElements())
s.add(e.nextElement());
ResourceBundle bundle = parent;
// Eliminate tail recursion.
do
{
return new DoubleEnumeration(properties.propertyNames(),
parent.getKeys());
e = bundle.getKeys();
while (e.hasMoreElements())
s.add(e.nextElement());
bundle = bundle.parent;
}
return properties.propertyNames();
while (bundle != null);
return Collections.enumeration(s);
}
}
} // class PropertyResourceBundle
......@@ -52,7 +52,8 @@ import java.text.DateFormatSymbols;
*
* @see Calendar
* @see GregorianCalender
* @author Jochen Hoenicke */
* @author Jochen Hoenicke
*/
public class SimpleTimeZone extends TimeZone
{
/**
......@@ -436,9 +437,9 @@ public class SimpleTimeZone extends TimeZone
* In the standard JDK the results given by this method may result in
* inaccurate results at the end of February or the beginning of March.
* To avoid this, you should use Calendar instead:
* <pre>
* offset = cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET);
* </pre>
* <code>offset = cal.get(Calendar.ZONE_OFFSET)
* + cal.get(Calendar.DST_OFFSET);</code>
*
* You could also use in
*
* This version doesn't suffer this inaccuracy.
......
......@@ -44,11 +44,11 @@ package java.util;
* it should have been scheduled and cancel itself when no longer needed.
* <p>
* Example:
* <code>
* <pre>
* Timer timer = new Timer();
* TimerTask task = new TimerTask() {
* public void run() {
* if (this.scheduledExecutionTime() < System.currentTimeMillis() + 500)
* if (this.scheduledExecutionTime() &lt; System.currentTimeMillis() + 500)
* // Do something
* else
* // Complain: We are more then half a second late!
......@@ -56,7 +56,7 @@ package java.util;
* this.cancel(); // This was our last execution
* };
* timer.scheduleAtFixedRate(task, 1000, 1000); // schedule every second
* </code>
* </pre>
* <p>
* Note that a TimerTask object is a one shot object and can only given once
* to a Timer. (The Timer will use the TimerTask object for bookkeeping,
......
/* TreeMap.java -- a class providing a basic Red-Black Tree data structure,
mapping Object --> Object
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.
......@@ -162,7 +162,7 @@ public class TreeMap extends AbstractMap
*
* @author Eric Blake <ebb9@email.byu.edu>
*/
private static final class Node extends BasicMapEntry
private static final class Node extends AbstractMap.BasicMapEntry
{
// All fields package visible for use by nested classes.
/** The color of this node. */
......@@ -623,8 +623,10 @@ public class TreeMap extends AbstractMap
Node n = getNode(key);
if (n == nil)
return null;
// Note: removeNode can alter the contents of n, so save value now.
Object result = n.value;
removeNode(n);
return n.value;
return result;
}
/**
......@@ -1768,7 +1770,7 @@ public class TreeMap extends AbstractMap
SubMap.this.clear();
}
};
return this.keys;
return this.values;
}
} // class SubMap
} // class TreeMap
/* java.util.WeakHashMap -- a hashtable that keeps only weak references
/* WeakHashMap -- a hashtable that keeps only weak references
to its keys, allowing the virtual machine to reclaim them
Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
......@@ -43,41 +43,41 @@ import java.lang.ref.WeakReference;
import java.lang.ref.ReferenceQueue;
/**
* A weak hash map has only weak references to the key. This means
* that it allows the key to be garbage collected if they are not used
* otherwise. If this happens, the weak hash map will eventually
* remove the whole entry from this map. <br>
* A weak hash map has only weak references to the key. This means that it
* allows the key to be garbage collected if it is not used otherwise. If
* this happens, the entry will eventually disappear from the map,
* asynchronously.
*
* A weak hash map makes most sense, if the keys doesn't override the
* <code>equals</code>-method: If there is no other reference to the
* <p>A weak hash map makes most sense when the keys doesn't override the
* <code>equals</code> method: If there is no other reference to the
* key nobody can ever look up the key in this table and so the entry
* can be removed. This table also works, if the <code>equals</code>
* method is overloaded, e.g. with Strings as keys, but you should be
* prepared that some entries disappear spontaneously. <br>
* can be removed. This table also works when the <code>equals</code>
* method is overloaded, such as String keys, but you should be prepared
* to deal with some entries disappearing spontaneously.
*
* You should also be prepared that this hash map behaves very
* strange: The size of this map may spontaneously shrink (even if you
* use a synchronized map and synchronize it); it behaves as if
* another thread removes entries from this table without
* synchronizations. The entry set returned by <code>entrySet</code>
* <p>Other strange behaviors to be aware of: The size of this map may
* spontaneously shrink (even if you use a synchronized map and synchronize
* it); it behaves as if another thread removes entries from this table
* without synchronization. The entry set returned by <code>entrySet</code>
* has similar phenomenons: The size may spontaneously shrink, or an
* entry, that was in the set before, suddenly disappears. <br>
* entry, that was in the set before, suddenly disappears.
*
* A weak hash map is not meant for caches; use a normal map, with
* soft references as values instead, or try {@link LinkedHashMap}. <br>
* <p>A weak hash map is not meant for caches; use a normal map, with
* soft references as values instead, or try {@link LinkedHashMap}.
*
* The weak hash map supports null values and null keys. The null key
* is never deleted from the map (except explictly of course).
* The performance of the methods are similar to that of a hash map. <br>
* <p>The weak hash map supports null values and null keys. The null key
* is never deleted from the map (except explictly of course). The
* performance of the methods are similar to that of a hash map.
*
* The value objects are strongly referenced by this table. So if a
* <p>The value objects are strongly referenced by this table. So if a
* value object maintains a strong reference to the key (either direct
* or indirect) the key will never be removed from this map. According
* to Sun, this problem may be fixed in a future release. It is not
* possible to do it with the jdk 1.2 reference model, though.
*
* @author Jochen Hoenicke
* @author Eric Blake <ebb9@email.byu.edu>
* @author Eric Blake (ebb9@email.byu.edu)
*
* @see HashMap
* @see WeakReference
* @see LinkedHashMap
......@@ -86,6 +86,9 @@ import java.lang.ref.ReferenceQueue;
*/
public class WeakHashMap extends AbstractMap implements Map
{
// WARNING: WeakHashMap is a CORE class in the bootstrap cycle. See the
// comments in vm/reference/java/lang/Runtime for implications of this fact.
/**
* The default capacity for an instance of HashMap.
* Sun's documentation mildly suggests that this (11) is the correct
......@@ -148,7 +151,7 @@ public class WeakHashMap extends AbstractMap implements Map
/**
* The rounded product of the capacity (i.e. number of buckets) and
* the load factor. When the number of elements exceeds the
* threshold, the HashMap calls <pre>rehash()</pre>.
* threshold, the HashMap calls <code>rehash()</code>.
*/
private int threshold;
......@@ -364,11 +367,11 @@ public class WeakHashMap extends AbstractMap implements Map
/**
* The slot of this entry. This should be
* <pre>
* Math.abs(key.hashCode() % buckets.length)
* </pre>
* <code>Math.abs(key.hashCode() % buckets.length)</code>.
*
* But since the key may be silently removed we have to remember
* the slot number.
*
* If this bucket was removed the slot is -1. This marker will
* prevent the bucket from being removed twice.
*/
......@@ -503,9 +506,10 @@ public class WeakHashMap extends AbstractMap implements Map
private final WeakEntrySet theEntrySet;
/**
* The hash buckets. These are linked lists.
* The hash buckets. These are linked lists. Package visible for use in
* nested classes.
*/
private WeakBucket[] buckets;
WeakBucket[] buckets;
/**
* Creates a new weak hash map with default load factor and default
......@@ -676,10 +680,12 @@ public class WeakHashMap extends AbstractMap implements Map
/**
* Removes a bucket from this hash map, if it wasn't removed before
* (e.g. one time through rehashing and one time through reference queue)
* (e.g. one time through rehashing and one time through reference queue).
* Package visible for use in nested classes.
*
* @param bucket the bucket to remove.
*/
private void internalRemove(WeakBucket bucket)
void internalRemove(WeakBucket bucket)
{
int slot = bucket.slot;
if (slot == -1)
......@@ -870,4 +876,4 @@ public class WeakHashMap extends AbstractMap implements Map
cleanQueue();
return super.values();
}
}
} // class WeakHashMap
......@@ -430,7 +430,7 @@ public class Attributes implements Cloneable, Map
* @returns the old value of the attribute name or null if it didn't exist
* yet
*/
private String putValue(Name name, String value)
String putValue(Name name, String value)
{
return (String) put(name, value);
}
......
/* Attributes.java -- exception thrown to indicate an problem with a jar file
Copyright (C) 2000 Free Software Foundation, Inc.
/* JarException.java -- thrown to indicate an problem with a jar file
Copyright (C) 2000, 2002 Free Software Foundation, Inc.
This file is part of GNU Classpath.
......@@ -41,35 +41,34 @@ import java.util.zip.ZipException;
/**
* This exception is thrown to indicate an problem with a jar file.
* It can be constructed with or without a descriptive message of the problem.
* <p>
* Note that none of the methods in the java.util.jar package actually declare
* to throw this exception, most just declare that they throw an IOException
* which is super class of JarException.
*
* @since 1.2
*
* @author Mark Wielaard (mark@klomp.org)
* @since 1.2
*/
public class JarException extends ZipException
{
// Constructors
/**
* Compatible with JDK 1.2+.
*/
private static final long serialVersionUID = 7159778400963954473L;
/**
* Create a new JarException without a descriptive error message.
*/
public JarException()
{
super();
}
/**
* Create a new JarException with a descriptive error message indicating
* what went wrong. This message can later be retrieved by calling the
* <code>getMessage()</code> method.
* @see java.lang.Throwable@getMessage()
*
* @param message The descriptive error message
* @see #getMessage()
*/
public JarException(String message)
{
......
......@@ -174,10 +174,19 @@ public class Manifest implements Cloneable
private static void read_main_section(Attributes attr,
BufferedReader br) throws IOException
{
read_version_info(attr, br);
// According to the spec we should actually call read_version_info() here.
read_attributes(attr, br);
// Explicitly set Manifest-Version attribute if not set in Main
// attributes of Manifest.
if (attr.getValue(Attributes.Name.MANIFEST_VERSION) == null)
attr.putValue(Attributes.Name.MANIFEST_VERSION, "0.0");
}
/**
* Pedantic method that requires the next attribute in the Manifest to be
* the "Manifest-Version". This follows the Manifest spec closely but
* reject some jar Manifest files out in the wild.
*/
private static void read_version_info(Attributes attr,
BufferedReader br) throws IOException
{
......@@ -185,7 +194,7 @@ public class Manifest implements Cloneable
try
{
String value = expect_header(version_header, br);
attr.putValue(version_header, value);
attr.putValue(Attributes.Name.MANIFEST_VERSION, value);
}
catch (IOException ioe)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment