rather than recreating an empty array in lots of places ..

-- 
Cheers,

Peter Donald
'Most men would rather die than think. Many do.'
                             Bertrand Russell
Index: src/java/org/apache/avalon/framework/info/Attribute.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-avalon-excalibur/info/src/java/org/apache/avalon/framework/info/Attribute.java,v
retrieving revision 1.6
diff -u -r1.6 Attribute.java
--- src/java/org/apache/avalon/framework/info/Attribute.java    11 Nov 2002 23:56:53 
-0000      1.6
+++ src/java/org/apache/avalon/framework/info/Attribute.java    26 Nov 2002 09:58:58 
+-0000
@@ -24,7 +24,15 @@
 public final class Attribute
     implements Serializable
 {
-    private static final String[] EMPTY_SET = new String[ 0 ];
+    /**
+     * An empty array of attributes.
+     */
+    public static final Attribute[] EMPTY_SET = new Attribute[ 0 ];
+
+    /**
+     * To save memory always return same emtpy array of names
+     */
+    private static final String[] EMPTY_NAME_SET = new String[ 0 ];
 
     /**
      * The name of the Attribute.
@@ -49,10 +57,6 @@
         {
             throw new NullPointerException( "name" );
         }
-        if( null == parameters )
-        {
-            throw new NullPointerException( "parameters" );
-        }
 
         m_name = name;
         m_parameters = parameters;
@@ -112,16 +116,23 @@
     {
         if( null == m_parameters )
         {
-            return EMPTY_SET;
+            return EMPTY_NAME_SET;
         }
         else
         {
-            return (String[])m_parameters.keySet().toArray( EMPTY_SET );
+            return (String[])m_parameters.keySet().toArray( EMPTY_NAME_SET );
         }
     }
 
     public String toString()
     {
-        return getName() + m_parameters;
+        if( null != m_parameters )
+        {
+            return getName() + m_parameters;
+        }
+        else
+        {
+            return getName();
+        }
     }
 }
Index: 
src/java/org/apache/avalon/framework/tools/infobuilder/LegacyBlockInfoReader.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-avalon-excalibur/info/src/java/org/apache/avalon/framework/tools/infobuilder/LegacyBlockInfoReader.java,v
retrieving revision 1.6
diff -u -r1.6 LegacyBlockInfoReader.java
--- src/java/org/apache/avalon/framework/tools/infobuilder/LegacyBlockInfoReader.java  
 24 Nov 2002 12:15:26 -0000      1.6
+++ src/java/org/apache/avalon/framework/tools/infobuilder/LegacyBlockInfoReader.java  
+ 26 Nov 2002 09:58:59 -0000
@@ -141,7 +141,7 @@
         {
             //TODO: Map phoenix type to uri space when figured out
             return new SchemaDescriptor( "",
-                                         schemaType, new Attribute[ 0 ] );
+                                         schemaType, Attribute.EMPTY_SET );
         }
 
     }
@@ -156,7 +156,7 @@
     {
         return new ContextDescriptor( "org.apache.avalon.phoenix.BlockContext",
                                       new EntryDescriptor[ 0 ],
-                                      new Attribute[ 0 ] );
+                                      Attribute.EMPTY_SET );
     }
 
     /**
@@ -224,7 +224,7 @@
         return new DependencyDescriptor( key,
                                          implementationKey,
                                          false,
-                                         new Attribute[ 0 ] );
+                                         Attribute.EMPTY_SET );
     }
 
     /**
Index: src/java/org/apache/avalon/framework/tools/infobuilder/XMLInfoReader.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-avalon-excalibur/info/src/java/org/apache/avalon/framework/tools/infobuilder/XMLInfoReader.java,v
retrieving revision 1.5
diff -u -r1.5 XMLInfoReader.java
--- src/java/org/apache/avalon/framework/tools/infobuilder/XMLInfoReader.java   24 Nov 
2002 12:15:26 -0000      1.5
+++ src/java/org/apache/avalon/framework/tools/infobuilder/XMLInfoReader.java   26 Nov 
+2002 09:59:00 -0000
@@ -114,7 +114,7 @@
 
         configuration = info.getChild( "parameters-schema", false );
         final SchemaDescriptor parametersSchema = buildSchema( configuration );
-        
+
         if( getLogger().isDebugEnabled() )
         {
             final String message =
@@ -399,7 +399,14 @@
     {
         final String name = config.getAttribute( "name" );
         final Properties parameters = buildParameters( config );
-        return new Attribute( name, parameters );
+        if( 0 == parameters.size() )
+        {
+            return new Attribute( name, null );
+        }
+        else
+        {
+            return new Attribute( name, parameters );
+        }
     }
 
     /**
Index: src/java/org/apache/avalon/framework/tools/qdox/AbstractInfoBuilder.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-avalon-excalibur/info/src/java/org/apache/avalon/framework/tools/qdox/AbstractInfoBuilder.java,v
retrieving revision 1.1
diff -u -r1.1 AbstractInfoBuilder.java
--- src/java/org/apache/avalon/framework/tools/qdox/AbstractInfoBuilder.java    16 Nov 
2002 05:14:07 -0000      1.1
+++ src/java/org/apache/avalon/framework/tools/qdox/AbstractInfoBuilder.java    26 Nov 
+2002 09:59:00 -0000
@@ -35,7 +35,6 @@
         "org.apache.avalon.framework.configuration.Configuration";
     protected static final String PARAMETERS_CLASS =
         "org.apache.avalon.framework.parameters.Parameters";
-    protected static final Attribute[] EMPTY_ATTRIBUTES = new Attribute[ 0 ];
 
     /**
      * Resolve the specified type.
Index: src/java/org/apache/avalon/framework/tools/qdox/DefaultInfoBuilder.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-avalon-excalibur/info/src/java/org/apache/avalon/framework/tools/qdox/DefaultInfoBuilder.java,v
retrieving revision 1.3
diff -u -r1.3 DefaultInfoBuilder.java
--- src/java/org/apache/avalon/framework/tools/qdox/DefaultInfoBuilder.java     24 Nov 
2002 12:15:26 -0000      1.3
+++ src/java/org/apache/avalon/framework/tools/qdox/DefaultInfoBuilder.java     26 Nov 
+2002 09:59:01 -0000
@@ -19,6 +19,7 @@
 import org.apache.avalon.framework.info.LoggerDescriptor;
 import org.apache.avalon.framework.info.SchemaDescriptor;
 import org.apache.avalon.framework.info.ServiceDescriptor;
+import org.apache.avalon.framework.info.Attribute;
 
 /**
  * This is a utility class that is used to build a ComponentInfo object
@@ -63,7 +64,7 @@
     private ComponentDescriptor buildComponent( final JavaClass javaClass )
     {
         final String type = javaClass.getFullyQualifiedName();
-        return new ComponentDescriptor( type, EMPTY_ATTRIBUTES );
+        return new ComponentDescriptor( type, Attribute.EMPTY_SET );
     }
 
     /**
@@ -81,7 +82,7 @@
             final DocletTag tag = tags[ i ];
             final String unresolvedType = getNamedParameter( tag, "type" );
             final String type = resolveType( javaClass, unresolvedType );
-            final ServiceDescriptor service = new ServiceDescriptor( type, 
EMPTY_ATTRIBUTES );
+            final ServiceDescriptor service = new ServiceDescriptor( type, 
+Attribute.EMPTY_SET );
             services.add( service );
         }
         return (ServiceDescriptor[])services.toArray( new ServiceDescriptor[ 
services.size() ] );
@@ -110,7 +111,7 @@
                 final String name =
                     getNamedParameter( tags[ i ], "name", "" );
                 final LoggerDescriptor logger =
-                    new LoggerDescriptor( name, EMPTY_ATTRIBUTES );
+                    new LoggerDescriptor( name, Attribute.EMPTY_SET );
                 loggers.add( logger );
             }
             return (LoggerDescriptor[])loggers.toArray( new LoggerDescriptor[ 
loggers.size() ] );
@@ -131,7 +132,7 @@
         {
             return new ContextDescriptor( CONTEXT_CLASS,
                                           new EntryDescriptor[ 0 ],
-                                          EMPTY_ATTRIBUTES );
+                                          Attribute.EMPTY_SET );
         }
         else
         {
@@ -152,13 +153,13 @@
                 final String optional = getNamedParameter( tags[ i ], "optional", 
"false" );
                 final boolean isOptional = "true".equals( optional );
                 final EntryDescriptor entry =
-                    new EntryDescriptor( key, entryType, isOptional, EMPTY_ATTRIBUTES 
);
+                    new EntryDescriptor( key, entryType, isOptional, 
+Attribute.EMPTY_SET );
                 entrySet.add( entry );
             }
             final EntryDescriptor[] entrys =
                 (EntryDescriptor[])entrySet.toArray( new EntryDescriptor[ 
entrySet.size() ] );
 
-            return new ContextDescriptor( type, entrys, EMPTY_ATTRIBUTES );
+            return new ContextDescriptor( type, entrys, Attribute.EMPTY_SET );
         }
     }
 
@@ -187,7 +188,7 @@
             final String location = getNamedParameter( tag, "location", "" );
             final String type = getNamedParameter( tag, "type", "" );
 
-            return new SchemaDescriptor( location, type, EMPTY_ATTRIBUTES );
+            return new SchemaDescriptor( location, type, Attribute.EMPTY_SET );
         }
     }
 
@@ -216,7 +217,7 @@
             final String location = getNamedParameter( tag, "location", "" );
             final String type = getNamedParameter( tag, "type", "" );
 
-            return new SchemaDescriptor( location, type, EMPTY_ATTRIBUTES );
+            return new SchemaDescriptor( location, type, Attribute.EMPTY_SET );
         }
     }
 
@@ -255,7 +256,7 @@
                 final String optional = getNamedParameter( tag, "optional", "false" );
                 final boolean isOptional = "true".equals( optional );
                 final DependencyDescriptor dependency =
-                    new DependencyDescriptor( key, type, isOptional, EMPTY_ATTRIBUTES 
);
+                    new DependencyDescriptor( key, type, isOptional, 
+Attribute.EMPTY_SET );
                 deps.add( dependency );
             }
             return (DependencyDescriptor[])deps.toArray( new DependencyDescriptor[ 
deps.size() ] );
Index: src/java/org/apache/avalon/framework/tools/qdox/LegacyInfoBuilder.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-avalon-excalibur/info/src/java/org/apache/avalon/framework/tools/qdox/LegacyInfoBuilder.java,v
retrieving revision 1.2
diff -u -r1.2 LegacyInfoBuilder.java
--- src/java/org/apache/avalon/framework/tools/qdox/LegacyInfoBuilder.java      24 Nov 
2002 12:15:26 -0000      1.2
+++ src/java/org/apache/avalon/framework/tools/qdox/LegacyInfoBuilder.java      26 Nov 
+2002 09:59:01 -0000
@@ -60,7 +60,7 @@
     {
         return new ContextDescriptor( "org.apache.avalon.phoenix.BlockContext",
                                       new EntryDescriptor[ 0 ],
-                                      new Attribute[ 0 ] );
+                                      Attribute.EMPTY_SET );
     }
 
     /**
@@ -72,7 +72,7 @@
     private ComponentDescriptor buildComponent( final JavaClass javaClass )
     {
         final String type = javaClass.getFullyQualifiedName();
-        return new ComponentDescriptor( type, EMPTY_ATTRIBUTES );
+        return new ComponentDescriptor( type, Attribute.EMPTY_SET );
     }
 
     /**
@@ -88,7 +88,7 @@
         for( int i = 0; i < tags.length; i++ )
         {
             final String type = getNamedParameter( tags[ i ], "name" );
-            final ServiceDescriptor service = new ServiceDescriptor( type, 
EMPTY_ATTRIBUTES );
+            final ServiceDescriptor service = new ServiceDescriptor( type, 
+Attribute.EMPTY_SET );
             services.add( service );
         }
         return (ServiceDescriptor[])services.toArray( new ServiceDescriptor[ 
services.size() ] );
@@ -117,8 +117,7 @@
         }
         final String type = getNamedParameter( tag, "type", "" );
         //TODO: Translate type into a uri type string
-        return new SchemaDescriptor(
-            "", type, EMPTY_ATTRIBUTES );
+        return new SchemaDescriptor( "", type, Attribute.EMPTY_SET );
     }
 
     /**
@@ -154,7 +153,7 @@
                 final String type = resolveType( javaClass, unresolvedType );
                 final String key = getNamedParameter( tag, "role", type );
                 final DependencyDescriptor dependency =
-                    new DependencyDescriptor( key, type, false, EMPTY_ATTRIBUTES );
+                    new DependencyDescriptor( key, type, false, Attribute.EMPTY_SET );
                 deps.add( dependency );
             }
             return (DependencyDescriptor[])deps.toArray( new DependencyDescriptor[ 
deps.size() ] );
Index: src/test/org/apache/avalon/framework/tools/infobuilder/test/InfoAssert.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-avalon-excalibur/info/src/test/org/apache/avalon/framework/tools/infobuilder/test/InfoAssert.java,v
retrieving revision 1.7
diff -u -r1.7 InfoAssert.java
--- src/test/org/apache/avalon/framework/tools/infobuilder/test/InfoAssert.java 24 Nov 
2002 12:15:26 -0000      1.7
+++ src/test/org/apache/avalon/framework/tools/infobuilder/test/InfoAssert.java 26 Nov 
+2002 09:59:02 -0000
@@ -26,8 +26,6 @@
  */
 public class InfoAssert
 {
-    public static final Attribute[] EMPTY_ATTRIBUTES = new Attribute[ 0 ];
-
     public static void assertEqualStructure( final String message,
                                              final ComponentInfo expected,
                                              final ComponentInfo actual )
Index: 
src/test/org/apache/avalon/framework/tools/infobuilder/test/InfoBuilderTestCase.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-avalon-excalibur/info/src/test/org/apache/avalon/framework/tools/infobuilder/test/InfoBuilderTestCase.java,v
retrieving revision 1.17
diff -u -r1.17 InfoBuilderTestCase.java
--- 
src/test/org/apache/avalon/framework/tools/infobuilder/test/InfoBuilderTestCase.java   
     24 Nov 2002 12:15:26 -0000      1.17
+++ 
+src/test/org/apache/avalon/framework/tools/infobuilder/test/InfoBuilderTestCase.java  
+      26 Nov 2002 09:59:03 -0000
@@ -105,17 +105,17 @@
     private ComponentInfo createComponentInfoWithParameters()
     {
         final ComponentDescriptor component =
-            new ComponentDescriptor( "org.realityforge.Component1", 
InfoAssert.EMPTY_ATTRIBUTES );
+            new ComponentDescriptor( "org.realityforge.Component1", 
+Attribute.EMPTY_SET );
 
         final ContextDescriptor context =
             new ContextDescriptor( "org.apache.avalon.framework.context.Context",
                                    new EntryDescriptor[ 0 ],
-                                   InfoAssert.EMPTY_ATTRIBUTES );
+                                   Attribute.EMPTY_SET );
 
         final SchemaDescriptor schema =
             new SchemaDescriptor( "",
                                   "",
-                                  InfoAssert.EMPTY_ATTRIBUTES );
+                                  Attribute.EMPTY_SET );
 
         return new ComponentInfo( component,
                                   new ServiceDescriptor[0],
@@ -212,22 +212,22 @@
     private ComponentInfo createDummyComponentInfo()
     {
         final ComponentDescriptor component =
-            new ComponentDescriptor( "org.realityforge.Component1", 
InfoAssert.EMPTY_ATTRIBUTES );
+            new ComponentDescriptor( "org.realityforge.Component1", 
+Attribute.EMPTY_SET );
 
-        final LoggerDescriptor logger1 = new LoggerDescriptor( "", 
InfoAssert.EMPTY_ATTRIBUTES );
-        final LoggerDescriptor logger2 = new LoggerDescriptor( "audit", 
InfoAssert.EMPTY_ATTRIBUTES );
+        final LoggerDescriptor logger1 = new LoggerDescriptor( "", 
+Attribute.EMPTY_SET );
+        final LoggerDescriptor logger2 = new LoggerDescriptor( "audit", 
+Attribute.EMPTY_SET );
         final LoggerDescriptor[] loggers = new LoggerDescriptor[]{logger1, logger2};
 
         final EntryDescriptor entry1 = new EntryDescriptor( "mbean",
                                                             "javax.jmx.MBeanServer",
                                                             false,
-                                                            
InfoAssert.EMPTY_ATTRIBUTES );
+                                                            Attribute.EMPTY_SET );
 
         final EntryDescriptor[] entrys = new EntryDescriptor[]{entry1};
         final ContextDescriptor context =
             new ContextDescriptor( "org.apache.avalon.phoenix.BlockContext",
                                    entrys,
-                                   InfoAssert.EMPTY_ATTRIBUTES );
+                                   Attribute.EMPTY_SET );
 
         final ServiceDescriptor service1 = createServiceDescriptor();
 
@@ -236,19 +236,19 @@
             new DependencyDescriptor( "org.realityforge.Service2",
                                       "org.realityforge.Service2",
                                       true,
-                                      InfoAssert.EMPTY_ATTRIBUTES );
+                                      Attribute.EMPTY_SET );
         final DependencyDescriptor dependency2 =
             new DependencyDescriptor( "foo",
                                       "org.realityforge.Service3",
                                       false,
-                                      InfoAssert.EMPTY_ATTRIBUTES );
+                                      Attribute.EMPTY_SET );
         final DependencyDescriptor[] deps =
             new DependencyDescriptor[]{dependency1, dependency2};
 
         final SchemaDescriptor schema =
             new SchemaDescriptor( "",
                                   "http://relaxng.org/ns/structure/1.0";,
-                                  InfoAssert.EMPTY_ATTRIBUTES );
+                                  Attribute.EMPTY_SET );
 
         return new ComponentInfo( component, services, loggers,
                                   context, deps, schema, null );

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to