summaryrefslogtreecommitdiff
path: root/java
diff options
context:
space:
mode:
Diffstat (limited to 'java')
-rw-r--r--java/applet/AppletContext.java8
-rw-r--r--java/awt/AWTEventMulticaster.java7
-rw-r--r--java/awt/AWTKeyStroke.java18
-rw-r--r--java/awt/Button.java6
-rw-r--r--java/awt/CheckboxMenuItem.java4
-rw-r--r--java/awt/Choice.java4
-rw-r--r--java/awt/Component.java31
-rw-r--r--java/awt/Container.java15
-rw-r--r--java/awt/Font.java9
-rw-r--r--java/awt/Graphics2D.java6
-rw-r--r--java/awt/GridBagLayout.java24
-rw-r--r--java/awt/KeyboardFocusManager.java16
-rw-r--r--java/awt/List.java4
-rw-r--r--java/awt/MenuBar.java2
-rw-r--r--java/awt/MenuItem.java6
-rw-r--r--java/awt/RenderingHints.java13
-rw-r--r--java/awt/Scrollbar.java2
-rw-r--r--java/awt/TextComponent.java2
-rw-r--r--java/awt/TextField.java2
-rw-r--r--java/awt/Toolkit.java12
-rw-r--r--java/awt/Window.java12
-rw-r--r--java/awt/datatransfer/DataFlavor.java12
-rw-r--r--java/awt/datatransfer/FlavorMap.java4
-rw-r--r--java/awt/datatransfer/FlavorTable.java4
-rw-r--r--java/awt/datatransfer/SystemFlavorMap.java12
-rw-r--r--java/awt/dnd/DragGestureEvent.java14
-rw-r--r--java/awt/dnd/DragGestureRecognizer.java6
-rw-r--r--java/awt/dnd/DragSource.java25
-rw-r--r--java/awt/dnd/DropTargetContext.java23
-rw-r--r--java/awt/dnd/DropTargetDragEvent.java2
-rw-r--r--java/awt/dnd/DropTargetDropEvent.java4
-rw-r--r--java/awt/dnd/DropTargetEvent.java4
-rw-r--r--java/awt/font/TextLayout.java4
-rw-r--r--java/awt/im/InputContext.java12
-rw-r--r--java/awt/im/InputMethodHighlight.java7
-rw-r--r--java/awt/im/spi/InputMethodContext.java3
-rw-r--r--java/awt/image/BufferedImage.java4
-rw-r--r--java/awt/image/CropImageFilter.java9
-rw-r--r--java/awt/image/ImageConsumer.java2
-rw-r--r--java/awt/image/ImageFilter.java3
-rw-r--r--java/awt/image/MemoryImageSource.java6
-rw-r--r--java/awt/image/PixelGrabber.java4
-rw-r--r--java/awt/image/RenderedImage.java2
-rw-r--r--java/awt/image/ReplicateScaleFilter.java9
-rw-r--r--java/awt/image/renderable/ParameterBlock.java24
-rw-r--r--java/awt/image/renderable/RenderableImage.java2
-rw-r--r--java/awt/image/renderable/RenderableImageOp.java2
-rw-r--r--java/beans/BeanDescriptor.java12
-rw-r--r--java/beans/Beans.java4
-rw-r--r--java/beans/DefaultPersistenceDelegate.java4
-rw-r--r--java/beans/Encoder.java5
-rw-r--r--java/beans/EventHandler.java18
-rw-r--r--java/beans/EventSetDescriptor.java20
-rw-r--r--java/beans/FeatureDescriptor.java6
-rw-r--r--java/beans/IndexedPropertyDescriptor.java8
-rw-r--r--java/beans/Introspector.java13
-rw-r--r--java/beans/PersistenceDelegate.java4
-rw-r--r--java/beans/PropertyDescriptor.java18
-rw-r--r--java/beans/PropertyEditorManager.java7
-rw-r--r--java/io/CharArrayWriter.java6
-rw-r--r--java/io/DeleteFileHelper.java13
-rw-r--r--java/io/File.java28
-rw-r--r--java/io/ObjectInputStream.java32
-rw-r--r--java/io/ObjectOutputStream.java10
-rw-r--r--java/io/ObjectStreamClass.java29
-rw-r--r--java/io/ObjectStreamField.java21
-rw-r--r--java/io/PrintStream.java54
-rw-r--r--java/io/PrintWriter.java52
-rw-r--r--java/io/RandomAccessFile.java2
-rw-r--r--java/io/Reader.java19
-rw-r--r--java/io/SequenceInputStream.java26
-rw-r--r--java/io/StringWriter.java21
-rw-r--r--java/io/Writer.java23
-rw-r--r--java/lang/Boolean.java16
-rw-r--r--java/lang/Byte.java34
-rw-r--r--java/lang/Character.java246
-rw-r--r--java/lang/Class.java120
-rw-r--r--java/lang/ClassLoader.java71
-rw-r--r--java/lang/Comparable.java8
-rw-r--r--java/lang/Compiler.java2
-rw-r--r--java/lang/Deprecated.java56
-rw-r--r--java/lang/Double.java27
-rw-r--r--java/lang/Enum.java43
-rw-r--r--java/lang/EnumConstantNotPresentException.java7
-rw-r--r--java/lang/Float.java27
-rw-r--r--java/lang/InheritableThreadLocal.java19
-rw-r--r--java/lang/Integer.java23
-rw-r--r--java/lang/Iterable.java4
-rw-r--r--java/lang/Long.java25
-rw-r--r--java/lang/Object.java2
-rw-r--r--java/lang/Override.java56
-rw-r--r--java/lang/Package.java14
-rw-r--r--java/lang/ProcessBuilder.java337
-rw-r--r--java/lang/SecurityManager.java6
-rw-r--r--java/lang/Short.java33
-rw-r--r--java/lang/String.java48
-rw-r--r--java/lang/StringBuffer.java120
-rw-r--r--java/lang/StringBuilder.java3
-rw-r--r--java/lang/SuppressWarnings.java69
-rw-r--r--java/lang/System.java488
-rw-r--r--java/lang/Thread.java85
-rw-r--r--java/lang/ThreadLocal.java24
-rw-r--r--java/lang/Void.java6
-rw-r--r--java/lang/annotation/Annotation.java3
-rw-r--r--java/lang/annotation/Documented.java50
-rw-r--r--java/lang/annotation/ElementType.java59
-rw-r--r--java/lang/annotation/IncompleteAnnotationException.java7
-rw-r--r--java/lang/annotation/Inherited.java51
-rw-r--r--java/lang/annotation/Retention.java59
-rw-r--r--java/lang/annotation/RetentionPolicy.java66
-rw-r--r--java/lang/annotation/Target.java52
-rw-r--r--java/lang/instrument/ClassDefinition.java6
-rw-r--r--java/lang/instrument/ClassFileTransformer.java3
-rw-r--r--java/lang/management/ManagementFactory.java15
-rw-r--r--java/lang/management/MemoryPoolMXBean.java2
-rw-r--r--java/lang/management/MemoryType.java51
-rw-r--r--java/lang/management/RuntimeMXBean.java4
-rw-r--r--java/lang/management/ThreadInfo.java16
-rw-r--r--java/lang/ref/PhantomReference.java10
-rw-r--r--java/lang/ref/Reference.java14
-rw-r--r--java/lang/ref/ReferenceQueue.java22
-rw-r--r--java/lang/ref/SoftReference.java12
-rw-r--r--java/lang/ref/WeakReference.java10
-rw-r--r--java/lang/reflect/AccessibleObject.java6
-rw-r--r--java/lang/reflect/AnnotatedElement.java6
-rw-r--r--java/lang/reflect/Array.java4
-rw-r--r--java/lang/reflect/GenericDeclaration.java3
-rw-r--r--java/lang/reflect/Proxy.java10
-rw-r--r--java/lang/reflect/TypeVariable.java7
-rw-r--r--java/math/BigDecimal.java67
-rw-r--r--java/math/BigInteger.java18
-rw-r--r--java/math/MathContext.java64
-rw-r--r--java/math/RoundingMode.java89
-rw-r--r--java/net/NetworkInterface.java20
-rw-r--r--java/net/Proxy.java137
-rw-r--r--java/net/ProxySelector.java117
-rw-r--r--java/net/URI.java10
-rw-r--r--java/net/URLClassLoader.java6
-rw-r--r--java/net/URLConnection.java9
-rw-r--r--java/nio/ByteBuffer.java10
-rw-r--r--java/nio/CharBuffer.java45
-rw-r--r--java/nio/DoubleBuffer.java10
-rw-r--r--java/nio/FloatBuffer.java10
-rw-r--r--java/nio/IntBuffer.java10
-rw-r--r--java/nio/LongBuffer.java10
-rw-r--r--java/nio/ShortBuffer.java10
-rw-r--r--java/nio/channels/Channel.java5
-rw-r--r--java/nio/channels/Selector.java4
-rw-r--r--java/nio/channels/spi/AbstractSelector.java8
-rw-r--r--java/nio/charset/Charset.java23
-rw-r--r--java/nio/charset/spi/CharsetProvider.java4
-rw-r--r--java/rmi/server/LoaderHandler.java5
-rw-r--r--java/rmi/server/RMIClassLoader.java17
-rw-r--r--java/rmi/server/RMIClassLoaderSpi.java10
-rw-r--r--java/security/AccessController.java12
-rw-r--r--java/security/AlgorithmParameters.java3
-rw-r--r--java/security/AlgorithmParametersSpi.java4
-rw-r--r--java/security/IdentityScope.java2
-rw-r--r--java/security/KeyFactory.java2
-rw-r--r--java/security/KeyFactorySpi.java7
-rw-r--r--java/security/KeyStore.java2
-rw-r--r--java/security/KeyStoreSpi.java2
-rw-r--r--java/security/MessageDigest.java12
-rw-r--r--java/security/MessageDigestSpi.java19
-rw-r--r--java/security/PermissionCollection.java4
-rw-r--r--java/security/Permissions.java2
-rw-r--r--java/security/PrivilegedAction.java6
-rw-r--r--java/security/PrivilegedExceptionAction.java6
-rw-r--r--java/security/SecureClassLoader.java7
-rw-r--r--java/security/Security.java12
-rw-r--r--java/security/Signature.java17
-rw-r--r--java/security/SignatureSpi.java19
-rw-r--r--java/security/acl/Acl.java4
-rw-r--r--java/security/acl/AclEntry.java6
-rw-r--r--java/security/acl/Group.java4
-rw-r--r--java/security/cert/CertPath.java4
-rw-r--r--java/security/cert/CertStore.java6
-rw-r--r--java/security/cert/CertStoreSpi.java6
-rw-r--r--java/security/cert/CertificateFactory.java10
-rw-r--r--java/security/cert/CertificateFactorySpi.java10
-rw-r--r--java/security/cert/CollectionCertStoreParameters.java5
-rw-r--r--java/security/cert/PKIXBuilderParameters.java4
-rw-r--r--java/security/cert/PKIXCertPathChecker.java5
-rw-r--r--java/security/cert/PKIXParameters.java19
-rw-r--r--java/security/cert/PolicyNode.java12
-rw-r--r--java/security/cert/PolicyQualifierInfo.java5
-rw-r--r--java/security/cert/X509CRL.java4
-rw-r--r--java/security/cert/X509CRLSelector.java5
-rw-r--r--java/security/cert/X509CertSelector.java17
-rw-r--r--java/security/cert/X509Certificate.java9
-rw-r--r--java/security/cert/X509Extension.java6
-rw-r--r--java/sql/Array.java13
-rw-r--r--java/sql/CallableStatement.java4
-rw-r--r--java/sql/Connection.java4
-rw-r--r--java/sql/DriverManager.java2
-rw-r--r--java/sql/Ref.java2
-rw-r--r--java/sql/ResultSet.java6
-rw-r--r--java/sql/Struct.java2
-rw-r--r--java/sql/Timestamp.java4
-rw-r--r--java/text/AttributedCharacterIterator.java9
-rw-r--r--java/text/AttributedString.java7
-rw-r--r--java/text/CollationKey.java17
-rw-r--r--java/text/Collator.java2
-rw-r--r--java/text/MessageFormat.java2
-rw-r--r--java/text/NumberFormat.java5
-rw-r--r--java/util/AbstractCollection.java48
-rw-r--r--java/util/AbstractList.java466
-rw-r--r--java/util/AbstractMap.java211
-rw-r--r--java/util/AbstractSequentialList.java30
-rw-r--r--java/util/AbstractSet.java33
-rw-r--r--java/util/ArrayList.java55
-rw-r--r--java/util/Arrays.java41
-rw-r--r--java/util/BitSet.java11
-rw-r--r--java/util/Calendar.java28
-rw-r--r--java/util/Collection.java22
-rw-r--r--java/util/Collections.java2670
-rw-r--r--java/util/Comparator.java6
-rw-r--r--java/util/Date.java20
-rw-r--r--java/util/Dictionary.java14
-rw-r--r--java/util/EnumMap.java394
-rw-r--r--java/util/EnumSet.java365
-rw-r--r--java/util/Enumeration.java7
-rw-r--r--java/util/Formatter.java222
-rw-r--r--java/util/GregorianCalendar.java3
-rw-r--r--java/util/HashMap.java138
-rw-r--r--java/util/HashSet.java22
-rw-r--r--java/util/Hashtable.java349
-rw-r--r--java/util/IdentityHashMap.java80
-rw-r--r--java/util/IllegalFormatConversionException.java6
-rw-r--r--java/util/Iterator.java6
-rw-r--r--java/util/LinkedHashMap.java26
-rw-r--r--java/util/LinkedHashSet.java13
-rw-r--r--java/util/LinkedList.java191
-rw-r--r--java/util/List.java34
-rw-r--r--java/util/ListIterator.java12
-rw-r--r--java/util/ListResourceBundle.java8
-rw-r--r--java/util/Map.java24
-rw-r--r--java/util/PriorityQueue.java332
-rw-r--r--java/util/Properties.java5
-rw-r--r--java/util/PropertyResourceBundle.java10
-rw-r--r--java/util/ResourceBundle.java2
-rw-r--r--java/util/Set.java19
-rw-r--r--java/util/SortedMap.java16
-rw-r--r--java/util/SortedSet.java16
-rw-r--r--java/util/Stack.java13
-rw-r--r--java/util/StringTokenizer.java2
-rw-r--r--java/util/Timer.java86
-rw-r--r--java/util/TreeMap.java234
-rw-r--r--java/util/TreeSet.java73
-rw-r--r--java/util/UUID.java13
-rw-r--r--java/util/Vector.java72
-rw-r--r--java/util/WeakHashMap.java54
-rw-r--r--java/util/concurrent/CopyOnWriteArrayList.java490
-rw-r--r--java/util/jar/Attributes.java14
-rw-r--r--java/util/jar/JarFile.java10
-rw-r--r--java/util/jar/Manifest.java10
-rw-r--r--java/util/logging/LogManager.java32
-rw-r--r--java/util/logging/LoggingMXBean.java2
-rw-r--r--java/util/prefs/Preferences.java4
-rw-r--r--java/util/zip/Deflater.java24
-rw-r--r--java/util/zip/DeflaterEngine.java6
-rw-r--r--java/util/zip/Inflater.java26
-rw-r--r--java/util/zip/ZipFile.java28
263 files changed, 8829 insertions, 2823 deletions
diff --git a/java/applet/AppletContext.java b/java/applet/AppletContext.java
index a17508fd4..5b6ce4524 100644
--- a/java/applet/AppletContext.java
+++ b/java/applet/AppletContext.java
@@ -1,5 +1,5 @@
/* AppletContext.java -- access the applet's runtime environment
- Copyright (C) 1999, 2002, 2004 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2002, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -52,7 +52,7 @@ import java.util.Iterator;
*
* @author Aaron M. Renn (arenn@urbanophile.com)
* @since 1.0
- * @status updated to 1.4
+ * @status updated to 1.5
*/
public interface AppletContext
{
@@ -90,7 +90,7 @@ public interface AppletContext
*
* @return a list of all the applets
*/
- Enumeration getApplets();
+ Enumeration<Applet> getApplets();
/**
* Displays the web page pointed to by the specified URL in the window
@@ -150,5 +150,5 @@ public interface AppletContext
* @return an iterator over the association keys
* @since 1.4
*/
- Iterator getStreamKeys();
+ Iterator<String> getStreamKeys();
} // interface AppletContext
diff --git a/java/awt/AWTEventMulticaster.java b/java/awt/AWTEventMulticaster.java
index f7b9163cf..07a6ffc20 100644
--- a/java/awt/AWTEventMulticaster.java
+++ b/java/awt/AWTEventMulticaster.java
@@ -1175,16 +1175,17 @@ public class AWTEventMulticaster
* @throws IllegalArgumentException if type is Void.TYPE
* @since 1.4
*/
- public static EventListener[] getListeners(EventListener l, Class type)
+ public static <T extends EventListener> T[] getListeners(EventListener l,
+ Class<T> type)
{
- ArrayList list = new ArrayList();
+ ArrayList<EventListener> list = new ArrayList<EventListener>();
if (l instanceof AWTEventMulticaster)
((AWTEventMulticaster) l).getListeners(list, type);
else if (type.isInstance(l))
list.add(l);
EventListener[] r = (EventListener[]) Array.newInstance(type, list.size());
list.toArray(r);
- return r;
+ return (T[]) r;
}
/**
diff --git a/java/awt/AWTKeyStroke.java b/java/awt/AWTKeyStroke.java
index 0e0622521..527e85873 100644
--- a/java/awt/AWTKeyStroke.java
+++ b/java/awt/AWTKeyStroke.java
@@ -1,5 +1,5 @@
/* AWTKeyStroke.java -- an immutable key stroke
- Copyright (C) 2002, 2004, 2005 Free Software Foundation
+ Copyright (C) 2002, 2004, 2005 Free Software Foundation
This file is part of GNU Classpath.
@@ -65,6 +65,7 @@ import java.util.StringTokenizer;
* no-arg constructor (of any accessibility).
*
* @author Eric Blake (ebb9@email.byu.edu)
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
* @see #getAWTKeyStroke(char)
* @since 1.4
* @status updated to 1.4
@@ -85,13 +86,15 @@ public class AWTKeyStroke implements Serializable
* under the assumption that garbage collection of a new keystroke is
* easy when we find the old one that it matches in the cache.
*/
- private static final LinkedHashMap cache = new LinkedHashMap(11, 0.75f, true)
+ private static final LinkedHashMap<AWTKeyStroke,AWTKeyStroke> cache =
+ new LinkedHashMap<AWTKeyStroke,AWTKeyStroke>(11, 0.75f, true)
{
/** The largest the keystroke cache can grow. */
private static final int MAX_CACHE_SIZE = 2048;
/** Prune stale entries. */
- protected boolean removeEldestEntry(Map.Entry eldest)
+ protected boolean removeEldestEntry(Map.Entry<AWTKeyStroke,AWTKeyStroke>
+ eldest)
{ // XXX - FIXME Use Map.Entry, not just Entry as gcj 3.1 workaround.
return size() > MAX_CACHE_SIZE;
}
@@ -114,7 +117,7 @@ public class AWTKeyStroke implements Serializable
*
* @see #getAWTKeyStroke(String)
*/
- static final HashMap vktable = new HashMap();
+ static final HashMap<String,Object> vktable = new HashMap<String,Object>();
static
{
// Using reflection saves the hassle of keeping this in sync with KeyEvent,
@@ -229,7 +232,7 @@ public class AWTKeyStroke implements Serializable
* @throws IllegalArgumentException subclass doesn't have no-arg constructor
* @throws ClassCastException subclass doesn't extend AWTKeyStroke
*/
- protected static void registerSubclass(final Class subclass)
+ protected static void registerSubclass(final Class<?> subclass)
{
if (subclass == null)
throw new IllegalArgumentException();
@@ -252,7 +255,8 @@ public class AWTKeyStroke implements Serializable
throws NoSuchMethodException, InstantiationException,
IllegalAccessException, InvocationTargetException
{
- Constructor c = subclass.getDeclaredConstructor(null);
+ Constructor<?> c =
+ subclass.getDeclaredConstructor((Class<?>[])null);
c.setAccessible(true);
// Create a new instance, to make sure that we can, and
// to cause any ClassCastException.
@@ -595,7 +599,7 @@ public class AWTKeyStroke implements Serializable
*/
protected Object readResolve() throws ObjectStreamException
{
- AWTKeyStroke s = (AWTKeyStroke) cache.get(this);
+ AWTKeyStroke s = cache.get(this);
if (s != null)
return s;
cache.put(this, this);
diff --git a/java/awt/Button.java b/java/awt/Button.java
index ae897a2f7..4c246c765 100644
--- a/java/awt/Button.java
+++ b/java/awt/Button.java
@@ -352,11 +352,11 @@ removeActionListener(ActionListener listener)
*
* @since 1.3
*/
- public EventListener[] getListeners(Class listenerType)
+ public <T extends EventListener> T[] getListeners(Class<T> listenerType)
{
if (listenerType == ActionListener.class)
- return getActionListeners();
- return (EventListener[]) Array.newInstance(listenerType, 0);
+ return (T[]) getActionListeners();
+ return (T[]) Array.newInstance(listenerType, 0);
}
/*************************************************************************/
diff --git a/java/awt/CheckboxMenuItem.java b/java/awt/CheckboxMenuItem.java
index 2df621b71..c886fc672 100644
--- a/java/awt/CheckboxMenuItem.java
+++ b/java/awt/CheckboxMenuItem.java
@@ -318,11 +318,11 @@ paramString()
* @exception ClassCastException If listenerType doesn't specify a class or
* interface that implements java.util.EventListener.
*/
- public EventListener[] getListeners (Class listenerType)
+ public <T extends EventListener> T[] getListeners (Class<T> listenerType)
{
if (listenerType == ItemListener.class)
return AWTEventMulticaster.getListeners (item_listeners, listenerType);
-
+
return super.getListeners (listenerType);
}
diff --git a/java/awt/Choice.java b/java/awt/Choice.java
index c3ec7b4c5..ae89b9e99 100644
--- a/java/awt/Choice.java
+++ b/java/awt/Choice.java
@@ -520,11 +520,11 @@ public class Choice extends Component
*
* @since 1.3
*/
- public EventListener[] getListeners (Class listenerType)
+ public <T extends EventListener> T[] getListeners (Class<T> listenerType)
{
if (listenerType == ItemListener.class)
return AWTEventMulticaster.getListeners (item_listeners, listenerType);
-
+
return super.getListeners (listenerType);
}
diff --git a/java/awt/Component.java b/java/awt/Component.java
index 0bf64096c..b6eadabbb 100644
--- a/java/awt/Component.java
+++ b/java/awt/Component.java
@@ -3422,29 +3422,29 @@ public abstract class Component
* @see #getPropertyChangeListeners()
* @since 1.3
*/
- public EventListener[] getListeners(Class listenerType)
+ public <T extends EventListener> T[] getListeners(Class<T> listenerType)
{
if (listenerType == ComponentListener.class)
- return getComponentListeners();
+ return (T[]) getComponentListeners();
if (listenerType == FocusListener.class)
- return getFocusListeners();
+ return (T[]) getFocusListeners();
if (listenerType == HierarchyListener.class)
- return getHierarchyListeners();
+ return (T[]) getHierarchyListeners();
if (listenerType == HierarchyBoundsListener.class)
- return getHierarchyBoundsListeners();
+ return (T[]) getHierarchyBoundsListeners();
if (listenerType == KeyListener.class)
- return getKeyListeners();
+ return (T[]) getKeyListeners();
if (listenerType == MouseListener.class)
- return getMouseListeners();
+ return (T[]) getMouseListeners();
if (listenerType == MouseMotionListener.class)
- return getMouseMotionListeners();
+ return (T[]) getMouseMotionListeners();
if (listenerType == MouseWheelListener.class)
- return getMouseWheelListeners();
+ return (T[]) getMouseWheelListeners();
if (listenerType == InputMethodListener.class)
- return getInputMethodListeners();
+ return (T[]) getInputMethodListeners();
if (listenerType == PropertyChangeListener.class)
- return getPropertyChangeListeners();
- return (EventListener[]) Array.newInstance(listenerType, 0);
+ return (T[]) getPropertyChangeListeners();
+ return (T[]) Array.newInstance(listenerType, 0);
}
/**
@@ -4336,7 +4336,8 @@ public abstract class Component
* @see KeyboardFocusManager#UP_CYCLE_TRAVERSAL_KEYS
* @since 1.4
*/
- public void setFocusTraversalKeys(int id, Set keystrokes)
+ public void setFocusTraversalKeys(int id,
+ Set<? extends AWTKeyStroke> keystrokes)
{
if (keystrokes == null)
{
@@ -4428,14 +4429,14 @@ public abstract class Component
*
* @since 1.4
*/
- public Set getFocusTraversalKeys (int id)
+ public Set<AWTKeyStroke> getFocusTraversalKeys (int id)
{
if (id != KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS &&
id != KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS &&
id != KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS)
throw new IllegalArgumentException();
- Set s = null;
+ Set<AWTKeyStroke> s = null;
if (focusTraversalKeys != null)
s = focusTraversalKeys[id];
diff --git a/java/awt/Container.java b/java/awt/Container.java
index dfc369822..83d9f7b78 100644
--- a/java/awt/Container.java
+++ b/java/awt/Container.java
@@ -69,10 +69,11 @@ import javax.accessibility.Accessible;
*
* @author original author unknown
* @author Eric Blake (ebb9@email.byu.edu)
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
*
* @since 1.0
*
- * @status still missing 1.4 support
+ * @status still missing 1.4 support, some generics from 1.5
*/
public class Container extends Component
{
@@ -1004,10 +1005,10 @@ public class Container extends Component
*
* @since 1.3
*/
- public EventListener[] getListeners(Class listenerType)
+ public <T extends EventListener> T[] getListeners(Class<T> listenerType)
{
if (listenerType == ContainerListener.class)
- return getContainerListeners();
+ return (T[]) getContainerListeners();
return super.getListeners(listenerType);
}
@@ -1370,7 +1371,8 @@ public class Container extends Component
*
* @since 1.4
*/
- public void setFocusTraversalKeys(int id, Set keystrokes)
+ public void setFocusTraversalKeys(int id,
+ Set<? extends AWTKeyStroke> keystrokes)
{
if (id != KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS &&
id != KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS &&
@@ -1458,7 +1460,8 @@ public class Container extends Component
if (focusTraversalKeys == null)
focusTraversalKeys = new Set[4];
- keystrokes = Collections.unmodifiableSet (new HashSet (keystrokes));
+ keystrokes =
+ Collections.unmodifiableSet(new HashSet<AWTKeyStroke>(keystrokes));
firePropertyChange (name, focusTraversalKeys[id], keystrokes);
focusTraversalKeys[id] = keystrokes;
@@ -1476,7 +1479,7 @@ public class Container extends Component
*
* @since 1.4
*/
- public Set getFocusTraversalKeys (int id)
+ public Set<AWTKeyStroke> getFocusTraversalKeys (int id)
{
if (id != KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS &&
id != KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS &&
diff --git a/java/awt/Font.java b/java/awt/Font.java
index 21fb35c7e..29b87d6af 100644
--- a/java/awt/Font.java
+++ b/java/awt/Font.java
@@ -44,6 +44,7 @@ import gnu.java.awt.peer.ClasspathFontPeer;
import java.awt.font.FontRenderContext;
import java.awt.font.GlyphVector;
import java.awt.font.LineMetrics;
+import java.awt.font.TextAttribute;
import java.awt.font.TextLayout;
import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;
@@ -351,7 +352,7 @@ public class Font implements Serializable
this.name = peer.getName(this);
}
- public Font(Map attrs)
+ public Font(Map<? extends AttributedCharacterIterator.Attribute, ?> attrs)
{
this(null, attrs);
}
@@ -797,7 +798,7 @@ public class Font implements Serializable
*
* @since 1.2
*/
- public Font deriveFont(Map attributes)
+ public Font deriveFont(Map<? extends AttributedCharacterIterator.Attribute, ?> attributes)
{
return peer.deriveFont(this, attributes);
}
@@ -811,7 +812,7 @@ public class Font implements Serializable
* @see java.text.AttributedCharacterIterator.Attribute
* @see java.awt.font.TextAttribute
*/
- public Map getAttributes()
+ public Map<TextAttribute, ?> getAttributes()
{
return peer.getAttributes(this);
}
@@ -890,7 +891,7 @@ public class Font implements Serializable
*
* @see java.awt.font.TextAttribute
*/
- public static Font getFont(Map attributes)
+ public static Font getFont(Map<? extends AttributedCharacterIterator.Attribute, ?> attributes)
{
return getFontFromToolkit(null, attributes);
}
diff --git a/java/awt/Graphics2D.java b/java/awt/Graphics2D.java
index ada13edc5..e0a1b4756 100644
--- a/java/awt/Graphics2D.java
+++ b/java/awt/Graphics2D.java
@@ -183,7 +183,7 @@ public abstract class Graphics2D extends Graphics
* @see #getComposite()
*/
public abstract void setComposite(Composite comp);
-
+
/**
* Sets the paint to be used for subsequent drawing operations.
*
@@ -227,14 +227,14 @@ public abstract class Graphics2D extends Graphics
*
* @see #addRenderingHints(Map)
*/
- public abstract void setRenderingHints(Map hints);
+ public abstract void setRenderingHints(Map<?,?> hints);
/**
* Adds/updates the rendering hint.
*
* @param hints the hints to add or update.
*/
- public abstract void addRenderingHints(Map hints);
+ public abstract void addRenderingHints(Map<?,?> hints);
/**
* Returns the current rendering hints.
diff --git a/java/awt/GridBagLayout.java b/java/awt/GridBagLayout.java
index 45ba859d8..0415c7bd3 100644
--- a/java/awt/GridBagLayout.java
+++ b/java/awt/GridBagLayout.java
@@ -46,6 +46,7 @@ import java.util.Hashtable;
/**
* @author Michael Koch (konqueror@gmx.de)
* @author Jeroen Frijters (jeroen@frijters.net)
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
*/
public class GridBagLayout
implements Serializable, LayoutManager2
@@ -62,8 +63,8 @@ public class GridBagLayout
// REMAINDER constraints.
// Constraints kept in comptable are never modified, and constraints
// kept in internalcomptable can be modified internally only.
- protected Hashtable comptable;
- private Hashtable internalcomptable;
+ protected Hashtable<Component,GridBagConstraints> comptable;
+ private Hashtable<Component,GridBagConstraints> internalcomptable;
protected GridBagLayoutInfo layoutInfo;
protected GridBagConstraints defaultConstraints;
@@ -74,8 +75,8 @@ public class GridBagLayout
public GridBagLayout ()
{
- this.comptable = new Hashtable();
- this.internalcomptable = new Hashtable();
+ this.comptable = new Hashtable<Component,GridBagConstraints>();
+ this.internalcomptable = new Hashtable<Component,GridBagConstraints>();
this.defaultConstraints= new GridBagConstraints();
}
@@ -499,16 +500,18 @@ public class GridBagLayout
// Guaranteed to contain the last component added to the given row
// or column, whose gridwidth/height is not REMAINDER.
- HashMap lastInRow = new HashMap();
- HashMap lastInCol = new HashMap();
+ HashMap<Integer,Component> lastInRow = new HashMap<Integer,Component>();
+ HashMap<Integer,Component> lastInCol = new HashMap<Integer,Component>();
Component[] components = parent.getComponents();
// Components sorted by gridwidths/heights,
// smallest to largest, with REMAINDER and RELATIVE at the end.
// These are useful when determining sizes and weights.
- ArrayList sortedByWidth = new ArrayList(components.length);
- ArrayList sortedByHeight = new ArrayList(components.length);
+ ArrayList<Component> sortedByWidth =
+ new ArrayList<Component>(components.length);
+ ArrayList<Component> sortedByHeight =
+ new ArrayList<Component>(components.length);
// STEP 1: first we figure out how many rows/columns
for (int i = 0; i < components.length; i++)
@@ -773,7 +776,7 @@ public class GridBagLayout
// STEP 3: Determine sizes and weights for columns.
for (int i = 0; i < sortedByWidth.size(); i++)
{
- Component component = (Component) sortedByWidth.get(i);
+ Component component = sortedByWidth.get(i);
// If component is not visible we dont have to care about it.
if (!component.isVisible())
@@ -887,7 +890,8 @@ public class GridBagLayout
* width. Otherwise, sort by height.
* FIXME: Use a better sorting algorithm.
*/
- private void sortBySpan (Component component, int span, ArrayList list, boolean sortByWidth)
+ private void sortBySpan (Component component, int span,
+ ArrayList<Component> list, boolean sortByWidth)
{
if (span == GridBagConstraints.REMAINDER
|| span == GridBagConstraints.RELATIVE)
diff --git a/java/awt/KeyboardFocusManager.java b/java/awt/KeyboardFocusManager.java
index eacbceb7d..cd138269e 100644
--- a/java/awt/KeyboardFocusManager.java
+++ b/java/awt/KeyboardFocusManager.java
@@ -1,5 +1,5 @@
/* KeyboardFocusManager.java -- manage component focusing via the keyboard
- Copyright (C) 2002, 2004 Free Software Foundation
+ Copyright (C) 2002, 2004, 2005 Free Software Foundation
This file is part of GNU Classpath.
@@ -555,7 +555,9 @@ public abstract class KeyboardFocusManager
* @see #UP_CYCLE_TRAVERSAL_KEYS
* @see #DOWN_CYCLE_TRAVERSAL_KEYS
*/
- public void setDefaultFocusTraversalKeys (int id, Set keystrokes)
+ public void setDefaultFocusTraversalKeys (int id,
+ Set<? extends AWTKeyStroke>
+ keystrokes)
{
if (id != KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS &&
id != KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS &&
@@ -627,7 +629,7 @@ public abstract class KeyboardFocusManager
* @see #UP_CYCLE_TRAVERSAL_KEYS
* @see #DOWN_CYCLE_TRAVERSAL_KEYS
*/
- public Set getDefaultFocusTraversalKeys (int id)
+ public Set<AWTKeyStroke> getDefaultFocusTraversalKeys (int id)
{
if (id < FORWARD_TRAVERSAL_KEYS || id > DOWN_CYCLE_TRAVERSAL_KEYS)
throw new IllegalArgumentException ();
@@ -989,9 +991,9 @@ public abstract class KeyboardFocusManager
* @return A list of explicitly registered key event dispatchers.
* @see KeyboardFocusManager#addKeyEventDispatcher(java.awt.KeyEventDispatcher)
*/
- protected List getKeyEventDispatchers ()
+ protected List<KeyEventDispatcher> getKeyEventDispatchers ()
{
- return (List) keyEventDispatchers.clone ();
+ return (List<KeyEventDispatcher>) keyEventDispatchers.clone ();
}
/**
@@ -1046,9 +1048,9 @@ public abstract class KeyboardFocusManager
* @return A list of explicitly registered key event post processors.
* @see KeyboardFocusManager#addKeyEventPostProcessor(java.awt.KeyEventPostProcessor)
*/
- protected List getKeyEventPostProcessors ()
+ protected List<KeyEventPostProcessor> getKeyEventPostProcessors ()
{
- return (List) keyEventPostProcessors.clone ();
+ return (List<KeyEventPostProcessor>) keyEventPostProcessors.clone ();
}
/**
diff --git a/java/awt/List.java b/java/awt/List.java
index d1c1dc84c..df8bffa19 100644
--- a/java/awt/List.java
+++ b/java/awt/List.java
@@ -991,11 +991,11 @@ public class List extends Component
*
* @since 1.3
*/
- public EventListener[] getListeners (Class listenerType)
+ public <T extends EventListener> T[] getListeners (Class<T> listenerType)
{
if (listenerType == ActionListener.class)
return AWTEventMulticaster.getListeners (action_listeners, listenerType);
-
+
if (listenerType == ItemListener.class)
return AWTEventMulticaster.getListeners (item_listeners, listenerType);
diff --git a/java/awt/MenuBar.java b/java/awt/MenuBar.java
index bd658cde6..6737d0419 100644
--- a/java/awt/MenuBar.java
+++ b/java/awt/MenuBar.java
@@ -272,7 +272,7 @@ public class MenuBar extends MenuComponent
*
* @return a list of all shortcuts for the menus in this menu bar
*/
- public synchronized Enumeration shortcuts()
+ public synchronized Enumeration<MenuShortcut> shortcuts()
{
Vector shortcuts = new Vector();
Enumeration e = menus.elements();
diff --git a/java/awt/MenuItem.java b/java/awt/MenuItem.java
index 7cbc9219f..b80ee4c1a 100644
--- a/java/awt/MenuItem.java
+++ b/java/awt/MenuItem.java
@@ -523,11 +523,11 @@ removeActionListener(ActionListener l)
* ClassClassException is thrown.
* @since 1.3
*/
- public EventListener[] getListeners(Class listenerType)
+ public <T extends EventListener> T[] getListeners(Class<T> listenerType)
{
if (listenerType == ActionListener.class)
- return getActionListeners();
- return (EventListener[]) Array.newInstance(listenerType, 0);
+ return (T[]) getActionListeners();
+ return (T[]) Array.newInstance(listenerType, 0);
}
/*************************************************************************/
diff --git a/java/awt/RenderingHints.java b/java/awt/RenderingHints.java
index 0e1db72b7..ce327e369 100644
--- a/java/awt/RenderingHints.java
+++ b/java/awt/RenderingHints.java
@@ -54,7 +54,8 @@ import java.util.Set;
* @author Rolf W. Rasmussen (rolfwr@ii.uib.no)
* @author Eric Blake (ebb9@email.byu.edu)
*/
-public class RenderingHints implements Map, Cloneable
+public class RenderingHints
+ implements Map<Object,Object>, Cloneable
{
/**
* The base class used to represent keys.
@@ -550,7 +551,7 @@ public class RenderingHints implements Map, Cloneable
* @param init a map containing a collection of hints (<code>null</code>
* permitted).
*/
- public RenderingHints(Map init)
+ public RenderingHints(Map<Key,?> init)
{
if (init != null)
putAll(init);
@@ -704,7 +705,7 @@ public class RenderingHints implements Map, Cloneable
* @throws IllegalArgumentException if the map contains a value that is
* not compatible with its key.
*/
- public void putAll(Map m)
+ public void putAll(Map<?,?> m)
{
// preprocess map to generate appropriate exceptions
Iterator iterator = m.keySet().iterator();
@@ -723,7 +724,7 @@ public class RenderingHints implements Map, Cloneable
*
* @return A set of keys.
*/
- public Set keySet()
+ public Set<Object> keySet()
{
return hintMap.keySet();
}
@@ -735,7 +736,7 @@ public class RenderingHints implements Map, Cloneable
*
* @return A collection of values.
*/
- public Collection values()
+ public Collection<Object> values()
{
return hintMap.values();
}
@@ -745,7 +746,7 @@ public class RenderingHints implements Map, Cloneable
*
* @return A set of entries.
*/
- public Set entrySet()
+ public Set<Map.Entry<Object,Object>> entrySet()
{
return Collections.unmodifiableSet(hintMap.entrySet());
}
diff --git a/java/awt/Scrollbar.java b/java/awt/Scrollbar.java
index 0a6ae17ef..0cba512f6 100644
--- a/java/awt/Scrollbar.java
+++ b/java/awt/Scrollbar.java
@@ -617,7 +617,7 @@ public class Scrollbar extends Component implements Accessible, Adjustable
* @exception ClassCastException If listenerType doesn't specify a class or
* interface that implements java.util.EventListener.
*/
- public EventListener[] getListeners(Class listenerType)
+ public <T extends EventListener> T[] getListeners(Class<T> listenerType)
{
if (listenerType == AdjustmentListener.class)
return AWTEventMulticaster.getListeners(adjustment_listeners,
diff --git a/java/awt/TextComponent.java b/java/awt/TextComponent.java
index 01eedaf16..8fdd94139 100644
--- a/java/awt/TextComponent.java
+++ b/java/awt/TextComponent.java
@@ -612,7 +612,7 @@ public class TextComponent extends Component
* @exception ClassCastException If listenerType doesn't specify a class or
* interface that implements java.util.EventListener.
*/
- public EventListener[] getListeners(Class listenerType)
+ public <T extends EventListener> T[] getListeners(Class<T> listenerType)
{
if (listenerType == TextListener.class)
return AWTEventMulticaster.getListeners(textListener, listenerType);
diff --git a/java/awt/TextField.java b/java/awt/TextField.java
index 61bd81ae3..b1df66f7c 100644
--- a/java/awt/TextField.java
+++ b/java/awt/TextField.java
@@ -428,7 +428,7 @@ public class TextField extends TextComponent
*
* @since 1.3
*/
- public EventListener[] getListeners (Class listenerType)
+ public <T extends EventListener> T[] getListeners (Class<T> listenerType)
{
if (listenerType == ActionListener.class)
return AWTEventMulticaster.getListeners (action_listeners, listenerType);
diff --git a/java/awt/Toolkit.java b/java/awt/Toolkit.java
index 29327cac5..69040722e 100644
--- a/java/awt/Toolkit.java
+++ b/java/awt/Toolkit.java
@@ -52,6 +52,7 @@ import java.awt.dnd.peer.DragSourceContextPeer;
import java.awt.event.AWTEventListener;
import java.awt.event.AWTEventListenerProxy;
import java.awt.event.KeyEvent;
+import java.awt.font.TextAttribute;
import java.awt.im.InputMethodHighlight;
import java.awt.image.ColorModel;
import java.awt.image.ImageObserver;
@@ -87,6 +88,7 @@ import java.net.URL;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList;
+import java.util.Hashtable;
import java.util.Map;
import java.util.Properties;
import java.util.StringTokenizer;
@@ -120,7 +122,8 @@ public abstract class Toolkit
/** The toolkit properties. */
private static Properties props = new Properties();
- protected final Map desktopProperties = new Properties();
+ protected final Map<String,Object> desktopProperties =
+ new Hashtable<String,Object>();
protected final PropertyChangeSupport desktopPropsSupport
= new PropertyChangeSupport(this);
@@ -983,8 +986,8 @@ public abstract class Toolkit
/**
* @since 1.3
*/
- public DragGestureRecognizer
- createDragGestureRecognizer(Class recognizer, DragSource ds,
+ public <T extends DragGestureRecognizer> T
+ createDragGestureRecognizer(Class<T> recognizer, DragSource ds,
Component comp, int actions,
DragGestureListener l)
{
@@ -1271,7 +1274,8 @@ public abstract class Toolkit
/**
* @since 1.3
*/
- public abstract Map mapInputMethodHighlight(InputMethodHighlight highlight);
+ public abstract Map<TextAttribute,?>
+ mapInputMethodHighlight(InputMethodHighlight highlight);
/**
* Initializes the accessibility framework. In particular, this loads the
diff --git a/java/awt/Window.java b/java/awt/Window.java
index aa13b1a27..41dff5577 100644
--- a/java/awt/Window.java
+++ b/java/awt/Window.java
@@ -1,5 +1,5 @@
/* Window.java --
- Copyright (C) 1999, 2000, 2002, 2003, 2004, 2006 Free Software Foundation
+ Copyright (C) 1999, 2000, 2002, 2003, 2004, 2005 Free Software Foundation
This file is part of GNU Classpath.
@@ -250,7 +250,9 @@ public class Window extends Container implements Accessible
/**
* Shows on-screen this window and any of its owned windows for whom
* isVisible returns true.
+ * @specnote: Deprecated starting in 1.5.
*/
+ @Deprecated
public void show()
{
synchronized (getTreeLock())
@@ -310,6 +312,10 @@ public class Window extends Container implements Accessible
}
}
+ /**
+ * @specnote: Deprecated starting in 1.5.
+ */
+ @Deprecated
public void hide()
{
// Hide visible owned windows.
@@ -604,10 +610,10 @@ public class Window extends Container implements Accessible
*
* @since 1.3
*/
- public EventListener[] getListeners(Class listenerType)
+ public <T extends EventListener> T[] getListeners(Class<T> listenerType)
{
if (listenerType == WindowListener.class)
- return getWindowListeners();
+ return (T[]) getWindowListeners();
return super.getListeners(listenerType);
}
diff --git a/java/awt/datatransfer/DataFlavor.java b/java/awt/datatransfer/DataFlavor.java
index e4a099485..baaf43d85 100644
--- a/java/awt/datatransfer/DataFlavor.java
+++ b/java/awt/datatransfer/DataFlavor.java
@@ -132,7 +132,7 @@ public class DataFlavor implements java.io.Externalizable, Cloneable
private MimeType mimeType;
// The representation class for this flavor
- private Class representationClass;
+ private Class<?> representationClass;
// The human readable name of this flavor
private String humanPresentableName;
@@ -153,8 +153,8 @@ public class DataFlavor implements java.io.Externalizable, Cloneable
*
* @exception ClassNotFoundException If the class cannot be loaded.
*/
- protected static final Class tryToLoadClass(String className,
- ClassLoader classLoader)
+ protected static final Class<?> tryToLoadClass(String className,
+ ClassLoader classLoader)
throws ClassNotFoundException
{
// Bootstrap
@@ -275,7 +275,7 @@ public class DataFlavor implements java.io.Externalizable, Cloneable
* @param representationClass The representation class for this object.
* @param humanPresentableName The display name of the object.
*/
- public DataFlavor(Class representationClass, String humanPresentableName)
+ public DataFlavor(Class<?> representationClass, String humanPresentableName)
{
if (representationClass == null)
throw new NullPointerException("representationClass must not be null");
@@ -431,7 +431,7 @@ public class DataFlavor implements java.io.Externalizable, Cloneable
*
* @return The representation class for this flavor.
*/
- public Class getRepresentationClass()
+ public Class<?> getRepresentationClass()
{
return(representationClass);
}
@@ -870,7 +870,7 @@ public class DataFlavor implements java.io.Externalizable, Cloneable
*
* @since 1.3
*/
- public final Class getDefaultRepresentationClass()
+ public final Class<?> getDefaultRepresentationClass()
{
return java.io.InputStream.class;
}
diff --git a/java/awt/datatransfer/FlavorMap.java b/java/awt/datatransfer/FlavorMap.java
index 59718c451..8842c8e55 100644
--- a/java/awt/datatransfer/FlavorMap.java
+++ b/java/awt/datatransfer/FlavorMap.java
@@ -58,7 +58,7 @@ public interface FlavorMap
*
* @return A <code>Map</code> of native data types.
*/
- Map getNativesForFlavors (DataFlavor[] flavors);
+ Map<DataFlavor, String> getNativesForFlavors (DataFlavor[] flavors);
/**
* Maps the specified native type names to <code>DataFlavor</code>'s.
@@ -71,5 +71,5 @@ public interface FlavorMap
*
* @return A <code>Map</code> of data flavors.
*/
- Map getFlavorsForNatives (String[] natives);
+ Map<String, DataFlavor> getFlavorsForNatives (String[] natives);
}
diff --git a/java/awt/datatransfer/FlavorTable.java b/java/awt/datatransfer/FlavorTable.java
index 11cdda06c..f6c43af83 100644
--- a/java/awt/datatransfer/FlavorTable.java
+++ b/java/awt/datatransfer/FlavorTable.java
@@ -59,7 +59,7 @@ public interface FlavorTable extends FlavorMap
* @param flavor the flavor to look up, or null to return all natives
* @return the sorted list of natives
*/
- List getNativesForFlavor(DataFlavor flavor);
+ List<String> getNativesForFlavor(DataFlavor flavor);
/**
* Returns a list of flavors corresponding to the given String native. The
@@ -69,5 +69,5 @@ public interface FlavorTable extends FlavorMap
* @param name the native name to look up, or null to return all flavors
* @return the sorted list of flavors
*/
- List getFlavorsForNative(String name);
+ List<DataFlavor> getFlavorsForNative(String name);
}
diff --git a/java/awt/datatransfer/SystemFlavorMap.java b/java/awt/datatransfer/SystemFlavorMap.java
index a80665aee..e163fe067 100644
--- a/java/awt/datatransfer/SystemFlavorMap.java
+++ b/java/awt/datatransfer/SystemFlavorMap.java
@@ -98,9 +98,9 @@ public final class SystemFlavorMap implements FlavorMap, FlavorTable
*
* @return A <code>Map</code> of native data types to data flavors.
*/
- public Map getNativesForFlavors (DataFlavor[] flavors)
+ public Map<DataFlavor, String> getNativesForFlavors (DataFlavor[] flavors)
{
- return new HashMap();
+ return new HashMap<DataFlavor, String>();
}
/**
@@ -114,9 +114,9 @@ public final class SystemFlavorMap implements FlavorMap, FlavorTable
*
* @return A <code>Map</code> of data flavors to native type names.
*/
- public Map getFlavorsForNatives (String[] natives)
+ public Map<String, DataFlavor> getFlavorsForNatives (String[] natives)
{
- return new HashMap();
+ return new HashMap<String, DataFlavor>();
}
/**
@@ -263,13 +263,13 @@ public final class SystemFlavorMap implements FlavorMap, FlavorTable
* specified native and a DataFlavor whose MIME type is a decoded
* version of the native.
*/
- public List getFlavorsForNative (String nat)
+ public List<DataFlavor> getFlavorsForNative (String nat)
throws NotImplementedException
{
throw new Error ("Not implemented");
}
- public List getNativesForFlavor (DataFlavor flav)
+ public List<String> getNativesForFlavor (DataFlavor flav)
throws NotImplementedException
{
throw new Error ("Not implemented");
diff --git a/java/awt/dnd/DragGestureEvent.java b/java/awt/dnd/DragGestureEvent.java
index 351ae5400..2a22abb12 100644
--- a/java/awt/dnd/DragGestureEvent.java
+++ b/java/awt/dnd/DragGestureEvent.java
@@ -59,7 +59,7 @@ public class DragGestureEvent extends EventObject
private Component component;
private final Point origin;
private final int action;
- private List events;
+ private List<InputEvent> events;
private DragGestureRecognizer dgr;
/**
@@ -71,15 +71,15 @@ public class DragGestureEvent extends EventObject
* @throws IllegalArgumentException - if input parameters are null
*/
public DragGestureEvent(DragGestureRecognizer dgr, int action, Point origin,
- List events)
- {
+ List<? extends InputEvent> events)
+ {
super(dgr);
if (origin == null || events == null || dgr == null)
throw new IllegalArgumentException();
-
+
this.origin = origin;
this.action = action;
- this.events = events;
+ this.events = (List<InputEvent>) events;
this.dgr = dgr;
this.component = dgr.getComponent();
this.dragSource = dgr.getDragSource();
@@ -130,7 +130,7 @@ public class DragGestureEvent extends EventObject
*
* @return an iterator representation of the List of events.
*/
- public Iterator iterator()
+ public Iterator<InputEvent> iterator()
{
return events.iterator();
}
@@ -155,7 +155,7 @@ public class DragGestureEvent extends EventObject
{
return events.toArray(array);
}
-
+
/**
* Gets the user's preferred action.
*
diff --git a/java/awt/dnd/DragGestureRecognizer.java b/java/awt/dnd/DragGestureRecognizer.java
index 212c5fa8d..3973e5284 100644
--- a/java/awt/dnd/DragGestureRecognizer.java
+++ b/java/awt/dnd/DragGestureRecognizer.java
@@ -1,5 +1,5 @@
/* DragGestureRecognizer.java --
- Copyright (C) 2002,2006 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2005, 2006 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -50,6 +50,8 @@ import java.util.TooManyListenersException;
/**
* STUBBED
+ * @author Michael Koch (konqueror@gmx.de)
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
* @since 1.2
*/
public abstract class DragGestureRecognizer implements Serializable
@@ -63,7 +65,7 @@ public abstract class DragGestureRecognizer implements Serializable
protected Component component;
protected transient DragGestureListener dragGestureListener;
protected int sourceActions;
- protected ArrayList events = new ArrayList();
+ protected ArrayList<InputEvent> events = new ArrayList<InputEvent>();
protected DragGestureRecognizer(DragSource ds, Component c, int sa,
DragGestureListener dgl)
diff --git a/java/awt/dnd/DragSource.java b/java/awt/dnd/DragSource.java
index f57749559..cd4a93a3e 100644
--- a/java/awt/dnd/DragSource.java
+++ b/java/awt/dnd/DragSource.java
@@ -225,15 +225,16 @@ public class DragSource implements Serializable
{
return flavorMap;
}
-
- public DragGestureRecognizer createDragGestureRecognizer(Class recognizer,
- Component c,
- int actions,
- DragGestureListener dgl)
+
+ public <T extends DragGestureRecognizer> T
+ createDragGestureRecognizer(Class<T> recognizer,
+ Component c,
+ int actions,
+ DragGestureListener dgl)
{
- return Toolkit.getDefaultToolkit().createDragGestureRecognizer(recognizer,
- this, c,
- actions, dgl);
+ return (T) Toolkit.getDefaultToolkit().createDragGestureRecognizer(recognizer,
+ this, c,
+ actions, dgl);
}
public DragGestureRecognizer createDefaultDragGestureRecognizer(Component c,
@@ -296,18 +297,18 @@ public class DragSource implements Serializable
/**
* @since 1.4
*/
- public EventListener[] getListeners (Class listenerType)
+ public <T extends EventListener> T[] getListeners (Class<T> listenerType)
{
if (listenerType == DragSourceListener.class)
return DnDEventMulticaster.getListeners (dragSourceListener,
- listenerType);
+ listenerType);
if (listenerType == DragSourceMotionListener.class)
return DnDEventMulticaster.getListeners (dragSourceMotionListener,
- listenerType);
+ listenerType);
// Return an empty EventListener array.
- return new EventListener [0];
+ return (T[]) new EventListener [0];
}
/**
diff --git a/java/awt/dnd/DropTargetContext.java b/java/awt/dnd/DropTargetContext.java
index 31945c34b..d970e2e08 100644
--- a/java/awt/dnd/DropTargetContext.java
+++ b/java/awt/dnd/DropTargetContext.java
@@ -1,5 +1,5 @@
/* DropTargetContext.java --
- Copyright (C) 2002, 2003, 2004, 2006, Free Software Foundation
+ Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation
This file is part of GNU Classpath.
@@ -49,6 +49,7 @@ import java.util.List;
/**
* @author Michael Koch (konqueror@gmx.de)
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
* @since 1.2
*/
public class DropTargetContext implements Serializable
@@ -128,51 +129,51 @@ public class DropTargetContext implements Serializable
*
* @exception InvalidDnDOperationException If a drop is not outstanding.
*/
- public void dropComplete(boolean success)
+ public void dropComplete (boolean success)
{
if (dtcp != null)
dtcp.dropComplete(success);
}
- protected void acceptDrag(int dragOperation)
+ protected void acceptDrag (int dragOperation)
{
if (dtcp != null)
dtcp.acceptDrag(dragOperation);
}
- protected void rejectDrag()
+ protected void rejectDrag ()
{
if (dtcp != null)
dtcp.rejectDrag();
}
- protected void acceptDrop(int dropOperation)
+ protected void acceptDrop (int dropOperation)
{
if (dtcp != null)
dtcp.acceptDrop(dropOperation);
}
- protected void rejectDrop()
+ protected void rejectDrop ()
{
if (dtcp != null)
dtcp.rejectDrop();
}
- protected DataFlavor[] getCurrentDataFlavors()
+ protected DataFlavor[] getCurrentDataFlavors ()
{
if (dtcp != null)
dtcp.getTransferDataFlavors();
return null;
}
- protected List getCurrentDataFlavorsAsList()
+ protected List<DataFlavor> getCurrentDataFlavorsAsList ()
{
- return Arrays.asList(getCurrentDataFlavors());
+ return Arrays.asList(getCurrentDataFlavors ());
}
- protected boolean isDataFlavorSupported(DataFlavor flavor)
+ protected boolean isDataFlavorSupported (DataFlavor flavor)
{
- return getCurrentDataFlavorsAsList().contains(flavor);
+ return getCurrentDataFlavorsAsList().contains (flavor);
}
/**
diff --git a/java/awt/dnd/DropTargetDragEvent.java b/java/awt/dnd/DropTargetDragEvent.java
index 2276d037d..58feb4387 100644
--- a/java/awt/dnd/DropTargetDragEvent.java
+++ b/java/awt/dnd/DropTargetDragEvent.java
@@ -108,7 +108,7 @@ public class DropTargetDragEvent extends DropTargetEvent
return context.getCurrentDataFlavors ();
}
- public List getCurrentDataFlavorsAsList ()
+ public List<DataFlavor> getCurrentDataFlavorsAsList ()
{
return context.getCurrentDataFlavorsAsList ();
}
diff --git a/java/awt/dnd/DropTargetDropEvent.java b/java/awt/dnd/DropTargetDropEvent.java
index 9754bb11e..dd85ef712 100644
--- a/java/awt/dnd/DropTargetDropEvent.java
+++ b/java/awt/dnd/DropTargetDropEvent.java
@@ -1,5 +1,5 @@
/* DropTargetDropEvent.java --
- Copyright (C) 2002 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2006 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -123,7 +123,7 @@ public class DropTargetDropEvent extends DropTargetEvent
return context.getCurrentDataFlavors();
}
- public List getCurrentDataFlavorsAsList()
+ public List<DataFlavor> getCurrentDataFlavorsAsList()
{
return context.getCurrentDataFlavorsAsList();
}
diff --git a/java/awt/dnd/DropTargetEvent.java b/java/awt/dnd/DropTargetEvent.java
index f75f756d0..cb2aec640 100644
--- a/java/awt/dnd/DropTargetEvent.java
+++ b/java/awt/dnd/DropTargetEvent.java
@@ -41,6 +41,10 @@ import java.util.EventObject;
public class DropTargetEvent extends EventObject
{
+
+ /**
+ * Serialization identifier for Sun 1.5 compatability
+ */
private static final long serialVersionUID = 2821229066521922993L;
protected DropTargetContext context;
diff --git a/java/awt/font/TextLayout.java b/java/awt/font/TextLayout.java
index 26e784b9a..dc0e537eb 100644
--- a/java/awt/font/TextLayout.java
+++ b/java/awt/font/TextLayout.java
@@ -244,7 +244,9 @@ public final class TextLayout implements Cloneable
layoutRuns();
}
- public TextLayout (String string, Map attributes, FontRenderContext frc)
+ public TextLayout (String string,
+ Map<? extends AttributedCharacterIterator.Attribute, ?> attributes,
+ FontRenderContext frc)
{
this( string, new Font( attributes ), frc );
}
diff --git a/java/awt/im/InputContext.java b/java/awt/im/InputContext.java
index 3806736df..c81993215 100644
--- a/java/awt/im/InputContext.java
+++ b/java/awt/im/InputContext.java
@@ -1,5 +1,5 @@
/* InputContext.java -- provides the context for text input
- Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -76,6 +76,7 @@ import java.util.Locale;
* java.awt.im.spi.InputMethodDescriptor.
*
* @author Eric Blake (ebb9@email.byu.edu)
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
* @see Component#getInputContext()
* @see Component#enableInputMethods(boolean)
* @since 1.2
@@ -86,7 +87,9 @@ public class InputContext
/**
* The list of installed input method descriptors.
*/
- private static final ArrayList descriptors = new ArrayList();
+ private static final ArrayList<InputMethodDescriptor> descriptors
+ = new ArrayList<InputMethodDescriptor>();
+
static
{
Enumeration e;
@@ -123,7 +126,7 @@ public class InputContext
{
if (line.charAt(0) != '#')
{
- Class c = Class.forName(line);
+ Class<?> c = Class.forName(line);
descriptors.add((InputMethodDescriptor) c.newInstance());
}
line = in.readLine().trim();
@@ -143,7 +146,8 @@ public class InputContext
private InputMethod im;
/** Map of locales to the most recently selected input method. */
- private final HashMap recent = new HashMap();
+ private final HashMap<Locale,InputMethod> recent
+ = new HashMap<Locale,InputMethod>();
/** The list of acceptable character subsets. */
private Character.Subset[] subsets;
diff --git a/java/awt/im/InputMethodHighlight.java b/java/awt/im/InputMethodHighlight.java
index 6fbe42fe5..a2ee86d44 100644
--- a/java/awt/im/InputMethodHighlight.java
+++ b/java/awt/im/InputMethodHighlight.java
@@ -41,6 +41,7 @@ import java.awt.Toolkit;
import java.text.Annotation;
import java.text.AttributedCharacterIterator;
import java.util.Map;
+import java.awt.font.TextAttribute;
/**
* This describes the highlight attributes of text composed in an input method.
@@ -95,7 +96,7 @@ public class InputMethodHighlight
private final int variation;
/** The unmodifiable map of rendering styles. */
- private final Map style;
+ private final Map<TextAttribute, ?> style;
/**
* Create an input method highlight style, with variation 0 and null style
@@ -134,7 +135,7 @@ public class InputMethodHighlight
* @since 1.3
*/
public InputMethodHighlight(boolean selected, int state, int variation,
- Map style)
+ Map<TextAttribute, ?> style)
{
if (state != RAW_TEXT && state != CONVERTED_TEXT)
throw new IllegalArgumentException();
@@ -181,7 +182,7 @@ public class InputMethodHighlight
* @return the style map
* @since 1.3
*/
- public Map getStyle()
+ public Map<TextAttribute, ?> getStyle()
{
return style;
}
diff --git a/java/awt/im/spi/InputMethodContext.java b/java/awt/im/spi/InputMethodContext.java
index 17ec4f8f7..aed21e8d3 100644
--- a/java/awt/im/spi/InputMethodContext.java
+++ b/java/awt/im/spi/InputMethodContext.java
@@ -1,5 +1,5 @@
/* InputMethodContext.java -- communication between an input method and client
- Copyright (C) 2002, 2004 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -53,6 +53,7 @@ import javax.swing.JFrame;
* {@link InputMethod#setInputMethodContext(InputMethodContext)}.
*
* @author Eric Blake (ebb9@email.byu.edu)
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
* @since 1.3
* @status updated to 1.4
*/
diff --git a/java/awt/image/BufferedImage.java b/java/awt/image/BufferedImage.java
index 2e483cceb..ef3141d0e 100644
--- a/java/awt/image/BufferedImage.java
+++ b/java/awt/image/BufferedImage.java
@@ -298,7 +298,7 @@ public class BufferedImage extends Image
public BufferedImage(ColorModel colormodel,
WritableRaster writableraster,
boolean premultiplied,
- Hashtable properties)
+ Hashtable<?,?> properties)
{
init(colormodel, writableraster, premultiplied, properties,
TYPE_CUSTOM);
@@ -628,7 +628,7 @@ public class BufferedImage extends Image
};
}
- public Vector getSources()
+ public Vector<RenderedImage> getSources()
{
return null;
}
diff --git a/java/awt/image/CropImageFilter.java b/java/awt/image/CropImageFilter.java
index 4fcfdec44..53b415620 100644
--- a/java/awt/image/CropImageFilter.java
+++ b/java/awt/image/CropImageFilter.java
@@ -91,11 +91,12 @@ public class CropImageFilter extends ImageFilter
*
* @param props the list of properties associated with this image
*/
- public void setProperties(Hashtable props)
+ public void setProperties(Hashtable<?, ?> props)
{
- props.put("filters", "CropImageFilter");
- if (consumer != null)
- consumer.setProperties(props);
+ Hashtable<Object, Object> prop2 = (Hashtable<Object, Object>) props;
+ prop2.put("filters", "CropImageFilter");
+ if (consumer != null)
+ consumer.setProperties(prop2);
}
/**
diff --git a/java/awt/image/ImageConsumer.java b/java/awt/image/ImageConsumer.java
index fc5ed11e5..11f64f978 100644
--- a/java/awt/image/ImageConsumer.java
+++ b/java/awt/image/ImageConsumer.java
@@ -136,7 +136,7 @@ public interface ImageConsumer
*
* @param props the list of properties associated with this image
*/
- void setProperties(Hashtable props);
+ void setProperties(Hashtable<?,?> props);
/**
* This <code>ColorModel</code> should indicate the model used by
diff --git a/java/awt/image/ImageFilter.java b/java/awt/image/ImageFilter.java
index d5eb8bf47..0ead45a4a 100644
--- a/java/awt/image/ImageFilter.java
+++ b/java/awt/image/ImageFilter.java
@@ -130,7 +130,7 @@ public class ImageFilter implements ImageConsumer, Cloneable
*
* @param props the list of properties associated with this image
*/
- public void setProperties(Hashtable props)
+ public void setProperties(Hashtable<?,?> props)
{
Hashtable copy = (Hashtable) props.clone();
Object o = copy.get("filters");
@@ -224,4 +224,3 @@ public class ImageFilter implements ImageConsumer, Cloneable
consumer.imageComplete(status);
}
}
-
diff --git a/java/awt/image/MemoryImageSource.java b/java/awt/image/MemoryImageSource.java
index c9f37fd5e..83a03ca44 100644
--- a/java/awt/image/MemoryImageSource.java
+++ b/java/awt/image/MemoryImageSource.java
@@ -88,7 +88,7 @@ public class MemoryImageSource implements ImageProducer
* @param props image properties (<code>null</code> permitted).
*/
public MemoryImageSource(int w, int h, ColorModel cm, byte[] pix, int off,
- int scan, Hashtable props)
+ int scan, Hashtable<?,?> props)
{
width = w;
height = h;
@@ -130,7 +130,7 @@ public class MemoryImageSource implements ImageProducer
* @param props image properties (<code>null</code> permitted).
*/
public MemoryImageSource(int w, int h, ColorModel cm, int[] pix, int off,
- int scan, Hashtable props)
+ int scan, Hashtable<?,?> props)
{
width = w;
height = h;
@@ -155,7 +155,7 @@ public class MemoryImageSource implements ImageProducer
*/
public MemoryImageSource(int w, int h, int[] pix, int off, int scan,
- Hashtable props)
+ Hashtable<?,?> props)
{
this(w, h, ColorModel.getRGBdefault(), pix, off, scan, props);
}
diff --git a/java/awt/image/PixelGrabber.java b/java/awt/image/PixelGrabber.java
index 70a80af3c..fc5e0efc0 100644
--- a/java/awt/image/PixelGrabber.java
+++ b/java/awt/image/PixelGrabber.java
@@ -55,7 +55,7 @@ public class PixelGrabber implements ImageConsumer
ColorModel model = ColorModel.getRGBdefault();
int hints;
- Hashtable props;
+ Hashtable<?,?> props;
int int_pixel_buffer[];
boolean ints_delivered = false;
@@ -442,7 +442,7 @@ public class PixelGrabber implements ImageConsumer
* @param props a list of properties associated with the image being
* produced
*/
- public synchronized void setProperties(Hashtable props)
+ public synchronized void setProperties(Hashtable<?,?> props)
{
this.props = props;
}
diff --git a/java/awt/image/RenderedImage.java b/java/awt/image/RenderedImage.java
index b35f86021..067e9b98e 100644
--- a/java/awt/image/RenderedImage.java
+++ b/java/awt/image/RenderedImage.java
@@ -46,7 +46,7 @@ import java.util.Vector;
*/
public interface RenderedImage
{
- Vector getSources();
+ Vector<RenderedImage> getSources();
Object getProperty(String name);
String[] getPropertyNames();
ColorModel getColorModel();
diff --git a/java/awt/image/ReplicateScaleFilter.java b/java/awt/image/ReplicateScaleFilter.java
index 8048838ae..5ba03f182 100644
--- a/java/awt/image/ReplicateScaleFilter.java
+++ b/java/awt/image/ReplicateScaleFilter.java
@@ -134,11 +134,12 @@ public class ReplicateScaleFilter extends ImageFilter
*
* @param props the list of properties associated with this image
*/
- public void setProperties(Hashtable props)
+ public void setProperties(Hashtable<?, ?> props)
{
- props.put("filters", "ReplicateScaleFilter");
- if (consumer != null)
- consumer.setProperties(props);
+ Hashtable<Object, Object> prop2 = (Hashtable<Object, Object>) props;
+ prop2.put("filters", "ReplicateScaleFilter");
+ if (consumer != null)
+ consumer.setProperties(prop2);
}
/**
diff --git a/java/awt/image/renderable/ParameterBlock.java b/java/awt/image/renderable/ParameterBlock.java
index 879d3c4fb..e484d6b87 100644
--- a/java/awt/image/renderable/ParameterBlock.java
+++ b/java/awt/image/renderable/ParameterBlock.java
@@ -45,20 +45,20 @@ import java.util.Vector;
public class ParameterBlock implements Cloneable, Serializable
{
private static final long serialVersionUID = -7577115551785240750L;
- protected Vector sources;
- protected Vector parameters;
+ protected Vector<Object> sources;
+ protected Vector<Object> parameters;
public ParameterBlock()
{
- this(new Vector(), new Vector());
+ this(new Vector<Object>(), new Vector<Object>());
}
- public ParameterBlock(Vector sources)
+ public ParameterBlock(Vector<Object> sources)
{
- this(sources, new Vector());
+ this(sources, new Vector<Object>());
}
- public ParameterBlock(Vector sources, Vector parameters)
+ public ParameterBlock(Vector<Object> sources, Vector<Object> parameters)
{
this.sources = sources;
this.parameters = parameters;
@@ -80,9 +80,9 @@ public class ParameterBlock implements Cloneable, Serializable
{
ParameterBlock pb = (ParameterBlock) shallowClone();
if (sources != null)
- pb.sources = (Vector) sources.clone();
+ pb.sources = (Vector<Object>) sources.clone();
if (parameters != null)
- pb.parameters = (Vector) parameters.clone();
+ pb.parameters = (Vector<Object>) parameters.clone();
return pb;
}
@@ -119,12 +119,12 @@ public class ParameterBlock implements Cloneable, Serializable
return sources.size();
}
- public Vector getSources()
+ public Vector<Object> getSources()
{
return sources;
}
- public void setSources(Vector sources)
+ public void setSources(Vector<Object> sources)
{
this.sources = sources;
}
@@ -140,12 +140,12 @@ public class ParameterBlock implements Cloneable, Serializable
return parameters.size();
}
- public Vector getParameters()
+ public Vector<Object> getParameters()
{
return parameters;
}
- public void setParameters(Vector parameters)
+ public void setParameters(Vector<Object> parameters)
{
this.parameters = parameters;
}
diff --git a/java/awt/image/renderable/RenderableImage.java b/java/awt/image/renderable/RenderableImage.java
index 45d2eb7eb..c2f6ad8b0 100644
--- a/java/awt/image/renderable/RenderableImage.java
+++ b/java/awt/image/renderable/RenderableImage.java
@@ -46,7 +46,7 @@ public interface RenderableImage
{
String HINTS_OBSERVED = "HINTS_OBSERVED";
- Vector getSources();
+ Vector<RenderableImage> getSources();
Object getProperty(String name);
String[] getPropertyNames();
boolean isDynamic();
diff --git a/java/awt/image/renderable/RenderableImageOp.java b/java/awt/image/renderable/RenderableImageOp.java
index 5385a82a3..b9d0cd39e 100644
--- a/java/awt/image/renderable/RenderableImageOp.java
+++ b/java/awt/image/renderable/RenderableImageOp.java
@@ -55,7 +55,7 @@ public class RenderableImageOp implements RenderableImage
this.block = (ParameterBlock) block.clone();
}
- public Vector getSources()
+ public Vector<RenderableImage> getSources()
{
if (block.sources == null)
return null;
diff --git a/java/beans/BeanDescriptor.java b/java/beans/BeanDescriptor.java
index 21227b2fe..b4bc6870d 100644
--- a/java/beans/BeanDescriptor.java
+++ b/java/beans/BeanDescriptor.java
@@ -48,14 +48,14 @@ package java.beans;
**/
public class BeanDescriptor extends FeatureDescriptor {
- Class beanClass;
- Class customizerClass;
+ Class<?> beanClass;
+ Class<?> customizerClass;
/** Create a new BeanDescriptor with the given beanClass and
** no customizer class.
** @param beanClass the class of the Bean.
**/
- public BeanDescriptor(Class beanClass) {
+ public BeanDescriptor(Class<?> beanClass) {
this(beanClass,null);
}
@@ -64,7 +64,7 @@ public class BeanDescriptor extends FeatureDescriptor {
** @param beanClass the class of the Bean.
** @param customizerClass the class of the Bean's Customizer.
**/
- public BeanDescriptor(Class beanClass, Class customizerClass) {
+ public BeanDescriptor(Class<?> beanClass, Class<?> customizerClass) {
this.beanClass = beanClass;
this.customizerClass = customizerClass;
@@ -78,12 +78,12 @@ public class BeanDescriptor extends FeatureDescriptor {
}
/** Get the Bean's class. **/
- public Class getBeanClass() {
+ public Class<?> getBeanClass() {
return beanClass;
}
/** Get the Bean's customizer's class. **/
- public Class getCustomizerClass() {
+ public Class<?> getCustomizerClass() {
return customizerClass;
}
}
diff --git a/java/beans/Beans.java b/java/beans/Beans.java
index ffcb83fc1..b3b0a422e 100644
--- a/java/beans/Beans.java
+++ b/java/beans/Beans.java
@@ -295,7 +295,7 @@ public class Beans
* @return the Bean as a new view, or if the operation
* could not be performed, the Bean itself.
*/
- public static Object getInstanceOf(Object bean, Class newClass)
+ public static Object getInstanceOf(Object bean, Class<?> newClass)
{
return bean;
}
@@ -314,7 +314,7 @@ public class Beans
* @return whether the Bean can be cast to the class type
* in question.
*/
- public static boolean isInstanceOf(Object bean, Class newBeanClass)
+ public static boolean isInstanceOf(Object bean, Class<?> newBeanClass)
{
return newBeanClass.isInstance(bean);
}
diff --git a/java/beans/DefaultPersistenceDelegate.java b/java/beans/DefaultPersistenceDelegate.java
index ca1041fef..08f6174bb 100644
--- a/java/beans/DefaultPersistenceDelegate.java
+++ b/java/beans/DefaultPersistenceDelegate.java
@@ -154,8 +154,8 @@ public class DefaultPersistenceDelegate extends PersistenceDelegate
return new Expression(oldInstance, oldInstance.getClass(), "new", args);
}
- protected void initialize(Class type, Object oldInstance, Object newInstance,
- Encoder out)
+ protected void initialize(Class<?> type, Object oldInstance,
+ Object newInstance, Encoder out)
{
// Calling the supertype's implementation of initialize makes it
// possible that descendants of classes like AbstractHashMap
diff --git a/java/beans/Encoder.java b/java/beans/Encoder.java
index b9d135831..cde1735f4 100644
--- a/java/beans/Encoder.java
+++ b/java/beans/Encoder.java
@@ -181,7 +181,7 @@ public class Encoder
return exceptionListener;
}
- public PersistenceDelegate getPersistenceDelegate(Class type)
+ public PersistenceDelegate getPersistenceDelegate(Class<?> type)
{
// This is not specified but the JDK behaves like this.
if (type == null)
@@ -215,7 +215,8 @@ public class Encoder
* access is thread safe.
* </p>
*/
- public void setPersistenceDelegate(Class type, PersistenceDelegate delegate)
+ public void setPersistenceDelegate(Class<?> type,
+ PersistenceDelegate delegate)
{
// If the argument is null this will cause a NullPointerException
// which is expected behavior.
diff --git a/java/beans/EventHandler.java b/java/beans/EventHandler.java
index 9c85893e0..318b27489 100644
--- a/java/beans/EventHandler.java
+++ b/java/beans/EventHandler.java
@@ -463,7 +463,8 @@ public class EventHandler implements InvocationHandler
* @param action Target property or method to invoke.
* @return A constructed proxy object.
*/
- public static Object create(Class listenerInterface, Object target, String action)
+ public static <T> T create(Class<T> listenerInterface, Object target,
+ String action)
{
return create(listenerInterface, target, action, null, null);
}
@@ -552,8 +553,8 @@ public class EventHandler implements InvocationHandler
* @param eventPropertyName Name of property to extract from event.
* @return A constructed proxy object.
*/
- public static Object create(Class listenerInterface, Object target,
- String action, String eventPropertyName)
+ public static <T> T create(Class<T> listenerInterface, Object target,
+ String action, String eventPropertyName)
{
return create(listenerInterface, target, action, eventPropertyName, null);
}
@@ -587,9 +588,9 @@ public class EventHandler implements InvocationHandler
* @param listenerMethodName Listener method to implement.
* @return A constructed proxy object.
*/
- public static Object create(Class listenerInterface, Object target,
- String action, String eventPropertyName,
- String listenerMethodName)
+ public static <T> T create(Class<T> listenerInterface, Object target,
+ String action, String eventPropertyName,
+ String listenerMethodName)
{
// Create EventHandler instance
EventHandler eh = new EventHandler(target, action, eventPropertyName,
@@ -597,10 +598,9 @@ public class EventHandler implements InvocationHandler
// Create proxy object passing in the event handler
Object proxy = Proxy.newProxyInstance(listenerInterface.getClassLoader(),
- new Class[] {listenerInterface},
+ new Class<?>[] {listenerInterface},
eh);
- return proxy;
+ return (T) proxy;
}
-
}
diff --git a/java/beans/EventSetDescriptor.java b/java/beans/EventSetDescriptor.java
index 381a45303..69c07423f 100644
--- a/java/beans/EventSetDescriptor.java
+++ b/java/beans/EventSetDescriptor.java
@@ -164,8 +164,8 @@ public class EventSetDescriptor extends FeatureDescriptor
* if listenerType is not an EventListener, or if methods are not
* found or are invalid.
*/
- public EventSetDescriptor(Class eventSourceClass, String eventSetName,
- Class listenerType, String listenerMethodName)
+ public EventSetDescriptor(Class<?> eventSourceClass, String eventSetName,
+ Class<?> listenerType, String listenerMethodName)
throws IntrospectionException
{
setName(eventSetName);
@@ -225,8 +225,8 @@ public class EventSetDescriptor extends FeatureDescriptor
* if listenerType is not an EventListener or if methods are not
* found or are invalid.
*/
- public EventSetDescriptor(Class eventSourceClass, String eventSetName,
- Class listenerType, String[] listenerMethodNames,
+ public EventSetDescriptor(Class<?> eventSourceClass, String eventSetName,
+ Class<?> listenerType, String[] listenerMethodNames,
String addListenerMethodName,
String removeListenerMethodName)
throws IntrospectionException
@@ -287,8 +287,8 @@ public class EventSetDescriptor extends FeatureDescriptor
* found or are invalid.
* @since 1.4
*/
- public EventSetDescriptor(Class eventSourceClass, String eventSetName,
- Class listenerType, String[] listenerMethodNames,
+ public EventSetDescriptor(Class<?> eventSourceClass, String eventSetName,
+ Class<?> listenerType, String[] listenerMethodNames,
String addListenerMethodName,
String removeListenerMethodName,
String getListenerMethodName)
@@ -357,7 +357,7 @@ public class EventSetDescriptor extends FeatureDescriptor
* methods are invalid.
* @since 1.4
*/
- public EventSetDescriptor(String eventSetName, Class listenerType,
+ public EventSetDescriptor(String eventSetName, Class<?> listenerType,
Method[] listenerMethods, Method addListenerMethod,
Method removeListenerMethod,
Method getListenerMethod)
@@ -402,7 +402,7 @@ public class EventSetDescriptor extends FeatureDescriptor
* if the listenerType is not an EventListener, or any of the
* methods are invalid.
*/
- public EventSetDescriptor(String eventSetName, Class listenerType,
+ public EventSetDescriptor(String eventSetName, Class<?> listenerType,
Method[] listenerMethods, Method addListenerMethod,
Method removeListenerMethod)
throws IntrospectionException
@@ -449,7 +449,7 @@ public class EventSetDescriptor extends FeatureDescriptor
* if the listenerType is not an EventListener, or any of the
* methods are invalid.
*/
- public EventSetDescriptor(String eventSetName, Class listenerType,
+ public EventSetDescriptor(String eventSetName, Class<?> listenerType,
MethodDescriptor[] listenerMethodDescriptors,
Method addListenerMethod,
Method removeListenerMethod)
@@ -484,7 +484,7 @@ public class EventSetDescriptor extends FeatureDescriptor
/** Returns the class that contains the event firing methods.
*/
- public Class getListenerType()
+ public Class<?> getListenerType()
{
return listenerType;
}
diff --git a/java/beans/FeatureDescriptor.java b/java/beans/FeatureDescriptor.java
index aeb409490..050885158 100644
--- a/java/beans/FeatureDescriptor.java
+++ b/java/beans/FeatureDescriptor.java
@@ -68,14 +68,14 @@ public class FeatureDescriptor
boolean hidden;
boolean preferred;
- Hashtable valueHash;
+ Hashtable<String,Object> valueHash;
/**
* Instantiate this FeatureDescriptor with appropriate default values.
*/
public FeatureDescriptor()
{
- valueHash = new Hashtable();
+ valueHash = new Hashtable<String,Object>();
}
/**
@@ -225,7 +225,7 @@ public class FeatureDescriptor
* @return an Enumerator over all the programmatic key names associated
* with this feature.
*/
- public Enumeration attributeNames()
+ public Enumeration<String> attributeNames()
{
return valueHash.keys();
}
diff --git a/java/beans/IndexedPropertyDescriptor.java b/java/beans/IndexedPropertyDescriptor.java
index 0ba2ed4f4..61c3f228d 100644
--- a/java/beans/IndexedPropertyDescriptor.java
+++ b/java/beans/IndexedPropertyDescriptor.java
@@ -76,7 +76,7 @@ import java.lang.reflect.Method;
*/
public class IndexedPropertyDescriptor extends PropertyDescriptor
{
- private Class indexedPropertyType;
+ private Class<?> indexedPropertyType;
private Method setIndex;
private Method getIndex;
@@ -112,7 +112,7 @@ public class IndexedPropertyDescriptor extends PropertyDescriptor
* @exception IntrospectionException if the methods are not found or
* invalid.
*/
- public IndexedPropertyDescriptor(String name, Class beanClass)
+ public IndexedPropertyDescriptor(String name, Class<?> beanClass)
throws IntrospectionException
{
super(name);
@@ -161,7 +161,7 @@ public class IndexedPropertyDescriptor extends PropertyDescriptor
*
* @exception IntrospectionException if the methods are not found or invalid.
*/
- public IndexedPropertyDescriptor(String name, Class beanClass,
+ public IndexedPropertyDescriptor(String name, Class<?> beanClass,
String getMethodName, String setMethodName,
String getIndexName, String setIndexName)
throws IntrospectionException
@@ -272,7 +272,7 @@ public class IndexedPropertyDescriptor extends PropertyDescriptor
: Array.newInstance(this.indexedPropertyType,0).getClass());
}
- public Class getIndexedPropertyType()
+ public Class<?> getIndexedPropertyType()
{
return indexedPropertyType;
}
diff --git a/java/beans/Introspector.java b/java/beans/Introspector.java
index 23c3cde5e..28df87f67 100644
--- a/java/beans/Introspector.java
+++ b/java/beans/Introspector.java
@@ -182,7 +182,8 @@ public class Introspector {
public static final int IGNORE_ALL_BEANINFO = 3;
static String[] beanInfoSearchPath = {"gnu.java.beans.info"};
- static Hashtable beanInfoCache = new Hashtable();
+ static Hashtable<Class<?>,BeanInfo> beanInfoCache =
+ new Hashtable<Class<?>,BeanInfo>();
private Introspector() {}
@@ -195,13 +196,13 @@ public class Introspector {
* @param beanClass the class to get BeanInfo about.
* @return the BeanInfo object representing the class.
*/
- public static BeanInfo getBeanInfo(Class beanClass)
+ public static BeanInfo getBeanInfo(Class<?> beanClass)
throws IntrospectionException
{
BeanInfo cachedInfo;
synchronized(beanClass)
{
- cachedInfo = (BeanInfo)beanInfoCache.get(beanClass);
+ cachedInfo = beanInfoCache.get(beanClass);
if(cachedInfo != null)
{
return cachedInfo;
@@ -245,7 +246,7 @@ public class Introspector {
* @throws IntrospectionException If something goes wrong while retrieving
* the bean data.
*/
- public static BeanInfo getBeanInfo(Class beanClass, int flag)
+ public static BeanInfo getBeanInfo(Class<?> beanClass, int flag)
throws IntrospectionException
{
IntrospectionIncubator ii;
@@ -312,7 +313,7 @@ public class Introspector {
* @throws NullPointerException if clz is null.
* @since 1.2
*/
- public static void flushFromCaches(Class clz)
+ public static void flushFromCaches(Class<?> clz)
{
synchronized (clz)
{
@@ -394,7 +395,7 @@ public class Introspector {
* @param stopClass the class to stop at.
* @return the BeanInfo object representing the class.
*/
- public static BeanInfo getBeanInfo(Class beanClass, Class stopClass)
+ public static BeanInfo getBeanInfo(Class<?> beanClass, Class<?> stopClass)
throws IntrospectionException
{
ExplicitInfo explicit = new ExplicitInfo(beanClass, stopClass);
diff --git a/java/beans/PersistenceDelegate.java b/java/beans/PersistenceDelegate.java
index 77953b676..a6f715763 100644
--- a/java/beans/PersistenceDelegate.java
+++ b/java/beans/PersistenceDelegate.java
@@ -52,8 +52,8 @@ package java.beans;
public abstract class PersistenceDelegate
{
- protected void initialize(Class type, Object oldInstance, Object newInstance,
- Encoder out)
+ protected void initialize(Class<?> type, Object oldInstance,
+ Object newInstance, Encoder out)
{
if (type != Object.class)
{
diff --git a/java/beans/PropertyDescriptor.java b/java/beans/PropertyDescriptor.java
index da2ca78ae..4b586d915 100644
--- a/java/beans/PropertyDescriptor.java
+++ b/java/beans/PropertyDescriptor.java
@@ -65,11 +65,11 @@ import java.lang.reflect.Method;
**/
public class PropertyDescriptor extends FeatureDescriptor
{
- Class propertyType;
+ Class<?> propertyType;
Method getMethod;
Method setMethod;
- Class propertyEditorClass;
+ Class<?> propertyEditorClass;
boolean bound;
boolean constrained;
@@ -103,7 +103,7 @@ public class PropertyDescriptor extends FeatureDescriptor
** @exception IntrospectionException if the methods are not found
** or invalid.
**/
- public PropertyDescriptor(String name, Class beanClass)
+ public PropertyDescriptor(String name, Class<?> beanClass)
throws IntrospectionException
{
setName(name);
@@ -159,7 +159,7 @@ public class PropertyDescriptor extends FeatureDescriptor
**/
public PropertyDescriptor(
String name,
- Class beanClass,
+ Class<?> beanClass,
String getMethodName,
String setMethodName)
throws IntrospectionException
@@ -213,7 +213,7 @@ public class PropertyDescriptor extends FeatureDescriptor
** This is the type the get method returns and the set method
** takes in.
**/
- public Class getPropertyType()
+ public Class<?> getPropertyType()
{
return propertyType;
}
@@ -330,7 +330,7 @@ public class PropertyDescriptor extends FeatureDescriptor
}
/** Get the PropertyEditor class. Defaults to null. **/
- public Class getPropertyEditorClass()
+ public Class<?> getPropertyEditorClass()
{
return propertyEditorClass;
}
@@ -341,7 +341,7 @@ public class PropertyDescriptor extends FeatureDescriptor
** @param propertyEditorClass the PropertyEditor class for this
** class to use.
**/
- public void setPropertyEditorClass(Class propertyEditorClass)
+ public void setPropertyEditorClass(Class<?> propertyEditorClass)
{
this.propertyEditorClass = propertyEditorClass;
}
@@ -516,10 +516,10 @@ public class PropertyDescriptor extends FeatureDescriptor
* @return The common property type of the two method.
* @throws IntrospectionException If any of the above requirements are not met.
*/
- private Class checkMethods(Method readMethod, Method writeMethod)
+ private Class<?> checkMethods(Method readMethod, Method writeMethod)
throws IntrospectionException
{
- Class newPropertyType = propertyType;
+ Class<?> newPropertyType = propertyType;
// a valid read method has zero arguments and a non-void return type.
if (readMethod != null)
diff --git a/java/beans/PropertyEditorManager.java b/java/beans/PropertyEditorManager.java
index da2a5678c..0dd3b176d 100644
--- a/java/beans/PropertyEditorManager.java
+++ b/java/beans/PropertyEditorManager.java
@@ -83,7 +83,8 @@ import java.awt.Font;
public class PropertyEditorManager
{
- static java.util.Hashtable editors = new java.util.Hashtable();
+ static java.util.Hashtable<Class<?>,Class<?>> editors =
+ new java.util.Hashtable<Class<?>,Class<?>>();
static String[] editorSearchPath = { "gnu.java.beans.editors",
"sun.beans.editors" };
@@ -118,7 +119,7 @@ public class PropertyEditorManager
* will edit.
* @param editorClass the PropertyEditor class.
*/
- public static void registerEditor(Class editedClass, Class editorClass)
+ public static void registerEditor(Class<?> editedClass, Class<?> editorClass)
{
editors.put(editedClass, editorClass);
}
@@ -132,7 +133,7 @@ public class PropertyEditorManager
* @return a PropertyEditor instance that can edit the
* specified class.
*/
- public static PropertyEditor findEditor(Class editedClass)
+ public static PropertyEditor findEditor(Class<?> editedClass)
{
try
{
diff --git a/java/io/CharArrayWriter.java b/java/io/CharArrayWriter.java
index 68e693b4a..0eead3ad3 100644
--- a/java/io/CharArrayWriter.java
+++ b/java/io/CharArrayWriter.java
@@ -267,7 +267,7 @@ public class CharArrayWriter extends Writer
* sequence is wrapped around an input buffer, the results will
* depend on the current position and length of that buffer.
*
- * @param cs the character sequence to append. If cs is null,
+ * @param seq the character sequence to append. If seq is null,
* then the string "null" (the string representation of null)
* is appended.
* @return a reference to this object.
@@ -291,10 +291,10 @@ public class CharArrayWriter extends Writer
* output stream underlying this writer, starting and ending at the
* specified positions within the sequence. The behaviour of this
* method matches the behaviour of writing the result of
- * <code>append(cs.subSequence(start,end))</code> when the sequence
+ * <code>append(seq.subSequence(start,end))</code> when the sequence
* is not null.
*
- * @param cs the character sequence to append. If cs is null,
+ * @param seq the character sequence to append. If seq is null,
* then the string "null" (the string representation of null)
* is appended.
* @param start the index of the first Unicode character to use from
diff --git a/java/io/DeleteFileHelper.java b/java/io/DeleteFileHelper.java
index d73628c49..6e33adce8 100644
--- a/java/io/DeleteFileHelper.java
+++ b/java/io/DeleteFileHelper.java
@@ -1,5 +1,5 @@
/* DeleteFileHelper.java -- Helper class to delete files on VM exit
- Copyright (C) 2004 Free Software Foundation, Inc.
+ Copyright (C) 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -40,22 +40,22 @@ package java.io;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList;
-import java.util.Iterator;
/**
* @author Guilhem Lavaux (guilhem@kaffe.org)
* @author Jeroen Frijters (jeroen@sumatra.nl)
* @author Michael Koch (konqueror@gmx.de)
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
*/
final class DeleteFileHelper extends Thread
{
- private static ArrayList filesToDelete;
+ private static ArrayList<File> filesToDelete;
static synchronized void add(File file)
{
if (filesToDelete == null)
{
- filesToDelete = new ArrayList();
+ filesToDelete = new ArrayList<File>();
AccessController.doPrivileged(new PrivilegedAction()
{
@@ -81,13 +81,10 @@ final class DeleteFileHelper extends Thread
private static synchronized void deleteFiles()
{
- Iterator it = filesToDelete.iterator();
-
- while (it.hasNext())
+ for (File file : filesToDelete)
{
try
{
- File file = (File) it.next();
file.delete();
}
catch (Exception e)
diff --git a/java/io/File.java b/java/io/File.java
index 49a0c818c..5d1b3ec85 100644
--- a/java/io/File.java
+++ b/java/io/File.java
@@ -60,7 +60,7 @@ import java.net.URL;
* @author Aaron M. Renn (arenn@urbanophile.com)
* @author Tom Tromey (tromey@cygnus.com)
*/
-public class File implements Serializable, Comparable
+public class File implements Serializable, Comparable<File>
{
private static final long serialVersionUID = 301077366599181567L;
@@ -1253,32 +1253,6 @@ public class File implements Serializable, Comparable
}
/**
- * This method compares the specified <code>Object</code> to this one
- * to test for equality. It does this by comparing the canonical path names
- * of the files. This method is identical to <code>compareTo(File)</code>
- * except that if the <code>Object</code> passed to it is not a
- * <code>File</code>, it throws a <code>ClassCastException</code>
- * <p>
- * The canonical paths of the files are determined by calling the
- * <code>getCanonicalPath</code> method on each object.
- * <p>
- * This method returns a 0 if the specified <code>Object</code> is equal
- * to this one, a negative value if it is less than this one
- * a positive value if it is greater than this one.
- *
- * @return An integer as described above
- *
- * @exception ClassCastException If the passed <code>Object</code> is
- * not a <code>File</code>
- *
- * @since 1.2
- */
- public int compareTo(Object obj)
- {
- return compareTo((File) obj);
- }
-
- /**
* This method renames the file represented by this object to the path
* of the file represented by the argument <code>File</code>.
*
diff --git a/java/io/ObjectInputStream.java b/java/io/ObjectInputStream.java
index 910312e34..d6c1406ea 100644
--- a/java/io/ObjectInputStream.java
+++ b/java/io/ObjectInputStream.java
@@ -55,6 +55,13 @@ import java.util.Iterator;
import java.util.TreeSet;
import java.util.Vector;
+/**
+ * @author Tom Tromey (tromey@redhat.com)
+ * @author Jeroen Frijters (jeroen@frijters.net)
+ * @author Guilhem Lavaux (guilhem@kaffe.org)
+ * @author Michael Koch (konqueror@gmx.de)
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
+ */
public class ObjectInputStream extends InputStream
implements ObjectInput, ObjectStreamConstants
{
@@ -97,8 +104,8 @@ public class ObjectInputStream extends InputStream
this.blockDataInput = new DataInputStream(this);
this.realInputStream = new DataInputStream(in);
this.nextOID = baseWireHandle;
- this.objectLookupTable = new Vector();
- this.classLookupTable = new Hashtable();
+ this.objectLookupTable = new Vector<Object>();
+ this.classLookupTable = new Hashtable<Class,ObjectStreamClass>();
setBlockDataMode(true);
readStreamHeader();
}
@@ -347,7 +354,8 @@ public class ObjectInputStream extends InputStream
int handle = assignNewHandle(obj);
Object prevObject = this.currentObject;
ObjectStreamClass prevObjectStreamClass = this.currentObjectStreamClass;
- TreeSet prevObjectValidators = this.currentObjectValidators;
+ TreeSet<ValidatorAndPriority> prevObjectValidators =
+ this.currentObjectValidators;
this.currentObject = obj;
this.currentObjectValidators = null;
@@ -754,7 +762,7 @@ public class ObjectInputStream extends InputStream
+ "ObjectInputValidation object");
if (currentObjectValidators == null)
- currentObjectValidators = new TreeSet();
+ currentObjectValidators = new TreeSet<ValidatorAndPriority>();
currentObjectValidators.add(new ValidatorAndPriority(validator, priority));
}
@@ -776,7 +784,7 @@ public class ObjectInputStream extends InputStream
*
* @see java.io.ObjectOutputStream#annotateClass (java.lang.Class)
*/
- protected Class resolveClass(ObjectStreamClass osc)
+ protected Class<?> resolveClass(ObjectStreamClass osc)
throws ClassNotFoundException, IOException
{
String name = osc.getName();
@@ -878,12 +886,12 @@ public class ObjectInputStream extends InputStream
}
- protected Class resolveProxyClass(String[] intfs)
+ protected Class<?> resolveProxyClass(String[] intfs)
throws IOException, ClassNotFoundException
{
ClassLoader cl = currentLoader();
- Class[] clss = new Class[intfs.length];
+ Class<?>[] clss = new Class<?>[intfs.length];
if(cl == null)
{
for (int i = 0; i < intfs.length; i++)
@@ -1891,10 +1899,10 @@ public class ObjectInputStream extends InputStream
{
try
{
- Iterator it = currentObjectValidators.iterator();
+ Iterator<ValidatorAndPriority> it = currentObjectValidators.iterator();
while(it.hasNext())
{
- ValidatorAndPriority vap = (ValidatorAndPriority) it.next();
+ ValidatorAndPriority vap = it.next();
ObjectInputValidation validator = vap.validator;
validator.validateObject();
}
@@ -1947,13 +1955,13 @@ public class ObjectInputStream extends InputStream
private boolean useSubclassMethod;
private int nextOID;
private boolean resolveEnabled;
- private Vector objectLookupTable;
+ private Vector<Object> objectLookupTable;
private Object currentObject;
private ObjectStreamClass currentObjectStreamClass;
- private TreeSet currentObjectValidators;
+ private TreeSet<ValidatorAndPriority> currentObjectValidators;
private boolean readDataFromBlock;
private boolean fieldsAlreadyRead;
- private Hashtable classLookupTable;
+ private Hashtable<Class,ObjectStreamClass> classLookupTable;
private GetField prereadFields;
private static boolean dump;
diff --git a/java/io/ObjectOutputStream.java b/java/io/ObjectOutputStream.java
index 4aa303218..c3c3df9a3 100644
--- a/java/io/ObjectOutputStream.java
+++ b/java/io/ObjectOutputStream.java
@@ -48,6 +48,7 @@ import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+
/**
* An <code>ObjectOutputStream</code> can be used to write objects
* as well as primitive data in a platform-independent manner to an
@@ -113,6 +114,11 @@ import java.lang.reflect.Method;
* @see java.io.Externalizable
* @see java.io.ObjectInputStream
* @see java.io.Serializable
+ * @author Tom Tromey (tromey@redhat.com)
+ * @author Jeroen Frijters (jeroen@frijters.net)
+ * @author Guilhem Lavaux (guilhem@kaffe.org)
+ * @author Michael Koch (konqueror@gmx.de)
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
*/
public class ObjectOutputStream extends OutputStream
implements ObjectOutput, ObjectStreamConstants
@@ -601,11 +607,11 @@ public class ObjectOutputStream extends OutputStream
*
* @see ObjectInputStream#resolveClass(java.io.ObjectStreamClass)
*/
- protected void annotateClass(Class cl) throws IOException
+ protected void annotateClass(Class<?> cl) throws IOException
{
}
- protected void annotateProxyClass(Class cl) throws IOException
+ protected void annotateProxyClass(Class<?> cl) throws IOException
{
}
diff --git a/java/io/ObjectStreamClass.java b/java/io/ObjectStreamClass.java
index 86de3c980..52a1ad428 100644
--- a/java/io/ObjectStreamClass.java
+++ b/java/io/ObjectStreamClass.java
@@ -1,6 +1,6 @@
/* ObjectStreamClass.java -- Class used to write class information
about serialized objects.
- Copyright (C) 1998, 1999, 2000, 2001, 2003 Free Software Foundation, Inc.
+ Copyright (C) 1998, 1999, 2000, 2001, 2003, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -60,6 +60,13 @@ import java.util.Arrays;
import java.util.Comparator;
import java.util.Hashtable;
+/**
+ * @author Tom Tromey (tromey@redhat.com)
+ * @author Jeroen Frijters (jeroen@frijters.net)
+ * @author Guilhem Lavaux (guilhem@kaffe.org)
+ * @author Michael Koch (konqueror@gmx.de)
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
+ */
public class ObjectStreamClass implements Serializable
{
static final ObjectStreamField[] INVALID_FIELDS = new ObjectStreamField[0];
@@ -79,7 +86,7 @@ public class ObjectStreamClass implements Serializable
*
* @see java.io.Serializable
*/
- public static ObjectStreamClass lookup(Class cl)
+ public static ObjectStreamClass lookup(Class<?> cl)
{
if (cl == null)
return null;
@@ -131,7 +138,7 @@ public class ObjectStreamClass implements Serializable
*
* @see java.io.ObjectInputStream
*/
- public Class forClass()
+ public Class<?> forClass()
{
return clazz;
}
@@ -234,7 +241,6 @@ public class ObjectStreamClass implements Serializable
return superClass;
}
-
/**
* returns an array of ObjectStreamClasses that represent the super
* classes of the class represented by this and the class
@@ -252,19 +258,19 @@ public class ObjectStreamClass implements Serializable
{
ObjectStreamClass[] result = hierarchy;
if (result == null)
- {
+ {
int d = 0;
-
+
for(ObjectStreamClass osc = this; osc != null; osc = osc.getSuper())
d++;
-
+
result = new ObjectStreamClass[d];
-
+
for (ObjectStreamClass osc = this; osc != null; osc = osc.getSuper())
{
result[--d] = osc;
}
-
+
hierarchy = result;
}
return result;
@@ -1054,7 +1060,8 @@ outer:
public static final ObjectStreamField[] NO_FIELDS = {};
- private static Hashtable classLookupTable = new Hashtable();
+ private static Hashtable<Class,ObjectStreamClass> classLookupTable
+ = new Hashtable<Class,ObjectStreamClass>();
private static final NullOutputStream nullOutputStream = new NullOutputStream();
private static final Comparator interfaceComparator = new InterfaceComparator();
private static final Comparator memberComparator = new MemberComparator();
@@ -1062,7 +1069,7 @@ outer:
Class[] writeMethodArgTypes = { java.io.ObjectOutputStream.class };
private ObjectStreamClass superClass;
- private Class clazz;
+ private Class<?> clazz;
private String name;
private long uid;
private byte flags;
diff --git a/java/io/ObjectStreamField.java b/java/io/ObjectStreamField.java
index 4d6eb7f1d..91f557870 100644
--- a/java/io/ObjectStreamField.java
+++ b/java/io/ObjectStreamField.java
@@ -1,5 +1,5 @@
/* ObjectStreamField.java -- Class used to store name and class of fields
- Copyright (C) 1998, 1999, 2003, 2004 Free Software Foundation, Inc.
+ Copyright (C) 1998, 1999, 2003, 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -48,11 +48,18 @@ import java.security.PrivilegedAction;
* This class intends to describe the field of a class for the serialization
* subsystem. Serializable fields in a serializable class can be explicitly
* exported using an array of ObjectStreamFields.
+ *
+ * @author Tom Tromey (tromey@redhat.com)
+ * @author Jeroen Frijters (jeroen@frijters.net)
+ * @author Guilhem Lavaux (guilhem@kaffe.org)
+ * @author Michael Koch (konqueror@gmx.de)
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
*/
-public class ObjectStreamField implements Comparable
+public class ObjectStreamField
+ implements Comparable<Object>
{
private String name;
- private Class type;
+ private Class<?> type;
private String typename;
private int offset = -1; // XXX make sure this is correct
private boolean unshared;
@@ -74,7 +81,7 @@ public class ObjectStreamField implements Comparable
* @param name Name of the field to export.
* @param type Type of the field in the concerned class.
*/
- public ObjectStreamField (String name, Class type)
+ public ObjectStreamField (String name, Class<?> type)
{
this (name, type, false);
}
@@ -88,7 +95,7 @@ public class ObjectStreamField implements Comparable
* @param type Type of the field in the concerned class.
* @param unshared true if field will be unshared, false otherwise.
*/
- public ObjectStreamField (String name, Class type, boolean unshared)
+ public ObjectStreamField (String name, Class<?> type, boolean unshared)
{
if (name == null)
throw new NullPointerException();
@@ -141,7 +148,7 @@ public class ObjectStreamField implements Comparable
*
* @return A class representing the type of the field.
*/
- public Class getType ()
+ public Class<?> getType ()
{
return type;
}
@@ -329,7 +336,7 @@ public class ObjectStreamField implements Comparable
*/
void checkFieldType() throws InvalidClassException
{
- Class ftype = field.getType();
+ Class<?> ftype = field.getType();
if (!ftype.isAssignableFrom(type))
throw new InvalidClassException
diff --git a/java/io/PrintStream.java b/java/io/PrintStream.java
index 2d31bbd1e..2d747c8c8 100644
--- a/java/io/PrintStream.java
+++ b/java/io/PrintStream.java
@@ -39,6 +39,9 @@ exception statement from your version. */
package java.io;
+import java.util.Locale;
+import java.util.Formatter;
+
import gnu.classpath.SystemProperties;
/* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3
@@ -58,8 +61,9 @@ import gnu.classpath.SystemProperties;
*
* @author Aaron M. Renn (arenn@urbanophile.com)
* @author Tom Tromey (tromey@cygnus.com)
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
*/
-public class PrintStream extends FilterOutputStream
+public class PrintStream extends FilterOutputStream implements Appendable
{
/* Notice the implementation is quite similar to OutputStreamWriter.
* This leads to some minor duplication, because neither inherits
@@ -620,5 +624,51 @@ public class PrintStream extends FilterOutputStream
setError ();
}
}
-} // class PrintStream
+ /** @since 1.5 */
+ public PrintStream append(char c)
+ {
+ print(c);
+ return this;
+ }
+
+ /** @since 1.5 */
+ public PrintStream append(CharSequence cs)
+ {
+ print(cs == null ? "null" : cs.toString());
+ return this;
+ }
+
+ /** @since 1.5 */
+ public PrintStream append(CharSequence cs, int start, int end)
+ {
+ print(cs == null ? "null" : cs.subSequence(start, end).toString());
+ return this;
+ }
+
+ /** @since 1.5 */
+ public PrintStream printf(String format, Object... args)
+ {
+ return format(format, args);
+ }
+
+ /** @since 1.5 */
+ public PrintStream printf(Locale locale, String format, Object... args)
+ {
+ return format(locale, format, args);
+ }
+
+ /** @since 1.5 */
+ public PrintStream format(String format, Object... args)
+ {
+ return format(Locale.getDefault(), format, args);
+ }
+
+ /** @since 1.5 */
+ public PrintStream format(Locale locale, String format, Object... args)
+ {
+ Formatter f = new Formatter(this, locale);
+ f.format(format, args);
+ return this;
+ }
+} // class PrintStream
diff --git a/java/io/PrintWriter.java b/java/io/PrintWriter.java
index 5667e7050..5b4294cba 100644
--- a/java/io/PrintWriter.java
+++ b/java/io/PrintWriter.java
@@ -1,5 +1,5 @@
/* PrintWriter.java -- prints primitive values and objects to a stream as text
- Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation
+ Copyright (C) 1998, 1999, 2000, 2001, 2005 Free Software Foundation
This file is part of GNU Classpath.
@@ -37,6 +37,9 @@ exception statement from your version. */
package java.io;
+import java.util.Locale;
+import java.util.Formatter;
+
/* Written using "Java Class Libraries", 2nd edition, plus online
* API docs for JDK 1.2 beta from http://www.javasoft.com.
* Status: Believed complete and correct.
@@ -636,5 +639,52 @@ public class PrintWriter extends Writer
{
write(str, 0, str.length());
}
+
+ /** @since 1.5 */
+ public PrintWriter append(char c)
+ {
+ write(c);
+ return this;
+ }
+
+ /** @since 1.5 */
+ public PrintWriter append(CharSequence cs)
+ {
+ write(cs == null ? "null" : cs.toString());
+ return this;
+ }
+
+ /** @since 1.5 */
+ public PrintWriter append(CharSequence cs, int start, int end)
+ {
+ write(cs == null ? "null" : cs.subSequence(start, end).toString());
+ return this;
+ }
+
+ /** @since 1.5 */
+ public PrintWriter printf(String format, Object... args)
+ {
+ return format(format, args);
+ }
+
+ /** @since 1.5 */
+ public PrintWriter printf(Locale locale, String format, Object... args)
+ {
+ return format(locale, format, args);
+ }
+
+ /** @since 1.5 */
+ public PrintWriter format(String format, Object... args)
+ {
+ return format(Locale.getDefault(), format, args);
+ }
+
+ /** @since 1.5 */
+ public PrintWriter format(Locale locale, String format, Object... args)
+ {
+ Formatter f = new Formatter(this, locale);
+ f.format(format, args);
+ return this;
+ }
}
diff --git a/java/io/RandomAccessFile.java b/java/io/RandomAccessFile.java
index 84f13a2fc..036fc8c6b 100644
--- a/java/io/RandomAccessFile.java
+++ b/java/io/RandomAccessFile.java
@@ -58,7 +58,7 @@ import java.nio.channels.FileChannel;
* @author Aaron M. Renn (arenn@urbanophile.com)
* @author Tom Tromey (tromey@cygnus.com)
*/
-public class RandomAccessFile implements DataOutput, DataInput
+public class RandomAccessFile implements DataOutput, DataInput, Closeable
{
// The underlying file.
diff --git a/java/io/Reader.java b/java/io/Reader.java
index 7970d9a24..6da1813c6 100644
--- a/java/io/Reader.java
+++ b/java/io/Reader.java
@@ -1,5 +1,5 @@
/* Reader.java -- base class of classes that read input as a stream of chars
- Copyright (C) 1998, 1999, 2000, 2003 Free Software Foundation
+ Copyright (C) 1998, 1999, 2000, 2003, 2004, 2005 Free Software Foundation
This file is part of GNU Classpath.
@@ -37,6 +37,8 @@ exception statement from your version. */
package java.io;
+import java.nio.CharBuffer;
+
/* Written using "Java Class Libraries", 2nd edition, plus online
* API docs for JDK 1.2 beta from http://www.javasoft.com.
* Status: Believed complete and correct.
@@ -53,7 +55,7 @@ package java.io;
* @date April 21, 1998.
* @author Aaron M. Renn (arenn@urbanophile.com)
*/
-public abstract class Reader
+public abstract class Reader implements Closeable, Readable
{
/**
* This is the <code>Object</code> used for synchronizing critical code
@@ -152,6 +154,19 @@ public abstract class Reader
return count > 0 ? buf[0] : -1;
}
+ /** @since 1.5 */
+ public int read(CharBuffer buffer) throws IOException
+ {
+ // We want to call put(), so we don't manipulate the CharBuffer
+ // directly.
+ int rem = buffer.remaining();
+ char[] buf = new char[rem];
+ int result = read(buf, 0, rem);
+ if (result != -1)
+ buffer.put(buf, 0, result);
+ return result;
+ }
+
/**
* Closes the stream. Any futher attempts to read from the
* stream may generate an <code>IOException</code>.
diff --git a/java/io/SequenceInputStream.java b/java/io/SequenceInputStream.java
index 7fefe2432..5ff85e989 100644
--- a/java/io/SequenceInputStream.java
+++ b/java/io/SequenceInputStream.java
@@ -1,5 +1,5 @@
/* SequenceInputStream.java -- Reads multiple input streams in sequence
- Copyright (C) 1998, 1999, 2001, 2005 Free Software Foundation, Inc.
+ Copyright (C) 1998, 1999, 2001, 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -71,8 +71,11 @@ public class SequenceInputStream extends InputStream
/** Secondary input stream; not used if constructed w/ enumeration. */
private InputStream in2;
- /** The enumeration handle; not used if constructed w/ 2 explicit input streams. */
- private Enumeration e;
+ /**
+ * The enumeration handle; not used if constructed w/ 2 explicit
+ * input streams.
+ */
+ private Enumeration<? extends InputStream> e;
/**
* This method creates a new <code>SequenceInputStream</code> that obtains
@@ -82,10 +85,10 @@ public class SequenceInputStream extends InputStream
* @param e An <code>Enumeration</code> that will return a list of
* <code>InputStream</code>s to read in sequence
*/
- public SequenceInputStream(Enumeration e)
+ public SequenceInputStream(Enumeration<? extends InputStream> e)
{
this.e = e;
- in = (InputStream) e.nextElement();
+ in = e.nextElement();
in2 = null;
}
@@ -207,14 +210,13 @@ public class SequenceInputStream extends InputStream
if (e != null)
{
if (e.hasMoreElements())
- nextIn = (InputStream) e.nextElement();
+ nextIn = e.nextElement();
+ }
+ else if (in2 != null)
+ {
+ nextIn = in2;
+ in2 = null;
}
- else
- if (in2 != null)
- {
- nextIn = in2;
- in2 = null;
- }
return nextIn;
}
diff --git a/java/io/StringWriter.java b/java/io/StringWriter.java
index a1e9aeb6b..5a16e63ea 100644
--- a/java/io/StringWriter.java
+++ b/java/io/StringWriter.java
@@ -183,6 +183,27 @@ public class StringWriter extends Writer
buffer.append(str.substring(offset, offset + len));
}
+ /** @since 1.5 */
+ public StringWriter append(char c)
+ {
+ write(c);
+ return this;
+ }
+
+ /** @since 1.5 */
+ public StringWriter append(CharSequence cs)
+ {
+ write(cs == null ? "null" : cs.toString());
+ return this;
+ }
+
+ /** @since 1.5 */
+ public StringWriter append(CharSequence cs, int start, int end)
+ {
+ write(cs == null ? "null" : cs.subSequence(start, end).toString());
+ return this;
+ }
+
/**
* This is the <code>StringBuffer</code> that we use to store bytes that
* are written.
diff --git a/java/io/Writer.java b/java/io/Writer.java
index f153e31cf..660b69089 100644
--- a/java/io/Writer.java
+++ b/java/io/Writer.java
@@ -53,7 +53,7 @@ package java.io;
* @author Aaron M. Renn (arenn@urbanophile.com)
* @author Per Bothner (bothner@cygnus.com)
*/
-public abstract class Writer
+public abstract class Writer implements Appendable, Closeable, Flushable
{
/**
* This is the object used to synchronize criticial code sections for
@@ -188,5 +188,24 @@ public abstract class Writer
write(buf, 0, len);
}
-} // class Writer
+ /** @since 1.5 */
+ public Writer append(char c) throws IOException
+ {
+ write(c);
+ return this;
+ }
+ /** @since 1.5 */
+ public Writer append(CharSequence cs) throws IOException
+ {
+ write(cs == null ? "null" : cs.toString());
+ return this;
+ }
+
+ /** @since 1.5 */
+ public Writer append(CharSequence cs, int start, int end) throws IOException
+ {
+ write(cs == null ? "null" : cs.subSequence(start, end).toString());
+ return this;
+ }
+}
diff --git a/java/lang/Boolean.java b/java/lang/Boolean.java
index 23992525c..2b0236d1b 100644
--- a/java/lang/Boolean.java
+++ b/java/lang/Boolean.java
@@ -1,5 +1,5 @@
/* Boolean.java -- object wrapper for boolean
- Copyright (C) 1998, 2001, 2002, 2005, 2006 Free Software Foundation, Inc.
+ Copyright (C) 1998, 2001, 2002, 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -49,7 +49,7 @@ import java.io.Serializable;
* @since 1.0
* @status updated to 1.5
*/
-public final class Boolean implements Serializable, Comparable
+public final class Boolean implements Serializable, Comparable<Boolean>
{
/**
* Compatible with JDK 1.0.2+.
@@ -78,7 +78,7 @@ public final class Boolean implements Serializable, Comparable
*
* @since 1.1
*/
- public static final Class TYPE = VMClassLoader.getPrimitiveClass('Z');
+ public static final Class<Boolean> TYPE = (Class<Boolean>) VMClassLoader.getPrimitiveClass('Z');
/**
* The immutable value of this Boolean.
@@ -237,14 +237,6 @@ public final class Boolean implements Serializable, Comparable
}
/**
- * Bridge method
- */
- public int compareTo(Object other)
- {
- return compareTo((Boolean)other);
- }
-
- /**
* If the String argument is "true", ignoring case, return true.
* Otherwise, return false.
*
@@ -255,5 +247,5 @@ public final class Boolean implements Serializable, Comparable
{
return "true".equalsIgnoreCase(b) ? true : false;
}
-
+
}
diff --git a/java/lang/Byte.java b/java/lang/Byte.java
index 2560bfcff..7f53a494b 100644
--- a/java/lang/Byte.java
+++ b/java/lang/Byte.java
@@ -1,5 +1,5 @@
/* Byte.java -- object wrapper for byte
- Copyright (C) 1998, 2001, 2002, 2005 Free Software Foundation, Inc.
+ Copyright (C) 1998, 2001, 2002, 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -49,10 +49,12 @@ package java.lang;
* @author John Keiser
* @author Per Bothner
* @author Eric Blake (ebb9@email.byu.edu)
+ * @author Tom Tromey (tromey@redhat.com)
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
* @since 1.1
* @status updated to 1.5
*/
-public final class Byte extends Number implements Comparable
+public final class Byte extends Number implements Comparable<Byte>
{
/**
* Compatible with JDK 1.1+.
@@ -75,7 +77,7 @@ public final class Byte extends Number implements Comparable
* The primitive type <code>byte</code> is represented by this
* <code>Class</code> object.
*/
- public static final Class TYPE = VMClassLoader.getPrimitiveClass('B');
+ public static final Class<Byte> TYPE = (Class<Byte>) VMClassLoader.getPrimitiveClass('B');
/**
* The number of bits needed to represent a <code>byte</code>.
@@ -87,6 +89,7 @@ public final class Byte extends Number implements Comparable
// valueOf(). We're required to cache all possible values here.
private static Byte[] byteCache = new Byte[MAX_VALUE - MIN_VALUE + 1];
+
/**
* The immutable value of this Byte.
*
@@ -208,20 +211,18 @@ public final class Byte extends Number implements Comparable
*
* @param val the value to wrap
* @return the <code>Byte</code>
- *
- * @since 1.5
*/
public static Byte valueOf(byte val)
{
synchronized (byteCache)
{
- if (byteCache[val - MIN_VALUE] == null)
- byteCache[val - MIN_VALUE] = new Byte(val);
- return byteCache[val - MIN_VALUE];
+ if (byteCache[val - MIN_VALUE] == null)
+ byteCache[val - MIN_VALUE] = new Byte(val);
+ return byteCache[val - MIN_VALUE];
}
}
- /**
+ /**
* Convert the specified <code>String</code> into a <code>Byte</code>.
* The <code>String</code> may represent decimal, hexadecimal, or
* octal numbers.
@@ -369,19 +370,4 @@ public final class Byte extends Number implements Comparable
return value - b.value;
}
- /**
- * Behaves like <code>compareTo(Byte)</code> unless the Object
- * is not a <code>Byte</code>.
- *
- * @param o the object to compare
- * @return the comparison
- * @throws ClassCastException if the argument is not a <code>Byte</code>
- * @see #compareTo(Byte)
- * @see Comparable
- * @since 1.2
- */
- public int compareTo(Object o)
- {
- return compareTo((Byte) o);
- }
}
diff --git a/java/lang/Character.java b/java/lang/Character.java
index 59ae12f77..b9c6f24e7 100644
--- a/java/lang/Character.java
+++ b/java/lang/Character.java
@@ -1,5 +1,5 @@
/* java.lang.Character -- Wrapper class for char, and Unicode subsets
- Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc.
+ Copyright (C) 1998, 1999, 2001, 2002, 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -65,11 +65,12 @@ import java.util.Locale;
* @author Paul N. Fisher
* @author Jochen Hoenicke
* @author Eric Blake (ebb9@email.byu.edu)
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
* @see CharData
* @since 1.0
- * @status updated to 1.4
+ * @status partly updated to 1.5; some things still missing
*/
-public final class Character implements Serializable, Comparable
+public final class Character implements Serializable, Comparable<Character>
{
/**
* A subset of Unicode blocks.
@@ -154,10 +155,8 @@ public final class Character implements Serializable, Comparable
/** The canonical name of the block according to the Unicode standard. */
private final String canonicalName;
- /** Constants for the <code>forName()</code> method */
- private static final int CANONICAL_NAME = 0;
- private static final int NO_SPACES_NAME = 1;
- private static final int CONSTANT_NAME = 2;
+ /** Enumeration for the <code>forName()</code> method */
+ private enum NameType { CANONICAL, NO_SPACES, CONSTANT; };
/**
* Constructor for strictly defined blocks.
@@ -169,7 +168,7 @@ public final class Character implements Serializable, Comparable
* standard.
*/
private UnicodeBlock(int start, int end, String name,
- String canonicalName)
+ String canonicalName)
{
super(name);
this.start = start;
@@ -203,8 +202,8 @@ public final class Character implements Serializable, Comparable
public static UnicodeBlock of(int codePoint)
{
if (codePoint > MAX_CODE_POINT)
- throw new IllegalArgumentException("The supplied integer value is " +
- "too large to be a codepoint.");
+ throw new IllegalArgumentException("The supplied integer value is " +
+ "too large to be a codepoint.");
// Simple binary search for the correct block.
int low = 0;
int hi = sets.length - 1;
@@ -258,59 +257,51 @@ public final class Character implements Serializable, Comparable
*/
public static final UnicodeBlock forName(String blockName)
{
- int type;
+ NameType type;
if (blockName.indexOf(' ') != -1)
- type = CANONICAL_NAME;
+ type = NameType.CANONICAL;
else if (blockName.indexOf('_') != -1)
- type = CONSTANT_NAME;
+ type = NameType.CONSTANT;
else
- type = NO_SPACES_NAME;
+ type = NameType.NO_SPACES;
Collator usCollator = Collator.getInstance(Locale.US);
usCollator.setStrength(Collator.PRIMARY);
/* Special case for deprecated blocks not in sets */
switch (type)
{
- case CANONICAL_NAME:
+ case CANONICAL:
if (usCollator.compare(blockName, "Surrogates Area") == 0)
return SURROGATES_AREA;
break;
- case NO_SPACES_NAME:
+ case NO_SPACES:
if (usCollator.compare(blockName, "SurrogatesArea") == 0)
return SURROGATES_AREA;
break;
- case CONSTANT_NAME:
+ case CONSTANT:
if (usCollator.compare(blockName, "SURROGATES_AREA") == 0)
return SURROGATES_AREA;
break;
}
/* Other cases */
- int setLength = sets.length;
switch (type)
{
- case CANONICAL_NAME:
- for (int i = 0; i < setLength; i++)
- {
- UnicodeBlock block = sets[i];
- if (usCollator.compare(blockName, block.canonicalName) == 0)
- return block;
- }
+ case CANONICAL:
+ for (UnicodeBlock block : sets)
+ if (usCollator.compare(blockName, block.canonicalName) == 0)
+ return block;
break;
- case NO_SPACES_NAME:
- for (int i = 0; i < setLength; i++)
- {
- UnicodeBlock block = sets[i];
- String nsName = block.canonicalName.replaceAll(" ","");
- if (usCollator.compare(blockName, nsName) == 0)
- return block;
- }
- break;
- case CONSTANT_NAME:
- for (int i = 0; i < setLength; i++)
- {
- UnicodeBlock block = sets[i];
- if (usCollator.compare(blockName, block.toString()) == 0)
- return block;
- }
+ case NO_SPACES:
+ for (UnicodeBlock block : sets)
+ {
+ String nsName = block.canonicalName.replaceAll(" ","");
+ if (usCollator.compare(blockName, nsName) == 0)
+ return block;
+ }
+ break;
+ case CONSTANT:
+ for (UnicodeBlock block : sets)
+ if (usCollator.compare(blockName, block.toString()) == 0)
+ return block;
break;
}
throw new IllegalArgumentException("No Unicode block found for " +
@@ -1513,10 +1504,11 @@ public final class Character implements Serializable, Comparable
* this. These are also returned from calls to <code>of(int)</code>
* and <code>of(char)</code>.
*/
+ @Deprecated
public static final UnicodeBlock SURROGATES_AREA
= new UnicodeBlock(0xD800, 0xDFFF,
"SURROGATES_AREA",
- "Surrogates Area");
+ "Surrogates Area");
/**
* The defined subsets.
@@ -1979,11 +1971,78 @@ public final class Character implements Serializable, Comparable
public static final char MAX_VALUE = '\uFFFF';
/**
+ * The minimum Unicode 4.0 code point. This value is <code>0</code>.
+ * @since 1.5
+ */
+ public static final int MIN_CODE_POINT = 0;
+
+ /**
+ * The maximum Unicode 4.0 code point, which is greater than the range
+ * of the char data type.
+ * This value is <code>0x10FFFF</code>.
+ * @since 1.5
+ */
+ public static final int MAX_CODE_POINT = 0x10FFFF;
+
+ /**
+ * The minimum Unicode high surrogate code unit, or
+ * <emph>leading-surrogate</emph>, in the UTF-16 character encoding.
+ * This value is <code>'\uD800'</code>.
+ * @since 1.5
+ */
+ public static final char MIN_HIGH_SURROGATE = '\uD800';
+
+ /**
+ * The maximum Unicode high surrogate code unit, or
+ * <emph>leading-surrogate</emph>, in the UTF-16 character encoding.
+ * This value is <code>'\uDBFF'</code>.
+ * @since 1.5
+ */
+ public static final char MAX_HIGH_SURROGATE = '\uDBFF';
+
+ /**
+ * The minimum Unicode low surrogate code unit, or
+ * <emph>trailing-surrogate</emph>, in the UTF-16 character encoding.
+ * This value is <code>'\uDC00'</code>.
+ * @since 1.5
+ */
+ public static final char MIN_LOW_SURROGATE = '\uDC00';
+
+ /**
+ * The maximum Unicode low surrogate code unit, or
+ * <emph>trailing-surrogate</emph>, in the UTF-16 character encoding.
+ * This value is <code>'\uDFFF'</code>.
+ * @since 1.5
+ */
+ public static final char MAX_LOW_SURROGATE = '\uDFFF';
+
+ /**
+ * The minimum Unicode surrogate code unit in the UTF-16 character encoding.
+ * This value is <code>'\uD800'</code>.
+ * @since 1.5
+ */
+ public static final char MIN_SURROGATE = MIN_HIGH_SURROGATE;
+
+ /**
+ * The maximum Unicode surrogate code unit in the UTF-16 character encoding.
+ * This value is <code>'\uDFFF'</code>.
+ * @since 1.5
+ */
+ public static final char MAX_SURROGATE = MAX_LOW_SURROGATE;
+
+ /**
+ * The lowest possible supplementary Unicode code point (the first code
+ * point outside the basic multilingual plane (BMP)).
+ * This value is <code>0x10000</code>.
+ */
+ public static final int MIN_SUPPLEMENTARY_CODE_POINT = 0x10000;
+
+ /**
* Class object representing the primitive char data type.
*
* @since 1.1
*/
- public static final Class TYPE = VMClassLoader.getPrimitiveClass('C');
+ public static final Class<Character> TYPE = (Class<Character>) VMClassLoader.getPrimitiveClass('C');
/**
* The number of bits needed to represent a <code>char</code>.
@@ -2378,7 +2437,7 @@ public final class Character implements Serializable, Comparable
* Stores unicode attribute offset lookup table. Exploit package visibility
* of String.value to avoid copying the array.
* @see CharData#DATA
- */
+ */
private static final char[][] data =
new char[][]{
String.zeroBasedStringValue(CharData.DATA[0]),
@@ -2528,71 +2587,6 @@ public final class Character implements Serializable, Comparable
private static final int MIRROR_MASK = 0x40;
/**
- * Min value for supplementary code point.
- *
- * @since 1.5
- */
- public static final int MIN_SUPPLEMENTARY_CODE_POINT = 0x10000;
-
- /**
- * Min value for code point.
- *
- * @since 1.5
- */
- public static final int MIN_CODE_POINT = 0;
-
-
- /**
- * Max value for code point.
- *
- * @since 1.5
- */
- public static final int MAX_CODE_POINT = 0x010ffff;
-
-
- /**
- * Minimum high surrogate code in UTF-16 encoding.
- *
- * @since 1.5
- */
- public static final char MIN_HIGH_SURROGATE = '\ud800';
-
- /**
- * Maximum high surrogate code in UTF-16 encoding.
- *
- * @since 1.5
- */
- public static final char MAX_HIGH_SURROGATE = '\udbff';
-
- /**
- * Minimum low surrogate code in UTF-16 encoding.
- *
- * @since 1.5
- */
- public static final char MIN_LOW_SURROGATE = '\udc00';
-
- /**
- * Maximum low surrogate code in UTF-16 encoding.
- *
- * @since 1.5
- */
- public static final char MAX_LOW_SURROGATE = '\udfff';
-
- /**
- * Minimum surrogate code in UTF-16 encoding.
- *
- * @since 1.5
- */
- public static final char MIN_SURROGATE = MIN_HIGH_SURROGATE;
-
- /**
- * Maximum low surrogate code in UTF-16 encoding.
- *
- * @since 1.5
- */
- public static final char MAX_SURROGATE = MAX_LOW_SURROGATE;
-
- /**
* Grabs an attribute offset from the Unicode attribute database. The lower
* 5 bits are the character type, the next 2 bits are flags, and the top
* 9 bits are the offset into the attribute tables.
@@ -2605,6 +2599,7 @@ public final class Character implements Serializable, Comparable
* @see CharData#DATA
* @see CharData#SHIFT
*/
+ // Package visible for use in String.
static char readCodePoint(int codePoint)
{
int plane = codePoint >>> 16;
@@ -2778,7 +2773,7 @@ public final class Character implements Serializable, Comparable
{
return isTitleCase((int)ch);
}
-
+
/**
* Determines if a character is a Unicode titlecase letter. For example,
* the character "Lj" (Latin capital L with small letter j) is titlecase.
@@ -3282,7 +3277,7 @@ public final class Character implements Serializable, Comparable
| (1 << CURRENCY_SYMBOL)
| (1 << CONNECTOR_PUNCTUATION))) != 0;
}
-
+
/**
* Determines if a character can follow the first letter in
* a Java identifier. This is the combination of isJavaLetter (isLetter,
@@ -3468,6 +3463,7 @@ public final class Character implements Serializable, Comparable
{
return isIdentifierIgnorable((int)ch);
}
+
/**
* Determines if a character is ignorable in a Unicode identifier. This
* includes the non-whitespace ISO control characters (<code>'\u0000'</code>
@@ -3610,7 +3606,7 @@ public final class Character implements Serializable, Comparable
return title[i + 1];
return toUpperCase(ch);
}
-
+
/**
* Converts a Unicode character into its titlecase equivalent mapping.
* If a mapping does not exist, then the character passed is returned.
@@ -4103,6 +4099,7 @@ public final class Character implements Serializable, Comparable
// The result will correctly be signed.
return getDirectionality((int)ch);
}
+
/**
* Returns the Unicode directionality property of the character. This
@@ -4198,30 +4195,13 @@ public final class Character implements Serializable, Comparable
}
/**
- * Compares an object to this Character. Assuming the object is a
- * Character object, this method performs the same comparison as
- * compareTo(Character).
- *
- * @param o object to compare
- * @return the comparison value
- * @throws ClassCastException if o is not a Character object
- * @throws NullPointerException if o is null
- * @see #compareTo(Character)
- * @since 1.2
- */
- public int compareTo(Object o)
- {
- return compareTo((Character) o);
- }
-
- /**
* Returns an <code>Character</code> object wrapping the value.
* In contrast to the <code>Character</code> constructor, this method
* will cache some values. It is used by boxing conversion.
*
* @param val the value to wrap
* @return the <code>Character</code>
- *
+ *
* @since 1.5
*/
public static Character valueOf(char val)
@@ -4230,9 +4210,9 @@ public final class Character implements Serializable, Comparable
return new Character(val);
synchronized (charCache)
{
- if (charCache[val - MIN_VALUE] == null)
- charCache[val - MIN_VALUE] = new Character(val);
- return charCache[val - MIN_VALUE];
+ if (charCache[val - MIN_VALUE] == null)
+ charCache[val - MIN_VALUE] = new Character(val);
+ return charCache[val - MIN_VALUE];
}
}
diff --git a/java/lang/Class.java b/java/lang/Class.java
index 090ac234a..a159898c0 100644
--- a/java/lang/Class.java
+++ b/java/lang/Class.java
@@ -42,17 +42,14 @@ import gnu.classpath.VMStackWalker;
import gnu.java.lang.reflect.ClassSignatureParser;
import java.io.InputStream;
-import java.io.ObjectStreamClass;
import java.io.Serializable;
import java.lang.annotation.Annotation;
-import java.lang.reflect.Array;
+import java.lang.annotation.Inherited;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.GenericDeclaration;
-import java.lang.reflect.GenericSignatureFormatError;
import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.MalformedParameterizedTypeException;
import java.lang.reflect.Member;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
@@ -66,6 +63,7 @@ import java.security.PrivilegedAction;
import java.security.ProtectionDomain;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
@@ -97,11 +95,10 @@ import java.util.HashSet;
* @author Eric Blake (ebb9@email.byu.edu)
* @author Tom Tromey (tromey@redhat.com)
* @author Andrew John Hughes (gnu_andrew@member.fsf.org)
- * @author Tom Tromey (tromey@cygnus.com)
* @since 1.0
* @see ClassLoader
*/
-public final class Class
+public final class Class<T>
implements Serializable, Type, AnnotatedElement, GenericDeclaration
{
/**
@@ -147,7 +144,7 @@ public final class Class
final transient Object vmdata;
/** newInstance() caches the default constructor */
- private transient Constructor constructor;
+ private transient Constructor<T> constructor;
/**
* Class is non-instantiable from Java code; only the VM can create
@@ -184,7 +181,7 @@ public final class Class
* @throws ExceptionInInitializerError if the class loads, but an exception
* occurs during initialization
*/
- public static Class forName(String name) throws ClassNotFoundException
+ public static Class<?> forName(String name) throws ClassNotFoundException
{
return VMClass.forName(name, true, VMStackWalker.getCallingClassLoader());
}
@@ -216,8 +213,8 @@ public final class Class
* @see ClassLoader
* @since 1.2
*/
- public static Class forName(String name, boolean initialize,
- ClassLoader classloader)
+ public static Class<?> forName(String name, boolean initialize,
+ ClassLoader classloader)
throws ClassNotFoundException
{
if (classloader == null)
@@ -232,7 +229,7 @@ public final class Class
sm.checkPermission(new RuntimePermission("getClassLoader"));
}
}
- return VMClass.forName(name, initialize, classloader);
+ return (Class<?>) VMClass.forName(name, initialize, classloader);
}
/**
@@ -258,12 +255,12 @@ public final class Class
*/
private Class[] internalGetClasses()
{
- ArrayList list = new ArrayList();
+ ArrayList<Class> list = new ArrayList<Class>();
list.addAll(Arrays.asList(getDeclaredClasses(true)));
Class superClass = getSuperclass();
if (superClass != null)
list.addAll(Arrays.asList(superClass.internalGetClasses()));
- return (Class[])list.toArray(new Class[list.size()]);
+ return list.toArray(new Class[list.size()]);
}
/**
@@ -307,7 +304,7 @@ public final class Class
* @see Array
* @since 1.1
*/
- public Class getComponentType()
+ public Class<?> getComponentType()
{
return VMClass.getComponentType (this);
}
@@ -326,7 +323,8 @@ public final class Class
* @see #getConstructors()
* @since 1.1
*/
- public Constructor getConstructor(Class[] types) throws NoSuchMethodException
+ public Constructor<T> getConstructor(Class... types)
+ throws NoSuchMethodException
{
memberAccessCheck(Member.PUBLIC);
Constructor[] constructors = getDeclaredConstructors(true);
@@ -371,7 +369,7 @@ public final class Class
* @see #getDeclaredConstructors()
* @since 1.1
*/
- public Constructor getDeclaredConstructor(Class[] types)
+ public Constructor<T> getDeclaredConstructor(Class... types)
throws NoSuchMethodException
{
memberAccessCheck(Member.DECLARED);
@@ -500,7 +498,7 @@ public final class Class
* @see #getDeclaredMethods()
* @since 1.1
*/
- public Method getDeclaredMethod(String methodName, Class[] types)
+ public Method getDeclaredMethod(String methodName, Class... types)
throws NoSuchMethodException
{
memberAccessCheck(Member.DECLARED);
@@ -544,7 +542,7 @@ public final class Class
* @return the declaring class of this class
* @since 1.1
*/
- public Class getDeclaringClass()
+ public Class<?> getDeclaringClass()
{
return VMClass.getDeclaringClass (this);
}
@@ -597,7 +595,7 @@ public final class Class
*/
private Field[] internalGetFields()
{
- HashSet set = new HashSet();
+ HashSet<Field> set = new HashSet<Field>();
set.addAll(Arrays.asList(getDeclaredFields(true)));
Class[] interfaces = getInterfaces();
for (int i = 0; i < interfaces.length; i++)
@@ -605,7 +603,7 @@ public final class Class
Class superClass = getSuperclass();
if (superClass != null)
set.addAll(Arrays.asList(superClass.internalGetFields()));
- return (Field[])set.toArray(new Field[set.size()]);
+ return set.toArray(new Field[set.size()]);
}
/**
@@ -663,7 +661,7 @@ public final class Class
{
MethodKey m = (MethodKey) o;
if (m.name.equals(name) && m.params.length == params.length
- && m.returnType == returnType)
+ && m.returnType == returnType)
{
for (int i = 0; i < params.length; i++)
{
@@ -704,7 +702,7 @@ public final class Class
* @see #getMethods()
* @since 1.1
*/
- public Method getMethod(String methodName, Class[] types)
+ public Method getMethod(String methodName, Class... types)
throws NoSuchMethodException
{
memberAccessCheck(Member.PUBLIC);
@@ -821,7 +819,7 @@ public final class Class
*/
private Method[] internalGetMethods()
{
- HashMap map = new HashMap();
+ HashMap<MethodKey,Method> map = new HashMap<MethodKey,Method>();
Method[] methods;
Class[] interfaces = getInterfaces();
for(int i = 0; i < interfaces.length; i++)
@@ -846,7 +844,7 @@ public final class Class
{
map.put(new MethodKey(methods[i]), methods[i]);
}
- return (Method[])map.values().toArray(new Method[map.size()]);
+ return map.values().toArray(new Method[map.size()]);
}
/**
@@ -1003,7 +1001,7 @@ public final class Class
*
* @return the direct superclass of this class
*/
- public Class getSuperclass()
+ public Class<? super T> getSuperclass()
{
return VMClass.getSuperclass (this);
}
@@ -1033,7 +1031,7 @@ public final class Class
* @throws NullPointerException if c is null
* @since 1.1
*/
- public boolean isAssignableFrom(Class c)
+ public boolean isAssignableFrom(Class<?> c)
{
return VMClass.isAssignableFrom (this, c);
}
@@ -1103,11 +1101,11 @@ public final class Class
* @throws ExceptionInInitializerError if class initialization caused by
* this call fails with an exception
*/
- public Object newInstance()
+ public T newInstance()
throws InstantiationException, IllegalAccessException
{
memberAccessCheck(Member.PUBLIC);
- Constructor constructor;
+ Constructor<T> constructor;
synchronized(this)
{
constructor = this.constructor;
@@ -1307,12 +1305,11 @@ public final class Class
* type, <code>U</code>.
* @since 1.5
*/
- /* FIXME[GENERICS]: Should be <U> Class<? extends U> asSubClass(Class<U> klass */
- public Class asSubclass(Class klass)
+ public <U> Class<? extends U> asSubclass(Class<U> klass)
{
if (! klass.isAssignableFrom(this))
throw new ClassCastException();
- return this; /* FIXME[GENERICS]: Should cast to Class<? extends U> */
+ return (Class<? extends U>) this;
}
/**
@@ -1322,12 +1319,11 @@ public final class Class
* @throws ClassCastException if obj is not an instance of this class
* @since 1.5
*/
- /* FIXME[GENERICS]: Should be T cast(Object obj) */
- public Object cast(Object obj)
+ public T cast(Object obj)
{
if (obj != null && ! isInstance(obj))
throw new ClassCastException();
- return obj; /* FIXME[GENERICS]: Should be cast to T */
+ return (T) obj;
}
/**
@@ -1395,15 +1391,13 @@ public final class Class
* class is not an <code>enum</code>.
* @since 1.5
*/
- /* FIXME[GENERICS]: T[] getEnumConstants() */
- public Object[] getEnumConstants()
+ public T[] getEnumConstants()
{
if (isEnum())
{
try
{
- return (Object[])
- getMethod("values", new Class[0]).invoke(null, new Object[0]);
+ return (T[]) getMethod("values").invoke(null);
}
catch (NoSuchMethodException exception)
{
@@ -1490,14 +1484,13 @@ public final class Class
* <code>null</code> if no such annotation exists.
* @since 1.5
*/
- /* FIXME[GENERICS]: <T extends Annotation> T getAnnotation(Class <T>) */
- public Annotation getAnnotation(Class annotationClass)
+ public <A extends Annotation> A getAnnotation(Class<A> annotationClass)
{
- Annotation foundAnnotation = null;
+ A foundAnnotation = null;
Annotation[] annotations = getAnnotations();
- for (int i = 0; i < annotations.length; i++)
- if (annotations[i].annotationType() == annotationClass)
- foundAnnotation = annotations[i];
+ for (Annotation annotation : annotations)
+ if (annotation.annotationType() == annotationClass)
+ foundAnnotation = (A) annotation;
return foundAnnotation;
}
@@ -1514,15 +1507,22 @@ public final class Class
*/
public Annotation[] getAnnotations()
{
- HashSet set = new HashSet();
- set.addAll(Arrays.asList(getDeclaredAnnotations()));
- Class[] interfaces = getInterfaces();
- for (int i = 0; i < interfaces.length; i++)
- set.addAll(Arrays.asList(interfaces[i].getAnnotations()));
- Class superClass = getSuperclass();
- if (superClass != null)
- set.addAll(Arrays.asList(superClass.getAnnotations()));
- return (Annotation[]) set.toArray(new Annotation[set.size()]);
+ HashMap<Class, Annotation> map = new HashMap<Class, Annotation>();
+ for (Annotation a : getDeclaredAnnotations())
+ map.put((Class) a.annotationType(), a);
+ for (Class<? super T> s = getSuperclass();
+ s != null;
+ s = s.getSuperclass())
+ {
+ for (Annotation a : s.getDeclaredAnnotations())
+ {
+ Class k = (Class) a.annotationType();
+ if (! map.containsKey(k) && k.isAnnotationPresent(Inherited.class))
+ map.put(k, a);
+ }
+ }
+ Collection<Annotation> v = map.values();
+ return v.toArray(new Annotation[v.size()]);
}
/**
@@ -1588,8 +1588,7 @@ public final class Class
* a top-level class.
* @since 1.5
*/
- /* FIXME[GENERICS]: Should return Class<?> */
- public Class getEnclosingClass()
+ public Class<?> getEnclosingClass()
{
return VMClass.getEnclosingClass(this);
}
@@ -1605,8 +1604,7 @@ public final class Class
* is returned.
* @since 1.5
*/
- /* FIXME[GENERICS]: Should return Constructor<?> */
- public Constructor getEnclosingConstructor()
+ public Constructor<?> getEnclosingConstructor()
{
return VMClass.getEnclosingConstructor(this);
}
@@ -1731,12 +1729,11 @@ public final class Class
* specification, version 3.
* @since 1.5
*/
- /* FIXME[GENERICS]: Should return TypeVariable<Class<T>> */
- public TypeVariable[] getTypeParameters()
+ public TypeVariable<Class<T>>[] getTypeParameters()
{
String sig = VMClass.getClassSignature(this);
if (sig == null)
- return new TypeVariable[0];
+ return (TypeVariable<Class<T>>[])new TypeVariable[0];
ClassSignatureParser p = new ClassSignatureParser(this, sig);
return p.getTypeParameters();
@@ -1751,8 +1748,7 @@ public final class Class
* @return true if an annotation exists for the specified type.
* @since 1.5
*/
- /* FIXME[GENERICS]: Should be Class<? extends Annotation> */
- public boolean isAnnotationPresent(Class
+ public boolean isAnnotationPresent(Class<? extends Annotation>
annotationClass)
{
return getAnnotation(annotationClass) != null;
diff --git a/java/lang/ClassLoader.java b/java/lang/ClassLoader.java
index 83ef98da3..3d7c32cc9 100644
--- a/java/lang/ClassLoader.java
+++ b/java/lang/ClassLoader.java
@@ -120,7 +120,6 @@ import java.util.StringTokenizer;
* @author Eric Blake (ebb9@email.byu.edu)
* @see Class
* @since 1.0
- * @status still missing 1.4 functionality
*/
public abstract class ClassLoader
{
@@ -128,7 +127,7 @@ public abstract class ClassLoader
* All packages defined by this classloader. It is not private in order to
* allow native code (and trusted subclasses) access to this field.
*/
- final HashMap definedPackages = new HashMap();
+ final HashMap<String, Package> definedPackages = new HashMap<String, Package>();
/**
* The classloader that is consulted before this classloader.
@@ -227,7 +226,7 @@ public abstract class ClassLoader
* by the null key. This map must be synchronized on this instance.
*/
// Package visible for use by Class.
- Map packageAssertionStatus;
+ Map<String, Boolean> packageAssertionStatus;
/**
* The map of class assertion status overrides, or null if no class
@@ -236,7 +235,7 @@ public abstract class ClassLoader
* instance.
*/
// Package visible for use by Class.
- Map classAssertionStatus;
+ Map<String, Boolean> classAssertionStatus;
/**
* VM private data.
@@ -289,7 +288,7 @@ public abstract class ClassLoader
* @return the loaded class
* @throws ClassNotFoundException if the class cannot be found
*/
- public Class loadClass(String name) throws ClassNotFoundException
+ public Class<?> loadClass(String name) throws ClassNotFoundException
{
return loadClass(name, false);
}
@@ -314,11 +313,11 @@ public abstract class ClassLoader
* @return the loaded class
* @throws ClassNotFoundException if the class cannot be found
*/
- protected synchronized Class loadClass(String name, boolean resolve)
+ protected synchronized Class<?> loadClass(String name, boolean resolve)
throws ClassNotFoundException
{
// Have we already loaded this class?
- Class c = findLoadedClass(name);
+ Class<?> c = findLoadedClass(name);
if (c == null)
{
// Can the class be loaded by a parent?
@@ -335,11 +334,11 @@ public abstract class ClassLoader
return parent.loadClass(name, resolve);
}
}
- catch (ClassNotFoundException e)
+ catch (ClassNotFoundException e)
{
}
- // Still not found, we have to do it ourself.
- c = findClass(name);
+ // Still not found, we have to do it ourself.
+ c = findClass(name);
}
if (resolve)
resolveClass(c);
@@ -388,7 +387,7 @@ public abstract class ClassLoader
* @throws ClassNotFoundException when the class can not be found
* @since 1.2
*/
- protected Class findClass(String name) throws ClassNotFoundException
+ protected Class<?> findClass(String name) throws ClassNotFoundException
{
throw new ClassNotFoundException(name);
}
@@ -406,7 +405,7 @@ public abstract class ClassLoader
* offset + len exceeds data
* @deprecated use {@link #defineClass(String, byte[], int, int)} instead
*/
- protected final Class defineClass(byte[] data, int offset, int len)
+ protected final Class<?> defineClass(byte[] data, int offset, int len)
throws ClassFormatError
{
return defineClass(null, data, offset, len);
@@ -431,8 +430,8 @@ public abstract class ClassLoader
* @throws SecurityException if name starts with "java."
* @since 1.1
*/
- protected final Class defineClass(String name, byte[] data, int offset,
- int len) throws ClassFormatError
+ protected final Class<?> defineClass(String name, byte[] data, int offset,
+ int len) throws ClassFormatError
{
return defineClass(name, data, offset, len, null);
}
@@ -460,9 +459,9 @@ public abstract class ClassLoader
* do not match up
* @since 1.2
*/
- protected final synchronized Class defineClass(String name, byte[] data,
- int offset, int len,
- ProtectionDomain domain)
+ protected final synchronized Class<?> defineClass(String name, byte[] data,
+ int offset, int len,
+ ProtectionDomain domain)
throws ClassFormatError
{
checkInitialized();
@@ -493,8 +492,8 @@ public abstract class ClassLoader
* do not match up
* @since 1.5
*/
- protected final Class defineClass(String name, ByteBuffer buf,
- ProtectionDomain domain)
+ protected final Class<?> defineClass(String name, ByteBuffer buf,
+ ProtectionDomain domain)
throws ClassFormatError
{
byte[] data = new byte[buf.remaining()];
@@ -510,7 +509,7 @@ public abstract class ClassLoader
* @throws NullPointerException if c is null
* @throws LinkageError if linking fails
*/
- protected final void resolveClass(Class c)
+ protected final void resolveClass(Class<?> c)
{
checkInitialized();
VMClassLoader.resolveClass(c);
@@ -525,7 +524,7 @@ public abstract class ClassLoader
* @return the found class
* @throws ClassNotFoundException if the class cannot be found
*/
- protected final Class findSystemClass(String name)
+ protected final Class<?> findSystemClass(String name)
throws ClassNotFoundException
{
checkInitialized();
@@ -563,7 +562,7 @@ public abstract class ClassLoader
* @param signers the signers to set
* @since 1.1
*/
- protected final void setSigners(Class c, Object[] signers)
+ protected final void setSigners(Class<?> c, Object[] signers)
{
checkInitialized();
c.setSigners(signers);
@@ -576,7 +575,7 @@ public abstract class ClassLoader
* @return the found Class, or null if it is not found
* @since 1.1
*/
- protected final synchronized Class findLoadedClass(String name)
+ protected final synchronized Class<?> findLoadedClass(String name)
{
checkInitialized();
return VMClassLoader.findLoadedClass(this, name);
@@ -631,14 +630,14 @@ public abstract class ClassLoader
* @since 1.2
* @specnote this was <code>final</code> prior to 1.5
*/
- public Enumeration getResources(String name) throws IOException
+ public Enumeration<URL> getResources(String name) throws IOException
{
- Enumeration parentResources;
+ Enumeration<URL> parentResources;
if (parent == null)
parentResources = VMClassLoader.getResources(name);
else
parentResources = parent.getResources(name);
- return new DoubleEnumeration(parentResources, findResources(name));
+ return new DoubleEnumeration<URL>(parentResources, findResources(name));
}
/**
@@ -658,9 +657,9 @@ public abstract class ClassLoader
* @throws IOException if I/O errors occur in the process
* @since 1.2
*/
- protected Enumeration findResources(String name) throws IOException
+ protected Enumeration<URL> findResources(String name) throws IOException
{
- return EmptyEnumeration.getInstance();
+ return (Enumeration<URL>) EmptyEnumeration.getInstance();
}
/**
@@ -705,7 +704,8 @@ public abstract class ClassLoader
* @throws IOException if I/O errors occur in the process
* @since 1.2
*/
- public static Enumeration getSystemResources(String name) throws IOException
+ public static Enumeration<URL> getSystemResources(String name)
+ throws IOException
{
return StaticData.systemClassLoader.getResources(name);
}
@@ -865,7 +865,7 @@ public abstract class ClassLoader
{
synchronized (definedPackages)
{
- p = (Package) definedPackages.get(name);
+ p = definedPackages.get(name);
}
}
return p;
@@ -955,7 +955,7 @@ public abstract class ClassLoader
{
if (packageAssertionStatus == null)
packageAssertionStatus
- = new HashMap(StaticData.systemPackageAssertionStatus);
+ = new HashMap<String, Boolean>(StaticData.systemPackageAssertionStatus);
packageAssertionStatus.put(name, Boolean.valueOf(enabled));
}
@@ -975,8 +975,8 @@ public abstract class ClassLoader
boolean enabled)
{
if (classAssertionStatus == null)
- classAssertionStatus =
- new HashMap(StaticData.systemClassAssertionStatus);
+ classAssertionStatus
+ = new HashMap<String, Boolean>(StaticData.systemClassAssertionStatus);
// The toString() hack catches null, as required.
classAssertionStatus.put(name.toString(), Boolean.valueOf(enabled));
}
@@ -994,8 +994,8 @@ public abstract class ClassLoader
public synchronized void clearAssertionStatus()
{
defaultAssertionStatus = false;
- packageAssertionStatus = new HashMap();
- classAssertionStatus = new HashMap();
+ packageAssertionStatus = null;
+ classAssertionStatus = null;
}
/**
@@ -1147,4 +1147,5 @@ public abstract class ClassLoader
if (! initialized)
throw new SecurityException("attempt to use uninitialized class loader");
}
+
}
diff --git a/java/lang/Comparable.java b/java/lang/Comparable.java
index a8afe1ec3..4ad39af83 100644
--- a/java/lang/Comparable.java
+++ b/java/lang/Comparable.java
@@ -1,5 +1,5 @@
/* Comparable.java -- Interface for comparaing objects to obtain an ordering
- Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc.
+ Copyright (C) 1998, 1999, 2001, 2002, 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -66,9 +66,9 @@ package java.lang;
* @see java.util.TreeSet
* @see java.util.TreeMap
* @since 1.2
- * @status updated to 1.4
+ * @status updated to 1.5
*/
-public interface Comparable
+public interface Comparable<T>
{
/**
* Compares this object with another, and returns a numerical result based
@@ -94,5 +94,5 @@ public interface Comparable
* @throws NullPointerException if o is null
* @throws ClassCastException if o cannot be compared
*/
- int compareTo(Object o);
+ int compareTo(T o);
}
diff --git a/java/lang/Compiler.java b/java/lang/Compiler.java
index 56fb951bb..0d990e938 100644
--- a/java/lang/Compiler.java
+++ b/java/lang/Compiler.java
@@ -74,7 +74,7 @@ public final class Compiler
* compilation failed, <code>true</code> if compilation succeeded
* @throws NullPointerException if oneClass is null
*/
- public static boolean compileClass(Class oneClass)
+ public static boolean compileClass(Class<?> oneClass)
{
return VMCompiler.compileClass(oneClass);
}
diff --git a/java/lang/Deprecated.java b/java/lang/Deprecated.java
new file mode 100644
index 000000000..a52abdb4e
--- /dev/null
+++ b/java/lang/Deprecated.java
@@ -0,0 +1,56 @@
+/* Deprecated - Annotation to mark elements as deprecated
+ Copyright (C) 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.lang;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+/**
+ * This annotation is used as a marker to indicate that the annotated
+ * declaration is deprecated and should not be used in new code.
+ * This replaces the old "@deprecated" javadoc tag.
+ *
+ * @author Tom Tromey (tromey@redhat.com)
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
+ * @since 1.5
+ */
+@Documented @Retention(RUNTIME)
+public @interface Deprecated
+{
+}
diff --git a/java/lang/Double.java b/java/lang/Double.java
index 03c560689..c71620314 100644
--- a/java/lang/Double.java
+++ b/java/lang/Double.java
@@ -1,5 +1,5 @@
/* Double.java -- object wrapper for double
- Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2005
+ Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -49,10 +49,12 @@ package java.lang;
* @author Paul Fisher
* @author Andrew Haley (aph@cygnus.com)
* @author Eric Blake (ebb9@email.byu.edu)
+ * @author Tom Tromey (tromey@redhat.com)
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
* @since 1.0
- * @status updated to 1.4
+ * @status partly updated to 1.5
*/
-public final class Double extends Number implements Comparable
+public final class Double extends Number implements Comparable<Double>
{
/**
* Compatible with JDK 1.0+.
@@ -98,7 +100,7 @@ public final class Double extends Number implements Comparable
* <code>Class</code> object.
* @since 1.1
*/
- public static final Class TYPE = VMClassLoader.getPrimitiveClass('D');
+ public static final Class<Double> TYPE = (Class<Double>) VMClassLoader.getPrimitiveClass('D');
/**
* The immutable value of this Double.
@@ -254,7 +256,6 @@ public final class Double extends Number implements Comparable
*
* @param val the value to wrap
* @return the <code>Double</code>
- *
* @since 1.5
*/
public static Double valueOf(double val)
@@ -575,22 +576,6 @@ public final class Double extends Number implements Comparable
}
/**
- * Behaves like <code>compareTo(Double)</code> unless the Object
- * is not an <code>Double</code>.
- *
- * @param o the object to compare
- * @return the comparison
- * @throws ClassCastException if the argument is not a <code>Double</code>
- * @see #compareTo(Double)
- * @see Comparable
- * @since 1.2
- */
- public int compareTo(Object o)
- {
- return compare(value, ((Double) o).value);
- }
-
- /**
* Behaves like <code>new Double(x).compareTo(new Double(y))</code>; in
* other words this compares two doubles, special casing NaN and zero,
* without the overhead of objects.
diff --git a/java/lang/Enum.java b/java/lang/Enum.java
index 5344d5c72..f141619be 100644
--- a/java/lang/Enum.java
+++ b/java/lang/Enum.java
@@ -48,10 +48,8 @@ import java.lang.reflect.Field;
* @author Andrew John Hughes (gnu_andrew@member.fsf.org)
* @since 1.5
*/
-/* FIXME[GENERICS]: Should be Enum<T extends Enum<T>>
- and Comparable<T> */
-public abstract class Enum
- implements Comparable, Serializable
+public abstract class Enum<T extends Enum<T>>
+ implements Comparable<T>, Serializable
{
/**
@@ -62,13 +60,13 @@ public abstract class Enum
/**
* The name of this enum constant.
*/
- String name;
+ final String name;
/**
* The number of this enum constant. Each constant is given a number
* which matches the order in which it was declared, starting with zero.
*/
- int ordinal;
+ final int ordinal;
/**
* This constructor is used by the compiler to create enumeration constants.
@@ -91,8 +89,8 @@ public abstract class Enum
* @exception IllegalArgumentException when there is no value s in
* the enum etype.
*/
- /* FIXME[GENERICS]: Should be <S extends Enum<S>> S valueOf(Class<S>) */
- public static Enum valueOf(Class etype, String s)
+ @SuppressWarnings("unchecked")
+ public static <S extends Enum<S>> S valueOf(Class<S> etype, String s)
{
if (etype == null || s == null)
throw new NullPointerException();
@@ -102,8 +100,7 @@ public abstract class Enum
Field f = etype.getDeclaredField(s);
if (! f.isEnumConstant())
throw new IllegalArgumentException(s);
- /* FIXME[GENERICS]: Should cast to S */
- return (Enum) f.get(null);
+ return (S) f.get(null);
}
catch (NoSuchFieldException exception)
{
@@ -167,7 +164,7 @@ public abstract class Enum
* @throws ClassCastException if <code>e</code> is not an enumeration
* constant of the same class.
*/
- public final int compareTo(Enum e)
+ public final int compareTo(T e)
{
if (getDeclaringClass() != e.getDeclaringClass())
throw new ClassCastException();
@@ -175,27 +172,6 @@ public abstract class Enum
}
/**
- * Returns an integer which represents the relative ordering of this
- * enumeration constant. Enumeration constants are ordered by their
- * ordinals, which represents their declaration order. So, comparing
- * two identical constants yields zero, while one declared prior to
- * this returns a positive integer and one declared after yields a
- * negative integer.
- *
- * @param o the enumeration constant to compare.
- * @return a negative integer if <code>e.ordinal < this.ordinal</code>,
- * zero if <code>e.ordinal == this.ordinal</code> and a positive
- * integer if <code>e.ordinal > this.ordinal</code>.
- * @throws ClassCastException if <code>e</code> is not an enumeration
- * constant of the same class.
- */
- /* FIXME[GENERICS]: Remove this method */
- public final int compareTo(Object o)
- {
- return compareTo((Enum)o);
- }
-
- /**
* Cloning of enumeration constants is prevented, to maintain their
* singleton status.
*
@@ -235,8 +211,7 @@ public abstract class Enum
*
* @return the type of this enumeration constant.
*/
- /* FIXME[GENERICS]: Should return Class<T> */
- public final Class getDeclaringClass()
+ public final Class<T> getDeclaringClass()
{
Class k = getClass();
// We might be in an anonymous subclass of the enum class, so go
diff --git a/java/lang/EnumConstantNotPresentException.java b/java/lang/EnumConstantNotPresentException.java
index 12b30fda5..4586c372c 100644
--- a/java/lang/EnumConstantNotPresentException.java
+++ b/java/lang/EnumConstantNotPresentException.java
@@ -54,7 +54,7 @@ public class EnumConstantNotPresentException extends RuntimeException
* The enum's type. Note that the name is fixed by the
* serialization spec.
*/
- private Class enumType;
+ private Class<? extends Enum> enumType;
/**
* The name of the missing enum constant. Note that the name is
@@ -68,7 +68,8 @@ public class EnumConstantNotPresentException extends RuntimeException
* @param theEnum the enum's class
* @param name the name of the missing enum constant
*/
- public EnumConstantNotPresentException(Class theEnum, String name)
+ public EnumConstantNotPresentException(Class<? extends Enum> theEnum,
+ String name)
{
super("enum " + theEnum + " is missing the constant " + name);
enumType = theEnum;
@@ -88,7 +89,7 @@ public class EnumConstantNotPresentException extends RuntimeException
* Return the enum type which is missing a constant.
* @return the enum type which is missing a constant
*/
- public Class enumType()
+ public Class<? extends Enum> enumType()
{
return enumType;
}
diff --git a/java/lang/Float.java b/java/lang/Float.java
index dcd5b2211..1e85922be 100644
--- a/java/lang/Float.java
+++ b/java/lang/Float.java
@@ -1,5 +1,5 @@
/* Float.java -- object wrapper for float
- Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2005
+ Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -49,10 +49,12 @@ package java.lang;
* @author Paul Fisher
* @author Andrew Haley (aph@cygnus.com)
* @author Eric Blake (ebb9@email.byu.edu)
+ * @author Tom Tromey (tromey@redhat.com)
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
* @since 1.0
- * @status updated to 1.4
+ * @status partly updated to 1.5
*/
-public final class Float extends Number implements Comparable
+public final class Float extends Number implements Comparable<Float>
{
/**
* Compatible with JDK 1.0+.
@@ -91,7 +93,7 @@ public final class Float extends Number implements Comparable
* <code>Class</code> object.
* @since 1.1
*/
- public static final Class TYPE = VMClassLoader.getPrimitiveClass('F');
+ public static final Class<Float> TYPE = (Class<Float>) VMClassLoader.getPrimitiveClass('F');
/**
* The number of bits needed to represent a <code>float</code>.
@@ -281,7 +283,6 @@ public final class Float extends Number implements Comparable
*
* @param val the value to wrap
* @return the <code>Float</code>
- *
* @since 1.5
*/
public static Float valueOf(float val)
@@ -584,22 +585,6 @@ public final class Float extends Number implements Comparable
}
/**
- * Behaves like <code>compareTo(Float)</code> unless the Object
- * is not an <code>Float</code>.
- *
- * @param o the object to compare
- * @return the comparison
- * @throws ClassCastException if the argument is not a <code>Float</code>
- * @see #compareTo(Float)
- * @see Comparable
- * @since 1.2
- */
- public int compareTo(Object o)
- {
- return compare(value, ((Float) o).value);
- }
-
- /**
* Behaves like <code>new Float(x).compareTo(new Float(y))</code>; in
* other words this compares two floats, special casing NaN and zero,
* without the overhead of objects.
diff --git a/java/lang/InheritableThreadLocal.java b/java/lang/InheritableThreadLocal.java
index b9c7624ef..2079a4c20 100644
--- a/java/lang/InheritableThreadLocal.java
+++ b/java/lang/InheritableThreadLocal.java
@@ -1,5 +1,5 @@
/* InheritableThreadLocal -- a ThreadLocal which inherits values across threads
- Copyright (C) 2000, 2001, 2002, 2003, 2005, 2006 Free Software Foundation, Inc.
+ Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -54,12 +54,15 @@ import java.util.Iterator;
*
* @author Mark Wielaard (mark@klomp.org)
* @author Eric Blake (ebb9@email.byu.edu)
+ * @author Tom Tromey (tromey@redhat.com)
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
* @see ThreadLocal
* @since 1.2
* @status updated to 1.4
*/
-public class InheritableThreadLocal extends ThreadLocal
+public class InheritableThreadLocal<T> extends ThreadLocal<T>
{
+
/**
* Creates a new InheritableThreadLocal that has no values associated
* with it yet.
@@ -77,7 +80,7 @@ public class InheritableThreadLocal extends ThreadLocal
* the moment of creation of the child
* @return the initial value for the child thread
*/
- protected Object childValue(Object parentValue)
+ protected T childValue(T parentValue)
{
return parentValue;
}
@@ -85,7 +88,7 @@ public class InheritableThreadLocal extends ThreadLocal
/**
* Generates the childValues of all <code>InheritableThreadLocal</code>s
* that are in the heritage of the current Thread for the newly created
- * childThread. Should be called from the contructor Thread.
+ * childThread. Should be called from the constructor Thread.
*
* @param childThread the newly created thread, to inherit from this thread
* @see Thread#Thread(ThreadGroup, Runnable, String)
@@ -102,14 +105,14 @@ public class InheritableThreadLocal extends ThreadLocal
Object key = keys.next();
if (key instanceof InheritableThreadLocal)
{
- InheritableThreadLocal local = (InheritableThreadLocal)key;
+ InheritableThreadLocal local = (InheritableThreadLocal)key;
Object parentValue = parentThread.locals.get(key);
- Object childValue = local.childValue(parentValue == NULL
- ? null : parentValue);
+ Object childValue = local.childValue(parentValue == sentinel
+ ? null : parentValue);
if (childThread.locals == null)
childThread.locals = new WeakIdentityHashMap();
childThread.locals.put(key, (childValue == null
- ? NULL : childValue));
+ ? sentinel : childValue));
}
}
}
diff --git a/java/lang/Integer.java b/java/lang/Integer.java
index f3fe85f50..e38eb53ed 100644
--- a/java/lang/Integer.java
+++ b/java/lang/Integer.java
@@ -51,10 +51,11 @@ package java.lang;
* @author Warren Levy
* @author Eric Blake (ebb9@email.byu.edu)
* @author Tom Tromey (tromey@redhat.com)
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
* @since 1.0
- * @status largely updated to 1.5
+ * @status updated to 1.5
*/
-public final class Integer extends Number implements Comparable
+public final class Integer extends Number implements Comparable<Integer>
{
/**
* Compatible with JDK 1.0.2+.
@@ -78,7 +79,7 @@ public final class Integer extends Number implements Comparable
* <code>Class</code> object.
* @since 1.1
*/
- public static final Class TYPE = VMClassLoader.getPrimitiveClass('I');
+ public static final Class<Integer> TYPE = (Class<Integer>) VMClassLoader.getPrimitiveClass('I');
/**
* The number of bits needed to represent an <code>int</code>.
@@ -526,22 +527,6 @@ public final class Integer extends Number implements Comparable
}
/**
- * Behaves like <code>compareTo(Integer)</code> unless the Object
- * is not an <code>Integer</code>.
- *
- * @param o the object to compare
- * @return the comparison
- * @throws ClassCastException if the argument is not an <code>Integer</code>
- * @see #compareTo(Integer)
- * @see Comparable
- * @since 1.2
- */
- public int compareTo(Object o)
- {
- return compareTo((Integer) o);
- }
-
- /**
* Return the number of bits set in x.
* @param x value to examine
* @since 1.5
diff --git a/java/lang/Iterable.java b/java/lang/Iterable.java
index 35c426484..ea593e88e 100644
--- a/java/lang/Iterable.java
+++ b/java/lang/Iterable.java
@@ -49,12 +49,12 @@ import java.util.*;
* @author Tom Tromey <tromey@redhat.com>
* @since 1.5
*/
-public interface Iterable
+public interface Iterable<E>
{
/**
* Returns an iterator for the collection.
*
* @return an iterator.
*/
- Iterator iterator ();
+ Iterator<E> iterator ();
}
diff --git a/java/lang/Long.java b/java/lang/Long.java
index 74e2a52df..f0fbc904c 100644
--- a/java/lang/Long.java
+++ b/java/lang/Long.java
@@ -1,5 +1,5 @@
/* Long.java -- object wrapper for long
- Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc.
+ Copyright (C) 1998, 1999, 2001, 2002, 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -49,10 +49,12 @@ package java.lang;
* @author John Keiser
* @author Warren Levy
* @author Eric Blake (ebb9@email.byu.edu)
+ * @author Tom Tromey (tromey@redhat.com)
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
* @since 1.0
* @status updated to 1.5
*/
-public final class Long extends Number implements Comparable
+public final class Long extends Number implements Comparable<Long>
{
/**
* Compatible with JDK 1.0.2+.
@@ -76,7 +78,7 @@ public final class Long extends Number implements Comparable
* <code>Class</code> object.
* @since 1.1
*/
- public static final Class TYPE = VMClassLoader.getPrimitiveClass ('J');
+ public static final Class<Long> TYPE = (Class<Long>) VMClassLoader.getPrimitiveClass ('J');
/**
* The number of bits needed to represent a <code>long</code>.
@@ -292,7 +294,6 @@ public final class Long extends Number implements Comparable
*
* @param val the value to wrap
* @return the <code>Long</code>
- *
* @since 1.5
*/
public static synchronized Long valueOf(long val)
@@ -517,22 +518,6 @@ public final class Long extends Number implements Comparable
}
/**
- * Behaves like <code>compareTo(Long)</code> unless the Object
- * is not a <code>Long</code>.
- *
- * @param o the object to compare
- * @return the comparison
- * @throws ClassCastException if the argument is not a <code>Long</code>
- * @see #compareTo(Long)
- * @see Comparable
- * @since 1.2
- */
- public int compareTo(Object o)
- {
- return compareTo((Long) o);
- }
-
- /**
* Return the number of bits set in x.
* @param x value to examine
* @since 1.5
diff --git a/java/lang/Object.java b/java/lang/Object.java
index 6212d7dfe..fbd1dc77d 100644
--- a/java/lang/Object.java
+++ b/java/lang/Object.java
@@ -326,7 +326,7 @@ public class Object
*
* @return the class of this Object
*/
- public final Class getClass()
+ public final Class<? extends Object> getClass()
{
return VMObject.getClass(this);
}
diff --git a/java/lang/Override.java b/java/lang/Override.java
new file mode 100644
index 000000000..16581045a
--- /dev/null
+++ b/java/lang/Override.java
@@ -0,0 +1,56 @@
+/* Override - Annotation to indicate that a method should be an override
+ Copyright (C) 2004 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.lang;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+import static java.lang.annotation.RetentionPolicy.SOURCE;
+import static java.lang.annotation.ElementType.METHOD;
+
+/**
+ * This annotation is used as a marker to indicate that the annotated
+ * method declaration is intended to override another method in the
+ * class hierarchy. If this is not the case, the compiler will emit a
+ * warning.
+ *
+ * @since 1.5
+ */
+@Retention(SOURCE) @Target(METHOD)
+public @interface Override
+{
+}
diff --git a/java/lang/Package.java b/java/lang/Package.java
index 38bb3240d..1141a0722 100644
--- a/java/lang/Package.java
+++ b/java/lang/Package.java
@@ -345,14 +345,13 @@ public class Package
* <code>null</code> if no such annotation exists.
* @since 1.5
*/
- /* FIXME[GENERICS]: <T extends Annotation> T getAnnotation(Class <T>) */
- public Annotation getAnnotation(Class annotationClass)
+ public <A extends Annotation> A getAnnotation(Class<A> annotationClass)
{
- Annotation foundAnnotation = null;
+ A foundAnnotation = null;
Annotation[] annotations = getAnnotations();
- for (int i = 0; i < annotations.length; i++)
- if (annotations[i].annotationType() == annotationClass)
- foundAnnotation = annotations[i];
+ for (Annotation annotation : annotations)
+ if (annotation.annotationType() == annotationClass)
+ foundAnnotation = (A) annotation;
return foundAnnotation;
}
@@ -406,8 +405,7 @@ public class Package
* @return true if an annotation exists for the specified type.
* @since 1.5
*/
- /* FIXME[GENERICS]: Signature is Class<? extends Annotation> */
- public boolean isAnnotationPresent(Class
+ public boolean isAnnotationPresent(Class<? extends Annotation>
annotationClass)
{
return getAnnotation(annotationClass) != null;
diff --git a/java/lang/ProcessBuilder.java b/java/lang/ProcessBuilder.java
new file mode 100644
index 000000000..9ffe24cde
--- /dev/null
+++ b/java/lang/ProcessBuilder.java
@@ -0,0 +1,337 @@
+/* ProcessBuilder.java - Represent spawned system process
+ Copyright (C) 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.lang;
+
+import java.io.File;
+import java.io.IOException;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * <p>
+ * This class is used to construct new operating system processes.
+ * A <code>ProcessBuilder</code> instance basically represent a
+ * template for a new process. Actual processes are generated from
+ * this template via use of the <code>start()</code> method, which
+ * may be invoked multiple times, with each invocation spawning a
+ * new process with the current attributes of the
+ * <code>ProcessBuilder</code> object. Each spawned process is
+ * independent of the <code>ProcessBuilder</code> object, and is
+ * unaffected by changes in its attributes.
+ * </p>
+ * <p>
+ * The following attributes define a process:
+ * </p>
+ * <ul>
+ * <li>The <emphasis>working directory</emphasis>; the activities of a
+ * process begin with the current directory set to this. By default,
+ * this is the working directory of the current process, as defined
+ * by the <code>user.dir</code> property.</li>
+ * <li>The <emphasis>command</emphasis> which invokes the process. This
+ * usually consists of the name of the program binary followed by an
+ * arbitrary number of arguments. For example, <code>find -type f</code>
+ * invokes the <code>find</code> binary with the arguments "-type" and "f".
+ * The command is provided a list, the elements of which are defined in a
+ * system dependent manner; the layout is affected by expected operating
+ * system conventions. A common method is to split the command on each
+ * space within the string. Thus, <code>find -type f</code> forms a
+ * three element list. However, in some cases, the expectation is that
+ * this split is performed by the program itself; thus, the list consists
+ * of only two elements (the program name and its arguments).</li>
+ * <li>The <emphasis>environment map</emphasis>, which links environment
+ * variables to their corresponding values. The initial contents of the map
+ * are the current environment values i.e. it contains the contents of the
+ * map returned by <code>System.getenv()</code>.</li>
+ * <li>The <emphasis>redirection flag</emphasis>, which specifies whether
+ * or not the contents of the error stream should be redirected to standard
+ * output. By default, this is false, and there are two output streams, one
+ * for normal data ({@link Process#getOutputStream()}) and one for error data
+ * ({@link Process#getErrorStream()}). When set to true, the two are merged,
+ * which simplifies the interleaving of the two streams. Data is read using
+ * the stream returned by {@link Process#getOutputStream()}, and the
+ * stream returned by {@link Process#getErrorStream()} throws an immediate
+ * end-of-file exception.</li>
+ * </ul>
+ * <p>
+ * All checks on attribute validity are delayed until <code>start()</code>
+ * is called. <code>ProcessBuilder</code> objects are <strong>not
+ * synchronized</strong>; the user must provide external synchronization
+ * where multiple threads may interact with the same
+ * <code>ProcessBuilder</code> object.
+ * </p>
+ *
+ * @author Tom Tromey (tromey@redhat.com)
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
+ * @see Process
+ * @see System#getenv()
+ * @since 1.5
+ */
+public final class ProcessBuilder
+{
+
+ /**
+ * The working directory of the process.
+ */
+ private File directory = new File(System.getProperty("user.dir"));
+
+ /**
+ * The command line syntax for invoking the process.
+ */
+ private List<String> command;
+
+ /**
+ * The mapping of environment variables to values.
+ */
+ private Map<String, String> environment =
+ new System.EnvironmentMap(System.getenv());
+
+ /**
+ * A flag indicating whether to redirect the error stream to standard
+ * output.
+ */
+ private boolean redirect = false;
+
+ /**
+ * Constructs a new <code>ProcessBuilder</code> with the specified
+ * command being used to invoke the process. The list is used directly;
+ * external changes are reflected in the <code>ProcessBuilder</code>.
+ *
+ * @param command the name of the program followed by its arguments.
+ */
+ public ProcessBuilder(List<String> command)
+ {
+ this.command = command;
+ }
+
+ /**
+ * Constructs a new <code>ProcessBuilder</code> with the specified
+ * command being used to invoke the process. This constructor
+ * simplifies creating a new <code>ProcessBuilder</code> by
+ * converting the provided series of constructor arguments into a
+ * list of command-line arguments.
+ *
+ * @param command the name of the program followed by its arguments.
+ */
+ public ProcessBuilder(String... command)
+ {
+ this.command = Arrays.asList(command);
+ }
+
+ /**
+ * Returns the current command line, used to invoke the process.
+ * The return value is simply a reference to the list of command
+ * line arguments used by the <code>ProcessBuilder</code> object;
+ * any changes made to it will be reflected in the operation of
+ * the <code>ProcessBuilder</code>.
+ *
+ * @return the list of command-line arguments.
+ */
+ public List<String> command()
+ {
+ return command;
+ }
+
+ /**
+ * Sets the command-line arguments to those specified. The list is
+ * used directly; external changes are reflected in the
+ * <code>ProcessBuilder</code>.
+ *
+ * @param command the name of the program followed by its arguments.
+ * @return a reference to this process builder.
+ */
+ public ProcessBuilder command(List<String> command)
+ {
+ this.command = command;
+ return this;
+ }
+
+ /**
+ * Sets the command-line arguments to those specified.
+ * This simplifies modifying the arguments by converting
+ * the provided series of constructor arguments into a
+ * list of command-line arguments.
+ *
+ * @param command the name of the program followed by its arguments.
+ * @return a reference to this process builder.
+ */
+ public ProcessBuilder command(String... command)
+ {
+ this.command = Arrays.asList(command);
+ return this;
+ }
+
+ /**
+ * Returns the working directory of the process. The
+ * returned value may be <code>null</code>; this
+ * indicates that the default behaviour of using the
+ * working directory of the current process should
+ * be adopted.
+ *
+ * @return the working directory.
+ */
+ public File directory()
+ {
+ return directory;
+ }
+
+ /**
+ * Sets the working directory to that specified.
+ * The supplied argument may be <code>null</code>,
+ * which indicates the default value should be used.
+ * The default is the working directory of the current
+ * process.
+ *
+ * @param directory the new working directory.
+ * @return a reference to this process builder.
+ */
+ public ProcessBuilder directory(File directory)
+ {
+ this.directory = directory;
+ return this;
+ }
+
+ /**
+ * <p>
+ * Returns the system environment variables of the process.
+ * If the underlying system does not support environment variables,
+ * an empty map is returned.
+ * </p>
+ * <p>
+ * The returned map does not accept queries using
+ * null keys or values, or those of a type other than
+ * <code>String</code>. Attempts to pass in a null value will
+ * throw a <code>NullPointerException</code>. Types other than
+ * <code>String</code> throw a <code>ClassCastException</code>.
+ * </p>
+ * <p>
+ * As the returned map is generated using data from the underlying
+ * platform, it may not comply with the <code>equals()</code>
+ * and <code>hashCode()</code> contracts. It is also likely that
+ * the keys of this map will be case-sensitive.
+ * </p>
+ * <p>
+ * Modification of the map is reliant on the underlying platform;
+ * some may not allow any changes to the environment variables or
+ * may prevent certain values being used. Attempts to do so will
+ * throw an <code>UnsupportedOperationException</code> or
+ * <code>IllegalArgumentException</code>, respectively.
+ * </p>
+ * <p>
+ * Use of this method may require a security check for the
+ * RuntimePermission "getenv.*".
+ * </p>
+ *
+ * @return a map of the system environment variables for the process.
+ * @throws SecurityException if the checkPermission method of
+ * an installed security manager prevents access to
+ * the system environment variables.
+ * @since 1.5
+ */
+ public Map<String, String> environment()
+ {
+ return environment;
+ }
+
+ /**
+ * Returns true if the output stream and error stream of the
+ * process will be merged to form one composite stream. The
+ * default return value is <code>false</code>.
+ *
+ * @return true if the output stream and error stream are to
+ * be merged.
+ */
+ public boolean redirectErrorStream()
+ {
+ return redirect;
+ }
+
+ /**
+ * Sets the error stream redirection flag. If set, the output
+ * and error streams are merged to form one composite stream.
+ *
+ * @param redirect the new value of the redirection flag.
+ * @return a reference to this process builder.
+ */
+ public ProcessBuilder redirectErrorStream(boolean redirect)
+ {
+ this.redirect = redirect;
+ return this;
+ }
+
+ /**
+ * <p>
+ * Starts execution of a new process, based on the attributes of
+ * this <code>ProcessBuilder</code> object. This is the point
+ * at which the command-line arguments are checked. The list
+ * must be non-empty and contain only non-null string objects.
+ * The other attributes have default values which are used in
+ * cases where their values are not explicitly specified.
+ * </p>
+ * <p>
+ * If a security manager is in place, then the
+ * {@link SecurityManager#checkExec()} method is called to
+ * ensure that permission is given to execute the process.
+ * </p>
+ * <p>
+ * The execution of the process is system-dependent. Various
+ * exceptions may result, due to problems at the operating system
+ * level. These are all returned as a form of {@link IOException}.
+ * </p>
+ *
+ * @return a <code>Process</code> object, representing the spawned
+ * subprocess.
+ * @throws IOException if a problem occurs with executing the process
+ * at the operating system level.
+ * @throws IndexOutOfBoundsException if the command to execute is
+ * actually an empty list.
+ * @throws NullPointerException if the command to execute is null
+ * or the list contains null elements.
+ * @throws SecurityException if a security manager exists and prevents
+ * execution of the subprocess.
+ */
+ public Process start() throws IOException
+ {
+ SecurityManager sm = SecurityManager.current; // Be thread-safe!
+ if (sm != null)
+ sm.checkExec(command.get(0));
+ return VMProcess.exec(command, environment, directory, redirect);
+ }
+}
diff --git a/java/lang/SecurityManager.java b/java/lang/SecurityManager.java
index 999fe83dd..61b4612b1 100644
--- a/java/lang/SecurityManager.java
+++ b/java/lang/SecurityManager.java
@@ -1,5 +1,5 @@
/* SecurityManager.java -- security checks for privileged actions
- Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc.
+ Copyright (C) 1998, 1999, 2001, 2002, 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -240,7 +240,7 @@ public class SecurityManager
* @return the most recent non-system Class on the execution stack
* @deprecated use {@link #checkPermission(Permission)} instead
*/
- protected Class currentLoadedClass()
+ protected Class<?> currentLoadedClass()
{
int i = classLoaderDepth();
return i >= 0 ? getClassContext()[i] : null;
@@ -983,7 +983,7 @@ public class SecurityManager
* @see Member#PUBLIC
* @since 1.1
*/
- public void checkMemberAccess(Class c, int memberType)
+ public void checkMemberAccess(Class<?> c, int memberType)
{
if (c == null)
throw new NullPointerException();
diff --git a/java/lang/Short.java b/java/lang/Short.java
index eb40cd9e0..41a31e260 100644
--- a/java/lang/Short.java
+++ b/java/lang/Short.java
@@ -1,5 +1,5 @@
/* Short.java -- object wrapper for short
- Copyright (C) 1998, 2001, 2002, 2005 Free Software Foundation, Inc.
+ Copyright (C) 1998, 2001, 2002, 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -48,10 +48,12 @@ package java.lang;
* @author Paul Fisher
* @author John Keiser
* @author Eric Blake (ebb9@email.byu.edu)
+ * @author Tom Tromey (tromey@redhat.com)
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
* @since 1.1
- * @status updated to 1.4
+ * @status updated to 1.5
*/
-public final class Short extends Number implements Comparable
+public final class Short extends Number implements Comparable<Short>
{
/**
* Compatible with JDK 1.1+.
@@ -74,7 +76,7 @@ public final class Short extends Number implements Comparable
* The primitive type <code>short</code> is represented by this
* <code>Class</code> object.
*/
- public static final Class TYPE = VMClassLoader.getPrimitiveClass('S');
+ public static final Class<Short> TYPE = (Class<Short>) VMClassLoader.getPrimitiveClass('S');
/**
* The number of bits needed to represent a <code>short</code>.
@@ -208,7 +210,6 @@ public final class Short extends Number implements Comparable
*
* @param val the value to wrap
* @return the <code>Short</code>
- *
* @since 1.5
*/
public static Short valueOf(short val)
@@ -217,9 +218,9 @@ public final class Short extends Number implements Comparable
return new Short(val);
synchronized (shortCache)
{
- if (shortCache[val - MIN_CACHE] == null)
- shortCache[val - MIN_CACHE] = new Short(val);
- return shortCache[val - MIN_CACHE];
+ if (shortCache[val - MIN_CACHE] == null)
+ shortCache[val - MIN_CACHE] = new Short(val);
+ return shortCache[val - MIN_CACHE];
}
}
@@ -371,22 +372,6 @@ public final class Short extends Number implements Comparable
}
/**
- * Behaves like <code>compareTo(Short)</code> unless the Object
- * is not a <code>Short</code>.
- *
- * @param o the object to compare
- * @return the comparison
- * @throws ClassCastException if the argument is not a <code>Short</code>
- * @see #compareTo(Short)
- * @see Comparable
- * @since 1.2
- */
- public int compareTo(Object o)
- {
- return compareTo((Short)o);
- }
-
- /**
* Reverse the bytes in val.
* @since 1.5
*/
diff --git a/java/lang/String.java b/java/lang/String.java
index dbc3f7d8b..28b77c0aa 100644
--- a/java/lang/String.java
+++ b/java/lang/String.java
@@ -1,5 +1,5 @@
/* String.java -- immutable character sequences; the object of string literals
- Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2005
+ Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -54,6 +54,7 @@ import java.nio.charset.IllegalCharsetNameException;
import java.nio.charset.UnsupportedCharsetException;
import java.text.Collator;
import java.util.Comparator;
+import java.util.Formatter;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -82,10 +83,13 @@ import java.util.regex.PatternSyntaxException;
* @author Paul N. Fisher
* @author Eric Blake (ebb9@email.byu.edu)
* @author Per Bothner (bothner@cygnus.com)
+ * @author Tom Tromey (tromey@redhat.com)
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
* @since 1.0
* @status updated to 1.4; but could use better data sharing via offset field
*/
-public final class String implements Serializable, Comparable, CharSequence
+public final class String
+ implements Serializable, Comparable<String>, CharSequence
{
// WARNING: String is a CORE class in the bootstrap cycle. See the comments
// in vm/reference/java/lang/Runtime for implications of this fact.
@@ -144,7 +148,7 @@ public final class String implements Serializable, Comparable, CharSequence
* compatibility with Sun's JDK.
*/
private static final class CaseInsensitiveComparator
- implements Comparator, Serializable
+ implements Comparator<String>, Serializable
{
/**
* Compatible with JDK 1.2.
@@ -168,9 +172,9 @@ public final class String implements Serializable, Comparable, CharSequence
* @throws ClassCastException if either argument is not a String
* @see #compareToIgnoreCase(String)
*/
- public int compare(Object o1, Object o2)
+ public int compare(String o1, String o2)
{
- return ((String) o1).compareToIgnoreCase((String) o2);
+ return o1.compareToIgnoreCase(o2);
}
} // class CaseInsensitiveComparator
@@ -182,7 +186,7 @@ public final class String implements Serializable, Comparable, CharSequence
* @see Collator#compare(String, String)
* @since 1.2
*/
- public static final Comparator CASE_INSENSITIVE_ORDER
+ public static final Comparator<String> CASE_INSENSITIVE_ORDER
= new CaseInsensitiveComparator();
/**
@@ -919,22 +923,6 @@ public final class String implements Serializable, Comparable, CharSequence
}
/**
- * Behaves like <code>compareTo(java.lang.String)</code> unless the Object
- * is not a <code>String</code>. Then it throws a
- * <code>ClassCastException</code>.
- *
- * @param o the object to compare against
- * @return the comparison
- * @throws NullPointerException if o is null
- * @throws ClassCastException if o is not a <code>String</code>
- * @since 1.2
- */
- public int compareTo(Object o)
- {
- return compareTo((String) o);
- }
-
- /**
* Compares this String and another String (case insensitive). This
* comparison is <em>similar</em> to equalsIgnoreCase, in that it ignores
* locale and multi-characater capitalization, and compares characters
@@ -1674,7 +1662,6 @@ public final class String implements Serializable, Comparable, CharSequence
* @return String containing the chars from data[offset..offset+count]
* @throws NullPointerException if data is null
* @throws IndexOutOfBoundsException if (offset &lt; 0 || count &lt; 0
- * || offset + count &lt; 0 (overflow)
* || offset + count &gt; data.length)
* (while unspecified, this is a StringIndexOutOfBoundsException)
* @see #String(char[], int, int)
@@ -1696,6 +1683,7 @@ public final class String implements Serializable, Comparable, CharSequence
* @throws NullPointerException if data is null
* @throws IndexOutOfBoundsException if (offset &lt; 0 || count &lt; 0
* || offset + count &lt; 0 (overflow)
+ * || offset + count &lt; 0 (overflow)
* || offset + count &gt; data.length)
* (while unspecified, this is a StringIndexOutOfBoundsException)
* @see #String(char[], int, int)
@@ -1792,6 +1780,20 @@ public final class String implements Serializable, Comparable, CharSequence
return Double.toString(d);
}
+
+ /** @since 1.5 */
+ public static String format(Locale locale, String format, Object... args)
+ {
+ Formatter f = new Formatter(locale);
+ return f.format(format, args).toString();
+ }
+
+ /** @since 1.5 */
+ public static String format(String format, Object... args)
+ {
+ return format(Locale.getDefault(), format, args);
+ }
+
/**
* If two Strings are considered equal, by the equals() method,
* then intern() will return the same String instance. ie.
diff --git a/java/lang/StringBuffer.java b/java/lang/StringBuffer.java
index caffd6e70..3aa84a21e 100644
--- a/java/lang/StringBuffer.java
+++ b/java/lang/StringBuffer.java
@@ -72,8 +72,12 @@ import java.io.Serializable;
* @since 1.0
* @status updated to 1.4
*/
-public final class StringBuffer implements Serializable, CharSequence
+public final class StringBuffer
+ implements Serializable, CharSequence, Appendable
{
+ // Implementation note: if you change this class, you usually will
+ // want to change StringBuilder as well.
+
/**
* Compatible with JDK 1.0+.
*/
@@ -148,21 +152,22 @@ public final class StringBuffer implements Serializable, CharSequence
}
/**
- * Create a new <code>StringBuffer</code> with the characters from the
+ * Create a new <code>StringBuffer</code> with the characters in the
* specified <code>CharSequence</code>. Initial capacity will be the
- * size of the CharSequence plus 16.
+ * length of the sequence plus 16; if the sequence reports a length
+ * less than or equal to 0, then the initial capacity will be 16.
*
- * @param sequence the <code>String</code> to convert
+ * @param seq the initializing <code>CharSequence</code>
* @throws NullPointerException if str is null
- *
* @since 1.5
*/
- public StringBuffer(CharSequence sequence)
+ public StringBuffer(CharSequence seq)
{
- count = Math.max(0, sequence.length());
+ int len = seq.length();
+ count = len <= 0 ? 0 : len;
value = new char[count + DEFAULT_CAPACITY];
- for (int i = 0; i < count; ++i)
- value[i] = sequence.charAt(i);
+ for (int i = 0; i < len; ++i)
+ value[i] = seq.charAt(i);
}
/**
@@ -391,46 +396,6 @@ public final class StringBuffer implements Serializable, CharSequence
}
/**
- * Append the <code>CharSequence</code> value of the argument to this
- * <code>StringBuffer</code>.
- *
- * @param sequence the <code>CharSequence</code> to append
- * @return this <code>StringBuffer</code>
- * @see #append(Object)
- * @since 1.5
- */
- public synchronized StringBuffer append(CharSequence sequence)
- {
- if (sequence == null)
- sequence = "null";
- return append(sequence, 0, sequence.length());
- }
-
- /**
- * Append the specified subsequence of the <code>CharSequence</code>
- * argument to this <code>StringBuffer</code>.
- *
- * @param sequence the <code>CharSequence</code> to append
- * @param start the starting index
- * @param end one past the ending index
- * @return this <code>StringBuffer</code>
- * @see #append(Object)
- * @since 1.5
- */
- public synchronized StringBuffer append(CharSequence sequence,
- int start, int end)
- {
- if (sequence == null)
- sequence = "null";
- if (start < 0 || end < 0 || start > end || end > sequence.length())
- throw new IndexOutOfBoundsException();
- ensureCapacity_unsynchronized(this.count + end - start);
- for (int i = start; i < end; ++i)
- value[count++] = sequence.charAt(i);
- return this;
- }
-
- /**
* Append the <code>char</code> array to this <code>StringBuffer</code>.
* This is similar (but more efficient) than
* <code>append(new String(data))</code>, except in the case of null.
@@ -470,6 +435,25 @@ public final class StringBuffer implements Serializable, CharSequence
}
/**
+ * Append the code point to this <code>StringBuffer</code>.
+ * This is like #append(char), but will append two characters
+ * if a supplementary code point is given.
+ *
+ * @param code the code point to append
+ * @return this <code>StringBuffer</code>
+ * @see Character#toChars(int, char[], int)
+ * @since 1.5
+ */
+ public synchronized StringBuffer appendCodePoint(int code)
+ {
+ int len = Character.charCount(code);
+ ensureCapacity_unsynchronized(count + len);
+ Character.toChars(code, value, count);
+ count += len;
+ return this;
+ }
+
+ /**
* Append the <code>String</code> value of the argument to this
* <code>StringBuffer</code>. Uses <code>String.valueOf()</code> to convert
* to <code>String</code>.
@@ -497,21 +481,39 @@ public final class StringBuffer implements Serializable, CharSequence
}
/**
- * Append the code point to this <code>StringBuffer</code>.
- * This is like #append(char), but will append two characters
- * if a supplementary code point is given.
+ * Append the characters in the <code>CharSequence</code> to this
+ * buffer.
*
- * @param code the code point to append
+ * @param seq the <code>CharSequence</code> providing the characters
* @return this <code>StringBuffer</code>
- * @see Character#toChars(int, char[], int)
* @since 1.5
*/
- public synchronized StringBuffer appendCodePoint(int code)
+ public synchronized StringBuffer append(CharSequence seq)
{
- int len = Character.charCount(code);
- ensureCapacity_unsynchronized(count + len);
- Character.toChars(code, value, count);
- count += len;
+ return append(seq, 0, seq.length());
+ }
+
+ /**
+ * Append some characters from the <code>CharSequence</code> to this
+ * buffer. If the argument is null, the four characters "null" are
+ * appended.
+ *
+ * @param seq the <code>CharSequence</code> providing the characters
+ * @param start the starting index
+ * @param end one past the final index
+ * @return this <code>StringBuffer</code>
+ * @since 1.5
+ */
+ public synchronized StringBuffer append(CharSequence seq, int start, int end)
+ {
+ if (seq == null)
+ return append("null");
+ if (end - start > 0)
+ {
+ ensureCapacity_unsynchronized(count + end - start);
+ for (; start < end; ++start)
+ value[count++] = seq.charAt(start);
+ }
return this;
}
diff --git a/java/lang/StringBuilder.java b/java/lang/StringBuilder.java
index 98af48f8f..95d04d1e7 100644
--- a/java/lang/StringBuilder.java
+++ b/java/lang/StringBuilder.java
@@ -74,9 +74,8 @@ import java.io.Serializable;
*
* @since 1.5
*/
-// FIX15: Implement Appendable when co-variant methods are available
public final class StringBuilder
- implements Serializable, CharSequence
+ implements Serializable, CharSequence, Appendable
{
// Implementation note: if you change this class, you usually will
// want to change StringBuffer as well.
diff --git a/java/lang/SuppressWarnings.java b/java/lang/SuppressWarnings.java
new file mode 100644
index 000000000..35b01a851
--- /dev/null
+++ b/java/lang/SuppressWarnings.java
@@ -0,0 +1,69 @@
+/* SuppressWarnings - Annotation to avoid compiler warnings
+ Copyright (C) 2004 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.lang;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+import static java.lang.annotation.RetentionPolicy.SOURCE;
+import static java.lang.annotation.ElementType.*;
+
+/**
+ * Tell the compiler that a given warning should be suppressed when it
+ * pertains to the marked program element and its sub-elements.
+ *
+ * Note that warning suppression is additive. For instance if a
+ * constructor has a warning suppressed, and a local variable in the
+ * constructor has a different warning suppressed, then the resulting
+ * set of suppressed warnings for that variable will be both warnings.
+ *
+ * @since 1.5
+ */
+@Retention(SOURCE)
+@Target({TYPE, FIELD, METHOD, PARAMETER, CONSTRUCTOR, LOCAL_VARIABLE})
+public @interface SuppressWarnings
+{
+ /**
+ * The list of warnings to suppress.
+ *
+ * It is valid to list a name more than once. Unrecognized names
+ * are not a compile-time error. At the present there is no
+ * standard for the names to be recognized by compilers; consult
+ * your compiler's documentation for this information.
+ */
+ String[] value ();
+}
diff --git a/java/lang/System.java b/java/lang/System.java
index 19278aa32..ca390bf16 100644
--- a/java/lang/System.java
+++ b/java/lang/System.java
@@ -44,6 +44,14 @@ import gnu.classpath.VMStackWalker;
import java.io.InputStream;
import java.io.PrintStream;
+import java.util.AbstractCollection;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
import java.util.Properties;
import java.util.PropertyPermission;
@@ -98,6 +106,11 @@ public final class System
public static final PrintStream err = VMSystem.makeStandardErrorStream();
/**
+ * A cached copy of the environment variable map.
+ */
+ private static Map<String,String> environmentMap;
+
+ /**
* This class is uninstantiable.
*/
private System()
@@ -118,6 +131,7 @@ public final class System
SecurityManager sm = SecurityManager.current; // Be thread-safe.
if (sm != null)
sm.checkPermission(new RuntimePermission("setIO"));
+
VMSystem.setIn(in);
}
@@ -134,8 +148,7 @@ public final class System
{
SecurityManager sm = SecurityManager.current; // Be thread-safe.
if (sm != null)
- sm.checkPermission(new RuntimePermission("setIO"));
-
+ sm.checkPermission(new RuntimePermission("setIO"));
VMSystem.setOut(out);
}
@@ -221,7 +234,7 @@ public final class System
{
return VMSystem.currentTimeMillis();
}
-
+
/**
* <p>
* Returns the current value of a nanosecond-precise system timer.
@@ -493,6 +506,60 @@ public final class System
}
/**
+ * <p>
+ * Returns an unmodifiable view of the system environment variables.
+ * If the underlying system does not support environment variables,
+ * an empty map is returned.
+ * </p>
+ * <p>
+ * The returned map is read-only and does not accept queries using
+ * null keys or values, or those of a type other than <code>String</code>.
+ * Attempts to modify the map will throw an
+ * <code>UnsupportedOperationException</code>, while attempts
+ * to pass in a null value will throw a
+ * <code>NullPointerException</code>. Types other than <code>String</code>
+ * throw a <code>ClassCastException</code>.
+ * </p>
+ * <p>
+ * As the returned map is generated using data from the underlying
+ * platform, it may not comply with the <code>equals()</code>
+ * and <code>hashCode()</code> contracts. It is also likely that
+ * the keys of this map will be case-sensitive.
+ * </p>
+ * <p>
+ * Use of this method may require a security check for the
+ * RuntimePermission "getenv.*".
+ * </p>
+ *
+ * @return a map of the system environment variables.
+ * @throws SecurityException if the checkPermission method of
+ * an installed security manager prevents access to
+ * the system environment variables.
+ * @since 1.5
+ */
+ public static Map<String, String> getenv()
+ {
+ SecurityManager sm = SecurityManager.current; // Be thread-safe.
+ if (sm != null)
+ sm.checkPermission(new RuntimePermission("getenv.*"));
+ if (environmentMap == null)
+ {
+ List<String> environ = (List<String>)VMSystem.environ();
+ Map<String,String> variables = new EnvironmentMap();
+ for (String pair : environ)
+ {
+ String[] parts = pair.split("=");
+ if (parts.length == 2)
+ variables.put(parts[0], parts[1]);
+ else
+ variables.put(parts[0], "");
+ }
+ environmentMap = Collections.unmodifiableMap(variables);
+ }
+ return environmentMap;
+ }
+
+ /**
* Terminate the Virtual Machine. This just calls
* <code>Runtime.getRuntime().exit(status)</code>, and never returns.
* Obviously, a security check is in order, <code>checkExit</code>.
@@ -604,4 +671,419 @@ public final class System
return VMRuntime.mapLibraryName(libname);
}
+
+ /**
+ * This is a specialised <code>Collection</code>, providing
+ * the necessary provisions for the collections used by the
+ * environment variable map. Namely, it prevents
+ * querying anything but <code>String</code>s.
+ *
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
+ */
+ private static class EnvironmentCollection
+ extends AbstractCollection<String>
+ {
+
+ /**
+ * The wrapped collection.
+ */
+ protected Collection<String> c;
+
+ /**
+ * Constructs a new environment collection, which
+ * wraps the elements of the supplied collection.
+ *
+ * @param coll the collection to use as a base for
+ * this collection.
+ */
+ public EnvironmentCollection(Collection<String> coll)
+ {
+ c = coll;
+ }
+
+ /**
+ * Blocks queries containing a null object or an object which
+ * isn't of type <code>String</code>. All other queries
+ * are forwarded to the underlying collection.
+ *
+ * @param obj the object to look for.
+ * @return true if the object exists in the collection.
+ * @throws NullPointerException if the specified object is null.
+ * @throws ClassCastException if the specified object is not a String.
+ */
+ public boolean contains(Object obj)
+ {
+ if (obj == null)
+ throw new
+ NullPointerException("This collection does not support " +
+ "null values.");
+ if (!(obj instanceof String))
+ throw new
+ ClassCastException("This collection only supports Strings.");
+ return c.contains(obj);
+ }
+
+ /**
+ * Blocks queries where the collection contains a null object or
+ * an object which isn't of type <code>String</code>. All other
+ * queries are forwarded to the underlying collection.
+ *
+ * @param coll the collection of objects to look for.
+ * @return true if the collection contains all elements in the collection.
+ * @throws NullPointerException if the collection is null.
+ * @throws NullPointerException if any collection entry is null.
+ * @throws ClassCastException if any collection entry is not a String.
+ */
+ public boolean containsAll(Collection<?> coll)
+ {
+ for (Object o: coll)
+ {
+ if (o == null)
+ throw new
+ NullPointerException("This collection does not support " +
+ "null values.");
+ if (!(o instanceof String))
+ throw new
+ ClassCastException("This collection only supports Strings.");
+ }
+ return c.containsAll(coll);
+ }
+
+ /**
+ * This returns an iterator over the map elements, with the
+ * same provisions as for the collection and underlying map.
+ *
+ * @return an iterator over the map elements.
+ */
+ public Iterator<String> iterator()
+ {
+ return c.iterator();
+ }
+
+ /**
+ * Blocks the removal of elements from the collection.
+ *
+ * @return true if the removal was sucessful.
+ * @throws NullPointerException if the collection is null.
+ * @throws NullPointerException if any collection entry is null.
+ * @throws ClassCastException if any collection entry is not a String.
+ */
+ public boolean remove(Object key)
+ {
+ if (key == null)
+ throw new
+ NullPointerException("This collection does not support " +
+ "null values.");
+ if (!(key instanceof String))
+ throw new
+ ClassCastException("This collection only supports Strings.");
+ return c.contains(key);
+ }
+
+ /**
+ * Blocks the removal of all elements in the specified
+ * collection from the collection.
+ *
+ * @param coll the collection of elements to remove.
+ * @return true if the elements were removed.
+ * @throws NullPointerException if the collection is null.
+ * @throws NullPointerException if any collection entry is null.
+ * @throws ClassCastException if any collection entry is not a String.
+ */
+ public boolean removeAll(Collection<?> coll)
+ {
+ for (Object o: coll)
+ {
+ if (o == null)
+ throw new
+ NullPointerException("This collection does not support " +
+ "null values.");
+ if (!(o instanceof String))
+ throw new
+ ClassCastException("This collection only supports Strings.");
+ }
+ return c.removeAll(coll);
+ }
+
+ /**
+ * Blocks the retention of all elements in the specified
+ * collection from the collection.
+ *
+ * @param c the collection of elements to retain.
+ * @return true if the other elements were removed.
+ * @throws NullPointerException if the collection is null.
+ * @throws NullPointerException if any collection entry is null.
+ * @throws ClassCastException if any collection entry is not a String.
+ */
+ public boolean retainAll(Collection<?> coll)
+ {
+ for (Object o: coll)
+ {
+ if (o == null)
+ throw new
+ NullPointerException("This collection does not support " +
+ "null values.");
+ if (!(o instanceof String))
+ throw new
+ ClassCastException("This collection only supports Strings.");
+ }
+ return c.containsAll(coll);
+ }
+
+ /**
+ * This simply calls the same method on the wrapped
+ * collection.
+ *
+ * @return the size of the underlying collection.
+ */
+ public int size()
+ {
+ return c.size();
+ }
+
+ } // class EnvironmentCollection<String>
+
+ /**
+ * This is a specialised <code>HashMap</code>, which
+ * prevents the addition or querying of anything other than
+ * <code>String</code> objects.
+ *
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
+ */
+ static class EnvironmentMap
+ extends HashMap<String,String>
+ {
+
+ /**
+ * Cache the entry set.
+ */
+ private transient Set<Map.Entry<String,String>> entries;
+
+ /**
+ * Cache the key set.
+ */
+ private transient Set<String> keys;
+
+ /**
+ * Cache the value collection.
+ */
+ private transient Collection<String> values;
+
+ /**
+ * Constructs a new empty <code>EnvironmentMap</code>.
+ */
+ EnvironmentMap()
+ {
+ super();
+ }
+
+ /**
+ * Constructs a new <code>EnvironmentMap</code> containing
+ * the contents of the specified map.
+ *
+ * @param m the map to be added to this.
+ * @throws NullPointerException if a key or value is null.
+ * @throws ClassCastException if a key or value is not a String.
+ */
+ EnvironmentMap(Map<String,String> m)
+ {
+ super(m);
+ }
+
+ /**
+ * Blocks queries containing a null key or one which is not
+ * of type <code>String</code>. All other queries
+ * are forwarded to the superclass.
+ *
+ * @param key the key to look for in the map.
+ * @return true if the key exists in the map.
+ * @throws NullPointerException if the specified key is null.
+ */
+ public boolean containsKey(Object key)
+ {
+ if (key == null)
+ throw new
+ NullPointerException("This map does not support null keys.");
+ if (!(key instanceof String))
+ throw new
+ ClassCastException("This map only allows queries using Strings.");
+ return super.containsKey(key);
+ }
+
+ /**
+ * Blocks queries using a null or non-<code>String</code> value.
+ * All other queries are forwarded to the superclass.
+ *
+ * @param value the value to look for in the map.
+ * @return true if the value exists in the map.
+ * @throws NullPointerException if the specified value is null.
+ */
+ public boolean containsValue(Object value)
+ {
+ if (value == null)
+ throw new
+ NullPointerException("This map does not support null values.");
+ if (!(value instanceof String))
+ throw new
+ ClassCastException("This map only allows queries using Strings.");
+ return super.containsValue(value);
+ }
+
+ /**
+ * Returns a set view of the map entries, with the same
+ * provisions as for the underlying map.
+ *
+ * @return a set containing the map entries.
+ */
+ public Set<Map.Entry<String,String>> entrySet()
+ {
+ if (entries == null)
+ entries = super.entrySet();
+ return entries;
+ }
+
+ /**
+ * Blocks queries containing a null or non-<code>String</code> key.
+ * All other queries are passed on to the superclass.
+ *
+ * @param key the key to retrieve the value for.
+ * @return the value associated with the given key.
+ * @throws NullPointerException if the specified key is null.
+ * @throws ClassCastException if the specified key is not a String.
+ */
+ public String get(Object key)
+ {
+ if (key == null)
+ throw new
+ NullPointerException("This map does not support null keys.");
+ if (!(key instanceof String))
+ throw new
+ ClassCastException("This map only allows queries using Strings.");
+ return super.get(key);
+ }
+
+ /**
+ * Returns a set view of the keys, with the same
+ * provisions as for the underlying map.
+ *
+ * @return a set containing the keys.
+ */
+ public Set<String> keySet()
+ {
+ if (keys == null)
+ keys = new EnvironmentSet(super.keySet());
+ return keys;
+ }
+
+ /**
+ * Associates the given key to the given value. If the
+ * map already contains the key, its value is replaced.
+ * The map does not accept null keys or values, or keys
+ * and values not of type {@link String}.
+ *
+ * @param key the key to map.
+ * @param value the value to be mapped.
+ * @return the previous value of the key, or null if there was no mapping
+ * @throws NullPointerException if a key or value is null.
+ * @throws ClassCastException if a key or value is not a String.
+ */
+ public String put(String key, String value)
+ {
+ if (key == null)
+ throw new NullPointerException("A new key is null.");
+ if (value == null)
+ throw new NullPointerException("A new value is null.");
+ if (!(key instanceof String))
+ throw new ClassCastException("A new key is not a String.");
+ if (!(value instanceof String))
+ throw new ClassCastException("A new value is not a String.");
+ return super.put(key, value);
+ }
+
+ /**
+ * Removes a key-value pair from the map. The queried key may not
+ * be null or of a type other than a <code>String</code>.
+ *
+ * @param key the key of the entry to remove.
+ * @return the removed value.
+ * @throws NullPointerException if the specified key is null.
+ * @throws ClassCastException if the specified key is not a String.
+ */
+ public String remove(Object key)
+ {
+ if (key == null)
+ throw new
+ NullPointerException("This map does not support null keys.");
+ if (!(key instanceof String))
+ throw new
+ ClassCastException("This map only allows queries using Strings.");
+ return super.remove(key);
+ }
+
+ /**
+ * Returns a collection view of the values, with the same
+ * provisions as for the underlying map.
+ *
+ * @return a collection containing the values.
+ */
+ public Collection<String> values()
+ {
+ if (values == null)
+ values = new EnvironmentCollection(super.values());
+ return values;
+ }
+
+ }
+
+ /**
+ * This is a specialised <code>Set</code>, providing
+ * the necessary provisions for the collections used by the
+ * environment variable map. Namely, it prevents
+ * modifications and the use of queries with null
+ * or non-<code>String</code> values.
+ *
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
+ */
+ private static class EnvironmentSet
+ extends EnvironmentCollection
+ implements Set<String>
+ {
+
+ /**
+ * Constructs a new environment set, which
+ * wraps the elements of the supplied set.
+ *
+ * @param set the set to use as a base for
+ * this set.
+ */
+ public EnvironmentSet(Set<String> set)
+ {
+ super(set);
+ }
+
+ /**
+ * This simply calls the same method on the wrapped
+ * collection.
+ *
+ * @param obj the object to compare with.
+ * @return true if the two objects are equal.
+ */
+ public boolean equals(Object obj)
+ {
+ return c.equals(obj);
+ }
+
+ /**
+ * This simply calls the same method on the wrapped
+ * collection.
+ *
+ * @return the hashcode of the collection.
+ */
+ public int hashCode()
+ {
+ return c.hashCode();
+ }
+
+ } // class EnvironmentSet<String>
+
} // class System
diff --git a/java/lang/Thread.java b/java/lang/Thread.java
index 5f70f558f..551cd1b9e 100644
--- a/java/lang/Thread.java
+++ b/java/lang/Thread.java
@@ -143,6 +143,9 @@ public class Thread implements Runnable
/** This thread's ID. */
private final long threadId;
+
+ /** The park blocker. See LockSupport. */
+ Object parkBlocker;
/** The next thread number to use. */
private static int numAnonymousThreadsCreated;
@@ -352,9 +355,9 @@ public class Thread implements Runnable
if (group == null)
{
if (sm != null)
- group = sm.getThreadGroup();
+ group = sm.getThreadGroup();
if (group == null)
- group = current.group;
+ group = current.group;
}
if (sm != null)
sm.checkAccess(group);
@@ -398,7 +401,7 @@ public class Thread implements Runnable
this.vmThread = vmThread;
this.runnable = null;
if (name == null)
- name = createAnonymousThreadName();
+ name = createAnonymousThreadName();
this.name = name;
this.priority = priority;
this.daemon = daemon;
@@ -413,11 +416,11 @@ public class Thread implements Runnable
// (and, as above, the constructiong sequence calls Thread.currenThread()).
contextClassLoaderIsSystemClassLoader = true;
synchronized (Thread.class)
- {
- this.threadId = ++totalThreadsCreated;
- }
+ {
+ this.threadId = totalThreadsCreated++;
+ }
}
-
+
/**
* Generate a name for an anonymous thread.
*/
@@ -466,7 +469,7 @@ public class Thread implements Runnable
{
VMThread t = vmThread;
if (t == null || group == null)
- throw new IllegalThreadStateException();
+ throw new IllegalThreadStateException();
return t.countStackFrames();
}
@@ -610,7 +613,7 @@ public class Thread implements Runnable
checkAccess();
VMThread t = vmThread;
if (t != null)
- t.interrupt();
+ t.interrupt();
}
/**
@@ -701,12 +704,12 @@ public class Thread implements Runnable
*/
public final void join(long ms, int ns) throws InterruptedException
{
- if(ms < 0 || ns < 0 || ns > 999999)
- throw new IllegalArgumentException();
+ if (ms < 0 || ns < 0 || ns > 999999)
+ throw new IllegalArgumentException();
VMThread t = vmThread;
- if(t != null)
- t.join(ms, ns);
+ if (t != null)
+ t.join(ms, ns);
}
/**
@@ -724,7 +727,7 @@ public class Thread implements Runnable
checkAccess();
VMThread t = vmThread;
if (t != null)
- t.resume();
+ t.resume();
}
/**
@@ -828,9 +831,9 @@ public class Thread implements Runnable
throw new NullPointerException();
VMThread t = vmThread;
if (t != null)
- t.setName(name);
+ t.setName(name);
else
- this.name = name;
+ this.name = name;
}
/**
@@ -888,7 +891,6 @@ public class Thread implements Runnable
*/
public static void sleep(long ms, int ns) throws InterruptedException
{
-
// Check parameters
if (ms < 0 )
throw new IllegalArgumentException("Negative milliseconds: " + ms);
@@ -913,7 +915,7 @@ public class Thread implements Runnable
public synchronized void start()
{
if (vmThread != null || group == null)
- throw new IllegalThreadStateException();
+ throw new IllegalThreadStateException();
VMThread.create(this, stacksize);
}
@@ -1010,7 +1012,7 @@ public class Thread implements Runnable
checkAccess();
VMThread t = vmThread;
if (t != null)
- t.suspend();
+ t.suspend();
}
/**
@@ -1037,9 +1039,9 @@ public class Thread implements Runnable
priority = Math.min(priority, group.getMaxPriority());
VMThread t = vmThread;
if (t != null)
- t.setPriority(priority);
+ t.setPriority(priority);
else
- this.priority = priority;
+ this.priority = priority;
}
/**
@@ -1233,6 +1235,37 @@ public class Thread implements Runnable
void uncaughtException(Thread thr, Throwable exc);
}
+ /**
+ * <p>
+ * Represents the current state of a thread, according to the VM rather
+ * than the operating system. It can be one of the following:
+ * </p>
+ * <ul>
+ * <li>NEW -- The thread has just been created but is not yet running.</li>
+ * <li>RUNNABLE -- The thread is currently running or can be scheduled
+ * to run.</li>
+ * <li>BLOCKED -- The thread is blocked waiting on an I/O operation
+ * or to obtain a lock.</li>
+ * <li>WAITING -- The thread is waiting indefinitely for another thread
+ * to do something.</li>
+ * <li>TIMED_WAITING -- The thread is waiting for a specific amount of time
+ * for another thread to do something.</li>
+ * <li>TERMINATED -- The thread has exited.</li>
+ * </ul>
+ *
+ * @since 1.5
+ */
+ public enum State
+ {
+ BLOCKED, NEW, RUNNABLE, TERMINATED, TIMED_WAITING, WAITING;
+
+ /**
+ * For compatability with Sun's JDK
+ */
+ private static final long serialVersionUID = 605505746047245783L;
+ }
+
+
/**
* Returns the current state of the thread. This
* is designed for monitoring thread behaviour, rather
@@ -1240,14 +1273,14 @@ public class Thread implements Runnable
*
* @return the current thread state.
*/
- public String getState()
+ public State getState()
{
VMThread t = vmThread;
if (t != null)
- return t.getState();
+ return State.valueOf(t.getState());
if (group == null)
- return "TERMINATED";
- return "NEW";
+ return State.TERMINATED;
+ return State.NEW;
}
/**
@@ -1283,7 +1316,7 @@ public class Thread implements Runnable
* @since 1.5
* @see #getStackTrace()
*/
- public static Map getAllStackTraces()
+ public static Map<Thread, StackTraceElement[]> getAllStackTraces()
{
ThreadGroup group = currentThread().group;
while (group.getParent() != null)
diff --git a/java/lang/ThreadLocal.java b/java/lang/ThreadLocal.java
index 64df8c3dd..6c4ba176a 100644
--- a/java/lang/ThreadLocal.java
+++ b/java/lang/ThreadLocal.java
@@ -1,5 +1,5 @@
/* ThreadLocal -- a variable with a unique value per thread
- Copyright (C) 2000, 2002, 2003, 2006 Free Software Foundation, Inc.
+ Copyright (C) 2000, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -84,16 +84,16 @@ import java.util.Map;
* @author Mark Wielaard (mark@klomp.org)
* @author Eric Blake (ebb9@email.byu.edu)
* @since 1.2
- * @status updated to 1.4
+ * @status updated to 1.5
*/
-public class ThreadLocal
+public class ThreadLocal<T>
{
/**
* Placeholder to distinguish between uninitialized and null set by the
* user. Do not expose this to the public. Package visible for use by
* InheritableThreadLocal
*/
- static final Object NULL = new Object();
+ static final Object sentinel = new Object();
/**
* Creates a ThreadLocal object without associating any value to it yet.
@@ -110,7 +110,7 @@ public class ThreadLocal
*
* @return the initial value of the variable in this thread
*/
- protected Object initialValue()
+ protected T initialValue()
{
return null;
}
@@ -123,18 +123,18 @@ public class ThreadLocal
*
* @return the value of the variable in this thread
*/
- public Object get()
+ public T get()
{
- Map map = Thread.getThreadLocals();
+ Map<ThreadLocal<T>,T> map = (Map<ThreadLocal<T>,T>) Thread.getThreadLocals();
// Note that we don't have to synchronize, as only this thread will
// ever modify the map.
- Object value = map.get(this);
+ T value = map.get(this);
if (value == null)
{
value = initialValue();
- map.put(this, value == null ? NULL : value);
+ map.put(this, (T) (value == null ? sentinel : value));
}
- return value == NULL ? null : value;
+ return value == (T) sentinel ? null : value;
}
/**
@@ -145,12 +145,12 @@ public class ThreadLocal
*
* @param value the value to set this thread's view of the variable to
*/
- public void set(Object value)
+ public void set(T value)
{
Map map = Thread.getThreadLocals();
// Note that we don't have to synchronize, as only this thread will
// ever modify the map.
- map.put(this, value == null ? NULL : value);
+ map.put(this, value == null ? sentinel : value);
}
/**
diff --git a/java/lang/Void.java b/java/lang/Void.java
index 150354268..05ed98503 100644
--- a/java/lang/Void.java
+++ b/java/lang/Void.java
@@ -1,5 +1,5 @@
/* Void.class - defines void.class
- Copyright (C) 1998, 1999, 2001, 2002 Free Software Foundation, Inc.
+ Copyright (C) 1998, 1999, 2001, 2002, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -49,7 +49,7 @@ package java.lang;
* @author John Keiser
* @author Eric Blake (ebb9@email.byu.edu)
* @since 1.1
- * @status updated to 1.4
+ * @status updated to 1.5
*/
public final class Void
{
@@ -57,7 +57,7 @@ public final class Void
* The return type <code>void</code> is represented by this
* <code>Class</code> object.
*/
- public static final Class TYPE = VMClassLoader.getPrimitiveClass('V');
+ public static final Class<Void> TYPE = (Class<Void>) VMClassLoader.getPrimitiveClass('V');
/**
* Void is non-instantiable.
diff --git a/java/lang/annotation/Annotation.java b/java/lang/annotation/Annotation.java
index 01e23930e..cc334ec3b 100644
--- a/java/lang/annotation/Annotation.java
+++ b/java/lang/annotation/Annotation.java
@@ -54,8 +54,7 @@ public interface Annotation
*
* @return the class of which this annotation is an instance.
*/
- /* FIXME[GENERICS]: Should return Class<? extends Annotation> */
- Class annotationType();
+ Class<? extends Annotation> annotationType();
/**
* <p>
diff --git a/java/lang/annotation/Documented.java b/java/lang/annotation/Documented.java
new file mode 100644
index 000000000..9a51bc2f0
--- /dev/null
+++ b/java/lang/annotation/Documented.java
@@ -0,0 +1,50 @@
+/* Documented.java - Indicates documented source element
+ Copyright (C) 2004, 2005 Free Software Foundation
+
+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.lang.annotation;
+
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+/**
+ * @author Tom Tromey (tromey@redhat.com)
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
+ * @since 1.5
+ */
+@Documented @Retention(RUNTIME)
+public @interface Documented
+{
+}
diff --git a/java/lang/annotation/ElementType.java b/java/lang/annotation/ElementType.java
new file mode 100644
index 000000000..3ab89c946
--- /dev/null
+++ b/java/lang/annotation/ElementType.java
@@ -0,0 +1,59 @@
+/* ElementType.java - Enum listing Java source elements
+ Copyright (C) 2004 Free Software Foundation
+
+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.lang.annotation;
+
+/**
+ * @since 1.5
+ */
+public enum ElementType
+{
+ ANNOTATION_TYPE,
+ CONSTRUCTOR,
+ FIELD,
+ LOCAL_VARIABLE,
+ METHOD,
+ PACKAGE,
+ PARAMETER,
+ TYPE;
+
+ /**
+ * For compatability with Sun's JDK
+ */
+ private static final long serialVersionUID = 2798216111136361587L;
+
+}
diff --git a/java/lang/annotation/IncompleteAnnotationException.java b/java/lang/annotation/IncompleteAnnotationException.java
index a35df0c09..5b20650d1 100644
--- a/java/lang/annotation/IncompleteAnnotationException.java
+++ b/java/lang/annotation/IncompleteAnnotationException.java
@@ -58,7 +58,8 @@ public class IncompleteAnnotationException extends RuntimeException
* @param type the type of annotation from which an element is missing.
* @param name the name of the missing element.
*/
- public IncompleteAnnotationException(Class type, String name)
+ public IncompleteAnnotationException(Class<? extends Annotation> type,
+ String name)
{
this.annotationType = type;
this.elementName = name;
@@ -70,7 +71,7 @@ public class IncompleteAnnotationException extends RuntimeException
*
* @return the type of annotation.
*/
- public Class annotationType()
+ public Class<? extends Annotation> annotationType()
{
return annotationType;
}
@@ -94,7 +95,7 @@ public class IncompleteAnnotationException extends RuntimeException
* @serial the type of the annotation from which an
* element was missing.
*/
- private Class annotationType;
+ private Class<? extends Annotation> annotationType;
/**
* The name of the missing element.
diff --git a/java/lang/annotation/Inherited.java b/java/lang/annotation/Inherited.java
new file mode 100644
index 000000000..34acbf47c
--- /dev/null
+++ b/java/lang/annotation/Inherited.java
@@ -0,0 +1,51 @@
+/* Inherited.java - Indicates inherited annotation
+ Copyright (C) 2004, 2005 Free Software Foundation
+
+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.lang.annotation;
+
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
+
+/**
+ * @author Tom Tromey (tromey@redhat.com)
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
+ * @since 1.5
+ */
+@Documented @Retention(RUNTIME) @Target(ANNOTATION_TYPE)
+public @interface Inherited
+{
+}
diff --git a/java/lang/annotation/Retention.java b/java/lang/annotation/Retention.java
new file mode 100644
index 000000000..8d8a79dbc
--- /dev/null
+++ b/java/lang/annotation/Retention.java
@@ -0,0 +1,59 @@
+/* Retention.java - Retention policy for an annotation
+ Copyright (C) 2004, 2005 Free Software Foundation
+
+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.lang.annotation;
+
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
+
+/**
+ * This annotation is used to specify the desired lifetime of another
+ * annotation.
+ *
+ * @author Tom Tromey (tromey@redhat.com)
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
+ * @see RetentionPolicy
+ * @since 1.5
+ */
+@Documented @Retention(RUNTIME) @Target(ANNOTATION_TYPE)
+public @interface Retention
+{
+ /**
+ * The value holds the lifetime of the annotation.
+ */
+ RetentionPolicy value();
+}
diff --git a/java/lang/annotation/RetentionPolicy.java b/java/lang/annotation/RetentionPolicy.java
new file mode 100644
index 000000000..56d2af1b7
--- /dev/null
+++ b/java/lang/annotation/RetentionPolicy.java
@@ -0,0 +1,66 @@
+/* RetentionPolicy.java - Enum listing lifetimes for an annotation
+ Copyright (C) 2004 Free Software Foundation
+
+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.lang.annotation;
+
+/**
+ * This enum is used to control the lifetime of an annotation.
+ *
+ * @see Retention
+ *
+ * @since 1.5
+ */
+public enum RetentionPolicy
+{
+ /** Indicates that the annotation should be stored in class files. */
+ CLASS,
+
+ /** Indicates that the annotation should be available at runtime. */
+ RUNTIME,
+
+ /**
+ * Indicates that the annotation should only be available when
+ * parsing the source code.
+ */
+ SOURCE;
+
+ /**
+ * For compatability with Sun's JDK
+ */
+ private static final long serialVersionUID = -1700821648800605045L;
+
+}
diff --git a/java/lang/annotation/Target.java b/java/lang/annotation/Target.java
new file mode 100644
index 000000000..c9d968632
--- /dev/null
+++ b/java/lang/annotation/Target.java
@@ -0,0 +1,52 @@
+/* Target.java - Indicate where an annotation may be applied
+ Copyright (C) 2004, 2005 Free Software Foundation
+
+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.lang.annotation;
+
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
+
+/**
+ * @author Tom Tromey (tromey@redhat.com)
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
+ * @since 1.5
+ */
+@Documented @Retention(RUNTIME) @Target(ANNOTATION_TYPE)
+public @interface Target
+{
+ ElementType[] value();
+}
diff --git a/java/lang/instrument/ClassDefinition.java b/java/lang/instrument/ClassDefinition.java
index 841597c31..f2fbf9296 100644
--- a/java/lang/instrument/ClassDefinition.java
+++ b/java/lang/instrument/ClassDefinition.java
@@ -60,8 +60,7 @@ public final class ClassDefinition
* @param theClassFile the new class file
* @throws NullPointerException if one of the argument is null
*/
- /* FIXME[GENERICS]: Signature should be (Class<?>, byte[]) */
- public ClassDefinition(Class theClass, byte[] theClassFile)
+ public ClassDefinition(Class<?> theClass, byte[] theClassFile)
{
if (theClass == null || theClassFile == null)
throw new NullPointerException();
@@ -72,8 +71,7 @@ public final class ClassDefinition
/**
* @return the Class
*/
- /* FIXME[GENERICS]: Should return Class<?> */
- public Class getDefinitionClass()
+ public Class<?> getDefinitionClass()
{
return theClass;
}
diff --git a/java/lang/instrument/ClassFileTransformer.java b/java/lang/instrument/ClassFileTransformer.java
index 68638d719..01b2f8aaa 100644
--- a/java/lang/instrument/ClassFileTransformer.java
+++ b/java/lang/instrument/ClassFileTransformer.java
@@ -75,10 +75,9 @@ public interface ClassFileTransformer
* @see Instrumentation#redefineClasses(java.lang.instrument.ClassDefinition[])
*
*/
- /* FIXME[GENERICS]: Class should be Class<?> */
byte[] transform(ClassLoader loader,
String className,
- Class classBeingRedefined,
+ Class<?> classBeingRedefined,
ProtectionDomain protectionDomain,
byte[] classfileBuffer)
throws IllegalClassFormatException;
diff --git a/java/lang/management/ManagementFactory.java b/java/lang/management/ManagementFactory.java
index 3a2c81c42..a51ca0f4c 100644
--- a/java/lang/management/ManagementFactory.java
+++ b/java/lang/management/ManagementFactory.java
@@ -374,9 +374,10 @@ public class ManagementFactory
*
* @return a list of memory pool beans, one for each pool.
*/
- public static List getMemoryPoolMXBeans()
+ public static List<MemoryPoolMXBean> getMemoryPoolMXBeans()
{
- List poolBeans = new ArrayList();
+ List<MemoryPoolMXBean> poolBeans =
+ new ArrayList<MemoryPoolMXBean>();
String[] names = VMManagementFactory.getMemoryPoolNames();
for (int a = 0; a < names.length; ++a)
try
@@ -399,9 +400,10 @@ public class ManagementFactory
*
* @return a list of memory manager beans, one for each manager.
*/
- public static List getMemoryManagerMXBeans()
+ public static List<MemoryManagerMXBean> getMemoryManagerMXBeans()
{
- List managerBeans = new ArrayList();
+ List<MemoryManagerMXBean> managerBeans =
+ new ArrayList<MemoryManagerMXBean>();
String[] names = VMManagementFactory.getMemoryManagerNames();
for (int a = 0; a < names.length; ++a)
try
@@ -425,9 +427,10 @@ public class ManagementFactory
*
* @return a list of garbage collector beans, one for each pool.
*/
- public static List getGarbageCollectorMXBeans()
+ public static List<GarbageCollectorMXBean> getGarbageCollectorMXBeans()
{
- List gcBeans = new ArrayList();
+ List<GarbageCollectorMXBean> gcBeans =
+ new ArrayList<GarbageCollectorMXBean>();
String[] names = VMManagementFactory.getGarbageCollectorNames();
for (int a = 0; a < names.length; ++a)
try
diff --git a/java/lang/management/MemoryPoolMXBean.java b/java/lang/management/MemoryPoolMXBean.java
index 5b04c64d3..36a8236dc 100644
--- a/java/lang/management/MemoryPoolMXBean.java
+++ b/java/lang/management/MemoryPoolMXBean.java
@@ -162,7 +162,7 @@ public interface MemoryPoolMXBean
*
* @return the type of this pool.
*/
- String getType();
+ MemoryType getType();
/**
* Returns memory usage statistics for the current memory usage
diff --git a/java/lang/management/MemoryType.java b/java/lang/management/MemoryType.java
new file mode 100644
index 000000000..4422b3298
--- /dev/null
+++ b/java/lang/management/MemoryType.java
@@ -0,0 +1,51 @@
+/* MemoryType.java - Enumeration of the types of memory pools.
+ Copyright (C) 2006 Free Software Foundation
+
+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.lang.management;
+
+/**
+ * Enumerates the possible types of memory pools. A value of this
+ * type is returned by {@link MemoryPoolMXBean#getMemoryType()}.
+ *
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
+ * @since 1.5
+ */
+public enum MemoryType
+{
+ HEAP, NON_HEAP;
+}
+
diff --git a/java/lang/management/RuntimeMXBean.java b/java/lang/management/RuntimeMXBean.java
index cee1d805f..a2931d127 100644
--- a/java/lang/management/RuntimeMXBean.java
+++ b/java/lang/management/RuntimeMXBean.java
@@ -106,7 +106,7 @@ public interface RuntimeMXBean
* denies ManagementPermission("monitor").
* @see java.lang.management.ManagementPermission
*/
- List getInputArguments();
+ List<String> getInputArguments();
/**
* Returns the library path. This is equivalent to obtaining the
@@ -212,7 +212,7 @@ public interface RuntimeMXBean
*
* @return the map of system properties.
*/
- Map getSystemProperties();
+ Map<String,String> getSystemProperties();
/**
* Returns the uptime of the virtual machine in milliseconds.
diff --git a/java/lang/management/ThreadInfo.java b/java/lang/management/ThreadInfo.java
index f3131715b..428aca3fa 100644
--- a/java/lang/management/ThreadInfo.java
+++ b/java/lang/management/ThreadInfo.java
@@ -102,7 +102,7 @@ public class ThreadInfo
/**
* The state of the thread which this instance concerns.
*/
- private String threadState;
+ private Thread.State threadState;
/**
* The number of times the thread has been blocked.
@@ -242,7 +242,7 @@ public class ThreadInfo
* @param trace the stack trace of the thread to a pre-determined
* depth (see VMThreadMXBeanImpl)
*/
- private ThreadInfo(long threadId, String threadName, String threadState,
+ private ThreadInfo(long threadId, String threadName, Thread.State threadState,
long blockedCount, long blockedTime, String lockName,
long lockOwnerId, String lockOwnerName, long waitedCount,
long waitedTime, boolean isInNative, boolean isSuspended,
@@ -389,7 +389,7 @@ public class ThreadInfo
dTraces[a].get("lineNumber")).intValue());
return new ThreadInfo(((Long) data.get("threadId")).longValue(),
(String) data.get("threadName"),
- (String) data.get("threadState"),
+ Thread.State.valueOf((String) data.get("threadState")),
((Long) data.get("blockedCount")).longValue(),
((Long) data.get("blockedTime")).longValue(),
(String) data.get("lockName"),
@@ -486,7 +486,7 @@ public class ThreadInfo
*/
public String getLockName()
{
- if (!threadState.equals("BLOCKED"))
+ if (threadState != Thread.State.BLOCKED)
return null;
return lockName;
}
@@ -504,7 +504,7 @@ public class ThreadInfo
*/
public long getLockOwnerId()
{
- if (!threadState.equals("BLOCKED"))
+ if (threadState != Thread.State.BLOCKED)
return -1;
return lockOwnerId;
}
@@ -522,7 +522,7 @@ public class ThreadInfo
*/
public String getLockOwnerName()
{
- if (!threadState.equals("BLOCKED"))
+ if (threadState != Thread.State.BLOCKED)
return null;
return lockOwnerName;
}
@@ -579,7 +579,7 @@ public class ThreadInfo
*
* @return the thread's state.
*/
- public String getThreadState()
+ public Thread.State getThreadState()
{
return threadState;
}
@@ -697,7 +697,7 @@ public class ThreadInfo
", waitedCount=" + waitedCount +
", isInNative=" + isInNative +
", isSuspended=" + isSuspended +
- (threadState.equals("BLOCKED") ?
+ (threadState == Thread.State.BLOCKED ?
", lockOwnerId=" + lockOwnerId +
", lockOwnerName=" + lockOwnerName : "") +
"]";
diff --git a/java/lang/ref/PhantomReference.java b/java/lang/ref/PhantomReference.java
index 4d929c29c..67e97d399 100644
--- a/java/lang/ref/PhantomReference.java
+++ b/java/lang/ref/PhantomReference.java
@@ -1,5 +1,5 @@
/* java.lang.ref.PhantomReference
- Copyright (C) 1999 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -46,8 +46,8 @@ package java.lang.ref;
*
* @author Jochen Hoenicke
*/
-public class PhantomReference
- extends Reference
+public class PhantomReference<T>
+ extends Reference<T>
{
/**
* Creates a new phantom reference.
@@ -56,7 +56,7 @@ public class PhantomReference
* finalized. This mustn't be <code>null</code>.
* @exception NullPointerException if q is null.
*/
- public PhantomReference(Object referent, ReferenceQueue q)
+ public PhantomReference(T referent, ReferenceQueue<? super T> q)
{
super(referent, q);
}
@@ -66,7 +66,7 @@ public class PhantomReference
* @return <code>null</code>, since the refered object may be
* finalized and thus not accessible.
*/
- public Object get()
+ public T get()
{
return null;
}
diff --git a/java/lang/ref/Reference.java b/java/lang/ref/Reference.java
index 7ea9bdd5a..ce224b891 100644
--- a/java/lang/ref/Reference.java
+++ b/java/lang/ref/Reference.java
@@ -1,5 +1,5 @@
/* java.lang.ref.Reference
- Copyright (C) 1999, 2002, 2003, 2006 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2002, 2003, 2004, 2006 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -70,19 +70,19 @@ package java.lang.ref;
* @author Jochen Hoenicke
* @see java.util.WeakHashMap
*/
-public abstract class Reference
+public abstract class Reference<T>
{
/**
* The underlying object. This field is handled in a special way by
* the garbage collector.
*/
- Object referent;
+ T referent;
/**
* The queue this reference is registered on. This is null, if this
* wasn't registered to any queue or reference was already enqueued.
*/
- volatile ReferenceQueue queue;
+ volatile ReferenceQueue<? super T> queue;
/**
* Link to the next entry on the queue. If this is null, this
@@ -106,7 +106,7 @@ public abstract class Reference
* class in a different package.
* @param ref the object we refer to.
*/
- Reference(Object ref)
+ Reference(T ref)
{
referent = ref;
}
@@ -119,7 +119,7 @@ public abstract class Reference
* @param q the reference queue to register on.
* @exception NullPointerException if q is null.
*/
- Reference(Object ref, ReferenceQueue q)
+ Reference(T ref, ReferenceQueue<? super T> q)
{
if (q == null)
throw new NullPointerException();
@@ -132,7 +132,7 @@ public abstract class Reference
* @return the object, this reference refers to, or null if the
* reference was cleared.
*/
- public Object get()
+ public T get()
{
synchronized (lock)
{
diff --git a/java/lang/ref/ReferenceQueue.java b/java/lang/ref/ReferenceQueue.java
index 59e00c858..281628779 100644
--- a/java/lang/ref/ReferenceQueue.java
+++ b/java/lang/ref/ReferenceQueue.java
@@ -1,5 +1,5 @@
/* java.lang.ref.ReferenceQueue
- Copyright (C) 1999, 2006 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2004, 2006 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -50,7 +50,7 @@ package java.lang.ref;
* @author Jochen Hoenicke
* @see Reference#enqueue()
*/
-public class ReferenceQueue
+public class ReferenceQueue<T>
{
/**
* This is a linked list of references. If this is null, the list is
@@ -60,7 +60,7 @@ public class ReferenceQueue
* itself (not to null, since <code>nextOnQueue</code> is used to
* determine if a reference is enqueued).
*/
- private Reference first;
+ private Reference<? extends T> first;
/**
* This is the lock that protects our linked list and is used to signal
@@ -82,7 +82,7 @@ public class ReferenceQueue
* @return a reference on the queue, if there is one,
* <code>null</code> otherwise.
*/
- public Reference poll()
+ public Reference<? extends T> poll()
{
return dequeue();
}
@@ -92,8 +92,8 @@ public class ReferenceQueue
* @param ref the reference that should be enqueued.
* @return true if successful, false if not.
*/
- final boolean enqueue(Reference ref)
- {
+ final boolean enqueue(Reference<? extends T> ref)
+ {
synchronized (lock)
{
if (ref.queue != this)
@@ -113,14 +113,14 @@ public class ReferenceQueue
* Remove a reference from the queue, if there is one.
* @return the first element of the queue, or null if there isn't any.
*/
- private Reference dequeue()
+ private Reference<? extends T> dequeue()
{
synchronized (lock)
{
if (first == null)
return null;
-
- Reference result = first;
+
+ Reference<? extends T> result = first;
first = (first == first.nextOnQueue) ? null : first.nextOnQueue;
result.nextOnQueue = null;
return result;
@@ -136,7 +136,7 @@ public class ReferenceQueue
* <code>null</code> if timeout period expired.
* @exception InterruptedException if the wait was interrupted.
*/
- public Reference remove(long timeout)
+ public Reference<? extends T> remove(long timeout)
throws InterruptedException
{
synchronized (lock)
@@ -156,7 +156,7 @@ public class ReferenceQueue
* @return the reference removed from the queue.
* @exception InterruptedException if the wait was interrupted.
*/
- public Reference remove()
+ public Reference<? extends T> remove()
throws InterruptedException
{
return remove(0L);
diff --git a/java/lang/ref/SoftReference.java b/java/lang/ref/SoftReference.java
index 97395eacd..077dc173d 100644
--- a/java/lang/ref/SoftReference.java
+++ b/java/lang/ref/SoftReference.java
@@ -1,5 +1,5 @@
/* java.lang.ref.SoftReference
- Copyright (C) 1999 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -47,14 +47,14 @@ package java.lang.ref;
*
* @author Jochen Hoenicke
*/
-public class SoftReference
- extends Reference
+public class SoftReference<T>
+ extends Reference<T>
{
/**
* Create a new soft reference, that is not registered to any queue.
* @param referent the object we refer to.
*/
- public SoftReference(Object referent)
+ public SoftReference(T referent)
{
super(referent);
}
@@ -65,7 +65,7 @@ public class SoftReference
* @param q the reference queue to register on.
* @exception NullPointerException if q is null.
*/
- public SoftReference(Object referent, ReferenceQueue q)
+ public SoftReference(T referent, ReferenceQueue<? super T> q)
{
super(referent, q);
}
@@ -75,7 +75,7 @@ public class SoftReference
* @return the object, this reference refers to, or null if the
* reference was cleared.
*/
- public Object get()
+ public T get()
{
/* Why is this overloaded???
* Maybe for a kind of LRU strategy. */
diff --git a/java/lang/ref/WeakReference.java b/java/lang/ref/WeakReference.java
index b4018fbb5..563563bf1 100644
--- a/java/lang/ref/WeakReference.java
+++ b/java/lang/ref/WeakReference.java
@@ -1,5 +1,5 @@
/* java.lang.ref.WeakReference
- Copyright (C) 1999 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -54,14 +54,14 @@ package java.lang.ref;
* @author Jochen Hoenicke
* @see java.util.WeakHashMap
*/
-public class WeakReference
- extends Reference
+public class WeakReference<T>
+ extends Reference<T>
{
/**
* Create a new weak reference, that is not registered to any queue.
* @param referent the object we refer to.
*/
- public WeakReference(Object referent)
+ public WeakReference(T referent)
{
super(referent);
}
@@ -72,7 +72,7 @@ public class WeakReference
* @param q the reference queue to register on.
* @exception NullPointerException if q is null.
*/
- public WeakReference(Object referent, ReferenceQueue q)
+ public WeakReference(T referent, ReferenceQueue<? super T> q)
{
super(referent, q);
}
diff --git a/java/lang/reflect/AccessibleObject.java b/java/lang/reflect/AccessibleObject.java
index 8f09eac1b..fd46a53dc 100644
--- a/java/lang/reflect/AccessibleObject.java
+++ b/java/lang/reflect/AccessibleObject.java
@@ -160,8 +160,7 @@ public class AccessibleObject
this.flag = flag;
}
- /* FIXME[GENERICS]: <T extends Annotation> T getAnnotation(Class <T>) */
- public Annotation getAnnotation(Class annotationClass)
+ public <T extends Annotation> T getAnnotation(Class<T> annotationClass)
{
throw new AssertionError("Subclass must override this method");
}
@@ -176,8 +175,7 @@ public class AccessibleObject
throw new AssertionError("Subclass must override this method");
}
- /* FIXME[GENERICS]: Signature is Class<? extends Annotation> */
- public boolean isAnnotationPresent(Class annotationClass)
+ public boolean isAnnotationPresent(Class<? extends Annotation> annotationClass)
{
return getAnnotation(annotationClass) != null;
}
diff --git a/java/lang/reflect/AnnotatedElement.java b/java/lang/reflect/AnnotatedElement.java
index 69a64a028..8f2a8b6f5 100644
--- a/java/lang/reflect/AnnotatedElement.java
+++ b/java/lang/reflect/AnnotatedElement.java
@@ -74,8 +74,7 @@ public interface AnnotatedElement
* <code>null</code> if no such annotation exists.
* @throws NullPointerException if the annotation class is <code>null</code>.
*/
- /* FIXME[GENERICS]: <T extends Annotation> T getAnnotation(Class <T>) */
- Annotation getAnnotation(Class annotationClass);
+ <T extends Annotation> T getAnnotation(Class<T> annotationClass);
/**
* Returns all annotations associated with the element. If there are
@@ -111,7 +110,6 @@ public interface AnnotatedElement
* @return true if an annotation exists for the specified type.
* @since 1.5
*/
- /* FIXME[GENERICS]: Signature is Class<? extends Annotation> */
- boolean isAnnotationPresent(Class annotationClass);
+ boolean isAnnotationPresent(Class<? extends Annotation> annotationClass);
}
diff --git a/java/lang/reflect/Array.java b/java/lang/reflect/Array.java
index ae65ffbf2..373bf204c 100644
--- a/java/lang/reflect/Array.java
+++ b/java/lang/reflect/Array.java
@@ -95,7 +95,7 @@ public final class Array
* @throws NegativeArraySizeException when length is less than 0
* @throws OutOfMemoryError if memory allocation fails
*/
- public static Object newInstance(Class componentType, int length)
+ public static Object newInstance(Class<?> componentType, int length)
{
if (! componentType.isPrimitive())
return VMArray.createObjectArray(componentType, length);
@@ -143,7 +143,7 @@ public final class Array
* than 0
* @throws OutOfMemoryError if memory allocation fails
*/
- public static Object newInstance(Class componentType, int[] dimensions)
+ public static Object newInstance(Class<?> componentType, int[] dimensions)
{
if (dimensions.length <= 0)
throw new IllegalArgumentException ("Empty dimensions array.");
diff --git a/java/lang/reflect/GenericDeclaration.java b/java/lang/reflect/GenericDeclaration.java
index 14f5ba832..244befd88 100644
--- a/java/lang/reflect/GenericDeclaration.java
+++ b/java/lang/reflect/GenericDeclaration.java
@@ -58,6 +58,5 @@ public interface GenericDeclaration
* class file does not conform to that specified in the 3rd edition
* of the Java Virtual Machine Specification.
*/
- /* FIXME[GENERICS]: Should be TypeVariable<?>[] */
- TypeVariable[] getTypeParameters();
+ TypeVariable<?>[] getTypeParameters();
}
diff --git a/java/lang/reflect/Proxy.java b/java/lang/reflect/Proxy.java
index 94aa0bbb2..ef743f6bc 100644
--- a/java/lang/reflect/Proxy.java
+++ b/java/lang/reflect/Proxy.java
@@ -156,7 +156,7 @@ import java.util.Set;
* @see Class
* @author Eric Blake (ebb9@email.byu.edu)
* @since 1.3
- * @status updated to 1.4, except for the use of ProtectionDomain
+ * @status updated to 1.5, except for the use of ProtectionDomain
*/
public class Proxy implements Serializable
{
@@ -255,8 +255,8 @@ public class Proxy implements Serializable
*/
// synchronized so that we aren't trying to build the same class
// simultaneously in two threads
- public static synchronized Class getProxyClass(ClassLoader loader,
- Class[] interfaces)
+ public static synchronized Class<?> getProxyClass(ClassLoader loader,
+ Class<?>... interfaces)
{
interfaces = (Class[]) interfaces.clone();
ProxyType pt = new ProxyType(loader, interfaces);
@@ -310,7 +310,7 @@ public class Proxy implements Serializable
* @see Constructor#newInstance(Object[])
*/
public static Object newProxyInstance(ClassLoader loader,
- Class[] interfaces,
+ Class<?>[] interfaces,
InvocationHandler handler)
{
try
@@ -358,7 +358,7 @@ public class Proxy implements Serializable
*/
// This is synchronized on the off chance that another thread is
// trying to add a class to the map at the same time we read it.
- public static synchronized boolean isProxyClass(Class clazz)
+ public static synchronized boolean isProxyClass(Class<?> clazz)
{
if (! Proxy.class.isAssignableFrom(clazz))
return false;
diff --git a/java/lang/reflect/TypeVariable.java b/java/lang/reflect/TypeVariable.java
index 4ecc20c9d..ec6af69db 100644
--- a/java/lang/reflect/TypeVariable.java
+++ b/java/lang/reflect/TypeVariable.java
@@ -58,9 +58,7 @@ package java.lang.reflect;
* @author Andrew John Hughes (gnu_andrew@member.fsf.org)
* @since 1.5
*/
-/* FIXME[GENERICS]: Should be TypeVariable<T extends GenericDeclaration> */
-public interface TypeVariable
- extends Type
+public interface TypeVariable<T extends GenericDeclaration> extends Type
{
/**
@@ -86,8 +84,7 @@ public interface TypeVariable
* @return the <code>GenericDeclaration</code> object for this type
* variable.
*/
- /* FIXME[GENERICS]: Should return type T */
- GenericDeclaration getGenericDeclaration();
+ T getGenericDeclaration();
/**
* Returns the name of the type variable, as written in the source
diff --git a/java/math/BigDecimal.java b/java/math/BigDecimal.java
index bca9b12c2..28c4d45d3 100644
--- a/java/math/BigDecimal.java
+++ b/java/math/BigDecimal.java
@@ -37,7 +37,7 @@ exception statement from your version. */
package java.math;
-public class BigDecimal extends Number implements Comparable
+public class BigDecimal extends Number implements Comparable<BigDecimal>
{
private BigInteger intVal;
private int scale;
@@ -672,7 +672,38 @@ public class BigDecimal extends Number implements Comparable
{
return divide (val, scale, roundingMode);
}
-
+
+ /**
+ * Returns a BigDecimal whose value is (this / val), with the specified scale
+ * and rounding according to the RoundingMode
+ * @param val the divisor
+ * @param scale the scale of the BigDecimal returned
+ * @param roundingMode the rounding mode to use
+ * @return a BigDecimal whose value is approximately (this / val)
+ * @throws ArithmeticException if divisor is zero or the rounding mode is
+ * UNNECESSARY but the specified scale cannot represent the value exactly
+ * @since 1.5
+ */
+ public BigDecimal divide(BigDecimal val,
+ int scale, RoundingMode roundingMode)
+ {
+ return divide (val, scale, roundingMode.ordinal());
+ }
+
+ /**
+ * Returns a BigDecimal whose value is (this / val) rounded according to the
+ * RoundingMode
+ * @param val the divisor
+ * @param roundingMode the rounding mode to use
+ * @return a BigDecimal whose value is approximately (this / val)
+ * @throws ArithmeticException if divisor is zero or the rounding mode is
+ * UNNECESSARY but the specified scale cannot represent the value exactly
+ */
+ public BigDecimal divide (BigDecimal val, RoundingMode roundingMode)
+ {
+ return divide (val, scale, roundingMode.ordinal());
+ }
+
public BigDecimal divide(BigDecimal val, int newScale, int roundingMode)
throws ArithmeticException, IllegalArgumentException
{
@@ -823,12 +854,7 @@ public class BigDecimal extends Number implements Comparable
return this;
}
- public int compareTo (Object obj)
- {
- return compareTo((BigDecimal) obj);
- }
-
- public int compareTo (BigDecimal val)
+ public int compareTo (BigDecimal val)
{
if (scale == val.scale)
return intVal.compareTo (val.intVal);
@@ -973,7 +999,7 @@ public class BigDecimal extends Number implements Comparable
{
return round(mc);
}
-
+
/**
* Returns a BigDecimal which is this BigDecimal rounded according to the
* MathContext rounding settings.
@@ -993,12 +1019,12 @@ public class BigDecimal extends Number implements Comparable
// Make a new BigDecimal which is the correct power of 10 to chop off
// the required number of digits and then call divide.
BigDecimal div = new BigDecimal(BigInteger.TEN.pow(numToChop));
- BigDecimal rounded = divide(div, scale, 4);
+ BigDecimal rounded = divide(div, scale, mc.getRoundingMode().ordinal());
rounded.scale -= numToChop;
rounded.precision = mcPrecision;
return rounded;
}
-
+
/**
* Returns the precision of this BigDecimal (the number of digits in the
* unscaled value). The precision of a zero value is 1.
@@ -1350,7 +1376,24 @@ public class BigDecimal extends Number implements Comparable
if( scale < 0 ) throw new ArithmeticException("Scale parameter < 0.");
return divide (ONE, scale, roundingMode);
}
-
+
+ /**
+ * Returns a BigDecimal whose value is the same as this BigDecimal but whose
+ * representation has a scale of <code>newScale</code>. If the scale is
+ * reduced then rounding may occur, according to the RoundingMode.
+ * @param newScale
+ * @param roundingMode
+ * @return a BigDecimal whose scale is as given, whose value is
+ * <code>this</code> with possible rounding
+ * @throws ArithmeticException if the rounding mode is UNNECESSARY but
+ * rounding is required
+ * @since 1.5
+ */
+ public BigDecimal setScale(int newScale, RoundingMode roundingMode)
+ {
+ return setScale(newScale, roundingMode.ordinal());
+ }
+
/**
* Returns a new BigDecimal constructed from the BigDecimal(String)
* constructor using the Double.toString(double) method to obtain
diff --git a/java/math/BigInteger.java b/java/math/BigInteger.java
index 3715cbbba..c897d8bf4 100644
--- a/java/math/BigInteger.java
+++ b/java/math/BigInteger.java
@@ -57,7 +57,7 @@ import java.util.Random;
* @date December 20, 1999.
* @status believed complete and correct.
*/
-public class BigInteger extends Number implements Comparable
+public class BigInteger extends Number implements Comparable<BigInteger>
{
/** All integers are stored in 2's-complement form.
* If words == null, the ival is the value of this BigInteger.
@@ -83,7 +83,8 @@ public class BigInteger extends Number implements Comparable
private static final int numFixNum = maxFixNum-minFixNum+1;
private static final BigInteger[] smallFixNums = new BigInteger[numFixNum];
- static {
+ static
+ {
for (int i = numFixNum; --i >= 0; )
smallFixNums[i] = new BigInteger(i + minFixNum);
}
@@ -92,14 +93,14 @@ public class BigInteger extends Number implements Comparable
* The constant zero as a BigInteger.
* @since 1.2
*/
- public static final BigInteger ZERO = smallFixNums[-minFixNum];
+ public static final BigInteger ZERO = smallFixNums[0 - minFixNum];
/**
* The constant one as a BigInteger.
* @since 1.2
*/
public static final BigInteger ONE = smallFixNums[1 - minFixNum];
-
+
/**
* The constant ten as a BigInteger.
* @since 1.5
@@ -394,14 +395,7 @@ public class BigInteger extends Number implements Comparable
return MPN.cmp(x.words, y.words, x_len);
}
- // JDK1.2
- public int compareTo(Object obj)
- {
- if (obj instanceof BigInteger)
- return compareTo(this, (BigInteger) obj);
- throw new ClassCastException();
- }
-
+ /** @since 1.2 */
public int compareTo(BigInteger val)
{
return compareTo(this, val);
diff --git a/java/math/MathContext.java b/java/math/MathContext.java
index 417d9c2e2..533ab13ac 100644
--- a/java/math/MathContext.java
+++ b/java/math/MathContext.java
@@ -48,6 +48,30 @@ import java.io.Serializable;
*/
public final class MathContext implements Serializable
{
+ /** A MathContext for unlimited precision arithmetic * */
+ public static final MathContext UNLIMITED =
+ new MathContext(0, RoundingMode.HALF_UP);
+
+ /**
+ * A MathContext for the IEEE 754R Decimal32 format - 7 digit preicision and
+ * HALF_EVEN rounding.
+ */
+ public static final MathContext DECIMAL32 =
+ new MathContext(7, RoundingMode.HALF_EVEN);
+
+ /**
+ * A MathContext for the IEEE 754R Decimal64 format - 16 digit preicision and
+ * HALF_EVEN rounding.
+ */
+ public static final MathContext DECIMAL64 =
+ new MathContext(16, RoundingMode.HALF_EVEN);
+
+ /**
+ * A MathContext for the IEEE 754R Decimal128 format - 34 digit preicision and
+ * HALF_EVEN rounding.
+ */
+ public static final MathContext DECIMAL128 =
+ new MathContext(34, RoundingMode.HALF_EVEN);
/**
* This is the serialVersionUID reported here:
@@ -56,7 +80,9 @@ public final class MathContext implements Serializable
private static final long serialVersionUID = 5579720004786848255L;
private int precision;
-
+
+ private RoundingMode roundMode;
+
/**
* Constructs a new MathContext with the specified precision and with HALF_UP
* rounding.
@@ -66,11 +92,25 @@ public final class MathContext implements Serializable
*/
public MathContext(int setPrecision)
{
+ this(setPrecision, RoundingMode.HALF_UP);
+ }
+
+ /**
+ * Constructs a new MathContext with the specified precision and rounding
+ * mode.
+ * @param setPrecision the precision
+ * @param setRoundingMode the rounding mode
+ *
+ * @throws IllegalArgumentException if precision is < 0.
+ */
+ public MathContext(int setPrecision, RoundingMode setRoundingMode)
+ {
if (setPrecision < 0)
throw new IllegalArgumentException("Precision cannot be less than zero.");
precision = setPrecision;
+ roundMode = setRoundingMode;
}
-
+
/**
* Constructs a MathContext from a String that has the same form as one
* produced by the toString() method.
@@ -85,6 +125,7 @@ public final class MathContext implements Serializable
{
int roundingModeIndex = val.indexOf("roundingMode", 10);
precision = Integer.parseInt(val.substring(10, roundingModeIndex - 1));
+ roundMode = RoundingMode.valueOf(val.substring(roundingModeIndex + 13));
}
catch (NumberFormatException nfe)
{
@@ -109,7 +150,8 @@ public final class MathContext implements Serializable
if (!(x instanceof MathContext))
return false;
MathContext mc = (MathContext)x;
- return mc.precision == this.precision;
+ return mc.precision == this.precision
+ && mc.roundMode.equals(this.roundMode);
}
/**
@@ -122,6 +164,18 @@ public final class MathContext implements Serializable
}
/**
+ * Returns the rounding mode setting. This will be one of
+ * RoundingMode.CEILING, RoundingMode.DOWN, RoundingMode.FLOOR,
+ * RoundingMode.HALF_DOWN, RoundingMode.HALF_EVEN, RoundingMode.HALF_UP,
+ * RoundingMode.UNNECESSARY, or RoundingMode.UP.
+ * @return the rounding mode setting.
+ */
+ public RoundingMode getRoundingMode()
+ {
+ return roundMode;
+ }
+
+ /**
* Returns "precision=p roundingMode=MODE" where p is an int giving the
* precision and MODE is UP, DOWN, HALF_UP, HALF_DOWN, HALF_EVEN, CEILING,
* FLOOR, or UNNECESSARY corresponding to rounding modes.
@@ -130,7 +184,7 @@ public final class MathContext implements Serializable
*/
public String toString()
{
- return "precision="+precision;
+ return "precision="+precision+" roundingMode="+roundMode;
}
/**
@@ -139,6 +193,6 @@ public final class MathContext implements Serializable
*/
public int hashCode()
{
- return precision;
+ return precision ^ roundMode.hashCode();
}
}
diff --git a/java/math/RoundingMode.java b/java/math/RoundingMode.java
new file mode 100644
index 000000000..c85bf4ff5
--- /dev/null
+++ b/java/math/RoundingMode.java
@@ -0,0 +1,89 @@
+/* RoundingMode.java -- An Enum to replace BigDecimal rounding constants.
+ Copyright (C) 1999, 2000, 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.math;
+
+/**
+ * An enum to specify rounding behaviour for numerical operations that may
+ * discard precision.
+ * @author Anthony Balkissoon abalkiss at redhat dot com
+ *
+ */
+public enum RoundingMode
+{
+ UP, DOWN, CEILING, FLOOR, HALF_UP, HALF_DOWN, HALF_EVEN, UNNECESSARY;
+
+ /**
+ * For compatability with Sun's JDK
+ */
+ private static final long serialVersionUID = 432302042773881265L;
+
+ /**
+ * Returns the RoundingMode object corresponding to the legacy rounding modes
+ * in BigDecimal.
+ * @param rm the legacy rounding mode
+ * @return the corresponding RoundingMode
+ */
+ public static RoundingMode valueOf(int rm)
+ {
+ switch (rm)
+ {
+ case BigDecimal.ROUND_CEILING:
+ return CEILING;
+ case BigDecimal.ROUND_FLOOR:
+ return FLOOR;
+ case BigDecimal.ROUND_DOWN:
+ return DOWN;
+ case BigDecimal.ROUND_UP:
+ return UP;
+ case BigDecimal.ROUND_HALF_UP:
+ return HALF_UP;
+ case BigDecimal.ROUND_HALF_DOWN:
+ return HALF_DOWN;
+ case BigDecimal.ROUND_HALF_EVEN:
+ return HALF_EVEN;
+ case BigDecimal.ROUND_UNNECESSARY:
+ return UNNECESSARY;
+ default:
+ throw new
+ IllegalArgumentException("invalid argument: " + rm +
+ ". Argument should be one of the " +
+ "rounding modes defined in BigDecimal.");
+ }
+ }
+}
diff --git a/java/net/NetworkInterface.java b/java/net/NetworkInterface.java
index 1b52cf3cb..6c78ead5b 100644
--- a/java/net/NetworkInterface.java
+++ b/java/net/NetworkInterface.java
@@ -61,11 +61,11 @@ import java.util.Vector;
public final class NetworkInterface
{
private final VMNetworkInterface netif;
-
+
private NetworkInterface(VMNetworkInterface netif)
- {
+ {
this.netif = netif;
- }
+ }
/** Creates an NetworkInterface instance which
* represents any interface in the system. Its only
@@ -97,7 +97,7 @@ public final class NetworkInterface
*
* @return An enumeration of all addresses.
*/
- public Enumeration getInetAddresses()
+ public Enumeration<InetAddress> getInetAddresses()
{
SecurityManager s = System.getSecurityManager();
Vector inetAddresses = new Vector(netif.addresses);
@@ -105,12 +105,12 @@ public final class NetworkInterface
if (s == null)
return inetAddresses.elements();
- Vector tmpInetAddresses = new Vector(1, 1);
+ Vector<InetAddress> tmpInetAddresses = new Vector<InetAddress>(1, 1);
- for (Enumeration addresses = inetAddresses.elements();
+ for (Enumeration<InetAddress> addresses = inetAddresses.elements();
addresses.hasMoreElements();)
{
- InetAddress addr = (InetAddress) addresses.nextElement();
+ InetAddress addr = addresses.nextElement();
try
{
s.checkConnect(addr.getHostAddress(), -1);
@@ -191,10 +191,12 @@ public final class NetworkInterface
*
* @exception SocketException If an error occurs
*/
- public static Enumeration getNetworkInterfaces() throws SocketException
+ public static Enumeration<NetworkInterface> getNetworkInterfaces()
+ throws SocketException
{
VMNetworkInterface[] netifs = VMNetworkInterface.getVMInterfaces();
- Vector networkInterfaces = new Vector(netifs.length);
+ Vector<NetworkInterface> networkInterfaces =
+ new Vector<NetworkInterface>(netifs.length);
for (int i = 0; i < netifs.length; i++)
{
if (!netifs[i].addresses.isEmpty())
diff --git a/java/net/Proxy.java b/java/net/Proxy.java
new file mode 100644
index 000000000..7b4ef2992
--- /dev/null
+++ b/java/net/Proxy.java
@@ -0,0 +1,137 @@
+/* Proxy.java -- Represends a proxy for a network connection
+ Copyright (C) 2006 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.net;
+
+
+/**
+ * Defines a proxy setting. This setting contains a type (https, socks,
+ * direct) and a socket address.
+ *
+ * @since 1.5
+ */
+public class Proxy
+{
+ /**
+ * Represents the proxy type.
+ */
+ public enum Type
+ {
+ DIRECT, HTTP, SOCKS;
+
+ /**
+ * For compatability with Sun's JDK
+ */
+ private static final long serialVersionUID = -2231209257930100533L;
+ };
+
+ public static final Proxy NO_PROXY = new Proxy(Type.DIRECT, null);
+
+ private Type type;
+ private SocketAddress address;
+
+ /**
+ * Creates a new <code>Proxy</code> object.
+ *
+ * @param type The type for this proxy
+ * @param address The address of this proxy
+ */
+ public Proxy(Type type, SocketAddress address)
+ {
+ this.type = type;
+ this.address = address;
+ }
+
+ /**
+ * Returns the socket address for this proxy object.
+ *
+ * @return the socket address
+ */
+ public SocketAddress address()
+ {
+ return address;
+ }
+
+ /**
+ * Returns the of this proxy instance.
+ *
+ * @return the type
+ *
+ * @see Type
+ */
+ public Type type()
+ {
+ return type;
+ }
+
+ /**
+ * Compares the given object with this object.
+ *
+ * @return <code>true</code> if both objects or equals,
+ * <code>false</code> otherwise.
+ */
+ public final boolean equals(Object obj)
+ {
+ if (! (obj instanceof Proxy))
+ return false;
+
+ Proxy tmp = (Proxy) obj;
+
+ return (type.equals(tmp.type)
+ && address.equals(tmp.address));
+ }
+
+ /**
+ * Returns the hashcode for this <code>Proxy</code> object.
+ *
+ * @return the hashcode
+ */
+ public final int hashCode()
+ {
+ return type.hashCode() ^ address.hashCode();
+ }
+
+ /**
+ * Returns a string representation of this <code>Proxy</code> object.
+ *
+ * @return the string
+ */
+ public String toString()
+ {
+ return type.toString() + ":" + address.toString();
+ }
+}
diff --git a/java/net/ProxySelector.java b/java/net/ProxySelector.java
new file mode 100644
index 000000000..78592a244
--- /dev/null
+++ b/java/net/ProxySelector.java
@@ -0,0 +1,117 @@
+/* ProxySelector.java -- A proxy selector class
+ Copyright (C) 2006 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.net;
+
+import gnu.java.net.DefaultProxySelector;
+
+import java.io.IOException;
+import java.util.List;
+
+/**
+ * Class for handling proxies for different connections.
+ *
+ * @since 1.5
+ */
+public abstract class ProxySelector
+{
+ /**
+ * Default proxy selector.
+ */
+ private static ProxySelector defaultSelector = new DefaultProxySelector();
+
+ /**
+ * Creates a new <code>ProxySelector</code> object.
+ */
+ public ProxySelector()
+ {
+ // Do nothing here.
+ }
+
+ /**
+ * Returns the default proxy selector.
+ *
+ * @return the default proxy selector
+ *
+ * @throws SecurityException If a security manager is installed and it
+ * denies NetPermission("getProxySelector")
+ */
+ public static ProxySelector getDefault()
+ {
+ SecurityManager sm = System.getSecurityManager();
+
+ if (sm != null)
+ sm.checkPermission(new NetPermission("getProxySelector"));
+
+ return defaultSelector;
+ }
+
+ /**
+ * Sets the default proxy selector.
+ *
+ * @param selector the defualt proxy selector
+ *
+ * @throws SecurityException If a security manager is installed and it
+ * denies NetPermission("setProxySelector")
+ */
+ public static void setDefault(ProxySelector selector)
+ {
+ SecurityManager sm = System.getSecurityManager();
+
+ if (sm != null)
+ sm.checkPermission(new NetPermission("setProxySelector"));
+
+ defaultSelector = selector;
+ }
+
+ /**
+ * Signals to the selector that a proxy was no available.
+ *
+ * @throws IllegalArgumentException If one argument is null
+ */
+ public abstract void connectFailed(URI uri, SocketAddress address,
+ IOException exception);
+
+ /**
+ * Returns the list of proxy settings for a given URI.
+ *
+ * @return list of proxy settings
+ *
+ * @throws IllegalArgumentException If uri is null
+ */
+ public abstract List<Proxy> select(URI uri);
+}
diff --git a/java/net/URI.java b/java/net/URI.java
index 401352fcf..689843c0b 100644
--- a/java/net/URI.java
+++ b/java/net/URI.java
@@ -156,7 +156,7 @@ import java.util.regex.Pattern;
* @since 1.4
*/
public final class URI
- implements Comparable, Serializable
+ implements Comparable<URI>, Serializable
{
/**
* For serialization compatability.
@@ -1229,7 +1229,7 @@ public final class URI
}
/**
- * Compare the URI with another object that must also be a URI.
+ * Compare the URI with another URI.
* Undefined components are taken to be less than any other component.
* The following criteria are observed:
* </p>
@@ -1265,16 +1265,14 @@ public final class URI
* </ul>
* </ul>
*
- * @param obj This object to compare this URI with
+ * @param uri The other URI to compare this URI with
* @return a negative integer, zero or a positive integer depending
* on whether this URI is less than, equal to or greater
* than that supplied, respectively.
- * @throws ClassCastException if the given object is not a URI
*/
- public int compareTo(Object obj)
+ public int compareTo(URI uri)
throws ClassCastException
{
- URI uri = (URI) obj;
if (scheme == null && uri.getScheme() != null)
return -1;
if (scheme != null)
diff --git a/java/net/URLClassLoader.java b/java/net/URLClassLoader.java
index 403f7485c..7e2353ac2 100644
--- a/java/net/URLClassLoader.java
+++ b/java/net/URLClassLoader.java
@@ -508,7 +508,7 @@ public class URLClassLoader extends SecureClassLoader
* loaded
* @return a Class object representing the found class
*/
- protected Class findClass(final String className)
+ protected Class<?> findClass(final String className)
throws ClassNotFoundException
{
// Just try to find the resource by the (almost) same name
@@ -714,10 +714,10 @@ public class URLClassLoader extends SecureClassLoader
* @exception IOException when an error occurs accessing one of the
* locations
*/
- public Enumeration findResources(String resourceName)
+ public Enumeration<URL> findResources(String resourceName)
throws IOException
{
- Vector resources = new Vector();
+ Vector<URL> resources = new Vector<URL>();
int max = urlinfos.size();
for (int i = 0; i < max; i++)
{
diff --git a/java/net/URLConnection.java b/java/net/URLConnection.java
index 468838db7..674058014 100644
--- a/java/net/URLConnection.java
+++ b/java/net/URLConnection.java
@@ -49,6 +49,7 @@ import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Collections;
import java.util.Date;
+import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.StringTokenizer;
@@ -402,10 +403,10 @@ public abstract class URLConnection
*
* @since 1.4
*/
- public Map getHeaderFields()
+ public Map<String,List<String>> getHeaderFields()
{
// Subclasses for specific protocols override this.
- return Collections.EMPTY_MAP;
+ return Collections.emptyMap();
}
/**
@@ -905,14 +906,14 @@ public abstract class URLConnection
*
* @since 1.4
*/
- public Map getRequestProperties()
+ public Map<String,List<String>> getRequestProperties()
{
if (connected)
throw new IllegalStateException("Already connected");
// Overridden by subclasses that support reading header fields from the
// request.
- return Collections.EMPTY_MAP;
+ return Collections.emptyMap();
}
/**
diff --git a/java/nio/ByteBuffer.java b/java/nio/ByteBuffer.java
index 0ccf7663c..78ad44718 100644
--- a/java/nio/ByteBuffer.java
+++ b/java/nio/ByteBuffer.java
@@ -1,5 +1,5 @@
/* ByteBuffer.java --
- Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -42,7 +42,7 @@ package java.nio;
* @since 1.4
*/
public abstract class ByteBuffer extends Buffer
- implements Comparable
+ implements Comparable<ByteBuffer>
{
ByteOrder endian = ByteOrder.BIG_ENDIAN;
@@ -290,7 +290,7 @@ public abstract class ByteBuffer extends Buffer
{
if (obj instanceof ByteBuffer)
{
- return compareTo (obj) == 0;
+ return compareTo ((ByteBuffer) obj) == 0;
}
return false;
@@ -302,10 +302,8 @@ public abstract class ByteBuffer extends Buffer
* @exception ClassCastException If obj is not an object derived from
* <code>ByteBuffer</code>.
*/
- public int compareTo (Object obj)
+ public int compareTo (ByteBuffer other)
{
- ByteBuffer other = (ByteBuffer) obj;
-
int num = Math.min(remaining(), other.remaining());
int pos_this = position();
int pos_other = other.position();
diff --git a/java/nio/CharBuffer.java b/java/nio/CharBuffer.java
index 356a920ee..34f429f62 100644
--- a/java/nio/CharBuffer.java
+++ b/java/nio/CharBuffer.java
@@ -1,5 +1,5 @@
/* CharBuffer.java --
- Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -38,11 +38,13 @@ exception statement from your version. */
package java.nio;
+import java.io.IOException;
+
/**
* @since 1.4
*/
public abstract class CharBuffer extends Buffer
- implements Comparable, CharSequence
+ implements Comparable<CharBuffer>, CharSequence, Readable, Appendable
{
int array_offset;
char[] backing_buffer;
@@ -163,6 +165,18 @@ public abstract class CharBuffer extends Buffer
return this;
}
+ /** @since 1.5 */
+ public int read(CharBuffer buffer) throws IOException
+ {
+ // We want to call put(), so we don't manipulate the CharBuffer
+ // directly.
+ int rem = Math.min(buffer.remaining(), remaining());
+ char[] buf = new char[rem];
+ get(buf);
+ buffer.put(buf);
+ return rem;
+ }
+
/**
* This method transfers <code>char</code>s from this buffer into the given
* destination array.
@@ -323,7 +337,7 @@ public abstract class CharBuffer extends Buffer
{
if (obj instanceof CharBuffer)
{
- return compareTo (obj) == 0;
+ return compareTo ((CharBuffer) obj) == 0;
}
return false;
@@ -335,10 +349,8 @@ public abstract class CharBuffer extends Buffer
* @exception ClassCastException If obj is not an object derived from
* <code>CharBuffer</code>.
*/
- public int compareTo (Object obj)
+ public int compareTo (CharBuffer other)
{
- CharBuffer other = (CharBuffer) obj;
-
int num = Math.min(remaining(), other.remaining());
int pos_this = position();
int pos_other = other.position();
@@ -503,4 +515,25 @@ public abstract class CharBuffer extends Buffer
return get (position () + index);
}
+
+ /** @since 1.5 */
+ public CharBuffer append(char c)
+ {
+ put(c);
+ return this;
+ }
+
+ /** @since 1.5 */
+ public CharBuffer append(CharSequence cs)
+ {
+ put(cs == null ? "null" : cs.toString());
+ return this;
+ }
+
+ /** @since 1.5 */
+ public CharBuffer append(CharSequence cs, int start, int end)
+ {
+ put(cs == null ? "null" : cs.subSequence(start, end).toString());
+ return this;
+ }
}
diff --git a/java/nio/DoubleBuffer.java b/java/nio/DoubleBuffer.java
index 381bb7166..be7861cbd 100644
--- a/java/nio/DoubleBuffer.java
+++ b/java/nio/DoubleBuffer.java
@@ -1,5 +1,5 @@
/* DoubleBuffer.java --
- Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -42,7 +42,7 @@ package java.nio;
* @since 1.4
*/
public abstract class DoubleBuffer extends Buffer
- implements Comparable
+ implements Comparable<DoubleBuffer>
{
int array_offset;
double[] backing_buffer;
@@ -273,7 +273,7 @@ public abstract class DoubleBuffer extends Buffer
{
if (obj instanceof DoubleBuffer)
{
- return compareTo (obj) == 0;
+ return compareTo ((DoubleBuffer) obj) == 0;
}
return false;
@@ -285,10 +285,8 @@ public abstract class DoubleBuffer extends Buffer
* @exception ClassCastException If obj is not an object derived from
* <code>DoubleBuffer</code>.
*/
- public int compareTo (Object obj)
+ public int compareTo (DoubleBuffer other)
{
- DoubleBuffer other = (DoubleBuffer) obj;
-
int num = Math.min(remaining(), other.remaining());
int pos_this = position();
int pos_other = other.position();
diff --git a/java/nio/FloatBuffer.java b/java/nio/FloatBuffer.java
index 8042333cb..62e353a68 100644
--- a/java/nio/FloatBuffer.java
+++ b/java/nio/FloatBuffer.java
@@ -1,5 +1,5 @@
/* FloatBuffer.java --
- Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -42,7 +42,7 @@ package java.nio;
* @since 1.4
*/
public abstract class FloatBuffer extends Buffer
- implements Comparable
+ implements Comparable<FloatBuffer>
{
int array_offset;
float[] backing_buffer;
@@ -273,7 +273,7 @@ public abstract class FloatBuffer extends Buffer
{
if (obj instanceof FloatBuffer)
{
- return compareTo (obj) == 0;
+ return compareTo ((FloatBuffer) obj) == 0;
}
return false;
@@ -285,10 +285,8 @@ public abstract class FloatBuffer extends Buffer
* @exception ClassCastException If obj is not an object derived from
* <code>FloatBuffer</code>.
*/
- public int compareTo (Object obj)
+ public int compareTo (FloatBuffer other)
{
- FloatBuffer other = (FloatBuffer) obj;
-
int num = Math.min(remaining(), other.remaining());
int pos_this = position();
int pos_other = other.position();
diff --git a/java/nio/IntBuffer.java b/java/nio/IntBuffer.java
index 1e1fe9c75..d6fcb51dd 100644
--- a/java/nio/IntBuffer.java
+++ b/java/nio/IntBuffer.java
@@ -1,5 +1,5 @@
/* IntBuffer.java --
- Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -42,7 +42,7 @@ package java.nio;
* @since 1.4
*/
public abstract class IntBuffer extends Buffer
- implements Comparable
+ implements Comparable<IntBuffer>
{
int array_offset;
int[] backing_buffer;
@@ -273,7 +273,7 @@ public abstract class IntBuffer extends Buffer
{
if (obj instanceof IntBuffer)
{
- return compareTo (obj) == 0;
+ return compareTo ((IntBuffer) obj) == 0;
}
return false;
@@ -285,10 +285,8 @@ public abstract class IntBuffer extends Buffer
* @exception ClassCastException If obj is not an object derived from
* <code>IntBuffer</code>.
*/
- public int compareTo (Object obj)
+ public int compareTo (IntBuffer other)
{
- IntBuffer other = (IntBuffer) obj;
-
int num = Math.min(remaining(), other.remaining());
int pos_this = position();
int pos_other = other.position();
diff --git a/java/nio/LongBuffer.java b/java/nio/LongBuffer.java
index b3d3557ed..9c3bfa627 100644
--- a/java/nio/LongBuffer.java
+++ b/java/nio/LongBuffer.java
@@ -1,5 +1,5 @@
/* LongBuffer.java --
- Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -42,7 +42,7 @@ package java.nio;
* @since 1.4
*/
public abstract class LongBuffer extends Buffer
- implements Comparable
+ implements Comparable<LongBuffer>
{
int array_offset;
long[] backing_buffer;
@@ -273,7 +273,7 @@ public abstract class LongBuffer extends Buffer
{
if (obj instanceof LongBuffer)
{
- return compareTo (obj) == 0;
+ return compareTo ((LongBuffer) obj) == 0;
}
return false;
@@ -285,10 +285,8 @@ public abstract class LongBuffer extends Buffer
* @exception ClassCastException If obj is not an object derived from
* <code>LongBuffer</code>.
*/
- public int compareTo (Object obj)
+ public int compareTo (LongBuffer other)
{
- LongBuffer other = (LongBuffer) obj;
-
int num = Math.min(remaining(), other.remaining());
int pos_this = position();
int pos_other = other.position();
diff --git a/java/nio/ShortBuffer.java b/java/nio/ShortBuffer.java
index 958fe8cd6..33e458a4b 100644
--- a/java/nio/ShortBuffer.java
+++ b/java/nio/ShortBuffer.java
@@ -1,5 +1,5 @@
/* ShortBuffer.java --
- Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -42,7 +42,7 @@ package java.nio;
* @since 1.4
*/
public abstract class ShortBuffer extends Buffer
- implements Comparable
+ implements Comparable<ShortBuffer>
{
int array_offset;
short[] backing_buffer;
@@ -273,7 +273,7 @@ public abstract class ShortBuffer extends Buffer
{
if (obj instanceof ShortBuffer)
{
- return compareTo (obj) == 0;
+ return compareTo ((ShortBuffer) obj) == 0;
}
return false;
@@ -285,10 +285,8 @@ public abstract class ShortBuffer extends Buffer
* @exception ClassCastException If obj is not an object derived from
* <code>ShortBuffer</code>.
*/
- public int compareTo (Object obj)
+ public int compareTo (ShortBuffer other)
{
- ShortBuffer other = (ShortBuffer) obj;
-
int num = Math.min(remaining(), other.remaining());
int pos_this = position();
int pos_other = other.position();
diff --git a/java/nio/channels/Channel.java b/java/nio/channels/Channel.java
index d488bd27d..33fcf3174 100644
--- a/java/nio/channels/Channel.java
+++ b/java/nio/channels/Channel.java
@@ -1,5 +1,5 @@
/* Channel.java --
- Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -39,8 +39,9 @@ exception statement from your version. */
package java.nio.channels;
import java.io.IOException;
+import java.io.Closeable;
-public interface Channel
+public interface Channel extends Closeable
{
/**
* Tells whether this channel is open or not
diff --git a/java/nio/channels/Selector.java b/java/nio/channels/Selector.java
index 2c883efd1..1c09db702 100644
--- a/java/nio/channels/Selector.java
+++ b/java/nio/channels/Selector.java
@@ -82,7 +82,7 @@ public abstract class Selector
*
* @exception ClosedSelectorException If this selector is closed.
*/
- public abstract Set keys();
+ public abstract Set<SelectionKey> keys();
/**
* Returns the SelectorProvider that created the selector.
@@ -115,7 +115,7 @@ public abstract class Selector
*
* @exception ClosedSelectorException If this selector is closed.
*/
- public abstract Set selectedKeys();
+ public abstract Set<SelectionKey> selectedKeys();
/**
* Selects a set of keys whose corresponding channels are ready
diff --git a/java/nio/channels/spi/AbstractSelector.java b/java/nio/channels/spi/AbstractSelector.java
index 78380738a..73f5077df 100644
--- a/java/nio/channels/spi/AbstractSelector.java
+++ b/java/nio/channels/spi/AbstractSelector.java
@@ -1,5 +1,5 @@
/* AbstractSelector.java --
- Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -49,7 +49,7 @@ public abstract class AbstractSelector extends Selector
{
private boolean closed;
private SelectorProvider provider;
- private HashSet cancelledKeys;
+ private HashSet<SelectionKey> cancelledKeys;
/**
* Initializes the slector.
@@ -59,7 +59,7 @@ public abstract class AbstractSelector extends Selector
protected AbstractSelector(SelectorProvider provider)
{
this.provider = provider;
- this.cancelledKeys = new HashSet();
+ this.cancelledKeys = new HashSet<SelectionKey>();
}
/**
@@ -115,7 +115,7 @@ public abstract class AbstractSelector extends Selector
*
* @return the cancelled keys set
*/
- protected final Set cancelledKeys()
+ protected final Set<SelectionKey> cancelledKeys()
{
if (! isOpen())
throw new ClosedSelectorException();
diff --git a/java/nio/charset/Charset.java b/java/nio/charset/Charset.java
index 3637703a3..556e4707e 100644
--- a/java/nio/charset/Charset.java
+++ b/java/nio/charset/Charset.java
@@ -60,7 +60,7 @@ import java.util.TreeMap;
* @since 1.4
* @status updated to 1.5
*/
-public abstract class Charset implements Comparable
+public abstract class Charset implements Comparable<Charset>
{
private CharsetEncoder cachedEncoder;
private CharsetDecoder cachedDecoder;
@@ -219,19 +219,20 @@ public abstract class Charset implements Comparable
return cs;
}
- public static SortedMap availableCharsets()
+ public static SortedMap<String, Charset> availableCharsets()
{
- TreeMap charsets = new TreeMap(String.CASE_INSENSITIVE_ORDER);
- for (Iterator i = provider().charsets(); i.hasNext(); )
+ TreeMap<String, Charset> charsets
+ = new TreeMap(String.CASE_INSENSITIVE_ORDER);
+ for (Iterator<Charset> i = provider().charsets(); i.hasNext(); )
{
- Charset cs = (Charset) i.next();
+ Charset cs = i.next();
charsets.put(cs.name(), cs);
}
CharsetProvider[] providers = providers2();
for (int j = 0; j < providers.length; j++)
{
- for (Iterator i = providers[j].charsets(); i.hasNext(); )
+ for (Iterator<Charset> i = providers[j].charsets(); i.hasNext(); )
{
Charset cs = (Charset) i.next();
charsets.put(cs.name(), cs);
@@ -284,14 +285,14 @@ public abstract class Charset implements Comparable
return canonicalName;
}
- public final Set aliases ()
+ public final Set<String> aliases ()
{
if (aliases == null)
- return Collections.EMPTY_SET;
+ return Collections.<String>emptySet();
// should we cache the aliasSet instead?
int n = aliases.length;
- HashSet aliasSet = new HashSet (n);
+ HashSet<String> aliasSet = new HashSet<String> (n);
for (int i = 0; i < n; ++i)
aliasSet.add (aliases[i]);
return Collections.unmodifiableSet (aliasSet);
@@ -376,9 +377,9 @@ public abstract class Charset implements Comparable
}
}
- public final int compareTo (Object ob)
+ public final int compareTo (Charset other)
{
- return canonicalName.compareToIgnoreCase (((Charset) ob).canonicalName);
+ return canonicalName.compareToIgnoreCase (other.canonicalName);
}
public final int hashCode ()
diff --git a/java/nio/charset/spi/CharsetProvider.java b/java/nio/charset/spi/CharsetProvider.java
index 496ccf927..03653f807 100644
--- a/java/nio/charset/spi/CharsetProvider.java
+++ b/java/nio/charset/spi/CharsetProvider.java
@@ -1,5 +1,5 @@
/* CharsetProvider.java -- charset service provider interface
- Copyright (C) 2002, 2006 Free Software Foundation
+ Copyright (C) 2002, 2005, 2006 Free Software Foundation
This file is part of GNU Classpath.
@@ -82,7 +82,7 @@ public abstract class CharsetProvider
* @return the iterator
* @see Charset#availableCharsets()
*/
- public abstract Iterator charsets();
+ public abstract Iterator<Charset> charsets();
/**
* Returns the named charset, by canonical name or alias.
diff --git a/java/rmi/server/LoaderHandler.java b/java/rmi/server/LoaderHandler.java
index 0489cd166..8e9661564 100644
--- a/java/rmi/server/LoaderHandler.java
+++ b/java/rmi/server/LoaderHandler.java
@@ -42,6 +42,7 @@ import java.net.URL;
/**
* @deprecated
+ * @since 1.1
*/
public interface LoaderHandler
{
@@ -54,13 +55,13 @@ public interface LoaderHandler
/**
* @deprecated
*/
- Class loadClass(String name)
+ Class<?> loadClass(String name)
throws MalformedURLException, ClassNotFoundException;
/**
* @deprecated
*/
- Class loadClass(URL codebase, String name)
+ Class<?> loadClass(URL codebase, String name)
throws MalformedURLException, ClassNotFoundException;
/**
diff --git a/java/rmi/server/RMIClassLoader.java b/java/rmi/server/RMIClassLoader.java
index 33c44198d..7b69d2f2c 100644
--- a/java/rmi/server/RMIClassLoader.java
+++ b/java/rmi/server/RMIClassLoader.java
@@ -51,6 +51,7 @@ import java.util.Iterator;
* network-based class loading in RMI. These methods are called by RMI's
* internal marshal streams to implement the dynamic class loading of types for
* RMI parameters and return values.
+ * @since 1.1
*/
public class RMIClassLoader
{
@@ -62,13 +63,13 @@ public class RMIClassLoader
/**
* @deprecated
*/
- public static Class loadClass(String name)
+ public static Class<?> loadClass(String name)
throws MalformedURLException, ClassNotFoundException
{
return loadClass("", name);
}
- public static Class loadClass(String codebase, String name)
+ public static Class<?> loadClass(String codebase, String name)
throws MalformedURLException, ClassNotFoundException
{
RMIClassLoaderSpi spi = getProviderInstance();
@@ -77,8 +78,8 @@ public class RMIClassLoader
return spi.loadClass(codebase, name, null);
}
- public static Class loadClass(String codebase, String name,
- ClassLoader defaultLoader)
+ public static Class<?> loadClass(String codebase, String name,
+ ClassLoader defaultLoader)
throws MalformedURLException, ClassNotFoundException
{
RMIClassLoaderSpi spi = getProviderInstance();
@@ -87,8 +88,8 @@ public class RMIClassLoader
return spi.loadClass(codebase, name, defaultLoader);
}
- public static Class loadProxyClass (String codeBase, String[] interfaces,
- ClassLoader defaultLoader)
+ public static Class<?> loadProxyClass (String codeBase, String[] interfaces,
+ ClassLoader defaultLoader)
throws MalformedURLException, ClassNotFoundException
{
RMIClassLoaderSpi spi = getProviderInstance();
@@ -114,7 +115,7 @@ public class RMIClassLoader
* @throws MalformedURLException if the URL is not well formed
* @throws ClassNotFoundException if the requested class cannot be found
*/
- public static Class loadClass(URL codeBase, String name)
+ public static Class<?> loadClass(URL codeBase, String name)
throws MalformedURLException, ClassNotFoundException
{
RMIClassLoaderSpi spi = getProviderInstance();
@@ -151,7 +152,7 @@ public class RMIClassLoader
* @return a space seperated list of URLs where the class-definition
* of cl may be found
*/
- public static String getClassAnnotation(Class cl)
+ public static String getClassAnnotation(Class<?> cl)
{
RMIClassLoaderSpi spi = getProviderInstance();
if (spi == null)
diff --git a/java/rmi/server/RMIClassLoaderSpi.java b/java/rmi/server/RMIClassLoaderSpi.java
index 372d81879..ec2c204f1 100644
--- a/java/rmi/server/RMIClassLoaderSpi.java
+++ b/java/rmi/server/RMIClassLoaderSpi.java
@@ -49,16 +49,16 @@ public abstract class RMIClassLoaderSpi
{
}
- public abstract Class loadClass (String codeBase, String name,
- ClassLoader defaultLoader)
+ public abstract Class<?> loadClass (String codeBase, String name,
+ ClassLoader defaultLoader)
throws MalformedURLException, ClassNotFoundException;
- public abstract Class loadProxyClass (String codeBase, String[] interfaces,
- ClassLoader defaultLoader)
+ public abstract Class<?> loadProxyClass (String codeBase, String[] interfaces,
+ ClassLoader defaultLoader)
throws MalformedURLException, ClassNotFoundException;
public abstract ClassLoader getClassLoader (String codebase)
throws MalformedURLException;
- public abstract String getClassAnnotation (Class cl);
+ public abstract String getClassAnnotation (Class<?> cl);
}
diff --git a/java/security/AccessController.java b/java/security/AccessController.java
index 93e34b87c..6f8b3ecbd 100644
--- a/java/security/AccessController.java
+++ b/java/security/AccessController.java
@@ -88,7 +88,7 @@ public final class AccessController
* should be be called.
* @return the result of the <code>action.run()</code> method.
*/
- public static Object doPrivileged(PrivilegedAction action)
+ public static <T> T doPrivileged(PrivilegedAction<T> action)
{
VMAccessController.pushContext(null);
try
@@ -115,8 +115,8 @@ public final class AccessController
* domains should be added to the protection domain of the calling class.
* @return the result of the <code>action.run()</code> method.
*/
- public static Object doPrivileged(PrivilegedAction action,
- AccessControlContext context)
+ public static <T> T doPrivileged(PrivilegedAction<T> action,
+ AccessControlContext context)
{
VMAccessController.pushContext(context);
try
@@ -145,7 +145,7 @@ public final class AccessController
* @exception PrivilegedActionException wrapped around any checked exception
* that is thrown in the <code>run()</code> method.
*/
- public static Object doPrivileged(PrivilegedExceptionAction action)
+ public static <T> T doPrivileged(PrivilegedExceptionAction<T> action)
throws PrivilegedActionException
{
VMAccessController.pushContext(null);
@@ -185,8 +185,8 @@ public final class AccessController
* @exception PrivilegedActionException wrapped around any checked exception
* that is thrown in the <code>run()</code> method.
*/
- public static Object doPrivileged(PrivilegedExceptionAction action,
- AccessControlContext context)
+ public static <T> T doPrivileged(PrivilegedExceptionAction<T> action,
+ AccessControlContext context)
throws PrivilegedActionException
{
VMAccessController.pushContext(context);
diff --git a/java/security/AlgorithmParameters.java b/java/security/AlgorithmParameters.java
index 14a28df21..f5e5063a1 100644
--- a/java/security/AlgorithmParameters.java
+++ b/java/security/AlgorithmParameters.java
@@ -268,7 +268,8 @@ public class AlgorithmParameters
* @throws InvalidParameterSpecException
* if <code>paramSpec</code> is invalid.
*/
- public final AlgorithmParameterSpec getParameterSpec(Class paramSpec)
+ public final <T extends AlgorithmParameterSpec>
+ T getParameterSpec(Class<T> paramSpec)
throws InvalidParameterSpecException
{
return paramSpi.engineGetParameterSpec(paramSpec);
diff --git a/java/security/AlgorithmParametersSpi.java b/java/security/AlgorithmParametersSpi.java
index a9faa1543..bd61ce7df 100644
--- a/java/security/AlgorithmParametersSpi.java
+++ b/java/security/AlgorithmParametersSpi.java
@@ -113,8 +113,8 @@ public abstract class AlgorithmParametersSpi
* @throws InvalidParameterSpecException if the paramSpec is an
* invalid parameter class
*/
- protected abstract AlgorithmParameterSpec engineGetParameterSpec(Class
- paramSpec)
+ protected abstract <T extends AlgorithmParameterSpec>
+ T engineGetParameterSpec(Class<T> paramSpec)
throws InvalidParameterSpecException;
diff --git a/java/security/IdentityScope.java b/java/security/IdentityScope.java
index d1ea1f295..610d3534c 100644
--- a/java/security/IdentityScope.java
+++ b/java/security/IdentityScope.java
@@ -201,7 +201,7 @@ public abstract class IdentityScope extends Identity
*
* @return an {@link Enumeration} of the identities in this scope.
*/
- public abstract Enumeration identities();
+ public abstract Enumeration<Identity> identities();
/**
* Returns a string representing this instance. It includes the name, the
diff --git a/java/security/KeyFactory.java b/java/security/KeyFactory.java
index 914975d77..043dd59a1 100644
--- a/java/security/KeyFactory.java
+++ b/java/security/KeyFactory.java
@@ -255,7 +255,7 @@ public class KeyFactory
* the requested key specification is inappropriate for this key or
* the key is unrecognized.
*/
- public final KeySpec getKeySpec(Key key, Class keySpec)
+ public final <T extends KeySpec> T getKeySpec(Key key, Class<T> keySpec)
throws InvalidKeySpecException
{
return keyFacSpi.engineGetKeySpec(key, keySpec);
diff --git a/java/security/KeyFactorySpi.java b/java/security/KeyFactorySpi.java
index 1894fad08..fa5637812 100644
--- a/java/security/KeyFactorySpi.java
+++ b/java/security/KeyFactorySpi.java
@@ -113,7 +113,8 @@ public abstract class KeyFactorySpi
* is inappropriate for this key or the key is
* unrecognized.
*/
- protected abstract KeySpec engineGetKeySpec(Key key, Class keySpec)
+ protected abstract <T extends KeySpec> T engineGetKeySpec(Key key,
+ Class<T> keySpec)
throws InvalidKeySpecException;
@@ -121,11 +122,11 @@ public abstract class KeyFactorySpi
* Translates the key from an unknown or untrusted provider
* into a key for this key factory.
*
- * @param the key from an unknown or untrusted provider
+ * @param key key from an unknown or untrusted provider
*
* @return the translated key
*
- * @throws InvalidKeySpecException if the key cannot be
+ * @throws InvalidKeyException if the key cannot be
* processed by this key factory
*/
protected abstract Key engineTranslateKey(Key key)
diff --git a/java/security/KeyStore.java b/java/security/KeyStore.java
index 3015e3295..1d036c31c 100644
--- a/java/security/KeyStore.java
+++ b/java/security/KeyStore.java
@@ -388,7 +388,7 @@ public class KeyStore
@return an Enumeration of the aliases
*/
- public final Enumeration aliases() throws KeyStoreException
+ public final Enumeration<String> aliases() throws KeyStoreException
{
return keyStoreSpi.engineAliases();
}
diff --git a/java/security/KeyStoreSpi.java b/java/security/KeyStoreSpi.java
index a16008f99..c8d231663 100644
--- a/java/security/KeyStoreSpi.java
+++ b/java/security/KeyStoreSpi.java
@@ -187,7 +187,7 @@ public abstract class KeyStoreSpi
*
* @return an Enumeration of the aliases
*/
- public abstract Enumeration engineAliases();
+ public abstract Enumeration<String> engineAliases();
/**
* Determines if the keystore contains the specified alias.
diff --git a/java/security/MessageDigest.java b/java/security/MessageDigest.java
index 5fa07cf2a..0f8e934e5 100644
--- a/java/security/MessageDigest.java
+++ b/java/security/MessageDigest.java
@@ -38,6 +38,7 @@ exception statement from your version. */
package java.security;
import gnu.java.security.Engine;
+import java.nio.ByteBuffer;
import java.lang.reflect.InvocationTargetException;
@@ -229,6 +230,17 @@ public abstract class MessageDigest extends MessageDigestSpi
}
/**
+ * Updates the digest with the remaining bytes of a buffer.
+ *
+ * @param input The input byte buffer.
+ * @since 1.5
+ */
+ public void update (ByteBuffer input)
+ {
+ engineUpdate (input);
+ }
+
+ /**
* Computes the final digest of the stored data.
*
* @return a byte array representing the message digest.
diff --git a/java/security/MessageDigestSpi.java b/java/security/MessageDigestSpi.java
index df3bd3ead..6615b1d93 100644
--- a/java/security/MessageDigestSpi.java
+++ b/java/security/MessageDigestSpi.java
@@ -37,6 +37,8 @@ exception statement from your version. */
package java.security;
+import java.nio.ByteBuffer;
+
/**
This is the Service Provider Interface (SPI) for MessageDigest
class in java.security. It provides the back end functionality
@@ -98,6 +100,23 @@ public abstract class MessageDigestSpi
protected abstract void engineUpdate(byte[]input, int offset, int len);
/**
+ * Updates this digest with the remaining bytes of a byte buffer.
+ *
+ * @param input The input buffer.
+ * @since 1.5
+ */
+ protected void engineUpdate (ByteBuffer input)
+ {
+ byte[] buf = new byte[1024];
+ while (input.hasRemaining())
+ {
+ int n = Math.min(input.remaining(), buf.length);
+ input.get (buf, 0, n);
+ engineUpdate (buf, 0, n);
+ }
+ }
+
+ /**
Computes the final digest of the stored bytes and returns
them. It performs any necessary padding. The message digest
should reset sensitive data after performing the digest.
diff --git a/java/security/PermissionCollection.java b/java/security/PermissionCollection.java
index 4e8ffe579..c5849830a 100644
--- a/java/security/PermissionCollection.java
+++ b/java/security/PermissionCollection.java
@@ -120,7 +120,7 @@ public abstract class PermissionCollection implements Serializable
*
* @return an <code>Enumeration</code> of this collection's objects
*/
- public abstract Enumeration elements();
+ public abstract Enumeration<Permission> elements();
/**
* This method sets this <code>PermissionCollection</code> object to be
@@ -159,7 +159,7 @@ public abstract class PermissionCollection implements Serializable
StringBuffer sb = new StringBuffer(super.toString());
sb.append(" (\n");
- Enumeration e = elements();
+ Enumeration<Permission> e = elements();
while (e.hasMoreElements())
sb.append(' ').append(e.nextElement()).append('\n');
return sb.append(")\n").toString();
diff --git a/java/security/Permissions.java b/java/security/Permissions.java
index e3fd06970..56f5ad8f5 100644
--- a/java/security/Permissions.java
+++ b/java/security/Permissions.java
@@ -150,7 +150,7 @@ public final class Permissions extends PermissionCollection
*
* @return an <code>Enumeration</code> of this collection's elements
*/
- public Enumeration elements()
+ public Enumeration<Permission> elements()
{
return new Enumeration()
{
diff --git a/java/security/PrivilegedAction.java b/java/security/PrivilegedAction.java
index c3a41346f..1a51eaade 100644
--- a/java/security/PrivilegedAction.java
+++ b/java/security/PrivilegedAction.java
@@ -47,9 +47,9 @@ package java.security;
* @see AccessController
* @see PrivilegedExceptionAction
* @since 1.1
- * @status updated to 1.4
+ * @status updated to 1.5
*/
-public interface PrivilegedAction
+public interface PrivilegedAction<T>
{
/**
* This method performs an operation that requires higher privileges to
@@ -60,5 +60,5 @@ public interface PrivilegedAction
* @see AccessController#doPrivileged(PrivilegedAction)
* @see AccessController#doPrivileged(PrivilegedAction, AccessControlContext)
*/
- Object run();
+ T run();
} // interface PrivilegedAction
diff --git a/java/security/PrivilegedExceptionAction.java b/java/security/PrivilegedExceptionAction.java
index d3d0478fd..351438e0b 100644
--- a/java/security/PrivilegedExceptionAction.java
+++ b/java/security/PrivilegedExceptionAction.java
@@ -46,9 +46,9 @@ package java.security;
*
* @author Aaron M. Renn (arenn@urbanophile.com)
* @since 1.1
- * @status updated to 1.4
+ * @status updated to 1.5
*/
-public interface PrivilegedExceptionAction
+public interface PrivilegedExceptionAction<T>
{
/**
* This method performs an operation that requires higher privileges to
@@ -61,5 +61,5 @@ public interface PrivilegedExceptionAction
* @see AccessController#doPrivileged(PrivilegedExceptionAction,
* AccessControlContext)
*/
- Object run() throws Exception;
+ T run() throws Exception;
} // interface PrivilegedExceptionAction
diff --git a/java/security/SecureClassLoader.java b/java/security/SecureClassLoader.java
index 3cd640555..dfc1758b5 100644
--- a/java/security/SecureClassLoader.java
+++ b/java/security/SecureClassLoader.java
@@ -37,6 +37,8 @@ exception statement from your version. */
package java.security;
+import java.util.WeakHashMap;
+
import java.nio.ByteBuffer;
import java.util.HashMap;
@@ -51,7 +53,8 @@ import java.util.HashMap;
*/
public class SecureClassLoader extends ClassLoader
{
- private final HashMap protectionDomainCache = new HashMap();
+ private final HashMap<CodeSource,ProtectionDomain> protectionDomainCache
+ = new HashMap<CodeSource, ProtectionDomain>();
protected SecureClassLoader(ClassLoader parent)
{
@@ -76,7 +79,7 @@ public class SecureClassLoader extends ClassLoader
*
* @exception ClassFormatError if the byte array is not in proper classfile format.
*/
- protected final Class defineClass(String name, byte[] b, int off, int len,
+ protected final Class<?> defineClass(String name, byte[] b, int off, int len,
CodeSource cs)
{
return super.defineClass(name, b, off, len, getProtectionDomain(cs));
diff --git a/java/security/Security.java b/java/security/Security.java
index d99c45149..d3d2c1ebc 100644
--- a/java/security/Security.java
+++ b/java/security/Security.java
@@ -138,7 +138,7 @@ public final class Security
Exception exception = null;
try
{
- ClassLoader sys = ClassLoader.getSystemClassLoader();
+ ClassLoader sys = ClassLoader.getSystemClassLoader();
providers.addElement(Class.forName(name, true, sys).newInstance());
}
catch (ClassNotFoundException x)
@@ -408,9 +408,9 @@ public final class Security
* {@link Provider}s.
* @since 1.4
*/
- public static Set getAlgorithms(String serviceName)
+ public static Set<String> getAlgorithms(String serviceName)
{
- HashSet result = new HashSet();
+ HashSet<String> result = new HashSet<String>();
if (serviceName == null || serviceName.length() == 0)
return result;
@@ -541,7 +541,7 @@ public final class Security
* {@link Map}'s <i>keys</i>.
* @see #getProviders(String)
*/
- public static Provider[] getProviders(Map filter)
+ public static Provider[] getProviders(Map<String,String> filter)
{
if (providers == null || providers.isEmpty())
return null;
@@ -549,7 +549,7 @@ public final class Security
if (filter == null)
return getProviders();
- Set querries = filter.keySet();
+ Set<String> querries = filter.keySet();
if (querries == null || querries.isEmpty())
return getProviders();
@@ -572,7 +572,7 @@ public final class Security
throw new InvalidParameterException(
"missing dot in '" + String.valueOf(querry)+"'");
- value = (String) filter.get(querry);
+ value = filter.get(querry);
// deconstruct querry into [service, algorithm, attribute]
if (value == null || value.trim().length() == 0) // <service>.<algorithm>
{
diff --git a/java/security/Signature.java b/java/security/Signature.java
index 6f65f3a89..1245707f7 100644
--- a/java/security/Signature.java
+++ b/java/security/Signature.java
@@ -41,6 +41,7 @@ package java.security;
import gnu.java.security.Engine;
import java.lang.reflect.InvocationTargetException;
+import java.nio.ByteBuffer;
import java.security.cert.Certificate;
import java.security.cert.X509Certificate;
import java.security.spec.AlgorithmParameterSpec;
@@ -474,6 +475,22 @@ public abstract class Signature extends SignatureSpi
else
throw new SignatureException();
}
+
+ /**
+ * Update this signature with the {@link java.nio.Buffer#remaining()}
+ * bytes of the input buffer.
+ *
+ * @param input The input buffer.
+ * @throws SignatureException If this instance was not properly
+ * initialized.
+ */
+ public final void update(ByteBuffer input) throws SignatureException
+ {
+ if (state != UNINITIALIZED)
+ engineUpdate(input);
+ else
+ throw new SignatureException("not initialized");
+ }
/**
* Returns the name of the algorithm currently used. The names of algorithms
diff --git a/java/security/SignatureSpi.java b/java/security/SignatureSpi.java
index 25d49dedd..3b46815ec 100644
--- a/java/security/SignatureSpi.java
+++ b/java/security/SignatureSpi.java
@@ -37,6 +37,7 @@ exception statement from your version. */
package java.security;
+import java.nio.ByteBuffer;
import java.security.spec.AlgorithmParameterSpec;
/**
@@ -131,6 +132,24 @@ public abstract class SignatureSpi
throws SignatureException;
/**
+ * Update this signature with the {@link java.nio.Buffer#remaining()}
+ * bytes of the given buffer.
+ *
+ * @param input The input buffer.
+ * @throws SignatureException
+ */
+ protected void engineUpdate(ByteBuffer input) throws SignatureException
+ {
+ byte[] buf = new byte[4096];
+ while (input.hasRemaining())
+ {
+ int l = Math.min(input.remaining(), buf.length);
+ input.get(buf, 0, l);
+ engineUpdate(buf, 0, l);
+ }
+ }
+
+ /**
* Returns the signature bytes of all the data fed to this instance. The
* format of the output depends on the underlying signature algorithm.
*
diff --git a/java/security/acl/Acl.java b/java/security/acl/Acl.java
index ff139afd6..6a3f7d52a 100644
--- a/java/security/acl/Acl.java
+++ b/java/security/acl/Acl.java
@@ -117,7 +117,7 @@ public interface Acl extends Owner
*
* @return An enumeration of the ACL entries
*/
- Enumeration entries();
+ Enumeration<AclEntry> entries();
/**
* This method tests whether or not the specified <code>Principal</code>
@@ -142,7 +142,7 @@ public interface Acl extends Owner
*
* @return A list of permissions for the <code>Principal</code>.
*/
- Enumeration getPermissions(Principal user);
+ Enumeration<Permission> getPermissions(Principal user);
/**
* This method returns the ACL as a <code>String</code>
diff --git a/java/security/acl/AclEntry.java b/java/security/acl/AclEntry.java
index 7b1bcf54d..ea906f184 100644
--- a/java/security/acl/AclEntry.java
+++ b/java/security/acl/AclEntry.java
@@ -94,7 +94,7 @@ public interface AclEntry extends Cloneable
/**
* This method adds the specified permission to this ACL entry.
*
- * @param perm The <code>Permission</code> to add
+ * @param permission The <code>Permission</code> to add
*
* @return <code>true</code> if the permission was added or <code>false</code> if it was already set for this entry
*/
@@ -113,7 +113,7 @@ public interface AclEntry extends Cloneable
* This method tests whether or not the specified permission is associated
* with this ACL entry.
*
- * @param perm The <code>Permission</code> to test
+ * @param permission The <code>Permission</code> to test
*
* @return <code>true</code> if this permission is associated with this entry or <code>false</code> otherwise
*/
@@ -125,7 +125,7 @@ public interface AclEntry extends Cloneable
*
* @return A list of permissions for this ACL entry
*/
- Enumeration permissions();
+ Enumeration<Permission> permissions();
/**
* This method returns this object as a <code>String</code>.
diff --git a/java/security/acl/Group.java b/java/security/acl/Group.java
index 3ffdf15a4..ed6d56a57 100644
--- a/java/security/acl/Group.java
+++ b/java/security/acl/Group.java
@@ -74,7 +74,7 @@ public interface Group extends Principal
* This method tests whether or not a given <code>Principal</code> is a
* member of this group.
*
- * @param user The <code>Principal</code> to test for membership
+ * @param member The <code>Principal</code> to test for membership
*
* @return <code>true</code> if the user is member, <code>false</code> otherwise
*/
@@ -86,5 +86,5 @@ public interface Group extends Principal
*
* @return The list of all members of the group
*/
- Enumeration members();
+ Enumeration<? extends Principal> members();
}
diff --git a/java/security/cert/CertPath.java b/java/security/cert/CertPath.java
index e818763aa..781eb3e27 100644
--- a/java/security/cert/CertPath.java
+++ b/java/security/cert/CertPath.java
@@ -161,7 +161,7 @@ public abstract class CertPath implements Serializable
*
* @return the iterator of supported encodings in the path
*/
- public abstract Iterator getEncodings();
+ public abstract Iterator<String> getEncodings();
/**
* Compares this path to another for semantic equality. To be equal, both
@@ -226,7 +226,7 @@ public abstract class CertPath implements Serializable
*
* @return the list of certificates, non-null but possibly empty
*/
- public abstract List getCertificates();
+ public abstract List<? extends Certificate> getCertificates();
/**
* Serializes the path in its encoded form, to ensure reserialization with
diff --git a/java/security/cert/CertStore.java b/java/security/cert/CertStore.java
index a2d1de335..a27086562 100644
--- a/java/security/cert/CertStore.java
+++ b/java/security/cert/CertStore.java
@@ -53,7 +53,7 @@ import java.util.Collection;
* A CertStore is a read-only repository for certificates and
* certificate revocation lists.
*
- * @since JDK 1.4
+ * @since 1.4
*/
public class CertStore
{
@@ -277,7 +277,7 @@ public class CertStore
* @return The collection of certificates.
* @throws CertStoreException If the certificates cannot be retrieved.
*/
- public final Collection getCertificates(CertSelector selector)
+ public final Collection<? extends Certificate> getCertificates(CertSelector selector)
throws CertStoreException
{
return storeSpi.engineGetCertificates(selector);
@@ -295,7 +295,7 @@ public class CertStore
* @return The collection of certificate revocation lists.
* @throws CertStoreException If the CRLs cannot be retrieved.
*/
- public final Collection getCRLs(CRLSelector selector)
+ public final Collection<? extends CRL> getCRLs(CRLSelector selector)
throws CertStoreException
{
return storeSpi.engineGetCRLs(selector);
diff --git a/java/security/cert/CertStoreSpi.java b/java/security/cert/CertStoreSpi.java
index a69545f0d..976d65ce9 100644
--- a/java/security/cert/CertStoreSpi.java
+++ b/java/security/cert/CertStoreSpi.java
@@ -50,7 +50,7 @@ import java.util.Collection;
* implement the {@link CertStoreParameters} interface, if they require
* parameters.
*
- * @since JDK 1.4
+ * @since 1.4
* @see CertStore
* @see CollectionCertStoreParameters
* @see LDAPCertStoreParameters
@@ -86,7 +86,7 @@ public abstract class CertStoreSpi
* @return A (non-null) collection of certificates.
* @throws CertStoreException If the certificates cannot be retrieved.
*/
- public abstract Collection engineGetCertificates(CertSelector selector)
+ public abstract Collection<? extends Certificate> engineGetCertificates(CertSelector selector)
throws CertStoreException;
/**
@@ -98,6 +98,6 @@ public abstract class CertStoreSpi
* @return A (non-null) collection of certificate revocation list.
* @throws CertStoreException If the CRLs cannot be retrieved.
*/
- public abstract Collection engineGetCRLs(CRLSelector selector)
+ public abstract Collection<? extends CRL> engineGetCRLs(CRLSelector selector)
throws CertStoreException;
}
diff --git a/java/security/cert/CertificateFactory.java b/java/security/cert/CertificateFactory.java
index 9a7db6cd5..8139c6ec5 100644
--- a/java/security/cert/CertificateFactory.java
+++ b/java/security/cert/CertificateFactory.java
@@ -58,7 +58,7 @@ import java.util.List;
*
* @author Mark Benvenuto
* @author Casey Marshall
- * @since JDK 1.2
+ * @since 1.2
* @status Fully compatible with JDK 1.4.
*/
public class CertificateFactory
@@ -247,7 +247,7 @@ public class CertificateFactory
* @throws CertificateException If an error occurs decoding the
* certificates.
*/
- public final Collection generateCertificates(InputStream inStream)
+ public final Collection<? extends Certificate> generateCertificates(InputStream inStream)
throws CertificateException
{
return certFacSpi.engineGenerateCertificates(inStream);
@@ -289,7 +289,7 @@ public class CertificateFactory
* InputStream data.
* @throws CRLException If an error occurs decoding the CRLs.
*/
- public final Collection generateCRLs(InputStream inStream)
+ public final Collection<? extends CRL> generateCRLs(InputStream inStream)
throws CRLException
{
return certFacSpi.engineGenerateCRLs( inStream );
@@ -336,7 +336,7 @@ public class CertificateFactory
* @throws CertificateException If an error occurs generating the
* CertPath.
*/
- public final CertPath generateCertPath(List certificates)
+ public final CertPath generateCertPath(List<? extends Certificate> certificates)
throws CertificateException
{
return certFacSpi.engineGenerateCertPath(certificates);
@@ -349,7 +349,7 @@ public class CertificateFactory
*
* @return The Iterator of supported encodings.
*/
- public final Iterator getCertPathEncodings()
+ public final Iterator<String> getCertPathEncodings()
{
return certFacSpi.engineGetCertPathEncodings();
}
diff --git a/java/security/cert/CertificateFactorySpi.java b/java/security/cert/CertificateFactorySpi.java
index beea9646a..e6a22b4eb 100644
--- a/java/security/cert/CertificateFactorySpi.java
+++ b/java/security/cert/CertificateFactorySpi.java
@@ -54,7 +54,7 @@ import java.util.List;
Certificate factories are used to generate certificates and
certificate revocation lists (CRL) from their encoding.
- @since JDK 1.2
+ @since 1.2
@author Mark Benvenuto
*/
@@ -117,7 +117,7 @@ public abstract class CertificateFactorySpi
@throws CertificateException Certificate parsing error
*/
- public abstract Collection engineGenerateCertificates(InputStream inStream)
+ public abstract Collection<? extends Certificate> engineGenerateCertificates(InputStream inStream)
throws CertificateException;
/**
@@ -157,7 +157,7 @@ public abstract class CertificateFactorySpi
@throws CRLException CRL parsing error
*/
- public abstract Collection engineGenerateCRLs(InputStream inStream)
+ public abstract Collection<? extends CRL> engineGenerateCRLs(InputStream inStream)
throws CRLException;
// 1.4 instance methods.
@@ -204,7 +204,7 @@ public abstract class CertificateFactorySpi
* @throws CertificateException If an error occurs generating the
* CertPath.
*/
- public CertPath engineGenerateCertPath(List certificates)
+ public CertPath engineGenerateCertPath(List<? extends Certificate> certificates)
throws CertificateException
{
throw new UnsupportedOperationException("not implemented");
@@ -217,7 +217,7 @@ public abstract class CertificateFactorySpi
*
* @return The Iterator of supported encodings.
*/
- public Iterator engineGetCertPathEncodings()
+ public Iterator<String> engineGetCertPathEncodings()
{
throw new UnsupportedOperationException("not implemented");
}
diff --git a/java/security/cert/CollectionCertStoreParameters.java b/java/security/cert/CollectionCertStoreParameters.java
index bac1e3b3e..b3ee93235 100644
--- a/java/security/cert/CollectionCertStoreParameters.java
+++ b/java/security/cert/CollectionCertStoreParameters.java
@@ -51,6 +51,7 @@ import java.util.Collections;
* collection may be changed at any time.
*
* @see CertStore
+ * @since 1.4
*/
public class CollectionCertStoreParameters implements CertStoreParameters
{
@@ -81,7 +82,7 @@ public class CollectionCertStoreParameters implements CertStoreParameters
* @param collection The collection.
* @throws NullPointerException If <i>collection</i> is null.
*/
- public CollectionCertStoreParameters(Collection collection)
+ public CollectionCertStoreParameters(Collection<?> collection)
{
if (collection == null)
throw new NullPointerException();
@@ -103,7 +104,7 @@ public class CollectionCertStoreParameters implements CertStoreParameters
*
* @return The collection.
*/
- public Collection getCollection()
+ public Collection<?> getCollection()
{
return collection;
}
diff --git a/java/security/cert/PKIXBuilderParameters.java b/java/security/cert/PKIXBuilderParameters.java
index 38b3df5e7..5e234cec1 100644
--- a/java/security/cert/PKIXBuilderParameters.java
+++ b/java/security/cert/PKIXBuilderParameters.java
@@ -48,6 +48,7 @@ import java.util.Set;
* Parameters for building certificate paths using the PKIX algorithm.
*
* @see CertPathBuilder
+ * @since 1.4
*/
public class PKIXBuilderParameters extends PKIXParameters
{
@@ -97,7 +98,8 @@ public class PKIXBuilderParameters extends PKIXParameters
* @throws ClassCastException If every element in <i>trustAnchors</i>
* is not a {@link TrustAnchor}.
*/
- public PKIXBuilderParameters(Set trustAnchors, CertSelector targetConstraints)
+ public PKIXBuilderParameters(Set<TrustAnchor> trustAnchors,
+ CertSelector targetConstraints)
throws InvalidAlgorithmParameterException
{
super(trustAnchors);
diff --git a/java/security/cert/PKIXCertPathChecker.java b/java/security/cert/PKIXCertPathChecker.java
index a6eef41a2..a69347fcd 100644
--- a/java/security/cert/PKIXCertPathChecker.java
+++ b/java/security/cert/PKIXCertPathChecker.java
@@ -59,6 +59,7 @@ import java.util.Set;
* the most-trusted certificate.
*
* @see PKIXParameters
+ * @since 1.4
*/
public abstract class PKIXCertPathChecker implements Cloneable
{
@@ -116,7 +117,7 @@ public abstract class PKIXCertPathChecker implements Cloneable
* @return An immutable set of Strings of the supported X.509 OIDs, or
* null if no extensions are supported.
*/
- public abstract Set getSupportedExtensions();
+ public abstract Set<String> getSupportedExtensions();
/**
* Checks a certificate, removing any critical extensions that are
@@ -128,6 +129,6 @@ public abstract class PKIXCertPathChecker implements Cloneable
* @throws CertPathValidatorException If this certificate fails this
* check.
*/
- public abstract void check(Certificate cert, Collection unresolvedCritExts)
+ public abstract void check(Certificate cert, Collection<String> unresolvedCritExts)
throws CertPathValidatorException;
}
diff --git a/java/security/cert/PKIXParameters.java b/java/security/cert/PKIXParameters.java
index 16ef07f88..bb68cb937 100644
--- a/java/security/cert/PKIXParameters.java
+++ b/java/security/cert/PKIXParameters.java
@@ -56,6 +56,7 @@ import java.util.Set;
* (Public-Key Infrastructure (X.509)) algorithm.
*
* @see CertPathBuilder
+ * @since 1.4
*/
public class PKIXParameters implements CertPathParameters
{
@@ -144,7 +145,7 @@ public class PKIXParameters implements CertPathParameters
* @throws ClassCastException If every element in <i>trustAnchors</i>
* is not a {@link TrustAnchor}.
*/
- public PKIXParameters(Set trustAnchors)
+ public PKIXParameters(Set<TrustAnchor> trustAnchors)
throws InvalidAlgorithmParameterException
{
this();
@@ -199,7 +200,7 @@ public class PKIXParameters implements CertPathParameters
*
* @return A (never null, never empty) immutable set of trust anchors.
*/
- public Set getTrustAnchors()
+ public Set<TrustAnchor> getTrustAnchors()
{
return Collections.unmodifiableSet(trustAnchors);
}
@@ -216,7 +217,7 @@ public class PKIXParameters implements CertPathParameters
* @throws ClassCastException If every element in <i>trustAnchors</i>
* is not a {@link TrustAnchor}.
*/
- public void setTrustAnchors(Set trustAnchors)
+ public void setTrustAnchors(Set<TrustAnchor> trustAnchors)
throws InvalidAlgorithmParameterException
{
if (trustAnchors.isEmpty())
@@ -235,7 +236,7 @@ public class PKIXParameters implements CertPathParameters
* @return An immutable set of initial policy OID strings, or the
* empty set if any policy is acceptable.
*/
- public Set getInitialPolicies()
+ public Set<String> getInitialPolicies()
{
return Collections.unmodifiableSet(initPolicies);
}
@@ -249,7 +250,7 @@ public class PKIXParameters implements CertPathParameters
* @throws ClassCastException If any element in <i>initPolicies</i> is
* not a string.
*/
- public void setInitialPolicies(Set initPolicies)
+ public void setInitialPolicies(Set<String> initPolicies)
{
this.initPolicies.clear();
if (initPolicies == null)
@@ -277,7 +278,7 @@ public class PKIXParameters implements CertPathParameters
*
* @return The list of cert stores.
*/
- public List getCertStores()
+ public List<CertStore> getCertStores()
{
return Collections.unmodifiableList(certStores);
}
@@ -288,7 +289,7 @@ public class PKIXParameters implements CertPathParameters
*
* @param certStores The cert stores.
*/
- public void setCertStores(List certStores)
+ public void setCertStores(List<CertStore> certStores)
{
this.certStores.clear();
if (certStores == null)
@@ -446,7 +447,7 @@ public class PKIXParameters implements CertPathParameters
*
* @return An immutable list of all certificate path checkers.
*/
- public List getCertPathCheckers()
+ public List<PKIXCertPathChecker> getCertPathCheckers()
{
return Collections.unmodifiableList(pathCheckers);
}
@@ -459,7 +460,7 @@ public class PKIXParameters implements CertPathParameters
* @throws ClassCastException If any element of <i>pathCheckers</i> is
* not a {@link PKIXCertPathChecker}.
*/
- public void setCertPathCheckers(List pathCheckers)
+ public void setCertPathCheckers(List<PKIXCertPathChecker> pathCheckers)
{
this.pathCheckers.clear();
if (pathCheckers == null)
diff --git a/java/security/cert/PolicyNode.java b/java/security/cert/PolicyNode.java
index 58d411cd3..b1196037e 100644
--- a/java/security/cert/PolicyNode.java
+++ b/java/security/cert/PolicyNode.java
@@ -38,6 +38,12 @@ exception statement from your version. */
package java.security.cert;
+import java.util.Iterator;
+import java.util.Set;
+
+/**
+ * @since 1.4
+ */
public interface PolicyNode
{
@@ -47,7 +53,7 @@ public interface PolicyNode
*
* @return An iterator over the child nodes.
*/
- java.util.Iterator getChildren();
+ Iterator<? extends PolicyNode> getChildren();
/**
* Get the depth of this node within the tree, starting at 0 for the
@@ -64,7 +70,7 @@ public interface PolicyNode
*
* @return The set of expected policies.
*/
- java.util.Set getExpectedPolicies();
+ Set<String> getExpectedPolicies();
/**
* Returns the parent node of this node, or null if this is the root
@@ -81,7 +87,7 @@ public interface PolicyNode
*
* @return The set of {@link PolicyQualifierInfo} objects.
*/
- java.util.Set getPolicyQualifiers();
+ Set<? extends PolicyQualifierInfo> getPolicyQualifiers();
/**
* Get the policy OID this node represents. The root node should return
diff --git a/java/security/cert/PolicyQualifierInfo.java b/java/security/cert/PolicyQualifierInfo.java
index 7dcf23156..b50f3f312 100644
--- a/java/security/cert/PolicyQualifierInfo.java
+++ b/java/security/cert/PolicyQualifierInfo.java
@@ -59,9 +59,10 @@ import java.io.IOException;
* PolicyQualifierId ::= OBJECT IDENTIFIER
* </pre>
*
- * @since JDK 1.4
+ * @since 1.4
+ * @specnote this class was final in 1.4, but beginning with 1.5 is not
*/
-public final class PolicyQualifierInfo
+public class PolicyQualifierInfo
{
// Fields.
diff --git a/java/security/cert/X509CRL.java b/java/security/cert/X509CRL.java
index 5657b3eb3..a00706e67 100644
--- a/java/security/cert/X509CRL.java
+++ b/java/security/cert/X509CRL.java
@@ -97,7 +97,7 @@ import javax.security.auth.x500.X500Principal;
@author Mark Benvenuto
- @since JDK 1.2
+ @since 1.2
*/
public abstract class X509CRL extends CRL implements X509Extension
{
@@ -304,7 +304,7 @@ public abstract class X509CRL extends CRL implements X509Extension
@return a set of revoked certificates.
*/
- public abstract Set getRevokedCertificates();
+ public abstract Set<? extends X509CRLEntry> getRevokedCertificates();
/**
Returns the DER ASN.1 encoded tbsCertList which is
diff --git a/java/security/cert/X509CRLSelector.java b/java/security/cert/X509CRLSelector.java
index 3c79fba9c..56b171369 100644
--- a/java/security/cert/X509CRLSelector.java
+++ b/java/security/cert/X509CRLSelector.java
@@ -69,6 +69,7 @@ import javax.security.auth.x500.X500Principal;
* use or modify this class then they need to synchronize on the object.
*
* @author Casey Marshall (csm@gnu.org)
+ * @since 1.4
*/
public class X509CRLSelector implements CRLSelector, Cloneable
{
@@ -157,7 +158,7 @@ public class X509CRLSelector implements CRLSelector, Cloneable
* @throws IOException If any of the elements in the collection is not
* a valid name.
*/
- public void setIssuerNames(Collection names) throws IOException
+ public void setIssuerNames(Collection<?> names) throws IOException
{
if (names == null)
{
@@ -224,7 +225,7 @@ public class X509CRLSelector implements CRLSelector, Cloneable
*
* @return The set of issuer names.
*/
- public Collection getIssuerNames()
+ public Collection<Object> getIssuerNames()
{
if (issuerNames != null)
return Collections.unmodifiableList(issuerNames);
diff --git a/java/security/cert/X509CertSelector.java b/java/security/cert/X509CertSelector.java
index 175e4c673..154ed2e4d 100644
--- a/java/security/cert/X509CertSelector.java
+++ b/java/security/cert/X509CertSelector.java
@@ -76,6 +76,7 @@ import javax.security.auth.x500.X500Principal;
* use or modify this class then they need to synchronize on the object.
*
* @author Casey Marshall (csm@gnu.org)
+ * @since 1.4
*/
public class X509CertSelector implements CertSelector, Cloneable
{
@@ -573,7 +574,7 @@ public class X509CertSelector implements CertSelector, Cloneable
*
* @return The set of key purpose OIDs (strings).
*/
- public Set getExtendedKeyUsage()
+ public Set<String> getExtendedKeyUsage()
{
if (keyPurposeSet != null)
return Collections.unmodifiableSet(keyPurposeSet);
@@ -588,7 +589,7 @@ public class X509CertSelector implements CertSelector, Cloneable
* @param keyPurposeSet The set of key purpose OIDs.
* @throws IOException If any element of the set is not a valid OID string.
*/
- public void setExtendedKeyUsage(Set keyPurposeSet) throws IOException
+ public void setExtendedKeyUsage(Set<String> keyPurposeSet) throws IOException
{
if (keyPurposeSet == null)
{
@@ -653,7 +654,7 @@ public class X509CertSelector implements CertSelector, Cloneable
* @param altNames The alternative names.
* @throws IOException If any element of the argument is invalid.
*/
- public void setSubjectAlternativeNames(Collection altNames)
+ public void setSubjectAlternativeNames(Collection<List<?>> altNames)
throws IOException
{
if (altNames == null)
@@ -786,7 +787,7 @@ public class X509CertSelector implements CertSelector, Cloneable
// certificate, and check it against the specified set.
// FIXME
-// public void setPolicy(Set policy) throws IOException
+// public void setPolicy(Set<String> policy) throws IOException
// {
// if (policy != null)
// {
@@ -807,7 +808,7 @@ public class X509CertSelector implements CertSelector, Cloneable
// }
// FIXME
-// public void setPathToNames(Collection names) throws IOException
+// public void setPathToNames(Collection<List<?>> names) throws IOException
// {
// if (names == null)
// {
@@ -843,19 +844,19 @@ public class X509CertSelector implements CertSelector, Cloneable
// }
// FIXME
-// public Collection getSubjectAlternativeNames()
+// public Collection<List<?>> getSubjectAlternativeNames()
// {
// return null;
// }
// FIXME
-// public Set getPolicy()
+// public Set<String> getPolicy()
// {
// return null;
// }
// FIXME
-// public Collection getPathToNames()
+// public Collection<List<?>> getPathToNames()
// {
// return null;
// }
diff --git a/java/security/cert/X509Certificate.java b/java/security/cert/X509Certificate.java
index f6c6fcfb9..bc1b5c235 100644
--- a/java/security/cert/X509Certificate.java
+++ b/java/security/cert/X509Certificate.java
@@ -41,6 +41,7 @@ package java.security.cert;
import java.math.BigInteger;
import java.security.Principal;
import java.util.Date;
+import java.util.List;
/**
* X509Certificate is the abstract class for X.509 certificates.
@@ -131,7 +132,7 @@ import java.util.Date;
* Profile</a></i>.</li>
* </ol>
*
- * @since JDK 1.2
+ * @since 1.2
* @author Mark Benvenuto
* @author Casey Marshall (rsdio@metastatic.org)
*/
@@ -487,7 +488,7 @@ public abstract class X509Certificate
* @throws CertificateParsingException If this extension cannot be
* parsed from its encoded form.
*/
- public java.util.List getExtendedKeyUsage()
+ public java.util.List<String> getExtendedKeyUsage()
throws CertificateParsingException
{
throw new UnsupportedOperationException();
@@ -531,7 +532,7 @@ public abstract class X509Certificate
* be parsed.
* @since JDK 1.4
*/
- public java.util.Collection getSubjectAlternativeNames()
+ public java.util.Collection<List<?>> getSubjectAlternativeNames()
throws CertificateParsingException
{
throw new UnsupportedOperationException();
@@ -558,7 +559,7 @@ public abstract class X509Certificate
* be parsed.
* @since JDK 1.4
*/
- public java.util.Collection getIssuerAlternativeNames()
+ public java.util.Collection<List<?>> getIssuerAlternativeNames()
throws CertificateParsingException
{
throw new UnsupportedOperationException();
diff --git a/java/security/cert/X509Extension.java b/java/security/cert/X509Extension.java
index d2cb80a9f..bd9473782 100644
--- a/java/security/cert/X509Extension.java
+++ b/java/security/cert/X509Extension.java
@@ -70,7 +70,7 @@ import java.util.Set;
@author Mark Benvenuto
- @since JDK 1.2
+ @since 1.2
*/
public interface X509Extension
{
@@ -91,7 +91,7 @@ public interface X509Extension
@return A Set containing the OIDs. If there are no CRITICAL
extensions or extensions at all this returns null.
*/
- Set getCriticalExtensionOIDs();
+ Set<String> getCriticalExtensionOIDs();
/**
Returns a set of the NON-CRITICAL extension OIDs from the
@@ -101,7 +101,7 @@ public interface X509Extension
@return A Set containing the OIDs. If there are no NON-CRITICAL
extensions or extensions at all this returns null.
*/
- Set getNonCriticalExtensionOIDs();
+ Set<String> getNonCriticalExtensionOIDs();
/**
Returns the DER encoded OCTET string for the specified
diff --git a/java/sql/Array.java b/java/sql/Array.java
index c3c42d9cb..cdd60a42f 100644
--- a/java/sql/Array.java
+++ b/java/sql/Array.java
@@ -84,7 +84,7 @@ public interface Array
* @return The contents of the array as an array of Java objects.
* @exception SQLException If an error occurs.
*/
- Object getArray(Map map) throws SQLException;
+ Object getArray(Map<String, Class<?>> map) throws SQLException;
/**
* Returns a portion of this array starting at <code>start</code>
@@ -94,7 +94,7 @@ public interface Array
* The object returned will be an array of Java objects of
* the appropriate types.
*
- * @param start The index into this array to start returning elements from.
+ * @param start The offset into this array to start returning elements from.
* @param count The requested number of elements to return.
* @return The requested portion of the array.
* @exception SQLException If an error occurs.
@@ -110,13 +110,14 @@ public interface Array
* <code>Map</code> will be used for overriding selected SQL type to
* Java class mappings.
*
- * @param start The index into this array to start returning elements from.
+ * @param start The offset into this array to start returning elements from.
* @param count The requested number of elements to return.
* @param map A mapping of SQL types to Java classes.
* @return The requested portion of the array.
* @exception SQLException If an error occurs.
*/
- Object getArray(long start, int count, Map map) throws SQLException;
+ Object getArray(long start, int count, Map<String, Class<?>> map)
+ throws SQLException;
/**
* Returns the elements in the array as a <code>ResultSet</code>.
@@ -143,7 +144,7 @@ public interface Array
* @exception SQLException If an error occurs.
* @see ResultSet
*/
- ResultSet getResultSet(Map map) throws SQLException;
+ ResultSet getResultSet(Map<String, Class<?>> map) throws SQLException;
/**
* This method returns a portion of the array as a <code>ResultSet</code>.
@@ -180,6 +181,6 @@ public interface Array
* @exception SQLException If an error occurs.
* @see ResultSet
*/
- ResultSet getResultSet(long start, int count, Map map)
+ ResultSet getResultSet(long start, int count, Map<String, Class<?>> map)
throws SQLException;
}
diff --git a/java/sql/CallableStatement.java b/java/sql/CallableStatement.java
index 75eade774..e605b381d 100644
--- a/java/sql/CallableStatement.java
+++ b/java/sql/CallableStatement.java
@@ -250,7 +250,7 @@ public interface CallableStatement extends PreparedStatement
* @exception SQLException If an error occurs.
* @since 1.2
*/
- Object getObject(int index, Map map) throws SQLException;
+ Object getObject(int index, Map<String, Class<?>> map) throws SQLException;
/**
* This method returns the value of the specified parameter as a Java
@@ -865,7 +865,7 @@ public interface CallableStatement extends PreparedStatement
* @exception SQLException If an error occurs.
* @since 1.4
*/
- Object getObject(String name, Map map) throws SQLException;
+ Object getObject(String name, Map<String, Class<?>> map) throws SQLException;
/**
* This method returns the value of the specified parameter as a Java
diff --git a/java/sql/Connection.java b/java/sql/Connection.java
index d827e75b0..8dc7544c7 100644
--- a/java/sql/Connection.java
+++ b/java/sql/Connection.java
@@ -339,7 +339,7 @@ public interface Connection
* @return The SQL type to Java class mapping.
* @exception SQLException If an error occurs.
*/
- Map getTypeMap() throws SQLException;
+ Map<String, Class<?>> getTypeMap() throws SQLException;
/**
* This method sets the mapping table for SQL types to Java classes.
@@ -348,7 +348,7 @@ public interface Connection
* @param map The new SQL mapping table.
* @exception SQLException If an error occurs.
*/
- void setTypeMap(Map map) throws SQLException;
+ void setTypeMap(Map<String, Class<?>> map) throws SQLException;
/**
* Sets the default holdability of <code>ResultSet</code>S that are created
diff --git a/java/sql/DriverManager.java b/java/sql/DriverManager.java
index 94f743b92..7d1ef07c1 100644
--- a/java/sql/DriverManager.java
+++ b/java/sql/DriverManager.java
@@ -264,7 +264,7 @@ public class DriverManager
*
* @return An <code>Enumeration</code> of all currently loaded JDBC drivers.
*/
- public static Enumeration getDrivers()
+ public static Enumeration<Driver> getDrivers()
{
Vector v = new Vector();
Enumeration e = drivers.elements();
diff --git a/java/sql/Ref.java b/java/sql/Ref.java
index 4ebd5e648..c5c54eefe 100644
--- a/java/sql/Ref.java
+++ b/java/sql/Ref.java
@@ -61,7 +61,7 @@ public interface Ref
/**
* @since 1.4
*/
- Object getObject(Map map) throws SQLException;
+ Object getObject(Map<String, Class<?>> map) throws SQLException;
/**
* @since 1.4
diff --git a/java/sql/ResultSet.java b/java/sql/ResultSet.java
index 79cba63d4..573deb3e1 100644
--- a/java/sql/ResultSet.java
+++ b/java/sql/ResultSet.java
@@ -1309,7 +1309,8 @@ public interface ResultSet
* @return The value of the column as an <code>Object</code>.
* @exception SQLException If an error occurs.
*/
- Object getObject(int columnIndex, Map map) throws SQLException;
+ Object getObject(int columnIndex, Map<String, Class<?>> map)
+ throws SQLException;
/**
* This method returns a <code>Ref</code> for the specified column which
@@ -1357,7 +1358,8 @@ public interface ResultSet
* @return The value of the column as an <code>Object</code>.
* @exception SQLException If an error occurs.
*/
- Object getObject(String columnName, Map map) throws SQLException;
+ Object getObject(String columnName, Map<String, Class<?>> map)
+ throws SQLException;
/**
* This method returns a <code>Ref</code> for the specified column which
diff --git a/java/sql/Struct.java b/java/sql/Struct.java
index 5cbc88e13..ce8db22bb 100644
--- a/java/sql/Struct.java
+++ b/java/sql/Struct.java
@@ -73,5 +73,5 @@ public interface Struct
* @return The attributes of this structure type.
* @exception SQLException If a error occurs.
*/
- Object[] getAttributes(Map map) throws SQLException;
+ Object[] getAttributes(Map<String, Class<?>> map) throws SQLException;
}
diff --git a/java/sql/Timestamp.java b/java/sql/Timestamp.java
index 66a57641a..18ccda557 100644
--- a/java/sql/Timestamp.java
+++ b/java/sql/Timestamp.java
@@ -1,5 +1,5 @@
/* Time.java -- Wrapper around java.util.Date
- Copyright (C) 1999, 2000, 2003, 2004, 2006 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2000, 2003, 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -312,7 +312,7 @@ public class Timestamp extends java.util.Date
* @see #compareTo(Timestamp)
* @since 1.2
*/
- public int compareTo(Object obj)
+ public int compareTo(java.util.Date obj)
{
return compareTo((Timestamp) obj);
}
diff --git a/java/text/AttributedCharacterIterator.java b/java/text/AttributedCharacterIterator.java
index 7eb073069..4f9c762b3 100644
--- a/java/text/AttributedCharacterIterator.java
+++ b/java/text/AttributedCharacterIterator.java
@@ -56,6 +56,7 @@ import java.util.Set;
* @since 1.2
*
* @author Aaron M. Renn (arenn@urbanophile.com)
+ * @since 1.2
*/
public interface AttributedCharacterIterator extends CharacterIterator
{
@@ -194,7 +195,7 @@ public interface AttributedCharacterIterator extends CharacterIterator
*
* @return A list of keys
*/
- Set getAllAttributeKeys();
+ Set<Attribute> getAllAttributeKeys();
/**
* Returns a <code>Map</code> of the attributes defined for the current
@@ -202,7 +203,7 @@ public interface AttributedCharacterIterator extends CharacterIterator
*
* @return A <code>Map</code> of the attributes for the current character.
*/
- Map getAttributes();
+ Map<Attribute, Object> getAttributes();
/**
* Returns the value of the specified attribute for the
@@ -232,7 +233,7 @@ public interface AttributedCharacterIterator extends CharacterIterator
*
* @return The start index of the run.
*/
- int getRunStart(Set attribs);
+ int getRunStart(Set<? extends Attribute> attribs);
/**
* Returns the index of the first character in the run that
@@ -261,7 +262,7 @@ public interface AttributedCharacterIterator extends CharacterIterator
*
* @return The end index of the run.
*/
- int getRunLimit(Set attribs);
+ int getRunLimit(Set<? extends Attribute> attribs);
/**
* Returns the index of the character after the end of the run
diff --git a/java/text/AttributedString.java b/java/text/AttributedString.java
index d2bc34408..6785bd3c5 100644
--- a/java/text/AttributedString.java
+++ b/java/text/AttributedString.java
@@ -54,6 +54,7 @@ import java.util.Set;
* @since 1.2
*
* @author Aaron M. Renn (arenn@urbanophile.com)
+ * @since 1.2
*/
public class AttributedString
{
@@ -118,7 +119,8 @@ public class AttributedString
* @param str The <code>String</code> to be attributed.
* @param attributes The attribute list.
*/
- public AttributedString(String str, Map attributes)
+ public AttributedString(String str,
+ Map<? extends AttributedCharacterIterator.Attribute, ?> attributes)
{
this(str);
@@ -299,7 +301,8 @@ public class AttributedString
* <code>null</code>.
* @throws IllegalArgumentException if the subrange is not valid.
*/
- public void addAttributes(Map attributes, int beginIndex, int endIndex)
+ public void addAttributes(Map<? extends AttributedCharacterIterator.Attribute, ?> attributes,
+ int beginIndex, int endIndex)
{
if (attributes == null)
throw new NullPointerException("null attribute");
diff --git a/java/text/CollationKey.java b/java/text/CollationKey.java
index a467869b8..12ad970e1 100644
--- a/java/text/CollationKey.java
+++ b/java/text/CollationKey.java
@@ -65,7 +65,7 @@ import java.util.Arrays;
* @author Tom Tromey (tromey@cygnus.com)
* @date March 25, 1999
*/
-public final class CollationKey implements Comparable
+public final class CollationKey implements Comparable<CollationKey>
{
/**
* This is the <code>Collator</code> this object was created from.
@@ -112,21 +112,6 @@ public final class CollationKey implements Comparable
}
/**
- * This method compares the specified object to this one. The specified
- * object must be an instance of <code>CollationKey</code> or an exception
- * will be thrown. An integer is returned which indicates whether the
- * specified object is less than, greater than, or equal to this object.
- *
- * @param obj The <code>Object</code> to compare against this one.
- *
- * @return A negative integer if this object is less than the specified object, 0 if it is equal or a positive integer if it is greater than the specified object.
- */
- public int compareTo (Object obj)
- {
- return compareTo ((CollationKey) obj);
- }
-
- /**
* This method tests the specified <code>Object</code> for equality with
* this object. This will be true if and only if:
* <p>
diff --git a/java/text/Collator.java b/java/text/Collator.java
index 08739163a..952361324 100644
--- a/java/text/Collator.java
+++ b/java/text/Collator.java
@@ -70,7 +70,7 @@ import java.util.ResourceBundle;
* @author Aaron M. Renn (arenn@urbanophile.com)
* @date March 18, 1999
*/
-public abstract class Collator implements Comparator, Cloneable
+public abstract class Collator implements Comparator<Object>, Cloneable
{
/**
* This constant is a strength value which indicates that only primary
diff --git a/java/text/MessageFormat.java b/java/text/MessageFormat.java
index f59cfd5ca..3d428ac7e 100644
--- a/java/text/MessageFormat.java
+++ b/java/text/MessageFormat.java
@@ -396,7 +396,7 @@ public class MessageFormat extends Format
* @param pattern The pattern used when formatting.
* @param arguments The array containing the objects to be formatted.
*/
- public static String format (String pattern, Object arguments[])
+ public static String format (String pattern, Object... arguments)
{
MessageFormat mf = new MessageFormat (pattern);
StringBuffer sb = new StringBuffer ();
diff --git a/java/text/NumberFormat.java b/java/text/NumberFormat.java
index 1fd71bf04..1bef97ffe 100644
--- a/java/text/NumberFormat.java
+++ b/java/text/NumberFormat.java
@@ -222,8 +222,11 @@ public abstract class NumberFormat extends Format implements Cloneable
return sbuf.toString();
}
+ /**
+ * @specnote this method was final in releases before 1.5
+ */
public StringBuffer format (Object obj, StringBuffer sbuf,
- FieldPosition pos)
+ FieldPosition pos)
{
if (obj instanceof Number)
return format(((Number) obj).doubleValue(), sbuf, pos);
diff --git a/java/util/AbstractCollection.java b/java/util/AbstractCollection.java
index 3ae98e073..ef7434223 100644
--- a/java/util/AbstractCollection.java
+++ b/java/util/AbstractCollection.java
@@ -1,5 +1,5 @@
/* AbstractCollection.java -- Abstract implementation of most of Collection
- Copyright (C) 1998, 2000, 2001, 2005 Free Software Foundation, Inc.
+ Copyright (C) 1998, 2000, 2001, 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -62,13 +62,16 @@ import java.lang.reflect.Array;
* @author Original author unknown
* @author Bryce McKinlay
* @author Eric Blake (ebb9@email.byu.edu)
+ * @author Tom Tromey (tromey@redhat.com)
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
* @see Collection
* @see AbstractSet
* @see AbstractList
* @since 1.2
* @status updated to 1.4
*/
-public abstract class AbstractCollection implements Collection
+public abstract class AbstractCollection<E>
+ implements Collection<E>, Iterable<E>
{
/**
* The main constructor, for use by subclasses.
@@ -84,7 +87,7 @@ public abstract class AbstractCollection implements Collection
*
* @return an iterator
*/
- public abstract Iterator iterator();
+ public abstract Iterator<E> iterator();
/**
* Return the number of elements in this collection. If there are more than
@@ -110,7 +113,7 @@ public abstract class AbstractCollection implements Collection
* @throws IllegalArgumentException if some aspect of the object prevents
* it from being added
*/
- public boolean add(Object o)
+ public boolean add(E o)
{
throw new UnsupportedOperationException();
}
@@ -138,9 +141,9 @@ public abstract class AbstractCollection implements Collection
* collection doesn't allow null values.
* @see #add(Object)
*/
- public boolean addAll(Collection c)
+ public boolean addAll(Collection<? extends E> c)
{
- Iterator itr = c.iterator();
+ Iterator<? extends E> itr = c.iterator();
boolean modified = false;
int pos = c.size();
while (--pos >= 0)
@@ -162,7 +165,7 @@ public abstract class AbstractCollection implements Collection
*/
public void clear()
{
- Iterator itr = iterator();
+ Iterator<E> itr = iterator();
int pos = size();
while (--pos >= 0)
{
@@ -184,7 +187,7 @@ public abstract class AbstractCollection implements Collection
*/
public boolean contains(Object o)
{
- Iterator itr = iterator();
+ Iterator<E> itr = iterator();
int pos = size();
while (--pos >= 0)
if (equals(o, itr.next()))
@@ -204,9 +207,9 @@ public abstract class AbstractCollection implements Collection
* @throws NullPointerException if the given collection is null
* @see #contains(Object)
*/
- public boolean containsAll(Collection c)
+ public boolean containsAll(Collection<?> c)
{
- Iterator itr = c.iterator();
+ Iterator<?> itr = c.iterator();
int pos = c.size();
while (--pos >= 0)
if (!contains(itr.next()))
@@ -247,7 +250,7 @@ public abstract class AbstractCollection implements Collection
*/
public boolean remove(Object o)
{
- Iterator itr = iterator();
+ Iterator<E> itr = iterator();
int pos = size();
while (--pos >= 0)
if (equals(o, itr.next()))
@@ -273,7 +276,7 @@ public abstract class AbstractCollection implements Collection
* @throws NullPointerException if the collection, c, is null.
* @see Iterator#remove()
*/
- public boolean removeAll(Collection c)
+ public boolean removeAll(Collection<?> c)
{
return removeAllInternal(c);
}
@@ -295,9 +298,9 @@ public abstract class AbstractCollection implements Collection
* @see Iterator#remove()
*/
// Package visible for use throughout java.util.
- boolean removeAllInternal(Collection c)
+ boolean removeAllInternal(Collection<?> c)
{
- Iterator itr = iterator();
+ Iterator<E> itr = iterator();
boolean modified = false;
int pos = size();
while (--pos >= 0)
@@ -324,7 +327,7 @@ public abstract class AbstractCollection implements Collection
* @throws NullPointerException if the collection, c, is null.
* @see Iterator#remove()
*/
- public boolean retainAll(Collection c)
+ public boolean retainAll(Collection<?> c)
{
return retainAllInternal(c);
}
@@ -347,9 +350,9 @@ public abstract class AbstractCollection implements Collection
* @see Iterator#remove()
*/
// Package visible for use throughout java.util.
- boolean retainAllInternal(Collection c)
+ boolean retainAllInternal(Collection<?> c)
{
- Iterator itr = iterator();
+ Iterator<E> itr = iterator();
boolean modified = false;
int pos = size();
while (--pos >= 0)
@@ -372,7 +375,7 @@ public abstract class AbstractCollection implements Collection
*/
public Object[] toArray()
{
- Iterator itr = iterator();
+ Iterator<E> itr = iterator();
int size = size();
Object[] a = new Object[size];
for (int pos = 0; pos < size; pos++)
@@ -402,19 +405,18 @@ public abstract class AbstractCollection implements Collection
* @throws ArrayStoreException if the type of the array precludes holding
* one of the elements of the Collection
*/
- public Object[] toArray(Object[] a)
+ public <T> T[] toArray(T[] a)
{
int size = size();
if (a.length < size)
- a = (Object[]) Array.newInstance(a.getClass().getComponentType(),
+ a = (T[]) Array.newInstance(a.getClass().getComponentType(),
size);
else if (a.length > size)
a[size] = null;
- Iterator itr = iterator();
+ Iterator<E> itr = iterator();
for (int pos = 0; pos < size; pos++)
- a[pos] = itr.next();
-
+ a[pos] = (T) (itr.next());
return a;
}
diff --git a/java/util/AbstractList.java b/java/util/AbstractList.java
index 114712eee..c47b59b21 100644
--- a/java/util/AbstractList.java
+++ b/java/util/AbstractList.java
@@ -1,5 +1,6 @@
/* AbstractList.java -- Abstract implementation of most of List
- Copyright (C) 1998, 1999, 2000, 2001, 2002, 2005 Free Software Foundation, Inc.
+ Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004, 2005
+ Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -68,7 +69,9 @@ package java.util;
* @since 1.2
* @status updated to 1.4
*/
-public abstract class AbstractList extends AbstractCollection implements List
+public abstract class AbstractList<E>
+ extends AbstractCollection<E>
+ implements List<E>
{
/**
* A count of the number of structural modifications that have been made to
@@ -101,7 +104,7 @@ public abstract class AbstractList extends AbstractCollection implements List
* @return the element at that position
* @throws IndexOutOfBoundsException if index &lt; 0 || index &gt;= size()
*/
- public abstract Object get(int index);
+ public abstract E get(int index);
/**
* Insert an element into the list at a given position (optional operation).
@@ -123,7 +126,7 @@ public abstract class AbstractList extends AbstractCollection implements List
* some other reason
* @see #modCount
*/
- public void add(int index, Object o)
+ public void add(int index, E o)
{
throw new UnsupportedOperationException();
}
@@ -144,7 +147,7 @@ public abstract class AbstractList extends AbstractCollection implements List
* some other reason
* @see #add(int, Object)
*/
- public boolean add(Object o)
+ public boolean add(E o)
{
add(size(), o);
return true;
@@ -173,9 +176,9 @@ public abstract class AbstractList extends AbstractCollection implements List
* @throws NullPointerException if the specified collection is null
* @see #add(int, Object)
*/
- public boolean addAll(int index, Collection c)
+ public boolean addAll(int index, Collection<? extends E> c)
{
- Iterator itr = c.iterator();
+ Iterator<? extends E> itr = c.iterator();
int size = c.size();
for (int pos = size; pos > 0; pos--)
add(index++, itr.next());
@@ -227,7 +230,7 @@ public abstract class AbstractList extends AbstractCollection implements List
if (size != ((List) o).size())
return false;
- Iterator itr1 = iterator();
+ Iterator<E> itr1 = iterator();
Iterator itr2 = ((List) o).iterator();
while (--size >= 0)
@@ -259,7 +262,7 @@ while (i.hasNext())
public int hashCode()
{
int hashCode = 1;
- Iterator itr = iterator();
+ Iterator<E> itr = iterator();
int pos = size();
while (--pos >= 0)
hashCode = 31 * hashCode + hashCode(itr.next());
@@ -277,7 +280,7 @@ while (i.hasNext())
*/
public int indexOf(Object o)
{
- ListIterator itr = listIterator();
+ ListIterator<E> itr = listIterator();
int size = size();
for (int pos = 0; pos < size; pos++)
if (equals(o, itr.next()))
@@ -297,10 +300,10 @@ while (i.hasNext())
* @return an Iterator over the elements of this list, in order
* @see #modCount
*/
- public Iterator iterator()
+ public Iterator<E> iterator()
{
// Bah, Sun's implementation forbids using listIterator(0).
- return new Iterator()
+ return new Iterator<E>()
{
private int pos = 0;
private int size = size();
@@ -342,7 +345,7 @@ while (i.hasNext())
* @throws ConcurrentModificationException if the
* list has been modified elsewhere.
*/
- public Object next()
+ public E next()
{
checkMod();
if (pos == size)
@@ -388,7 +391,7 @@ while (i.hasNext())
public int lastIndexOf(Object o)
{
int pos = size();
- ListIterator itr = listIterator(pos);
+ ListIterator<E> itr = listIterator(pos);
while (--pos >= 0)
if (equals(o, itr.previous()))
return pos;
@@ -402,7 +405,7 @@ while (i.hasNext())
* @return a ListIterator over the elements of this list, in order, starting
* at the beginning
*/
- public ListIterator listIterator()
+ public ListIterator<E> listIterator()
{
return listIterator(0);
}
@@ -425,13 +428,13 @@ while (i.hasNext())
* @throws IndexOutOfBoundsException if index &lt; 0 || index &gt; size()
* @see #modCount
*/
- public ListIterator listIterator(final int index)
+ public ListIterator<E> listIterator(final int index)
{
if (index < 0 || index > size())
throw new IndexOutOfBoundsException("Index: " + index + ", Size:"
+ size());
- return new ListIterator()
+ return new ListIterator<E>()
{
private int knownMod = modCount;
private int position = index;
@@ -485,7 +488,7 @@ while (i.hasNext())
* @throws ConcurrentModificationException if the
* list has been modified elsewhere.
*/
- public Object next()
+ public E next()
{
checkMod();
if (position == size)
@@ -503,7 +506,7 @@ while (i.hasNext())
* @throws ConcurrentModificationException if the
* list has been modified elsewhere.
*/
- public Object previous()
+ public E previous()
{
checkMod();
if (position == 0)
@@ -577,7 +580,7 @@ while (i.hasNext())
* @throws ConcurrentModificationException if the list
* has been modified elsewhere.
*/
- public void set(Object o)
+ public void set(E o)
{
checkMod();
if (lastReturned < 0)
@@ -599,7 +602,7 @@ while (i.hasNext())
* @throws ConcurrentModificationException if the list
* has been modified elsewhere.
*/
- public void add(Object o)
+ public void add(E o)
{
checkMod();
AbstractList.this.add(position++, o);
@@ -624,7 +627,7 @@ while (i.hasNext())
* @throws IndexOutOfBoundsException if index &lt; 0 || index &gt;= size()
* @see #modCount
*/
- public Object remove(int index)
+ public E remove(int index)
{
throw new UnsupportedOperationException();
}
@@ -650,7 +653,7 @@ while (i.hasNext())
*/
protected void removeRange(int fromIndex, int toIndex)
{
- ListIterator itr = listIterator(fromIndex);
+ ListIterator<E> itr = listIterator(fromIndex);
for (int index = fromIndex; index < toIndex; index++)
{
itr.next();
@@ -673,7 +676,7 @@ while (i.hasNext())
* @throws IllegalArgumentException if o cannot be added to this list for
* some other reason
*/
- public Object set(int index, Object o)
+ public E set(int index, E o)
{
throw new UnsupportedOperationException();
}
@@ -722,7 +725,7 @@ while (i.hasNext())
* @see ConcurrentModificationException
* @see RandomAccess
*/
- public List subList(int fromIndex, int toIndex)
+ public List<E> subList(int fromIndex, int toIndex)
{
// This follows the specification of AbstractList, but is inconsistent
// with the one in List. Don't you love Sun's inconsistencies?
@@ -732,8 +735,8 @@ while (i.hasNext())
throw new IndexOutOfBoundsException();
if (this instanceof RandomAccess)
- return new RandomAccessSubList(this, fromIndex, toIndex);
- return new SubList(this, fromIndex, toIndex);
+ return new RandomAccessSubList<E>(this, fromIndex, toIndex);
+ return new SubList<E>(this, fromIndex, toIndex);
}
/**
@@ -744,16 +747,16 @@ while (i.hasNext())
* @author Original author unknown
* @author Eric Blake (ebb9@email.byu.edu)
*/
- private static class SubList extends AbstractList
+ private static class SubList<E> extends AbstractList<E>
{
// Package visible, for use by iterator.
/** The original list. */
- final AbstractList backingList;
+ final AbstractList<E> backingList;
/** The index of the first element of the sublist. */
final int offset;
/** The size of the sublist. */
int size;
-
+
/**
* Construct the sublist.
*
@@ -761,14 +764,14 @@ while (i.hasNext())
* @param fromIndex the lower bound, inclusive
* @param toIndex the upper bound, exclusive
*/
- SubList(AbstractList backing, int fromIndex, int toIndex)
+ SubList(AbstractList<E> backing, int fromIndex, int toIndex)
{
backingList = backing;
modCount = backing.modCount;
offset = fromIndex;
size = toIndex - fromIndex;
}
-
+
/**
* This method checks the two modCount fields to ensure that there has
* not been a concurrent modification, returning if all is okay.
@@ -780,9 +783,9 @@ while (i.hasNext())
void checkMod()
{
if (modCount != backingList.modCount)
- throw new ConcurrentModificationException();
+ throw new ConcurrentModificationException();
}
-
+
/**
* This method checks that a value is between 0 and size (inclusive). If
* it is not, an exception is thrown.
@@ -794,10 +797,10 @@ while (i.hasNext())
private void checkBoundsInclusive(int index)
{
if (index < 0 || index > size)
- throw new IndexOutOfBoundsException("Index: " + index + ", Size:"
- + size);
+ throw new IndexOutOfBoundsException("Index: " + index + ", Size:"
+ + size);
}
-
+
/**
* This method checks that a value is between 0 (inclusive) and size
* (exclusive). If it is not, an exception is thrown.
@@ -809,10 +812,10 @@ while (i.hasNext())
private void checkBoundsExclusive(int index)
{
if (index < 0 || index >= size)
- throw new IndexOutOfBoundsException("Index: " + index + ", Size:"
- + size);
+ throw new IndexOutOfBoundsException("Index: " + index + ", Size:"
+ + size);
}
-
+
/**
* Specified by AbstractList.subList to return the private field size.
*
@@ -825,7 +828,7 @@ while (i.hasNext())
checkMod();
return size;
}
-
+
/**
* Specified by AbstractList.subList to delegate to the backing list.
*
@@ -842,13 +845,13 @@ while (i.hasNext())
* @throws IllegalArgumentException if o cannot be added to the backing list
* for some other reason
*/
- public Object set(int index, Object o)
+ public E set(int index, E o)
{
checkMod();
checkBoundsExclusive(index);
return backingList.set(index + offset, o);
}
-
+
/**
* Specified by AbstractList.subList to delegate to the backing list.
*
@@ -858,13 +861,13 @@ while (i.hasNext())
* modified externally to this sublist
* @throws IndexOutOfBoundsException if index &lt; 0 || index &gt;= size()
*/
- public Object get(int index)
+ public E get(int index)
{
checkMod();
checkBoundsExclusive(index);
return backingList.get(index + offset);
}
-
+
/**
* Specified by AbstractList.subList to delegate to the backing list.
*
@@ -880,7 +883,7 @@ while (i.hasNext())
* @throws IllegalArgumentException if o cannot be added to the backing
* list for some other reason.
*/
- public void add(int index, Object o)
+ public void add(int index, E o)
{
checkMod();
checkBoundsInclusive(index);
@@ -888,7 +891,7 @@ while (i.hasNext())
size++;
modCount = backingList.modCount;
}
-
+
/**
* Specified by AbstractList.subList to delegate to the backing list.
*
@@ -900,16 +903,16 @@ while (i.hasNext())
* @throws UnsupportedOperationException if the backing list does not
* support the remove operation
*/
- public Object remove(int index)
+ public E remove(int index)
{
checkMod();
checkBoundsExclusive(index);
- Object o = backingList.remove(index + offset);
+ E o = backingList.remove(index + offset);
size--;
modCount = backingList.modCount;
return o;
}
-
+
/**
* Specified by AbstractList.subList to delegate to the backing list.
* This does no bounds checking, as it assumes it will only be called
@@ -925,12 +928,12 @@ while (i.hasNext())
protected void removeRange(int fromIndex, int toIndex)
{
checkMod();
-
+
backingList.removeRange(offset + fromIndex, offset + toIndex);
size -= toIndex - fromIndex;
modCount = backingList.modCount;
}
-
+
/**
* Specified by AbstractList.subList to delegate to the backing list.
*
@@ -948,7 +951,7 @@ while (i.hasNext())
* to this list for some other reason
* @throws NullPointerException if the specified collection is null
*/
- public boolean addAll(int index, Collection c)
+ public boolean addAll(int index, Collection<? extends E> c)
{
checkMod();
checkBoundsInclusive(index);
@@ -958,7 +961,7 @@ while (i.hasNext())
modCount = backingList.modCount;
return result;
}
-
+
/**
* Specified by AbstractList.subList to return addAll(size, c).
*
@@ -974,21 +977,21 @@ while (i.hasNext())
* to this list for some other reason
* @throws NullPointerException if the specified collection is null
*/
- public boolean addAll(Collection c)
+ public boolean addAll(Collection<? extends E> c)
{
return addAll(size, c);
}
-
+
/**
* Specified by AbstractList.subList to return listIterator().
*
* @return an iterator over the sublist
*/
- public Iterator iterator()
+ public Iterator<E> iterator()
{
return listIterator();
}
-
+
/**
* Specified by AbstractList.subList to return a wrapper around the
* backing list's iterator.
@@ -999,179 +1002,180 @@ while (i.hasNext())
* modified externally to this sublist
* @throws IndexOutOfBoundsException if the value is out of range
*/
- public ListIterator listIterator(final int index)
+ public ListIterator<E> listIterator(final int index)
{
checkMod();
checkBoundsInclusive(index);
-
- return new ListIterator()
- {
- private final ListIterator i = backingList.listIterator(index + offset);
- private int position = index;
-
- /**
- * Tests to see if there are any more objects to
- * return.
- *
- * @return True if the end of the list has not yet been
- * reached.
- */
- public boolean hasNext()
- {
- return position < size;
- }
-
- /**
- * Tests to see if there are objects prior to the
- * current position in the list.
- *
- * @return True if objects exist prior to the current
- * position of the iterator.
- */
- public boolean hasPrevious()
- {
- return position > 0;
- }
-
- /**
- * Retrieves the next object from the list.
- *
- * @return The next object.
- * @throws NoSuchElementException if there are no
- * more objects to retrieve.
- * @throws ConcurrentModificationException if the
- * list has been modified elsewhere.
- */
- public Object next()
- {
- if (position == size)
- throw new NoSuchElementException();
- position++;
- return i.next();
- }
-
- /**
- * Retrieves the previous object from the list.
- *
- * @return The next object.
- * @throws NoSuchElementException if there are no
- * previous objects to retrieve.
- * @throws ConcurrentModificationException if the
- * list has been modified elsewhere.
- */
- public Object previous()
- {
- if (position == 0)
- throw new NoSuchElementException();
- position--;
- return i.previous();
- }
-
- /**
- * Returns the index of the next element in the
- * list, which will be retrieved by <code>next()</code>
- *
- * @return The index of the next element.
- */
- public int nextIndex()
- {
- return i.nextIndex() - offset;
- }
-
- /**
- * Returns the index of the previous element in the
- * list, which will be retrieved by <code>previous()</code>
- *
- * @return The index of the previous element.
- */
- public int previousIndex()
- {
- return i.previousIndex() - offset;
- }
-
- /**
- * Removes the last object retrieved by <code>next()</code>
- * from the list, if the list supports object removal.
- *
- * @throws IllegalStateException if the iterator is positioned
- * before the start of the list or the last object has already
- * been removed.
- * @throws UnsupportedOperationException if the list does
- * not support removing elements.
- */
- public void remove()
- {
- i.remove();
- size--;
- position = nextIndex();
- modCount = backingList.modCount;
- }
-
-
- /**
- * Replaces the last object retrieved by <code>next()</code>
- * or <code>previous</code> with o, if the list supports object
- * replacement and an add or remove operation has not already
- * been performed.
- *
- * @throws IllegalStateException if the iterator is positioned
- * before the start of the list or the last object has already
- * been removed.
- * @throws UnsupportedOperationException if the list doesn't support
- * the addition or removal of elements.
- * @throws ClassCastException if the type of o is not a valid type
- * for this list.
- * @throws IllegalArgumentException if something else related to o
- * prevents its addition.
- * @throws ConcurrentModificationException if the list
- * has been modified elsewhere.
- */
- public void set(Object o)
- {
- i.set(o);
- }
-
- /**
- * Adds the supplied object before the element that would be returned
- * by a call to <code>next()</code>, if the list supports addition.
- *
- * @param o The object to add to the list.
- * @throws UnsupportedOperationException if the list doesn't support
- * the addition of new elements.
- * @throws ClassCastException if the type of o is not a valid type
- * for this list.
- * @throws IllegalArgumentException if something else related to o
- * prevents its addition.
- * @throws ConcurrentModificationException if the list
- * has been modified elsewhere.
- */
- public void add(Object o)
- {
- i.add(o);
- size++;
- position++;
- modCount = backingList.modCount;
- }
-
- // Here is the reason why the various modCount fields are mostly
- // ignored in this wrapper listIterator.
- // If the backing listIterator is failfast, then the following holds:
- // Using any other method on this list will call a corresponding
- // method on the backing list *after* the backing listIterator
- // is created, which will in turn cause a ConcurrentModException
- // when this listIterator comes to use the backing one. So it is
- // implicitly failfast.
- // If the backing listIterator is NOT failfast, then the whole of
- // this list isn't failfast, because the modCount field of the
- // backing list is not valid. It would still be *possible* to
- // make the iterator failfast wrt modifications of the sublist
- // only, but somewhat pointless when the list can be changed under
- // us.
- // Either way, no explicit handling of modCount is needed.
- // However modCount = backingList.modCount must be executed in add
- // and remove, and size must also be updated in these two methods,
- // since they do not go through the corresponding methods of the subList.
- };
+
+ return new ListIterator<E>()
+ {
+ private final ListIterator<E> i
+ = backingList.listIterator(index + offset);
+ private int position = index;
+
+ /**
+ * Tests to see if there are any more objects to
+ * return.
+ *
+ * @return True if the end of the list has not yet been
+ * reached.
+ */
+ public boolean hasNext()
+ {
+ return position < size;
+ }
+
+ /**
+ * Tests to see if there are objects prior to the
+ * current position in the list.
+ *
+ * @return True if objects exist prior to the current
+ * position of the iterator.
+ */
+ public boolean hasPrevious()
+ {
+ return position > 0;
+ }
+
+ /**
+ * Retrieves the next object from the list.
+ *
+ * @return The next object.
+ * @throws NoSuchElementException if there are no
+ * more objects to retrieve.
+ * @throws ConcurrentModificationException if the
+ * list has been modified elsewhere.
+ */
+ public E next()
+ {
+ if (position == size)
+ throw new NoSuchElementException();
+ position++;
+ return i.next();
+ }
+
+ /**
+ * Retrieves the previous object from the list.
+ *
+ * @return The next object.
+ * @throws NoSuchElementException if there are no
+ * previous objects to retrieve.
+ * @throws ConcurrentModificationException if the
+ * list has been modified elsewhere.
+ */
+ public E previous()
+ {
+ if (position == 0)
+ throw new NoSuchElementException();
+ position--;
+ return i.previous();
+ }
+
+ /**
+ * Returns the index of the next element in the
+ * list, which will be retrieved by <code>next()</code>
+ *
+ * @return The index of the next element.
+ */
+ public int nextIndex()
+ {
+ return i.nextIndex() - offset;
+ }
+
+ /**
+ * Returns the index of the previous element in the
+ * list, which will be retrieved by <code>previous()</code>
+ *
+ * @return The index of the previous element.
+ */
+ public int previousIndex()
+ {
+ return i.previousIndex() - offset;
+ }
+
+ /**
+ * Removes the last object retrieved by <code>next()</code>
+ * from the list, if the list supports object removal.
+ *
+ * @throws IllegalStateException if the iterator is positioned
+ * before the start of the list or the last object has already
+ * been removed.
+ * @throws UnsupportedOperationException if the list does
+ * not support removing elements.
+ */
+ public void remove()
+ {
+ i.remove();
+ size--;
+ position = nextIndex();
+ modCount = backingList.modCount;
+ }
+
+
+ /**
+ * Replaces the last object retrieved by <code>next()</code>
+ * or <code>previous</code> with o, if the list supports object
+ * replacement and an add or remove operation has not already
+ * been performed.
+ *
+ * @throws IllegalStateException if the iterator is positioned
+ * before the start of the list or the last object has already
+ * been removed.
+ * @throws UnsupportedOperationException if the list doesn't support
+ * the addition or removal of elements.
+ * @throws ClassCastException if the type of o is not a valid type
+ * for this list.
+ * @throws IllegalArgumentException if something else related to o
+ * prevents its addition.
+ * @throws ConcurrentModificationException if the list
+ * has been modified elsewhere.
+ */
+ public void set(E o)
+ {
+ i.set(o);
+ }
+
+ /**
+ * Adds the supplied object before the element that would be returned
+ * by a call to <code>next()</code>, if the list supports addition.
+ *
+ * @param o The object to add to the list.
+ * @throws UnsupportedOperationException if the list doesn't support
+ * the addition of new elements.
+ * @throws ClassCastException if the type of o is not a valid type
+ * for this list.
+ * @throws IllegalArgumentException if something else related to o
+ * prevents its addition.
+ * @throws ConcurrentModificationException if the list
+ * has been modified elsewhere.
+ */
+ public void add(E o)
+ {
+ i.add(o);
+ size++;
+ position++;
+ modCount = backingList.modCount;
+ }
+
+ // Here is the reason why the various modCount fields are mostly
+ // ignored in this wrapper listIterator.
+ // If the backing listIterator is failfast, then the following holds:
+ // Using any other method on this list will call a corresponding
+ // method on the backing list *after* the backing listIterator
+ // is created, which will in turn cause a ConcurrentModException
+ // when this listIterator comes to use the backing one. So it is
+ // implicitly failfast.
+ // If the backing listIterator is NOT failfast, then the whole of
+ // this list isn't failfast, because the modCount field of the
+ // backing list is not valid. It would still be *possible* to
+ // make the iterator failfast wrt modifications of the sublist
+ // only, but somewhat pointless when the list can be changed under
+ // us.
+ // Either way, no explicit handling of modCount is needed.
+ // However modCount = backingList.modCount must be executed in add
+ // and remove, and size must also be updated in these two methods,
+ // since they do not go through the corresponding methods of the subList.
+ };
}
} // class SubList
@@ -1181,7 +1185,7 @@ while (i.hasNext())
*
* @author Eric Blake (ebb9@email.byu.edu)
*/
- private static final class RandomAccessSubList extends SubList
+ private static final class RandomAccessSubList<E> extends SubList<E>
implements RandomAccess
{
/**
@@ -1191,10 +1195,10 @@ while (i.hasNext())
* @param fromIndex the lower bound, inclusive
* @param toIndex the upper bound, exclusive
*/
- RandomAccessSubList(AbstractList backing, int fromIndex, int toIndex)
+ RandomAccessSubList(AbstractList<E> backing, int fromIndex, int toIndex)
{
super(backing, fromIndex, toIndex);
}
} // class RandomAccessSubList
-
+
} // class AbstractList
diff --git a/java/util/AbstractMap.java b/java/util/AbstractMap.java
index b4ab882ad..29249e1dc 100644
--- a/java/util/AbstractMap.java
+++ b/java/util/AbstractMap.java
@@ -1,5 +1,6 @@
/* AbstractMap.java -- Abstract implementation of most of Map
- Copyright (C) 1998, 1999, 2000, 2001, 2002, 2005 Free Software Foundation, Inc.
+ Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004, 2005
+ Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -38,6 +39,8 @@ exception statement from your version. */
package java.util;
+import java.io.Serializable;
+
/**
* An abstract implementation of Map to make it easier to create your own
* implementations. In order to create an unmodifiable Map, subclass
@@ -64,9 +67,43 @@ package java.util;
* @since 1.2
* @status updated to 1.4
*/
-public abstract class AbstractMap implements Map
+public abstract class AbstractMap<K, V> implements Map<K, V>
{
- /** An "enum" of iterator types. */
+ /** @since 1.6 */
+ public static class SimpleImmutableEntry<K, V>
+ implements Entry<K, V>, Serializable
+ {
+ K key;
+ V value;
+
+ public SimpleImmutableEntry(K key, V value)
+ {
+ this.key = key;
+ this.value = value;
+ }
+
+ public SimpleImmutableEntry(Entry<? extends K, ? extends V> entry)
+ {
+ this(entry.getKey(), entry.getValue());
+ }
+
+ public K getKey()
+ {
+ return key;
+ }
+
+ public V getValue()
+ {
+ return value;
+ }
+
+ public V setValue(V value)
+ {
+ throw new UnsupportedOperationException("setValue not supported on immutable entry");
+ }
+ }
+
+/** An "enum" of iterator types. */
// Package visible for use by subclasses.
static final int KEYS = 0,
VALUES = 1,
@@ -76,13 +113,13 @@ public abstract class AbstractMap implements Map
* The cache for {@link #keySet()}.
*/
// Package visible for use by subclasses.
- Set keys;
+ Set<K> keys;
/**
* The cache for {@link #values()}.
*/
// Package visible for use by subclasses.
- Collection values;
+ Collection<V> values;
/**
* The main constructor, for use by subclasses.
@@ -104,7 +141,7 @@ public abstract class AbstractMap implements Map
* @return the entry set
* @see Map.Entry
*/
- public abstract Set entrySet();
+ public abstract Set<Map.Entry<K, V>> entrySet();
/**
* Remove all entries from this Map (optional operation). This default
@@ -133,7 +170,7 @@ public abstract class AbstractMap implements Map
*/
protected Object clone() throws CloneNotSupportedException
{
- AbstractMap copy = (AbstractMap) super.clone();
+ AbstractMap<K, V> copy = (AbstractMap<K, V>) super.clone();
// Clear out the caches; they are stale.
copy.keys = null;
copy.values = null;
@@ -155,10 +192,10 @@ public abstract class AbstractMap implements Map
*/
public boolean containsKey(Object key)
{
- Iterator entries = entrySet().iterator();
+ Iterator<Map.Entry<K, V>> entries = entrySet().iterator();
int pos = size();
while (--pos >= 0)
- if (equals(key, ((Map.Entry) entries.next()).getKey()))
+ if (equals(key, entries.next().getKey()))
return true;
return false;
}
@@ -178,10 +215,10 @@ public abstract class AbstractMap implements Map
*/
public boolean containsValue(Object value)
{
- Iterator entries = entrySet().iterator();
+ Iterator<Map.Entry<K, V>> entries = entrySet().iterator();
int pos = size();
while (--pos >= 0)
- if (equals(value, ((Map.Entry) entries.next()).getValue()))
+ if (equals(value, entries.next().getValue()))
return true;
return false;
}
@@ -198,9 +235,9 @@ public abstract class AbstractMap implements Map
*/
public boolean equals(Object o)
{
- return (o == this ||
- (o instanceof Map &&
- entrySet().equals(((Map) o).entrySet())));
+ return (o == this
+ || (o instanceof Map
+ && entrySet().equals(((Map<K, V>) o).entrySet())));
}
/**
@@ -215,13 +252,13 @@ public abstract class AbstractMap implements Map
* @throws NullPointerException if this map does not accept null keys
* @see #containsKey(Object)
*/
- public Object get(Object key)
+ public V get(Object key)
{
- Iterator entries = entrySet().iterator();
+ Iterator<Map.Entry<K, V>> entries = entrySet().iterator();
int pos = size();
while (--pos >= 0)
{
- Map.Entry entry = (Map.Entry) entries.next();
+ Map.Entry<K, V> entry = entries.next();
if (equals(key, entry.getKey()))
return entry.getValue();
}
@@ -273,10 +310,10 @@ public abstract class AbstractMap implements Map
* @see #containsKey(Object)
* @see #values()
*/
- public Set keySet()
+ public Set<K> keySet()
{
if (keys == null)
- keys = new AbstractSet()
+ keys = new AbstractSet<K>()
{
/**
* Retrieves the number of keys in the backing map.
@@ -294,7 +331,7 @@ public abstract class AbstractMap implements Map
*
* @param key The key to search for.
* @return True if the key was found, false otherwise.
- */
+ */
public boolean contains(Object key)
{
return containsKey(key);
@@ -307,14 +344,15 @@ public abstract class AbstractMap implements Map
*
* @return An iterator over the keys.
*/
- public Iterator iterator()
+ public Iterator<K> iterator()
{
- return new Iterator()
+ return new Iterator<K>()
{
/**
* The iterator returned by <code>entrySet()</code>.
*/
- private final Iterator map_iterator = entrySet().iterator();
+ private final Iterator<Map.Entry<K, V>> map_iterator
+ = entrySet().iterator();
/**
* Returns true if a call to <code>next()</code> will
@@ -333,10 +371,10 @@ public abstract class AbstractMap implements Map
* by the underlying <code>entrySet()</code> iterator.
*
* @return The next key.
- */
- public Object next()
+ */
+ public K next()
{
- return ((Map.Entry) map_iterator.next()).getKey();
+ return map_iterator.next().getKey();
}
/**
@@ -374,7 +412,7 @@ public abstract class AbstractMap implements Map
* @throws NullPointerException if the map forbids null keys or values
* @see #containsKey(Object)
*/
- public Object put(Object key, Object value)
+ public V put(K key, V value)
{
throw new UnsupportedOperationException();
}
@@ -396,13 +434,16 @@ public abstract class AbstractMap implements Map
* @throws NullPointerException if <code>m</code> is null.
* @see #put(Object, Object)
*/
- public void putAll(Map m)
+ public void putAll(Map<? extends K, ? extends V> m)
{
- Iterator entries = m.entrySet().iterator();
+ // FIXME: bogus circumlocution.
+ Iterator entries2 = m.entrySet().iterator();
+ Iterator<Map.Entry<? extends K, ? extends V>> entries
+ = (Iterator<Map.Entry<? extends K, ? extends V>>) entries2;
int pos = m.size();
while (--pos >= 0)
{
- Map.Entry entry = (Map.Entry) entries.next();
+ Map.Entry<? extends K, ? extends V> entry = entries.next();
put(entry.getKey(), entry.getValue());
}
}
@@ -424,17 +465,17 @@ public abstract class AbstractMap implements Map
* @throws UnsupportedOperationException if deletion is unsupported
* @see Iterator#remove()
*/
- public Object remove(Object key)
+ public V remove(Object key)
{
- Iterator entries = entrySet().iterator();
+ Iterator<Map.Entry<K, V>> entries = entrySet().iterator();
int pos = size();
while (--pos >= 0)
{
- Map.Entry entry = (Map.Entry) entries.next();
+ Map.Entry<K, V> entry = entries.next();
if (equals(key, entry.getKey()))
{
// Must get the value before we remove it from iterator.
- Object r = entry.getValue();
+ V r = entry.getValue();
entries.remove();
return r;
}
@@ -469,11 +510,11 @@ public abstract class AbstractMap implements Map
*/
public String toString()
{
- Iterator entries = entrySet().iterator();
+ Iterator<Map.Entry<K, V>> entries = entrySet().iterator();
StringBuffer r = new StringBuffer("{");
for (int pos = size(); pos > 0; pos--)
{
- Map.Entry entry = (Map.Entry) entries.next();
+ Map.Entry<K, V> entry = entries.next();
r.append(entry.getKey());
r.append('=');
r.append(entry.getValue());
@@ -504,18 +545,18 @@ public abstract class AbstractMap implements Map
* @see #containsValue(Object)
* @see #keySet()
*/
- public Collection values()
+ public Collection<V> values()
{
if (values == null)
- values = new AbstractCollection()
+ values = new AbstractCollection<V>()
{
- /**
+ /**
* Returns the number of values stored in
* the backing map.
*
* @return The number of values.
*/
- public int size()
+ public int size()
{
return AbstractMap.this.size();
}
@@ -539,46 +580,47 @@ public abstract class AbstractMap implements Map
*
* @return An iterator over the values.
*/
- public Iterator iterator()
+ public Iterator<V> iterator()
{
- return new Iterator()
+ return new Iterator<V>()
{
/**
* The iterator returned by <code>entrySet()</code>.
*/
- private final Iterator map_iterator = entrySet().iterator();
-
- /**
- * Returns true if a call to <code>next()</call> will
- * return another value.
- *
- * @return True if the iterator has not yet reached
- * the last value.
- */
+ private final Iterator<Map.Entry<K, V>> map_iterator
+ = entrySet().iterator();
+
+ /**
+ * Returns true if a call to <code>next()</call> will
+ * return another value.
+ *
+ * @return True if the iterator has not yet reached
+ * the last value.
+ */
public boolean hasNext()
{
return map_iterator.hasNext();
}
- /**
- * Returns the value from the next entry retrieved
- * by the underlying <code>entrySet()</code> iterator.
- *
- * @return The next value.
- */
- public Object next()
+ /**
+ * Returns the value from the next entry retrieved
+ * by the underlying <code>entrySet()</code> iterator.
+ *
+ * @return The next value.
+ */
+ public V next()
{
- return ((Map.Entry) map_iterator.next()).getValue();
+ return map_iterator.next().getValue();
}
- /**
- * Removes the map entry which has a key equal
- * to that returned by the last call to
- * <code>next()</code>.
- *
- * @throws UnsupportedOperationException if the
- * map doesn't support removal.
- */
+ /**
+ * Removes the map entry which has a key equal
+ * to that returned by the last call to
+ * <code>next()</code>.
+ *
+ * @throws UnsupportedOperationException if the
+ * map doesn't support removal.
+ */
public void remove()
{
map_iterator.remove();
@@ -623,31 +665,36 @@ public abstract class AbstractMap implements Map
*
* @author Jon Zeppieri
* @author Eric Blake (ebb9@email.byu.edu)
+ *
+ * @since 1.6
*/
- // XXX - FIXME Use fully qualified implements as gcj 3.1 workaround.
- // Bug still exists in 3.4.1
- static class BasicMapEntry implements Map.Entry
+ public static class SimpleEntry<K, V> implements Entry<K, V>, Serializable
{
/**
* The key. Package visible for direct manipulation.
*/
- Object key;
+ K key;
/**
* The value. Package visible for direct manipulation.
*/
- Object value;
+ V value;
/**
* Basic constructor initializes the fields.
* @param newKey the key
* @param newValue the value
*/
- BasicMapEntry(Object newKey, Object newValue)
+ public SimpleEntry(K newKey, V newValue)
{
key = newKey;
value = newValue;
}
+
+ public SimpleEntry(Entry<? extends K, ? extends V> entry)
+ {
+ this(entry.getKey(), entry.getValue());
+ }
/**
* Compares the specified object with this entry. Returns true only if
@@ -662,14 +709,14 @@ public abstract class AbstractMap implements Map
* @param o the object to compare
* @return <code>true</code> if it is equal
*/
- public final boolean equals(Object o)
+ public boolean equals(Object o)
{
if (! (o instanceof Map.Entry))
return false;
// Optimize for our own entries.
- if (o instanceof BasicMapEntry)
+ if (o instanceof SimpleEntry)
{
- BasicMapEntry e = (BasicMapEntry) o;
+ SimpleEntry e = (SimpleEntry) o;
return (AbstractMap.equals(key, e.key)
&& AbstractMap.equals(value, e.value));
}
@@ -683,7 +730,7 @@ public abstract class AbstractMap implements Map
*
* @return the key
*/
- public final Object getKey()
+ public final K getKey()
{
return key;
}
@@ -694,7 +741,7 @@ public abstract class AbstractMap implements Map
*
* @return the value
*/
- public final Object getValue()
+ public final V getValue()
{
return value;
}
@@ -728,9 +775,9 @@ public abstract class AbstractMap implements Map
* @throws IllegalArgumentException if something else about this
* value prevents it being stored in the map.
*/
- public Object setValue(Object newVal)
+ public V setValue(V newVal)
{
- Object r = value;
+ V r = value;
value = newVal;
return r;
}
@@ -745,5 +792,7 @@ public abstract class AbstractMap implements Map
{
return key + "=" + value;
}
- } // class BasicMapEntry
+ } // class SimpleEntry
+
+
}
diff --git a/java/util/AbstractSequentialList.java b/java/util/AbstractSequentialList.java
index 79583228d..81b0714e1 100644
--- a/java/util/AbstractSequentialList.java
+++ b/java/util/AbstractSequentialList.java
@@ -1,5 +1,5 @@
/* AbstractSequentialList.java -- List implementation for sequential access
- Copyright (C) 1998, 1999, 2000, 2001, 2005 Free Software Foundation, Inc.
+ Copyright (C) 1998, 1999, 2000, 2001, 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -71,7 +71,7 @@ package java.util;
* @since 1.2
* @status updated to 1.4
*/
-public abstract class AbstractSequentialList extends AbstractList
+public abstract class AbstractSequentialList<E> extends AbstractList<E>
{
/**
* The main constructor, for use by subclasses.
@@ -88,7 +88,7 @@ public abstract class AbstractSequentialList extends AbstractList
* @return the list iterator
* @throws IndexOutOfBoundsException if index &lt; 0 || index &gt; size()
*/
- public abstract ListIterator listIterator(int index);
+ public abstract ListIterator<E> listIterator(int index);
/**
* Insert an element into the list at a given position (optional operation).
@@ -109,7 +109,7 @@ public abstract class AbstractSequentialList extends AbstractList
* @throws NullPointerException if o is null and the list does not permit
* the addition of null values.
*/
- public void add(int index, Object o)
+ public void add(int index, E o)
{
listIterator(index).add(o);
}
@@ -143,11 +143,11 @@ public abstract class AbstractSequentialList extends AbstractList
* does not permit the addition of null values.
* @see #add(int, Object)
*/
- public boolean addAll(int index, Collection c)
+ public boolean addAll(int index, Collection<? extends E> c)
{
- Iterator ci = c.iterator();
+ Iterator<? extends E> ci = c.iterator();
int size = c.size();
- ListIterator i = listIterator(index);
+ ListIterator<E> i = listIterator(index);
for (int pos = size; pos > 0; pos--)
i.add(ci.next());
return size > 0;
@@ -161,7 +161,7 @@ public abstract class AbstractSequentialList extends AbstractList
* @return the element at index index in this list
* @throws IndexOutOfBoundsException if index &lt; 0 || index &gt;= size()
*/
- public Object get(int index)
+ public E get(int index)
{
// This is a legal listIterator position, but an illegal get.
if (index == size())
@@ -176,7 +176,7 @@ public abstract class AbstractSequentialList extends AbstractList
*
* @return an Iterator over the elements of this list, in order
*/
- public Iterator iterator()
+ public Iterator<E> iterator()
{
return listIterator();
}
@@ -192,14 +192,14 @@ public abstract class AbstractSequentialList extends AbstractList
* remove operation
* @throws IndexOutOfBoundsException if index &lt; 0 || index &gt;= size()
*/
- public Object remove(int index)
+ public E remove(int index)
{
// This is a legal listIterator position, but an illegal remove.
if (index == size())
throw new IndexOutOfBoundsException("Index: " + index + ", Size:"
+ size());
- ListIterator i = listIterator(index);
- Object removed = i.next();
+ ListIterator<E> i = listIterator(index);
+ E removed = i.next();
i.remove();
return removed;
}
@@ -221,14 +221,14 @@ public abstract class AbstractSequentialList extends AbstractList
* @throws NullPointerException if o is null and the list does not allow
* a value to be set to null.
*/
- public Object set(int index, Object o)
+ public E set(int index, E o)
{
// This is a legal listIterator position, but an illegal set.
if (index == size())
throw new IndexOutOfBoundsException("Index: " + index + ", Size:"
+ size());
- ListIterator i = listIterator(index);
- Object old = i.next();
+ ListIterator<E> i = listIterator(index);
+ E old = i.next();
i.set(o);
return old;
}
diff --git a/java/util/AbstractSet.java b/java/util/AbstractSet.java
index f0d7cb199..423ac8083 100644
--- a/java/util/AbstractSet.java
+++ b/java/util/AbstractSet.java
@@ -1,5 +1,6 @@
/* AbstractSet.java -- Abstract implementation of most of Set
- Copyright (C) 1998, 2000, 2001, 2005 Free Software Foundation, Inc.
+ Copyright (C) 1998, 2000, 2001, 2004, 2005
+ Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -58,7 +59,9 @@ package java.util;
* @since 1.2
* @status updated to 1.4
*/
-public abstract class AbstractSet extends AbstractCollection implements Set
+public abstract class AbstractSet<E>
+ extends AbstractCollection<E>
+ implements Set<E>
{
/**
* The main constructor, for use by subclasses.
@@ -79,9 +82,9 @@ public abstract class AbstractSet extends AbstractCollection implements Set
*/
public boolean equals(Object o)
{
- return (o == this ||
- (o instanceof Set && ((Set) o).size() == size()
- && containsAll((Collection) o)));
+ return (o == this
+ || (o instanceof Set && ((Set) o).size() == size()
+ && containsAll((Collection) o)));
}
/**
@@ -94,7 +97,7 @@ public abstract class AbstractSet extends AbstractCollection implements Set
*/
public int hashCode()
{
- Iterator itr = iterator();
+ Iterator<E> itr = iterator();
int hash = 0;
int pos = size();
while (--pos >= 0)
@@ -119,21 +122,25 @@ public abstract class AbstractSet extends AbstractCollection implements Set
* @see Collection#contains(Object)
* @see Iterator#remove()
*/
- public boolean removeAll(Collection c)
+ public boolean removeAll(Collection<?> c)
{
int oldsize = size();
int count = c.size();
- Iterator i;
if (oldsize < count)
{
+ Iterator<E> i;
for (i = iterator(), count = oldsize; count > 0; count--)
- if (c.contains(i.next()))
- i.remove();
+ {
+ if (c.contains(i.next()))
+ i.remove();
+ }
}
else
- for (i = c.iterator(); count > 0; count--)
- remove(i.next());
+ {
+ Iterator<?> i;
+ for (i = c.iterator(); count > 0; count--)
+ remove(i.next());
+ }
return oldsize != size();
}
-
}
diff --git a/java/util/ArrayList.java b/java/util/ArrayList.java
index 50b5638ed..0693049b5 100644
--- a/java/util/ArrayList.java
+++ b/java/util/ArrayList.java
@@ -81,8 +81,8 @@ import java.lang.reflect.Array;
* @see AbstractList
* @status updated to 1.4
*/
-public class ArrayList extends AbstractList
- implements List, RandomAccess, Cloneable, Serializable
+public class ArrayList<E> extends AbstractList<E>
+ implements List<E>, RandomAccess, Cloneable, Serializable
{
/**
* Compatible with JDK 1.2
@@ -103,7 +103,7 @@ public class ArrayList extends AbstractList
/**
* Where the data is stored.
*/
- private transient Object[] data;
+ private transient E[] data;
/**
* Construct a new ArrayList with the supplied initial capacity.
@@ -116,7 +116,7 @@ public class ArrayList extends AbstractList
// Must explicitly check, to get correct exception.
if (capacity < 0)
throw new IllegalArgumentException();
- data = new Object[capacity];
+ data = (E[]) new Object[capacity];
}
/**
@@ -135,7 +135,7 @@ public class ArrayList extends AbstractList
* @param c the collection whose elements will initialize this list
* @throws NullPointerException if c is null
*/
- public ArrayList(Collection c)
+ public ArrayList(Collection<? extends E> c)
{
this((int) (c.size() * 1.1f));
addAll(c);
@@ -151,7 +151,7 @@ public class ArrayList extends AbstractList
// so don't update modCount.
if (size != data.length)
{
- Object[] newData = new Object[size];
+ E[] newData = (E[]) new Object[size];
System.arraycopy(data, 0, newData, 0, size);
data = newData;
}
@@ -173,7 +173,7 @@ public class ArrayList extends AbstractList
if (minCapacity > current)
{
- Object[] newData = new Object[Math.max(current * 2, minCapacity)];
+ E[] newData = (E[]) new Object[Math.max(current * 2, minCapacity)];
System.arraycopy(data, 0, newData, 0, size);
data = newData;
}
@@ -247,11 +247,11 @@ public class ArrayList extends AbstractList
*/
public Object clone()
{
- ArrayList clone = null;
+ ArrayList<E> clone = null;
try
{
- clone = (ArrayList) super.clone();
- clone.data = (Object[]) data.clone();
+ clone = (ArrayList<E>) super.clone();
+ clone.data = (E[]) data.clone();
}
catch (CloneNotSupportedException e)
{
@@ -268,7 +268,7 @@ public class ArrayList extends AbstractList
*/
public Object[] toArray()
{
- Object[] array = new Object[size];
+ E[] array = (E[]) new Object[size];
System.arraycopy(data, 0, array, 0, size);
return array;
}
@@ -287,11 +287,10 @@ public class ArrayList extends AbstractList
* an element in this list
* @throws NullPointerException if a is null
*/
- public Object[] toArray(Object[] a)
+ public <T> T[] toArray(T[] a)
{
if (a.length < size)
- a = (Object[]) Array.newInstance(a.getClass().getComponentType(),
- size);
+ a = (T[]) Array.newInstance(a.getClass().getComponentType(), size);
else if (a.length > size)
a[size] = null;
System.arraycopy(data, 0, a, 0, size);
@@ -304,7 +303,7 @@ public class ArrayList extends AbstractList
* @param index the index of the element we are fetching
* @throws IndexOutOfBoundsException if index &lt; 0 || index &gt;= size()
*/
- public Object get(int index)
+ public E get(int index)
{
checkBoundExclusive(index);
return data[index];
@@ -319,10 +318,10 @@ public class ArrayList extends AbstractList
* @return the element previously at the specified index
* @throws IndexOutOfBoundsException if index &lt; 0 || index &gt;= 0
*/
- public Object set(int index, Object e)
+ public E set(int index, E e)
{
checkBoundExclusive(index);
- Object result = data[index];
+ E result = data[index];
data[index] = e;
return result;
}
@@ -334,7 +333,7 @@ public class ArrayList extends AbstractList
* @param e the element to be appended to this list
* @return true, the add will always succeed
*/
- public boolean add(Object e)
+ public boolean add(E e)
{
modCount++;
if (size == data.length)
@@ -352,7 +351,7 @@ public class ArrayList extends AbstractList
* @param e the item being added
* @throws IndexOutOfBoundsException if index &lt; 0 || index &gt; size()
*/
- public void add(int index, Object e)
+ public void add(int index, E e)
{
checkBoundInclusive(index);
modCount++;
@@ -371,10 +370,10 @@ public class ArrayList extends AbstractList
* @return the removed Object
* @throws IndexOutOfBoundsException if index &lt; 0 || index &gt;= size()
*/
- public Object remove(int index)
+ public E remove(int index)
{
checkBoundExclusive(index);
- Object r = data[index];
+ E r = data[index];
modCount++;
if (index != --size)
System.arraycopy(data, index + 1, data, index, size - index);
@@ -407,7 +406,7 @@ public class ArrayList extends AbstractList
* @return true if the list was modified, in other words c is not empty
* @throws NullPointerException if c is null
*/
- public boolean addAll(Collection c)
+ public boolean addAll(Collection<? extends E> c)
{
return addAll(size, c);
}
@@ -422,10 +421,10 @@ public class ArrayList extends AbstractList
* @throws IndexOutOfBoundsException if index &lt; 0 || index &gt; 0
* @throws NullPointerException if c is null
*/
- public boolean addAll(int index, Collection c)
+ public boolean addAll(int index, Collection<? extends E> c)
{
checkBoundInclusive(index);
- Iterator itr = c.iterator();
+ Iterator<? extends E> itr = c.iterator();
int csize = c.size();
modCount++;
@@ -502,7 +501,7 @@ public class ArrayList extends AbstractList
* @return true if this list changed
* @throws NullPointerException if c is null
*/
- boolean removeAllInternal(Collection c)
+ boolean removeAllInternal(Collection<?> c)
{
int i;
int j;
@@ -530,7 +529,7 @@ public class ArrayList extends AbstractList
* @throws NullPointerException if c is null
* @since 1.2
*/
- boolean retainAllInternal(Collection c)
+ boolean retainAllInternal(Collection<?> c)
{
int i;
int j;
@@ -584,8 +583,8 @@ public class ArrayList extends AbstractList
// the `size' field.
s.defaultReadObject();
int capacity = s.readInt();
- data = new Object[capacity];
+ data = (E[]) new Object[capacity];
for (int i = 0; i < size; i++)
- data[i] = s.readObject();
+ data[i] = (E) s.readObject();
}
}
diff --git a/java/util/Arrays.java b/java/util/Arrays.java
index 1fa595941..fbbf43f20 100644
--- a/java/util/Arrays.java
+++ b/java/util/Arrays.java
@@ -362,7 +362,7 @@ public class Arrays
* @throws NullPointerException if a null element is compared with natural
* ordering (only possible when c is null)
*/
- public static int binarySearch(Object[] a, Object key, Comparator c)
+ public static <T> int binarySearch(T[] a, T key, Comparator<? super T> c)
{
int low = 0;
int hi = a.length - 1;
@@ -2163,7 +2163,7 @@ public class Arrays
* @throws NullPointerException if a null element is compared with natural
* ordering (only possible when c is null)
*/
- public static void sort(Object[] a, Comparator c)
+ public static <T> void sort(T[] a, Comparator<? super T> c)
{
sort(a, 0, a.length, c);
}
@@ -2213,7 +2213,8 @@ public class Arrays
* @throws NullPointerException if a null element is compared with natural
* ordering (only possible when c is null)
*/
- public static void sort(Object[] a, int fromIndex, int toIndex, Comparator c)
+ public static <T> void sort(T[] a, int fromIndex, int toIndex,
+ Comparator<? super T> c)
{
if (fromIndex > toIndex)
throw new IllegalArgumentException("fromIndex " + fromIndex
@@ -2235,7 +2236,7 @@ public class Arrays
{
// not already sorted
int j = i;
- Object elem = a[j];
+ T elem = a[j];
do
{
a[j] = a[j - 1];
@@ -2253,9 +2254,9 @@ public class Arrays
if (len <= 6)
return;
- Object[] src = a;
- Object[] dest = new Object[len];
- Object[] t = null; // t is used for swapping src and dest
+ T[] src = a;
+ T[] dest = (T[]) new Object[len];
+ T[] t = null; // t is used for swapping src and dest
// The difference of the fromIndex of the src and dest array.
int srcDestDiff = -fromIndex;
@@ -2349,7 +2350,7 @@ public class Arrays
* @see RandomAccess
* @see Arrays.ArrayList
*/
- public static List asList(final Object[] a)
+ public static <T> List<T> asList(final T... a)
{
return new Arrays.ArrayList(a);
}
@@ -2546,11 +2547,10 @@ public class Arrays
}
/**
- * Returns the hashcode of an array of integer numbers. If two arrays
+ * Returns the hashcode of an array of objects. If two arrays
* are equal, according to <code>equals()</code>, they should have the
* same hashcode. The hashcode returned by the method is equal to that
- * obtained by the corresponding <code>List</code> object. This has the same
- * data, but represents ints in their wrapper class, <code>Integer</code>.
+ * obtained by the corresponding <code>List</code> object.
* For <code>null</code>, 0 is returned.
*
* @param v an array of integer numbers for which the hash code should be
@@ -2571,7 +2571,6 @@ public class Arrays
return result;
}
- /** @since 1.5 */
public static int deepHashCode(Object[] v)
{
if (v == null)
@@ -2914,7 +2913,7 @@ public class Arrays
* @author Eric Blake (ebb9@email.byu.edu)
* @status updated to 1.4
*/
- private static final class ArrayList extends AbstractList
+ private static final class ArrayList<E> extends AbstractList<E>
implements Serializable, RandomAccess
{
// We override the necessary methods, plus others which will be much
@@ -2929,14 +2928,14 @@ public class Arrays
* The array we are viewing.
* @serial the array
*/
- private final Object[] a;
+ private final E[] a;
/**
* Construct a list view of the array.
* @param a the array to view
* @throws NullPointerException if a is null
*/
- ArrayList(Object[] a)
+ ArrayList(E[] a)
{
// We have to explicitly check.
if (a == null)
@@ -2951,7 +2950,7 @@ public class Arrays
* @param index The index to retrieve an object from.
* @return The object at the array index specified.
*/
- public Object get(int index)
+ public E get(int index)
{
return a[index];
}
@@ -2974,9 +2973,9 @@ public class Arrays
* @param element The new object.
* @return The object replaced by this operation.
*/
- public Object set(int index, Object element)
+ public E set(int index, E element)
{
- Object old = a[index];
+ E old = a[index];
a[index] = element;
return old;
}
@@ -3047,12 +3046,12 @@ public class Arrays
* @return The array containing the objects in this list,
* which may or may not be == to array.
*/
- public Object[] toArray(Object[] array)
+ public <T> T[] toArray(T[] array)
{
int size = a.length;
if (array.length < size)
- array = (Object[])
- Array.newInstance(array.getClass().getComponentType(), size);
+ array = (T[]) Array.newInstance(array.getClass().getComponentType(),
+ size);
else if (array.length > size)
array[size] = null;
diff --git a/java/util/BitSet.java b/java/util/BitSet.java
index f1b5aaa06..e4f923b7f 100644
--- a/java/util/BitSet.java
+++ b/java/util/BitSet.java
@@ -741,4 +741,15 @@ public class BitSet implements Cloneable, Serializable
bits = nd;
}
}
+
+ // This is used by EnumSet for efficiency.
+ final boolean containsAll(BitSet other)
+ {
+ for (int i = other.bits.length - 1; i >= 0; i--)
+ {
+ if ((bits[i] & other.bits[i]) != other.bits[i])
+ return false;
+ }
+ return true;
+ }
}
diff --git a/java/util/Calendar.java b/java/util/Calendar.java
index f48de85f1..8c46c0193 100644
--- a/java/util/Calendar.java
+++ b/java/util/Calendar.java
@@ -104,7 +104,8 @@ day_of_week + week_of_year</pre>
* @see TimeZone
* @see java.text.DateFormat
*/
-public abstract class Calendar implements Serializable, Cloneable
+public abstract class Calendar
+ implements Serializable, Cloneable, Comparable<Calendar>
{
/**
* Constant representing the era time field.
@@ -1219,6 +1220,31 @@ public abstract class Calendar implements Serializable, Cloneable
}
/**
+ * Compares the time of two calendar instances.
+ * @param calendar the calendar to which the time should be compared.
+ * @return 0 if the two calendars are set to the same time,
+ * less than 0 if the time of this calendar is before that of
+ * <code>cal</code>, or more than 0 if the time of this calendar is after
+ * that of <code>cal</code>.
+ *
+ * @param cal the calendar to compare this instance with.
+ * @throws NullPointerException if <code>cal</code> is null.
+ * @throws IllegalArgumentException if either calendar has fields set to
+ * invalid values.
+ * @since 1.5
+ */
+ public int compareTo(Calendar cal)
+ {
+ long t1 = getTimeInMillis();
+ long t2 = cal.getTimeInMillis();
+ if(t1 == t2)
+ return 0;
+ if(t1 > t2)
+ return 1;
+ return -1;
+ }
+
+ /**
* Return a clone of this object.
*/
public Object clone()
diff --git a/java/util/Collection.java b/java/util/Collection.java
index f7db708c1..b57566f70 100644
--- a/java/util/Collection.java
+++ b/java/util/Collection.java
@@ -1,5 +1,5 @@
/* Collection.java -- Interface that represents a collection of objects
- Copyright (C) 1998, 2001, 2005 Free Software Foundation, Inc.
+ Copyright (C) 1998, 2001, 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -67,6 +67,8 @@ package java.util;
*
* @author Original author unknown
* @author Eric Blake (ebb9@email.byu.edu)
+ * @author Tom Tromey (tromey@redhat.com)
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
* @see List
* @see Set
* @see Map
@@ -81,9 +83,9 @@ package java.util;
* @see Arrays
* @see AbstractCollection
* @since 1.2
- * @status updated to 1.5 (minus generics)
+ * @status updated to 1.4
*/
-public interface Collection extends Iterable
+public interface Collection<E> extends Iterable<E>
{
/**
* Add an element to this collection.
@@ -99,7 +101,7 @@ public interface Collection extends Iterable
* @throws IllegalArgumentException if o cannot be added to this
* collection for some other reason.
*/
- boolean add(Object o);
+ boolean add(E o);
/**
* Add the contents of a given collection to this collection.
@@ -116,7 +118,7 @@ public interface Collection extends Iterable
* @throws IllegalArgumentException if some element of c cannot be added
* to this collection for some other reason.
*/
- boolean addAll(Collection c);
+ boolean addAll(Collection<? extends E> c);
/**
* Clear the collection, such that a subsequent call to isEmpty() would
@@ -152,7 +154,7 @@ public interface Collection extends Iterable
* collection does not support null values.
* @throws NullPointerException if c itself is null.
*/
- boolean containsAll(Collection c);
+ boolean containsAll(Collection<?> c);
/**
* Test whether this collection is equal to some object. The Collection
@@ -200,7 +202,7 @@ public interface Collection extends Iterable
*
* @return an Iterator over the elements of this collection, in any order.
*/
- Iterator iterator();
+ Iterator<E> iterator();
/**
* Remove a single occurrence of an object from this collection. That is,
@@ -233,7 +235,7 @@ public interface Collection extends Iterable
* collection does not support removing null values.
* @throws NullPointerException if c itself is null.
*/
- boolean removeAll(Collection c);
+ boolean removeAll(Collection<?> c);
/**
* Remove all elements of this collection that are not contained in a given
@@ -249,7 +251,7 @@ public interface Collection extends Iterable
* collection does not support retaining null values.
* @throws NullPointerException if c itself is null.
*/
- boolean retainAll(Collection c);
+ boolean retainAll(Collection<?> c);
/**
* Get the number of elements in this collection.
@@ -284,5 +286,5 @@ public interface Collection extends Iterable
* @throws ArrayStoreException if the type of any element of the
* collection is not a subtype of the element type of a.
*/
- Object[] toArray(Object[] a);
+ <T> T[] toArray(T[] a);
}
diff --git a/java/util/Collections.java b/java/util/Collections.java
index 43e9104b1..c15fa092b 100644
--- a/java/util/Collections.java
+++ b/java/util/Collections.java
@@ -62,13 +62,15 @@ import java.io.Serializable;
*
* @author Original author unknown
* @author Eric Blake (ebb9@email.byu.edu)
+ * @author Tom Tromey (tromey@redhat.com)
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
* @see Collection
* @see Set
* @see List
* @see Map
* @see Arrays
* @since 1.2
- * @status updated to 1.4
+ * @status updated to 1.5
*/
public class Collections
{
@@ -90,7 +92,7 @@ public class Collections
* @param l the list to check
* @return <code>true</code> if it should be treated as sequential-access
*/
- private static boolean isSequential(List l)
+ private static boolean isSequential(List<?> l)
{
return ! (l instanceof RandomAccess) && l.size() > LARGE_LIST_SIZE;
}
@@ -109,12 +111,26 @@ public class Collections
public static final Set EMPTY_SET = new EmptySet();
/**
+ * Returns an immutable, serializable parameterized empty set.
+ * Unlike the constant <code>EMPTY_SET</code>, the set returned by
+ * this method is type-safe.
+ *
+ * @return an empty parameterized set.
+ * @since 1.5
+ */
+ public static final <T> Set<T> emptySet()
+ {
+ /* FIXME: Could this be optimized? */
+ return new EmptySet<T>();
+ }
+
+ /**
* The implementation of {@link #EMPTY_SET}. This class name is required
* for compatibility with Sun's JDK serializability.
*
* @author Eric Blake (ebb9@email.byu.edu)
*/
- private static final class EmptySet extends AbstractSet
+ private static final class EmptySet<T> extends AbstractSet<T>
implements Serializable
{
/**
@@ -143,9 +159,9 @@ public class Collections
* @return A non-iterating iterator.
*/
// This is really cheating! I think it's perfectly valid, though.
- public Iterator iterator()
+ public Iterator<T> iterator()
{
- return EMPTY_LIST.iterator();
+ return (Iterator<T>) EMPTY_LIST.iterator();
}
// The remaining methods are optional, but provide a performance
@@ -166,7 +182,7 @@ public class Collections
* against the members of this set.
* @return <code>true</code> if c is empty.
*/
- public boolean containsAll(Collection c)
+ public boolean containsAll(Collection<?> c)
{
return c.isEmpty();
}
@@ -206,7 +222,7 @@ public class Collections
* all be removed from this set.
* @return <code>false</code>.
*/
- public boolean removeAll(Collection c)
+ public boolean removeAll(Collection<?> c)
{
return false;
}
@@ -217,7 +233,7 @@ public class Collections
* all be retained within this set.
* @return <code>false</code>.
*/
- public boolean retainAll(Collection c)
+ public boolean retainAll(Collection<?> c)
{
return false;
}
@@ -237,7 +253,7 @@ public class Collections
* @return The original array with any existing
* initial element set to null.
*/
- public Object[] toArray(Object[] a)
+ public <E> E[] toArray(E[] a)
{
if (a.length > 0)
a[0] = null;
@@ -263,12 +279,26 @@ public class Collections
public static final List EMPTY_LIST = new EmptyList();
/**
+ * Returns an immutable, serializable parameterized empty list.
+ * Unlike the constant <code>EMPTY_LIST</code>, the list returned by
+ * this method is type-safe.
+ *
+ * @return an empty parameterized list.
+ * @since 1.5
+ */
+ public static final <T> List<T> emptyList()
+ {
+ /* FIXME: Could this be optimized? */
+ return new EmptyList<T>();
+ }
+
+ /**
* The implementation of {@link #EMPTY_LIST}. This class name is required
* for compatibility with Sun's JDK serializability.
*
* @author Eric Blake (ebb9@email.byu.edu)
*/
- private static final class EmptyList extends AbstractList
+ private static final class EmptyList<T> extends AbstractList<T>
implements Serializable, RandomAccess
{
/**
@@ -301,7 +331,7 @@ public class Collections
* @throws IndexOutOfBoundsException as any given index
* is outside the bounds of an empty array.
*/
- public Object get(int index)
+ public T get(int index)
{
throw new IndexOutOfBoundsException();
}
@@ -324,7 +354,7 @@ public class Collections
* against the members of this list.
* @return <code>true</code> if c is also empty.
*/
- public boolean containsAll(Collection c)
+ public boolean containsAll(Collection<?> c)
{
return c.isEmpty();
}
@@ -385,7 +415,7 @@ public class Collections
* all be removed from this list.
* @return <code>false</code>.
*/
- public boolean removeAll(Collection c)
+ public boolean removeAll(Collection<?> c)
{
return false;
}
@@ -396,7 +426,7 @@ public class Collections
* all be retained within this list.
* @return <code>false</code>.
*/
- public boolean retainAll(Collection c)
+ public boolean retainAll(Collection<?> c)
{
return false;
}
@@ -416,7 +446,7 @@ public class Collections
* @return The original array with any existing
* initial element set to null.
*/
- public Object[] toArray(Object[] a)
+ public <E> E[] toArray(E[] a)
{
if (a.length > 0)
a[0] = null;
@@ -441,12 +471,26 @@ public class Collections
public static final Map EMPTY_MAP = new EmptyMap();
/**
+ * Returns an immutable, serializable parameterized empty map.
+ * Unlike the constant <code>EMPTY_MAP</code>, the map returned by
+ * this method is type-safe.
+ *
+ * @return an empty parameterized map.
+ * @since 1.5
+ */
+ public static final <K,V> Map<K,V> emptyMap()
+ {
+ /* FIXME: Could this be optimized? */
+ return new EmptyMap<K,V>();
+ }
+
+ /**
* The implementation of {@link #EMPTY_MAP}. This class name is required
* for compatibility with Sun's JDK serializability.
*
* @author Eric Blake (ebb9@email.byu.edu)
*/
- private static final class EmptyMap extends AbstractMap
+ private static final class EmptyMap<K, V> extends AbstractMap<K, V>
implements Serializable
{
/**
@@ -465,7 +509,7 @@ public class Collections
* There are no entries.
* @return The empty set.
*/
- public Set entrySet()
+ public Set<Map.Entry<K, V>> entrySet()
{
return EMPTY_SET;
}
@@ -508,7 +552,7 @@ public class Collections
* @param o The key of the object to retrieve.
* @return null.
*/
- public Object get(Object o)
+ public V get(Object o)
{
return null;
}
@@ -526,7 +570,7 @@ public class Collections
* No entries.
* @return The empty set.
*/
- public Set keySet()
+ public Set<K> keySet()
{
return EMPTY_SET;
}
@@ -536,7 +580,7 @@ public class Collections
* @param o The key of the mapping to remove.
* @return null, as there is never a mapping for o.
*/
- public Object remove(Object o)
+ public V remove(Object o)
{
return null;
}
@@ -555,7 +599,7 @@ public class Collections
* Collection, will work. Besides, that's what the JDK uses!
* @return The empty set.
*/
- public Collection values()
+ public Collection<V> values()
{
return EMPTY_SET;
}
@@ -578,7 +622,7 @@ public class Collections
* clever, but worth it for removing a duplicate of the search code.
* Note: This code is also used in Arrays (for sort as well as search).
*/
- static final int compare(Object o1, Object o2, Comparator c)
+ static final <T> int compare(T o1, T o2, Comparator<? super T> c)
{
return c == null ? ((Comparable) o1).compareTo(o2) : c.compare(o1, o2);
}
@@ -607,7 +651,8 @@ public class Collections
* @throws NullPointerException if a null element has compareTo called
* @see #sort(List)
*/
- public static int binarySearch(List l, Object key)
+ public static <T> int binarySearch(List<? extends Comparable<? super T>> l,
+ T key)
{
return binarySearch(l, key, null);
}
@@ -639,7 +684,8 @@ public class Collections
* ordering (only possible when c is null)
* @see #sort(List, Comparator)
*/
- public static int binarySearch(List l, Object key, Comparator c)
+ public static <T> int binarySearch(List<? extends T> l, T key,
+ Comparator<? super T> c)
{
int pos = 0;
int low = 0;
@@ -649,9 +695,9 @@ public class Collections
// if the list is sequential-access.
if (isSequential(l))
{
- ListIterator itr = l.listIterator();
+ ListIterator<T> itr = ((List<T>) l).listIterator();
int i = 0;
- Object o = itr.next(); // Assumes list is not empty (see isSequential)
+ T o = itr.next(); // Assumes list is not empty (see isSequential)
boolean forward = true;
while (low <= hi)
{
@@ -685,7 +731,7 @@ public class Collections
while (low <= hi)
{
pos = (low + hi) >>> 1;
- final int d = compare(l.get(pos), key, c);
+ final int d = compare(((List<T>) l).get(pos), key, c);
if (d == 0)
return pos;
else if (d > 0)
@@ -712,14 +758,14 @@ public class Collections
* @throws UnsupportedOperationException if dest.listIterator() does not
* support the set operation
*/
- public static void copy(List dest, List source)
+ public static <T> void copy(List<? super T> dest, List<? extends T> source)
{
int pos = source.size();
if (dest.size() < pos)
throw new IndexOutOfBoundsException("Source does not fit in dest");
- Iterator i1 = source.iterator();
- ListIterator i2 = dest.listIterator();
+ Iterator<? extends T> i1 = source.iterator();
+ ListIterator<? super T> i2 = dest.listIterator();
while (--pos >= 0)
{
@@ -735,10 +781,10 @@ public class Collections
* @param c the Collection to iterate over
* @return an Enumeration backed by an Iterator over c
*/
- public static Enumeration enumeration(Collection c)
+ public static <T> Enumeration<T> enumeration(Collection<T> c)
{
- final Iterator i = c.iterator();
- return new Enumeration()
+ final Iterator<T> i = c.iterator();
+ return new Enumeration<T>()
{
/**
* Returns <code>true</code> if there are more elements to
@@ -758,7 +804,7 @@ public class Collections
* @return The result of <code>next()</code>
* called on the underlying iterator.
*/
- public final Object nextElement()
+ public final T nextElement()
{
return i.next();
}
@@ -774,9 +820,9 @@ public class Collections
* @throws UnsupportedOperationException if l.listIterator() does not
* support the set operation.
*/
- public static void fill(List l, Object val)
+ public static <T> void fill(List<? super T> l, T val)
{
- ListIterator itr = l.listIterator();
+ ListIterator<? super T> itr = l.listIterator();
for (int i = l.size() - 1; i >= 0; --i)
{
itr.next();
@@ -797,7 +843,7 @@ public class Collections
* @return the index where found, or -1
* @since 1.4
*/
- public static int indexOfSubList(List source, List target)
+ public static int indexOfSubList(List<?> source, List<?> target)
{
int ssize = source.size();
for (int i = 0, j = target.size(); j <= ssize; i++, j++)
@@ -819,7 +865,7 @@ public class Collections
* @return the index where found, or -1
* @since 1.4
*/
- public static int lastIndexOfSubList(List source, List target)
+ public static int lastIndexOfSubList(List<?> source, List<?> target)
{
int ssize = source.size();
for (int i = ssize - target.size(), j = ssize; i >= 0; i--, j--)
@@ -838,9 +884,9 @@ public class Collections
* @see ArrayList
* @since 1.4
*/
- public static ArrayList list(Enumeration e)
+ public static <T> ArrayList<T> list(Enumeration<T> e)
{
- ArrayList l = new ArrayList();
+ ArrayList<T> l = new ArrayList<T>();
while (e.hasMoreElements())
l.add(e.nextElement());
return l;
@@ -857,7 +903,8 @@ public class Collections
* @exception ClassCastException if elements in c are not mutually comparable
* @exception NullPointerException if null.compareTo is called
*/
- public static Object max(Collection c)
+ public static <T extends Object & Comparable<? super T>>
+ T max(Collection<? extends T> c)
{
return max(c, null);
}
@@ -876,14 +923,15 @@ public class Collections
* @throws NullPointerException if null is compared by natural ordering
* (only possible when order is null)
*/
- public static Object max(Collection c, Comparator order)
+ public static <T> T max(Collection<? extends T> c,
+ Comparator<? super T> order)
{
- Iterator itr = c.iterator();
- Object max = itr.next(); // throws NoSuchElementException
+ Iterator<? extends T> itr = c.iterator();
+ T max = itr.next(); // throws NoSuchElementException
int csize = c.size();
for (int i = 1; i < csize; i++)
{
- Object o = itr.next();
+ T o = itr.next();
if (compare(max, o, order) < 0)
max = o;
}
@@ -901,7 +949,8 @@ public class Collections
* @throws ClassCastException if elements in c are not mutually comparable
* @throws NullPointerException if null.compareTo is called
*/
- public static Object min(Collection c)
+ public static <T extends Object & Comparable<? super T>>
+ T min(Collection<? extends T> c)
{
return min(c, null);
}
@@ -920,14 +969,15 @@ public class Collections
* @throws NullPointerException if null is compared by natural ordering
* (only possible when order is null)
*/
- public static Object min(Collection c, Comparator order)
+ public static <T> T min(Collection<? extends T> c,
+ Comparator<? super T> order)
{
- Iterator itr = c.iterator();
- Object min = itr.next(); // throws NoSuchElementExcception
+ Iterator<? extends T> itr = c.iterator();
+ T min = itr.next(); // throws NoSuchElementExcception
int csize = c.size();
for (int i = 1; i < csize; i++)
{
- Object o = itr.next();
+ T o = itr.next();
if (compare(min, o, order) > 0)
min = o;
}
@@ -949,9 +999,9 @@ public class Collections
* @see Serializable
* @see RandomAccess
*/
- public static List nCopies(final int n, final Object o)
+ public static <T> List<T> nCopies(final int n, final T o)
{
- return new CopiesList(n, o);
+ return new CopiesList<T>(n, o);
}
/**
@@ -960,7 +1010,7 @@ public class Collections
*
* @author Eric Blake (ebb9@email.byu.edu)
*/
- private static final class CopiesList extends AbstractList
+ private static final class CopiesList<T> extends AbstractList<T>
implements Serializable, RandomAccess
{
/**
@@ -978,7 +1028,7 @@ public class Collections
* The repeated list element.
* @serial the list contents
*/
- private final Object element;
+ private final T element;
/**
* Constructs the list.
@@ -987,7 +1037,7 @@ public class Collections
* @param o the object
* @throws IllegalArgumentException if n &lt; 0
*/
- CopiesList(int n, Object o)
+ CopiesList(int n, T o)
{
if (n < 0)
throw new IllegalArgumentException();
@@ -1010,7 +1060,7 @@ public class Collections
* as the list contains only copies of <code>element</code>).
* @return The element used by this list.
*/
- public Object get(int index)
+ public T get(int index)
{
if (index < 0 || index >= n)
throw new IndexOutOfBoundsException();
@@ -1058,11 +1108,11 @@ public class Collections
* elements, all of which are equal to the element
* used by this list.
*/
- public List subList(int from, int to)
+ public List<T> subList(int from, int to)
{
if (from < 0 || to > n)
throw new IndexOutOfBoundsException();
- return new CopiesList(to - from, element);
+ return new CopiesList<T>(to - from, element);
}
/**
@@ -1108,9 +1158,9 @@ public class Collections
* it being added to the list
* @since 1.4
*/
- public static boolean replaceAll(List list, Object oldval, Object newval)
+ public static <T> boolean replaceAll(List<T> list, T oldval, T newval)
{
- ListIterator itr = list.listIterator();
+ ListIterator<T> itr = list.listIterator();
boolean replace_occured = false;
for (int i = list.size(); --i >= 0; )
if (AbstractCollection.equals(oldval, itr.next()))
@@ -1128,7 +1178,7 @@ public class Collections
* @throws UnsupportedOperationException if l.listIterator() does not
* support the set operation
*/
- public static void reverse(List l)
+ public static void reverse(List<?> l)
{
ListIterator i1 = l.listIterator();
int pos1 = 1;
@@ -1136,15 +1186,43 @@ public class Collections
ListIterator i2 = l.listIterator(pos2);
while (pos1 < pos2)
{
- Object o = i1.next();
- i1.set(i2.previous());
- i2.set(o);
+ Object o1 = i1.next();
+ Object o2 = i2.previous();
+ i1.set(o2);
+ i2.set(o1);
++pos1;
--pos2;
}
}
/**
+ * Get a comparator that implements the reverse of the ordering
+ * specified by the given Comparator. If the Comparator is null,
+ * this is equivalent to {@link #reverseOrder()}. The return value
+ * of this method is Serializable, if the specified Comparator is
+ * either Serializable or null.
+ *
+ * @param c the comparator to invert
+ * @return a comparator that imposes reverse ordering
+ * @see Comparable
+ * @see Serializable
+ *
+ * @since 1.5
+ */
+ public static <T> Comparator<T> reverseOrder(final Comparator<T> c)
+ {
+ if (c == null)
+ return (Comparator<T>) rcInstance;
+ return new ReverseComparator<T> ()
+ {
+ public int compare(T a, T b)
+ {
+ return - c.compare(a, b);
+ }
+ };
+ }
+
+ /**
* Get a comparator that implements the reverse of natural ordering. In
* other words, this sorts Comparable objects opposite of how their
* compareTo method would sort. This makes it easy to sort into reverse
@@ -1155,9 +1233,9 @@ public class Collections
* @see Comparable
* @see Serializable
*/
- public static Comparator reverseOrder()
+ public static <T> Comparator<T> reverseOrder()
{
- return rcInstance;
+ return (Comparator<T>) rcInstance;
}
/**
@@ -1171,8 +1249,8 @@ public class Collections
*
* @author Eric Blake (ebb9@email.byu.edu)
*/
- private static final class ReverseComparator
- implements Comparator, Serializable
+ private static class ReverseComparator<T>
+ implements Comparator<T>, Serializable
{
/**
* Compatible with JDK 1.4.
@@ -1193,7 +1271,7 @@ public class Collections
* @param b the second object
* @return &lt;, ==, or &gt; 0 according to b.compareTo(a)
*/
- public int compare(Object a, Object b)
+ public int compare(T a, T b)
{
return ((Comparable) b).compareTo(a);
}
@@ -1229,7 +1307,7 @@ public class Collections
* @throws UnsupportedOperationException if the list does not support set
* @since 1.4
*/
- public static void rotate(List list, int distance)
+ public static void rotate(List<?> list, int distance)
{
int size = list.size();
if (size == 0)
@@ -1262,12 +1340,13 @@ public class Collections
// Now, make the swaps. We must take the remainder every time through
// the inner loop so that we don't overflow i to negative values.
+ List<Object> objList = (List<Object>) list;
while (--lcm >= 0)
{
- Object o = list.get(lcm);
+ Object o = objList.get(lcm);
for (int i = lcm + distance; i != lcm; i = (i + distance) % size)
- o = list.set(i, o);
- list.set(lcm, o);
+ o = objList.set(i, o);
+ objList.set(lcm, o);
}
}
}
@@ -1293,15 +1372,15 @@ public class Collections
* @throws UnsupportedOperationException if l.listIterator() does not
* support the set operation
*/
- public static void shuffle(List l)
+ public static void shuffle(List<?> l)
{
if (defaultRandom == null)
{
synchronized (Collections.class)
- {
- if (defaultRandom == null)
- defaultRandom = new Random();
- }
+ {
+ if (defaultRandom == null)
+ defaultRandom = new Random();
+ }
}
shuffle(l, defaultRandom);
}
@@ -1336,15 +1415,16 @@ public class Collections
* @throws UnsupportedOperationException if l.listIterator() does not
* support the set operation
*/
- public static void shuffle(List l, Random r)
+ public static void shuffle(List<?> l, Random r)
{
int lsize = l.size();
- ListIterator i = l.listIterator(lsize);
+ List<Object> list = (List<Object>) l;
+ ListIterator<Object> i = list.listIterator(lsize);
boolean sequential = isSequential(l);
Object[] a = null; // stores a copy of the list for the sequential case
if (sequential)
- a = l.toArray();
+ a = list.toArray();
for (int pos = lsize - 1; pos > 0; --pos)
{
@@ -1360,12 +1440,94 @@ public class Collections
a[swap] = i.previous();
}
else
- o = l.set(swap, i.previous());
+ o = list.set(swap, i.previous());
i.set(o);
}
}
+ /**
+ * Returns the frequency of the specified object within the supplied
+ * collection. The frequency represents the number of occurrences of
+ * elements within the collection which return <code>true</code> when
+ * compared with the object using the <code>equals</code> method.
+ *
+ * @param c the collection to scan for occurrences of the object.
+ * @param o the object to locate occurrances of within the collection.
+ * @throws NullPointerException if the collection is <code>null</code>.
+ * @since 1.5
+ */
+ public static int frequency (Collection<?> c, Object o)
+ {
+ int result = 0;
+ for (Object v : c)
+ {
+ if (AbstractCollection.equals(o, v))
+ ++result;
+ }
+ return result;
+ }
+
+ /**
+ * Adds all the specified elements to the given collection, in a similar
+ * way to the <code>addAll</code> method of the <code>Collection</code>.
+ * However, this is a variable argument method which allows the new elements
+ * to be specified individually or in array form, as opposed to the list
+ * required by the collection's <code>addAll</code> method. This has
+ * benefits in both simplicity (multiple elements can be added without
+ * having to be wrapped inside a grouping structure) and efficiency
+ * (as a redundant list doesn't have to be created to add an individual
+ * set of elements or an array).
+ *
+ * @param c the collection to which the elements should be added.
+ * @param a the elements to be added to the collection.
+ * @return true if the collection changed its contents as a result.
+ * @throws UnsupportedOperationException if the collection does not support
+ * addition.
+ * @throws NullPointerException if one or more elements in a are null,
+ * and the collection does not allow null
+ * elements. This exception is also thrown
+ * if either <code>c</code> or <code>a</code>
+ * are null.
+ * @throws IllegalArgumentException if the collection won't allow an element
+ * to be added for some other reason.
+ * @since 1.5
+ */
+ public static <T> boolean addAll(Collection<? super T> c, T... a)
+ {
+ boolean overall = false;
+
+ for (T element : a)
+ {
+ boolean result = c.add(element);
+ if (result)
+ overall = true;
+ }
+ return overall;
+ }
+
+ /**
+ * Returns true if the two specified collections have no elements in
+ * common. This method may give unusual results if one or both collections
+ * use a non-standard equality test. In the trivial case of comparing
+ * a collection with itself, this method returns true if, and only if,
+ * the collection is empty.
+ *
+ * @param c1 the first collection to compare.
+ * @param c2 the second collection to compare.
+ * @return true if the collections are disjoint.
+ * @throws NullPointerException if either collection is null.
+ * @since 1.5
+ */
+ public static boolean disjoint(Collection<?> c1, Collection<?> c2)
+ {
+ Collection<Object> oc1 = (Collection<Object>) c1;
+ for (Object o : oc1)
+ if (c2.contains(o))
+ return false;
+ return true;
+ }
+
/**
* Obtain an immutable Set consisting of a single element. The return value
@@ -1375,9 +1537,9 @@ public class Collections
* @return an immutable Set containing only o
* @see Serializable
*/
- public static Set singleton(Object o)
+ public static <T> Set<T> singleton(T o)
{
- return new SingletonSet(o);
+ return new SingletonSet<T>(o);
}
/**
@@ -1386,7 +1548,7 @@ public class Collections
*
* @author Eric Blake (ebb9@email.byu.edu)
*/
- private static final class SingletonSet extends AbstractSet
+ private static final class SingletonSet<T> extends AbstractSet<T>
implements Serializable
{
/**
@@ -1399,13 +1561,13 @@ public class Collections
* The single element; package visible for use in nested class.
* @serial the singleton
*/
- final Object element;
+ final T element;
/**
* Construct a singleton.
* @param o the element
*/
- SingletonSet(Object o)
+ SingletonSet(T o)
{
element = o;
}
@@ -1422,9 +1584,9 @@ public class Collections
/**
* Returns an iterator over the lone element.
*/
- public Iterator iterator()
+ public Iterator<T> iterator()
{
- return new Iterator()
+ return new Iterator<T>()
{
/**
* Flag to indicate whether or not the element has
@@ -1450,7 +1612,7 @@ public class Collections
* @throws NoSuchElementException if the object
* has already been retrieved.
*/
- public Object next()
+ public T next()
{
if (hasNext)
{
@@ -1497,9 +1659,9 @@ public class Collections
* @return <code>true</code> if c only contains either no elements or
* elements equal to the element in this singleton.
*/
- public boolean containsAll(Collection c)
+ public boolean containsAll(Collection<?> c)
{
- Iterator i = c.iterator();
+ Iterator<?> i = c.iterator();
int pos = c.size();
while (--pos >= 0)
if (! equals(i.next(), element))
@@ -1549,9 +1711,9 @@ public class Collections
* @see RandomAccess
* @since 1.3
*/
- public static List singletonList(Object o)
+ public static <T> List<T> singletonList(T o)
{
- return new SingletonList(o);
+ return new SingletonList<T>(o);
}
/**
@@ -1560,7 +1722,7 @@ public class Collections
*
* @author Eric Blake (ebb9@email.byu.edu)
*/
- private static final class SingletonList extends AbstractList
+ private static final class SingletonList<T> extends AbstractList<T>
implements Serializable, RandomAccess
{
/**
@@ -1572,13 +1734,13 @@ public class Collections
* The single element.
* @serial the singleton
*/
- private final Object element;
+ private final T element;
/**
* Construct a singleton.
* @param o the element
*/
- SingletonList(Object o)
+ SingletonList(T o)
{
element = o;
}
@@ -1601,7 +1763,7 @@ public class Collections
* @throws IndexOutOfBoundsException if
* index is not 0.
*/
- public Object get(int index)
+ public T get(int index)
{
if (index == 0)
return element;
@@ -1628,9 +1790,9 @@ public class Collections
* @return <code>true</code> if c only contains either no elements or
* elements equal to the element in this singleton.
*/
- public boolean containsAll(Collection c)
+ public boolean containsAll(Collection<?> c)
{
- Iterator i = c.iterator();
+ Iterator<?> i = c.iterator();
int pos = c.size();
while (--pos >= 0)
if (! equals(i.next(), element))
@@ -1682,7 +1844,7 @@ public class Collections
* @throws IndexOutOfBoundsException if either bound is greater
* than 1.
*/
- public List subList(int from, int to)
+ public List<T> subList(int from, int to)
{
if (from == to && (to == 0 || to == 1))
return EMPTY_LIST;
@@ -1725,9 +1887,9 @@ public class Collections
* @see Serializable
* @since 1.3
*/
- public static Map singletonMap(Object key, Object value)
+ public static <K, V> Map<K, V> singletonMap(K key, V value)
{
- return new SingletonMap(key, value);
+ return new SingletonMap<K, V>(key, value);
}
/**
@@ -1736,7 +1898,7 @@ public class Collections
*
* @author Eric Blake (ebb9@email.byu.edu)
*/
- private static final class SingletonMap extends AbstractMap
+ private static final class SingletonMap<K, V> extends AbstractMap<K, V>
implements Serializable
{
/**
@@ -1748,25 +1910,25 @@ public class Collections
* The single key.
* @serial the singleton key
*/
- private final Object k;
+ private final K k;
/**
* The corresponding value.
* @serial the singleton value
*/
- private final Object v;
+ private final V v;
/**
* Cache the entry set.
*/
- private transient Set entries;
+ private transient Set<Map.Entry<K, V>> entries;
/**
* Construct a singleton.
* @param key the key
* @param value the value
*/
- SingletonMap(Object key, Object value)
+ SingletonMap(K key, V value)
{
k = key;
v = value;
@@ -1777,25 +1939,28 @@ public class Collections
*
* @return A singleton containing the map entry.
*/
- public Set entrySet()
+ public Set<Map.Entry<K, V>> entrySet()
{
if (entries == null)
- entries = singleton(new AbstractMap.BasicMapEntry(k, v)
- {
- /**
- * Sets the value of the map entry to the supplied value.
- * An exception is always thrown, as the map is immutable.
- *
- * @param o The new value.
- * @return The old value.
- * @throws UnsupportedOperationException as setting the value
- * is not supported.
- */
- public Object setValue(Object o)
- {
- throw new UnsupportedOperationException();
- }
- });
+ {
+ Map.Entry<K,V> entry = new AbstractMap.SimpleEntry<K, V>(k, v)
+ {
+ /**
+ * Sets the value of the map entry to the supplied value.
+ * An exception is always thrown, as the map is immutable.
+ *
+ * @param o The new value.
+ * @return The old value.
+ * @throws UnsupportedOperationException as setting the value
+ * is not supported.
+ */
+ public V setValue(V o)
+ {
+ throw new UnsupportedOperationException();
+ }
+ };
+ entries = singleton(entry);
+ }
return entries;
}
@@ -1832,7 +1997,7 @@ public class Collections
* @return The singleton value if the key is the same as the
* singleton key, null otherwise.
*/
- public Object get(Object key)
+ public V get(Object key)
{
return equals(key, k) ? v : null;
}
@@ -1853,7 +2018,7 @@ public class Collections
*
* @return A singleton containing the key.
*/
- public Set keySet()
+ public Set<K> keySet()
{
if (keys == null)
keys = singleton(k);
@@ -1876,7 +2041,7 @@ public class Collections
*
* @return A singleton containing the value.
*/
- public Collection values()
+ public Collection<V> values()
{
if (values == null)
values = singleton(v);
@@ -1910,7 +2075,7 @@ public class Collections
* some element that is <code>null</code>.
* @see Arrays#sort(Object[])
*/
- public static void sort(List l)
+ public static <T extends Comparable<? super T>> void sort(List<T> l)
{
sort(l, null);
}
@@ -1934,15 +2099,15 @@ public class Collections
*
* @see Arrays#sort(Object[], Comparator)
*/
- public static void sort(List l, Comparator c)
+ public static <T> void sort(List<T> l, Comparator<? super T> c)
{
- Object[] a = l.toArray();
+ T[] a = (T[]) l.toArray();
Arrays.sort(a, c);
- ListIterator i = l.listIterator();
+ ListIterator<T> i = l.listIterator();
for (int pos = 0, alen = a.length; pos < alen; pos++)
{
- i.next();
- i.set(a[pos]);
+ i.next();
+ i.set(a[pos]);
}
}
@@ -1958,9 +2123,10 @@ public class Collections
* list.size()
* @since 1.4
*/
- public static void swap(List l, int i, int j)
+ public static void swap(List<?> l, int i, int j)
{
- l.set(i, l.set(j, l.get(i)));
+ List<Object> list = (List<Object>) l;
+ list.set(i, list.set(j, list.get(i)));
}
@@ -1991,9 +2157,9 @@ public class Collections
* @return a synchronized view of the collection
* @see Serializable
*/
- public static Collection synchronizedCollection(Collection c)
+ public static <T> Collection<T> synchronizedCollection(Collection<T> c)
{
- return new SynchronizedCollection(c);
+ return new SynchronizedCollection<T>(c);
}
/**
@@ -2004,8 +2170,8 @@ public class Collections
*
* @author Eric Blake (ebb9@email.byu.edu)
*/
- static class SynchronizedCollection
- implements Collection, Serializable
+ static class SynchronizedCollection<T>
+ implements Collection<T>, Serializable
{
/**
* Compatible with JDK 1.4.
@@ -2016,7 +2182,7 @@ public class Collections
* The wrapped collection. Package visible for use by subclasses.
* @serial the real collection
*/
- final Collection c;
+ final Collection<T> c;
/**
* The object to synchronize on. When an instance is created via public
@@ -2031,7 +2197,7 @@ public class Collections
* @param c the collection to wrap
* @throws NullPointerException if c is null
*/
- SynchronizedCollection(Collection c)
+ SynchronizedCollection(Collection<T> c)
{
this.c = c;
mutex = this;
@@ -2045,7 +2211,7 @@ public class Collections
* @param sync the mutex
* @param c the collection
*/
- SynchronizedCollection(Object sync, Collection c)
+ SynchronizedCollection(Object sync, Collection<T> c)
{
this.c = c;
mutex = sync;
@@ -2067,7 +2233,7 @@ public class Collections
* @throws IllegalArgumentException if o cannot be added to this
* collection for some other reason.
*/
- public boolean add(Object o)
+ public boolean add(T o)
{
synchronized (mutex)
{
@@ -2092,7 +2258,7 @@ public class Collections
* @throws IllegalArgumentException if some element of col cannot be added
* to this collection for some other reason.
*/
- public boolean addAll(Collection col)
+ public boolean addAll(Collection<? extends T> col)
{
synchronized (mutex)
{
@@ -2149,7 +2315,7 @@ public class Collections
* collection does not support null values.
* @throws NullPointerException if cl itself is null.
*/
- public boolean containsAll(Collection c1)
+ public boolean containsAll(Collection<?> c1)
{
synchronized (mutex)
{
@@ -2180,11 +2346,11 @@ public class Collections
* @return An iterator over the elements in the underlying collection,
* which returns each element in any order.
*/
- public Iterator iterator()
+ public Iterator<T> iterator()
{
synchronized (mutex)
{
- return new SynchronizedIterator(mutex, c.iterator());
+ return new SynchronizedIterator<T>(mutex, c.iterator());
}
}
@@ -2226,7 +2392,7 @@ public class Collections
* collection does not support removing null values.
* @throws NullPointerException if c itself is null.
*/
- public boolean removeAll(Collection col)
+ public boolean removeAll(Collection<?> col)
{
synchronized (mutex)
{
@@ -2251,7 +2417,7 @@ public class Collections
* collection does not support removing null values.
* @throws NullPointerException if c itself is null.
*/
- public boolean retainAll(Collection col)
+ public boolean retainAll(Collection<?> col)
{
synchronized (mutex)
{
@@ -2307,7 +2473,7 @@ public class Collections
* @throws ArrayStoreException if the type of any element of the
* collection is not a subtype of the element type of a.
*/
- public Object[] toArray(Object[] a)
+ public <T> T[] toArray(T[] a)
{
synchronized (mutex)
{
@@ -2337,7 +2503,7 @@ public class Collections
*
* @author Eric Blake (ebb9@email.byu.edu)
*/
- private static class SynchronizedIterator implements Iterator
+ private static class SynchronizedIterator<T> implements Iterator<T>
{
/**
* The object to synchronize on. Package visible for use by subclass.
@@ -2347,14 +2513,14 @@ public class Collections
/**
* The wrapped iterator.
*/
- private final Iterator i;
+ private final Iterator<T> i;
/**
* Only trusted code creates a wrapper, with the specified sync.
* @param sync the mutex
* @param i the wrapped iterator
*/
- SynchronizedIterator(Object sync, Iterator i)
+ SynchronizedIterator(Object sync, Iterator<T> i)
{
this.i = i;
mutex = sync;
@@ -2367,7 +2533,7 @@ public class Collections
* @return The next object in the collection.
* @throws NoSuchElementException if there are no more elements
*/
- public Object next()
+ public T next()
{
synchronized (mutex)
{
@@ -2441,11 +2607,11 @@ public class Collections
* @see Serializable
* @see RandomAccess
*/
- public static List synchronizedList(List l)
+ public static <T> List<T> synchronizedList(List<T> l)
{
if (l instanceof RandomAccess)
- return new SynchronizedRandomAccessList(l);
- return new SynchronizedList(l);
+ return new SynchronizedRandomAccessList<T>(l);
+ return new SynchronizedList<T>(l);
}
/**
@@ -2456,8 +2622,8 @@ public class Collections
*
* @author Eric Blake (ebb9@email.byu.edu)
*/
- static class SynchronizedList extends SynchronizedCollection
- implements List
+ static class SynchronizedList<T> extends SynchronizedCollection<T>
+ implements List<T>
{
/**
* Compatible with JDK 1.4.
@@ -2469,14 +2635,14 @@ public class Collections
* excessive casting. Package visible for use by subclass.
* @serial the wrapped list
*/
- final List list;
+ final List<T> list;
/**
* Wrap a given list.
* @param l the list to wrap
* @throws NullPointerException if l is null
*/
- SynchronizedList(List l)
+ SynchronizedList(List<T> l)
{
super(l);
list = l;
@@ -2487,7 +2653,7 @@ public class Collections
* @param sync the mutex
* @param l the list
*/
- SynchronizedList(Object sync, List l)
+ SynchronizedList(Object sync, List<T> l)
{
super(sync, l);
list = l;
@@ -2512,7 +2678,7 @@ public class Collections
* @throws NullPointerException if o is null and this list doesn't support
* the addition of null values.
*/
- public void add(int index, Object o)
+ public void add(int index, T o)
{
synchronized (mutex)
{
@@ -2538,7 +2704,7 @@ public class Collections
* @throws NullPointerException if o is null and this list doesn't support
* the addition of null values.
*/
- public boolean addAll(int index, Collection c)
+ public boolean addAll(int index, Collection<? extends T> c)
{
synchronized (mutex)
{
@@ -2574,7 +2740,7 @@ public class Collections
* @return the element at index index in this list
* @throws IndexOutOfBoundsException if index &lt; 0 || index &gt;= size()
*/
- public Object get(int index)
+ public T get(int index)
{
synchronized (mutex)
{
@@ -2651,11 +2817,11 @@ public class Collections
* to be performed, in addition to those supplied by the
* standard iterator.
*/
- public ListIterator listIterator()
+ public ListIterator<T> listIterator()
{
synchronized (mutex)
{
- return new SynchronizedListIterator(mutex, list.listIterator());
+ return new SynchronizedListIterator<T>(mutex, list.listIterator());
}
}
@@ -2676,11 +2842,12 @@ public class Collections
* standard iterator.
* @throws IndexOutOfBoundsException if index &lt; 0 || index &gt; size()
*/
- public ListIterator listIterator(int index)
+ public ListIterator<T> listIterator(int index)
{
synchronized (mutex)
{
- return new SynchronizedListIterator(mutex, list.listIterator(index));
+ return new SynchronizedListIterator<T>(mutex,
+ list.listIterator(index));
}
}
@@ -2695,7 +2862,7 @@ public class Collections
* remove operation
* @throws IndexOutOfBoundsException if index &lt; 0 || index &gt;= size()
*/
- public Object remove(int index)
+ public T remove(int index)
{
synchronized (mutex)
{
@@ -2721,7 +2888,7 @@ public class Collections
* @throws NullPointerException if o is null and this
* list does not support null values.
*/
- public Object set(int index, Object o)
+ public T set(int index, T o)
{
synchronized (mutex)
{
@@ -2747,11 +2914,12 @@ public class Collections
* @throws IndexOutOfBoundsException if fromIndex &lt; 0
* || toIndex &gt; size() || fromIndex &gt; toIndex
*/
- public List subList(int fromIndex, int toIndex)
+ public List<T> subList(int fromIndex, int toIndex)
{
synchronized (mutex)
{
- return new SynchronizedList(mutex, list.subList(fromIndex, toIndex));
+ return new SynchronizedList<T>(mutex,
+ list.subList(fromIndex, toIndex));
}
}
} // class SynchronizedList
@@ -2763,8 +2931,8 @@ public class Collections
*
* @author Eric Blake (ebb9@email.byu.edu)
*/
- private static final class SynchronizedRandomAccessList
- extends SynchronizedList implements RandomAccess
+ private static final class SynchronizedRandomAccessList<T>
+ extends SynchronizedList<T> implements RandomAccess
{
/**
* Compatible with JDK 1.4.
@@ -2776,7 +2944,7 @@ public class Collections
* @param l the list to wrap
* @throws NullPointerException if l is null
*/
- SynchronizedRandomAccessList(List l)
+ SynchronizedRandomAccessList(List<T> l)
{
super(l);
}
@@ -2787,7 +2955,7 @@ public class Collections
* @param sync the mutex
* @param l the list
*/
- SynchronizedRandomAccessList(Object sync, List l)
+ SynchronizedRandomAccessList(Object sync, List<T> l)
{
super(sync, l);
}
@@ -2811,13 +2979,13 @@ public class Collections
* @throws IndexOutOfBoundsException if fromIndex &lt; 0
* || toIndex &gt; size() || fromIndex &gt; toIndex
*/
- public List subList(int fromIndex, int toIndex)
+ public List<T> subList(int fromIndex, int toIndex)
{
synchronized (mutex)
{
- return new SynchronizedRandomAccessList(mutex,
- list.subList(fromIndex,
- toIndex));
+ return new SynchronizedRandomAccessList<T>(mutex,
+ list.subList(fromIndex,
+ toIndex));
}
}
} // class SynchronizedRandomAccessList
@@ -2828,21 +2996,21 @@ public class Collections
*
* @author Eric Blake (ebb9@email.byu.edu)
*/
- private static final class SynchronizedListIterator
- extends SynchronizedIterator implements ListIterator
+ private static final class SynchronizedListIterator<T>
+ extends SynchronizedIterator<T> implements ListIterator<T>
{
/**
* The wrapped iterator, stored both here and in the superclass to
* avoid excessive casting.
*/
- private final ListIterator li;
+ private final ListIterator<T> li;
/**
* Only trusted code creates a wrapper, with the specified sync.
* @param sync the mutex
* @param li the wrapped iterator
*/
- SynchronizedListIterator(Object sync, ListIterator li)
+ SynchronizedListIterator(Object sync, ListIterator<T> li)
{
super(sync, li);
this.li = li;
@@ -2866,7 +3034,7 @@ public class Collections
* @throws UnsupportedOperationException if this ListIterator does not
* support the add operation.
*/
- public void add(Object o)
+ public void add(T o)
{
synchronized (mutex)
{
@@ -2916,7 +3084,7 @@ public class Collections
* @return the next element in the list in the reverse direction
* @throws NoSuchElementException if there are no more elements
*/
- public Object previous()
+ public T previous()
{
synchronized (mutex)
{
@@ -2958,7 +3126,7 @@ public class Collections
* @throws UnsupportedOperationException if this ListIterator does not
* support the set operation
*/
- public void set(Object o)
+ public void set(T o)
{
synchronized (mutex)
{
@@ -2992,9 +3160,9 @@ public class Collections
* @return a synchronized view of the map
* @see Serializable
*/
- public static Map synchronizedMap(Map m)
+ public static <K, V> Map<K, V> synchronizedMap(Map<K, V> m)
{
- return new SynchronizedMap(m);
+ return new SynchronizedMap<K, V>(m);
}
/**
@@ -3003,7 +3171,7 @@ public class Collections
*
* @author Eric Blake (ebb9@email.byu.edu)
*/
- private static class SynchronizedMap implements Map, Serializable
+ private static class SynchronizedMap<K, V> implements Map<K, V>, Serializable
{
/**
* Compatible with JDK 1.4.
@@ -3014,7 +3182,7 @@ public class Collections
* The wrapped map.
* @serial the real map
*/
- private final Map m;
+ private final Map<K, V> m;
/**
* The object to synchronize on. When an instance is created via public
@@ -3028,24 +3196,24 @@ public class Collections
/**
* Cache the entry set.
*/
- private transient Set entries;
+ private transient Set<Map.Entry<K, V>> entries;
/**
* Cache the key set.
*/
- private transient Set keys;
+ private transient Set<K> keys;
/**
* Cache the value collection.
*/
- private transient Collection values;
+ private transient Collection<V> values;
/**
* Wrap a given map.
* @param m the map to wrap
* @throws NullPointerException if m is null
*/
- SynchronizedMap(Map m)
+ SynchronizedMap(Map<K, V> m)
{
this.m = m;
mutex = this;
@@ -3058,7 +3226,7 @@ public class Collections
* @param sync the mutex
* @param m the map
*/
- SynchronizedMap(Object sync, Map m)
+ SynchronizedMap(Object sync, Map<K, V> m)
{
this.m = m;
mutex = sync;
@@ -3122,15 +3290,15 @@ public class Collections
// means "return a SynchronizedSet, except that the iterator() method
// returns an SynchronizedIterator whose next() method returns a
// synchronized wrapper around its normal return value".
- public Set entrySet()
+ public Set<Map.Entry<K, V>> entrySet()
{
// Define this here to spare some nesting.
- class SynchronizedMapEntry implements Map.Entry
+ class SynchronizedMapEntry<K, V> implements Map.Entry<K, V>
{
- final Map.Entry e;
- SynchronizedMapEntry(Object o)
+ final Map.Entry<K, V> e;
+ SynchronizedMapEntry(Map.Entry<K, V> o)
{
- e = (Map.Entry) o;
+ e = o;
}
/**
@@ -3155,7 +3323,7 @@ public class Collections
*
* @return The key of the underlying map entry.
*/
- public Object getKey()
+ public K getKey()
{
synchronized (mutex)
{
@@ -3169,7 +3337,7 @@ public class Collections
*
* @return The value of the underlying map entry.
*/
- public Object getValue()
+ public V getValue()
{
synchronized (mutex)
{
@@ -3210,7 +3378,7 @@ public class Collections
* prevents it from existing in this map.
* @throws NullPointerException if the map forbids null values.
*/
- public Object setValue(Object value)
+ public V setValue(V value)
{
synchronized (mutex)
{
@@ -3237,7 +3405,7 @@ public class Collections
if (entries == null)
synchronized (mutex)
{
- entries = new SynchronizedSet(mutex, m.entrySet())
+ entries = new SynchronizedSet<Map.Entry<K, V>>(mutex, m.entrySet())
{
/**
* Returns an iterator over the set. The iterator has no specific order,
@@ -3247,11 +3415,12 @@ public class Collections
*
* @return A synchronized set iterator.
*/
- public Iterator iterator()
+ public Iterator<Map.Entry<K, V>> iterator()
{
synchronized (super.mutex)
{
- return new SynchronizedIterator(super.mutex, c.iterator())
+ return new SynchronizedIterator<Map.Entry<K, V>>(super.mutex,
+ c.iterator())
{
/**
* Retrieves the next map entry from the iterator.
@@ -3261,11 +3430,11 @@ public class Collections
*
* @return A synchronized map entry.
*/
- public Object next()
+ public Map.Entry<K, V> next()
{
synchronized (super.mutex)
{
- return new SynchronizedMapEntry(super.next());
+ return new SynchronizedMapEntry<K, V>(super.next());
}
}
};
@@ -3309,7 +3478,7 @@ public class Collections
* @throws ClassCastException if the key is an inappropriate type.
* @throws NullPointerException if this map does not accept null keys.
*/
- public Object get(Object key)
+ public V get(Object key)
{
synchronized (mutex)
{
@@ -3359,12 +3528,12 @@ public class Collections
*
* @return A synchronized set containing the keys of the underlying map.
*/
- public Set keySet()
+ public Set<K> keySet()
{
if (keys == null)
synchronized (mutex)
{
- keys = new SynchronizedSet(mutex, m.keySet());
+ keys = new SynchronizedSet<K>(mutex, m.keySet());
}
return keys;
}
@@ -3387,7 +3556,7 @@ public class Collections
* and the map forbids null keys or values
* @see #containsKey(Object)
*/
- public Object put(Object key, Object value)
+ public V put(K key, V value)
{
synchronized (mutex)
{
@@ -3409,7 +3578,7 @@ public class Collections
* if <code>m</code> is null.
* @see #put(Object, Object)
*/
- public void putAll(Map map)
+ public void putAll(Map<? extends K, ? extends V> map)
{
synchronized (mutex)
{
@@ -3432,7 +3601,7 @@ public class Collections
* @throws ClassCastException if the type of the key is not a valid type
* for this map.
*/
- public Object remove(Object o)
+ public V remove(Object o)
{
synchronized (mutex)
{
@@ -3485,12 +3654,12 @@ public class Collections
*
* @return the collection of all values in the underlying map.
*/
- public Collection values()
+ public Collection<V> values()
{
if (values == null)
synchronized (mutex)
{
- values = new SynchronizedCollection(mutex, m.values());
+ values = new SynchronizedCollection<V>(mutex, m.values());
}
return values;
}
@@ -3520,9 +3689,9 @@ public class Collections
* @return a synchronized view of the set
* @see Serializable
*/
- public static Set synchronizedSet(Set s)
+ public static <T> Set<T> synchronizedSet(Set<T> s)
{
- return new SynchronizedSet(s);
+ return new SynchronizedSet<T>(s);
}
/**
@@ -3533,8 +3702,8 @@ public class Collections
*
* @author Eric Blake (ebb9@email.byu.edu)
*/
- static class SynchronizedSet extends SynchronizedCollection
- implements Set
+ static class SynchronizedSet<T> extends SynchronizedCollection<T>
+ implements Set<T>
{
/**
* Compatible with JDK 1.4.
@@ -3546,7 +3715,7 @@ public class Collections
* @param s the set to wrap
* @throws NullPointerException if s is null
*/
- SynchronizedSet(Set s)
+ SynchronizedSet(Set<T> s)
{
super(s);
}
@@ -3556,7 +3725,7 @@ public class Collections
* @param sync the mutex
* @param s the set
*/
- SynchronizedSet(Object sync, Set s)
+ SynchronizedSet(Object sync, Set<T> s)
{
super(sync, s);
}
@@ -3626,9 +3795,9 @@ public class Collections
* @return a synchronized view of the sorted map
* @see Serializable
*/
- public static SortedMap synchronizedSortedMap(SortedMap m)
+ public static <K, V> SortedMap<K, V> synchronizedSortedMap(SortedMap<K, V> m)
{
- return new SynchronizedSortedMap(m);
+ return new SynchronizedSortedMap<K, V>(m);
}
/**
@@ -3637,8 +3806,9 @@ public class Collections
*
* @author Eric Blake (ebb9@email.byu.edu)
*/
- private static final class SynchronizedSortedMap extends SynchronizedMap
- implements SortedMap
+ private static final class SynchronizedSortedMap<K, V>
+ extends SynchronizedMap<K, V>
+ implements SortedMap<K, V>
{
/**
* Compatible with JDK 1.4.
@@ -3650,14 +3820,14 @@ public class Collections
* excessive casting.
* @serial the wrapped map
*/
- private final SortedMap sm;
+ private final SortedMap<K, V> sm;
/**
* Wrap a given map.
* @param sm the map to wrap
* @throws NullPointerException if sm is null
*/
- SynchronizedSortedMap(SortedMap sm)
+ SynchronizedSortedMap(SortedMap<K, V> sm)
{
super(sm);
this.sm = sm;
@@ -3668,7 +3838,7 @@ public class Collections
* @param sync the mutex
* @param sm the map
*/
- SynchronizedSortedMap(Object sync, SortedMap sm)
+ SynchronizedSortedMap(Object sync, SortedMap<K, V> sm)
{
super(sync, sm);
this.sm = sm;
@@ -3681,7 +3851,7 @@ public class Collections
*
* @return the sorting comparator.
*/
- public Comparator comparator()
+ public Comparator<? super K> comparator()
{
synchronized (mutex)
{
@@ -3696,7 +3866,7 @@ public class Collections
* @return the first key.
* @throws NoSuchElementException if this map is empty.
*/
- public Object firstKey()
+ public K firstKey()
{
synchronized (mutex)
{
@@ -3723,11 +3893,11 @@ public class Collections
* @throws NullPointerException if toKey is null. but the map does not allow
* null keys.
*/
- public SortedMap headMap(Object toKey)
+ public SortedMap<K, V> headMap(K toKey)
{
synchronized (mutex)
{
- return new SynchronizedSortedMap(mutex, sm.headMap(toKey));
+ return new SynchronizedSortedMap<K, V>(mutex, sm.headMap(toKey));
}
}
@@ -3738,7 +3908,7 @@ public class Collections
* @return the last key.
* @throws NoSuchElementException if this map is empty.
*/
- public Object lastKey()
+ public K lastKey()
{
synchronized (mutex)
{
@@ -3764,11 +3934,12 @@ public class Collections
* @throws NullPointerException if fromKey or toKey is null. but the map does
* not allow null keys.
*/
- public SortedMap subMap(Object fromKey, Object toKey)
+ public SortedMap<K, V> subMap(K fromKey, K toKey)
{
synchronized (mutex)
{
- return new SynchronizedSortedMap(mutex, sm.subMap(fromKey, toKey));
+ return new SynchronizedSortedMap<K, V>(mutex,
+ sm.subMap(fromKey, toKey));
}
}
@@ -3788,11 +3959,11 @@ public class Collections
* @throws NullPointerException if fromKey is null. but the map does not allow
* null keys.
*/
- public SortedMap tailMap(Object fromKey)
+ public SortedMap<K, V> tailMap(K fromKey)
{
synchronized (mutex)
{
- return new SynchronizedSortedMap(mutex, sm.tailMap(fromKey));
+ return new SynchronizedSortedMap<K, V>(mutex, sm.tailMap(fromKey));
}
}
} // class SynchronizedSortedMap
@@ -3822,9 +3993,9 @@ public class Collections
* @return a synchronized view of the sorted set
* @see Serializable
*/
- public static SortedSet synchronizedSortedSet(SortedSet s)
+ public static <T> SortedSet<T> synchronizedSortedSet(SortedSet<T> s)
{
- return new SynchronizedSortedSet(s);
+ return new SynchronizedSortedSet<T>(s);
}
/**
@@ -3833,8 +4004,9 @@ public class Collections
*
* @author Eric Blake (ebb9@email.byu.edu)
*/
- private static final class SynchronizedSortedSet extends SynchronizedSet
- implements SortedSet
+ private static final class SynchronizedSortedSet<T>
+ extends SynchronizedSet<T>
+ implements SortedSet<T>
{
/**
* Compatible with JDK 1.4.
@@ -3846,14 +4018,14 @@ public class Collections
* excessive casting.
* @serial the wrapped set
*/
- private final SortedSet ss;
+ private final SortedSet<T> ss;
/**
* Wrap a given set.
* @param ss the set to wrap
* @throws NullPointerException if ss is null
*/
- SynchronizedSortedSet(SortedSet ss)
+ SynchronizedSortedSet(SortedSet<T> ss)
{
super(ss);
this.ss = ss;
@@ -3864,7 +4036,7 @@ public class Collections
* @param sync the mutex
* @param ss the set
*/
- SynchronizedSortedSet(Object sync, SortedSet ss)
+ SynchronizedSortedSet(Object sync, SortedSet<T> ss)
{
super(sync, ss);
this.ss = ss;
@@ -3877,7 +4049,7 @@ public class Collections
*
* @return the sorting comparator.
*/
- public Comparator comparator()
+ public Comparator<? super T> comparator()
{
synchronized (mutex)
{
@@ -3892,7 +4064,7 @@ public class Collections
* @return the first element.
* @throws NoSuchElementException if this set is empty.
*/
- public Object first()
+ public T first()
{
synchronized (mutex)
{
@@ -3919,11 +4091,11 @@ public class Collections
* @throws NullPointerException if toElement is null. but the set does not allow
* null elements.
*/
- public SortedSet headSet(Object toElement)
+ public SortedSet<T> headSet(T toElement)
{
synchronized (mutex)
{
- return new SynchronizedSortedSet(mutex, ss.headSet(toElement));
+ return new SynchronizedSortedSet<T>(mutex, ss.headSet(toElement));
}
}
@@ -3934,7 +4106,7 @@ public class Collections
* @return the last element.
* @throws NoSuchElementException if this set is empty.
*/
- public Object last()
+ public T last()
{
synchronized (mutex)
{
@@ -3960,12 +4132,13 @@ public class Collections
* @throws NullPointerException if fromElement or toElement is null. but the set does
* not allow null elements.
*/
- public SortedSet subSet(Object fromElement, Object toElement)
+ public SortedSet<T> subSet(T fromElement, T toElement)
{
synchronized (mutex)
{
- return new SynchronizedSortedSet(mutex,
- ss.subSet(fromElement, toElement));
+ return new SynchronizedSortedSet<T>(mutex,
+ ss.subSet(fromElement,
+ toElement));
}
}
@@ -3985,11 +4158,11 @@ public class Collections
* @throws NullPointerException if fromElement is null. but the set does not allow
* null elements.
*/
- public SortedSet tailSet(Object fromElement)
+ public SortedSet<T> tailSet(T fromElement)
{
synchronized (mutex)
{
- return new SynchronizedSortedSet(mutex, ss.tailSet(fromElement));
+ return new SynchronizedSortedSet<T>(mutex, ss.tailSet(fromElement));
}
}
} // class SynchronizedSortedSet
@@ -4014,9 +4187,9 @@ public class Collections
* @return a read-only view of the collection
* @see Serializable
*/
- public static Collection unmodifiableCollection(Collection c)
+ public static <T> Collection<T> unmodifiableCollection(Collection<? extends T> c)
{
- return new UnmodifiableCollection(c);
+ return new UnmodifiableCollection<T>(c);
}
/**
@@ -4025,8 +4198,8 @@ public class Collections
*
* @author Eric Blake (ebb9@email.byu.edu)
*/
- private static class UnmodifiableCollection
- implements Collection, Serializable
+ private static class UnmodifiableCollection<T>
+ implements Collection<T>, Serializable
{
/**
* Compatible with JDK 1.4.
@@ -4037,14 +4210,14 @@ public class Collections
* The wrapped collection. Package visible for use by subclasses.
* @serial the real collection
*/
- final Collection c;
+ final Collection<? extends T> c;
/**
* Wrap a given collection.
* @param c the collection to wrap
* @throws NullPointerException if c is null
*/
- UnmodifiableCollection(Collection c)
+ UnmodifiableCollection(Collection<? extends T> c)
{
this.c = c;
if (c == null)
@@ -4060,7 +4233,7 @@ public class Collections
* @throws UnsupportedOperationException as an unmodifiable collection does not
* support the add operation.
*/
- public boolean add(Object o)
+ public boolean add(T o)
{
throw new UnsupportedOperationException();
}
@@ -4074,7 +4247,7 @@ public class Collections
* @throws UnsupportedOperationException as an unmodifiable collection does not
* support the <code>addAll</code> operation.
*/
- public boolean addAll(Collection c)
+ public boolean addAll(Collection<? extends T> c)
{
throw new UnsupportedOperationException();
}
@@ -4122,7 +4295,7 @@ public class Collections
* collection does not support null values.
* @throws NullPointerException if c itself is null.
*/
- public boolean containsAll(Collection c1)
+ public boolean containsAll(Collection<?> c1)
{
return c.containsAll(c1);
}
@@ -4145,9 +4318,9 @@ public class Collections
* @return an UnmodifiableIterator over the elements of the underlying
* collection, in any order.
*/
- public Iterator iterator()
+ public Iterator<T> iterator()
{
- return new UnmodifiableIterator(c.iterator());
+ return new UnmodifiableIterator<T>(c.iterator());
}
/**
@@ -4175,7 +4348,7 @@ public class Collections
* @throws UnsupportedOperationException as an unmodifiable collection
* does not support the <code>removeAll()</code> operation.
*/
- public boolean removeAll(Collection c)
+ public boolean removeAll(Collection<?> c)
{
throw new UnsupportedOperationException();
}
@@ -4190,7 +4363,7 @@ public class Collections
* @throws UnsupportedOperationException as an unmodifiable collection
* does not support the <code>retainAll()</code> operation.
*/
- public boolean retainAll(Collection c)
+ public boolean retainAll(Collection<?> c)
{
throw new UnsupportedOperationException();
}
@@ -4234,7 +4407,7 @@ public class Collections
* @throws ArrayStoreException if the type of any element of the
* collection is not a subtype of the element type of a.
*/
- public Object[] toArray(Object[] a)
+ public <S> S[] toArray(S[] a)
{
return c.toArray(a);
}
@@ -4256,18 +4429,18 @@ public class Collections
*
* @author Eric Blake (ebb9@email.byu.edu)
*/
- private static class UnmodifiableIterator implements Iterator
+ private static class UnmodifiableIterator<T> implements Iterator<T>
{
/**
* The wrapped iterator.
*/
- private final Iterator i;
+ private final Iterator<? extends T> i;
/**
* Only trusted code creates a wrapper.
* @param i the wrapped iterator
*/
- UnmodifiableIterator(Iterator i)
+ UnmodifiableIterator(Iterator<? extends T> i)
{
this.i = i;
}
@@ -4278,10 +4451,11 @@ public class Collections
* @return the next element in the collection.
* @throws NoSuchElementException if there are no more elements.
*/
- public Object next()
+ public T next()
{
return i.next();
}
+
/**
* Tests whether there are still elements to be retrieved from the
* underlying collection by <code>next()</code>. When this method
@@ -4328,11 +4502,11 @@ public class Collections
* @see Serializable
* @see RandomAccess
*/
- public static List unmodifiableList(List l)
+ public static <T> List<T> unmodifiableList(List<? extends T> l)
{
if (l instanceof RandomAccess)
- return new UnmodifiableRandomAccessList(l);
- return new UnmodifiableList(l);
+ return new UnmodifiableRandomAccessList<T>(l);
+ return new UnmodifiableList<T>(l);
}
/**
@@ -4342,8 +4516,8 @@ public class Collections
*
* @author Eric Blake (ebb9@email.byu.edu)
*/
- private static class UnmodifiableList extends UnmodifiableCollection
- implements List
+ private static class UnmodifiableList<T> extends UnmodifiableCollection<T>
+ implements List<T>
{
/**
* Compatible with JDK 1.4.
@@ -4356,17 +4530,17 @@ public class Collections
* excessive casting. Package visible for use by subclass.
* @serial the wrapped list
*/
- final List list;
+ final List<T> list;
/**
* Wrap a given list.
* @param l the list to wrap
* @throws NullPointerException if l is null
*/
- UnmodifiableList(List l)
+ UnmodifiableList(List<? extends T> l)
{
super(l);
- list = l;
+ list = (List<T>) l;
}
/**
@@ -4379,7 +4553,7 @@ public class Collections
* @throws UnsupportedOperationException as an unmodifiable
* list doesn't support the <code>add()</code> operation.
*/
- public void add(int index, Object o)
+ public void add(int index, T o)
{
throw new UnsupportedOperationException();
}
@@ -4394,7 +4568,7 @@ public class Collections
* @throws UnsupportedOperationException as an unmodifiable
* list doesn't support the <code>addAll()</code> operation.
*/
- public boolean addAll(int index, Collection c)
+ public boolean addAll(int index, Collection<? extends T> c)
{
throw new UnsupportedOperationException();
}
@@ -4419,7 +4593,7 @@ public class Collections
* @return the element at index index in this list
* @throws IndexOutOfBoundsException if index &lt; 0 || index &gt;= size()
*/
- public Object get(int index)
+ public T get(int index)
{
return list.get(index);
}
@@ -4477,9 +4651,9 @@ public class Collections
* @return a <code>UnmodifiableListIterator</code> over the elements of the
* underlying list, in order, starting at the beginning.
*/
- public ListIterator listIterator()
+ public ListIterator<T> listIterator()
{
- return new UnmodifiableListIterator(list.listIterator());
+ return new UnmodifiableListIterator<T>(list.listIterator());
}
/**
@@ -4496,9 +4670,9 @@ public class Collections
* underlying list, in order, starting at the specified index.
* @throws IndexOutOfBoundsException if index &lt; 0 || index &gt; size()
*/
- public ListIterator listIterator(int index)
+ public ListIterator<T> listIterator(int index)
{
- return new UnmodifiableListIterator(list.listIterator(index));
+ return new UnmodifiableListIterator<T>(list.listIterator(index));
}
/**
@@ -4511,7 +4685,7 @@ public class Collections
* list does not support the <code>remove()</code>
* operation.
*/
- public Object remove(int index)
+ public T remove(int index)
{
throw new UnsupportedOperationException();
}
@@ -4527,7 +4701,7 @@ public class Collections
* list does not support the <code>set()</code>
* operation.
*/
- public Object set(int index, Object o)
+ public T set(int index, T o)
{
throw new UnsupportedOperationException();
}
@@ -4547,7 +4721,7 @@ public class Collections
* @throws IndexOutOfBoundsException if fromIndex &lt; 0
* || toIndex &gt; size() || fromIndex &gt; toIndex.
*/
- public List subList(int fromIndex, int toIndex)
+ public List<T> subList(int fromIndex, int toIndex)
{
return unmodifiableList(list.subList(fromIndex, toIndex));
}
@@ -4560,8 +4734,8 @@ public class Collections
*
* @author Eric Blake (ebb9@email.byu.edu)
*/
- private static final class UnmodifiableRandomAccessList
- extends UnmodifiableList implements RandomAccess
+ private static final class UnmodifiableRandomAccessList<T>
+ extends UnmodifiableList<T> implements RandomAccess
{
/**
* Compatible with JDK 1.4.
@@ -4573,7 +4747,7 @@ public class Collections
* @param l the list to wrap
* @throws NullPointerException if l is null
*/
- UnmodifiableRandomAccessList(List l)
+ UnmodifiableRandomAccessList(List<? extends T> l)
{
super(l);
}
@@ -4584,20 +4758,20 @@ public class Collections
*
* @author Eric Blake (ebb9@email.byu.edu)
*/
- private static final class UnmodifiableListIterator
- extends UnmodifiableIterator implements ListIterator
+ private static final class UnmodifiableListIterator<T>
+ extends UnmodifiableIterator<T> implements ListIterator<T>
{
/**
* The wrapped iterator, stored both here and in the superclass to
* avoid excessive casting.
*/
- private final ListIterator li;
+ private final ListIterator<T> li;
/**
* Only trusted code creates a wrapper.
* @param li the wrapped iterator
*/
- UnmodifiableListIterator(ListIterator li)
+ UnmodifiableListIterator(ListIterator<T> li)
{
super(li);
this.li = li;
@@ -4611,7 +4785,7 @@ public class Collections
* @throws UnsupportedOperationException as the iterator of an unmodifiable
* list does not support the <code>add()</code> operation.
*/
- public void add(Object o)
+ public void add(T o)
{
throw new UnsupportedOperationException();
}
@@ -4648,7 +4822,7 @@ public class Collections
* @return the previous element in the list.
* @throws NoSuchElementException if there are no more prior elements.
*/
- public Object previous()
+ public T previous()
{
return li.previous();
}
@@ -4674,7 +4848,7 @@ public class Collections
* @throws UnsupportedOperationException as the iterator of an unmodifiable
* list does not support the <code>set()</code> operation.
*/
- public void set(Object o)
+ public void set(T o)
{
throw new UnsupportedOperationException();
}
@@ -4697,9 +4871,10 @@ public class Collections
* @return a read-only view of the map
* @see Serializable
*/
- public static Map unmodifiableMap(Map m)
+ public static <K, V> Map<K, V> unmodifiableMap(Map<? extends K,
+ ? extends V> m)
{
- return new UnmodifiableMap(m);
+ return new UnmodifiableMap<K, V>(m);
}
/**
@@ -4708,7 +4883,7 @@ public class Collections
*
* @author Eric Blake (ebb9@email.byu.edu)
*/
- private static class UnmodifiableMap implements Map, Serializable
+ private static class UnmodifiableMap<K, V> implements Map<K, V>, Serializable
{
/**
* Compatible with JDK 1.4.
@@ -4719,31 +4894,31 @@ public class Collections
* The wrapped map.
* @serial the real map
*/
- private final Map m;
+ private final Map<K, V> m;
/**
* Cache the entry set.
*/
- private transient Set entries;
+ private transient Set<Map.Entry<K, V>> entries;
/**
* Cache the key set.
*/
- private transient Set keys;
+ private transient Set<K> keys;
/**
* Cache the value collection.
*/
- private transient Collection values;
+ private transient Collection<V> values;
/**
* Wrap a given map.
* @param m the map to wrap
* @throws NullPointerException if m is null
*/
- UnmodifiableMap(Map m)
+ UnmodifiableMap(Map<? extends K, ? extends V> m)
{
- this.m = m;
+ this.m = (Map<K,V>) m;
if (m == null)
throw new NullPointerException();
}
@@ -4804,10 +4979,10 @@ public class Collections
* @return the unmodifiable set view of all mapping entries.
* @see Map.Entry
*/
- public Set entrySet()
+ public Set<Map.Entry<K, V>> entrySet()
{
if (entries == null)
- entries = new UnmodifiableEntrySet(m.entrySet());
+ entries = new UnmodifiableEntrySet<K,V>(m.entrySet());
return entries;
}
@@ -4817,17 +4992,18 @@ public class Collections
*
* @author Eric Blake (ebb9@email.byu.edu)
*/
- private static final class UnmodifiableEntrySet extends UnmodifiableSet
+ private static final class UnmodifiableEntrySet<K,V>
+ extends UnmodifiableSet<Map.Entry<K,V>>
implements Serializable
{
// Unmodifiable implementation of Map.Entry used as return value for
// UnmodifiableEntrySet accessors (iterator, toArray, toArray(Object[]))
- private static final class UnmodifiableMapEntry
- implements Map.Entry
+ private static final class UnmodifiableMapEntry<K,V>
+ implements Map.Entry<K,V>
{
- private final Map.Entry e;
+ private final Map.Entry<K,V> e;
- private UnmodifiableMapEntry(Map.Entry e)
+ private UnmodifiableMapEntry(Map.Entry<K,V> e)
{
super();
this.e = e;
@@ -4850,7 +5026,7 @@ public class Collections
*
* @return the key.
*/
- public Object getKey()
+ public K getKey()
{
return e.getKey();
}
@@ -4860,7 +5036,7 @@ public class Collections
*
* @return the value.
*/
- public Object getValue()
+ public V getValue()
{
return e.getValue();
}
@@ -4885,7 +5061,7 @@ public class Collections
* @throws UnsupportedOperationException as an unmodifiable map entry
* does not support the <code>setValue()</code> operation.
*/
- public Object setValue(Object value)
+ public V setValue(V value)
{
throw new UnsupportedOperationException();
}
@@ -4910,15 +5086,15 @@ public class Collections
* Wrap a given set.
* @param s the set to wrap
*/
- UnmodifiableEntrySet(Set s)
+ UnmodifiableEntrySet(Set<Map.Entry<K,V>> s)
{
super(s);
}
// The iterator must return unmodifiable map entries.
- public Iterator iterator()
+ public Iterator<Map.Entry<K,V>> iterator()
{
- return new UnmodifiableIterator(c.iterator())
+ return new UnmodifiableIterator<Map.Entry<K,V>>(c.iterator())
{
/**
* Obtains the next element from the underlying set of
@@ -4927,49 +5103,45 @@ public class Collections
* @return the next element in the collection.
* @throws NoSuchElementException if there are no more elements.
*/
- public Object next()
+ public Map.Entry<K,V> next()
{
- final Map.Entry e = (Map.Entry) super.next();
- return new UnmodifiableMapEntry(e);
- }
+ final Map.Entry<K,V> e = super.next();
+ return new UnmodifiableMapEntry<K,V>(e);
+ }
};
}
// The array returned is an array of UnmodifiableMapEntry instead of
// Map.Entry
- public Object[] toArray()
+ public Map.Entry<K,V>[] toArray()
{
- Object[] mapEntryResult = super.toArray();
- UnmodifiableMapEntry result[] = null;
-
+ Map.Entry<K,V>[] mapEntryResult = (Map.Entry<K,V>[]) super.toArray();
+ UnmodifiableMapEntry<K,V> result[] = null;
+
if (mapEntryResult != null)
{
- result = new UnmodifiableMapEntry[mapEntryResult.length];
- for (int i = 0; i < mapEntryResult.length; i++)
- {
- Map.Entry r = (Map.Entry) mapEntryResult[i];
- result[i] = new UnmodifiableMapEntry(r);
- }
- }
+ result = (UnmodifiableMapEntry<K,V>[])
+ new UnmodifiableMapEntry[mapEntryResult.length];
+ for (int i = 0; i < mapEntryResult.length; ++i)
+ result[i] = new UnmodifiableMapEntry(mapEntryResult[i]);
+ }
return result;
}
-
+
// The array returned is an array of UnmodifiableMapEntry instead of
// Map.Entry
- public Object[] toArray(Object[] array)
+ public Map.Entry<K,V>[] toArray(Map.Entry<K,V>[] array)
{
super.toArray(array);
-
+
if (array != null)
- {
- for (int i = 0; i < array.length; i++)
- {
- array[i] = new UnmodifiableMapEntry((Map.Entry) array[i]);
- }
- }
+ for (int i = 0; i < array.length; i++)
+ array[i] =
+ new UnmodifiableMapEntry<K,V>(array[i]);
return array;
}
+
} // class UnmodifiableEntrySet
/**
@@ -4997,7 +5169,7 @@ public class Collections
* @throws NullPointerException if this map does not accept null keys.
* @see #containsKey(Object)
*/
- public Object get(Object key)
+ public V get(Object key)
{
return m.get(key);
}
@@ -5012,7 +5184,7 @@ public class Collections
* @throws UnsupportedOperationException as an unmodifiable
* map does not support the <code>put()</code> operation.
*/
- public Object put(Object key, Object value)
+ public V put(K key, V value)
{
throw new UnsupportedOperationException();
}
@@ -5048,10 +5220,10 @@ public class Collections
*
* @return the set view of all keys.
*/
- public Set keySet()
+ public Set<K> keySet()
{
if (keys == null)
- keys = new UnmodifiableSet(m.keySet());
+ keys = new UnmodifiableSet<K>(m.keySet());
return keys;
}
@@ -5064,7 +5236,7 @@ public class Collections
* @throws UnsupportedOperationException as an unmodifiable
* map does not support the <code>putAll</code> operation.
*/
- public void putAll(Map m)
+ public void putAll(Map<? extends K, ? extends V> m)
{
throw new UnsupportedOperationException();
}
@@ -5080,7 +5252,7 @@ public class Collections
* @throws UnsupportedOperationException as an unmodifiable
* map does not support the <code>remove</code> operation.
*/
- public Object remove(Object o)
+ public V remove(Object o)
{
throw new UnsupportedOperationException();
}
@@ -5117,10 +5289,10 @@ public class Collections
*
* @return the collection view of all values.
*/
- public Collection values()
+ public Collection<V> values()
{
if (values == null)
- values = new UnmodifiableCollection(m.values());
+ values = new UnmodifiableCollection<V>(m.values());
return values;
}
} // class UnmodifiableMap
@@ -5142,9 +5314,9 @@ public class Collections
* @return a read-only view of the set
* @see Serializable
*/
- public static Set unmodifiableSet(Set s)
+ public static <T> Set<T> unmodifiableSet(Set<? extends T> s)
{
- return new UnmodifiableSet(s);
+ return new UnmodifiableSet<T>(s);
}
/**
@@ -5153,8 +5325,8 @@ public class Collections
*
* @author Eric Blake (ebb9@email.byu.edu)
*/
- private static class UnmodifiableSet extends UnmodifiableCollection
- implements Set
+ private static class UnmodifiableSet<T> extends UnmodifiableCollection<T>
+ implements Set<T>
{
/**
* Compatible with JDK 1.4.
@@ -5166,7 +5338,7 @@ public class Collections
* @param s the set to wrap
* @throws NullPointerException if s is null
*/
- UnmodifiableSet(Set s)
+ UnmodifiableSet(Set<? extends T> s)
{
super(s);
}
@@ -5211,9 +5383,10 @@ public class Collections
* @return a read-only view of the map
* @see Serializable
*/
- public static SortedMap unmodifiableSortedMap(SortedMap m)
+ public static <K, V> SortedMap<K, V> unmodifiableSortedMap(SortedMap<K,
+ ? extends V> m)
{
- return new UnmodifiableSortedMap(m);
+ return new UnmodifiableSortedMap<K, V>(m);
}
/**
@@ -5222,8 +5395,9 @@ public class Collections
*
* @author Eric Blake (ebb9@email.byu.edu)
*/
- private static class UnmodifiableSortedMap extends UnmodifiableMap
- implements SortedMap
+ private static class UnmodifiableSortedMap<K, V>
+ extends UnmodifiableMap<K, V>
+ implements SortedMap<K, V>
{
/**
* Compatible with JDK 1.4.
@@ -5235,17 +5409,17 @@ public class Collections
* excessive casting.
* @serial the wrapped map
*/
- private final SortedMap sm;
+ private final SortedMap<K, V> sm;
/**
* Wrap a given map.
* @param sm the map to wrap
* @throws NullPointerException if sm is null
*/
- UnmodifiableSortedMap(SortedMap sm)
+ UnmodifiableSortedMap(SortedMap<K, ? extends V> sm)
{
super(sm);
- this.sm = sm;
+ this.sm = (SortedMap<K,V>) sm;
}
/**
@@ -5254,7 +5428,7 @@ public class Collections
*
* @return the sorting comparator.
*/
- public Comparator comparator()
+ public Comparator<? super K> comparator()
{
return sm.comparator();
}
@@ -5265,7 +5439,7 @@ public class Collections
* @return the first key.
* @throws NoSuchElementException if this map is empty.
*/
- public Object firstKey()
+ public K firstKey()
{
return sm.firstKey();
}
@@ -5292,9 +5466,9 @@ public class Collections
* @throws NullPointerException if toKey is null but the map does not allow
* null keys.
*/
- public SortedMap headMap(Object toKey)
+ public SortedMap<K, V> headMap(K toKey)
{
- return new UnmodifiableSortedMap(sm.headMap(toKey));
+ return new UnmodifiableSortedMap<K, V>(sm.headMap(toKey));
}
/**
@@ -5303,7 +5477,7 @@ public class Collections
* @return the last key.
* @throws NoSuchElementException if this map is empty.
*/
- public Object lastKey()
+ public K lastKey()
{
return sm.lastKey();
}
@@ -5334,9 +5508,9 @@ public class Collections
* @throws NullPointerException if fromKey or toKey is null but the map
* does not allow null keys.
*/
- public SortedMap subMap(Object fromKey, Object toKey)
+ public SortedMap<K, V> subMap(K fromKey, K toKey)
{
- return new UnmodifiableSortedMap(sm.subMap(fromKey, toKey));
+ return new UnmodifiableSortedMap<K, V>(sm.subMap(fromKey, toKey));
}
/**
@@ -5361,9 +5535,9 @@ public class Collections
* @throws NullPointerException if fromKey is null but the map does not allow
* null keys
*/
- public SortedMap tailMap(Object fromKey)
+ public SortedMap<K, V> tailMap(K fromKey)
{
- return new UnmodifiableSortedMap(sm.tailMap(fromKey));
+ return new UnmodifiableSortedMap<K, V>(sm.tailMap(fromKey));
}
} // class UnmodifiableSortedMap
@@ -5384,9 +5558,9 @@ public class Collections
* @return a read-only view of the set
* @see Serializable
*/
- public static SortedSet unmodifiableSortedSet(SortedSet s)
+ public static <T> SortedSet<T> unmodifiableSortedSet(SortedSet<T> s)
{
- return new UnmodifiableSortedSet(s);
+ return new UnmodifiableSortedSet<T>(s);
}
/**
@@ -5395,8 +5569,8 @@ public class Collections
*
* @author Eric Blake (ebb9@email.byu.edu)
*/
- private static class UnmodifiableSortedSet extends UnmodifiableSet
- implements SortedSet
+ private static class UnmodifiableSortedSet<T> extends UnmodifiableSet<T>
+ implements SortedSet<T>
{
/**
* Compatible with JDK 1.4.
@@ -5408,14 +5582,14 @@ public class Collections
* excessive casting.
* @serial the wrapped set
*/
- private SortedSet ss;
+ private SortedSet<T> ss;
/**
* Wrap a given set.
* @param ss the set to wrap
* @throws NullPointerException if ss is null
*/
- UnmodifiableSortedSet(SortedSet ss)
+ UnmodifiableSortedSet(SortedSet<T> ss)
{
super(ss);
this.ss = ss;
@@ -5427,7 +5601,7 @@ public class Collections
*
* @return the sorting comparator
*/
- public Comparator comparator()
+ public Comparator<? super T> comparator()
{
return ss.comparator();
}
@@ -5439,7 +5613,7 @@ public class Collections
* @return the first element.
* @throws NoSuchElementException if the set is empty.
*/
- public Object first()
+ public T first()
{
return ss.first();
}
@@ -5467,9 +5641,9 @@ public class Collections
* @throws NullPointerException if toElement is null but the set does not
* allow null elements.
*/
- public SortedSet headSet(Object toElement)
+ public SortedSet<T> headSet(T toElement)
{
- return new UnmodifiableSortedSet(ss.headSet(toElement));
+ return new UnmodifiableSortedSet<T>(ss.headSet(toElement));
}
/**
@@ -5479,7 +5653,7 @@ public class Collections
* @return the last element.
* @throws NoSuchElementException if the set is empty.
*/
- public Object last()
+ public T last()
{
return ss.last();
}
@@ -5510,9 +5684,9 @@ public class Collections
* @throws NullPointerException if fromElement or toElement is null but the
* set does not allow null elements.
*/
- public SortedSet subSet(Object fromElement, Object toElement)
+ public SortedSet<T> subSet(T fromElement, T toElement)
{
- return new UnmodifiableSortedSet(ss.subSet(fromElement, toElement));
+ return new UnmodifiableSortedSet<T>(ss.subSet(fromElement, toElement));
}
/**
@@ -5536,9 +5710,1717 @@ public class Collections
* @throws NullPointerException if fromElement is null but the set does not
* allow null elements.
*/
- public SortedSet tailSet(Object fromElement)
+ public SortedSet<T> tailSet(T fromElement)
{
- return new UnmodifiableSortedSet(ss.tailSet(fromElement));
+ return new UnmodifiableSortedSet<T>(ss.tailSet(fromElement));
}
} // class UnmodifiableSortedSet
+
+ /**
+ * <p>
+ * Returns a dynamically typesafe view of the given collection,
+ * where any modification is first checked to ensure that the type
+ * of the new data is appropriate. Although the addition of
+ * generics and parametrically-typed collections prevents an
+ * incorrect type of element being added to a collection at
+ * compile-time, via static type checking, this can be overridden by
+ * casting. In contrast, wrapping the collection within a
+ * dynamically-typesafe wrapper, using this and associated methods,
+ * <emph>guarantees</emph> that the collection will only contain
+ * elements of an appropriate type (provided it only contains such
+ * at the type of wrapping, and all subsequent access is via the
+ * wrapper). This can be useful for debugging the cause of a
+ * <code>ClassCastException</code> caused by erroneous casting, or
+ * for protecting collections from corruption by external libraries.
+ * </p>
+ * <p>
+ * Since the collection might be a List or a Set, and those
+ * have incompatible equals and hashCode requirements, this relies
+ * on Object's implementation rather than passing those calls on to
+ * the wrapped collection. The returned Collection implements
+ * Serializable, but can only be serialized if the collection it
+ * wraps is likewise Serializable.
+ * </p>
+ *
+ * @param c the collection to wrap in a dynamically typesafe wrapper
+ * @param type the type of elements the collection should hold.
+ * @return a dynamically typesafe view of the collection.
+ * @see Serializable
+ * @since 1.5
+ */
+ public static <E> Collection<E> checkedCollection(Collection<E> c,
+ Class<E> type)
+ {
+ return new CheckedCollection<E>(c, type);
+ }
+
+ /**
+ * The implementation of {@link #checkedCollection(Collection,Class)}. This
+ * class name is required for compatibility with Sun's JDK serializability.
+ *
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
+ * @since 1.5
+ */
+ private static class CheckedCollection<E>
+ implements Collection<E>, Serializable
+ {
+ /**
+ * Compatible with JDK 1.5.
+ */
+ private static final long serialVersionUID = 1578914078182001775L;
+
+ /**
+ * The wrapped collection. Package visible for use by subclasses.
+ * @serial the real collection
+ */
+ final Collection<E> c;
+
+ /**
+ * The type of the elements of this collection.
+ * @serial the element type.
+ */
+ final Class<E> type;
+
+ /**
+ * Wrap a given collection.
+ * @param c the collection to wrap
+ * @param type the type to wrap
+ * @throws NullPointerException if c is null
+ */
+ CheckedCollection(Collection<E> c, Class<E> type)
+ {
+ this.c = c;
+ this.type = type;
+ if (c == null)
+ throw new NullPointerException();
+ }
+
+ /**
+ * Adds the supplied object to the collection, on the condition that
+ * it is of the correct type.
+ *
+ * @param o the object to add.
+ * @return <code>true</code> if the collection was modified as a result
+ * of this action.
+ * @throws ClassCastException if the object is not of the correct type.
+ */
+ public boolean add(E o)
+ {
+ if (type.isInstance(o))
+ return c.add(o);
+ else
+ throw new ClassCastException("The element is of the incorrect type.");
+ }
+
+ /**
+ * Adds the elements of the specified collection to the backing collection,
+ * provided they are all of the correct type.
+ *
+ * @param coll the collection to add.
+ * @return <code>true</code> if the collection was modified as a result
+ * of this action.
+ * @throws ClassCastException if <code>c</code> contained elements of an
+ * incorrect type.
+ */
+ public boolean addAll(Collection<? extends E> coll)
+ {
+ Collection<E> typedColl = (Collection<E>) c;
+ for (E element : typedColl)
+ {
+ if (!type.isInstance(element))
+ throw new ClassCastException("A member of the collection is not of the correct type.");
+ }
+ return c.addAll(typedColl);
+ }
+
+ /**
+ * Removes all elements from the underlying collection.
+ */
+ public void clear()
+ {
+ c.clear();
+ }
+
+ /**
+ * Test whether the underlying collection contains a given object as one
+ * of its elements.
+ *
+ * @param o the element to look for.
+ * @return <code>true</code> if the underlying 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 the
+ * underlying collection.
+ * @throws NullPointerException if o is null and the underlying collection
+ * doesn't support null values.
+ */
+ public boolean contains(Object o)
+ {
+ return c.contains(o);
+ }
+
+ /**
+ * Test whether the underlying collection contains every element in a given
+ * collection.
+ *
+ * @param coll the collection to test for.
+ * @return <code>true</code> if for every element o in c, contains(o) would
+ * return <code>true</code>.
+ * @throws ClassCastException if the type of any element in c is not a
+ * valid type for the underlying collection.
+ * @throws NullPointerException if some element of c is null and the
+ * underlying collection does not support
+ * null values.
+ * @throws NullPointerException if c itself is null.
+ */
+ public boolean containsAll(Collection<?> coll)
+ {
+ return c.containsAll(coll);
+ }
+
+ /**
+ * Tests whether the underlying collection is empty, that is,
+ * if size() == 0.
+ *
+ * @return <code>true</code> if this collection contains no elements.
+ */
+ public boolean isEmpty()
+ {
+ return c.isEmpty();
+ }
+
+ /**
+ * Obtain an Iterator over the underlying collection, which maintains
+ * its checked nature.
+ *
+ * @return a Iterator over the elements of the underlying
+ * collection, in any order.
+ */
+ public Iterator<E> iterator()
+ {
+ return new CheckedIterator<E>(c.iterator(), type);
+ }
+
+ /**
+ * Removes the supplied object from the collection, if it exists.
+ *
+ * @param o The object to remove.
+ * @return <code>true</code> if the object was removed (i.e. the underlying
+ * collection returned 1 or more instances of o).
+ */
+ public boolean remove(Object o)
+ {
+ return c.remove(o);
+ }
+
+ /**
+ * Removes all objects in the supplied collection from the backing
+ * collection, if they exist within it.
+ *
+ * @param coll the collection of objects to remove.
+ * @return <code>true</code> if the collection was modified.
+ */
+ public boolean removeAll(Collection<?> coll)
+ {
+ return c.removeAll(coll);
+ }
+
+ /**
+ * Retains all objects specified by the supplied collection which exist
+ * within the backing collection, and removes all others.
+ *
+ * @param coll the collection of objects to retain.
+ * @return <code>true</code> if the collection was modified.
+ */
+ public boolean retainAll(Collection<?> coll)
+ {
+ return c.retainAll(coll);
+ }
+
+ /**
+ * Retrieves the number of elements in the underlying collection.
+ *
+ * @return the number of elements in the collection.
+ */
+ public int size()
+ {
+ return c.size();
+ }
+
+ /**
+ * Copy the current contents of the underlying collection into an array.
+ *
+ * @return an array of type Object[] with a length equal to the size of the
+ * underlying collection and containing the elements currently in
+ * the underlying collection, in any order.
+ */
+ public Object[] toArray()
+ {
+ return c.toArray();
+ }
+
+ /**
+ * <p>
+ * Copy the current contents of the underlying collection into an array. If
+ * the array passed as an argument has length less than the size of the
+ * underlying collection, an array of the same run-time type as a, with a
+ * length equal to the size of the underlying collection, is allocated
+ * using reflection.
+ * </p>
+ * <p>
+ * Otherwise, a itself is used. The elements of the underlying 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.
+ * </p>
+ * <p>
+ * <emph>Note</emph>: 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 the underlying
+ * 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.
+ */
+ public <S> S[] toArray(S[] a)
+ {
+ return c.toArray(a);
+ }
+
+ /**
+ * A textual representation of the unmodifiable collection.
+ *
+ * @return The checked collection in the form of a <code>String</code>.
+ */
+ public String toString()
+ {
+ return c.toString();
+ }
+ } // class CheckedCollection
+
+ /**
+ * The implementation of the various iterator methods in the
+ * checked classes.
+ *
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
+ * @since 1.5
+ */
+ private static class CheckedIterator<E>
+ implements Iterator<E>
+ {
+ /**
+ * The wrapped iterator.
+ */
+ private final Iterator<E> i;
+
+ /**
+ * The type of the elements of this collection.
+ * @serial the element type.
+ */
+ final Class<E> type;
+
+ /**
+ * Only trusted code creates a wrapper.
+ * @param i the wrapped iterator
+ * @param type the type of the elements within the checked list.
+ */
+ CheckedIterator(Iterator<E> i, Class<E> type)
+ {
+ this.i = i;
+ this.type = type;
+ }
+
+ /**
+ * Obtains the next element in the underlying collection.
+ *
+ * @return the next element in the collection.
+ * @throws NoSuchElementException if there are no more elements.
+ */
+ public E next()
+ {
+ return i.next();
+ }
+
+ /**
+ * Tests whether there are still elements to be retrieved from the
+ * underlying collection by <code>next()</code>. When this method
+ * returns <code>true</code>, an exception will not be thrown on calling
+ * <code>next()</code>.
+ *
+ * @return <code>true</code> if there is at least one more element in the
+ * underlying collection.
+ */
+ public boolean hasNext()
+ {
+ return i.hasNext();
+ }
+
+ /**
+ * Removes the next element from the collection.
+ */
+ public void remove()
+ {
+ i.remove();
+ }
+ } // class CheckedIterator
+
+ /**
+ * <p>
+ * Returns a dynamically typesafe view of the given list,
+ * where any modification is first checked to ensure that the type
+ * of the new data is appropriate. Although the addition of
+ * generics and parametrically-typed collections prevents an
+ * incorrect type of element being added to a collection at
+ * compile-time, via static type checking, this can be overridden by
+ * casting. In contrast, wrapping the collection within a
+ * dynamically-typesafe wrapper, using this and associated methods,
+ * <emph>guarantees</emph> that the collection will only contain
+ * elements of an appropriate type (provided it only contains such
+ * at the type of wrapping, and all subsequent access is via the
+ * wrapper). This can be useful for debugging the cause of a
+ * <code>ClassCastException</code> caused by erroneous casting, or
+ * for protecting collections from corruption by external libraries.
+ * </p>
+ * <p>
+ * The returned List implements Serializable, but can only be serialized if
+ * the list it wraps is likewise Serializable. In addition, if the wrapped
+ * list implements RandomAccess, this does too.
+ * </p>
+ *
+ * @param l the list to wrap
+ * @param type the type of the elements within the checked list.
+ * @return a dynamically typesafe view of the list
+ * @see Serializable
+ * @see RandomAccess
+ */
+ public static <E> List<E> checkedList(List<E> l, Class<E> type)
+ {
+ if (l instanceof RandomAccess)
+ return new CheckedRandomAccessList<E>(l, type);
+ return new CheckedList<E>(l, type);
+ }
+
+ /**
+ * The implementation of {@link #checkedList(List,Class)} for sequential
+ * lists. This class name is required for compatibility with Sun's JDK
+ * serializability.
+ *
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
+ * @since 1.5
+ */
+ private static class CheckedList<E>
+ extends CheckedCollection<E>
+ implements List<E>
+ {
+ /**
+ * Compatible with JDK 1.5.
+ */
+ private static final long serialVersionUID = 65247728283967356L;
+
+ /**
+ * The wrapped list; stored both here and in the superclass to avoid
+ * excessive casting. Package visible for use by subclass.
+ * @serial the wrapped list
+ */
+ final List<E> list;
+
+ /**
+ * Wrap a given list.
+ * @param l the list to wrap
+ * @param type the type of the elements within the checked list.
+ * @throws NullPointerException if l is null
+ */
+ CheckedList(List<E> l, Class<E> type)
+ {
+ super(l, type);
+ list = l;
+ }
+
+ /**
+ * Adds the supplied element to the underlying list at the specified
+ * index, provided it is of the right type.
+ *
+ * @param index The index at which to place the new element.
+ * @param o the object to add.
+ * @throws ClassCastException if the type of the object is not a
+ * valid type for the underlying collection.
+ */
+ public void add(int index, E o)
+ {
+ if (type.isInstance(o))
+ list.add(index, o);
+ else
+ throw new ClassCastException("The object is of the wrong type.");
+ }
+
+ /**
+ * Adds the members of the supplied collection to the underlying
+ * collection at the specified index, provided they are all of the
+ * correct type.
+ *
+ * @param index the index at which to place the new element.
+ * @param c the collections of objects to add.
+ * @throws ClassCastException if the type of any element in c is not a
+ * valid type for the underlying collection.
+ */
+ public boolean addAll(int index, Collection<? extends E> coll)
+ {
+ Collection<E> typedColl = (Collection<E>) coll;
+ for (E element : typedColl)
+ {
+ if (!type.isInstance(element))
+ throw new ClassCastException("A member of the collection is not of the correct type.");
+ }
+ return list.addAll(index, coll);
+ }
+
+ /**
+ * Returns <code>true</code> if the object, o, is an instance of
+ * <code>List</code> with the same size and elements
+ * as the underlying list.
+ *
+ * @param o The object to compare.
+ * @return <code>true</code> if o is equivalent to the underlying list.
+ */
+ public boolean equals(Object o)
+ {
+ return list.equals(o);
+ }
+
+ /**
+ * Retrieves the element at a given index in the underlying list.
+ *
+ * @param index the index of the element to be returned
+ * @return the element at the specified index in the underlying list
+ * @throws IndexOutOfBoundsException if index &lt; 0 || index &gt;= size()
+ */
+ public E get(int index)
+ {
+ return list.get(index);
+ }
+
+ /**
+ * Computes the hash code for the underlying list.
+ * The exact computation is described in the documentation
+ * of the <code>List</code> interface.
+ *
+ * @return The hash code of the underlying list.
+ * @see List#hashCode()
+ */
+ public int hashCode()
+ {
+ return list.hashCode();
+ }
+
+ /**
+ * Obtain the first index at which a given object is to be found in the
+ * underlying list.
+ *
+ * @param o the object to search for
+ * @return the least integer n such that <code>o == null ? get(n) == null :
+ * o.equals(get(n))</code>, or -1 if there is no such index.
+ * @throws ClassCastException if the type of o is not a valid
+ * type for the underlying list.
+ * @throws NullPointerException if o is null and the underlying
+ * list does not support null values.
+ */
+ public int indexOf(Object o)
+ {
+ return list.indexOf(o);
+ }
+
+ /**
+ * Obtain the last index at which a given object is to be found in the
+ * underlying list.
+ *
+ * @return the greatest integer n such that
+ * <code>o == null ? get(n) == null : o.equals(get(n))</code>,
+ * or -1 if there is no such index.
+ * @throws ClassCastException if the type of o is not a valid
+ * type for the underlying list.
+ * @throws NullPointerException if o is null and the underlying
+ * list does not support null values.
+ */
+ public int lastIndexOf(Object o)
+ {
+ return list.lastIndexOf(o);
+ }
+
+ /**
+ * Obtains a list iterator over the underlying list, starting at the
+ * beginning and maintaining the checked nature of this list.
+ *
+ * @return a <code>CheckedListIterator</code> over the elements of the
+ * underlying list, in order, starting at the beginning.
+ */
+ public ListIterator<E> listIterator()
+ {
+ return new CheckedListIterator<E>(list.listIterator(), type);
+ }
+
+ /**
+ * Obtains a list iterator over the underlying list, starting at the
+ * specified index and maintaining the checked nature of this list. An
+ * initial call to <code>next()</code> will retrieve the element at the
+ * specified index, and an initial call to <code>previous()</code> will
+ * retrieve the element at index - 1.
+ *
+ * @param index the position, between 0 and size() inclusive, to begin the
+ * iteration from.
+ * @return a <code>CheckedListIterator</code> over the elements of the
+ * underlying list, in order, starting at the specified index.
+ * @throws IndexOutOfBoundsException if index &lt; 0 || index &gt; size()
+ */
+ public ListIterator<E> listIterator(int index)
+ {
+ return new CheckedListIterator<E>(list.listIterator(index), type);
+ }
+
+ /**
+ * Removes the element at the specified index.
+ *
+ * @param index The index of the element to remove.
+ * @return the removed element.
+ */
+ public E remove(int index)
+ {
+ return list.remove(index);
+ }
+
+ /**
+ * Replaces the element at the specified index in the underlying list
+ * with that supplied.
+ *
+ * @param index the index of the element to replace.
+ * @param o the new object to place at the specified index.
+ * @return the replaced element.
+ */
+ public E set(int index, E o)
+ {
+ return list.set(index, o);
+ }
+
+ /**
+ * Obtain a List view of a subsection of the underlying list, from
+ * fromIndex (inclusive) to toIndex (exclusive). If the two indices
+ * are equal, the sublist is empty. The returned list will be
+ * checked, like this list. Changes to the elements of the
+ * returned list will be reflected in the underlying list. The effect
+ * of structural modifications is undefined.
+ *
+ * @param fromIndex the index that the returned list should start from
+ * (inclusive).
+ * @param toIndex the index that the returned list should go
+ * to (exclusive).
+ * @return a List backed by a subsection of the underlying list.
+ * @throws IndexOutOfBoundsException if fromIndex &lt; 0
+ * || toIndex &gt; size() || fromIndex &gt; toIndex.
+ */
+ public List<E> subList(int fromIndex, int toIndex)
+ {
+ return checkedList(list.subList(fromIndex, toIndex), type);
+ }
+ } // class CheckedList
+
+ /**
+ * The implementation of {@link #checkedList(List)} for random-access
+ * lists. This class name is required for compatibility with Sun's JDK
+ * serializability.
+ *
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
+ * @since 1.5
+ */
+ private static final class CheckedRandomAccessList<E>
+ extends CheckedList<E>
+ implements RandomAccess
+ {
+ /**
+ * Compatible with JDK 1.5.
+ */
+ private static final long serialVersionUID = 1638200125423088369L;
+
+ /**
+ * Wrap a given list.
+ * @param l the list to wrap
+ * @param type the type of the elements within the checked list.
+ * @throws NullPointerException if l is null
+ */
+ CheckedRandomAccessList(List<E> l, Class<E> type)
+ {
+ super(l, type);
+ }
+ } // class CheckedRandomAccessList
+
+ /**
+ * The implementation of {@link CheckedList#listIterator()}.
+ *
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
+ * @since 1.5
+ */
+ private static final class CheckedListIterator<E>
+ extends CheckedIterator<E>
+ implements ListIterator<E>
+ {
+ /**
+ * The wrapped iterator, stored both here and in the superclass to
+ * avoid excessive casting.
+ */
+ private final ListIterator<E> li;
+
+ /**
+ * Only trusted code creates a wrapper.
+ * @param li the wrapped iterator
+ */
+ CheckedListIterator(ListIterator<E> li, Class<E> type)
+ {
+ super(li, type);
+ this.li = li;
+ }
+
+ /**
+ * Adds the supplied object at the current iterator position, provided
+ * it is of the correct type.
+ *
+ * @param o the object to add.
+ * @throws ClassCastException if the type of the object is not a
+ * valid type for the underlying collection.
+ */
+ public void add(E o)
+ {
+ if (type.isInstance(o))
+ li.add(o);
+ else
+ throw new ClassCastException("The object is of the wrong type.");
+ }
+
+ /**
+ * Tests whether there are still elements to be retrieved from the
+ * underlying collection by <code>previous()</code>. When this method
+ * returns <code>true</code>, an exception will not be thrown on calling
+ * <code>previous()</code>.
+ *
+ * @return <code>true</code> if there is at least one more element prior
+ * to the current position in the underlying list.
+ */
+ public boolean hasPrevious()
+ {
+ return li.hasPrevious();
+ }
+
+ /**
+ * Find the index of the element that would be returned by a call to next.
+ * If <code>hasNext()</code> returns <code>false</code>, this returns the
+ * list size.
+ *
+ * @return the index of the element that would be returned by
+ * <code>next()</code>.
+ */
+ public int nextIndex()
+ {
+ return li.nextIndex();
+ }
+
+ /**
+ * Obtains the previous element in the underlying list.
+ *
+ * @return the previous element in the list.
+ * @throws NoSuchElementException if there are no more prior elements.
+ */
+ public E previous()
+ {
+ return li.previous();
+ }
+
+ /**
+ * Find the index of the element that would be returned by a call to
+ * previous. If <code>hasPrevious()</code> returns <code>false</code>,
+ * this returns -1.
+ *
+ * @return the index of the element that would be returned by
+ * <code>previous()</code>.
+ */
+ public int previousIndex()
+ {
+ return li.previousIndex();
+ }
+
+ /**
+ * Sets the next element to that supplied, provided that it is of the
+ * correct type.
+ *
+ * @param o The new object to replace the existing one.
+ * @throws ClassCastException if the type of the object is not a
+ * valid type for the underlying collection.
+ */
+ public void set(E o)
+ {
+ if (type.isInstance(o))
+ li.set(o);
+ else
+ throw new ClassCastException("The object is of the wrong type.");
+ }
+ } // class CheckedListIterator
+
+ /**
+ * <p>
+ * Returns a dynamically typesafe view of the given map,
+ * where any modification is first checked to ensure that the type
+ * of the new data is appropriate. Although the addition of
+ * generics and parametrically-typed collections prevents an
+ * incorrect type of element being added to a collection at
+ * compile-time, via static type checking, this can be overridden by
+ * casting. In contrast, wrapping the collection within a
+ * dynamically-typesafe wrapper, using this and associated methods,
+ * <emph>guarantees</emph> that the collection will only contain
+ * elements of an appropriate type (provided it only contains such
+ * at the type of wrapping, and all subsequent access is via the
+ * wrapper). This can be useful for debugging the cause of a
+ * <code>ClassCastException</code> caused by erroneous casting, or
+ * for protecting collections from corruption by external libraries.
+ * </p>
+ * <p>
+ * The returned Map implements Serializable, but can only be serialized if
+ * the map it wraps is likewise Serializable.
+ * </p>
+ *
+ * @param m the map to wrap
+ * @param keyType the dynamic type of the map's keys.
+ * @param valueType the dynamic type of the map's values.
+ * @return a dynamically typesafe view of the map
+ * @see Serializable
+ */
+ public static <K, V> Map<K, V> checkedMap(Map<K, V> m, Class<K> keyType,
+ Class<V> valueType)
+ {
+ return new CheckedMap<K, V>(m, keyType, valueType);
+ }
+
+ /**
+ * The implementation of {@link #checkedMap(Map)}. This
+ * class name is required for compatibility with Sun's JDK serializability.
+ *
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
+ * @since 1.5
+ */
+ private static class CheckedMap<K, V>
+ implements Map<K, V>, Serializable
+ {
+ /**
+ * Compatible with JDK 1.5.
+ */
+ private static final long serialVersionUID = 5742860141034234728L;
+
+ /**
+ * The wrapped map.
+ * @serial the real map
+ */
+ private final Map<K, V> m;
+
+ /**
+ * The type of the map's keys.
+ * @serial the key type.
+ */
+ final Class<K> keyType;
+
+ /**
+ * The type of the map's values.
+ * @serial the value type.
+ */
+ final Class<V> valueType;
+
+ /**
+ * Cache the entry set.
+ */
+ private transient Set<Map.Entry<K, V>> entries;
+
+ /**
+ * Cache the key set.
+ */
+ private transient Set<K> keys;
+
+ /**
+ * Cache the value collection.
+ */
+ private transient Collection<V> values;
+
+ /**
+ * Wrap a given map.
+ * @param m the map to wrap
+ * @param keyType the dynamic type of the map's keys.
+ * @param valueType the dynamic type of the map's values.
+ * @throws NullPointerException if m is null
+ */
+ CheckedMap(Map<K, V> m, Class<K> keyType, Class<V> valueType)
+ {
+ this.m = m;
+ this.keyType = keyType;
+ this.valueType = valueType;
+ if (m == null)
+ throw new NullPointerException();
+ }
+
+ /**
+ * Clears all pairs from the map.
+ */
+ public void clear()
+ {
+ m.clear();
+ }
+
+ /**
+ * Returns <code>true</code> if the underlying map contains a mapping for
+ * the given key.
+ *
+ * @param key the key to search for
+ * @return <code>true</code> if the map contains the key
+ * @throws ClassCastException if the key is of an inappropriate type
+ * @throws NullPointerException if key is <code>null</code> but the map
+ * does not permit null keys
+ */
+ public boolean containsKey(Object key)
+ {
+ return m.containsKey(key);
+ }
+
+ /**
+ * Returns <code>true</code> if the underlying map contains at least one
+ * mapping with the given value. In other words, it returns
+ * <code>true</code> if a value v exists where
+ * <code>(value == null ? v == null : value.equals(v))</code>.
+ * This usually requires linear time.
+ *
+ * @param value the value to search for
+ * @return <code>true</code> if the map contains the value
+ * @throws ClassCastException if the type of the value is not a valid type
+ * for this map.
+ * @throws NullPointerException if the value is null and the map doesn't
+ * support null values.
+ */
+ public boolean containsValue(Object value)
+ {
+ return m.containsValue(value);
+ }
+
+ /**
+ * <p>
+ * Returns a checked set view of the entries in the underlying map.
+ * Each element in the set is a unmodifiable variant of
+ * <code>Map.Entry</code>.
+ * </p>
+ * <p>
+ * The set is backed by the map, so that changes in one show up in the
+ * other. Modifications made while an iterator is in progress cause
+ * undefined behavior.
+ * </p>
+ *
+ * @return the checked set view of all mapping entries.
+ * @see Map.Entry
+ */
+ public Set<Map.Entry<K, V>> entrySet()
+ {
+ if (entries == null)
+ {
+ Class<Map.Entry<K,V>> klass =
+ (Class<Map.Entry<K,V>>) (Class) Map.Entry.class;
+ entries = new CheckedEntrySet<Map.Entry<K,V>,K,V>(m.entrySet(),
+ klass,
+ keyType,
+ valueType);
+ }
+ return entries;
+ }
+
+ /**
+ * The implementation of {@link CheckedMap#entrySet()}. This class
+ * is <emph>not</emph> serializable.
+ *
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
+ * @since 1.5
+ */
+ private static final class CheckedEntrySet<E,SK,SV>
+ extends CheckedSet<E>
+ {
+ /**
+ * The type of the map's keys.
+ * @serial the key type.
+ */
+ private final Class<SK> keyType;
+
+ /**
+ * The type of the map's values.
+ * @serial the value type.
+ */
+ private final Class<SV> valueType;
+
+ /**
+ * Wrap a given set of map entries.
+ *
+ * @param s the set to wrap.
+ * @param type the type of the set's entries.
+ * @param keyType the type of the map's keys.
+ * @param valueType the type of the map's values.
+ */
+ CheckedEntrySet(Set<E> s, Class<E> type, Class<SK> keyType,
+ Class<SV> valueType)
+ {
+ super(s, type);
+ this.keyType = keyType;
+ this.valueType = valueType;
+ }
+
+ // The iterator must return checked map entries.
+ public Iterator<E> iterator()
+ {
+ return new CheckedIterator<E>(c.iterator(), type)
+ {
+ /**
+ * Obtains the next element from the underlying set of
+ * map entries.
+ *
+ * @return the next element in the collection.
+ * @throws NoSuchElementException if there are no more elements.
+ */
+ public E next()
+ {
+ final Map.Entry e = (Map.Entry) super.next();
+ return (E) new Map.Entry()
+ {
+ /**
+ * Returns <code>true</code> if the object, o, is also a map
+ * entry with an identical key and value.
+ *
+ * @param o the object to compare.
+ * @return <code>true</code> if o is an equivalent map entry.
+ */
+ public boolean equals(Object o)
+ {
+ return e.equals(o);
+ }
+
+ /**
+ * Returns the key of this map entry.
+ *
+ * @return the key.
+ */
+ public Object getKey()
+ {
+ return e.getKey();
+ }
+
+ /**
+ * Returns the value of this map entry.
+ *
+ * @return the value.
+ */
+ public Object getValue()
+ {
+ return e.getValue();
+ }
+
+ /**
+ * Computes the hash code of this map entry.
+ * The computation is described in the <code>Map</code>
+ * interface documentation.
+ *
+ * @return the hash code of this entry.
+ * @see Map#hashCode()
+ */
+ public int hashCode()
+ {
+ return e.hashCode();
+ }
+
+ /**
+ * Sets the value of this map entry, provided it is of the
+ * right type.
+ *
+ * @param value The new value.
+ * @throws ClassCastException if the type of the value is not
+ * a valid type for the underlying
+ * map.
+ */
+ public Object setValue(Object value)
+ {
+ if (valueType.isInstance(value))
+ return e.setValue(value);
+ else
+ throw new ClassCastException("The value is of the wrong type.");
+ }
+
+ /**
+ * Returns a textual representation of the map entry.
+ *
+ * @return The map entry as a <code>String</code>.
+ */
+ public String toString()
+ {
+ return e.toString();
+ }
+ };
+ }
+ };
+ }
+ } // class CheckedEntrySet
+
+ /**
+ * Returns <code>true</code> if the object, o, is also an instance
+ * of <code>Map</code> with an equal set of map entries.
+ *
+ * @param o The object to compare.
+ * @return <code>true</code> if o is an equivalent map.
+ */
+ public boolean equals(Object o)
+ {
+ return m.equals(o);
+ }
+
+ /**
+ * Returns the value associated with the supplied key or
+ * null if no such mapping exists. An ambiguity can occur
+ * if null values are accepted by the underlying map.
+ * In this case, <code>containsKey()</code> can be used
+ * to separate the two possible cases of a null result.
+ *
+ * @param key The key to look up.
+ * @return the value associated with the key, or null if key not in map.
+ * @throws ClassCastException if the key is an inappropriate type.
+ * @throws NullPointerException if this map does not accept null keys.
+ * @see #containsKey(Object)
+ */
+ public V get(Object key)
+ {
+ return m.get(key);
+ }
+
+ /**
+ * Adds a new pair to the map, provided both the key and the value are
+ * of the correct types.
+ *
+ * @param key The new key.
+ * @param value The new value.
+ * @return the previous value of the key, or null if there was no mapping.
+ * @throws ClassCastException if the type of the key or the value is
+ * not a valid type for the underlying map.
+ */
+ public V put(K key, V value)
+ {
+ if (keyType.isInstance(key))
+ {
+ if (valueType.isInstance(value))
+ return m.put(key,value);
+ else
+ throw new ClassCastException("The value is of the wrong type.");
+ }
+ throw new ClassCastException("The key is of the wrong type.");
+ }
+
+ /**
+ * Computes the hash code for the underlying map, as the sum
+ * of the hash codes of all entries.
+ *
+ * @return The hash code of the underlying map.
+ * @see Map.Entry#hashCode()
+ */
+ public int hashCode()
+ {
+ return m.hashCode();
+ }
+
+ /**
+ * Returns <code>true</code> if the underlying map contains no entries.
+ *
+ * @return <code>true</code> if the map is empty.
+ */
+ public boolean isEmpty()
+ {
+ return m.isEmpty();
+ }
+
+ /**
+ * <p>
+ * Returns a checked set view of the keys in the underlying map.
+ * The set is backed by the map, so that changes in one show up in the
+ * other.
+ * </p>
+ * <p>
+ * Modifications made while an iterator is in progress cause undefined
+ * behavior. These modifications are again limited to the values of
+ * the keys.
+ * </p>
+ *
+ * @return the set view of all keys.
+ */
+ public Set<K> keySet()
+ {
+ if (keys == null)
+ keys = new CheckedSet<K>(m.keySet(), keyType);
+ return keys;
+ }
+
+ /**
+ * Adds all pairs within the supplied map to the underlying map,
+ * provided they are all have the correct key and value types.
+ *
+ * @param m the map, the entries of which should be added
+ * to the underlying map.
+ * @throws ClassCastException if the type of a key or value is
+ * not a valid type for the underlying map.
+ */
+ public void putAll(Map<? extends K, ? extends V> map)
+ {
+ Map<K,V> typedMap = (Map<K,V>) map;
+ for (Map.Entry<K,V> entry : typedMap.entrySet())
+ {
+ if (!keyType.isInstance(entry.getKey()))
+ throw new ClassCastException("A key is of the wrong type.");
+ if (!valueType.isInstance(entry.getValue()))
+ throw new ClassCastException("A value is of the wrong type.");
+ }
+ m.putAll(typedMap);
+ }
+
+ /**
+ * Removes a pair from the map.
+ *
+ * @param o The key of the entry to remove.
+ * @return The value the key was associated with, or null
+ * if no such mapping existed. Null is also returned
+ * if the removed entry had a null key.
+ * @throws UnsupportedOperationException as an unmodifiable
+ * map does not support the <code>remove</code> operation.
+ */
+ public V remove(Object o)
+ {
+ return m.remove(o);
+ }
+
+
+ /**
+ * Returns the number of key-value mappings in the underlying map.
+ * If there are more than Integer.MAX_VALUE mappings, Integer.MAX_VALUE
+ * is returned.
+ *
+ * @return the number of mappings.
+ */
+ public int size()
+ {
+ return m.size();
+ }
+
+ /**
+ * Returns a textual representation of the map.
+ *
+ * @return The map in the form of a <code>String</code>.
+ */
+ public String toString()
+ {
+ return m.toString();
+ }
+
+ /**
+ * <p>
+ * Returns a unmodifiable collection view of the values in the underlying
+ * map. The collection is backed by the map, so that changes in one show
+ * up in the other.
+ * </p>
+ * <p>
+ * Modifications made while an iterator is in progress cause undefined
+ * behavior. These modifications are again limited to the values of
+ * the keys.
+ * </p>
+ *
+ * @return the collection view of all values.
+ */
+ public Collection<V> values()
+ {
+ if (values == null)
+ values = new CheckedCollection<V>(m.values(), valueType);
+ return values;
+ }
+ } // class CheckedMap
+
+ /**
+ * <p>
+ * Returns a dynamically typesafe view of the given set,
+ * where any modification is first checked to ensure that the type
+ * of the new data is appropriate. Although the addition of
+ * generics and parametrically-typed collections prevents an
+ * incorrect type of element being added to a collection at
+ * compile-time, via static type checking, this can be overridden by
+ * casting. In contrast, wrapping the collection within a
+ * dynamically-typesafe wrapper, using this and associated methods,
+ * <emph>guarantees</emph> that the collection will only contain
+ * elements of an appropriate type (provided it only contains such
+ * at the type of wrapping, and all subsequent access is via the
+ * wrapper). This can be useful for debugging the cause of a
+ * <code>ClassCastException</code> caused by erroneous casting, or
+ * for protecting collections from corruption by external libraries.
+ * </p>
+ * <p>
+ * The returned Set implements Serializable, but can only be serialized if
+ * the set it wraps is likewise Serializable.
+ * </p>
+ *
+ * @param s the set to wrap.
+ * @param type the type of the elements within the checked list.
+ * @return a dynamically typesafe view of the set
+ * @see Serializable
+ */
+ public static <E> Set<E> checkedSet(Set<E> s, Class<E> type)
+ {
+ return new CheckedSet<E>(s, type);
+ }
+
+ /**
+ * The implementation of {@link #checkedSet(Set)}. This class
+ * name is required for compatibility with Sun's JDK serializability.
+ *
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
+ * @since 1.5
+ */
+ private static class CheckedSet<E>
+ extends CheckedCollection<E>
+ implements Set<E>
+ {
+ /**
+ * Compatible with JDK 1.5.
+ */
+ private static final long serialVersionUID = 4694047833775013803L;
+
+ /**
+ * Wrap a given set.
+ *
+ * @param s the set to wrap
+ * @throws NullPointerException if s is null
+ */
+ CheckedSet(Set<E> s, Class<E> type)
+ {
+ super(s, type);
+ }
+
+ /**
+ * Returns <code>true</code> if the object, o, is also an instance of
+ * <code>Set</code> of the same size and with the same entries.
+ *
+ * @return <code>true</code> if o is an equivalent set.
+ */
+ public boolean equals(Object o)
+ {
+ return c.equals(o);
+ }
+
+ /**
+ * Computes the hash code of this set, as the sum of the
+ * hash codes of all elements within the set.
+ *
+ * @return the hash code of the set.
+ */
+ public int hashCode()
+ {
+ return c.hashCode();
+ }
+ } // class CheckedSet
+
+ /**
+ * <p>
+ * Returns a dynamically typesafe view of the given sorted map,
+ * where any modification is first checked to ensure that the type
+ * of the new data is appropriate. Although the addition of
+ * generics and parametrically-typed collections prevents an
+ * incorrect type of element being added to a collection at
+ * compile-time, via static type checking, this can be overridden by
+ * casting. In contrast, wrapping the collection within a
+ * dynamically-typesafe wrapper, using this and associated methods,
+ * <emph>guarantees</emph> that the collection will only contain
+ * elements of an appropriate type (provided it only contains such
+ * at the type of wrapping, and all subsequent access is via the
+ * wrapper). This can be useful for debugging the cause of a
+ * <code>ClassCastException</code> caused by erroneous casting, or
+ * for protecting collections from corruption by external libraries.
+ * </p>
+ * <p>
+ * The returned SortedMap implements Serializable, but can only be
+ * serialized if the map it wraps is likewise Serializable.
+ * </p>
+ *
+ * @param m the map to wrap.
+ * @param keyType the dynamic type of the map's keys.
+ * @param valueType the dynamic type of the map's values.
+ * @return a dynamically typesafe view of the map
+ * @see Serializable
+ */
+ public static <K, V> SortedMap<K, V> checkedSortedMap(SortedMap<K, V> m,
+ Class<K> keyType,
+ Class<V> valueType)
+ {
+ return new CheckedSortedMap<K, V>(m, keyType, valueType);
+ }
+
+ /**
+ * The implementation of {@link #checkedSortedMap(SortedMap,Class,Class)}.
+ * This class name is required for compatibility with Sun's JDK
+ * serializability.
+ *
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
+ */
+ private static class CheckedSortedMap<K, V>
+ extends CheckedMap<K, V>
+ implements SortedMap<K, V>
+ {
+ /**
+ * Compatible with JDK 1.5.
+ */
+ private static final long serialVersionUID = 1599671320688067438L;
+
+ /**
+ * The wrapped map; stored both here and in the superclass to avoid
+ * excessive casting.
+ * @serial the wrapped map
+ */
+ private final SortedMap<K, V> sm;
+
+ /**
+ * Wrap a given map.
+ *
+ * @param sm the map to wrap
+ * @param keyType the dynamic type of the map's keys.
+ * @param valueType the dynamic type of the map's values.
+ * @throws NullPointerException if sm is null
+ */
+ CheckedSortedMap(SortedMap<K, V> sm, Class<K> keyType, Class<V> valueType)
+ {
+ super(sm, keyType, valueType);
+ this.sm = sm;
+ }
+
+ /**
+ * Returns the comparator used in sorting the underlying map,
+ * or null if it is the keys' natural ordering.
+ *
+ * @return the sorting comparator.
+ */
+ public Comparator<? super K> comparator()
+ {
+ return sm.comparator();
+ }
+
+ /**
+ * Returns the first (lowest sorted) key in the map.
+ *
+ * @return the first key.
+ * @throws NoSuchElementException if this map is empty.
+ */
+ public K firstKey()
+ {
+ return sm.firstKey();
+ }
+
+ /**
+ * <p>
+ * Returns a checked view of the portion of the map strictly less
+ * than toKey. The view is backed by the underlying map, so changes in
+ * one show up in the other. The submap supports all optional operations
+ * of the original. This operation is equivalent to
+ * <code>subMap(firstKey(), toKey)</code>.
+ * </p>
+ * <p>
+ * The returned map throws an IllegalArgumentException any time a key is
+ * used which is out of the range of toKey. Note that the endpoint, toKey,
+ * is not included; if you want this value to be included, pass its
+ * successor object in to toKey. For example, for Integers, you could
+ * request <code>headMap(new Integer(limit.intValue() + 1))</code>.
+ * </p>
+ *
+ * @param toKey the exclusive upper range of the submap.
+ * @return the submap.
+ * @throws ClassCastException if toKey is not comparable to the map
+ * contents.
+ * @throws IllegalArgumentException if this is a subMap, and toKey is out
+ * of range.
+ * @throws NullPointerException if toKey is null but the map does not allow
+ * null keys.
+ */
+ public SortedMap<K, V> headMap(K toKey)
+ {
+ return new CheckedSortedMap<K, V>(sm.headMap(toKey), keyType, valueType);
+ }
+
+ /**
+ * Returns the last (highest sorted) key in the map.
+ *
+ * @return the last key.
+ * @throws NoSuchElementException if this map is empty.
+ */
+ public K lastKey()
+ {
+ return sm.lastKey();
+ }
+
+ /**
+ * <p>
+ * Returns a checked view of the portion of the map greater than or
+ * equal to fromKey, and strictly less than toKey. The view is backed by
+ * the underlying map, so changes in one show up in the other. The submap
+ * supports all optional operations of the original.
+ * </p>
+ * <p>
+ * The returned map throws an IllegalArgumentException any time a key is
+ * used which is out of the range of fromKey and toKey. Note that the
+ * lower endpoint is included, but the upper is not; if you want to
+ * change the inclusion or exclusion of an endpoint, pass its successor
+ * object in instead. For example, for Integers, you could request
+ * <code>subMap(new Integer(lowlimit.intValue() + 1),
+ * new Integer(highlimit.intValue() + 1))</code> to reverse
+ * the inclusiveness of both endpoints.
+ * </p>
+ *
+ * @param fromKey the inclusive lower range of the submap.
+ * @param toKey the exclusive upper range of the submap.
+ * @return the submap.
+ * @throws ClassCastException if fromKey or toKey is not comparable to
+ * the map contents.
+ * @throws IllegalArgumentException if this is a subMap, and fromKey or
+ * toKey is out of range.
+ * @throws NullPointerException if fromKey or toKey is null but the map
+ * does not allow null keys.
+ */
+ public SortedMap<K, V> subMap(K fromKey, K toKey)
+ {
+ return new CheckedSortedMap<K, V>(sm.subMap(fromKey, toKey), keyType,
+ valueType);
+ }
+
+ /**
+ * <p>
+ * Returns a checked view of the portion of the map greater than or
+ * equal to fromKey. The view is backed by the underlying map, so changes
+ * in one show up in the other. The submap supports all optional operations
+ * of the original.
+ * </p>
+ * <p>
+ * The returned map throws an IllegalArgumentException any time a key is
+ * used which is out of the range of fromKey. Note that the endpoint,
+ * fromKey, is included; if you do not want this value to be included,
+ * pass its successor object in to fromKey. For example, for Integers,
+ * you could request
+ * <code>tailMap(new Integer(limit.intValue() + 1))</code>.
+ * </p>
+ *
+ * @param fromKey the inclusive lower range of the submap
+ * @return the submap
+ * @throws ClassCastException if fromKey is not comparable to the map
+ * contents
+ * @throws IllegalArgumentException if this is a subMap, and fromKey is out
+ * of range
+ * @throws NullPointerException if fromKey is null but the map does not
+ * allow null keys
+ */
+ public SortedMap<K, V> tailMap(K fromKey)
+ {
+ return new CheckedSortedMap<K, V>(sm.tailMap(fromKey), keyType,
+ valueType);
+ }
+ } // class CheckedSortedMap
+
+ /**
+ * <p>
+ * Returns a dynamically typesafe view of the given sorted set,
+ * where any modification is first checked to ensure that the type
+ * of the new data is appropriate. Although the addition of
+ * generics and parametrically-typed collections prevents an
+ * incorrect type of element being added to a collection at
+ * compile-time, via static type checking, this can be overridden by
+ * casting. In contrast, wrapping the collection within a
+ * dynamically-typesafe wrapper, using this and associated methods,
+ * <emph>guarantees</emph> that the collection will only contain
+ * elements of an appropriate type (provided it only contains such
+ * at the type of wrapping, and all subsequent access is via the
+ * wrapper). This can be useful for debugging the cause of a
+ * <code>ClassCastException</code> caused by erroneous casting, or
+ * for protecting collections from corruption by external libraries.
+ * </p>
+ * <p>
+ * The returned SortedSet implements Serializable, but can only be
+ * serialized if the set it wraps is likewise Serializable.
+ * </p>
+ *
+ * @param s the set to wrap.
+ * @param type the type of the set's elements.
+ * @return a dynamically typesafe view of the set
+ * @see Serializable
+ */
+ public static <E> SortedSet<E> checkedSortedSet(SortedSet<E> s,
+ Class<E> type)
+ {
+ return new CheckedSortedSet<E>(s, type);
+ }
+
+ /**
+ * The implementation of {@link #checkedSortedSet(SortedSet,Class)}. This
+ * class name is required for compatibility with Sun's JDK serializability.
+ *
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
+ * @since 1.5
+ */
+ private static class CheckedSortedSet<E>
+ extends CheckedSet<E>
+ implements SortedSet<E>
+ {
+ /**
+ * Compatible with JDK 1.4.
+ */
+ private static final long serialVersionUID = 1599911165492914959L;
+
+ /**
+ * The wrapped set; stored both here and in the superclass to avoid
+ * excessive casting.
+ *
+ * @serial the wrapped set
+ */
+ private SortedSet<E> ss;
+
+ /**
+ * Wrap a given set.
+ *
+ * @param ss the set to wrap.
+ * @param type the type of the set's elements.
+ * @throws NullPointerException if ss is null
+ */
+ CheckedSortedSet(SortedSet<E> ss, Class<E> type)
+ {
+ super(ss, type);
+ this.ss = ss;
+ }
+
+ /**
+ * Returns the comparator used in sorting the underlying set,
+ * or null if it is the elements' natural ordering.
+ *
+ * @return the sorting comparator
+ */
+ public Comparator<? super E> comparator()
+ {
+ return ss.comparator();
+ }
+
+ /**
+ * Returns the first (lowest sorted) element in the underlying
+ * set.
+ *
+ * @return the first element.
+ * @throws NoSuchElementException if the set is empty.
+ */
+ public E first()
+ {
+ return ss.first();
+ }
+
+ /**
+ * <p>
+ * Returns a checked view of the portion of the set strictly
+ * less than toElement. The view is backed by the underlying set,
+ * so changes in one show up in the other. The subset supports
+ * all optional operations of the original. This operation
+ * is equivalent to <code>subSet(first(), toElement)</code>.
+ * </p>
+ * <p>
+ * The returned set throws an IllegalArgumentException any time an
+ * element is used which is out of the range of toElement. Note that
+ * the endpoint, toElement, is not included; if you want this value
+ * included, pass its successor object in to toElement. For example,
+ * for Integers, you could request
+ * <code>headSet(new Integer(limit.intValue() + 1))</code>.
+ * </p>
+ *
+ * @param toElement the exclusive upper range of the subset
+ * @return the subset.
+ * @throws ClassCastException if toElement is not comparable to the set
+ * contents.
+ * @throws IllegalArgumentException if this is a subSet, and toElement is
+ * out of range.
+ * @throws NullPointerException if toElement is null but the set does not
+ * allow null elements.
+ */
+ public SortedSet<E> headSet(E toElement)
+ {
+ return new CheckedSortedSet<E>(ss.headSet(toElement), type);
+ }
+
+ /**
+ * Returns the last (highest sorted) element in the underlying
+ * set.
+ *
+ * @return the last element.
+ * @throws NoSuchElementException if the set is empty.
+ */
+ public E last()
+ {
+ return ss.last();
+ }
+
+ /**
+ * <p>
+ * Returns a checked view of the portion of the set greater than or
+ * equal to fromElement, and strictly less than toElement. The view is
+ * backed by the underlying set, so changes in one show up in the other.
+ * The subset supports all optional operations of the original.
+ * </p>
+ * <p>
+ * The returned set throws an IllegalArgumentException any time an
+ * element is used which is out of the range of fromElement and toElement.
+ * Note that the lower endpoint is included, but the upper is not; if you
+ * want to change the inclusion or exclusion of an endpoint, pass its
+ * successor object in instead. For example, for Integers, you can request
+ * <code>subSet(new Integer(lowlimit.intValue() + 1),
+ * new Integer(highlimit.intValue() + 1))</code> to reverse
+ * the inclusiveness of both endpoints.
+ * </p>
+ *
+ * @param fromElement the inclusive lower range of the subset.
+ * @param toElement the exclusive upper range of the subset.
+ * @return the subset.
+ * @throws ClassCastException if fromElement or toElement is not comparable
+ * to the set contents.
+ * @throws IllegalArgumentException if this is a subSet, and fromElement or
+ * toElement is out of range.
+ * @throws NullPointerException if fromElement or toElement is null but the
+ * set does not allow null elements.
+ */
+ public SortedSet<E> subSet(E fromElement, E toElement)
+ {
+ return new CheckedSortedSet<E>(ss.subSet(fromElement, toElement), type);
+ }
+
+ /**
+ * <p>
+ * Returns a checked view of the portion of the set greater than or equal
+ * to fromElement. The view is backed by the underlying set, so changes in
+ * one show up in the other. The subset supports all optional operations
+ * of the original.
+ * </p>
+ * <p>
+ * The returned set throws an IllegalArgumentException any time an
+ * element is used which is out of the range of fromElement. Note that
+ * the endpoint, fromElement, is included; if you do not want this value
+ * to be included, pass its successor object in to fromElement. For
+ * example, for Integers, you could request
+ * <code>tailSet(new Integer(limit.intValue() + 1))</code>.
+ * </p>
+ *
+ * @param fromElement the inclusive lower range of the subset
+ * @return the subset.
+ * @throws ClassCastException if fromElement is not comparable to the set
+ * contents.
+ * @throws IllegalArgumentException if this is a subSet, and fromElement is
+ * out of range.
+ * @throws NullPointerException if fromElement is null but the set does not
+ * allow null elements.
+ */
+ public SortedSet<E> tailSet(E fromElement)
+ {
+ return new CheckedSortedSet<E>(ss.tailSet(fromElement), type);
+ }
+ } // class CheckedSortedSet
+
} // class Collections
diff --git a/java/util/Comparator.java b/java/util/Comparator.java
index 386bdc1d6..ca414e7b1 100644
--- a/java/util/Comparator.java
+++ b/java/util/Comparator.java
@@ -1,5 +1,5 @@
/* Comparator.java -- Interface for objects that specify an ordering
- Copyright (C) 1998, 2001, 2005 Free Software Foundation, Inc.
+ Copyright (C) 1998, 2001, 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -71,7 +71,7 @@ package java.util;
* @since 1.2
* @status updated to 1.4
*/
-public interface Comparator
+public interface Comparator<T>
{
/**
* Return an integer that is negative, zero or positive depending on whether
@@ -102,7 +102,7 @@ public interface Comparator
* @throws ClassCastException if the elements are not of types that can be
* compared by this ordering.
*/
- int compare(Object o1, Object o2);
+ int compare(T o1, T o2);
/**
* Return true if the object is equal to this object. To be
diff --git a/java/util/Date.java b/java/util/Date.java
index aecca29b3..5c43bf3c1 100644
--- a/java/util/Date.java
+++ b/java/util/Date.java
@@ -108,7 +108,7 @@ import java.text.SimpleDateFormat;
* @author Andrew John Hughes (gnu_andrew@member.fsf.org)
*/
public class Date
- implements Cloneable, Comparable, Serializable
+ implements Cloneable, Comparable<Date>, Serializable
{
/**
* This is the serialization UID for this class
@@ -354,24 +354,6 @@ public class Date
}
/**
- * Compares this Date to another object. This behaves like
- * <code>compareTo(Date)</code>, but it takes a generic object
- * and throws a <code>ClassCastException</code> if obj is
- * not a <code>Date</code>.
- *
- * @param obj the other date.
- * @return 0, if the date represented
- * by obj is exactly the same as the time represented by this
- * object, a negative if this Date is before the other Date, and
- * a positive value otherwise.
- * @exception ClassCastException if obj is not of type Date.
- */
- public int compareTo(Object obj)
- {
- return compareTo((Date) obj);
- }
-
- /**
* Computes the hash code of this <code>Date</code> as the
* XOR of the most significant and the least significant
* 32 bits of the 64 bit milliseconds value.
diff --git a/java/util/Dictionary.java b/java/util/Dictionary.java
index 0d44ab67d..7b82a9f64 100644
--- a/java/util/Dictionary.java
+++ b/java/util/Dictionary.java
@@ -1,6 +1,6 @@
/* Dictionary.java -- an abstract (and essentially worthless)
class which is Hashtable's superclass
- Copyright (C) 1998, 2001, 2002 Free Software Foundation, Inc.
+ Copyright (C) 1998, 2001, 2002, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -57,7 +57,7 @@ package java.util;
* @since 1.0
* @status updated to 1.4
*/
-public abstract class Dictionary
+public abstract class Dictionary<K, V>
{
// WARNING: Dictionary is a CORE class in the bootstrap cycle. See the
// comments in vm/reference/java/lang/Runtime for implications of this fact.
@@ -75,7 +75,7 @@ public abstract class Dictionary
* @return an Enumeration of the values
* @see #keys()
*/
- public abstract Enumeration elements();
+ public abstract Enumeration<V> elements();
/**
* Returns the value associated with the supplied key, or null
@@ -87,7 +87,7 @@ public abstract class Dictionary
* @throws NullPointerException if key is null
* @see #put(Object, Object)
*/
- public abstract Object get(Object key);
+ public abstract V get(Object key);
/**
* Returns true when there are no elements in this Dictionary.
@@ -102,7 +102,7 @@ public abstract class Dictionary
* @return an Enumeration of the keys
* @see #elements()
*/
- public abstract Enumeration keys();
+ public abstract Enumeration<K> keys();
/**
* Inserts a new value into this Dictionary, located by the
@@ -115,7 +115,7 @@ public abstract class Dictionary
* @throws NullPointerException if key or value is null
* @see #get(Object)
*/
- public abstract Object put(Object key, Object value);
+ public abstract V put(K key, V value);
/**
* Removes from the Dictionary the value located by the given key. A null
@@ -125,7 +125,7 @@ public abstract class Dictionary
* @return the value associated with the removed key
* @throws NullPointerException if key is null
*/
- public abstract Object remove(Object key);
+ public abstract V remove(Object key);
/**
* Returns the number of values currently in this Dictionary.
diff --git a/java/util/EnumMap.java b/java/util/EnumMap.java
new file mode 100644
index 000000000..477dff8e0
--- /dev/null
+++ b/java/util/EnumMap.java
@@ -0,0 +1,394 @@
+/* EnumMap.java - Map where keys are enum constants
+ Copyright (C) 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.Serializable;
+
+/**
+ * @author Tom Tromey (tromey@redhat.com)
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
+ * @since 1.5
+ */
+
+public class EnumMap<K extends Enum<K>, V>
+ extends AbstractMap<K, V>
+ implements Cloneable, Serializable
+{
+ private static final long serialVersionUID = 458661240069192865L;
+
+ V[] store;
+ int cardinality;
+ Class<K> enumClass;
+
+ /**
+ * The cache for {@link #entrySet()}.
+ */
+ transient Set<Map.Entry<K, V>> entries;
+
+ static final Object emptySlot = new Object();
+
+ public EnumMap(Class<K> keyType)
+ {
+ store = (V[]) new Object[keyType.getEnumConstants().length];
+ Arrays.fill(store, emptySlot);
+ cardinality = 0;
+ enumClass = keyType;
+ }
+
+ public EnumMap(EnumMap<K, ? extends V> map)
+ {
+ store = (V[]) map.store.clone();
+ cardinality = map.cardinality;
+ enumClass = map.enumClass;
+ }
+
+ public EnumMap(Map<K, ? extends V> map)
+ {
+ if (map instanceof EnumMap)
+ {
+ EnumMap<K, ? extends V> other = (EnumMap<K, ? extends V>) map;
+ store = (V[]) other.store.clone();
+ cardinality = other.cardinality;
+ enumClass = other.enumClass;
+ }
+ else
+ {
+ for (K key : map.keySet())
+ {
+ V value = map.get(key);
+ if (store == null)
+ {
+ enumClass = key.getDeclaringClass();
+ store = (V[]) new Object[enumClass.getEnumConstants().length];
+ }
+ int o = key.ordinal();
+ if (store[o] == emptySlot)
+ ++cardinality;
+ store[o] = value;
+ }
+ // There must be a single element.
+ if (store == null)
+ throw new IllegalArgumentException("no elements in map");
+ }
+ }
+
+ public int size()
+ {
+ return cardinality;
+ }
+
+ public boolean containsValue(Object value)
+ {
+ for (V i : store)
+ {
+ if (i != emptySlot && AbstractCollection.equals(i , value))
+ return true;
+ }
+ return false;
+ }
+
+ public boolean containsKey(Object key)
+ {
+ if (! (key instanceof Enum))
+ return false;
+ Enum<K> e = (Enum<K>) key;
+ if (e.getDeclaringClass() != enumClass)
+ return false;
+ return store[e.ordinal()] != emptySlot;
+ }
+
+ public V get(Object key)
+ {
+ if (! (key instanceof Enum))
+ return null;
+ Enum<K> e = (Enum<K>) key;
+ if (e.getDeclaringClass() != enumClass)
+ return null;
+ return store[e.ordinal()];
+ }
+
+ public V put(K key, V value)
+ {
+ int o = key.ordinal();
+ V result;
+ if (store[o] == emptySlot)
+ {
+ result = null;
+ ++cardinality;
+ }
+ else
+ result = store[o];
+ store[o] = value;
+ return result;
+ }
+
+ public V remove(Object key)
+ {
+ if (! (key instanceof Enum))
+ return null;
+ Enum<K> e = (Enum<K>) key;
+ if (e.getDeclaringClass() != enumClass)
+ return null;
+ V result = store[e.ordinal()];
+ if (result == emptySlot)
+ result = null;
+ else
+ --cardinality;
+ store[e.ordinal()] = (V) emptySlot;
+ return result;
+ }
+
+ public void putAll(Map<? extends K, ? extends V> map)
+ {
+ for (K key : map.keySet())
+ {
+ V value = map.get(key);
+
+ int o = key.ordinal();
+ if (store[o] == emptySlot)
+ ++cardinality;
+ store[o] = value;
+ }
+ }
+
+ public void clear()
+ {
+ Arrays.fill(store, emptySlot);
+ cardinality = 0;
+ }
+
+ public Set<K> keySet()
+ {
+ if (keys == null)
+ {
+ keys = new AbstractSet<K>()
+ {
+ public int size()
+ {
+ return cardinality;
+ }
+
+ public Iterator<K> iterator()
+ {
+ return new Iterator<K>()
+ {
+ int count = 0;
+ int index = -1;
+
+ public boolean hasNext()
+ {
+ return count < cardinality;
+ }
+
+ public K next()
+ {
+ ++count;
+ for (++index; store[index] == emptySlot; ++index)
+ ;
+ return enumClass.getEnumConstants()[index];
+ }
+
+ public void remove()
+ {
+ --cardinality;
+ store[index] = (V) emptySlot;
+ }
+ };
+ }
+
+ public void clear()
+ {
+ EnumMap.this.clear();
+ }
+
+ public boolean contains(Object o)
+ {
+ return contains(o);
+ }
+
+ public boolean remove(Object o)
+ {
+ return EnumMap.this.remove(o) != null;
+ }
+ };
+ }
+ return keys;
+ }
+
+ public Collection<V> values()
+ {
+ if (values == null)
+ {
+ values = new AbstractCollection<V>()
+ {
+ public int size()
+ {
+ return cardinality;
+ }
+
+ public Iterator<V> iterator()
+ {
+ return new Iterator<V>()
+ {
+ int count = 0;
+ int index = -1;
+
+ public boolean hasNext()
+ {
+ return count < cardinality;
+ }
+
+ public V next()
+ {
+ ++count;
+ for (++index; store[index] == emptySlot; ++index)
+ ;
+ return store[index];
+ }
+
+ public void remove()
+ {
+ --cardinality;
+ store[index] = (V) emptySlot;
+ }
+ };
+ }
+
+ public void clear()
+ {
+ EnumMap.this.clear();
+ }
+ };
+ }
+ return values;
+ }
+
+ public Set<Map.Entry<K, V>> entrySet()
+ {
+ if (entries == null)
+ {
+ entries = new AbstractSet<Map.Entry<K, V>>()
+ {
+ public int size()
+ {
+ return cardinality;
+ }
+
+ public Iterator<Map.Entry<K, V>> iterator()
+ {
+ return new Iterator<Map.Entry<K, V>>()
+ {
+ int count = 0;
+ int index = -1;
+
+ public boolean hasNext()
+ {
+ return count < cardinality;
+ }
+
+ public Map.Entry<K,V> next()
+ {
+ ++count;
+ for (++index; store[index] == emptySlot; ++index)
+ ;
+ // FIXME: we could just return something that
+ // only knows the index. That would be cleaner.
+ return new AbstractMap.SimpleEntry<K, V>(enumClass.getEnumConstants()[index],
+ store[index])
+ {
+ public V setValue(V newVal)
+ {
+ value = newVal;
+ return put(key, newVal);
+ }
+ };
+ }
+
+ public void remove()
+ {
+ --cardinality;
+ store[index] = (V) emptySlot;
+ }
+ };
+ }
+
+ public void clear()
+ {
+ EnumMap.this.clear();
+ }
+
+ public boolean contains(Object o)
+ {
+ if (! (o instanceof Map.Entry))
+ return false;
+ Map.Entry<K, V> other = (Map.Entry<K, V>) o;
+ return (containsKey(other.getKey())
+ && AbstractCollection.equals(get(other.getKey()),
+ other.getValue()));
+ }
+
+ public boolean remove(Object o)
+ {
+ if (! (o instanceof Map.Entry))
+ return false;
+ Map.Entry<K, V> other = (Map.Entry<K, V>) o;
+ return EnumMap.this.remove(other.getKey()) != null;
+ }
+ };
+ }
+ return entries;
+ }
+
+ public boolean equals(Object o)
+ {
+ if (! (o instanceof EnumMap))
+ return false;
+ EnumMap<K, V> other = (EnumMap<K, V>) o;
+ if (other.enumClass != enumClass || other.cardinality != cardinality)
+ return false;
+ return Arrays.equals(store, other.store);
+ }
+
+ public EnumMap<K, V> clone()
+ {
+ /* This constructor provides this functionality */
+ return new EnumMap(this);
+ }
+
+}
diff --git a/java/util/EnumSet.java b/java/util/EnumSet.java
new file mode 100644
index 000000000..44ae370ba
--- /dev/null
+++ b/java/util/EnumSet.java
@@ -0,0 +1,365 @@
+/* EnumSet.java - Set of enum objects
+ Copyright (C) 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.Serializable;
+
+/**
+ * @author Tom Tromey (tromey@redhat.com)
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
+ * @since 1.5
+ */
+
+// FIXME: serialization is special.
+public class EnumSet<T extends Enum<T>>
+ extends AbstractSet<T>
+ implements Cloneable, Serializable
+{
+ private static final long serialVersionUID = 4782406773684236311L;
+
+ BitSet store;
+ int cardinality;
+ Class<T> enumClass;
+
+ EnumSet()
+ {
+ }
+
+ public EnumSet<T> clone()
+ {
+ EnumSet<T> r;
+
+ try
+ {
+ r = (EnumSet<T>) super.clone();
+ }
+ catch (CloneNotSupportedException _)
+ {
+ /* Can't happen */
+ return null;
+ }
+ r.store = (BitSet) store.clone();
+ return r;
+ }
+
+ public int size()
+ {
+ return cardinality;
+ }
+
+ public Iterator<T> iterator()
+ {
+ return new Iterator<T>()
+ {
+ int next = -1;
+ int count = 0;
+
+ public boolean hasNext()
+ {
+ return count < cardinality;
+ }
+
+ public T next()
+ {
+ next = store.nextSetBit(next + 1);
+ ++count;
+ return enumClass.getEnumConstants()[next];
+ }
+
+ public void remove()
+ {
+ if (! store.get(next))
+ {
+ store.clear(next);
+ --cardinality;
+ }
+ }
+ };
+ }
+
+ public boolean add(T val)
+ {
+ if (store.get(val.ordinal()))
+ return false;
+ store.set(val.ordinal());
+ ++cardinality;
+ return true;
+ }
+
+ public boolean addAll(Collection<? extends T> c)
+ {
+ boolean result = false;
+ if (c instanceof EnumSet)
+ {
+ EnumSet<T> other = (EnumSet<T>) c;
+ if (enumClass == other.enumClass)
+ {
+ store.or(other.store);
+ int save = cardinality;
+ cardinality = store.cardinality();
+ result = save != cardinality;
+ }
+ }
+ else
+ {
+ for (T val : c)
+ {
+ if (add (val))
+ result = true;
+ }
+ }
+ return result;
+ }
+
+ public void clear()
+ {
+ store.clear();
+ cardinality = 0;
+ }
+
+ public boolean contains(Object o)
+ {
+ if (! (o instanceof Enum))
+ return false;
+ Enum<T> e = (Enum<T>) o;
+ if (e.getDeclaringClass() != enumClass)
+ return false;
+ return store.get(e.ordinal());
+ }
+
+ public boolean containsAll(Collection<?> c)
+ {
+ if (c instanceof EnumSet)
+ {
+ EnumSet<T> other = (EnumSet<T>) c;
+ if (enumClass == other.enumClass)
+ return store.containsAll(other.store);
+ return false;
+ }
+ return super.containsAll(c);
+ }
+
+ public boolean remove(Object o)
+ {
+ if (! (o instanceof Enum))
+ return false;
+ Enum<T> e = (Enum<T>) o;
+ if (e.getDeclaringClass() != enumClass)
+ return false;
+ store.clear(e.ordinal());
+ --cardinality;
+ return true;
+ }
+
+ public boolean removeAll(Collection<?> c)
+ {
+ if (c instanceof EnumSet)
+ {
+ EnumSet<T> other = (EnumSet<T>) c;
+ if (enumClass != other.enumClass)
+ return false;
+ store.andNot(other.store);
+ int save = cardinality;
+ cardinality = store.cardinality();
+ return save != cardinality;
+ }
+ return super.removeAll(c);
+ }
+
+ public boolean retainAll(Collection<?> c)
+ {
+ if (c instanceof EnumSet)
+ {
+ EnumSet<T> other = (EnumSet<T>) c;
+ if (enumClass != other.enumClass)
+ return false;
+ store.and(other.store);
+ int save = cardinality;
+ cardinality = store.cardinality();
+ return save != cardinality;
+ }
+ return super.retainAll(c);
+ }
+
+ public static <T extends Enum<T>> EnumSet<T> allOf(Class<T> eltType)
+ {
+ EnumSet<T> r = new EnumSet<T>();
+ r.store = new BitSet(eltType.getEnumConstants().length);
+ r.store.set(0, r.store.size());
+ r.cardinality = r.store.size();
+ r.enumClass = eltType;
+ return r;
+ }
+
+ public static <T extends Enum<T>> EnumSet<T> noneOf(Class<T> eltType)
+ {
+ EnumSet<T> r = new EnumSet<T>();
+ r.store = new BitSet(eltType.getEnumConstants().length);
+ r.enumClass = eltType;
+ return r;
+ }
+
+ public static <T extends Enum<T>> EnumSet<T> copyOf(EnumSet<T> other)
+ {
+ // We can't just use `other.clone' since we don't want to make a
+ // subclass.
+ EnumSet<T> r = new EnumSet<T>();
+ r.store = (BitSet) other.store.clone();
+ r.cardinality = other.cardinality;
+ r.enumClass = other.enumClass;
+ return r;
+ }
+
+ public static <T extends Enum<T>> EnumSet<T> copyOf(Collection<T> other)
+ {
+ if (other instanceof EnumSet)
+ return copyOf((EnumSet<T>) other);
+ EnumSet<T> r = new EnumSet<T>();
+ for (T val : other)
+ {
+ if (r.store == null)
+ {
+ r.enumClass = val.getDeclaringClass();
+ r.store = new BitSet(r.enumClass.getEnumConstants().length);
+ }
+ r.store.set(val.ordinal());
+ }
+ // The collection must contain at least one element.
+ if (r.store == null)
+ throw new IllegalArgumentException();
+ r.cardinality = r.store.cardinality();
+ return r;
+ }
+
+ public static <T extends Enum<T>> EnumSet<T> complementOf(EnumSet<T> other)
+ {
+ EnumSet<T> r = new EnumSet<T>();
+ r.store = (BitSet) other.store.clone();
+ r.store.flip(0, r.store.size());
+ r.cardinality = r.store.size() - other.cardinality;
+ r.enumClass = other.enumClass;
+ return r;
+ }
+
+ public static <T extends Enum<T>> EnumSet<T> of(T first)
+ {
+ EnumSet<T> r = new EnumSet<T>();
+ r.enumClass = first.getDeclaringClass();
+ r.store = new BitSet(r.enumClass.getEnumConstants().length);
+ r.store.set(first.ordinal());
+ r.cardinality = 1;
+ return r;
+ }
+
+ public static <T extends Enum<T>> EnumSet<T> of(T first, T second)
+ {
+ EnumSet<T> r = new EnumSet<T>();
+ r.enumClass = first.getDeclaringClass();
+ r.store = new BitSet(r.enumClass.getEnumConstants().length);
+ r.store.set(first.ordinal());
+ r.store.set(second.ordinal());
+ r.cardinality = r.store.cardinality();
+ return r;
+ }
+
+ public static <T extends Enum<T>> EnumSet<T> of(T first, T second, T third)
+ {
+ EnumSet<T> r = new EnumSet<T>();
+ r.enumClass = first.getDeclaringClass();
+ r.store = new BitSet(r.enumClass.getEnumConstants().length);
+ r.store.set(first.ordinal());
+ r.store.set(second.ordinal());
+ r.store.set(third.ordinal());
+ r.cardinality = r.store.cardinality();
+ return r;
+ }
+
+ public static <T extends Enum<T>> EnumSet<T> of(T first, T second, T third,
+ T fourth)
+ {
+ EnumSet<T> r = new EnumSet<T>();
+ r.enumClass = first.getDeclaringClass();
+ r.store = new BitSet(r.enumClass.getEnumConstants().length);
+ r.store.set(first.ordinal());
+ r.store.set(second.ordinal());
+ r.store.set(third.ordinal());
+ r.store.set(fourth.ordinal());
+ r.cardinality = r.store.cardinality();
+ return r;
+ }
+
+ public static <T extends Enum<T>> EnumSet<T> of(T first, T second, T third,
+ T fourth, T fifth)
+ {
+ EnumSet<T> r = new EnumSet<T>();
+ r.enumClass = first.getDeclaringClass();
+ r.store = new BitSet(r.enumClass.getEnumConstants().length);
+ r.store.set(first.ordinal());
+ r.store.set(second.ordinal());
+ r.store.set(third.ordinal());
+ r.store.set(fourth.ordinal());
+ r.store.set(fifth.ordinal());
+ r.cardinality = r.store.cardinality();
+ return r;
+ }
+
+ public static <T extends Enum<T>> EnumSet<T> of(T first, T... rest)
+ {
+ EnumSet<T> r = new EnumSet<T>();
+ r.enumClass = first.getDeclaringClass();
+ r.store = new BitSet(r.enumClass.getEnumConstants().length);
+ r.store.set(first.ordinal());
+ for (T val : rest)
+ r.store.set(val.ordinal());
+ r.cardinality = r.store.cardinality();
+ return r;
+ }
+
+ public static <T extends Enum<T>> EnumSet<T> range(T from, T to)
+ {
+ if (from.compareTo(to) > 0)
+ throw new IllegalArgumentException();
+ EnumSet<T> r = new EnumSet<T>();
+ r.store = new BitSet(from.getDeclaringClass().getEnumConstants().length);
+ r.store.set(from.ordinal(), to.ordinal() + 1);
+ r.enumClass = from.getDeclaringClass();
+ r.cardinality = to.ordinal() - from.ordinal() + 1;
+ return r;
+ }
+}
diff --git a/java/util/Enumeration.java b/java/util/Enumeration.java
index 1365bbb2f..2aec31b6f 100644
--- a/java/util/Enumeration.java
+++ b/java/util/Enumeration.java
@@ -1,5 +1,6 @@
/* Enumeration.java -- Interface for enumerating lists of objects
- Copyright (C) 1998, 1999, 2001, 2005 Free Software Foundation, Inc.
+ Copyright (C) 1998, 1999, 2001, 2004, 2005
+ Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -60,7 +61,7 @@ package java.util;
* @since 1.0
* @status updated to 1.4
*/
-public interface Enumeration
+public interface Enumeration<E>
{
/**
* Tests whether there are elements remaining in the enumeration.
@@ -77,5 +78,5 @@ public interface Enumeration
* @return the next element in the enumeration
* @throws NoSuchElementException if there are no more elements
*/
- Object nextElement();
+ E nextElement();
}
diff --git a/java/util/Formatter.java b/java/util/Formatter.java
index 01d546315..12b705bce 100644
--- a/java/util/Formatter.java
+++ b/java/util/Formatter.java
@@ -89,7 +89,7 @@ public final class Formatter
/**
* The output of the formatter.
*/
- private StringBuilder out;
+ private Appendable out;
/**
* The locale used by the formatter.
@@ -143,6 +143,15 @@ public final class Formatter
= SystemProperties.getProperty("line.separator");
/**
+ * The type of numeric output format for a {@link BigDecimal}.
+ */
+ public enum BigDecimalLayoutForm
+ {
+ DECIMAL_FLOAT,
+ SCIENTIFIC
+ }
+
+ /**
* Constructs a new <code>Formatter</code> using the default
* locale and a {@link StringBuilder} as the output stream.
*/
@@ -170,7 +179,7 @@ public final class Formatter
*
* @param app the output stream to use.
*/
- public Formatter(StringBuilder app)
+ public Formatter(Appendable app)
{
this(app, Locale.getDefault());
}
@@ -183,13 +192,189 @@ public final class Formatter
* @param app the output stream to use.
* @param loc the locale to use.
*/
- public Formatter(StringBuilder app, Locale loc)
+ public Formatter(Appendable app, Locale loc)
{
this.out = app == null ? new StringBuilder() : app;
this.locale = loc;
}
/**
+ * Constructs a new <code>Formatter</code> using the default
+ * locale and character set, with the specified file as the
+ * output stream.
+ *
+ * @param file the file to use for output.
+ * @throws FileNotFoundException if the file does not exist
+ * and can not be created.
+ * @throws SecurityException if a security manager is present
+ * and doesn't allow writing to the file.
+ */
+ public Formatter(File file)
+ throws FileNotFoundException
+ {
+ this(new OutputStreamWriter(new FileOutputStream(file)));
+ }
+
+ /**
+ * Constructs a new <code>Formatter</code> using the default
+ * locale, with the specified file as the output stream
+ * and the supplied character set.
+ *
+ * @param file the file to use for output.
+ * @param charset the character set to use for output.
+ * @throws FileNotFoundException if the file does not exist
+ * and can not be created.
+ * @throws SecurityException if a security manager is present
+ * and doesn't allow writing to the file.
+ * @throws UnsupportedEncodingException if the supplied character
+ * set is not supported.
+ */
+ public Formatter(File file, String charset)
+ throws FileNotFoundException, UnsupportedEncodingException
+ {
+ this(file, charset, Locale.getDefault());
+ }
+
+ /**
+ * Constructs a new <code>Formatter</code> using the specified
+ * file as the output stream with the supplied character set
+ * and locale. If the locale is <code>null</code>, then no
+ * localization is applied.
+ *
+ * @param file the file to use for output.
+ * @param charset the character set to use for output.
+ * @param loc the locale to use.
+ * @throws FileNotFoundException if the file does not exist
+ * and can not be created.
+ * @throws SecurityException if a security manager is present
+ * and doesn't allow writing to the file.
+ * @throws UnsupportedEncodingException if the supplied character
+ * set is not supported.
+ */
+ public Formatter(File file, String charset, Locale loc)
+ throws FileNotFoundException, UnsupportedEncodingException
+ {
+ this(new OutputStreamWriter(new FileOutputStream(file), charset),
+ loc);
+ }
+
+ /**
+ * Constructs a new <code>Formatter</code> using the default
+ * locale and character set, with the specified output stream.
+ *
+ * @param out the output stream to use.
+ */
+ public Formatter(OutputStream out)
+ {
+ this(new OutputStreamWriter(out));
+ }
+
+ /**
+ * Constructs a new <code>Formatter</code> using the default
+ * locale, with the specified file output stream and the
+ * supplied character set.
+ *
+ * @param out the output stream.
+ * @param charset the character set to use for output.
+ * @throws UnsupportedEncodingException if the supplied character
+ * set is not supported.
+ */
+ public Formatter(OutputStream out, String charset)
+ throws UnsupportedEncodingException
+ {
+ this(out, charset, Locale.getDefault());
+ }
+
+ /**
+ * Constructs a new <code>Formatter</code> using the specified
+ * output stream with the supplied character set and locale.
+ * If the locale is <code>null</code>, then no localization is
+ * applied.
+ *
+ * @param file the output stream.
+ * @param charset the character set to use for output.
+ * @param loc the locale to use.
+ * @throws UnsupportedEncodingException if the supplied character
+ * set is not supported.
+ */
+ public Formatter(OutputStream out, String charset, Locale loc)
+ throws UnsupportedEncodingException
+ {
+ this(new OutputStreamWriter(out, charset), loc);
+ }
+
+ /**
+ * Constructs a new <code>Formatter</code> using the default
+ * locale with the specified output stream. The character
+ * set used is that of the output stream.
+ *
+ * @param out the output stream to use.
+ */
+ public Formatter(PrintStream out)
+ {
+ this((Appendable) out);
+ }
+
+ /**
+ * Constructs a new <code>Formatter</code> using the default
+ * locale and character set, with the specified file as the
+ * output stream.
+ *
+ * @param file the file to use for output.
+ * @throws FileNotFoundException if the file does not exist
+ * and can not be created.
+ * @throws SecurityException if a security manager is present
+ * and doesn't allow writing to the file.
+ */
+ public Formatter(String file) throws FileNotFoundException
+ {
+ this(new OutputStreamWriter(new FileOutputStream(file)));
+ }
+
+ /**
+ * Constructs a new <code>Formatter</code> using the default
+ * locale, with the specified file as the output stream
+ * and the supplied character set.
+ *
+ * @param file the file to use for output.
+ * @param charset the character set to use for output.
+ * @throws FileNotFoundException if the file does not exist
+ * and can not be created.
+ * @throws SecurityException if a security manager is present
+ * and doesn't allow writing to the file.
+ * @throws UnsupportedEncodingException if the supplied character
+ * set is not supported.
+ */
+ public Formatter(String file, String charset)
+ throws FileNotFoundException, UnsupportedEncodingException
+ {
+ this(file, charset, Locale.getDefault());
+ }
+
+ /**
+ * Constructs a new <code>Formatter</code> using the specified
+ * file as the output stream with the supplied character set
+ * and locale. If the locale is <code>null</code>, then no
+ * localization is applied.
+ *
+ * @param file the file to use for output.
+ * @param charset the character set to use for output.
+ * @param loc the locale to use.
+ * @throws FileNotFoundException if the file does not exist
+ * and can not be created.
+ * @throws SecurityException if a security manager is present
+ * and doesn't allow writing to the file.
+ * @throws UnsupportedEncodingException if the supplied character
+ * set is not supported.
+ */
+ public Formatter(String file, String charset, Locale loc)
+ throws FileNotFoundException, UnsupportedEncodingException
+ {
+ this(new OutputStreamWriter(new FileOutputStream(file), charset),
+ loc);
+ }
+
+ /**
* Closes the formatter, so as to release used resources.
* If the underlying output stream supports the {@link Closeable}
* interface, then this is also closed. Attempts to use
@@ -201,6 +386,16 @@ public final class Formatter
{
if (closed)
return;
+ try
+ {
+ if (out instanceof Closeable)
+ ((Closeable) out).close();
+ }
+ catch (IOException _)
+ {
+ // FIXME: do we ignore these or do we set ioException?
+ // The docs seem to indicate that we should ignore.
+ }
closed = true;
}
@@ -215,6 +410,16 @@ public final class Formatter
{
if (closed)
throw new FormatterClosedException();
+ try
+ {
+ if (out instanceof Flushable)
+ ((Flushable) out).flush();
+ }
+ catch (IOException _)
+ {
+ // FIXME: do we ignore these or do we set ioException?
+ // The docs seem to indicate that we should ignore.
+ }
}
/**
@@ -544,9 +749,6 @@ public final class Formatter
noPrecision(precision);
// Some error checking.
- if ((flags & FormattableFlags.ZERO) != 0
- && (flags & FormattableFlags.LEFT_JUSTIFY) == 0)
- throw new IllegalFormatFlagsException(getName(flags));
if ((flags & FormattableFlags.PLUS) != 0
&& (flags & FormattableFlags.SPACE) != 0)
throw new IllegalFormatFlagsException(getName(flags));
@@ -984,7 +1186,7 @@ public final class Formatter
advance();
if (start == index)
return -1;
- return Integer.decode(format.substring(start, index)).intValue();
+ return Integer.decode(format.substring(start, index));
}
/**
@@ -1090,7 +1292,7 @@ public final class Formatter
* between it and the arguments.
* @throws FormatterClosedException if the formatter is closed.
*/
- public Formatter format(Locale loc, String fmt, Object[] args)
+ public Formatter format(Locale loc, String fmt, Object... args)
{
if (closed)
throw new FormatterClosedException();
@@ -1233,7 +1435,7 @@ public final class Formatter
* between it and the arguments.
* @throws FormatterClosedException if the formatter is closed.
*/
- public Formatter format(String format, Object[] args)
+ public Formatter format(String format, Object... args)
{
return format(locale, format, args);
}
@@ -1269,7 +1471,7 @@ public final class Formatter
* @return the formatter's output stream.
* @throws FormatterClosedException if the formatter is closed.
*/
- public StringBuilder out()
+ public Appendable out()
{
if (closed)
throw new FormatterClosedException();
diff --git a/java/util/GregorianCalendar.java b/java/util/GregorianCalendar.java
index 83ac00e77..4a66d6e08 100644
--- a/java/util/GregorianCalendar.java
+++ b/java/util/GregorianCalendar.java
@@ -935,11 +935,10 @@ public class GregorianCalendar extends Calendar
fields[MONTH] += 12;
fields[YEAR]--;
}
+ isTimeSet = false;
int maxDay = getActualMaximum(DAY_OF_MONTH);
if (fields[DAY_OF_MONTH] > maxDay)
fields[DAY_OF_MONTH] = maxDay;
- set(YEAR, fields[YEAR]);
- set(MONTH, fields[MONTH]);
break;
case DAY_OF_MONTH:
case DAY_OF_YEAR:
diff --git a/java/util/HashMap.java b/java/util/HashMap.java
index a734af484..92022a7d5 100644
--- a/java/util/HashMap.java
+++ b/java/util/HashMap.java
@@ -96,8 +96,8 @@ import java.io.Serializable;
* @since 1.2
* @status updated to 1.4
*/
-public class HashMap extends AbstractMap
- implements Map, Cloneable, Serializable
+public class HashMap<K, V> extends AbstractMap<K, V>
+ implements Map<K, V>, Cloneable, Serializable
{
/**
* Default number of buckets. This is the value the JDK 1.3 uses. Some
@@ -136,7 +136,7 @@ public class HashMap extends AbstractMap
* Array containing the actual key-value mappings.
* Package visible for use by nested and subclasses.
*/
- transient HashEntry[] buckets;
+ transient HashEntry<K, V>[] buckets;
/**
* Counts the number of modifications this HashMap has undergone, used
@@ -154,7 +154,7 @@ public class HashMap extends AbstractMap
/**
* The cache for {@link #entrySet()}.
*/
- private transient Set entries;
+ private transient Set<Map.Entry<K, V>> entries;
/**
* Class to represent an entry in the hash table. Holds a single key-value
@@ -162,19 +162,19 @@ public class HashMap extends AbstractMap
*
* @author Eric Blake (ebb9@email.byu.edu)
*/
- static class HashEntry extends AbstractMap.BasicMapEntry
+ static class HashEntry<K, V> extends AbstractMap.SimpleEntry<K, V>
{
/**
* The next entry in the linked list. Package visible for use by subclass.
*/
- HashEntry next;
+ HashEntry<K, V> next;
/**
* Simple constructor.
* @param key the key
* @param value the value
*/
- HashEntry(Object key, Object value)
+ HashEntry(K key, V value)
{
super(key, value);
}
@@ -194,7 +194,7 @@ public class HashMap extends AbstractMap
*
* @return the value of this key as it is removed
*/
- Object cleanup()
+ V cleanup()
{
return value;
}
@@ -220,7 +220,7 @@ public class HashMap extends AbstractMap
* <b>NOTE: key / value pairs are not cloned in this constructor.</b>
* @throws NullPointerException if m is null
*/
- public HashMap(Map m)
+ public HashMap(Map<? extends K, ? extends V> m)
{
this(Math.max(m.size() * 2, DEFAULT_CAPACITY), DEFAULT_LOAD_FACTOR);
putAll(m);
@@ -256,7 +256,7 @@ public class HashMap extends AbstractMap
if (initialCapacity == 0)
initialCapacity = 1;
- buckets = new HashEntry[initialCapacity];
+ buckets = (HashEntry<K, V>[]) new HashEntry[initialCapacity];
this.loadFactor = loadFactor;
threshold = (int) (initialCapacity * loadFactor);
}
@@ -292,10 +292,10 @@ public class HashMap extends AbstractMap
* @see #put(Object, Object)
* @see #containsKey(Object)
*/
- public Object get(Object key)
+ public V get(Object key)
{
int idx = hash(key);
- HashEntry e = buckets[idx];
+ HashEntry<K, V> e = buckets[idx];
while (e != null)
{
if (equals(key, e.key))
@@ -316,7 +316,7 @@ public class HashMap extends AbstractMap
public boolean containsKey(Object key)
{
int idx = hash(key);
- HashEntry e = buckets[idx];
+ HashEntry<K, V> e = buckets[idx];
while (e != null)
{
if (equals(key, e.key))
@@ -339,17 +339,17 @@ public class HashMap extends AbstractMap
* @see #get(Object)
* @see Object#equals(Object)
*/
- public Object put(Object key, Object value)
+ public V put(K key, V value)
{
int idx = hash(key);
- HashEntry e = buckets[idx];
+ HashEntry<K, V> e = buckets[idx];
while (e != null)
{
if (equals(key, e.key))
{
e.access(); // Must call this for bookkeeping in LinkedHashMap.
- Object r = e.value;
+ V r = e.value;
e.value = value;
return r;
}
@@ -378,23 +378,25 @@ public class HashMap extends AbstractMap
*
* @param m the map to be hashed into this
*/
- public void putAll(Map m)
+ public void putAll(Map<? extends K, ? extends V> m)
{
- Iterator itr = m.entrySet().iterator();
- while (itr.hasNext())
+ Map<K,V> addMap;
+
+ addMap = (Map<K,V>) m;
+ for (Map.Entry<K,V> e : addMap.entrySet())
{
- Map.Entry e = (Map.Entry) itr.next();
// Optimize in case the Entry is one of our own.
- if (e instanceof AbstractMap.BasicMapEntry)
+ if (e instanceof AbstractMap.SimpleEntry)
{
- AbstractMap.BasicMapEntry entry = (AbstractMap.BasicMapEntry) e;
+ AbstractMap.SimpleEntry<? extends K, ? extends V> entry
+ = (AbstractMap.SimpleEntry<? extends K, ? extends V>) e;
put(entry.key, entry.value);
}
else
put(e.getKey(), e.getValue());
}
}
-
+
/**
* Removes from the HashMap and returns the value which is mapped by the
* supplied key. If the key maps to nothing, then the HashMap remains
@@ -405,11 +407,11 @@ public class HashMap extends AbstractMap
* @param key the key used to locate the value to remove
* @return whatever the key mapped to, if present
*/
- public Object remove(Object key)
+ public V remove(Object key)
{
int idx = hash(key);
- HashEntry e = buckets[idx];
- HashEntry last = null;
+ HashEntry<K, V> e = buckets[idx];
+ HashEntry<K, V> last = null;
while (e != null)
{
@@ -455,7 +457,7 @@ public class HashMap extends AbstractMap
{
for (int i = buckets.length - 1; i >= 0; i--)
{
- HashEntry e = buckets[i];
+ HashEntry<K, V> e = buckets[i];
while (e != null)
{
if (equals(value, e.value))
@@ -474,16 +476,16 @@ public class HashMap extends AbstractMap
*/
public Object clone()
{
- HashMap copy = null;
+ HashMap<K, V> copy = null;
try
{
- copy = (HashMap) super.clone();
+ copy = (HashMap<K, V>) super.clone();
}
catch (CloneNotSupportedException x)
{
// This is impossible.
}
- copy.buckets = new HashEntry[buckets.length];
+ copy.buckets = (HashEntry<K, V>[]) new HashEntry[buckets.length];
copy.putAllInternal(this);
// Clear the entry cache. AbstractMap.clone() does the others.
copy.entries = null;
@@ -499,19 +501,19 @@ public class HashMap extends AbstractMap
* @see #values()
* @see #entrySet()
*/
- public Set keySet()
+ public Set<K> keySet()
{
if (keys == null)
// Create an AbstractSet with custom implementations of those methods
// that can be overridden easily and efficiently.
- keys = new AbstractSet()
+ keys = new AbstractSet<K>()
{
public int size()
{
return size;
}
- public Iterator iterator()
+ public Iterator<K> iterator()
{
// Cannot create the iterator directly, because of LinkedHashMap.
return HashMap.this.iterator(KEYS);
@@ -550,19 +552,19 @@ public class HashMap extends AbstractMap
* @see #keySet()
* @see #entrySet()
*/
- public Collection values()
+ public Collection<V> values()
{
if (values == null)
// We don't bother overriding many of the optional methods, as doing so
// wouldn't provide any significant performance advantage.
- values = new AbstractCollection()
+ values = new AbstractCollection<V>()
{
public int size()
{
return size;
}
- public Iterator iterator()
+ public Iterator<V> iterator()
{
// Cannot create the iterator directly, because of LinkedHashMap.
return HashMap.this.iterator(VALUES);
@@ -589,19 +591,19 @@ public class HashMap extends AbstractMap
* @see #values()
* @see Map.Entry
*/
- public Set entrySet()
+ public Set<Map.Entry<K, V>> entrySet()
{
if (entries == null)
// Create an AbstractSet with custom implementations of those methods
// that can be overridden easily and efficiently.
- entries = new AbstractSet()
+ entries = new AbstractSet<Map.Entry<K, V>>()
{
public int size()
{
return size;
}
- public Iterator iterator()
+ public Iterator<Map.Entry<K, V>> iterator()
{
// Cannot create the iterator directly, because of LinkedHashMap.
return HashMap.this.iterator(ENTRIES);
@@ -619,7 +621,7 @@ public class HashMap extends AbstractMap
public boolean remove(Object o)
{
- HashEntry e = getEntry(o);
+ HashEntry<K, V> e = getEntry(o);
if (e != null)
{
HashMap.this.remove(e.key);
@@ -641,9 +643,9 @@ public class HashMap extends AbstractMap
* @param callRemove whether to call the removeEldestEntry method
* @see #put(Object, Object)
*/
- void addEntry(Object key, Object value, int idx, boolean callRemove)
+ void addEntry(K key, V value, int idx, boolean callRemove)
{
- HashEntry e = new HashEntry(key, value);
+ HashEntry<K, V> e = new HashEntry<K, V>(key, value);
e.next = buckets[idx];
buckets[idx] = e;
}
@@ -657,14 +659,14 @@ public class HashMap extends AbstractMap
* @see #entrySet()
*/
// Package visible, for use in nested classes.
- final HashEntry getEntry(Object o)
+ final HashEntry<K, V> getEntry(Object o)
{
if (! (o instanceof Map.Entry))
return null;
- Map.Entry me = (Map.Entry) o;
- Object key = me.getKey();
+ Map.Entry<K, V> me = (Map.Entry<K, V>) o;
+ K key = me.getKey();
int idx = hash(key);
- HashEntry e = buckets[idx];
+ HashEntry<K, V> e = buckets[idx];
while (e != null)
{
if (equals(e.key, key))
@@ -693,9 +695,10 @@ public class HashMap extends AbstractMap
* @param type {@link #KEYS}, {@link #VALUES}, or {@link #ENTRIES}
* @return the appropriate iterator
*/
- Iterator iterator(int type)
+ <T> Iterator<T> iterator(int type)
{
- return new HashIterator(type);
+ // FIXME: bogus cast here.
+ return new HashIterator<T>(type);
}
/**
@@ -705,15 +708,16 @@ public class HashMap extends AbstractMap
*
* @param m the map to initialize this from
*/
- void putAllInternal(Map m)
+ void putAllInternal(Map<? extends K, ? extends V> m)
{
- Iterator itr = m.entrySet().iterator();
+ Map<K,V> addMap;
+
+ addMap = (Map<K,V>) m;
size = 0;
- while (itr.hasNext())
+ for (Map.Entry<K,V> e : addMap.entrySet())
{
size++;
- Map.Entry e = (Map.Entry) itr.next();
- Object key = e.getKey();
+ K key = e.getKey();
int idx = hash(key);
addEntry(key, e.getValue(), idx, false);
}
@@ -730,20 +734,20 @@ public class HashMap extends AbstractMap
*/
private void rehash()
{
- HashEntry[] oldBuckets = buckets;
+ HashEntry<K, V>[] oldBuckets = buckets;
int newcapacity = (buckets.length * 2) + 1;
threshold = (int) (newcapacity * loadFactor);
- buckets = new HashEntry[newcapacity];
+ buckets = (HashEntry<K, V>[]) new HashEntry[newcapacity];
for (int i = oldBuckets.length - 1; i >= 0; i--)
{
- HashEntry e = oldBuckets[i];
+ HashEntry<K, V> e = oldBuckets[i];
while (e != null)
{
int idx = hash(e.key);
- HashEntry dest = buckets[idx];
- HashEntry next = e.next;
+ HashEntry<K, V> dest = buckets[idx];
+ HashEntry<K, V> next = e.next;
e.next = buckets[idx];
buckets[idx] = e;
e = next;
@@ -769,10 +773,10 @@ public class HashMap extends AbstractMap
s.writeInt(buckets.length);
s.writeInt(size);
// Avoid creating a wasted Set by creating the iterator directly.
- Iterator it = iterator(ENTRIES);
+ Iterator<HashEntry<K, V>> it = iterator(ENTRIES);
while (it.hasNext())
{
- HashEntry entry = (HashEntry) it.next();
+ HashEntry<K, V> entry = it.next();
s.writeObject(entry.key);
s.writeObject(entry.value);
}
@@ -796,13 +800,13 @@ public class HashMap extends AbstractMap
s.defaultReadObject();
// Read and use capacity, followed by key/value pairs.
- buckets = new HashEntry[s.readInt()];
+ buckets = (HashEntry<K, V>[]) new HashEntry[s.readInt()];
int len = s.readInt();
size = len;
while (len-- > 0)
{
Object key = s.readObject();
- addEntry(key, s.readObject(), hash(key), false);
+ addEntry((K) key, (V) s.readObject(), hash(key), false);
}
}
@@ -813,7 +817,7 @@ public class HashMap extends AbstractMap
*
* @author Jon Zeppieri
*/
- private final class HashIterator implements Iterator
+ private final class HashIterator<T> implements Iterator<T>
{
/**
* The type of this Iterator: {@link #KEYS}, {@link #VALUES},
@@ -861,7 +865,7 @@ public class HashMap extends AbstractMap
* @throws ConcurrentModificationException if the HashMap was modified
* @throws NoSuchElementException if there is none
*/
- public Object next()
+ public T next()
{
if (knownMod != modCount)
throw new ConcurrentModificationException();
@@ -876,10 +880,10 @@ public class HashMap extends AbstractMap
next = e.next;
last = e;
if (type == VALUES)
- return e.value;
+ return (T) e.value;
if (type == KEYS)
- return e.key;
- return e;
+ return (T) e.key;
+ return (T) e;
}
/**
diff --git a/java/util/HashSet.java b/java/util/HashSet.java
index 681d5bb1b..c08b6db5a 100644
--- a/java/util/HashSet.java
+++ b/java/util/HashSet.java
@@ -76,8 +76,8 @@ import java.io.Serializable;
* @since 1.2
* @status updated to 1.4
*/
-public class HashSet extends AbstractSet
- implements Set, Cloneable, Serializable
+public class HashSet<T> extends AbstractSet<T>
+ implements Set<T>, Cloneable, Serializable
{
/**
* Compatible with JDK 1.2.
@@ -87,7 +87,7 @@ public class HashSet extends AbstractSet
/**
* The HashMap which backs this Set.
*/
- private transient HashMap map;
+ private transient HashMap<T, String> map;
/**
* Construct a new, empty HashSet whose backing HashMap has the default
@@ -133,7 +133,7 @@ public class HashSet extends AbstractSet
* @param c a collection of initial set elements
* @throws NullPointerException if c is null
*/
- public HashSet(Collection c)
+ public HashSet(Collection<? extends T> c)
{
this(Math.max(2 * c.size(), HashMap.DEFAULT_CAPACITY));
addAll(c);
@@ -146,7 +146,7 @@ public class HashSet extends AbstractSet
* @param o the Object to add to this Set
* @return true if the set did not already contain o
*/
- public boolean add(Object o)
+ public boolean add(T o)
{
return map.put(o, "") == null;
}
@@ -167,16 +167,16 @@ public class HashSet extends AbstractSet
*/
public Object clone()
{
- HashSet copy = null;
+ HashSet<T> copy = null;
try
{
- copy = (HashSet) super.clone();
+ copy = (HashSet<T>) super.clone();
}
catch (CloneNotSupportedException x)
{
// Impossible to get here.
}
- copy.map = (HashMap) map.clone();
+ copy.map = (HashMap<T, String>) map.clone();
return copy;
}
@@ -210,7 +210,7 @@ public class HashSet extends AbstractSet
* @return a set iterator
* @see ConcurrentModificationException
*/
- public Iterator iterator()
+ public Iterator<T> iterator()
{
// Avoid creating intermediate keySet() object by using non-public API.
return map.iterator(HashMap.KEYS);
@@ -263,7 +263,7 @@ public class HashSet extends AbstractSet
{
s.defaultWriteObject();
// Avoid creating intermediate keySet() object by using non-public API.
- Iterator it = map.iterator(HashMap.KEYS);
+ Iterator<T> it = map.iterator(HashMap.KEYS);
s.writeInt(map.buckets.length);
s.writeFloat(map.loadFactor);
s.writeInt(map.size);
@@ -288,6 +288,6 @@ public class HashSet extends AbstractSet
map = init(s.readInt(), s.readFloat());
for (int size = s.readInt(); size > 0; size--)
- map.put(s.readObject(), "");
+ map.put((T) s.readObject(), "");
}
}
diff --git a/java/util/Hashtable.java b/java/util/Hashtable.java
index 4c00d18a8..2e265a473 100644
--- a/java/util/Hashtable.java
+++ b/java/util/Hashtable.java
@@ -100,8 +100,8 @@ import java.io.Serializable;
* @since 1.0
* @status updated to 1.4
*/
-public class Hashtable extends Dictionary
- implements Map, Cloneable, Serializable
+public class Hashtable<K, V> extends Dictionary<K, V>
+ implements Map<K, V>, 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.
@@ -139,7 +139,7 @@ public class Hashtable extends Dictionary
* Array containing the actual key-value mappings.
*/
// Package visible for use by nested classes.
- transient HashEntry[] buckets;
+ transient HashEntry<K, V>[] buckets;
/**
* Counts the number of modifications this Hashtable has undergone, used
@@ -157,34 +157,35 @@ public class Hashtable extends Dictionary
/**
* The cache for {@link #keySet()}.
*/
- private transient Set keys;
+ private transient Set<K> keys;
/**
* The cache for {@link #values()}.
*/
- private transient Collection values;
+ private transient Collection<V> values;
/**
* The cache for {@link #entrySet()}.
*/
- private transient Set entries;
+ private transient Set<Map.Entry<K, V>> entries;
/**
* Class to represent an entry in the hash table. Holds a single key-value
* 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 AbstractMap.BasicMapEntry
+ private static final class HashEntry<K, V>
+ extends AbstractMap.SimpleEntry<K, V>
{
/** The next entry in the linked list. */
- HashEntry next;
+ HashEntry<K, V> next;
/**
* Simple constructor.
* @param key the key, already guaranteed non-null
* @param value the value, already guaranteed non-null
*/
- HashEntry(Object key, Object value)
+ HashEntry(K key, V value)
{
super(key, value);
}
@@ -195,7 +196,7 @@ public class Hashtable extends Dictionary
* @return the prior value
* @throws NullPointerException if <code>newVal</code> is null
*/
- public Object setValue(Object newVal)
+ public V setValue(V newVal)
{
if (newVal == null)
throw new NullPointerException();
@@ -226,7 +227,7 @@ public class Hashtable extends Dictionary
* to or from `null'.
* @since 1.2
*/
- public Hashtable(Map m)
+ public Hashtable(Map<? extends K, ? extends V> m)
{
this(Math.max(m.size() * 2, DEFAULT_CAPACITY), DEFAULT_LOAD_FACTOR);
putAll(m);
@@ -263,7 +264,7 @@ public class Hashtable extends Dictionary
if (initialCapacity == 0)
initialCapacity = 1;
- buckets = new HashEntry[initialCapacity];
+ buckets = (HashEntry<K, V>[]) new HashEntry[initialCapacity];
this.loadFactor = loadFactor;
threshold = (int) (initialCapacity * loadFactor);
}
@@ -295,7 +296,7 @@ public class Hashtable extends Dictionary
* @see #elements()
* @see #keySet()
*/
- public Enumeration keys()
+ public Enumeration<K> keys()
{
return new KeyEnumerator();
}
@@ -309,7 +310,7 @@ public class Hashtable extends Dictionary
* @see #keys()
* @see #values()
*/
- public Enumeration elements()
+ public Enumeration<V> elements()
{
return new ValueEnumerator();
}
@@ -333,7 +334,7 @@ public class Hashtable extends Dictionary
for (int i = buckets.length - 1; i >= 0; i--)
{
- HashEntry e = buckets[i];
+ HashEntry<K, V> e = buckets[i];
while (e != null)
{
if (e.value.equals(value))
@@ -341,7 +342,7 @@ public class Hashtable extends Dictionary
e = e.next;
}
}
-
+
return false;
}
@@ -376,7 +377,7 @@ public class Hashtable extends Dictionary
public synchronized boolean containsKey(Object key)
{
int idx = hash(key);
- HashEntry e = buckets[idx];
+ HashEntry<K, V> e = buckets[idx];
while (e != null)
{
if (e.key.equals(key))
@@ -396,10 +397,10 @@ public class Hashtable extends Dictionary
* @see #put(Object, Object)
* @see #containsKey(Object)
*/
- public synchronized Object get(Object key)
+ public synchronized V get(Object key)
{
int idx = hash(key);
- HashEntry e = buckets[idx];
+ HashEntry<K, V> e = buckets[idx];
while (e != null)
{
if (e.key.equals(key))
@@ -421,10 +422,10 @@ public class Hashtable extends Dictionary
* @see #get(Object)
* @see Object#equals(Object)
*/
- public synchronized Object put(Object key, Object value)
+ public synchronized V put(K key, V value)
{
int idx = hash(key);
- HashEntry e = buckets[idx];
+ HashEntry<K, V> e = buckets[idx];
// Check if value is null since it is not permitted.
if (value == null)
@@ -435,7 +436,7 @@ public class Hashtable extends Dictionary
if (e.key.equals(key))
{
// Bypass e.setValue, since we already know value is non-null.
- Object r = e.value;
+ V r = e.value;
e.value = value;
return r;
}
@@ -454,7 +455,7 @@ public class Hashtable extends Dictionary
idx = hash(key);
}
- e = new HashEntry(key, value);
+ e = new HashEntry<K, V>(key, value);
e.next = buckets[idx];
buckets[idx] = e;
@@ -470,11 +471,11 @@ public class Hashtable extends Dictionary
* @param key the key used to locate the value to remove
* @return whatever the key mapped to, if present
*/
- public synchronized Object remove(Object key)
+ public synchronized V remove(Object key)
{
int idx = hash(key);
- HashEntry e = buckets[idx];
- HashEntry last = null;
+ HashEntry<K, V> e = buckets[idx];
+ HashEntry<K, V> last = null;
while (e != null)
{
@@ -502,17 +503,19 @@ public class Hashtable extends Dictionary
* @param m the map to be hashed into this
* @throws NullPointerException if m is null, or contains null keys or values
*/
- public synchronized void putAll(Map m)
+ public synchronized void putAll(Map<? extends K, ? extends V> m)
{
- Iterator itr = m.entrySet().iterator();
+ Map<K,V> addMap;
+
+ addMap = (Map<K,V>) m;
- while (itr.hasNext())
+ for (Map.Entry<K,V> e : addMap.entrySet())
{
- Map.Entry e = (Map.Entry) itr.next();
// Optimize in case the Entry is one of our own.
- if (e instanceof AbstractMap.BasicMapEntry)
+ if (e instanceof AbstractMap.SimpleEntry)
{
- AbstractMap.BasicMapEntry entry = (AbstractMap.BasicMapEntry) e;
+ AbstractMap.SimpleEntry<? extends K, ? extends V> entry
+ = (AbstractMap.SimpleEntry<? extends K, ? extends V>) e;
put(entry.key, entry.value);
}
else
@@ -543,16 +546,16 @@ public class Hashtable extends Dictionary
*/
public synchronized Object clone()
{
- Hashtable copy = null;
+ Hashtable<K, V> copy = null;
try
{
- copy = (Hashtable) super.clone();
+ copy = (Hashtable<K, V>) super.clone();
}
catch (CloneNotSupportedException x)
{
// This is impossible.
}
- copy.buckets = new HashEntry[buckets.length];
+ copy.buckets = (HashEntry<K, V>[]) new HashEntry[buckets.length];
copy.putAllInternal(this);
// Clear the caches.
copy.keys = null;
@@ -576,7 +579,7 @@ public class Hashtable extends Dictionary
// Since we are already synchronized, and entrySet().iterator()
// would repeatedly re-lock/release the monitor, we directly use the
// unsynchronized EntryIterator instead.
- Iterator entries = new EntryIterator();
+ Iterator<Map.Entry<K, V>> entries = new EntryIterator();
StringBuffer r = new StringBuffer("{");
for (int pos = size; pos > 0; pos--)
{
@@ -603,20 +606,20 @@ public class Hashtable extends Dictionary
* @see #entrySet()
* @since 1.2
*/
- public Set keySet()
+ public Set<K> keySet()
{
if (keys == null)
{
// Create a synchronized AbstractSet with custom implementations of
// those methods that can be overridden easily and efficiently.
- Set r = new AbstractSet()
+ Set<K> r = new AbstractSet<K>()
{
public int size()
{
return size;
}
- public Iterator iterator()
+ public Iterator<K> iterator()
{
return new KeyIterator();
}
@@ -640,7 +643,7 @@ public class Hashtable extends Dictionary
};
// We must specify the correct object to synchronize upon, hence the
// use of a non-public API
- keys = new Collections.SynchronizedSet(this, r);
+ keys = new Collections.SynchronizedSet<K>(this, r);
}
return keys;
}
@@ -661,20 +664,20 @@ public class Hashtable extends Dictionary
* @see #entrySet()
* @since 1.2
*/
- public Collection values()
+ public Collection<V> values()
{
if (values == null)
{
// We don't bother overriding many of the optional methods, as doing so
// wouldn't provide any significant performance advantage.
- Collection r = new AbstractCollection()
+ Collection<V> r = new AbstractCollection<V>()
{
public int size()
{
return size;
}
- public Iterator iterator()
+ public Iterator<V> iterator()
{
return new ValueIterator();
}
@@ -686,7 +689,7 @@ public class Hashtable extends Dictionary
};
// We must specify the correct object to synchronize upon, hence the
// use of a non-public API
- values = new Collections.SynchronizedCollection(this, r);
+ values = new Collections.SynchronizedCollection<V>(this, r);
}
return values;
}
@@ -713,20 +716,20 @@ public class Hashtable extends Dictionary
* @see Map.Entry
* @since 1.2
*/
- public Set entrySet()
+ public Set<Map.Entry<K, V>> entrySet()
{
if (entries == null)
{
// Create an AbstractSet with custom implementations of those methods
// that can be overridden easily and efficiently.
- Set r = new AbstractSet()
+ Set<Map.Entry<K, V>> r = new AbstractSet<Map.Entry<K, V>>()
{
public int size()
{
return size;
}
- public Iterator iterator()
+ public Iterator<Map.Entry<K, V>> iterator()
{
return new EntryIterator();
}
@@ -743,7 +746,7 @@ public class Hashtable extends Dictionary
public boolean remove(Object o)
{
- HashEntry e = getEntry(o);
+ HashEntry<K, V> e = getEntry(o);
if (e != null)
{
Hashtable.this.remove(e.key);
@@ -754,7 +757,7 @@ public class Hashtable extends Dictionary
};
// We must specify the correct object to synchronize upon, hence the
// use of a non-public API
- entries = new Collections.SynchronizedSet(this, r);
+ entries = new Collections.SynchronizedSet<Map.Entry<K, V>>(this, r);
}
return entries;
}
@@ -772,7 +775,7 @@ public class Hashtable extends Dictionary
*/
public boolean equals(Object o)
{
- // no need to synchronize, entrySet().equals() does that
+ // no need to synchronize, entrySet().equals() does that.
if (o == this)
return true;
if (!(o instanceof Map))
@@ -793,7 +796,7 @@ public class Hashtable extends Dictionary
// Since we are already synchronized, and entrySet().iterator()
// would repeatedly re-lock/release the monitor, we directly use the
// unsynchronized EntryIterator instead.
- Iterator itr = new EntryIterator();
+ Iterator<Map.Entry<K, V>> itr = new EntryIterator();
int hashcode = 0;
for (int pos = size; pos > 0; pos--)
hashcode += itr.next().hashCode();
@@ -826,16 +829,16 @@ public class Hashtable extends Dictionary
* @see #entrySet()
*/
// Package visible, for use in nested classes.
- HashEntry getEntry(Object o)
+ HashEntry<K, V> getEntry(Object o)
{
if (! (o instanceof Map.Entry))
return null;
- Object key = ((Map.Entry) o).getKey();
+ K key = ((Map.Entry<K, V>) o).getKey();
if (key == null)
return null;
int idx = hash(key);
- HashEntry e = buckets[idx];
+ HashEntry<K, V> e = buckets[idx];
while (e != null)
{
if (e.equals(o))
@@ -852,18 +855,19 @@ public class Hashtable extends Dictionary
*
* @param m the map to initialize this from
*/
- void putAllInternal(Map m)
+ void putAllInternal(Map<? extends K, ? extends V> m)
{
- Iterator itr = m.entrySet().iterator();
+ Map<K,V> addMap;
+
+ addMap = (Map<K,V>) m;
size = 0;
- while (itr.hasNext())
+ for (Map.Entry<K,V> e : addMap.entrySet())
{
size++;
- Map.Entry e = (Map.Entry) itr.next();
- Object key = e.getKey();
+ K key = e.getKey();
int idx = hash(key);
- HashEntry he = new HashEntry(key, e.getValue());
+ HashEntry<K, V> he = new HashEntry<K, V>(key, e.getValue());
he.next = buckets[idx];
buckets[idx] = he;
}
@@ -882,19 +886,19 @@ public class Hashtable extends Dictionary
*/
protected void rehash()
{
- HashEntry[] oldBuckets = buckets;
+ HashEntry<K, V>[] oldBuckets = buckets;
int newcapacity = (buckets.length * 2) + 1;
threshold = (int) (newcapacity * loadFactor);
- buckets = new HashEntry[newcapacity];
+ buckets = (HashEntry<K, V>[]) new HashEntry[newcapacity];
for (int i = oldBuckets.length - 1; i >= 0; i--)
{
- HashEntry e = oldBuckets[i];
+ HashEntry<K, V> e = oldBuckets[i];
while (e != null)
{
int idx = hash(e.key);
- HashEntry dest = buckets[idx];
+ HashEntry<K, V> dest = buckets[idx];
if (dest != null)
{
@@ -911,7 +915,7 @@ public class Hashtable extends Dictionary
buckets[idx] = e;
}
- HashEntry next = e.next;
+ HashEntry<K, V> next = e.next;
e.next = null;
e = next;
}
@@ -939,10 +943,10 @@ public class Hashtable extends Dictionary
// Since we are already synchronized, and entrySet().iterator()
// would repeatedly re-lock/release the monitor, we directly use the
// unsynchronized EntryIterator instead.
- Iterator it = new EntryIterator();
+ Iterator<Map.Entry<K, V>> it = new EntryIterator();
while (it.hasNext())
{
- HashEntry entry = (HashEntry) it.next();
+ HashEntry<K, V> entry = (HashEntry<K, V>) it.next();
s.writeObject(entry.key);
s.writeObject(entry.value);
}
@@ -966,13 +970,13 @@ public class Hashtable extends Dictionary
s.defaultReadObject();
// Read and use capacity.
- buckets = new HashEntry[s.readInt()];
+ buckets = (HashEntry<K, V>[]) new HashEntry[s.readInt()];
int len = s.readInt();
// Read and use key/value pairs.
// TODO: should we be defensive programmers, and check for illegal nulls?
while (--len >= 0)
- put(s.readObject(), s.readObject());
+ put((K) s.readObject(), (V) s.readObject());
}
/**
@@ -987,7 +991,8 @@ public class Hashtable extends Dictionary
* @author Jon Zeppieri
* @author Fridjof Siebert
*/
- private class EntryIterator implements Iterator
+ private class EntryIterator
+ implements Iterator<Entry<K,V>>
{
/**
* The number of modifications to the backing Hashtable that we know about.
@@ -998,16 +1003,16 @@ public class Hashtable extends Dictionary
/** Current index in the physical hash table. */
int idx = buckets.length;
/** The last Entry returned by a next() call. */
- HashEntry last;
+ HashEntry<K, V> last;
/**
* The next entry that should be returned by next(). It is set to something
* if we're iterating through a bucket that contains multiple linked
* entries. It is null if next() needs to find a new bucket.
*/
- HashEntry next;
+ HashEntry<K, V> next;
/**
- * Construct a new EtryIterator
+ * Construct a new EntryIterator
*/
EntryIterator()
{
@@ -1029,14 +1034,14 @@ public class Hashtable extends Dictionary
* @throws ConcurrentModificationException if the hashtable was modified
* @throws NoSuchElementException if there is none
*/
- public Object next()
+ public Map.Entry<K,V> next()
{
if (knownMod != modCount)
throw new ConcurrentModificationException();
if (count == 0)
throw new NoSuchElementException();
count--;
- HashEntry e = next;
+ HashEntry<K, V> e = next;
while (e == null)
if (idx <= 0)
@@ -1070,12 +1075,43 @@ public class Hashtable extends Dictionary
/**
* A class which implements the Iterator interface and is used for
- * iterating over keys in Hashtables.
+ * iterating over keys in Hashtables. This class uses an
+ * <code>EntryIterator</code> to obtain the keys of each entry.
*
* @author Fridtjof Siebert
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
*/
- private class KeyIterator extends EntryIterator
+ private class KeyIterator
+ implements Iterator<K>
{
+
+ /**
+ * This entry iterator is used for most operations. Only
+ * <code>next()</code> gives a different result, by returning just
+ * the key rather than the whole element.
+ */
+ private EntryIterator iterator;
+
+ /**
+ * Construct a new KeyIterator
+ */
+ KeyIterator()
+ {
+ iterator = new EntryIterator();
+ }
+
+
+ /**
+ * Returns true if the entry iterator has more elements.
+ *
+ * @return true if there are more elements
+ * @throws ConcurrentModificationException if the hashtable was modified
+ */
+ public boolean hasNext()
+ {
+ return iterator.hasNext();
+ }
+
/**
* Returns the next element in the Iterator's sequential view.
*
@@ -1084,34 +1120,88 @@ public class Hashtable extends Dictionary
* @throws ConcurrentModificationException if the hashtable was modified
* @throws NoSuchElementException if there is none
*/
- public Object next()
+ public K next()
{
- return ((HashEntry)super.next()).key;
+ return ((HashEntry<K,V>) iterator.next()).key;
}
- } // class KeyIterator
-
-
+ /**
+ * Removes the last element used by the <code>next()</code> method
+ * using the entry iterator.
+ *
+ * @throws ConcurrentModificationException if the hashtable was modified
+ * @throws IllegalStateException if called when there is no last element
+ */
+ public void remove()
+ {
+ iterator.remove();
+ }
+ } // class KeyIterator
+
/**
* A class which implements the Iterator interface and is used for
- * iterating over values in Hashtables.
+ * iterating over values in Hashtables. This class uses an
+ * <code>EntryIterator</code> to obtain the values of each entry.
*
* @author Fridtjof Siebert
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
*/
- private class ValueIterator extends EntryIterator
+ private class ValueIterator
+ implements Iterator<V>
{
+
/**
- * Returns the next element in the Iterator's sequential view.
+ * This entry iterator is used for most operations. Only
+ * <code>next()</code> gives a different result, by returning just
+ * the value rather than the whole element.
+ */
+ private EntryIterator iterator;
+
+ /**
+ * Construct a new KeyIterator
+ */
+ ValueIterator()
+ {
+ iterator = new EntryIterator();
+ }
+
+
+ /**
+ * Returns true if the entry iterator has more elements.
*
- * @return the next element
+ * @return true if there are more elements
+ * @throws ConcurrentModificationException if the hashtable was modified
+ */
+ public boolean hasNext()
+ {
+ return iterator.hasNext();
+ }
+
+ /**
+ * Returns the value of the next element in the iterator's sequential view.
+ *
+ * @return the next value
*
* @throws ConcurrentModificationException if the hashtable was modified
* @throws NoSuchElementException if there is none
*/
- public Object next()
+ public V next()
+ {
+ return ((HashEntry<K,V>) iterator.next()).value;
+ }
+
+ /**
+ * Removes the last element used by the <code>next()</code> method
+ * using the entry iterator.
+ *
+ * @throws ConcurrentModificationException if the hashtable was modified
+ * @throws IllegalStateException if called when there is no last element
+ */
+ public void remove()
{
- return ((HashEntry)super.next()).value;
+ iterator.remove();
}
+
} // class ValueIterator
/**
@@ -1128,7 +1218,8 @@ public class Hashtable extends Dictionary
* @author Jon Zeppieri
* @author Fridjof Siebert
*/
- private class EntryEnumerator implements Enumeration
+ private class EntryEnumerator
+ implements Enumeration<Entry<K,V>>
{
/** The number of elements remaining to be returned by next(). */
int count = size;
@@ -1139,7 +1230,7 @@ public class Hashtable extends Dictionary
* set if we are iterating through a bucket with multiple entries, or null
* if we must look in the next bucket.
*/
- HashEntry next;
+ HashEntry<K, V> next;
/**
* Construct the enumeration.
@@ -1163,12 +1254,12 @@ public class Hashtable extends Dictionary
* @return the next element
* @throws NoSuchElementException if there is none.
*/
- public Object nextElement()
+ public Map.Entry<K,V> nextElement()
{
if (count == 0)
throw new NoSuchElementException("Hashtable Enumerator");
count--;
- HashEntry e = next;
+ HashEntry<K, V> e = next;
while (e == null)
if (idx <= 0)
@@ -1195,18 +1286,47 @@ public class Hashtable extends Dictionary
*
* @author Jon Zeppieri
* @author Fridjof Siebert
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
*/
- private final class KeyEnumerator extends EntryEnumerator
+ private final class KeyEnumerator
+ implements Enumeration<K>
{
/**
+ * This entry enumerator is used for most operations. Only
+ * <code>nextElement()</code> gives a different result, by returning just
+ * the key rather than the whole element.
+ */
+ private EntryEnumerator enumerator;
+
+ /**
+ * Construct a new KeyEnumerator
+ */
+ KeyEnumerator()
+ {
+ enumerator = new EntryEnumerator();
+ }
+
+
+ /**
+ * Returns true if the entry enumerator has more elements.
+ *
+ * @return true if there are more elements
+ * @throws ConcurrentModificationException if the hashtable was modified
+ */
+ public boolean hasMoreElements()
+ {
+ return enumerator.hasMoreElements();
+ }
+
+ /**
* Returns the next element.
* @return the next element
* @throws NoSuchElementException if there is none.
*/
- public Object nextElement()
+ public K nextElement()
{
- HashEntry entry = (HashEntry) super.nextElement();
- Object retVal = null;
+ HashEntry<K,V> entry = (HashEntry<K,V>) enumerator.nextElement();
+ K retVal = null;
if (entry != null)
retVal = entry.key;
return retVal;
@@ -1227,18 +1347,47 @@ public class Hashtable extends Dictionary
*
* @author Jon Zeppieri
* @author Fridjof Siebert
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
*/
- private final class ValueEnumerator extends EntryEnumerator
+ private final class ValueEnumerator
+ implements Enumeration<V>
{
/**
+ * This entry enumerator is used for most operations. Only
+ * <code>nextElement()</code> gives a different result, by returning just
+ * the value rather than the whole element.
+ */
+ private EntryEnumerator enumerator;
+
+ /**
+ * Construct a new ValueEnumerator
+ */
+ ValueEnumerator()
+ {
+ enumerator = new EntryEnumerator();
+ }
+
+
+ /**
+ * Returns true if the entry enumerator has more elements.
+ *
+ * @return true if there are more elements
+ * @throws ConcurrentModificationException if the hashtable was modified
+ */
+ public boolean hasMoreElements()
+ {
+ return enumerator.hasMoreElements();
+ }
+
+ /**
* Returns the next element.
* @return the next element
* @throws NoSuchElementException if there is none.
*/
- public Object nextElement()
+ public V nextElement()
{
- HashEntry entry = (HashEntry) super.nextElement();
- Object retVal = null;
+ HashEntry<K,V> entry = (HashEntry<K,V>) enumerator.nextElement();
+ V retVal = null;
if (entry != null)
retVal = entry.value;
return retVal;
diff --git a/java/util/IdentityHashMap.java b/java/util/IdentityHashMap.java
index d1fe0625d..8dead96c1 100644
--- a/java/util/IdentityHashMap.java
+++ b/java/util/IdentityHashMap.java
@@ -90,8 +90,8 @@ import java.io.Serializable;
* @since 1.4
* @status updated to 1.4
*/
-public class IdentityHashMap extends AbstractMap
- implements Map, Serializable, Cloneable
+public class IdentityHashMap<K,V> extends AbstractMap<K,V>
+ implements Map<K,V>, Serializable, Cloneable
{
/** The default capacity. */
private static final int DEFAULT_CAPACITY = 21;
@@ -131,7 +131,7 @@ public class IdentityHashMap extends AbstractMap
/**
* The cache for {@link #entrySet()}.
*/
- private transient Set entries;
+ private transient Set<Map.Entry<K,V>> entries;
/**
* The threshold for rehashing, which is 75% of (table.length / 2).
@@ -173,7 +173,7 @@ public class IdentityHashMap extends AbstractMap
* @param m The map whose elements are to be put in this map
* @throws NullPointerException if m is null
*/
- public IdentityHashMap(Map m)
+ public IdentityHashMap(Map<? extends K, ? extends V> m)
{
this(Math.max(m.size() << 1, DEFAULT_CAPACITY));
putAll(m);
@@ -272,19 +272,19 @@ public class IdentityHashMap extends AbstractMap
* @see #values()
* @see Map.Entry
*/
- public Set entrySet()
+ public Set<Map.Entry<K,V>> entrySet()
{
if (entries == null)
- entries = new AbstractSet()
+ entries = new AbstractSet<Map.Entry<K,V>>()
{
public int size()
{
return size;
}
- public Iterator iterator()
+ public Iterator<Map.Entry<K,V>> iterator()
{
- return new IdentityIterator(ENTRIES);
+ return new IdentityIterator<Map.Entry<K,V>>(ENTRIES);
}
public void clear()
@@ -357,11 +357,11 @@ public class IdentityHashMap extends AbstractMap
* @see #put(Object, Object)
* @see #containsKey(Object)
*/
- public Object get(Object key)
+ public V get(Object key)
{
key = xform(key);
int h = hash(key);
- return table[h] == key ? unxform(table[h + 1]) : null;
+ return (V) (table[h] == key ? unxform(table[h + 1]) : null);
}
/**
@@ -415,19 +415,19 @@ public class IdentityHashMap extends AbstractMap
* @see #values()
* @see #entrySet()
*/
- public Set keySet()
+ public Set<K> keySet()
{
if (keys == null)
- keys = new AbstractSet()
+ keys = new AbstractSet<K>()
{
public int size()
{
return size;
}
- public Iterator iterator()
+ public Iterator<K> iterator()
{
- return new IdentityIterator(KEYS);
+ return new IdentityIterator<K>(KEYS);
}
public void clear()
@@ -484,16 +484,16 @@ public class IdentityHashMap extends AbstractMap
* @return the prior mapping of the key, or null if there was none
* @see #get(Object)
*/
- public Object put(Object key, Object value)
+ public V put(K key, V value)
{
- key = xform(key);
- value = xform(value);
+ key = (K) xform(key);
+ value = (V) xform(value);
// We don't want to rehash if we're overwriting an existing slot.
int h = hash(key);
if (table[h] == key)
{
- Object r = unxform(table[h + 1]);
+ V r = (V) unxform(table[h + 1]);
table[h + 1] = value;
return r;
}
@@ -510,7 +510,7 @@ public class IdentityHashMap extends AbstractMap
for (int i = old.length - 2; i >= 0; i -= 2)
{
- Object oldkey = old[i];
+ K oldkey = (K) old[i];
if (oldkey != null)
{
h = hash(oldkey);
@@ -541,7 +541,7 @@ public class IdentityHashMap extends AbstractMap
* @param m the map to copy
* @throws NullPointerException if m is null
*/
- public void putAll(Map m)
+ public void putAll(Map<? extends K, ? extends V> m)
{
// Why did Sun specify this one? The superclass does the right thing.
super.putAll(m);
@@ -595,7 +595,7 @@ public class IdentityHashMap extends AbstractMap
* @param key the key used to locate the value to remove
* @return whatever the key mapped to, if present
*/
- public Object remove(Object key)
+ public V remove(Object key)
{
key = xform(key);
int h = hash(key);
@@ -605,7 +605,7 @@ public class IdentityHashMap extends AbstractMap
size--;
Object r = unxform(table[h + 1]);
removeAtIndex(h);
- return r;
+ return (V) r;
}
return null;
}
@@ -637,19 +637,19 @@ public class IdentityHashMap extends AbstractMap
* @see #keySet()
* @see #entrySet()
*/
- public Collection values()
+ public Collection<V> values()
{
if (values == null)
- values = new AbstractCollection()
+ values = new AbstractCollection<V>()
{
public int size()
{
return size;
}
- public Iterator iterator()
+ public Iterator<V> iterator()
{
- return new IdentityIterator(VALUES);
+ return new IdentityIterator<V>(VALUES);
}
public void clear()
@@ -736,7 +736,7 @@ public class IdentityHashMap extends AbstractMap
* @author Tom Tromey (tromey@redhat.com)
* @author Eric Blake (ebb9@email.byu.edu)
*/
- private class IdentityIterator implements Iterator
+ private class IdentityIterator<I> implements Iterator<I>
{
/**
* The type of this Iterator: {@link #KEYS}, {@link #VALUES},
@@ -774,7 +774,7 @@ public class IdentityHashMap extends AbstractMap
* @throws ConcurrentModificationException if the Map was modified
* @throws NoSuchElementException if there is none
*/
- public Object next()
+ public I next()
{
if (knownMod != modCount)
throw new ConcurrentModificationException();
@@ -789,10 +789,10 @@ public class IdentityHashMap extends AbstractMap
key = table[loc];
}
while (key == null);
-
- return type == KEYS ? unxform(key)
- : (type == VALUES ? unxform(table[loc + 1])
- : new IdentityEntry(loc));
+
+ return (I) (type == KEYS ? unxform(key)
+ : (type == VALUES ? unxform(table[loc + 1])
+ : new IdentityEntry(loc)));
}
/**
@@ -825,7 +825,7 @@ public class IdentityHashMap extends AbstractMap
*
* @author Eric Blake (ebb9@email.byu.edu)
*/
- private final class IdentityEntry implements Map.Entry
+ private final class IdentityEntry<EK,EV> implements Map.Entry<EK,EV>
{
/** The location of this entry. */
final int loc;
@@ -870,11 +870,11 @@ public class IdentityHashMap extends AbstractMap
* @throws ConcurrentModificationException if the entry was invalidated
* by modifying the Map or calling Iterator.remove()
*/
- public Object getKey()
+ public EK getKey()
{
if (knownMod != modCount)
throw new ConcurrentModificationException();
- return unxform(table[loc]);
+ return (EK) unxform(table[loc]);
}
/**
@@ -884,11 +884,11 @@ public class IdentityHashMap extends AbstractMap
* @throws ConcurrentModificationException if the entry was invalidated
* by modifying the Map or calling Iterator.remove()
*/
- public Object getValue()
+ public EV getValue()
{
if (knownMod != modCount)
throw new ConcurrentModificationException();
- return unxform(table[loc + 1]);
+ return (EV) unxform(table[loc + 1]);
}
/**
@@ -916,11 +916,11 @@ public class IdentityHashMap extends AbstractMap
* @throws ConcurrentModificationException if the entry was invalidated
* by modifying the Map or calling Iterator.remove()
*/
- public Object setValue(Object value)
+ public EV setValue(EV value)
{
if (knownMod != modCount)
throw new ConcurrentModificationException();
- Object r = unxform(table[loc + 1]);
+ EV r = (EV) unxform(table[loc + 1]);
table[loc + 1] = xform(value);
return r;
}
@@ -960,7 +960,7 @@ public class IdentityHashMap extends AbstractMap
table = new Object[Math.max(num << 1, DEFAULT_CAPACITY) << 1];
// Read key/value pairs.
while (--num >= 0)
- put(s.readObject(), s.readObject());
+ put((K) s.readObject(), (V) s.readObject());
}
/**
diff --git a/java/util/IllegalFormatConversionException.java b/java/util/IllegalFormatConversionException.java
index 2f981f26e..d59c0a4b1 100644
--- a/java/util/IllegalFormatConversionException.java
+++ b/java/util/IllegalFormatConversionException.java
@@ -67,7 +67,7 @@ public class IllegalFormatConversionException
* @serial the mismatching argument type.
*/
// Note: name fixed by serialization.
- Class arg;
+ Class<?> arg;
/**
* Constructs a new <code>IllegalFormatConversionException</code>
@@ -78,7 +78,7 @@ public class IllegalFormatConversionException
* @param arg the type which doesn't match the conversion character.
* @throws NullPointerException if <code>arg</code> is null.
*/
- public IllegalFormatConversionException(char c, Class arg)
+ public IllegalFormatConversionException(char c, Class<?> arg)
{
super("The type, " + arg + ", is invalid for the conversion character, " +
c + ".");
@@ -103,7 +103,7 @@ public class IllegalFormatConversionException
*
* @return the type of the mismatched argument.
*/
- public Class getArgumentClass()
+ public Class<?> getArgumentClass()
{
return arg;
}
diff --git a/java/util/Iterator.java b/java/util/Iterator.java
index 31ecff8a2..41111a52d 100644
--- a/java/util/Iterator.java
+++ b/java/util/Iterator.java
@@ -1,5 +1,5 @@
/* Iterator.java -- Interface for iterating over collections
- Copyright (C) 1998, 2001, 2005 Free Software Foundation, Inc.
+ Copyright (C) 1998, 2001, 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -54,7 +54,7 @@ package java.util;
* @since 1.2
* @status updated to 1.4
*/
-public interface Iterator
+public interface Iterator<E>
{
/**
* Tests whether there are elements remaining in the collection. In other
@@ -70,7 +70,7 @@ public interface Iterator
* @return the next element in the collection
* @throws NoSuchElementException if there are no more elements
*/
- Object next();
+ E next();
/**
* Remove from the underlying collection the last element returned by next
diff --git a/java/util/LinkedHashMap.java b/java/util/LinkedHashMap.java
index 2b002b272..6ec06a949 100644
--- a/java/util/LinkedHashMap.java
+++ b/java/util/LinkedHashMap.java
@@ -97,6 +97,8 @@ package java.util;
* non-deterministic behavior.
*
* @author Eric Blake (ebb9@email.byu.edu)
+ * @author Tom Tromey (tromey@redhat.com)
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
* @see Object#hashCode()
* @see Collection
* @see Map
@@ -106,7 +108,7 @@ package java.util;
* @since 1.4
* @status updated to 1.4
*/
-public class LinkedHashMap extends HashMap
+public class LinkedHashMap<K,V> extends HashMap<K,V>
{
/**
* Compatible with JDK 1.4.
@@ -130,16 +132,16 @@ public class LinkedHashMap extends HashMap
* Class to represent an entry in the hash table. Holds a single key-value
* pair and the doubly-linked insertion order list.
*/
- class LinkedHashEntry extends HashEntry
+ class LinkedHashEntry<K,V> extends HashEntry<K,V>
{
/**
* The predecessor in the iteration list. If this entry is the root
* (eldest), pred points to the newest entry.
*/
- LinkedHashEntry pred;
+ LinkedHashEntry<K,V> pred;
/** The successor in the iteration list, null if this is the newest. */
- LinkedHashEntry succ;
+ LinkedHashEntry<K,V> succ;
/**
* Simple constructor.
@@ -147,7 +149,7 @@ public class LinkedHashMap extends HashMap
* @param key the key
* @param value the value
*/
- LinkedHashEntry(Object key, Object value)
+ LinkedHashEntry(K key, V value)
{
super(key, value);
if (root == null)
@@ -186,7 +188,7 @@ public class LinkedHashMap extends HashMap
succ = null;
pred = root.pred;
pred.succ = this;
- root.pred = this;
+ root.pred = this;
}
}
}
@@ -197,7 +199,7 @@ public class LinkedHashMap extends HashMap
*
* @return the value of this key as it is removed
*/
- Object cleanup()
+ V cleanup()
{
if (this == root)
{
@@ -243,7 +245,7 @@ public class LinkedHashMap extends HashMap
* are not cloned in this constructor.</b>
* @throws NullPointerException if m is null
*/
- public LinkedHashMap(Map m)
+ public LinkedHashMap(Map<? extends K, ? extends V> m)
{
super(m);
accessOrder = false;
@@ -335,10 +337,10 @@ public class LinkedHashMap extends HashMap
* @see #put(Object, Object)
* @see #containsKey(Object)
*/
- public Object get(Object key)
+ public V get(Object key)
{
int idx = hash(key);
- HashEntry e = buckets[idx];
+ HashEntry<K,V> e = buckets[idx];
while (e != null)
{
if (equals(key, e.key))
@@ -390,7 +392,7 @@ public class LinkedHashMap extends HashMap
* earliest element inserted.
* @return true if <code>eldest</code> should be removed
*/
- protected boolean removeEldestEntry(Map.Entry eldest)
+ protected boolean removeEldestEntry(Map.Entry<K,V> eldest)
{
return false;
}
@@ -407,7 +409,7 @@ public class LinkedHashMap extends HashMap
* @see #removeEldestEntry(Map.Entry)
* @see LinkedHashEntry#LinkedHashEntry(Object, Object)
*/
- void addEntry(Object key, Object value, int idx, boolean callRemove)
+ void addEntry(K key, V value, int idx, boolean callRemove)
{
LinkedHashEntry e = new LinkedHashEntry(key, value);
e.next = buckets[idx];
diff --git a/java/util/LinkedHashSet.java b/java/util/LinkedHashSet.java
index 6c68195c3..a0b32f349 100644
--- a/java/util/LinkedHashSet.java
+++ b/java/util/LinkedHashSet.java
@@ -1,6 +1,6 @@
/* LinkedHashSet.java -- a set backed by a LinkedHashMap, for linked
list traversal.
- Copyright (C) 2001, 2005 Free Software Foundation, Inc.
+ Copyright (C) 2001, 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -88,8 +88,8 @@ import java.io.Serializable;
* @since 1.4
* @status updated to 1.4
*/
-public class LinkedHashSet extends HashSet
- implements Set, Cloneable, Serializable
+public class LinkedHashSet<T> extends HashSet<T>
+ implements Set<T>, Cloneable, Serializable
{
/**
* Compatible with JDK 1.4.
@@ -140,7 +140,7 @@ public class LinkedHashSet extends HashSet
* @param c a collection of initial set elements
* @throws NullPointerException if c is null
*/
- public LinkedHashSet(Collection c)
+ public LinkedHashSet(Collection<? extends T> c)
{
super(c);
}
@@ -152,9 +152,8 @@ public class LinkedHashSet extends HashSet
* @param load the initial load factor
* @return the backing HashMap
*/
- HashMap init(int capacity, float load)
+ HashMap<T, String> init(int capacity, float load)
{
- return new LinkedHashMap(capacity, load);
+ return new LinkedHashMap<T, String>(capacity, load);
}
-
}
diff --git a/java/util/LinkedList.java b/java/util/LinkedList.java
index e77ae536b..2d78573d0 100644
--- a/java/util/LinkedList.java
+++ b/java/util/LinkedList.java
@@ -71,8 +71,8 @@ import java.lang.reflect.Array;
* @since 1.2
* @status missing javadoc, but complete to 1.4
*/
-public class LinkedList extends AbstractSequentialList
- implements List, Cloneable, Serializable
+public class LinkedList<T> extends AbstractSequentialList<T>
+ implements List<T>, Queue<T>, Cloneable, Serializable
{
/**
* Compatible with JDK 1.2.
@@ -82,12 +82,12 @@ public class LinkedList extends AbstractSequentialList
/**
* The first element in the list.
*/
- transient Entry first;
+ transient Entry<T> first;
/**
* The last element in the list.
*/
- transient Entry last;
+ transient Entry<T> last;
/**
* The current length of the list.
@@ -97,22 +97,22 @@ public class LinkedList extends AbstractSequentialList
/**
* Class to represent an entry in the list. Holds a single element.
*/
- private static final class Entry
+ private static final class Entry<T>
{
/** The element in the list. */
- Object data;
+ T data;
/** The next list entry, null if this is last. */
- Entry next;
+ Entry<T> next;
/** The previous list entry, null if this is first. */
- Entry previous;
+ Entry<T> previous;
/**
* Construct an entry.
* @param data the list element
*/
- Entry(Object data)
+ Entry(T data)
{
this.data = data;
}
@@ -131,9 +131,9 @@ public class LinkedList extends AbstractSequentialList
* @return the entry at position n
*/
// Package visible for use in nested classes.
- Entry getEntry(int n)
+ Entry<T> getEntry(int n)
{
- Entry e;
+ Entry<T> e;
if (n < size / 2)
{
e = first;
@@ -158,7 +158,7 @@ public class LinkedList extends AbstractSequentialList
* @param e the entry to remove
*/
// Package visible for use in nested classes.
- void removeEntry(Entry e)
+ void removeEntry(Entry<T> e)
{
modCount++;
size--;
@@ -224,7 +224,7 @@ public class LinkedList extends AbstractSequentialList
* @param c the collection to populate this list from
* @throws NullPointerException if c is null
*/
- public LinkedList(Collection c)
+ public LinkedList(Collection<? extends T> c)
{
addAll(c);
}
@@ -235,7 +235,7 @@ public class LinkedList extends AbstractSequentialList
* @return the first list element
* @throws NoSuchElementException if the list is empty
*/
- public Object getFirst()
+ public T getFirst()
{
if (size == 0)
throw new NoSuchElementException();
@@ -248,7 +248,7 @@ public class LinkedList extends AbstractSequentialList
* @return the last list element
* @throws NoSuchElementException if the list is empty
*/
- public Object getLast()
+ public T getLast()
{
if (size == 0)
throw new NoSuchElementException();
@@ -261,13 +261,13 @@ public class LinkedList extends AbstractSequentialList
* @return the former first element in the list
* @throws NoSuchElementException if the list is empty
*/
- public Object removeFirst()
+ public T removeFirst()
{
if (size == 0)
throw new NoSuchElementException();
modCount++;
size--;
- Object r = first.data;
+ T r = first.data;
if (first.next != null)
first.next.previous = null;
@@ -285,13 +285,13 @@ public class LinkedList extends AbstractSequentialList
* @return the former last element in the list
* @throws NoSuchElementException if the list is empty
*/
- public Object removeLast()
+ public T removeLast()
{
if (size == 0)
throw new NoSuchElementException();
modCount++;
size--;
- Object r = last.data;
+ T r = last.data;
if (last.previous != null)
last.previous.next = null;
@@ -308,9 +308,9 @@ public class LinkedList extends AbstractSequentialList
*
* @param o the element to insert
*/
- public void addFirst(Object o)
+ public void addFirst(T o)
{
- Entry e = new Entry(o);
+ Entry<T> e = new Entry(o);
modCount++;
if (size == 0)
@@ -329,9 +329,9 @@ public class LinkedList extends AbstractSequentialList
*
* @param o the element to insert
*/
- public void addLast(Object o)
+ public void addLast(T o)
{
- addLastEntry(new Entry(o));
+ addLastEntry(new Entry<T>(o));
}
/**
@@ -339,7 +339,7 @@ public class LinkedList extends AbstractSequentialList
*
* @param e the entry to add
*/
- private void addLastEntry(Entry e)
+ private void addLastEntry(Entry<T> e)
{
modCount++;
if (size == 0)
@@ -362,7 +362,7 @@ public class LinkedList extends AbstractSequentialList
*/
public boolean contains(Object o)
{
- Entry e = first;
+ Entry<T> e = first;
while (e != null)
{
if (equals(o, e.data))
@@ -388,9 +388,9 @@ public class LinkedList extends AbstractSequentialList
* @param o the entry to add
* @return true, as it always succeeds
*/
- public boolean add(Object o)
+ public boolean add(T o)
{
- addLastEntry(new Entry(o));
+ addLastEntry(new Entry<T>(o));
return true;
}
@@ -403,7 +403,7 @@ public class LinkedList extends AbstractSequentialList
*/
public boolean remove(Object o)
{
- Entry e = first;
+ Entry<T> e = first;
while (e != null)
{
if (equals(o, e.data))
@@ -425,7 +425,7 @@ public class LinkedList extends AbstractSequentialList
* @return true if the list was modified
* @throws NullPointerException if c is null
*/
- public boolean addAll(Collection c)
+ public boolean addAll(Collection<? extends T> c)
{
return addAll(size, c);
}
@@ -440,7 +440,7 @@ public class LinkedList extends AbstractSequentialList
* @throws NullPointerException if c is null
* @throws IndexOutOfBoundsException if index &lt; 0 || index &gt; size()
*/
- public boolean addAll(int index, Collection c)
+ public boolean addAll(int index, Collection<? extends T> c)
{
checkBoundsInclusive(index);
int csize = c.size();
@@ -448,13 +448,13 @@ public class LinkedList extends AbstractSequentialList
if (csize == 0)
return false;
- Iterator itr = c.iterator();
+ Iterator<? extends T> itr = c.iterator();
// Get the entries just before and after index. If index is at the start
// of the list, BEFORE is null. If index is at the end of the list, AFTER
// is null. If the list is empty, both are null.
- Entry after = null;
- Entry before = null;
+ Entry<T> after = null;
+ Entry<T> before = null;
if (index != size)
{
after = getEntry(index);
@@ -467,15 +467,15 @@ public class LinkedList extends AbstractSequentialList
// to the first entry, in order to deal with the case where (c == this).
// [Actually, we don't have to handle this case to fufill the
// contract for addAll(), but Sun's implementation appears to.]
- Entry e = new Entry(itr.next());
+ Entry<T> e = new Entry<T>(itr.next());
e.previous = before;
- Entry prev = e;
- Entry firstNew = e;
+ Entry<T> prev = e;
+ Entry<T> firstNew = e;
// Create and link all the remaining entries.
for (int pos = 1; pos < csize; pos++)
{
- e = new Entry(itr.next());
+ e = new Entry<T>(itr.next());
e.previous = prev;
prev.next = e;
prev = e;
@@ -518,7 +518,7 @@ public class LinkedList extends AbstractSequentialList
* @return the element at index
* @throws IndexOutOfBoundsException if index &lt; 0 || index &gt;= size()
*/
- public Object get(int index)
+ public T get(int index)
{
checkBoundsExclusive(index);
return getEntry(index).data;
@@ -532,11 +532,11 @@ public class LinkedList extends AbstractSequentialList
* @return the prior element
* @throws IndexOutOfBoundsException if index &lt; 0 || index &gt;= size()
*/
- public Object set(int index, Object o)
+ public T set(int index, T o)
{
checkBoundsExclusive(index);
- Entry e = getEntry(index);
- Object old = e.data;
+ Entry<T> e = getEntry(index);
+ T old = e.data;
e.data = o;
return old;
}
@@ -548,15 +548,15 @@ public class LinkedList extends AbstractSequentialList
* @param o the element to insert
* @throws IndexOutOfBoundsException if index &lt; 0 || index &gt; size()
*/
- public void add(int index, Object o)
+ public void add(int index, T o)
{
checkBoundsInclusive(index);
- Entry e = new Entry(o);
+ Entry<T> e = new Entry<T>(o);
if (index < size)
{
modCount++;
- Entry after = getEntry(index);
+ Entry<T> after = getEntry(index);
e.next = after;
e.previous = after.previous;
if (after.previous == null)
@@ -577,10 +577,10 @@ public class LinkedList extends AbstractSequentialList
* @return the removed element
* @throws IndexOutOfBoundsException if index &lt; 0 || index &gt; size()
*/
- public Object remove(int index)
+ public T remove(int index)
{
checkBoundsExclusive(index);
- Entry e = getEntry(index);
+ Entry<T> e = getEntry(index);
removeEntry(e);
return e.data;
}
@@ -594,7 +594,7 @@ public class LinkedList extends AbstractSequentialList
public int indexOf(Object o)
{
int index = 0;
- Entry e = first;
+ Entry<T> e = first;
while (e != null)
{
if (equals(o, e.data))
@@ -614,7 +614,7 @@ public class LinkedList extends AbstractSequentialList
public int lastIndexOf(Object o)
{
int index = size - 1;
- Entry e = last;
+ Entry<T> e = last;
while (e != null)
{
if (equals(o, e.data))
@@ -634,10 +634,10 @@ public class LinkedList extends AbstractSequentialList
* next(), or size() to be initially positioned at the end of the list
* @throws IndexOutOfBoundsException if index &lt; 0 || index &gt; size()
*/
- public ListIterator listIterator(int index)
+ public ListIterator<T> listIterator(int index)
{
checkBoundsInclusive(index);
- return new LinkedListItr(index);
+ return new LinkedListItr<T>(index);
}
/**
@@ -648,10 +648,10 @@ public class LinkedList extends AbstractSequentialList
*/
public Object clone()
{
- LinkedList copy = null;
+ LinkedList<T> copy = null;
try
{
- copy = (LinkedList) super.clone();
+ copy = (LinkedList<T>) super.clone();
}
catch (CloneNotSupportedException ex)
{
@@ -669,7 +669,7 @@ public class LinkedList extends AbstractSequentialList
public Object[] toArray()
{
Object[] array = new Object[size];
- Entry e = first;
+ Entry<T> e = first;
for (int i = 0; i < size; i++)
{
array[i] = e.data;
@@ -692,22 +692,66 @@ public class LinkedList extends AbstractSequentialList
* an element in this list
* @throws NullPointerException if a is null
*/
- public Object[] toArray(Object[] a)
+ public <S> S[] toArray(S[] a)
{
if (a.length < size)
- a = (Object[]) Array.newInstance(a.getClass().getComponentType(), size);
+ a = (S[]) Array.newInstance(a.getClass().getComponentType(), size);
else if (a.length > size)
a[size] = null;
- Entry e = first;
+ Entry<T> e = first;
for (int i = 0; i < size; i++)
{
- a[i] = e.data;
+ a[i] = (S) e.data;
e = e.next;
}
return a;
}
/**
+ * @since 1.5
+ */
+ public boolean offer(T value)
+ {
+ return add(value);
+ }
+
+ /**
+ * @since 1.5
+ */
+ public T element()
+ {
+ return getFirst();
+ }
+
+ /**
+ * @since 1.5
+ */
+ public T peek()
+ {
+ if (size == 0)
+ return null;
+ return getFirst();
+ }
+
+ /**
+ * @since 1.5
+ */
+ public T poll()
+ {
+ if (size == 0)
+ return null;
+ return removeFirst();
+ }
+
+ /**
+ * @since 1.5
+ */
+ public T remove()
+ {
+ return removeFirst();
+ }
+
+ /**
* Serializes this object to the given stream.
*
* @param s the stream to write to
@@ -719,7 +763,7 @@ public class LinkedList extends AbstractSequentialList
{
s.defaultWriteObject();
s.writeInt(size);
- Entry e = first;
+ Entry<T> e = first;
while (e != null)
{
s.writeObject(e.data);
@@ -742,7 +786,7 @@ public class LinkedList extends AbstractSequentialList
s.defaultReadObject();
int i = s.readInt();
while (--i >= 0)
- addLastEntry(new Entry(s.readObject()));
+ addLastEntry(new Entry<T>((T) s.readObject()));
}
/**
@@ -752,19 +796,20 @@ public class LinkedList extends AbstractSequentialList
* @author Original author unknown
* @author Eric Blake (ebb9@email.byu.edu)
*/
- private final class LinkedListItr implements ListIterator
+ private final class LinkedListItr<I>
+ implements ListIterator<I>
{
/** Number of modifications we know about. */
private int knownMod = modCount;
/** Entry that will be returned by next(). */
- private Entry next;
+ private Entry<I> next;
/** Entry that will be returned by previous(). */
- private Entry previous;
+ private Entry<I> previous;
/** Entry that will be affected by remove() or set(). */
- private Entry lastReturned;
+ private Entry<I> lastReturned;
/** Index of `next'. */
private int position;
@@ -779,11 +824,11 @@ public class LinkedList extends AbstractSequentialList
if (index == size)
{
next = null;
- previous = last;
+ previous = (Entry<I>) last;
}
else
{
- next = getEntry(index);
+ next = (Entry<I>) getEntry(index);
previous = next.previous;
}
position = index;
@@ -847,7 +892,7 @@ public class LinkedList extends AbstractSequentialList
* @throws ConcurrentModificationException if the list was modified
* @throws NoSuchElementException if there is no next
*/
- public Object next()
+ public I next()
{
checkMod();
if (next == null)
@@ -865,7 +910,7 @@ public class LinkedList extends AbstractSequentialList
* @throws ConcurrentModificationException if the list was modified
* @throws NoSuchElementException if there is no previous
*/
- public Object previous()
+ public I previous()
{
checkMod();
if (previous == null)
@@ -895,7 +940,7 @@ public class LinkedList extends AbstractSequentialList
next = lastReturned.next;
previous = lastReturned.previous;
- removeEntry(lastReturned);
+ removeEntry((Entry<T>) lastReturned);
knownMod++;
lastReturned = null;
@@ -907,26 +952,26 @@ public class LinkedList extends AbstractSequentialList
* @param o the element to add
* @throws ConcurrentModificationException if the list was modified
*/
- public void add(Object o)
+ public void add(I o)
{
checkMod();
modCount++;
knownMod++;
size++;
position++;
- Entry e = new Entry(o);
+ Entry<I> e = new Entry<I>(o);
e.previous = previous;
e.next = next;
if (previous != null)
previous.next = e;
else
- first = e;
+ first = (Entry<T>) e;
if (next != null)
next.previous = e;
else
- last = e;
+ last = (Entry<T>) e;
previous = e;
lastReturned = null;
@@ -939,7 +984,7 @@ public class LinkedList extends AbstractSequentialList
* @throws ConcurrentModificationException if the list was modified
* @throws IllegalStateException if there was no last element
*/
- public void set(Object o)
+ public void set(I o)
{
checkMod();
if (lastReturned == null)
diff --git a/java/util/List.java b/java/util/List.java
index 445811292..0a1c4098c 100644
--- a/java/util/List.java
+++ b/java/util/List.java
@@ -1,5 +1,5 @@
/* List.java -- An ordered collection which allows indexed access
- Copyright (C) 1998, 2001, 2005 Free Software Foundation, Inc.
+ Copyright (C) 1998, 2001, 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -80,7 +80,7 @@ package java.util;
* @since 1.2
* @status updated to 1.4
*/
-public interface List extends Collection
+public interface List<E> extends Collection<E>
{
/**
* Insert an element into the list at a given position (optional operation).
@@ -100,7 +100,7 @@ public interface List extends Collection
* @throws NullPointerException if o is null and this list doesn't support
* the addition of null values.
*/
- void add(int index, Object o);
+ void add(int index, E o);
/**
* Add an element to the end of the list (optional operation). If the list
@@ -118,7 +118,7 @@ public interface List extends Collection
* @throws NullPointerException if o is null and this list doesn't support
* the addition of null values.
*/
- boolean add(Object o);
+ boolean add(E o);
/**
* Insert the contents of a collection into the list at a given position
@@ -143,7 +143,7 @@ public interface List extends Collection
* @throws NullPointerException if the specified collection is null
* @see #add(int, Object)
*/
- boolean addAll(int index, Collection c);
+ boolean addAll(int index, Collection<? extends E> c);
/**
* Add the contents of a collection to the end of the list (optional
@@ -165,7 +165,7 @@ public interface List extends Collection
* doesn't support the addition of null values.
* @see #add(Object)
*/
- boolean addAll(Collection c);
+ boolean addAll(Collection<? extends E> c);
/**
* Clear the list, such that a subsequent call to isEmpty() would return
@@ -202,7 +202,7 @@ public interface List extends Collection
* list does not support null values.
* @see #contains(Object)
*/
- boolean containsAll(Collection c);
+ boolean containsAll(Collection<?> c);
/**
* Test whether this list is equal to another object. A List is defined to be
@@ -226,7 +226,7 @@ public interface List extends Collection
* @return the element at index index in this list
* @throws IndexOutOfBoundsException if index &lt; 0 || index &gt;= size()
*/
- Object get(int index);
+ E get(int index);
/**
* Obtains a hash code for this list. In order to obey the general
@@ -276,7 +276,7 @@ while (i.hasNext())
*
* @return an Iterator over the elements of this list, in order
*/
- Iterator iterator();
+ Iterator<E> iterator();
/**
* Obtain the last index at which a given object is to be found in this
@@ -297,7 +297,7 @@ while (i.hasNext())
* @return a ListIterator over the elements of this list, in order, starting
* at the beginning
*/
- ListIterator listIterator();
+ ListIterator<E> listIterator();
/**
* Obtain a ListIterator over this list, starting at a given position.
@@ -310,7 +310,7 @@ while (i.hasNext())
* at index
* @throws IndexOutOfBoundsException if index &lt; 0 || index &gt; size()
*/
- ListIterator listIterator(int index);
+ ListIterator<E> listIterator(int index);
/**
* Remove the element at a given position in this list (optional operation).
@@ -322,7 +322,7 @@ while (i.hasNext())
* remove operation
* @throws IndexOutOfBoundsException if index &lt; 0 || index &gt;= size()
*/
- Object remove(int index);
+ E remove(int index);
/**
* Remove the first occurence of an object from this list (optional
@@ -357,7 +357,7 @@ while (i.hasNext())
* @see #remove(Object)
* @see #contains(Object)
*/
- boolean removeAll(Collection c);
+ boolean removeAll(Collection<?> c);
/**
* Remove all elements of this list that are not contained in a given
@@ -376,7 +376,7 @@ while (i.hasNext())
* @see #remove(Object)
* @see #contains(Object)
*/
- boolean retainAll(Collection c);
+ boolean retainAll(Collection<?> c);
/**
* Replace an element of this list with another object (optional operation).
@@ -394,7 +394,7 @@ while (i.hasNext())
* @throws NullPointerException if o is null and this
* list does not support null values.
*/
- Object set(int index, Object o);
+ E set(int index, E o);
/**
* Get the number of elements in this list. If the list contains more
@@ -420,7 +420,7 @@ while (i.hasNext())
* @throws IndexOutOfBoundsException if fromIndex &lt; 0
* || toIndex &gt; size() || fromIndex &gt; toIndex
*/
- List subList(int fromIndex, int toIndex);
+ List<E> subList(int fromIndex, int toIndex);
/**
* Copy the current contents of this list into an array.
@@ -447,5 +447,5 @@ while (i.hasNext())
* collection is not a subtype of the element type of a
* @throws NullPointerException if the specified array is null
*/
- Object[] toArray(Object[] a);
+ <T> T[] toArray(T[] a);
}
diff --git a/java/util/ListIterator.java b/java/util/ListIterator.java
index 5e17108c9..9b74528c5 100644
--- a/java/util/ListIterator.java
+++ b/java/util/ListIterator.java
@@ -1,5 +1,5 @@
/* ListIterator.java -- Extended Iterator for iterating over ordered lists
- Copyright (C) 1998, 1999, 2001, 2005 Free Software Foundation, Inc.
+ Copyright (C) 1998, 1999, 2001, 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -59,7 +59,7 @@ package java.util;
* @since 1.2
* @status updated to 1.4
*/
-public interface ListIterator extends Iterator
+public interface ListIterator<E> extends Iterator<E>
{
/**
* Tests whether there are elements remaining in the list in the forward
@@ -88,7 +88,7 @@ public interface ListIterator extends Iterator
* @return the next element in the list in the forward direction
* @throws NoSuchElementException if there are no more elements
*/
- Object next();
+ E next();
/**
* Obtain the next element in the list in the reverse direction. Repeated
@@ -100,7 +100,7 @@ public interface ListIterator extends Iterator
* @return the next element in the list in the reverse direction
* @throws NoSuchElementException if there are no more elements
*/
- Object previous();
+ E previous();
/**
* Find the index of the element that would be returned by a call to next.
@@ -134,7 +134,7 @@ public interface ListIterator extends Iterator
* @throws UnsupportedOperationException if this ListIterator does not
* support the add operation.
*/
- void add(Object o);
+ void add(E o);
/**
* Remove from the list the element last returned by a call to next or
@@ -166,5 +166,5 @@ public interface ListIterator extends Iterator
* @throws UnsupportedOperationException if this ListIterator does not
* support the set operation
*/
- void set(Object o);
+ void set(E o);
}
diff --git a/java/util/ListResourceBundle.java b/java/util/ListResourceBundle.java
index 2bc51c3b0..2e48a22b5 100644
--- a/java/util/ListResourceBundle.java
+++ b/java/util/ListResourceBundle.java
@@ -108,21 +108,21 @@ public abstract class ListResourceBundle extends ResourceBundle
*
* @return an enumeration of the keys
*/
- public Enumeration getKeys()
+ public Enumeration<String> 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();
- Set s = new HashSet();
+ Set<String> s = new HashSet<String>();
int i = contents.length;
while (--i >= 0)
- s.add(contents[i][0]);
+ s.add((String) contents[i][0]);
ResourceBundle bundle = parent;
// Eliminate tail recursion.
while (bundle != null)
{
- Enumeration e = bundle.getKeys();
+ Enumeration<String> e = bundle.getKeys();
while (e.hasMoreElements())
s.add(e.nextElement());
bundle = bundle.parent;
diff --git a/java/util/Map.java b/java/util/Map.java
index 986ab9a84..67b3d8aa5 100644
--- a/java/util/Map.java
+++ b/java/util/Map.java
@@ -78,7 +78,7 @@ package java.util;
* @since 1.2
* @status updated to 1.4
*/
-public interface Map
+public interface Map<K, V>
{
/**
* Remove all entries from this Map (optional operation).
@@ -127,7 +127,7 @@ public interface Map
* @return the set view of all mapping entries
* @see Map.Entry
*/
- Set entrySet();
+ Set<Map.Entry<K, V>> entrySet();
/**
* Compares the specified object with this map for equality. Returns
@@ -153,7 +153,7 @@ public interface Map
* @throws NullPointerException if this map does not accept null keys
* @see #containsKey(Object)
*/
- Object get(Object key);
+ V get(Object key);
/**
* Associates the given key to the given value (optional operation). If the
@@ -172,7 +172,7 @@ public interface Map
* and the map forbids null keys or values
* @see #containsKey(Object)
*/
- Object put(Object key, Object value);
+ V put(K key, V value);
/**
* Returns the hash code for this map. This is the sum of all hashcodes
@@ -204,7 +204,7 @@ public interface Map
*
* @return the set view of all keys
*/
- Set keySet();
+ Set<K> keySet();
/**
* Copies all entries of the given map to this one (optional operation). If
@@ -219,7 +219,7 @@ public interface Map
* if <code>m</code> is null.
* @see #put(Object, Object)
*/
- void putAll(Map m);
+ void putAll(Map<? extends K, ? extends V> m);
/**
* Removes the mapping for this key if present (optional operation). If
@@ -234,7 +234,7 @@ public interface Map
* @throws ClassCastException if the type of the key is not a valid type
* for this map.
*/
- Object remove(Object key);
+ V remove(Object o);
/**
* Returns the number of key-value mappings in the map. If there are more
@@ -257,7 +257,7 @@ public interface Map
*
* @return the collection view of all values
*/
- Collection values();
+ Collection<V> values();
/**
* A map entry (key-value pair). The Map.entrySet() method returns a set
@@ -273,14 +273,14 @@ public interface Map
* @since 1.2
* @status updated to 1.4
*/
- interface Entry
+ interface Entry<K, V>
{
/**
* Get the key corresponding to this entry.
*
* @return the key
*/
- Object getKey();
+ K getKey();
/**
* Get the value corresponding to this entry. If you already called
@@ -288,7 +288,7 @@ public interface Map
*
* @return the value
*/
- Object getValue();
+ V getValue();
/**
* Replaces the value with the specified object (optional operation).
@@ -303,7 +303,7 @@ public interface Map
* prevents it from existing in this map
* @throws NullPointerException if the map forbids null values
*/
- Object setValue(Object value);
+ V setValue(V value);
/**
diff --git a/java/util/PriorityQueue.java b/java/util/PriorityQueue.java
new file mode 100644
index 000000000..703d7471d
--- /dev/null
+++ b/java/util/PriorityQueue.java
@@ -0,0 +1,332 @@
+/* PriorityQueue.java -- Unbounded priority queue
+ Copyright (C) 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.Serializable;
+
+/**
+ * @author Tom Tromey (tromey@redhat.com)
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
+ * @since 1.5
+ */
+public class PriorityQueue<E> extends AbstractQueue<E> implements Serializable
+{
+ private static final int DEFAULT_CAPACITY = 11;
+
+ private static final long serialVersionUID = -7720805057305804111L;
+
+ /** Number of elements actually used in the storage array. */
+ int used;
+
+ /**
+ * This is the storage for the underlying binomial heap.
+ * The idea is, each node is less than or equal to its children.
+ * A node at index N (0-based) has two direct children, at
+ * nodes 2N+1 and 2N+2.
+ */
+ E[] storage;
+
+ /**
+ * The comparator we're using, or null for natural ordering.
+ */
+ Comparator<? super E> comparator;
+
+ public PriorityQueue()
+ {
+ this(DEFAULT_CAPACITY, null);
+ }
+
+ public PriorityQueue(Collection<? extends E> c)
+ {
+ this(Math.max(1, (int) (1.1 * c.size())), null);
+
+ // Special case where we can find the comparator to use.
+ if (c instanceof SortedSet)
+ {
+ SortedSet<? extends E> ss = (SortedSet<? extends E>) c;
+ this.comparator = (Comparator<? super E>) ss.comparator();
+ // We can insert the elements directly, since they are sorted.
+ int i = 0;
+ for (E val : ss)
+ {
+ if (val == null)
+ throw new NullPointerException();
+ storage[i++] = val;
+ }
+ }
+ else if (c instanceof PriorityQueue)
+ {
+ PriorityQueue<? extends E> pq = (PriorityQueue<? extends E>) c;
+ this.comparator = (Comparator<? super E>)pq.comparator();
+ // We can just copy the contents.
+ System.arraycopy(pq.storage, 0, storage, 0, pq.storage.length);
+ }
+
+ addAll(c);
+ }
+
+ public PriorityQueue(int cap)
+ {
+ this(cap, null);
+ }
+
+ public PriorityQueue(int cap, Comparator<? super E> comp)
+ {
+ this.used = 0;
+ this.storage = (E[]) new Object[cap];
+ this.comparator = comp;
+ }
+
+ public PriorityQueue(PriorityQueue<? extends E> c)
+ {
+ this(Math.max(1, (int) (1.1 * c.size())),
+ (Comparator<? super E>)c.comparator());
+ // We can just copy the contents.
+ System.arraycopy(c.storage, 0, storage, 0, c.storage.length);
+ }
+
+ public PriorityQueue(SortedSet<? extends E> c)
+ {
+ this(Math.max(1, (int) (1.1 * c.size())),
+ (Comparator<? super E>)c.comparator());
+ // We can insert the elements directly, since they are sorted.
+ int i = 0;
+ for (E val : c)
+ {
+ if (val == null)
+ throw new NullPointerException();
+ storage[i++] = val;
+ }
+ }
+
+ public void clear()
+ {
+ Arrays.fill(storage, null);
+ used = 0;
+ }
+
+ public Comparator<? super E> comparator()
+ {
+ return comparator;
+ }
+
+ public Iterator<E> iterator()
+ {
+ return new Iterator<E>()
+ {
+ int index = -1;
+ int count = 0;
+
+ public boolean hasNext()
+ {
+ return count < used;
+ }
+
+ public E next()
+ {
+ while (storage[++index] == null)
+ ;
+ ++count;
+ return storage[index];
+ }
+
+ public void remove()
+ {
+ PriorityQueue.this.remove(index);
+ }
+ };
+ }
+
+ public boolean offer(E o)
+ {
+ if (o == null)
+ throw new NullPointerException();
+
+ int slot = findSlot(-1);
+
+ storage[slot] = o;
+ ++used;
+ bubbleUp(slot);
+
+ return true;
+ }
+
+ public E peek()
+ {
+ return used == 0 ? null : storage[0];
+ }
+
+ public E poll()
+ {
+ if (used == 0)
+ return null;
+ E result = storage[0];
+ remove(0);
+ return result;
+ }
+
+ public boolean remove(Object o)
+ {
+ if (o != null)
+ {
+ for (int i = 0; i < storage.length; ++i)
+ {
+ if (o.equals(storage[i]))
+ {
+ remove(i);
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ public int size()
+ {
+ return used;
+ }
+
+ // It is more efficient to implement this locally -- less searching
+ // for free slots.
+ public boolean addAll(Collection<? extends E> c)
+ {
+ if (c == this)
+ throw new IllegalArgumentException();
+
+ int newSlot = -1;
+ int save = used;
+ for (E val : c)
+ {
+ if (val == null)
+ throw new NullPointerException();
+ newSlot = findSlot(newSlot);
+ storage[newSlot] = val;
+ ++used;
+ bubbleUp(newSlot);
+ }
+
+ return save != used;
+ }
+
+ int findSlot(int start)
+ {
+ int slot;
+ if (used == storage.length)
+ {
+ resize();
+ slot = used;
+ }
+ else
+ {
+ for (slot = start + 1; slot < storage.length; ++slot)
+ {
+ if (storage[slot] == null)
+ break;
+ }
+ // We'll always find a slot.
+ }
+ return slot;
+ }
+
+ void remove(int index)
+ {
+ // Remove the element at INDEX. We do this by finding the least
+ // child and moving it into place, then iterating until we reach
+ // the bottom of the tree.
+ while (storage[index] != null)
+ {
+ int child = 2 * index + 1;
+
+ // See if we went off the end.
+ if (child >= storage.length)
+ {
+ storage[index] = null;
+ break;
+ }
+
+ // Find which child we want to promote. If one is not null,
+ // we pick it. If both are null, it doesn't matter, we're
+ // about to leave. If neither is null, pick the lesser.
+ if (child + 1 >= storage.length || storage[child + 1] == null)
+ {
+ // Nothing.
+ }
+ else if (storage[child] == null
+ || (Collections.compare(storage[child], storage[child + 1],
+ comparator) > 0))
+ ++child;
+ storage[index] = storage[child];
+ index = child;
+ }
+ --used;
+ }
+
+ void bubbleUp(int index)
+ {
+ // The element at INDEX was inserted into a blank spot. Now move
+ // it up the tree to its natural resting place.
+ while (index > 0)
+ {
+ // This works regardless of whether we're at 2N+1 or 2N+2.
+ int parent = (index - 1) / 2;
+ if (Collections.compare(storage[parent], storage[index], comparator)
+ <= 0)
+ {
+ // Parent is the same or smaller than this element, so the
+ // invariant is preserved. Note that if the new element
+ // is smaller than the parent, then it is necessarily
+ // smaller than the parent's other child.
+ break;
+ }
+
+ E temp = storage[index];
+ storage[index] = storage[parent];
+ storage[parent] = temp;
+
+ index = parent;
+ }
+ }
+
+ void resize()
+ {
+ E[] new_data = (E[]) new Object[2 * storage.length];
+ System.arraycopy(storage, 0, new_data, 0, storage.length);
+ storage = new_data;
+ }
+}
diff --git a/java/util/Properties.java b/java/util/Properties.java
index eb208f5a9..e294fee7e 100644
--- a/java/util/Properties.java
+++ b/java/util/Properties.java
@@ -104,7 +104,7 @@ s16=1,3</pre>
* @see PropertyResourceBundle
* @status updated to 1.4
*/
-public class Properties extends Hashtable
+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.
@@ -370,6 +370,7 @@ label = Name:\\u0020</pre>
* value that are not strings
* @deprecated use {@link #store(OutputStream, String)} instead
*/
+ @Deprecated
public void save(OutputStream out, String header)
{
try
@@ -489,7 +490,7 @@ label = Name:\\u0020</pre>
*
* @return an Enumeration of all defined keys
*/
- public Enumeration propertyNames()
+ 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,
diff --git a/java/util/PropertyResourceBundle.java b/java/util/PropertyResourceBundle.java
index aaff0766a..53a1af536 100644
--- a/java/util/PropertyResourceBundle.java
+++ b/java/util/PropertyResourceBundle.java
@@ -126,15 +126,17 @@ public class PropertyResourceBundle extends ResourceBundle
*
* @return an enumeration of the keys
*/
- public Enumeration getKeys()
+ public Enumeration<String> getKeys()
{
if (parent == null)
- return properties.propertyNames();
+ // FIXME: bogus cast.
+ return (Enumeration<String>) 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();
+ Set<String> s = new HashSet<String>();
+ // FIXME: bogus cast.
+ Enumeration<String> e = (Enumeration<String>) properties.propertyNames();
while (e.hasMoreElements())
s.add(e.nextElement());
ResourceBundle bundle = parent;
diff --git a/java/util/ResourceBundle.java b/java/util/ResourceBundle.java
index 0d2f104b9..9b82bc801 100644
--- a/java/util/ResourceBundle.java
+++ b/java/util/ResourceBundle.java
@@ -437,7 +437,7 @@ public abstract class ResourceBundle
*
* @return an enumeration of the keys
*/
- public abstract Enumeration getKeys();
+ public abstract Enumeration<String> getKeys();
/**
* Tries to load a class or a property file with the specified name.
diff --git a/java/util/Set.java b/java/util/Set.java
index 839959e62..35f75b5e7 100644
--- a/java/util/Set.java
+++ b/java/util/Set.java
@@ -1,5 +1,6 @@
/* Set.java -- A collection that prohibits duplicates
- Copyright (C) 1998, 2001, 2005 Free Software Foundation, Inc.
+ Copyright (C) 1998, 2001, 2004, 2005
+ Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -66,7 +67,7 @@ package java.util;
* @since 1.2
* @status updated to 1.4
*/
-public interface Set extends Collection
+public interface Set<E> extends Collection<E>
{
/**
* Adds the specified element to the set if it is not already present
@@ -83,7 +84,7 @@ public interface Set extends Collection
* being added
* @throws NullPointerException if null is not permitted in this set
*/
- boolean add(Object o);
+ boolean add(E o);
/**
* Adds all of the elements of the given collection to this set (optional
@@ -102,7 +103,7 @@ public interface Set extends Collection
* if the argument c is null
* @see #add(Object)
*/
- boolean addAll(Collection c);
+ boolean addAll(Collection<? extends E> c);
/**
* Removes all elements from this set (optional operation). This set will
@@ -139,7 +140,7 @@ public interface Set extends Collection
* set doesn't support null values.
* @see #contains(Object)
*/
- boolean containsAll(Collection c);
+ boolean containsAll(Collection<?> c);
/**
* Compares the specified object to this for equality. For sets, the object
@@ -173,7 +174,7 @@ public interface Set extends Collection
*
* @return a set iterator
*/
- Iterator iterator();
+ Iterator<E> iterator();
/**
* Removes the specified element from this set (optional operation). If
@@ -205,7 +206,7 @@ public interface Set extends Collection
* set doesn't support removing null values.
* @see #remove(Object)
*/
- boolean removeAll(Collection c);
+ boolean removeAll(Collection<?> c);
/**
* Retains only the elements in this set that are also in the specified
@@ -222,7 +223,7 @@ public interface Set extends Collection
* set doesn't support retaining null values.
* @see #remove(Object)
*/
- boolean retainAll(Collection c);
+ boolean retainAll(Collection<?> c);
/**
* Returns the number of elements in the set. If there are more
@@ -260,5 +261,5 @@ public interface Set extends Collection
* @throws NullPointerException if a is null
* @see #toArray()
*/
- Object[] toArray(Object[] a);
+ <T> T[] toArray(T[] a);
}
diff --git a/java/util/SortedMap.java b/java/util/SortedMap.java
index acfbd0d36..2b98848f4 100644
--- a/java/util/SortedMap.java
+++ b/java/util/SortedMap.java
@@ -1,5 +1,5 @@
/* SortedMap.java -- A map that makes guarantees about the order of its keys
- Copyright (C) 1998, 2001, 2005 Free Software Foundation, Inc.
+ Copyright (C) 1998, 2001, 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -72,7 +72,7 @@ package java.util;
* @since 1.2
* @status updated to 1.4
*/
-public interface SortedMap extends Map
+public interface SortedMap<K, V> extends Map<K, V>
{
/**
* Returns the comparator used in sorting this map, or null if it is
@@ -80,7 +80,7 @@ public interface SortedMap extends Map
*
* @return the sorting comparator
*/
- Comparator comparator();
+ Comparator<? super K> comparator();
/**
* Returns the first (lowest sorted) key in the map.
@@ -88,7 +88,7 @@ public interface SortedMap extends Map
* @return the first key
* @throws NoSuchElementException if this map is empty.
*/
- Object firstKey();
+ K firstKey();
/**
* Returns a view of the portion of the map strictly less than toKey. The
@@ -110,7 +110,7 @@ public interface SortedMap extends Map
* @throws NullPointerException if toKey is null but the map does not allow
* null keys
*/
- SortedMap headMap(Object toKey);
+ SortedMap<K, V> headMap(K toKey);
/**
* Returns the last (highest sorted) key in the map.
@@ -118,7 +118,7 @@ public interface SortedMap extends Map
* @return the last key
* @throws NoSuchElementException if this map is empty.
*/
- Object lastKey();
+ K lastKey();
/**
* Returns a view of the portion of the map greater than or equal to
@@ -146,7 +146,7 @@ public interface SortedMap extends Map
* @throws NullPointerException if fromKey or toKey is null but the map
* does not allow null keys
*/
- SortedMap subMap(Object fromKey, Object toKey);
+ SortedMap<K, V> subMap(K fromKey, K toKey);
/**
* Returns a view of the portion of the map greater than or equal to
@@ -169,5 +169,5 @@ public interface SortedMap extends Map
* @throws NullPointerException if fromKey is null but the map does not allow
* null keys
*/
- SortedMap tailMap(Object fromKey);
+ SortedMap<K, V> tailMap(K fromKey);
}
diff --git a/java/util/SortedSet.java b/java/util/SortedSet.java
index 48a24a8e0..89f155a0d 100644
--- a/java/util/SortedSet.java
+++ b/java/util/SortedSet.java
@@ -1,6 +1,6 @@
/* SortedSet.java -- A set that makes guarantees about the order of its
elements
- Copyright (C) 1998, 2001, 2005 Free Software Foundation, Inc.
+ Copyright (C) 1998, 2001, 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -74,7 +74,7 @@ package java.util;
* @since 1.2
* @status updated to 1.4
*/
-public interface SortedSet extends Set
+public interface SortedSet<E> extends Set<E>
{
/**
* Returns the comparator used in sorting this set, or null if it is
@@ -82,7 +82,7 @@ public interface SortedSet extends Set
*
* @return the sorting comparator
*/
- Comparator comparator();
+ Comparator<? super E> comparator();
/**
* Returns the first (lowest sorted) element in the set.
@@ -90,7 +90,7 @@ public interface SortedSet extends Set
* @return the first element
* @throws NoSuchElementException if the set is empty.
*/
- Object first();
+ E first();
/**
* Returns a view of the portion of the set strictly less than toElement. The
@@ -113,7 +113,7 @@ public interface SortedSet extends Set
* @throws NullPointerException if toElement is null but the set does not
* allow null elements
*/
- SortedSet headSet(Object toElement);
+ SortedSet<E> headSet(E toElement);
/**
* Returns the last (highest sorted) element in the set.
@@ -121,7 +121,7 @@ public interface SortedSet extends Set
* @return the last element
* @throws NoSuchElementException if the set is empty.
*/
- Object last();
+ E last();
/**
* Returns a view of the portion of the set greater than or equal to
@@ -149,7 +149,7 @@ public interface SortedSet extends Set
* @throws NullPointerException if fromElement or toElement is null but the
* set does not allow null elements
*/
- SortedSet subSet(Object fromElement, Object toElement);
+ SortedSet<E> subSet(E fromElement, E toElement);
/**
* Returns a view of the portion of the set greater than or equal to
@@ -172,5 +172,5 @@ public interface SortedSet extends Set
* @throws NullPointerException if fromElement is null but the set does not
* allow null elements
*/
- SortedSet tailSet(Object fromElement);
+ SortedSet<E> tailSet(E fromElement);
}
diff --git a/java/util/Stack.java b/java/util/Stack.java
index 730ce177c..404a146c2 100644
--- a/java/util/Stack.java
+++ b/java/util/Stack.java
@@ -1,6 +1,7 @@
/* Stack.java - Class that provides a Last In First Out (LIFO)
datatype, known more commonly as a Stack
- Copyright (C) 1998, 1999, 2001, 2005 Free Software Foundation, Inc.
+ Copyright (C) 1998, 1999, 2001, 2004, 2005
+ Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -58,7 +59,7 @@ package java.util;
* @since 1.0
* @status updated to 1.4
*/
-public class Stack extends Vector
+public class Stack<T> extends Vector<T>
{
// We could use Vector methods internally for the following methods,
// but have used Vector fields directly for efficiency (i.e. this
@@ -84,7 +85,7 @@ public class Stack extends Vector
* @return the Object pushed onto the stack
* @see Vector#addElement(Object)
*/
- public Object push(Object item)
+ public T push(T item)
{
// When growing the Stack, use the Vector routines in case more
// memory is needed.
@@ -101,13 +102,13 @@ public class Stack extends Vector
* @return the Object popped from the stack
* @throws EmptyStackException if the stack is empty
*/
- public synchronized Object pop()
+ public synchronized T pop()
{
if (elementCount == 0)
throw new EmptyStackException();
modCount++;
- Object obj = elementData[--elementCount];
+ T obj = elementData[--elementCount];
// Set topmost element to null to assist the gc in cleanup.
elementData[elementCount] = null;
@@ -120,7 +121,7 @@ public class Stack extends Vector
* @return the top Object on the stack
* @throws EmptyStackException if the stack is empty
*/
- public synchronized Object peek()
+ public synchronized T peek()
{
if (elementCount == 0)
throw new EmptyStackException();
diff --git a/java/util/StringTokenizer.java b/java/util/StringTokenizer.java
index 21298c75e..0b59abe2f 100644
--- a/java/util/StringTokenizer.java
+++ b/java/util/StringTokenizer.java
@@ -58,7 +58,7 @@ package java.util;
* @see java.io.StreamTokenizer
* @status updated to 1.4
*/
-public class StringTokenizer implements Enumeration
+public class StringTokenizer implements Enumeration<Object>
{
// WARNING: StringTokenizer is a CORE class in the bootstrap cycle. See the
// comments in vm/reference/java/lang/Runtime for implications of this fact.
diff --git a/java/util/Timer.java b/java/util/Timer.java
index 01a6fe8ea..9b23a8fe7 100644
--- a/java/util/Timer.java
+++ b/java/util/Timer.java
@@ -306,50 +306,50 @@ public class Timer
// Null out any elements that are canceled. Skip element 0 as
// it is the sentinel.
for (int i = elements; i > 0; --i)
- {
- if (heap[i].scheduled < 0)
- {
- ++removed;
-
- // Remove an element by pushing the appropriate child
- // into place, and then iterating to the bottom of the
- // tree.
- int index = i;
- while (heap[index] != null)
- {
- int child = 2 * index;
- if (child >= heap.length)
- {
- // Off end; we're done.
- heap[index] = null;
- break;
- }
-
- if (child + 1 >= heap.length || heap[child + 1] == null)
- {
- // Nothing -- we're done.
- }
- else if (heap[child] == null
- || (heap[child].scheduled
- > heap[child + 1].scheduled))
- ++child;
- heap[index] = heap[child];
- index = child;
- }
- }
- }
-
+ {
+ if (heap[i].scheduled < 0)
+ {
+ ++removed;
+
+ // Remove an element by pushing the appropriate child
+ // into place, and then iterating to the bottom of the
+ // tree.
+ int index = i;
+ while (heap[index] != null)
+ {
+ int child = 2 * index;
+ if (child >= heap.length)
+ {
+ // Off end; we're done.
+ heap[index] = null;
+ break;
+ }
+
+ if (child + 1 >= heap.length || heap[child + 1] == null)
+ {
+ // Nothing -- we're done.
+ }
+ else if (heap[child] == null
+ || (heap[child].scheduled
+ > heap[child + 1].scheduled))
+ ++child;
+ heap[index] = heap[child];
+ index = child;
+ }
+ }
+ }
+
// Make a new heap if we shrank enough.
int newLen = heap.length;
while (elements - removed + DEFAULT_SIZE / 2 <= newLen / 4)
- newLen /= 2;
+ newLen /= 2;
if (newLen != heap.length)
- {
- TimerTask[] newHeap = new TimerTask[newLen];
- System.arraycopy(heap, 0, newHeap, 0, elements + 1);
- heap = newHeap;
- }
-
+ {
+ TimerTask[] newHeap = new TimerTask[newLen];
+ System.arraycopy(heap, 0, newHeap, 0, elements + 1);
+ heap = newHeap;
+ }
+
return removed;
}
} // TaskQueue
@@ -474,11 +474,11 @@ public class Timer
this(daemon, Thread.NORM_PRIORITY);
}
- /**
+ /**
* Create a new Timer whose Thread has the indicated name. It will have
* normal priority and will not be a daemon thread.
* @param name the name of the Thread
- * @since 1.5
+ * @since 1.5
*/
public Timer(String name)
{
@@ -691,7 +691,7 @@ public class Timer
{
queue.setNullOnEmpty(true);
}
-
+
/**
* Removes all cancelled tasks from the queue.
* @return the number of tasks removed
diff --git a/java/util/TreeMap.java b/java/util/TreeMap.java
index 60d0a4d50..88abce10d 100644
--- a/java/util/TreeMap.java
+++ b/java/util/TreeMap.java
@@ -90,8 +90,8 @@ import java.io.Serializable;
* @since 1.2
* @status updated to 1.4
*/
-public class TreeMap extends AbstractMap
- implements SortedMap, Cloneable, Serializable
+public class TreeMap<K, V> extends AbstractMap<K, V>
+ implements SortedMap<K, V>, Cloneable, Serializable
{
// Implementation note:
// A red-black tree is a binary search tree with the additional properties
@@ -140,7 +140,7 @@ public class TreeMap extends AbstractMap
/**
* The cache for {@link #entrySet()}.
*/
- private transient Set entries;
+ private transient Set<Map.Entry<K,V>> entries;
/**
* Counts the number of modifications this TreeMap has undergone, used
@@ -154,7 +154,7 @@ public class TreeMap extends AbstractMap
* Package visible for use by nested classes.
* @serial the comparator ordering this tree, or null
*/
- final Comparator comparator;
+ final Comparator<? super K> comparator;
/**
* Class to represent an entry in the tree. Holds a single key-value pair,
@@ -162,25 +162,25 @@ public class TreeMap extends AbstractMap
*
* @author Eric Blake (ebb9@email.byu.edu)
*/
- private static final class Node extends AbstractMap.BasicMapEntry
+ private static final class Node<K, V> extends AbstractMap.SimpleEntry<K, V>
{
// All fields package visible for use by nested classes.
/** The color of this node. */
int color;
/** The left child node. */
- Node left = nil;
+ Node<K, V> left = nil;
/** The right child node. */
- Node right = nil;
+ Node<K, V> right = nil;
/** The parent node. */
- Node parent = nil;
+ Node<K, V> parent = nil;
/**
* Simple constructor.
* @param key the key
* @param value the value
*/
- Node(Object key, Object value, int color)
+ Node(K key, V value, int color)
{
super(key, value);
this.color = color;
@@ -210,7 +210,7 @@ public class TreeMap extends AbstractMap
* @param c the sort order for the keys of this map, or null
* for the natural order
*/
- public TreeMap(Comparator c)
+ public TreeMap(Comparator<? super K> c)
{
comparator = c;
fabricateTree(0);
@@ -230,7 +230,7 @@ public class TreeMap extends AbstractMap
* @throws NullPointerException if map is null
* @see Comparable
*/
- public TreeMap(Map map)
+ public TreeMap(Map<? extends K, ? extends V> map)
{
this((Comparator) null);
putAll(map);
@@ -244,7 +244,7 @@ public class TreeMap extends AbstractMap
* @param sm a SortedMap, whose entries will be put into this TreeMap
* @throws NullPointerException if sm is null
*/
- public TreeMap(SortedMap sm)
+ public TreeMap(SortedMap<K, ? extends V> sm)
{
this(sm.comparator());
int pos = sm.size();
@@ -313,7 +313,7 @@ public class TreeMap extends AbstractMap
*
* @return the map's comparator
*/
- public Comparator comparator()
+ public Comparator<? super K> comparator()
{
return comparator;
}
@@ -329,7 +329,7 @@ public class TreeMap extends AbstractMap
*/
public boolean containsKey(Object key)
{
- return getNode(key) != nil;
+ return getNode((K) key) != nil;
}
/**
@@ -364,19 +364,19 @@ public class TreeMap extends AbstractMap
* @see #values()
* @see Map.Entry
*/
- public Set entrySet()
+ public Set<Map.Entry<K,V>> entrySet()
{
if (entries == null)
// Create an AbstractSet with custom implementations of those methods
// that can be overriden easily and efficiently.
- entries = new AbstractSet()
+ entries = new AbstractSet<Map.Entry<K,V>>()
{
public int size()
{
return size;
}
- public Iterator iterator()
+ public Iterator<Map.Entry<K,V>> iterator()
{
return new TreeIterator(ENTRIES);
}
@@ -390,8 +390,8 @@ public class TreeMap extends AbstractMap
{
if (! (o instanceof Map.Entry))
return false;
- Map.Entry me = (Map.Entry) o;
- Node n = getNode(me.getKey());
+ Map.Entry<K,V> me = (Map.Entry<K,V>) o;
+ Node<K,V> n = getNode(me.getKey());
return n != nil && AbstractSet.equals(me.getValue(), n.value);
}
@@ -399,8 +399,8 @@ public class TreeMap extends AbstractMap
{
if (! (o instanceof Map.Entry))
return false;
- Map.Entry me = (Map.Entry) o;
- Node n = getNode(me.getKey());
+ Map.Entry<K,V> me = (Map.Entry<K,V>) o;
+ Node<K,V> n = getNode(me.getKey());
if (n != nil && AbstractSet.equals(me.getValue(), n.value))
{
removeNode(n);
@@ -418,7 +418,7 @@ public class TreeMap extends AbstractMap
* @return the first key
* @throws NoSuchElementException if the map is empty
*/
- public Object firstKey()
+ public K firstKey()
{
if (root == nil)
throw new NoSuchElementException();
@@ -439,10 +439,10 @@ public class TreeMap extends AbstractMap
* @see #put(Object, Object)
* @see #containsKey(Object)
*/
- public Object get(Object key)
+ public V get(Object key)
{
// Exploit fact that nil.value == null.
- return getNode(key).value;
+ return getNode((K) key).value;
}
/**
@@ -460,9 +460,9 @@ public class TreeMap extends AbstractMap
* @throws NullPointerException if toKey is null, but the comparator does not
* tolerate null elements
*/
- public SortedMap headMap(Object toKey)
+ public SortedMap<K, V> headMap(K toKey)
{
- return new SubMap(nil, toKey);
+ return new SubMap((K)(Object)nil, toKey);
}
/**
@@ -474,19 +474,19 @@ public class TreeMap extends AbstractMap
* @see #values()
* @see #entrySet()
*/
- public Set keySet()
+ public Set<K> keySet()
{
if (keys == null)
// Create an AbstractSet with custom implementations of those methods
// that can be overriden easily and efficiently.
- keys = new AbstractSet()
+ keys = new AbstractSet<K>()
{
public int size()
{
return size;
}
- public Iterator iterator()
+ public Iterator<K> iterator()
{
return new TreeIterator(KEYS);
}
@@ -503,7 +503,7 @@ public class TreeMap extends AbstractMap
public boolean remove(Object key)
{
- Node n = getNode(key);
+ Node<K,V> n = getNode((K) key);
if (n == nil)
return false;
removeNode(n);
@@ -519,7 +519,7 @@ public class TreeMap extends AbstractMap
* @return the last key
* @throws NoSuchElementException if the map is empty
*/
- public Object lastKey()
+ public K lastKey()
{
if (root == nil)
throw new NoSuchElementException("empty");
@@ -542,10 +542,10 @@ public class TreeMap extends AbstractMap
* @see #get(Object)
* @see Object#equals(Object)
*/
- public Object put(Object key, Object value)
+ public V put(K key, V value)
{
- Node current = root;
- Node parent = nil;
+ Node<K,V> current = root;
+ Node<K,V> parent = nil;
int comparison = 0;
// Find new node's parent.
@@ -595,13 +595,13 @@ public class TreeMap extends AbstractMap
* @throws NullPointerException if a key in m is null, and the comparator
* does not tolerate nulls
*/
- public void putAll(Map m)
+ public void putAll(Map<? extends K, ? extends V> m)
{
Iterator itr = m.entrySet().iterator();
int pos = m.size();
while (--pos >= 0)
{
- Map.Entry e = (Map.Entry) itr.next();
+ Map.Entry<K,V> e = (Map.Entry<K,V>) itr.next();
put(e.getKey(), e.getValue());
}
}
@@ -619,13 +619,13 @@ public class TreeMap extends AbstractMap
* @throws NullPointerException if key is null, but the comparator does
* not tolerate nulls
*/
- public Object remove(Object key)
+ public V remove(Object key)
{
- Node n = getNode(key);
+ Node<K, V> n = getNode((K)key);
if (n == nil)
return null;
// Note: removeNode can alter the contents of n, so save value now.
- Object result = n.value;
+ V result = n.value;
removeNode(n);
return result;
}
@@ -659,7 +659,7 @@ public class TreeMap extends AbstractMap
* comparator does not tolerate null elements
* @throws IllegalArgumentException if fromKey is greater than toKey
*/
- public SortedMap subMap(Object fromKey, Object toKey)
+ public SortedMap<K, V> subMap(K fromKey, K toKey)
{
return new SubMap(fromKey, toKey);
}
@@ -679,9 +679,9 @@ public class TreeMap extends AbstractMap
* @throws NullPointerException if fromKey is null, but the comparator
* does not tolerate null elements
*/
- public SortedMap tailMap(Object fromKey)
+ public SortedMap<K, V> tailMap(K fromKey)
{
- return new SubMap(fromKey, nil);
+ return new SubMap(fromKey, (K)(Object)nil);
}
/**
@@ -694,19 +694,19 @@ public class TreeMap extends AbstractMap
* @see #keySet()
* @see #entrySet()
*/
- public Collection values()
+ public Collection<V> values()
{
if (values == null)
// We don't bother overriding many of the optional methods, as doing so
// wouldn't provide any significant performance advantage.
- values = new AbstractCollection()
+ values = new AbstractCollection<V>()
{
public int size()
{
return size;
}
- public Iterator iterator()
+ public Iterator<V> iterator()
{
return new TreeIterator(VALUES);
}
@@ -729,7 +729,7 @@ public class TreeMap extends AbstractMap
* or are not Comparable with natural ordering
* @throws NullPointerException if o1 or o2 is null with natural ordering
*/
- final int compare(Object o1, Object o2)
+ final int compare(K o1, K o2)
{
return (comparator == null
? ((Comparable) o1).compareTo(o2)
@@ -742,7 +742,7 @@ public class TreeMap extends AbstractMap
* @param node the child of the node just deleted, possibly nil
* @param parent the parent of the node just deleted, never nil
*/
- private void deleteFixup(Node node, Node parent)
+ private void deleteFixup(Node<K,V> node, Node<K,V> parent)
{
// if (parent == nil)
// throw new InternalError();
@@ -754,7 +754,7 @@ public class TreeMap extends AbstractMap
if (node == parent.left)
{
// Rebalance left side.
- Node sibling = parent.right;
+ Node<K,V> sibling = parent.right;
// if (sibling == nil)
// throw new InternalError();
if (sibling.color == RED)
@@ -798,7 +798,7 @@ public class TreeMap extends AbstractMap
else
{
// Symmetric "mirror" of left-side case.
- Node sibling = parent.left;
+ Node<K,V> sibling = parent.left;
// if (sibling == nil)
// throw new InternalError();
if (sibling.color == RED)
@@ -931,7 +931,7 @@ public class TreeMap extends AbstractMap
*
* @return the first node
*/
- final Node firstNode()
+ final Node<K, V> firstNode()
{
// Exploit fact that nil.left == nil.
Node node = root;
@@ -947,9 +947,9 @@ public class TreeMap extends AbstractMap
* @param key the key to search for
* @return the node where the key is found, or nil
*/
- final Node getNode(Object key)
+ final Node<K, V> getNode(K key)
{
- Node current = root;
+ Node<K,V> current = root;
while (current != nil)
{
int comparison = compare(key, current.key);
@@ -970,13 +970,13 @@ public class TreeMap extends AbstractMap
* @param key the upper bound, exclusive
* @return the previous node
*/
- final Node highestLessThan(Object key)
+ final Node<K,V> highestLessThan(K key)
{
if (key == nil)
return lastNode();
- Node last = nil;
- Node current = root;
+ Node<K,V> last = nil;
+ Node<K,V> current = root;
int comparison = 0;
while (current != nil)
@@ -998,7 +998,7 @@ public class TreeMap extends AbstractMap
*
* @param n the newly inserted node
*/
- private void insertFixup(Node n)
+ private void insertFixup(Node<K,V> n)
{
// Only need to rebalance when parent is a RED node, and while at least
// 2 levels deep into the tree (ie: node has a grandparent). Remember
@@ -1073,7 +1073,7 @@ public class TreeMap extends AbstractMap
*
* @return the last node
*/
- private Node lastNode()
+ private Node<K,V> lastNode()
{
// Exploit fact that nil.right == nil.
Node node = root;
@@ -1091,13 +1091,13 @@ public class TreeMap extends AbstractMap
* @param first true to return the first element instead of nil for nil key
* @return the next node
*/
- final Node lowestGreaterThan(Object key, boolean first)
+ final Node<K,V> lowestGreaterThan(K key, boolean first)
{
if (key == nil)
return first ? firstNode() : nil;
- Node last = nil;
- Node current = root;
+ Node<K,V> last = nil;
+ Node<K,V> current = root;
int comparison = 0;
while (current != nil)
@@ -1120,7 +1120,7 @@ public class TreeMap extends AbstractMap
* @param node the current node, not nil
* @return the prior node in sorted order
*/
- private Node predecessor(Node node)
+ private Node<K,V> predecessor(Node<K,V> node)
{
if (node.left != nil)
{
@@ -1169,21 +1169,21 @@ public class TreeMap extends AbstractMap
/**
* Construct a tree from sorted keys in linear time, with values of "".
- * Package visible for use by TreeSet.
+ * Package visible for use by TreeSet, which uses a value type of String.
*
* @param keys the iterator over the sorted keys
* @param count the number of nodes to insert
* @see TreeSet#TreeSet(SortedSet)
*/
- final void putKeysLinear(Iterator keys, int count)
+ final void putKeysLinear(Iterator<K> keys, int count)
{
fabricateTree(count);
- Node node = firstNode();
+ Node<K,V> node = firstNode();
while (--count >= 0)
{
node.key = keys.next();
- node.value = "";
+ node.value = (V) "";
node = successor(node);
}
}
@@ -1211,10 +1211,10 @@ public class TreeMap extends AbstractMap
*
* @param node the node to remove
*/
- final void removeNode(Node node)
+ final void removeNode(Node<K,V> node)
{
- Node splice;
- Node child;
+ Node<K,V> splice;
+ Node<K,V> child;
modCount++;
size--;
@@ -1268,7 +1268,7 @@ public class TreeMap extends AbstractMap
*
* @param node the node to rotate
*/
- private void rotateLeft(Node node)
+ private void rotateLeft(Node<K,V> node)
{
Node child = node.right;
// if (node == nil || child == nil)
@@ -1301,7 +1301,7 @@ public class TreeMap extends AbstractMap
*
* @param node the node to rotate
*/
- private void rotateRight(Node node)
+ private void rotateRight(Node<K,V> node)
{
Node child = node.left;
// if (node == nil || child == nil)
@@ -1336,7 +1336,7 @@ public class TreeMap extends AbstractMap
* @param node the current node, not nil
* @return the next node in sorted order
*/
- final Node successor(Node node)
+ final Node<K,V> successor(Node<K,V> node)
{
if (node.right != nil)
{
@@ -1346,7 +1346,7 @@ public class TreeMap extends AbstractMap
return node;
}
- Node parent = node.parent;
+ Node<K,V> parent = node.parent;
// Exploit fact that nil.right == nil and node is non-nil.
while (node == parent.right)
{
@@ -1489,24 +1489,26 @@ public class TreeMap extends AbstractMap
*
* @author Eric Blake (ebb9@email.byu.edu)
*/
- private final class SubMap extends AbstractMap implements SortedMap
+ private final class SubMap<SK extends K,SV extends V>
+ extends AbstractMap<SK,SV>
+ implements SortedMap<SK,SV>
{
/**
* The lower range of this view, inclusive, or nil for unbounded.
* Package visible for use by nested classes.
*/
- final Object minKey;
+ final SK minKey;
/**
* The upper range of this view, exclusive, or nil for unbounded.
* Package visible for use by nested classes.
*/
- final Object maxKey;
+ final SK maxKey;
/**
* The cache for {@link #entrySet()}.
*/
- private Set entries;
+ private Set<Map.Entry<SK,SV>> entries;
/**
* Create a SubMap representing the elements between minKey (inclusive)
@@ -1517,9 +1519,9 @@ public class TreeMap extends AbstractMap
* @param maxKey the upper bound
* @throws IllegalArgumentException if minKey &gt; maxKey
*/
- SubMap(Object minKey, Object maxKey)
+ SubMap(SK minKey, SK maxKey)
{
- if (minKey != nil && maxKey != nil && compare(minKey, maxKey) > 0)
+ if (minKey != nil && maxKey != nil && compare((K) minKey, (K) maxKey) > 0)
throw new IllegalArgumentException("fromKey > toKey");
this.minKey = minKey;
this.maxKey = maxKey;
@@ -1533,10 +1535,10 @@ public class TreeMap extends AbstractMap
* @param key the key to check
* @return true if the key is in range
*/
- boolean keyInRange(Object key)
+ boolean keyInRange(SK key)
{
- return ((minKey == nil || compare(key, minKey) >= 0)
- && (maxKey == nil || compare(key, maxKey) < 0));
+ return ((minKey == nil || compare((K) key, (K) minKey) >= 0)
+ && (maxKey == nil || compare((K) key, (K) maxKey) < 0));
}
public void clear()
@@ -1551,14 +1553,14 @@ public class TreeMap extends AbstractMap
}
}
- public Comparator comparator()
+ public Comparator<? super SK> comparator()
{
return comparator;
}
public boolean containsKey(Object key)
{
- return keyInRange(key) && TreeMap.this.containsKey(key);
+ return keyInRange((SK) key) && TreeMap.this.containsKey(key);
}
public boolean containsValue(Object value)
@@ -1574,19 +1576,19 @@ public class TreeMap extends AbstractMap
return false;
}
- public Set entrySet()
+ public Set<Map.Entry<SK,SV>> entrySet()
{
if (entries == null)
// Create an AbstractSet with custom implementations of those methods
// that can be overriden easily and efficiently.
- entries = new AbstractSet()
+ entries = new AbstractSet<Map.Entry<SK,SV>>()
{
public int size()
{
return SubMap.this.size();
}
- public Iterator iterator()
+ public Iterator<Map.Entry<SK,SV>> iterator()
{
Node first = lowestGreaterThan(minKey, true);
Node max = lowestGreaterThan(maxKey, false);
@@ -1602,11 +1604,11 @@ public class TreeMap extends AbstractMap
{
if (! (o instanceof Map.Entry))
return false;
- Map.Entry me = (Map.Entry) o;
- Object key = me.getKey();
+ Map.Entry<SK,SV> me = (Map.Entry<SK,SV>) o;
+ SK key = me.getKey();
if (! keyInRange(key))
return false;
- Node n = getNode(key);
+ Node<K,V> n = getNode((K) key);
return n != nil && AbstractSet.equals(me.getValue(), n.value);
}
@@ -1614,11 +1616,11 @@ public class TreeMap extends AbstractMap
{
if (! (o instanceof Map.Entry))
return false;
- Map.Entry me = (Map.Entry) o;
- Object key = me.getKey();
+ Map.Entry<SK,SV> me = (Map.Entry<SK,SV>) o;
+ SK key = me.getKey();
if (! keyInRange(key))
return false;
- Node n = getNode(key);
+ Node<K,V> n = getNode((K) key);
if (n != nil && AbstractSet.equals(me.getValue(), n.value))
{
removeNode(n);
@@ -1630,29 +1632,29 @@ public class TreeMap extends AbstractMap
return entries;
}
- public Object firstKey()
+ public SK firstKey()
{
- Node node = lowestGreaterThan(minKey, true);
+ Node<SK,SV> node = (Node<SK,SV>) lowestGreaterThan(minKey, true);
if (node == nil || ! keyInRange(node.key))
throw new NoSuchElementException();
return node.key;
}
- public Object get(Object key)
+ public SV get(Object key)
{
- if (keyInRange(key))
- return TreeMap.this.get(key);
+ if (keyInRange((SK) key))
+ return (SV) TreeMap.this.get(key);
return null;
}
- public SortedMap headMap(Object toKey)
+ public SortedMap<SK,SV> headMap(SK toKey)
{
if (! keyInRange(toKey))
throw new IllegalArgumentException("key outside range");
return new SubMap(minKey, toKey);
}
- public Set keySet()
+ public Set<SK> keySet()
{
if (this.keys == null)
// Create an AbstractSet with custom implementations of those methods
@@ -1664,7 +1666,7 @@ public class TreeMap extends AbstractMap
return SubMap.this.size();
}
- public Iterator iterator()
+ public Iterator<SK> iterator()
{
Node first = lowestGreaterThan(minKey, true);
Node max = lowestGreaterThan(maxKey, false);
@@ -1678,16 +1680,16 @@ public class TreeMap extends AbstractMap
public boolean contains(Object o)
{
- if (! keyInRange(o))
+ if (! keyInRange((SK) o))
return false;
- return getNode(o) != nil;
+ return getNode((K) o) != nil;
}
public boolean remove(Object o)
{
- if (! keyInRange(o))
+ if (! keyInRange((SK) o))
return false;
- Node n = getNode(o);
+ Node n = getNode((K) o);
if (n != nil)
{
removeNode(n);
@@ -1699,25 +1701,25 @@ public class TreeMap extends AbstractMap
return this.keys;
}
- public Object lastKey()
+ public SK lastKey()
{
- Node node = highestLessThan(maxKey);
+ Node<SK,SV> node = (Node<SK,SV>) highestLessThan(maxKey);
if (node == nil || ! keyInRange(node.key))
throw new NoSuchElementException();
- return node.key;
+ return (SK) node.key;
}
- public Object put(Object key, Object value)
+ public SV put(SK key, SV value)
{
if (! keyInRange(key))
throw new IllegalArgumentException("Key outside range");
- return TreeMap.this.put(key, value);
+ return (SV) TreeMap.this.put(key, value);
}
- public Object remove(Object key)
+ public SV remove(Object key)
{
- if (keyInRange(key))
- return TreeMap.this.remove(key);
+ if (keyInRange((SK)key))
+ return (SV) TreeMap.this.remove(key);
return null;
}
@@ -1734,21 +1736,21 @@ public class TreeMap extends AbstractMap
return count;
}
- public SortedMap subMap(Object fromKey, Object toKey)
+ public SortedMap<SK, SV> subMap(SK fromKey, SK toKey)
{
if (! keyInRange(fromKey) || ! keyInRange(toKey))
throw new IllegalArgumentException("key outside range");
return new SubMap(fromKey, toKey);
}
- public SortedMap tailMap(Object fromKey)
+ public SortedMap<SK, SV> tailMap(SK fromKey)
{
if (! keyInRange(fromKey))
throw new IllegalArgumentException("key outside range");
return new SubMap(fromKey, maxKey);
}
- public Collection values()
+ public Collection<SV> values()
{
if (this.values == null)
// Create an AbstractCollection with custom implementations of those
@@ -1760,7 +1762,7 @@ public class TreeMap extends AbstractMap
return SubMap.this.size();
}
- public Iterator iterator()
+ public Iterator<SV> iterator()
{
Node first = lowestGreaterThan(minKey, true);
Node max = lowestGreaterThan(maxKey, false);
diff --git a/java/util/TreeSet.java b/java/util/TreeSet.java
index 34cb39acc..2851e4a5a 100644
--- a/java/util/TreeSet.java
+++ b/java/util/TreeSet.java
@@ -1,5 +1,5 @@
/* TreeSet.java -- a class providing a TreeMap-backed SortedSet
- Copyright (C) 1999, 2000, 2001, 2004, 2005 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2000, 2001, 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -68,6 +68,8 @@ import java.io.Serializable;
* @author Jon Zeppieri
* @author Bryce McKinlay
* @author Eric Blake (ebb9@email.byu.edu)
+ * @author Tom Tromey (tromey@redhat.com)
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
* @see Collection
* @see Set
* @see HashSet
@@ -79,8 +81,8 @@ import java.io.Serializable;
* @since 1.2
* @status updated to 1.4
*/
-public class TreeSet extends AbstractSet
- implements SortedSet, Cloneable, Serializable
+public class TreeSet<T> extends AbstractSet<T>
+ implements SortedSet<T>, Cloneable, Serializable
{
/**
* Compatible with JDK 1.2.
@@ -92,7 +94,7 @@ public class TreeSet extends AbstractSet
*/
// Not final because of readObject. This will always be one of TreeMap or
// TreeMap.SubMap, which both extend AbstractMap.
- private transient SortedMap map;
+ private transient SortedMap<T, String> map;
/**
* Construct a new TreeSet whose backing TreeMap using the "natural"
@@ -103,7 +105,7 @@ public class TreeSet extends AbstractSet
*/
public TreeSet()
{
- map = new TreeMap();
+ map = new TreeMap<T, String>();
}
/**
@@ -113,9 +115,9 @@ public class TreeSet extends AbstractSet
*
* @param comparator the Comparator this Set will use
*/
- public TreeSet(Comparator comparator)
+ public TreeSet(Comparator<? super T> comparator)
{
- map = new TreeMap(comparator);
+ map = new TreeMap<T, String>(comparator);
}
/**
@@ -130,9 +132,9 @@ public class TreeSet extends AbstractSet
* @throws NullPointerException if the collection is null
* @see Comparable
*/
- public TreeSet(Collection collection)
+ public TreeSet(Collection<? extends T> collection)
{
- map = new TreeMap();
+ map = new TreeMap<T, String>();
addAll(collection);
}
@@ -145,11 +147,14 @@ public class TreeSet extends AbstractSet
* and will initialize itself with all its elements
* @throws NullPointerException if sortedSet is null
*/
- public TreeSet(SortedSet sortedSet)
+ public TreeSet(SortedSet<T> sortedSet)
{
- map = new TreeMap(sortedSet.comparator());
- Iterator itr = sortedSet.iterator();
- ((TreeMap) map).putKeysLinear(itr, sortedSet.size());
+ Iterator<T> itr;
+
+ map = new TreeMap<T, String>
+ ((Comparator<? super T>)sortedSet.comparator());
+ itr = ((SortedSet<T>) sortedSet).iterator();
+ ((TreeMap<T, String>) map).putKeysLinear(itr, sortedSet.size());
}
/**
@@ -158,7 +163,7 @@ public class TreeSet extends AbstractSet
*
* @param backingMap the submap
*/
- private TreeSet(SortedMap backingMap)
+ private TreeSet(SortedMap<T,String> backingMap)
{
map = backingMap;
}
@@ -171,7 +176,7 @@ public class TreeSet extends AbstractSet
* @throws ClassCastException if the element cannot be compared with objects
* already in the set
*/
- public boolean add(Object obj)
+ public boolean add(T obj)
{
return map.put(obj, "") == null;
}
@@ -185,11 +190,11 @@ public class TreeSet extends AbstractSet
* @throws ClassCastException if an element in c cannot be compared with
* objects already in the set
*/
- public boolean addAll(Collection c)
+ public boolean addAll(Collection<? extends T> c)
{
boolean result = false;
int pos = c.size();
- Iterator itr = c.iterator();
+ Iterator<? extends T> itr = c.iterator();
while (--pos >= 0)
result |= (map.put(itr.next(), "") == null);
return result;
@@ -210,12 +215,12 @@ public class TreeSet extends AbstractSet
*/
public Object clone()
{
- TreeSet copy = null;
+ TreeSet<T> copy = null;
try
{
- copy = (TreeSet) super.clone();
+ copy = (TreeSet<T>) super.clone();
// Map may be either TreeMap or TreeMap.SubMap, hence the ugly casts.
- copy.map = (SortedMap) ((AbstractMap) map).clone();
+ copy.map = (SortedMap<T, String>) ((AbstractMap<T, String>) map).clone();
}
catch (CloneNotSupportedException x)
{
@@ -229,7 +234,7 @@ public class TreeSet extends AbstractSet
*
* @return the comparator, or null if the set uses natural ordering
*/
- public Comparator comparator()
+ public Comparator<? super T> comparator()
{
return map.comparator();
}
@@ -253,7 +258,7 @@ public class TreeSet extends AbstractSet
* @return the first element
* @throws NoSuchElementException if the set is empty
*/
- public Object first()
+ public T first()
{
return map.firstKey();
}
@@ -273,9 +278,9 @@ public class TreeSet extends AbstractSet
* @throws NullPointerException if to is null, but the comparator does not
* tolerate null elements
*/
- public SortedSet headSet(Object to)
+ public SortedSet<T> headSet(T to)
{
- return new TreeSet(map.headMap(to));
+ return new TreeSet<T>(map.headMap(to));
}
/**
@@ -294,7 +299,7 @@ public class TreeSet extends AbstractSet
*
* @return an iterator
*/
- public Iterator iterator()
+ public Iterator<T> iterator()
{
return map.keySet().iterator();
}
@@ -305,7 +310,7 @@ public class TreeSet extends AbstractSet
* @return the last element
* @throws NoSuchElementException if the set is empty
*/
- public Object last()
+ public T last()
{
return map.lastKey();
}
@@ -351,9 +356,9 @@ public class TreeSet extends AbstractSet
* does not tolerate null elements
* @throws IllegalArgumentException if from is greater than to
*/
- public SortedSet subSet(Object from, Object to)
+ public SortedSet<T> subSet(T from, T to)
{
- return new TreeSet(map.subMap(from, to));
+ return new TreeSet<T>(map.subMap(from, to));
}
/**
@@ -371,9 +376,9 @@ public class TreeSet extends AbstractSet
* @throws NullPointerException if from is null, but the comparator
* does not tolerate null elements
*/
- public SortedSet tailSet(Object from)
+ public SortedSet<T> tailSet(T from)
{
- return new TreeSet(map.tailMap(from));
+ return new TreeSet<T>(map.tailMap(from));
}
/**
@@ -387,7 +392,7 @@ public class TreeSet extends AbstractSet
private void writeObject(ObjectOutputStream s) throws IOException
{
s.defaultWriteObject();
- Iterator itr = map.keySet().iterator();
+ Iterator<T> itr = map.keySet().iterator();
int pos = map.size();
s.writeObject(map.comparator());
s.writeInt(pos);
@@ -408,9 +413,9 @@ public class TreeSet extends AbstractSet
throws IOException, ClassNotFoundException
{
s.defaultReadObject();
- Comparator comparator = (Comparator) s.readObject();
+ Comparator<? super T> comparator = (Comparator<? super T>) s.readObject();
int size = s.readInt();
- map = new TreeMap(comparator);
- ((TreeMap) map).putFromObjStream(s, size, false);
+ map = new TreeMap<T, String>(comparator);
+ ((TreeMap<T, String>) map).putFromObjStream(s, size, false);
}
}
diff --git a/java/util/UUID.java b/java/util/UUID.java
index 6a57d27b4..9a402d159 100644
--- a/java/util/UUID.java
+++ b/java/util/UUID.java
@@ -77,7 +77,7 @@ import java.security.NoSuchAlgorithmException;
*/
public final class UUID
extends Object
- implements Serializable, Comparable // genericizeme!
+ implements Serializable, Comparable<UUID>
{
private static final long serialVersionUID = -4856846361193249489L;
@@ -127,17 +127,6 @@ public final class UUID
*
* @return -1 if this < val, 0 if they are equal, 1 if this > val.
*/
- public int compareTo(Object val)
- {
- return compareTo((UUID)val);
- }
-
- /**
- * Compare this UUID to another.
- * The comparison is performed as between two 128-bit integers.
- *
- * @return -1 if this < val, 0 if they are equal, 1 if this > val.
- */
public int compareTo(UUID o)
{
if( mostSigBits < o.mostSigBits )
diff --git a/java/util/Vector.java b/java/util/Vector.java
index eced68eae..ea29ce093 100644
--- a/java/util/Vector.java
+++ b/java/util/Vector.java
@@ -82,8 +82,8 @@ import java.lang.reflect.Array;
* @since 1.0
* @status updated to 1.4
*/
-public class Vector extends AbstractList
- implements List, RandomAccess, Cloneable, Serializable
+public class Vector<T> extends AbstractList<T>
+ implements List<T>, RandomAccess, Cloneable, Serializable
{
/**
* Compatible with JDK 1.0+.
@@ -95,7 +95,7 @@ public class Vector extends AbstractList
* in positions 0 through elementCount - 1, and all remaining slots are null.
* @serial the elements
*/
- protected Object[] elementData;
+ protected T[] elementData;
/**
* The number of elements currently in the vector, also returned by
@@ -130,10 +130,10 @@ public class Vector extends AbstractList
* @throws NullPointerException if c is null
* @since 1.2
*/
- public Vector(Collection c)
+ public Vector(Collection<? extends T> c)
{
elementCount = c.size();
- elementData = c.toArray(new Object[elementCount]);
+ elementData = c.toArray((T[]) new Object[elementCount]);
}
/**
@@ -149,7 +149,7 @@ public class Vector extends AbstractList
{
if (initialCapacity < 0)
throw new IllegalArgumentException();
- elementData = new Object[initialCapacity];
+ elementData = (T[]) new Object[initialCapacity];
this.capacityIncrement = capacityIncrement;
}
@@ -192,7 +192,7 @@ public class Vector extends AbstractList
// vector since that is a much less likely case; it's more efficient to
// not do the check and lose a bit of performance in that infrequent case
- Object[] newArray = new Object[elementCount];
+ T[] newArray = (T[]) new Object[elementCount];
System.arraycopy(elementData, 0, newArray, 0, elementCount);
elementData = newArray;
}
@@ -218,7 +218,7 @@ public class Vector extends AbstractList
else
newCapacity = elementData.length + capacityIncrement;
- Object[] newArray = new Object[Math.max(newCapacity, minCapacity)];
+ T[] newArray = (T[]) new Object[Math.max(newCapacity, minCapacity)];
System.arraycopy(elementData, 0, newArray, 0, elementCount);
elementData = newArray;
@@ -284,9 +284,9 @@ public class Vector extends AbstractList
* @see #iterator()
*/
// No need to synchronize as the Enumeration is not thread-safe!
- public Enumeration elements()
+ public Enumeration<T> elements()
{
- return new Enumeration()
+ return new Enumeration<T>()
{
private int i = 0;
@@ -295,7 +295,7 @@ public class Vector extends AbstractList
return i < elementCount;
}
- public Object nextElement()
+ public T nextElement()
{
if (i >= elementCount)
throw new NoSuchElementException();
@@ -385,7 +385,7 @@ public class Vector extends AbstractList
* @throws ArrayIndexOutOfBoundsException index &lt; 0 || index &gt;= size()
* @see #get(int)
*/
- public synchronized Object elementAt(int index)
+ public synchronized T elementAt(int index)
{
checkBoundExclusive(index);
return elementData[index];
@@ -397,7 +397,7 @@ public class Vector extends AbstractList
* @return the first Object in the Vector
* @throws NoSuchElementException the Vector is empty
*/
- public synchronized Object firstElement()
+ public synchronized T firstElement()
{
if (elementCount == 0)
throw new NoSuchElementException();
@@ -411,7 +411,7 @@ public class Vector extends AbstractList
* @return the last Object in the Vector
* @throws NoSuchElementException the Vector is empty
*/
- public synchronized Object lastElement()
+ public synchronized T lastElement()
{
if (elementCount == 0)
throw new NoSuchElementException();
@@ -427,7 +427,7 @@ public class Vector extends AbstractList
* @throws ArrayIndexOutOfBoundsException the index is out of range
* @see #set(int, Object)
*/
- public void setElementAt(Object obj, int index)
+ public void setElementAt(T obj, int index)
{
set(index, obj);
}
@@ -454,7 +454,7 @@ public class Vector extends AbstractList
* @throws ArrayIndexOutOfBoundsException index &lt; 0 || index &gt; size()
* @see #add(int, Object)
*/
- public synchronized void insertElementAt(Object obj, int index)
+ public synchronized void insertElementAt(T obj, int index)
{
checkBoundInclusive(index);
if (elementCount == elementData.length)
@@ -472,7 +472,7 @@ public class Vector extends AbstractList
*
* @param obj the object to add to the Vector
*/
- public synchronized void addElement(Object obj)
+ public synchronized void addElement(T obj)
{
if (elementCount == elementData.length)
ensureCapacity(elementCount + 1);
@@ -570,11 +570,11 @@ public class Vector extends AbstractList
* @throws NullPointerException if <code>a</code> is null
* @since 1.2
*/
- public synchronized Object[] toArray(Object[] a)
+ public synchronized <S> S[] toArray(S[] a)
{
if (a.length < elementCount)
- a = (Object[]) Array.newInstance(a.getClass().getComponentType(),
- elementCount);
+ a = (S[]) Array.newInstance(a.getClass().getComponentType(),
+ elementCount);
else if (a.length > elementCount)
a[elementCount] = null;
System.arraycopy(elementData, 0, a, 0, elementCount);
@@ -589,7 +589,7 @@ public class Vector extends AbstractList
* @throws ArrayIndexOutOfBoundsException index &lt; 0 || index &gt;= size()
* @since 1.2
*/
- public Object get(int index)
+ public T get(int index)
{
return elementAt(index);
}
@@ -604,10 +604,10 @@ public class Vector extends AbstractList
* @throws ArrayIndexOutOfBoundsException index &lt; 0 || index &gt;= size()
* @since 1.2
*/
- public synchronized Object set(int index, Object element)
+ public synchronized T set(int index, T element)
{
checkBoundExclusive(index);
- Object temp = elementData[index];
+ T temp = elementData[index];
elementData[index] = element;
return temp;
}
@@ -619,7 +619,7 @@ public class Vector extends AbstractList
* @return true, as specified by List
* @since 1.2
*/
- public boolean add(Object o)
+ public boolean add(T o)
{
addElement(o);
return true;
@@ -647,7 +647,7 @@ public class Vector extends AbstractList
* @throws ArrayIndexOutOfBoundsException index &lt; 0 || index &gt; size()
* @since 1.2
*/
- public void add(int index, Object element)
+ public void add(int index, T element)
{
insertElementAt(element, index);
}
@@ -660,10 +660,10 @@ public class Vector extends AbstractList
* @throws ArrayIndexOutOfBoundsException index &lt; 0 || index &gt;= size()
* @since 1.2
*/
- public synchronized Object remove(int index)
+ public synchronized T remove(int index)
{
checkBoundExclusive(index);
- Object temp = elementData[index];
+ T temp = elementData[index];
modCount++;
elementCount--;
if (index < elementCount)
@@ -689,7 +689,7 @@ public class Vector extends AbstractList
* @throws NullPointerException if c is null
* @since 1.2
*/
- public synchronized boolean containsAll(Collection c)
+ public synchronized boolean containsAll(Collection<?> c)
{
// Here just for the sychronization.
return super.containsAll(c);
@@ -705,7 +705,7 @@ public class Vector extends AbstractList
* @throws NullPointerException if c is null
* @since 1.2
*/
- public synchronized boolean addAll(Collection c)
+ public synchronized boolean addAll(Collection<? extends T> c)
{
return addAll(elementCount, c);
}
@@ -718,7 +718,7 @@ public class Vector extends AbstractList
* @throws NullPointerException if c is null
* @since 1.2
*/
- public synchronized boolean removeAll(Collection c)
+ public synchronized boolean removeAll(Collection<?> c)
{
// The NullPointerException is thrown implicitly when the Vector
// is not empty and c is null. The RI allows null arguments when
@@ -749,7 +749,7 @@ public class Vector extends AbstractList
* @throws NullPointerException if c is null
* @since 1.2
*/
- public synchronized boolean retainAll(Collection c)
+ public synchronized boolean retainAll(Collection<?> c)
{
// The NullPointerException is thrown implicitly when the Vector
// is not empty and c is null. The RI allows null arguments when
@@ -783,10 +783,10 @@ public class Vector extends AbstractList
* @throws ArrayIndexOutOfBoundsException index &lt; 0 || index &gt; size()
* @since 1.2
*/
- public synchronized boolean addAll(int index, Collection c)
+ public synchronized boolean addAll(int index, Collection<? extends T> c)
{
checkBoundInclusive(index);
- Iterator itr = c.iterator();
+ Iterator<? extends T> itr = c.iterator();
int csize = c.size();
modCount++;
@@ -857,12 +857,12 @@ public class Vector extends AbstractList
* @see ConcurrentModificationException
* @since 1.2
*/
- public synchronized List subList(int fromIndex, int toIndex)
+ public synchronized List<T> subList(int fromIndex, int toIndex)
{
- List sub = super.subList(fromIndex, toIndex);
+ List<T> sub = super.subList(fromIndex, toIndex);
// We must specify the correct object to synchronize upon, hence the
// use of a non-public API
- return new Collections.SynchronizedList(this, sub);
+ return new Collections.SynchronizedList<T>(this, sub);
}
/**
diff --git a/java/util/WeakHashMap.java b/java/util/WeakHashMap.java
index ef2444c04..1f4602915 100644
--- a/java/util/WeakHashMap.java
+++ b/java/util/WeakHashMap.java
@@ -1,6 +1,6 @@
/* WeakHashMap -- a hashtable that keeps only weak references
to its keys, allowing the virtual machine to reclaim them
- Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -77,14 +77,16 @@ import java.lang.ref.WeakReference;
*
* @author Jochen Hoenicke
* @author Eric Blake (ebb9@email.byu.edu)
+ * @author Tom Tromey (tromey@redhat.com)
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
*
* @see HashMap
* @see WeakReference
* @see LinkedHashMap
* @since 1.2
- * @status updated to 1.4
+ * @status updated to 1.4 (partial 1.5)
*/
-public class WeakHashMap extends AbstractMap implements Map
+public class WeakHashMap<K,V> extends AbstractMap<K,V>
{
// WARNING: WeakHashMap is a CORE class in the bootstrap cycle. See the
// comments in vm/reference/java/lang/Runtime for implications of this fact.
@@ -349,19 +351,19 @@ public class WeakHashMap extends AbstractMap implements Map
*
* @author Jochen Hoenicke
*/
- private static class WeakBucket extends WeakReference
+ private static class WeakBucket<K, V> extends WeakReference<K>
{
/**
* The value of this entry. The key is stored in the weak
* reference that we extend.
*/
- Object value;
+ V value;
/**
* The next bucket describing another entry that uses the same
* slot.
*/
- WeakBucket next;
+ WeakBucket<K, V> next;
/**
* The slot of this entry. This should be
@@ -384,7 +386,7 @@ public class WeakHashMap extends AbstractMap implements Map
* @param slot the slot. This must match the slot where this bucket
* will be enqueued.
*/
- public WeakBucket(Object key, ReferenceQueue queue, Object value,
+ public WeakBucket(K key, ReferenceQueue queue, V value,
int slot)
{
super(key, queue);
@@ -397,18 +399,18 @@ public class WeakHashMap extends AbstractMap implements Map
* current bucket. It also keeps a strong reference to the
* key; bad things may happen otherwise.
*/
- class WeakEntry implements Map.Entry
+ class WeakEntry implements Map.Entry<K, V>
{
/**
* The strong ref to the key.
*/
- Object key;
+ K key;
/**
* Creates a new entry for the key.
* @param key the key
*/
- public WeakEntry(Object key)
+ public WeakEntry(K key)
{
this.key = key;
}
@@ -426,7 +428,7 @@ public class WeakHashMap extends AbstractMap implements Map
* Returns the key.
* @return the key
*/
- public Object getKey()
+ public K getKey()
{
return key == NULL_KEY ? null : key;
}
@@ -435,7 +437,7 @@ public class WeakHashMap extends AbstractMap implements Map
* Returns the value.
* @return the value
*/
- public Object getValue()
+ public V getValue()
{
return value;
}
@@ -446,9 +448,9 @@ public class WeakHashMap extends AbstractMap implements Map
* @param newVal the new value
* @return the old value
*/
- public Object setValue(Object newVal)
+ public V setValue(V newVal)
{
- Object oldVal = value;
+ V oldVal = value;
value = newVal;
return oldVal;
}
@@ -491,7 +493,7 @@ public class WeakHashMap extends AbstractMap implements Map
*/
WeakEntry getEntry()
{
- final Object key = this.get();
+ final K key = this.get();
if (key == null)
return null;
return new WeakEntry(key);
@@ -559,7 +561,7 @@ public class WeakHashMap extends AbstractMap implements Map
* @throws NullPointerException if m is null
* @since 1.3
*/
- public WeakHashMap(Map m)
+ public WeakHashMap(Map<? extends K, ? extends V> m)
{
this(m.size(), DEFAULT_LOAD_FACTOR);
putAll(m);
@@ -754,10 +756,10 @@ public class WeakHashMap extends AbstractMap implements Map
* the key wasn't in this map, or if the mapped value was
* explicitly set to null.
*/
- public Object get(Object key)
+ public V get(Object key)
{
cleanQueue();
- WeakBucket.WeakEntry entry = internalGet(key);
+ WeakBucket<K, V>.WeakEntry entry = internalGet(key);
return entry == null ? null : entry.getValue();
}
@@ -769,10 +771,10 @@ public class WeakHashMap extends AbstractMap implements Map
* null if the key wasn't in this map, or if the mapped value
* was explicitly set to null.
*/
- public Object put(Object key, Object value)
+ public V put(K key, V value)
{
cleanQueue();
- WeakBucket.WeakEntry entry = internalGet(key);
+ WeakBucket<K, V>.WeakEntry entry = internalGet(key);
if (entry != null)
return entry.setValue(value);
@@ -791,10 +793,10 @@ public class WeakHashMap extends AbstractMap implements Map
* null if the key wasn't in this map, or if the mapped value was
* explicitly set to null.
*/
- public Object remove(Object key)
+ public V remove(Object key)
{
cleanQueue();
- WeakBucket.WeakEntry entry = internalGet(key);
+ WeakBucket<K, V>.WeakEntry entry = internalGet(key);
if (entry == null)
return null;
@@ -811,7 +813,7 @@ public class WeakHashMap extends AbstractMap implements Map
* this weak hash map.
* @return a set representation of the entries.
*/
- public Set entrySet()
+ public Set<Map.Entry<K,V>> entrySet()
{
cleanQueue();
return theEntrySet;
@@ -846,7 +848,7 @@ public class WeakHashMap extends AbstractMap implements Map
* this weak hash map.
* @return a set representation of the keys.
*/
- public Set keySet()
+ public Set<K> keySet()
{
cleanQueue();
return super.keySet();
@@ -857,7 +859,7 @@ public class WeakHashMap extends AbstractMap implements Map
* key already exists in this map, its value is replaced.
* @param m the map to copy in
*/
- public void putAll(Map m)
+ public void putAll(Map<? extends K, ? extends V> m)
{
super.putAll(m);
}
@@ -870,7 +872,7 @@ public class WeakHashMap extends AbstractMap implements Map
* this weak hash map.
* @return a collection representation of the values.
*/
- public Collection values()
+ public Collection<V> values()
{
cleanQueue();
return super.values();
diff --git a/java/util/concurrent/CopyOnWriteArrayList.java b/java/util/concurrent/CopyOnWriteArrayList.java
new file mode 100644
index 000000000..ec2c90cc1
--- /dev/null
+++ b/java/util/concurrent/CopyOnWriteArrayList.java
@@ -0,0 +1,490 @@
+/* CopyOnWriteArrayList.java
+ Copyright (C) 2006 Free Software Foundation
+
+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.concurrent;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.lang.reflect.Array;
+import java.util.AbstractList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.RandomAccess;
+
+/** @since 1.5 */
+public class CopyOnWriteArrayList<E> extends AbstractList<E> implements
+ List<E>, RandomAccess, Cloneable, Serializable
+{
+ /**
+ * Where the data is stored.
+ */
+ private transient E[] data;
+
+ /**
+ * Construct a new ArrayList with the default capacity (16).
+ */
+ public CopyOnWriteArrayList()
+ {
+ data = (E[]) new Object[0];
+ }
+
+ /**
+ * Construct a new ArrayList, and initialize it with the elements in the
+ * supplied Collection. The initial capacity is 110% of the Collection's size.
+ *
+ * @param c
+ * the collection whose elements will initialize this list
+ * @throws NullPointerException
+ * if c is null
+ */
+ public CopyOnWriteArrayList(Collection< ? extends E> c)
+ {
+ // FIXME ... correct? use c.toArray()
+ data = (E[]) new Object[c.size()];
+ int index = 0;
+ for (E value : c)
+ data[index++] = value;
+ }
+
+ /**
+ * Construct a new ArrayList, and initialize it with the elements in the
+ * supplied array.
+ *
+ * @param array
+ * the array used to initialize this list
+ * @throws NullPointerException
+ * if array is null
+ */
+ public CopyOnWriteArrayList(E[] array)
+ {
+ data = array.clone();
+ }
+
+ /**
+ * Returns the number of elements in this list.
+ *
+ * @return the list size
+ */
+ public int size()
+ {
+ return data.length;
+ }
+
+ /**
+ * Checks if the list is empty.
+ *
+ * @return true if there are no elements
+ */
+ public boolean isEmpty()
+ {
+ return data.length == 0;
+ }
+
+ /**
+ * Returns true iff element is in this ArrayList.
+ *
+ * @param e
+ * the element whose inclusion in the List is being tested
+ * @return true if the list contains e
+ */
+ public boolean contains(Object e)
+ {
+ return indexOf(e) != -1;
+ }
+
+ /**
+ * Returns the lowest index at which element appears in this List, or -1 if it
+ * does not appear.
+ *
+ * @param e
+ * the element whose inclusion in the List is being tested
+ * @return the index where e was found
+ */
+ public int indexOf(Object e)
+ {
+ E[] data = this.data;
+ for (int i = 0; i < data.length; i++)
+ if (equals(e, data[i]))
+ return i;
+ return -1;
+ }
+
+ /**
+ * Return the lowest index greater equal <code>index</code> at which
+ * <code>e</code> appears in this List, or -1 if it does not
+ * appear.
+ *
+ * @param e the element whose inclusion in the list is being tested
+ * @param index the index at which the search begins
+ * @return the index where <code>e</code> was found
+ */
+ public int indexOf(E e, int index)
+ {
+ E[] data = this.data;
+
+ for (int i = index; i < data.length; i++)
+ if (equals(e, data[i]))
+ return i;
+ return -1;
+ }
+
+ /**
+ * Returns the highest index at which element appears in this List, or -1 if
+ * it does not appear.
+ *
+ * @param e
+ * the element whose inclusion in the List is being tested
+ * @return the index where e was found
+ */
+ public int lastIndexOf(Object e)
+ {
+ E[] data = this.data;
+ for (int i = data.length - 1; i >= 0; i--)
+ if (equals(e, data[i]))
+ return i;
+ return -1;
+ }
+
+ /**
+ * Returns the highest index lesser equal <code>index</code> at
+ * which <code>e</code> appears in this List, or -1 if it does not
+ * appear.
+ *
+ * @param e the element whose inclusion in the list is being tested
+ * @param index the index at which the search begins
+ * @return the index where <code>e</code> was found
+ */
+ public int lastIndexOf(E e, int index)
+ {
+ E[] data = this.data;
+
+ for (int i = index; i >= 0; i--)
+ if (equals(e, data[i]))
+ return i;
+ return -1;
+ }
+
+ /**
+ * Creates a shallow copy of this ArrayList (elements are not cloned).
+ *
+ * @return the cloned object
+ */
+ public Object clone()
+ {
+ CopyOnWriteArrayList<E> clone = null;
+ try
+ {
+ clone = (CopyOnWriteArrayList<E>) super.clone();
+ clone.data = (E[]) data.clone();
+ }
+ catch (CloneNotSupportedException e)
+ {
+ // Impossible to get here.
+ }
+ return clone;
+ }
+
+ /**
+ * Returns an Object array containing all of the elements in this ArrayList.
+ * The array is independent of this list.
+ *
+ * @return an array representation of this list
+ */
+ public Object[] toArray()
+ {
+ E[] data = this.data;
+ E[] array = (E[]) new Object[data.length];
+ System.arraycopy(data, 0, array, 0, data.length);
+ return array;
+ }
+
+ /**
+ * Returns an Array whose component type is the runtime component type of the
+ * passed-in Array. The returned Array is populated with all of the elements
+ * in this ArrayList. If the passed-in Array is not large enough to store all
+ * of the elements in this List, a new Array will be created and returned; if
+ * the passed-in Array is <i>larger</i> than the size of this List, then
+ * size() index will be set to null.
+ *
+ * @param a
+ * the passed-in Array
+ * @return an array representation of this list
+ * @throws ArrayStoreException
+ * if the runtime type of a does not allow an element in this list
+ * @throws NullPointerException
+ * if a is null
+ */
+ public <T> T[] toArray(T[] a)
+ {
+ E[] data = this.data;
+ if (a.length < data.length)
+ a = (T[]) Array.newInstance(a.getClass().getComponentType(), data.length);
+ else if (a.length > data.length)
+ a[data.length] = null;
+ System.arraycopy(data, 0, a, 0, data.length);
+ return a;
+ }
+
+ /**
+ * Retrieves the element at the user-supplied index.
+ *
+ * @param index
+ * the index of the element we are fetching
+ * @throws IndexOutOfBoundsException
+ * if index &lt; 0 || index &gt;= size()
+ */
+ public E get(int index)
+ {
+ return data[index];
+ }
+
+ /**
+ * Sets the element at the specified index. The new element, e, can be an
+ * object of any type or null.
+ *
+ * @param index
+ * the index at which the element is being set
+ * @param e
+ * the element to be set
+ * @return the element previously at the specified index
+ * @throws IndexOutOfBoundsException
+ * if index &lt; 0 || index &gt;= 0
+ */
+ public synchronized E set(int index, E e)
+ {
+ E result = data[index];
+ E[] newData = data.clone();
+ newData[index] = e;
+ data = newData;
+ return result;
+ }
+
+ /**
+ * Appends the supplied element to the end of this list. The element, e, can
+ * be an object of any type or null.
+ *
+ * @param e
+ * the element to be appended to this list
+ * @return true, the add will always succeed
+ */
+ public synchronized boolean add(E e)
+ {
+ E[] data = this.data;
+ E[] newData = (E[]) new Object[data.length + 1];
+ System.arraycopy(data, 0, newData, 0, data.length);
+ newData[data.length] = e;
+ this.data = newData;
+ return true;
+ }
+
+ /**
+ * Adds the supplied element at the specified index, shifting all elements
+ * currently at that index or higher one to the right. The element, e, can be
+ * an object of any type or null.
+ *
+ * @param index
+ * the index at which the element is being added
+ * @param e
+ * the item being added
+ * @throws IndexOutOfBoundsException
+ * if index &lt; 0 || index &gt; size()
+ */
+ public synchronized void add(int index, E e)
+ {
+ E[] data = this.data;
+ E[] newData = (E[]) new Object[data.length + 1];
+ System.arraycopy(data, 0, newData, 0, index);
+ newData[index] = e;
+ System.arraycopy(data, index, newData, index + 1, data.length - index);
+ this.data = newData;
+ }
+
+ /**
+ * Removes the element at the user-supplied index.
+ *
+ * @param index
+ * the index of the element to be removed
+ * @return the removed Object
+ * @throws IndexOutOfBoundsException
+ * if index &lt; 0 || index &gt;= size()
+ */
+ public synchronized E remove(int index)
+ {
+ E[] data = this.data;
+ E[] newData = (E[]) new Object[data.length - 1];
+ System.arraycopy(data, 0, newData, 0, index - 1);
+ System.arraycopy(data, index + 1, newData, index,
+ data.length - index - 1);
+ E r = data[index];
+ this.data = newData;
+ return r;
+ }
+
+ /**
+ * Removes all elements from this List
+ */
+ public synchronized void clear()
+ {
+ data = (E[]) new Object[0];
+ }
+
+ /**
+ * Add each element in the supplied Collection to this List. It is undefined
+ * what happens if you modify the list while this is taking place; for
+ * example, if the collection contains this list. c can contain objects of any
+ * type, as well as null values.
+ *
+ * @param c
+ * a Collection containing elements to be added to this List
+ * @return true if the list was modified, in other words c is not empty
+ * @throws NullPointerException
+ * if c is null
+ */
+ public synchronized boolean addAll(Collection< ? extends E> c)
+ {
+ return addAll(data.length, c);
+ }
+
+ /**
+ * Add all elements in the supplied collection, inserting them beginning at
+ * the specified index. c can contain objects of any type, as well as null
+ * values.
+ *
+ * @param index
+ * the index at which the elements will be inserted
+ * @param c
+ * the Collection containing the elements to be inserted
+ * @throws IndexOutOfBoundsException
+ * if index &lt; 0 || index &gt; 0
+ * @throws NullPointerException
+ * if c is null
+ */
+ public synchronized boolean addAll(int index, Collection< ? extends E> c)
+ {
+ E[] data = this.data;
+ Iterator<? extends E> itr = c.iterator();
+ int csize = c.size();
+ if (csize == 0)
+ return false;
+
+ E[] newData = (E[]) new Object[data.length + csize];
+ System.arraycopy(data, 0, newData, 0, data.length);
+ int end = data.length;
+ for (E value : c)
+ newData[end++] = value;
+ this.data = newData;
+ return true;
+ }
+
+ public synchronized boolean addIfAbsent(E val)
+ {
+ if (contains(val))
+ return false;
+ add(val);
+ return true;
+ }
+
+ public synchronized int addAllAbsent(Collection<? extends E> c)
+ {
+ int result = 0;
+ for (E val : c)
+ {
+ if (addIfAbsent(val))
+ ++result;
+ }
+ return result;
+ }
+
+ /**
+ * Serializes this object to the given stream.
+ *
+ * @param s
+ * the stream to write to
+ * @throws IOException
+ * if the underlying stream fails
+ * @serialData the size field (int), the length of the backing array (int),
+ * followed by its elements (Objects) in proper order.
+ */
+ private void writeObject(ObjectOutputStream s) throws IOException
+ {
+ // The 'size' field.
+ s.defaultWriteObject();
+ // We serialize unused list entries to preserve capacity.
+ int len = data.length;
+ s.writeInt(len);
+ // it would be more efficient to just write "size" items,
+ // this need readObject read "size" items too.
+ for (int i = 0; i < data.length; i++)
+ s.writeObject(data[i]);
+ }
+
+ /**
+ * Deserializes this object from the given stream.
+ *
+ * @param s
+ * the stream to read from
+ * @throws ClassNotFoundException
+ * if the underlying stream fails
+ * @throws IOException
+ * if the underlying stream fails
+ * @serialData the size field (int), the length of the backing array (int),
+ * followed by its elements (Objects) in proper order.
+ */
+ private void readObject(ObjectInputStream s) throws IOException,
+ ClassNotFoundException
+ {
+ // the `size' field.
+ s.defaultReadObject();
+ int capacity = s.readInt();
+ data = (E[]) new Object[capacity];
+ for (int i = 0; i < capacity; i++)
+ data[i] = (E) s.readObject();
+ }
+
+ static final boolean equals(Object o1, Object o2)
+ {
+ return o1 == null ? o2 == null : o1.equals(o2);
+ }
+
+ Object[] getArray()
+ {
+ return data;
+ }
+}
diff --git a/java/util/jar/Attributes.java b/java/util/jar/Attributes.java
index 92d29cf49..329fe6323 100644
--- a/java/util/jar/Attributes.java
+++ b/java/util/jar/Attributes.java
@@ -67,8 +67,8 @@ import java.util.Set;
* @see java.util.jar.Attributes.Name
* @author Mark Wielaard (mark@klomp.org)
*/
-public class Attributes
- implements Cloneable, java.util.Map // Fully qualified for jikes 1.22
+public class Attributes
+ implements Cloneable, Map<Object, Object>
{
// Fields
@@ -78,7 +78,7 @@ public class Attributes
* implementation it is actually a Hashtable, but that can be different in
* other implementations.
*/
- protected Map map;
+ protected Map<Object, Object> map;
// Inner class
@@ -492,7 +492,7 @@ public class Attributes
*
* @return a set of attribute name value pairs
*/
- public Set entrySet()
+ public Set<Map.Entry<Object, Object>> entrySet()
{
return map.entrySet();
}
@@ -558,7 +558,7 @@ public class Attributes
/**
* Gives a Set of all the values of defined attribute names.
*/
- public Set keySet()
+ public Set<Object> keySet()
{
return map.keySet();
}
@@ -587,7 +587,7 @@ public class Attributes
* @exception ClassCastException if the supplied map is not an instance of
* Attributes
*/
- public void putAll(Map attr)
+ public void putAll(Map<?, ?> attr)
{
if (!(attr instanceof Attributes))
{
@@ -622,7 +622,7 @@ public class Attributes
* Returns all the values of the defined attribute name/value pairs as a
* Collection.
*/
- public Collection values()
+ public Collection<Object> values()
{
return map.values();
}
diff --git a/java/util/jar/JarFile.java b/java/util/jar/JarFile.java
index 4416662a3..680773659 100644
--- a/java/util/jar/JarFile.java
+++ b/java/util/jar/JarFile.java
@@ -321,7 +321,7 @@ public class JarFile extends ZipFile
*
* @exception IllegalStateException when the JarFile is already closed
*/
- public Enumeration entries() throws IllegalStateException
+ public Enumeration<JarEntry> entries() throws IllegalStateException
{
return new JarEnumeration(super.entries(), this);
}
@@ -330,13 +330,13 @@ public class JarFile extends ZipFile
* Wraps a given Zip Entries Enumeration. For every zip entry a
* JarEntry is created and the corresponding Attributes are looked up.
*/
- private static class JarEnumeration implements Enumeration
+ private static class JarEnumeration implements Enumeration<JarEntry>
{
- private final Enumeration entries;
+ private final Enumeration<? extends ZipEntry> entries;
private final JarFile jarfile;
- JarEnumeration(Enumeration e, JarFile f)
+ JarEnumeration(Enumeration<? extends ZipEntry> e, JarFile f)
{
entries = e;
jarfile = f;
@@ -347,7 +347,7 @@ public class JarFile extends ZipFile
return entries.hasMoreElements();
}
- public Object nextElement()
+ public JarEntry nextElement()
{
ZipEntry zip = (ZipEntry) entries.nextElement();
JarEntry jar = new JarEntry(zip);
diff --git a/java/util/jar/Manifest.java b/java/util/jar/Manifest.java
index 64a0c476a..8effc2878 100644
--- a/java/util/jar/Manifest.java
+++ b/java/util/jar/Manifest.java
@@ -38,7 +38,7 @@ exception statement from your version. */
package java.util.jar;
import gnu.java.util.jar.JarUtils;
-
+
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -60,7 +60,7 @@ public class Manifest implements Cloneable
private final Attributes mainAttr;
/** A map of atrributes for all entries described in this Manifest. */
- private final Map entries;
+ private final Map<String, Attributes> entries;
// Constructors
@@ -70,7 +70,7 @@ public class Manifest implements Cloneable
public Manifest()
{
mainAttr = new Attributes();
- entries = new Hashtable();
+ entries = new Hashtable<String, Attributes>();
}
/**
@@ -104,7 +104,7 @@ public class Manifest implements Cloneable
public Manifest(Manifest man)
{
mainAttr = new Attributes(man.getMainAttributes());
- entries = new Hashtable(man.getEntries());
+ entries = new Hashtable<String, Attributes>(man.getEntries());
}
// Methods
@@ -122,7 +122,7 @@ public class Manifest implements Cloneable
* in this manifest. Adding, changing or removing from this entries map
* changes the entries of this manifest.
*/
- public Map getEntries()
+ public Map<String, Attributes> getEntries()
{
return entries;
}
diff --git a/java/util/logging/LogManager.java b/java/util/logging/LogManager.java
index aec63633a..fbc0fe78a 100644
--- a/java/util/logging/LogManager.java
+++ b/java/util/logging/LogManager.java
@@ -129,7 +129,7 @@ public class LogManager
* The registered named loggers; maps the name of a Logger to
* a WeakReference to it.
*/
- private Map loggers;
+ private Map<String, WeakReference<Logger>> loggers;
/**
* The properties for the logging framework which have been
@@ -150,7 +150,7 @@ public class LogManager
* this case.
*/
private final PropertyChangeSupport pcs = new PropertyChangeSupport( /* source bean */
- LogManager.class);
+ LogManager.class);
protected LogManager()
{
@@ -269,7 +269,7 @@ public class LogManager
*/
name = logger.getName();
- ref = (WeakReference) loggers.get(name);
+ ref = loggers.get(name);
if (ref != null)
{
if (ref.get() != null)
@@ -286,7 +286,7 @@ public class LogManager
checkAccess();
Logger parent = findAncestor(logger);
- loggers.put(name, new WeakReference(logger));
+ loggers.put(name, new WeakReference<Logger>(logger));
if (parent != logger.getParent())
logger.setParent(parent);
@@ -334,7 +334,7 @@ public class LogManager
possChild.setParent(logger);
}
-
+
return true;
}
@@ -362,15 +362,13 @@ public class LogManager
int bestNameLength = 0;
Logger cand;
- String candName;
int candNameLength;
if (child == Logger.root)
return null;
- for (Iterator iter = loggers.keySet().iterator(); iter.hasNext();)
+ for (String candName : loggers.keySet())
{
- candName = (String) iter.next();
candNameLength = candName.length();
if (candNameLength > bestNameLength
@@ -378,7 +376,7 @@ public class LogManager
&& childName.startsWith(candName)
&& childName.charAt(candNameLength) == '.')
{
- cand = (Logger) ((WeakReference) loggers.get(candName)).get();
+ cand = loggers.get(candName).get();
if ((cand == null) || (cand == child))
continue;
@@ -403,14 +401,14 @@ public class LogManager
*/
public synchronized Logger getLogger(String name)
{
- WeakReference ref;
+ WeakReference<Logger> ref;
/* Throw a NullPointerException if name is null. */
name.getClass();
- ref = (WeakReference) loggers.get(name);
+ ref = loggers.get(name);
if (ref != null)
- return (Logger) ref.get();
+ return ref.get();
else
return null;
}
@@ -423,7 +421,7 @@ public class LogManager
* @return an Enumeration with the names of the currently
* registered Loggers.
*/
- public synchronized Enumeration getLoggerNames()
+ public synchronized Enumeration<String> getLoggerNames()
{
return Collections.enumeration(loggers.keySet());
}
@@ -446,16 +444,16 @@ public class LogManager
properties = new Properties();
- Iterator iter = loggers.values().iterator();
+ Iterator<WeakReference<Logger>> iter = loggers.values().iterator();
while (iter.hasNext())
+ for (WeakReference<Logger> ref : loggers.values())
{
- WeakReference ref;
Logger logger;
- ref = (WeakReference) iter.next();
+ ref = iter.next();
if (ref != null)
{
- logger = (Logger) ref.get();
+ logger = ref.get();
if (logger == null)
iter.remove();
diff --git a/java/util/logging/LoggingMXBean.java b/java/util/logging/LoggingMXBean.java
index 5f866c980..3e0a7276d 100644
--- a/java/util/logging/LoggingMXBean.java
+++ b/java/util/logging/LoggingMXBean.java
@@ -60,7 +60,7 @@ public interface LoggingMXBean
/**
* Return a list of all logger names.
*/
- List/*<String>*/ getLoggerNames();
+ List<String> getLoggerNames();
/**
* Return the name of the parent of the indicated logger.
diff --git a/java/util/prefs/Preferences.java b/java/util/prefs/Preferences.java
index 297759d88..e53e4fc79 100644
--- a/java/util/prefs/Preferences.java
+++ b/java/util/prefs/Preferences.java
@@ -251,7 +251,7 @@ public abstract class Preferences {
* @exception SecurityException when a security manager is installed and
* the caller does not have <code>RuntimePermission("preferences")</code>.
*/
- public static Preferences systemNodeForPackage(Class c)
+ public static Preferences systemNodeForPackage(Class<?> c)
throws SecurityException
{
return nodeForPackage(c, systemRoot());
@@ -270,7 +270,7 @@ public abstract class Preferences {
* @exception SecurityException when a security manager is installed and
* the caller does not have <code>RuntimePermission("preferences")</code>.
*/
- public static Preferences userNodeForPackage(Class c)
+ public static Preferences userNodeForPackage(Class<?> c)
throws SecurityException
{
return nodeForPackage(c, userRoot());
diff --git a/java/util/zip/Deflater.java b/java/util/zip/Deflater.java
index a4ec0e643..e97c6054f 100644
--- a/java/util/zip/Deflater.java
+++ b/java/util/zip/Deflater.java
@@ -1,5 +1,5 @@
/* Deflater.java - Compress a data stream
- Copyright (C) 1999, 2000, 2001, 2004 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2000, 2001, 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -150,7 +150,7 @@ public class Deflater
private int state;
/** The total bytes of output written. */
- private int totalOut;
+ private long totalOut;
/** The pending output. */
private DeflaterPending pending;
@@ -241,16 +241,36 @@ public class Deflater
/**
* Gets the number of input bytes processed so far.
*/
+ @Deprecated
public int getTotalIn()
{
+ return (int) engine.getTotalIn();
+ }
+
+ /**
+ * Gets the number of input bytes processed so far.
+ * @since 1.5
+ */
+ public long getBytesRead()
+ {
return engine.getTotalIn();
}
/**
* Gets the number of output bytes so far.
*/
+ @Deprecated
public int getTotalOut()
{
+ return (int) totalOut;
+ }
+
+ /**
+ * Gets the number of output bytes so far.
+ * @since 1.5
+ */
+ public long getBytesWritten()
+ {
return totalOut;
}
diff --git a/java/util/zip/DeflaterEngine.java b/java/util/zip/DeflaterEngine.java
index f79e47742..51587165e 100644
--- a/java/util/zip/DeflaterEngine.java
+++ b/java/util/zip/DeflaterEngine.java
@@ -1,5 +1,5 @@
/* DeflaterEngine.java --
- Copyright (C) 2001, 2004 Free Software Foundation, Inc.
+ Copyright (C) 2001, 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -92,7 +92,7 @@ class DeflaterEngine implements DeflaterConstants
private byte[] inputBuf;
/** The total bytes of input read. */
- private int totalIn;
+ private long totalIn;
/** The offset into inputBuf, where input data starts. */
private int inputOff;
@@ -163,7 +163,7 @@ class DeflaterEngine implements DeflaterConstants
return chksum;
}
- public final int getTotalIn()
+ public final long getTotalIn()
{
return totalIn;
}
diff --git a/java/util/zip/Inflater.java b/java/util/zip/Inflater.java
index f1616d601..509b95764 100644
--- a/java/util/zip/Inflater.java
+++ b/java/util/zip/Inflater.java
@@ -140,13 +140,13 @@ public class Inflater
/**
* The total number of inflated bytes.
*/
- private int totalOut;
+ private long totalOut;
/**
* The total number of bytes set with setInput(). This is not the
* value returned by getTotalIn(), since this also includes the
* unprocessed input.
*/
- private int totalIn;
+ private long totalIn;
/**
* This variable stores the nowrap flag that was given to the constructor.
* True means, that the inflated stream doesn't contain a header nor the
@@ -246,8 +246,19 @@ public class Inflater
* Gets the total number of processed compressed input bytes.
* @return the total number of bytes of processed input bytes.
*/
+ @Deprecated
public int getTotalIn()
{
+ return (int) (totalIn - getRemaining());
+ }
+
+ /**
+ * Gets the total number of processed compressed input bytes.
+ * @return the total number of bytes of processed input bytes.
+ * @since 1.5
+ */
+ public long getBytesRead()
+ {
return totalIn - getRemaining();
}
@@ -255,8 +266,19 @@ public class Inflater
* Gets the total number of output bytes returned by inflate().
* @return the total number of output bytes.
*/
+ @Deprecated
public int getTotalOut()
{
+ return (int) totalOut;
+ }
+
+ /**
+ * Gets the total number of output bytes returned by inflate().
+ * @return the total number of output bytes.
+ * @since 1.5
+ */
+ public long getBytesWritten()
+ {
return totalOut;
}
diff --git a/java/util/zip/ZipFile.java b/java/util/zip/ZipFile.java
index 2bae2eb1f..3b34bd1f5 100644
--- a/java/util/zip/ZipFile.java
+++ b/java/util/zip/ZipFile.java
@@ -91,7 +91,7 @@ public class ZipFile implements ZipConstants
private final RandomAccessFile raf;
// The entries of this zip file when initialized and not yet closed.
- private LinkedHashMap entries;
+ private LinkedHashMap<String, ZipEntry> entries;
private boolean closed = false;
@@ -253,7 +253,7 @@ public class ZipFile implements ZipConstants
throw new EOFException(name);
int centralOffset = inp.readLeInt();
- entries = new LinkedHashMap(count+count/2);
+ entries = new LinkedHashMap<String, ZipEntry> (count+count/2);
inp.seek(centralOffset);
for (int i = 0; i < count; i++)
@@ -330,7 +330,7 @@ public class ZipFile implements ZipConstants
*
* @exception IllegalStateException when the ZipFile has already been closed
*/
- public Enumeration entries()
+ public Enumeration<? extends ZipEntry> entries()
{
checkClosed();
@@ -350,7 +350,7 @@ public class ZipFile implements ZipConstants
* @exception IllegalStateException when the ZipFile has already been closed.
* @exception IOException when the entries could not be read.
*/
- private LinkedHashMap getEntries() throws IOException
+ private LinkedHashMap<String, ZipEntry> getEntries() throws IOException
{
synchronized(raf)
{
@@ -378,11 +378,11 @@ public class ZipFile implements ZipConstants
try
{
- LinkedHashMap entries = getEntries();
- ZipEntry entry = (ZipEntry) entries.get(name);
+ LinkedHashMap<String, ZipEntry> entries = getEntries();
+ ZipEntry entry = entries.get(name);
// If we didn't find it, maybe it's a directory.
if (entry == null && !name.endsWith("/"))
- entry = (ZipEntry) entries.get(name + '/');
+ entry = entries.get(name + '/');
return entry != null ? new ZipEntry(entry, name) : null;
}
catch (IOException ioe)
@@ -417,9 +417,9 @@ public class ZipFile implements ZipConstants
{
checkClosed();
- LinkedHashMap entries = getEntries();
+ LinkedHashMap<String, ZipEntry> entries = getEntries();
String name = entry.getName();
- ZipEntry zipEntry = (ZipEntry) entries.get(name);
+ ZipEntry zipEntry = entries.get(name);
if (zipEntry == null)
return null;
@@ -494,11 +494,11 @@ public class ZipFile implements ZipConstants
}
}
- private static class ZipEntryEnumeration implements Enumeration
+ private static class ZipEntryEnumeration implements Enumeration<ZipEntry>
{
- private final Iterator elements;
+ private final Iterator<ZipEntry> elements;
- public ZipEntryEnumeration(Iterator elements)
+ public ZipEntryEnumeration(Iterator<ZipEntry> elements)
{
this.elements = elements;
}
@@ -508,12 +508,12 @@ public class ZipFile implements ZipConstants
return elements.hasNext();
}
- public Object nextElement()
+ public ZipEntry nextElement()
{
/* We return a clone, just to be safe that the user doesn't
* change the entry.
*/
- return ((ZipEntry)elements.next()).clone();
+ return (ZipEntry) (elements.next().clone());
}
}