classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cp-patches] [generics] Patch: FYI: more genericization


From: Tom Tromey
Subject: [cp-patches] [generics] Patch: FYI: more genericization
Date: 06 Dec 2005 17:43:47 -0700
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50

I'm checking this in on the generics branch.

Even more genericization that I somehow missed earlier.  I really
suspect japi is just feeding me methods and classes piecemeal somehow
:-)

This one includes some real bug fixes in javax.imageio.  An earlier
patch I made to ImageIO was in error, so I more fully genericized this
class in order to catch bugs.  I think this is the first batch of
actual bugs caught by genericization -- which is nice but hardly
stellar for a safety feature.  Another way to look at it is that we're
really great and hardly make mistakes in this area :-)

The ImageIO fixes should be back-ported to the trunk.  I'll try to do
that.

There's a bit more genericization to come, and then of course whatever
japi coughs up in a couple of days.

Tom


2005-12-06  Tom Tromey  <address@hidden>

        * javax/imageio/ImageIO.java (ImageReaderIterator): Genericized.
        Added new constructor.
        (ImageWriterIterator): Likewise.
        (getReadersByFilter): Genericized.
        (getWritersByFilter): Likewise.
        (getImageReadersBySuffix): Likewise.
        (getImageWriters): Likewise.
        (hasNext): Likewise.
        * javax/print/attribute/AttributeSetUtilities.java
        (verifyAttributeCategory): Genericized.
        (verifyAttributeValue): Likewise.
        (verifyCategoryForValue): Likewise.
        * javax/print/attribute/AttributeSet.java (containsKey): Genericized.
        (get): Likewise.
        (remove): Likewise.
        * javax/print/attribute/Attribute.java (getCategory): Genericized.
        * javax/print/attribute/HashAttributeSet.java (HashAttributeSet):
        Genericized.
        (containsKey): Likewise.
        * javax/imageio/spi/ServiceRegistry.java (deregisterAll):
        Genericized.
        * javax/imageio/spi/IIOServiceProvider.java (onDeregistration):
        Genericized.
        (onRegistration): Likewise.
        * javax/imageio/metadata/IIOMetadataFormatImpl.java (getObjectClass):
        Genericized.
        (getObjectMaxValue): Likewise.
        (getObjectMinValue): Likewise.
        * javax/imageio/ImageIO.java (getImageReadersBySuffix): Genericized.
        (getImageWriters): Likewise.

Index: javax/imageio/ImageIO.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/imageio/ImageIO.java,v
retrieving revision 1.4.2.8
diff -u -r1.4.2.8 ImageIO.java
--- javax/imageio/ImageIO.java  1 Dec 2005 15:09:47 -0000       1.4.2.8
+++ javax/imageio/ImageIO.java  7 Dec 2005 00:46:23 -0000
@@ -315,27 +315,37 @@
     }
   }
 
