You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by sc...@apache.org on 2003/12/29 16:26:39 UTC

cvs commit: jakarta-commons/collections/src/java/org/apache/commons/collections/map CompositeMap.java StaticBucketMap.java

scolebourne    2003/12/29 07:26:39

  Modified:    collections/src/java/org/apache/commons/collections/map
                        CompositeMap.java StaticBucketMap.java
  Log:
  Change to standard variable naming and braces style
  
  Revision  Changes    Path
  1.3       +85 -64    jakarta-commons/collections/src/java/org/apache/commons/collections/map/CompositeMap.java
  
  Index: CompositeMap.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/map/CompositeMap.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- CompositeMap.java	29 Dec 2003 01:04:43 -0000	1.2
  +++ CompositeMap.java	29 Dec 2003 15:26:39 -0000	1.3
  @@ -79,23 +79,25 @@
    * @author Brian McCallister
    */
   public class CompositeMap implements Map {
  +    
       /** Array of all maps in the composite */
  -    private Map[] composite = null;
  +    private Map[] composite;
       
       /** Handle mutation operations */
  -    private MapMutator mutator = null;
  +    private MapMutator mutator;
       
       /**
  -     * Create a new, empty, CompositeMap
  +     * Create a new, empty, CompositeMap.
        */
       public CompositeMap() {
           this(new Map[]{}, null);
       }
       
       /**
  -     * Create a new CompositeMap with two composited Map instances
  -     * @param one First Map to be composited
  -     * @param two Second Map to be composited
  +     * Create a new CompositeMap with two composited Map instances.
  +     * 
  +     * @param one  the first Map to be composited
  +     * @param two  the second Map to be composited
        * @throws IllegalArgumentException if there is a key collision
        */
       public CompositeMap(Map one, Map two) {
  @@ -103,10 +105,11 @@
       }
       
       /**
  -     * Create a new CompositeMap with two composited Map instances
  -     * @param one First Map to be composited
  -     * @param two Second Map to be composited
  -     * @param mutator MapMutator to be used for mutation operations
  +     * Create a new CompositeMap with two composited Map instances.
  +     * 
  +     * @param one  the first Map to be composited
  +     * @param two  the second Map to be composited
  +     * @param mutator  MapMutator to be used for mutation operations
        */
       public CompositeMap(Map one, Map two, MapMutator mutator) {
           this(new Map[]{one, two}, mutator);
  @@ -115,7 +118,8 @@
       /**
        * Create a new CompositeMap which composites all of the Map instances in the
        * argument. It copies the argument array, it does not use it directly.
  -     * @param composite Maps to be composited
  +     * 
  +     * @param composite  the Maps to be composited
        * @throws IllegalArgumentException if there is a key collision
        */
       public CompositeMap(Map[] composite) {
  @@ -125,8 +129,9 @@
       /**
        * Create a new CompositeMap which composites all of the Map instances in the
        * argument. It copies the argument array, it does not use it directly.
  -     * @param composite Maps to be composited
  -     * @param mutator MapMutator to be used for mutation operations
  +     * 
  +     * @param composite  Maps to be composited
  +     * @param mutator  MapMutator to be used for mutation operations
        */
       public CompositeMap(Map[] composite, MapMutator mutator) {
           this.mutator = mutator;
  @@ -136,18 +141,20 @@
           }
       }
       
  +    //-----------------------------------------------------------------------
       /**
  -     * Specify the MapMutator to be used by mutation operations
  -     * @param mutator The MapMutator to be used for mutation delegation
  +     * Specify the MapMutator to be used by mutation operations.
  +     * 
  +     * @param mutator  the MapMutator to be used for mutation delegation
        */
       public void setMutator(MapMutator mutator) {
           this.mutator = mutator;
       }
       
       /**
  -     * Add an additional Map to the composite
  +     * Add an additional Map to the composite.
        *
  -     * @param map Map to be added to the composite
  +     * @param map  the Map to be added to the composite
        * @throws IllegalArgumentException if there is a key collision and there is no
        *         MapMutator set to handle it.
        */
  @@ -170,9 +177,9 @@
       }
       
       /**
  -     * Remove a Map from the composite
  +     * Remove a Map from the composite.
        *
  -     * @param map The Map to be removed from the composite
  +     * @param map  the Map to be removed from the composite
        * @return The removed Map or <code>null</code> if map is not in the composite
        */
       public synchronized Map removeComposited(Map map) {
  @@ -188,11 +195,10 @@
           }
           return null;
       }
  -    
  -    /* Map Implementation */
  -    
  +
  +    //-----------------------------------------------------------------------    
       /**
  -     * Calls <code>clear()</code> on all composited Maps
  +     * Calls <code>clear()</code> on all composited Maps.
        *
        * @throws UnsupportedOperationException if any of the composited Maps do not support clear()
        */
  @@ -209,7 +215,7 @@
        * <tt>(key==null ? k==null : key.equals(k))</tt>.  (There can be
        * at most one such mapping.)
        *
  -     * @param key key whose presence in this map is to be tested.
  +     * @param key  key whose presence in this map is to be tested.
        * @return <tt>true</tt> if this map contains a mapping for the specified
        *         key.
        *
  @@ -220,7 +226,9 @@
        */
       public boolean containsKey(Object key) {
           for (int i = this.composite.length - 1; i >= 0; --i) {
  -            if (this.composite[i].containsKey(key)) return true;
  +            if (this.composite[i].containsKey(key)) {
  +                return true;
  +            }
           }
           return false;
       }
  @@ -243,7 +251,9 @@
        */
       public boolean containsValue(Object value) {
           for (int i = this.composite.length - 1; i >= 0; --i) {
  -            if (this.composite[i].containsValue(value)) return true;
  +            if (this.composite[i].containsValue(value)) {
  +                return true;
  +            }
           }
           return false;
       }
  @@ -299,7 +309,9 @@
        */
       public Object get(Object key) {
           for (int i = this.composite.length - 1; i >= 0; --i) {
  -            if (this.composite[i].containsKey(key)) return this.composite[i].get(key);
  +            if (this.composite[i].containsKey(key)) {
  +                return this.composite[i].get(key);
  +            }
           }
           return null;
       }
  @@ -311,7 +323,9 @@
        */
       public boolean isEmpty() {
           for (int i = this.composite.length - 1; i >= 0; --i) {
  -            if (!this.composite[i].isEmpty()) return false;
  +            if (!this.composite[i].isEmpty()) {
  +                return false;
  +            }
           }
           return true;
       }
  @@ -365,7 +379,9 @@
        *            <tt>null</tt>.
        */
       public Object put(Object key, Object value) {
  -        if (this.mutator == null) throw new UnsupportedOperationException("No mutator specified");
  +        if (this.mutator == null) {
  +            throw new UnsupportedOperationException("No mutator specified");
  +        }
           return this.mutator.put(this, this.composite, key, value);
       }
       
  @@ -377,7 +393,7 @@
        * specified map.  The behavior of this operation is unspecified if the
        * specified map is modified while the operation is in progress.
        *
  -     * @param t Mappings to be stored in this map.
  +     * @param map Mappings to be stored in this map.
        *
        * @throws UnsupportedOperationException if the <tt>putAll</tt> method is
        * 		  not supported by this map.
  @@ -391,9 +407,11 @@
        *         this map does not permit <tt>null</tt> keys or values, and the
        *         specified map contains <tt>null</tt> keys or values.
        */
  -    public void putAll(Map t) {
  -        if (this.mutator == null) throw new UnsupportedOperationException("No mutator specified");
  -        this.mutator.putAll(this, this.composite, t);
  +    public void putAll(Map map) {
  +        if (this.mutator == null) {
  +            throw new UnsupportedOperationException("No mutator specified");
  +        }
  +        this.mutator.putAll(this, this.composite, map);
       }
       
       /**
  @@ -423,7 +441,9 @@
        */
       public Object remove(Object key) {
           for (int i = this.composite.length - 1; i >= 0; --i) {
  -            if (this.composite[i].containsKey(key)) return this.composite[i].remove(key);
  +            if (this.composite[i].containsKey(key)) {
  +                return this.composite[i].remove(key);
  +            }
           }
           return null;
       }
  @@ -465,18 +485,10 @@
       }
       
       /**
  -     * @see Map#hashCode
  -     */
  -    public int hashCode() {
  -        int code = 0;
  -        for (Iterator i = this.entrySet().iterator(); i.hasNext();) {
  -            code += i.next().hashCode();
  -        }
  -        return code;
  -    }
  -    
  -    /**
  -     * @see Map#equals
  +     * Checks if this Map equals another as per the Map specification.
  +     * 
  +     * @param obj  the object to compare to
  +     * @return true if the maps are equal
        */
       public boolean equals(Object obj) {
           if (obj instanceof Map) {
  @@ -487,6 +499,17 @@
       }
       
       /**
  +     * Gets a hash code for the Map as per the Map specification.
  +     */
  +    public int hashCode() {
  +        int code = 0;
  +        for (Iterator i = this.entrySet().iterator(); i.hasNext();) {
  +            code += i.next().hashCode();
  +        }
  +        return code;
  +    }
  +    
  +    /**
        * This interface allows definition for all of the indeterminate
        * mutators in a CompositeMap, as well as providing a hook for
        * callbacks on key collisions.
  @@ -496,24 +519,22 @@
            * Called when adding a new Composited Map results in a
            * key collision.
            *
  -         * @param composite the CompositeMap withthe collision
  -         * @param existing the Map already in the composite which contains the
  +         * @param composite  the CompositeMap withthe collision
  +         * @param existing  the Map already in the composite which contains the
            *        offending key
  -         * @param added the Map being added
  -         * @param intersect the intersection of the keysets of the existing and added maps
  +         * @param added  the Map being added
  +         * @param intersect  the intersection of the keysets of the existing and added maps
            */
  -        public void resolveCollision(CompositeMap composite,
  -        Map existing,
  -        Map added,
  -        Collection intersect);
  +        public void resolveCollision(
  +            CompositeMap composite, Map existing, Map added, Collection intersect);
           
           /**
            * Called when the CompositeMap.put() method is invoked.
            *
  -         * @param map the CompositeMap which is being modified
  -         * @param composited array of Maps in the CompositeMap being modified
  -         * @param key key with which the specified value is to be associated.
  -         * @param value value to be associated with the specified key.
  +         * @param map  the CompositeMap which is being modified
  +         * @param composited  array of Maps in the CompositeMap being modified
  +         * @param key  key with which the specified value is to be associated.
  +         * @param value  value to be associated with the specified key.
            * @return previous value associated with specified key, or <tt>null</tt>
            *	       if there was no mapping for key.  A <tt>null</tt> return can
            *	       also indicate that the map previously associated <tt>null</tt>
  @@ -534,9 +555,9 @@
           /**
            * Called when the CompositeMap.putAll() method is invoked.
            *
  -         * @param map the CompositeMap which is being modified
  -         * @param composited array of Maps in the CompositeMap being modified
  -         * @param t Mappings to be stored in this CompositeMap
  +         * @param map  the CompositeMap which is being modified
  +         * @param composited  array of Maps in the CompositeMap being modified
  +         * @param mapToAdd  Mappings to be stored in this CompositeMap
            *
            * @throws UnsupportedOperationException if not defined
            * @throws ClassCastException if the class of the specified key or value
  @@ -547,6 +568,6 @@
            *            keys or values, and the specified key or value is
            *            <tt>null</tt>.
            */
  -        public void putAll(CompositeMap map, Map[] composited, Map t);
  +        public void putAll(CompositeMap map, Map[] composited, Map mapToAdd);
       }
   }
  
  
  
  1.6       +7 -5      jakarta-commons/collections/src/java/org/apache/commons/collections/map/StaticBucketMap.java
  
  Index: StaticBucketMap.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/map/StaticBucketMap.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- StaticBucketMap.java	29 Dec 2003 15:08:15 -0000	1.5
  +++ StaticBucketMap.java	29 Dec 2003 15:26:39 -0000	1.6
  @@ -415,13 +415,15 @@
       /**
        * Puts all the entries from the specified map into this map.
        * This operation is <b>not atomic</b> and may have undesired effects.
  +     * 
  +     * @param map  the map of entries to add
        */
  -    public void putAll(Map other) {
  -        Iterator i = other.keySet().iterator();
  +    public void putAll(Map map) {
  +        Iterator i = map.keySet().iterator();
   
           while (i.hasNext()) {
               Object key = i.next();
  -            put(key, other.get(key));
  +            put(key, map.get(key));
           }
       }
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org