avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From leosu...@apache.org
Subject cvs commit: avalon-sandbox/attributes/api/src/test/org/apache/avalon/attributes/test Dependency.java
Date Sun, 10 Aug 2003 21:48:15 GMT
leosutic    2003/08/10 14:48:15

  Modified:    attributes/api/src/java/org/apache/avalon/attributes
                        CachedRepository.java DefaultCachedRepository.java
                        EmptyCachedRepository.java
               attributes/api/src/test/org/apache/avalon/attributes/test
                        Dependency.java
  Removed:     attributes build.xml
  Log:
  1. Moved all build stuff into Maven.
  2. Wrote a proper test case.
  3. Included support for attributes attached to fields and constructors.
  4. Slight code cleanups.
  
  Revision  Changes    Path
  1.2       +1 -1      avalon-sandbox/attributes/api/src/java/org/apache/avalon/attributes/CachedRepository.java
  
  Index: CachedRepository.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/attributes/api/src/java/org/apache/avalon/attributes/CachedRepository.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- CachedRepository.java	10 Aug 2003 13:46:08 -0000	1.1
  +++ CachedRepository.java	10 Aug 2003 21:48:15 -0000	1.2
  @@ -3,7 +3,7 @@
   import java.lang.reflect.Field;
   import java.lang.reflect.Constructor;
   import java.lang.reflect.Method;
  -import java.util.*;
  +import java.util.Collection;
   
   interface CachedRepository {
       
  
  
  
  1.3       +45 -14    avalon-sandbox/attributes/api/src/java/org/apache/avalon/attributes/DefaultCachedRepository.java
  
  Index: DefaultCachedRepository.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/attributes/api/src/java/org/apache/avalon/attributes/DefaultCachedRepository.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DefaultCachedRepository.java	10 Aug 2003 15:05:24 -0000	1.2
  +++ DefaultCachedRepository.java	10 Aug 2003 21:48:15 -0000	1.3
  @@ -3,16 +3,24 @@
   import java.lang.reflect.Field;
   import java.lang.reflect.Constructor;
   import java.lang.reflect.Method;
  -import java.util.*;
  +import java.util.ArrayList;
  +import java.util.Collection;
  +import java.util.Iterator;
  +import java.util.Map;
  +import java.util.Set;
  +import java.util.HashSet;
  +import java.util.HashMap;
   
   class DefaultCachedRepository implements CachedRepository {
       
  +    private final static Collection EMPTY_COLLECTION = new ArrayList (0);
  +    
       private final Set classAttributes = new HashSet ();
       private final Map fields = new HashMap ();
       private final Map methods = new HashMap ();
       private final Map constructors = new HashMap ();
       
  -    public DefaultCachedRepository (Class clazz, AttributeRepositoryClass repo) throws
Exception {
  +    public DefaultCachedRepository (Class clazz, AttributeRepositoryClass repo) {
           // ---- Fix up class attributes
           this.classAttributes.addAll (repo.getClassAttributes ());
           this.classAttributes.addAll (getInheritableClassAttributes (clazz.getSuperclass
()));
  @@ -28,13 +36,18 @@
               String key = Util.getSignature (m);
               
               Set attributes = new HashSet ();
  -            attributes.addAll ((Collection) repo.getMethodAttributes ().get (key));
  +            
  +            if (repo.getMethodAttributes ().containsKey (key)) {
  +                attributes.addAll ((Collection) repo.getMethodAttributes ().get (key));
  +            }
               attributes.addAll (getInheritableMethodAttributes (clazz.getSuperclass (),
m.getName (), m.getParameterTypes ()));
               for (int j = 0; j < ifs.length; j++) {
                   attributes.addAll (getInheritableMethodAttributes (ifs[j], m.getName (),
m.getParameterTypes ()));
               }
               
  -            this.methods.put (m, attributes);
  +            if (attributes.size () > 0) {
  +                this.methods.put (m, attributes);
  +            }
           }
           
           // --- Just copy constructor attributes (they aren't inherited)
  @@ -42,7 +55,10 @@
           for (int i = 0; i < constructors.length; i++) {
               Constructor ctor = constructors[i];
               String key = Util.getSignature (ctor);
  -            this.constructors.put (ctor, repo.getConstructorAttributes ().get (key));
  +            
  +            if (repo.getConstructorAttributes ().containsKey (key)) {
  +                this.constructors.put (ctor, repo.getConstructorAttributes ().get (key));
  +            }
           }
           
           // --- Just copy field attributes (they aren't inherited)
  @@ -50,7 +66,9 @@
           for (int i = 0; i < fields.length; i++) {
               Field f = fields[i];
               String key = f.getName ();
  -            this.fields.put (f, repo.getFieldAttributes ().get (key));
  +            if (repo.getFieldAttributes ().containsKey (key)) {
  +                this.fields.put (f, repo.getFieldAttributes ().get (key));
  +            }
           }
       }
       
  @@ -60,7 +78,7 @@
           Iterator iter = attrs.iterator ();
           while (iter.hasNext ()) {
               Object attr = iter.next ();
  -            if (Attributes.hasAttribute (attr.getClass (), Inheritable.class)) {
  +            if (Attributes.hasAttributeType (attr.getClass (), Inheritable.class)) {
                   result.add (attr);
               }
           }
  @@ -115,19 +133,32 @@
           return result;
       }
       
  -    public Collection getAttributes () throws Exception {
  +    public Collection getAttributes () {
           return classAttributes;
       }
       
  -    public Collection getAttributes (Field f) throws Exception {
  -        return (Collection) fields.get (f);
  +    public Collection getAttributes (Field f) {
  +        if (fields.containsKey (f)) {
  +            return (Collection) fields.get (f);
  +        } else {
  +            return EMPTY_COLLECTION;
  +        }
  +        
       }
       
  -    public Collection getAttributes (Method m) throws Exception {
  -        return (Collection) methods.get (m);
  +    public Collection getAttributes (Method m) {
  +        if (methods.containsKey (m)) {
  +            return (Collection) methods.get (m);
  +        } else {
  +            return EMPTY_COLLECTION;
  +        }
       }
       
  -    public Collection getAttributes (Constructor c) throws Exception {
  -        return (Collection) constructors.get (c);
  +    public Collection getAttributes (Constructor c) {
  +        if (constructors.containsKey (c)) {
  +            return (Collection) constructors.get (c);
  +        } else {
  +            return EMPTY_COLLECTION;
  +        }
       }   
   }
  
  
  
  1.2       +5 -1      avalon-sandbox/attributes/api/src/java/org/apache/avalon/attributes/EmptyCachedRepository.java
  
  Index: EmptyCachedRepository.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/attributes/api/src/java/org/apache/avalon/attributes/EmptyCachedRepository.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- EmptyCachedRepository.java	10 Aug 2003 13:46:08 -0000	1.1
  +++ EmptyCachedRepository.java	10 Aug 2003 21:48:15 -0000	1.2
  @@ -3,8 +3,12 @@
   import java.lang.reflect.Field;
   import java.lang.reflect.Constructor;
   import java.lang.reflect.Method;
  -import java.util.*;
  +import java.util.ArrayList;
  +import java.util.Collection;
   
  +/**
  + * Null implementation of a cached repository.
  + */
   class EmptyCachedRepository implements CachedRepository {
       
       private final static Collection EMPTY_COLLECTION = new ArrayList (0);
  
  
  
  1.2       +11 -1     avalon-sandbox/attributes/api/src/test/org/apache/avalon/attributes/test/Dependency.java
  
  Index: Dependency.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/attributes/api/src/test/org/apache/avalon/attributes/test/Dependency.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Dependency.java	10 Aug 2003 13:46:08 -0000	1.1
  +++ Dependency.java	10 Aug 2003 21:48:15 -0000	1.2
  @@ -5,7 +5,7 @@
   /**
    * Declares a dependency.
    * 
  - * @Inheritable ()
  + * @Inheritable
    */
   public class Dependency {
       
  @@ -23,6 +23,16 @@
       
       public String getDependencyName () {
           return name;
  +    }
  +    
  +    public boolean equals (Object o) {
  +        return o instanceof Dependency &&
  +            ((Dependency) o).clazz == clazz &&
  +            ((Dependency) o).name.equals (name);
  +    }
  +    
  +    public int hashCode () {
  +        return clazz.hashCode () ^ name.hashCode ();
       }
       
       public String toString () {
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org
For additional commands, e-mail: cvs-help@avalon.apache.org


Mime
View raw message