-  private static final class ImageReaderIterator implements Iterator
+  private static final class ImageReaderIterator
+    implements Iterator<ImageReader>
   {
-    Iterator it;
+    Iterator<ImageReaderSpi> it;
     Object readerExtension;
     
-    public ImageReaderIterator(Iterator it, Object readerExtension)
+    public ImageReaderIterator(Iterator<ImageReaderSpi> it,
+                               Object readerExtension)
     {
       this.it = it;
       this.readerExtension = readerExtension;
     }
+    
+    public ImageReaderIterator(Iterator<ImageReaderSpi> it)
+    {
+      this.it = it;
+    }
 
     public boolean hasNext()
     {
       return it.hasNext();
     }
 
-    public Object next()
+    public ImageReader next()
     {
       try
         {
-          return ((ImageReaderSpi) 
it.next()).createReaderInstance(readerExtension);
+          ImageReaderSpi spi = it.next();
+          return (readerExtension == null
+              ? spi.createReaderInstance()
+              : spi.createReaderInstance(readerExtension));
         }
       catch (IOException e)
         {
@@ -349,27 +359,37 @@
     }
   }
 
-  private static final class ImageWriterIterator implements Iterator
+  private static final class ImageWriterIterator
+    implements Iterator<ImageWriter>
   {
-    Iterator it;
+    Iterator<ImageWriterSpi> it;
     Object writerExtension;
     
-    public ImageWriterIterator(Iterator it, Object writerExtension)
+    public ImageWriterIterator(Iterator<ImageWriterSpi> it,
+                               Object writerExtension)
     {
       this.it = it;
       this.writerExtension = writerExtension;
     }
+    
+    public ImageWriterIterator(Iterator<ImageWriterSpi> it)
+    {
+      this.it = it;
+    }
 
     public boolean hasNext()
     {
       return it.hasNext();
     }
 
-    public Object next()
+    public ImageWriter next()
     {
       try
         {
-          return ((ImageWriterSpi) 
it.next()).createWriterInstance(writerExtension);
+          ImageWriterSpi spi = it.next();
+          return (writerExtension == null
+              ? spi.createWriterInstance()
+              : spi.createWriterInstance(writerExtension));
         }
       catch (IOException e)
         {
@@ -386,13 +406,14 @@
   private static File cacheDirectory;
   private static boolean useCache = true;
 
-  private static Iterator getReadersByFilter(Class type,
-                                             ServiceRegistry.Filter filter,
-                                             Object readerExtension)
+  private static Iterator<ImageReader> 
getReadersByFilter(Class<ImageReaderSpi> type,
+                                                          
ServiceRegistry.Filter filter,
+                                                          Object 
readerExtension)
   {
     try
       {
-        Iterator it = getRegistry().getServiceProviders(type, filter, true);
+        Iterator<ImageReaderSpi> it
+          = getRegistry().getServiceProviders(type, filter, true);
         return new ImageReaderIterator(it, readerExtension);
       }
     catch (IllegalArgumentException e)
@@ -401,13 +422,14 @@
       }
   }
   
-  private static Iterator getWritersByFilter(Class type,
-                                            ServiceRegistry.Filter filter,
-                                             Object writerExtension)
+  private static Iterator<ImageWriter> 
getWritersByFilter(Class<ImageWriterSpi> type,
+                                                          
ServiceRegistry.Filter filter,
+                                                          Object 
writerExtension)
   {
     try
       {
-        Iterator it = getRegistry().getServiceProviders(type, filter, true);
+        Iterator<ImageWriterSpi> it
+          = getRegistry().getServiceProviders(type, filter, true);
         return new ImageWriterIterator(it, writerExtension);
       }
     catch (IllegalArgumentException e)
@@ -477,7 +499,7 @@
    *
    * @exception IllegalArgumentException if fileSuffix is null
    */
-  public static Iterator getImageReadersBySuffix(String fileSuffix)
+  public static Iterator<ImageReader> getImageReadersBySuffix(String 
fileSuffix)
   {
     if (fileSuffix == null)
       throw new IllegalArgumentException("formatName may not be null");
@@ -1102,9 +1124,11 @@
     if (input == null)
       throw new IllegalArgumentException ("null argument");
 
-    return getRegistry().getServiceProviders (ImageReader.class,
-                                             new ReaderObjectFilter(input),
-                                             true);
+    Iterator<ImageReaderSpi> spiIterator
+      = getRegistry().getServiceProviders (ImageReaderSpi.class,
+                                           new ReaderObjectFilter(input),
+                                           true);
+    return new ImageReaderIterator(spiIterator);
   }
 
   /**
@@ -1117,16 +1141,18 @@
    *
    * @return an iterator over a collection of image writers
    */
-  public static Iterator getImageWriters (ImageTypeSpecifier type,
+  public static Iterator<ImageWriter> getImageWriters (ImageTypeSpecifier type,
                                          String formatName)
   {
     if (type == null || formatName == null)
       throw new IllegalArgumentException ("null argument");
 
-    return getRegistry().getServiceProviders (ImageWriterSpi.class,
-                                             new WriterObjectFilter(type,
-                                                                     
formatName),
-                                             true);
+    final Iterator<ImageWriterSpi> spiIterator
+      = getRegistry().getServiceProviders (ImageWriterSpi.class,
+                                           new WriterObjectFilter(type,
+                                                                  formatName),
+                                                                  true);
+    return new ImageWriterIterator(spiIterator);
   }
 
   /**
@@ -1188,9 +1214,27 @@
     if (reader == null || writer == null)
       throw new IllegalArgumentException ("null argument");
 
-    return getRegistry().getServiceProviders (ImageTranscoder.class,
-                                             new TranscoderFilter (reader,
-                                                                    writer),
-                                             true);
+    final Iterator<ImageTranscoderSpi> spiIterator
+      = getRegistry().getServiceProviders (ImageTranscoderSpi.class,
+                                           new TranscoderFilter (reader,
+                                                                 writer),
+                                           true);
+    return new Iterator<ImageTranscoder>()
+    {
+      public boolean hasNext()
+      {
+        return spiIterator.hasNext();
+      }
+      
+      public ImageTranscoder next()
+      {
+        return spiIterator.next().createTranscoderInstance();
+      }
+      
+      public void remove()
+      {
+        throw new UnsupportedOperationException();
+      }
+    };
   }
 }
Index: javax/imageio/metadata/IIOMetadataFormatImpl.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/javax/imageio/metadata/IIOMetadataFormatImpl.java,v
retrieving revision 1.1.2.4
diff -u -r1.1.2.4 IIOMetadataFormatImpl.java
--- javax/imageio/metadata/IIOMetadataFormatImpl.java   1 Dec 2005 15:09:47 
-0000       1.1.2.4
+++ javax/imageio/metadata/IIOMetadataFormatImpl.java   7 Dec 2005 00:46:24 
-0000
@@ -836,7 +836,7 @@
     return ((Integer) ((NodeObjectArray) getNodeObject 
(node)).getArrayMinLength ()).intValue();
   }
 
-  public Class getObjectClass (String elementName)
+  public Class<?> getObjectClass (String elementName)
   {
     IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
     return getNodeObject (node).getClassType ();
@@ -854,13 +854,13 @@
     return ((NodeObjectEnumerated) getNodeObject (node)).getEnumerations ();
   }
 
-  public Comparable getObjectMaxValue (String elementName)
+  public Comparable<?> getObjectMaxValue (String elementName)
   {
     IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
     return ((NodeObjectBounded) getNodeObject (node)).getMaxValue ();
   }
 
-  public Comparable getObjectMinValue (String elementName)
+  public Comparable<?> getObjectMinValue (String elementName)
   {
     IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
     return ((NodeObjectBounded) getNodeObject (node)).getMinValue ();
Index: javax/imageio/spi/IIOServiceProvider.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/javax/imageio/spi/IIOServiceProvider.java,v
retrieving revision 1.1.2.2
diff -u -r1.1.2.2 IIOServiceProvider.java
--- javax/imageio/spi/IIOServiceProvider.java   2 Aug 2005 20:12:35 -0000       
1.1.2.2
+++ javax/imageio/spi/IIOServiceProvider.java   7 Dec 2005 00:46:24 -0000
@@ -110,7 +110,7 @@
    * @param category the service category for which this provider has
    * been registered as an implementor.
    */
-  public void onRegistration(ServiceRegistry registry, Class category)
+  public void onRegistration(ServiceRegistry registry, Class<?> category)
   {
   }
 
@@ -128,7 +128,7 @@
    * @param category the service category for which this provider has
    * been registered as an implementor.
    */
-  public void onDeregistration(ServiceRegistry registry, Class category)
+  public void onDeregistration(ServiceRegistry registry, Class<?> category)
   {
   }
 
Index: javax/imageio/spi/ServiceRegistry.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/imageio/spi/ServiceRegistry.java,v
retrieving revision 1.1.2.5
diff -u -r1.1.2.5 ServiceRegistry.java
--- javax/imageio/spi/ServiceRegistry.java      1 Dec 2005 15:09:47 -0000       
1.1.2.5
+++ javax/imageio/spi/ServiceRegistry.java      7 Dec 2005 00:46:24 -0000
@@ -535,7 +535,7 @@
    * #ServiceRegistry(Iterator) constructor} of this
    * <code>ServiceRegistry</code>.
    */
-  public synchronized void deregisterAll(Class category)
+  public synchronized void deregisterAll(Class<?> category)
   {
     boolean ok = false;
 
Index: javax/print/attribute/Attribute.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/print/attribute/Attribute.java,v
retrieving revision 1.2.2.2
diff -u -r1.2.2.2 Attribute.java
--- javax/print/attribute/Attribute.java        27 Nov 2005 21:00:37 -0000      
1.2.2.2
+++ javax/print/attribute/Attribute.java        7 Dec 2005 00:46:24 -0000
@@ -52,7 +52,7 @@
    * 
    * @return The concrete address@hidden Class} instance of the attribute 
class.
    */
-  Class getCategory ();
+  Class<?> getCategory ();
 
   /**
    * Returns the descriptive name of the attribute category.
Index: javax/print/attribute/AttributeSet.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/print/attribute/AttributeSet.java,v
retrieving revision 1.2.2.2
diff -u -r1.2.2.2 AttributeSet.java
--- javax/print/attribute/AttributeSet.java     27 Nov 2005 21:00:37 -0000      
1.2.2.2
+++ javax/print/attribute/AttributeSet.java     7 Dec 2005 00:46:24 -0000
@@ -110,7 +110,7 @@
    * @return <code>true</code> if an attribute of the category is contained
    * in the set, <code>false</code> otherwise.
    */
-  boolean containsKey (Class category);
+  boolean containsKey (Class<?> category);
   
   /**
    * Checks if this attribute set contains the given attribute.
@@ -143,7 +143,7 @@
    * @throws ClassCastException if category is not implementing 
    * <code>Attribute</code>.
    */
-  Attribute get (Class category);
+  Attribute get (Class<?> category);
   
   /**
    * Returns the hashcode value. The hashcode value is the sum of all hashcodes
@@ -178,7 +178,7 @@
    * @return <code>true</code> if an attribute is removed, false in all other 
cases. 
    * @throws UnmodifiableSetException if the set does not support modification.
    */
-  boolean remove (Class category);
+  boolean remove (Class<?> category);
   
   /**
    * Returns the number of elements in this attribute set.
Index: javax/print/attribute/AttributeSetUtilities.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/javax/print/attribute/AttributeSetUtilities.java,v
retrieving revision 1.2.2.3
diff -u -r1.2.2.3 AttributeSetUtilities.java
--- javax/print/attribute/AttributeSetUtilities.java    27 Nov 2005 21:00:37 
-0000      1.2.2.3
+++ javax/print/attribute/AttributeSetUtilities.java    7 Dec 2005 00:46:24 
-0000
@@ -435,8 +435,8 @@
    * that implements interfaceName
    * @exception NullPointerException if object is null
    */
-  public static Class verifyAttributeCategory(Object object,
-                                              Class interfaceName)
+  public static Class<?> verifyAttributeCategory(Object object,
+                                                 Class<?> interfaceName)
   {
     if (object == null)
       throw new NullPointerException("object may not be null");
@@ -461,7 +461,7 @@
    * @exception NullPointerException if object is null
    */
   public static Attribute verifyAttributeValue(Object object,
-                                               Class interfaceName)
+                                               Class<?> interfaceName)
   {
     if (object == null)
       throw new NullPointerException("object may not be null");
@@ -482,7 +482,7 @@
    * @exception IllegalArgumentException if the categories are not equal
    * @exception NullPointerException if category is null
    */
-  public static void verifyCategoryForValue(Class category,
+  public static void verifyCategoryForValue(Class<?> category,
                                             Attribute attribute)
   {
     if (category == null || attribute == null)
Index: javax/print/attribute/HashAttributeSet.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/javax/print/attribute/HashAttributeSet.java,v
retrieving revision 1.3.2.2
diff -u -r1.3.2.2 HashAttributeSet.java
--- javax/print/attribute/HashAttributeSet.java 27 Nov 2005 21:00:37 -0000      
1.3.2.2
+++ javax/print/attribute/HashAttributeSet.java 7 Dec 2005 00:46:24 -0000
@@ -107,7 +107,7 @@
    *
    * @exception NullPointerException if interfaceName is null
    */
-  protected HashAttributeSet(Class interfaceName)
+  protected HashAttributeSet(Class<?> interfaceName)
   {
     if (interfaceName == null)
       throw new NullPointerException("interfaceName may not be null");
@@ -126,7 +126,7 @@
    * interfaceName
    * @exception NullPointerException if attribute or interfaceName is null
    */
-  protected HashAttributeSet(Attribute attribute, Class interfaceName)
+  protected HashAttributeSet(Attribute attribute, Class<?> interfaceName)
   {
     this(interfaceName);
     
@@ -148,7 +148,7 @@
    * interface of interfaceName
    * @exception NullPointerException if attributes or interfaceName is null
    */
-  protected HashAttributeSet(Attribute[] attributes, Class interfaceName)
+  protected HashAttributeSet(Attribute[] attributes, Class<?> interfaceName)
   {
     this(interfaceName);
     
@@ -170,7 +170,7 @@
    * @exception ClassCastException if any element of attributes is not an
    * interface of interfaceName
    */
-  protected HashAttributeSet(AttributeSet attributes, Class interfaceName)
+  protected HashAttributeSet(AttributeSet attributes, Class<?> interfaceName)
   {
     this(interfaceName);
     
@@ -253,7 +253,7 @@
    * @return <code>true</code> if an attribute of the category is contained
    * in the set, <code>false</code> otherwise.
    */
-  public boolean containsKey(Class category)
+  public boolean containsKey(Class<?> category)
   {
     return attributeMap.containsKey(category);
   }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]