Change to standard variable naming and braces style

git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@131478 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Stephen Colebourne 2003-12-29 15:26:39 +00:00
parent 1408f0635a
commit a7f9fcfb60
2 changed files with 92 additions and 69 deletions

View File

@ -1,5 +1,5 @@
/* /*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/map/CompositeMap.java,v 1.2 2003/12/29 01:04:43 scolebourne Exp $ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/map/CompositeMap.java,v 1.3 2003/12/29 15:26:39 scolebourne Exp $
* ==================================================================== * ====================================================================
* *
* The Apache Software License, Version 1.1 * The Apache Software License, Version 1.1
@ -74,28 +74,30 @@ import org.apache.commons.collections.set.CompositeSet;
* strategy is provided then add and remove are unsupported. * strategy is provided then add and remove are unsupported.
* *
* @since Commons Collections 3.0 * @since Commons Collections 3.0
* @version $Revision: 1.2 $ $Date: 2003/12/29 01:04:43 $ * @version $Revision: 1.3 $ $Date: 2003/12/29 15:26:39 $
* *
* @author Brian McCallister * @author Brian McCallister
*/ */
public class CompositeMap implements Map { public class CompositeMap implements Map {
/** Array of all maps in the composite */ /** Array of all maps in the composite */
private Map[] composite = null; private Map[] composite;
/** Handle mutation operations */ /** Handle mutation operations */
private MapMutator mutator = null; private MapMutator mutator;
/** /**
* Create a new, empty, CompositeMap * Create a new, empty, CompositeMap.
*/ */
public CompositeMap() { public CompositeMap() {
this(new Map[]{}, null); this(new Map[]{}, null);
} }
/** /**
* Create a new CompositeMap with two composited Map instances * Create a new CompositeMap with two composited Map instances.
* @param one First Map to be composited *
* @param two Second Map to be composited * @param one the first Map to be composited
* @param two the second Map to be composited
* @throws IllegalArgumentException if there is a key collision * @throws IllegalArgumentException if there is a key collision
*/ */
public CompositeMap(Map one, Map two) { public CompositeMap(Map one, Map two) {
@ -103,9 +105,10 @@ public class CompositeMap implements Map {
} }
/** /**
* Create a new CompositeMap with two composited Map instances * Create a new CompositeMap with two composited Map instances.
* @param one First Map to be composited *
* @param two Second Map to be composited * @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 * @param mutator MapMutator to be used for mutation operations
*/ */
public CompositeMap(Map one, Map two, MapMutator mutator) { public CompositeMap(Map one, Map two, MapMutator mutator) {
@ -115,7 +118,8 @@ public class CompositeMap implements Map {
/** /**
* Create a new CompositeMap which composites all of the Map instances in the * 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. * 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 * @throws IllegalArgumentException if there is a key collision
*/ */
public CompositeMap(Map[] composite) { public CompositeMap(Map[] composite) {
@ -125,6 +129,7 @@ public class CompositeMap implements Map {
/** /**
* Create a new CompositeMap which composites all of the Map instances in the * 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. * argument. It copies the argument array, it does not use it directly.
*
* @param composite Maps to be composited * @param composite Maps to be composited
* @param mutator MapMutator to be used for mutation operations * @param mutator MapMutator to be used for mutation operations
*/ */
@ -136,18 +141,20 @@ public class CompositeMap implements Map {
} }
} }
//-----------------------------------------------------------------------
/** /**
* Specify the MapMutator to be used by mutation operations * Specify the MapMutator to be used by mutation operations.
* @param mutator The MapMutator to be used for mutation delegation *
* @param mutator the MapMutator to be used for mutation delegation
*/ */
public void setMutator(MapMutator mutator) { public void setMutator(MapMutator mutator) {
this.mutator = 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 * @throws IllegalArgumentException if there is a key collision and there is no
* MapMutator set to handle it. * MapMutator set to handle it.
*/ */
@ -170,9 +177,9 @@ public class CompositeMap implements Map {
} }
/** /**
* 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 * @return The removed Map or <code>null</code> if map is not in the composite
*/ */
public synchronized Map removeComposited(Map map) { public synchronized Map removeComposited(Map map) {
@ -189,10 +196,9 @@ public class CompositeMap implements Map {
return null; 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() * @throws UnsupportedOperationException if any of the composited Maps do not support clear()
*/ */
@ -220,7 +226,9 @@ public class CompositeMap implements Map {
*/ */
public boolean containsKey(Object key) { public boolean containsKey(Object key) {
for (int i = this.composite.length - 1; i >= 0; --i) { 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; return false;
} }
@ -243,7 +251,9 @@ public class CompositeMap implements Map {
*/ */
public boolean containsValue(Object value) { public boolean containsValue(Object value) {
for (int i = this.composite.length - 1; i >= 0; --i) { 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; return false;
} }
@ -299,7 +309,9 @@ public class CompositeMap implements Map {
*/ */
public Object get(Object key) { public Object get(Object key) {
for (int i = this.composite.length - 1; i >= 0; --i) { 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; return null;
} }
@ -311,7 +323,9 @@ public class CompositeMap implements Map {
*/ */
public boolean isEmpty() { public boolean isEmpty() {
for (int i = this.composite.length - 1; i >= 0; --i) { 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; return true;
} }
@ -365,7 +379,9 @@ public class CompositeMap implements Map {
* <tt>null</tt>. * <tt>null</tt>.
*/ */
public Object put(Object key, Object value) { 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); return this.mutator.put(this, this.composite, key, value);
} }
@ -377,7 +393,7 @@ public class CompositeMap implements Map {
* specified map. The behavior of this operation is unspecified if the * specified map. The behavior of this operation is unspecified if the
* specified map is modified while the operation is in progress. * 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 * @throws UnsupportedOperationException if the <tt>putAll</tt> method is
* not supported by this map. * not supported by this map.
@ -391,9 +407,11 @@ public class CompositeMap implements Map {
* this map does not permit <tt>null</tt> keys or values, and the * this map does not permit <tt>null</tt> keys or values, and the
* specified map contains <tt>null</tt> keys or values. * specified map contains <tt>null</tt> keys or values.
*/ */
public void putAll(Map t) { public void putAll(Map map) {
if (this.mutator == null) throw new UnsupportedOperationException("No mutator specified"); if (this.mutator == null) {
this.mutator.putAll(this, this.composite, t); throw new UnsupportedOperationException("No mutator specified");
}
this.mutator.putAll(this, this.composite, map);
} }
/** /**
@ -423,7 +441,9 @@ public class CompositeMap implements Map {
*/ */
public Object remove(Object key) { public Object remove(Object key) {
for (int i = this.composite.length - 1; i >= 0; --i) { 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; return null;
} }
@ -465,18 +485,10 @@ public class CompositeMap implements Map {
} }
/** /**
* @see Map#hashCode * Checks if this Map equals another as per the Map specification.
*/ *
public int hashCode() { * @param obj the object to compare to
int code = 0; * @return true if the maps are equal
for (Iterator i = this.entrySet().iterator(); i.hasNext();) {
code += i.next().hashCode();
}
return code;
}
/**
* @see Map#equals
*/ */
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (obj instanceof Map) { if (obj instanceof Map) {
@ -486,6 +498,17 @@ public class CompositeMap implements Map {
return false; return false;
} }
/**
* 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 * This interface allows definition for all of the indeterminate
* mutators in a CompositeMap, as well as providing a hook for * mutators in a CompositeMap, as well as providing a hook for
@ -502,10 +525,8 @@ public class CompositeMap implements Map {
* @param added the Map being added * @param added the Map being added
* @param intersect the intersection of the keysets of the existing and added maps * @param intersect the intersection of the keysets of the existing and added maps
*/ */
public void resolveCollision(CompositeMap composite, public void resolveCollision(
Map existing, CompositeMap composite, Map existing, Map added, Collection intersect);
Map added,
Collection intersect);
/** /**
* Called when the CompositeMap.put() method is invoked. * Called when the CompositeMap.put() method is invoked.
@ -536,7 +557,7 @@ public class CompositeMap implements Map {
* *
* @param map the CompositeMap which is being modified * @param map the CompositeMap which is being modified
* @param composited array of Maps in the CompositeMap being modified * @param composited array of Maps in the CompositeMap being modified
* @param t Mappings to be stored in this CompositeMap * @param mapToAdd Mappings to be stored in this CompositeMap
* *
* @throws UnsupportedOperationException if not defined * @throws UnsupportedOperationException if not defined
* @throws ClassCastException if the class of the specified key or value * @throws ClassCastException if the class of the specified key or value
@ -547,6 +568,6 @@ public class CompositeMap implements Map {
* keys or values, and the specified key or value is * keys or values, and the specified key or value is
* <tt>null</tt>. * <tt>null</tt>.
*/ */
public void putAll(CompositeMap map, Map[] composited, Map t); public void putAll(CompositeMap map, Map[] composited, Map mapToAdd);
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/map/StaticBucketMap.java,v 1.5 2003/12/29 15:08:15 scolebourne Exp $ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/map/StaticBucketMap.java,v 1.6 2003/12/29 15:26:39 scolebourne Exp $
* ==================================================================== * ====================================================================
* *
* The Apache Software License, Version 1.1 * The Apache Software License, Version 1.1
@ -132,7 +132,7 @@ import org.apache.commons.collections.KeyValue;
* operations will affect the map.<p> * operations will affect the map.<p>
* *
* @since Commons Collections 3.0 (previously in main package v2.1) * @since Commons Collections 3.0 (previously in main package v2.1)
* @version $Revision: 1.5 $ $Date: 2003/12/29 15:08:15 $ * @version $Revision: 1.6 $ $Date: 2003/12/29 15:26:39 $
* *
* @author Berin Loritsch * @author Berin Loritsch
* @author Gerhard Froehlich * @author Gerhard Froehlich
@ -415,13 +415,15 @@ public final class StaticBucketMap implements Map {
/** /**
* Puts all the entries from the specified map into this map. * Puts all the entries from the specified map into this map.
* This operation is <b>not atomic</b> and may have undesired effects. * 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) { public void putAll(Map map) {
Iterator i = other.keySet().iterator(); Iterator i = map.keySet().iterator();
while (i.hasNext()) { while (i.hasNext()) {
Object key = i.next(); Object key = i.next();
put(key, other.get(key)); put(key, map.get(key));
} }
} }