[jboss-cvs] jboss-portal/server/src/main/org/jboss/portal/server/util ...
Julien Viet
julien at jboss.com
Sun Jul 30 18:35:17 EDT 2006
User: julien
Date: 06/07/30 18:35:17
Modified: server/src/main/org/jboss/portal/server/util
Parameters.java
Log:
move the code to append a parameter map to the Parameters class as it will be reused from there
Revision Changes Path
1.12 +71 -50 jboss-portal/server/src/main/org/jboss/portal/server/util/Parameters.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: Parameters.java
===================================================================
RCS file: /cvsroot/jboss/jboss-portal/server/src/main/org/jboss/portal/server/util/Parameters.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -b -r1.11 -r1.12
--- Parameters.java 22 Jun 2006 02:11:14 -0000 1.11
+++ Parameters.java 30 Jul 2006 22:35:17 -0000 1.12
@@ -36,7 +36,7 @@
* A set of parameters.
*
* @author <a href="mailto:julien at jboss.org">Julien Viet</a>
- * @version $Revision: 1.11 $
+ * @version $Revision: 1.12 $
*/
public class Parameters implements Serializable
{
@@ -162,50 +162,6 @@
}
/**
- * Replace all the parameters.
- *
- * @throws IllegalArgumentException if the map is not valid
- */
- public void replace(Map map)
- {
- validateMap(map);
- if (this.map != null)
- {
- this.map.clear();
- if (map.isEmpty() == false)
- {
- this.map.putAll(map);
- }
- }
- else
- {
- if (map.isEmpty() == false)
- {
- this.map = new HashMap(map);
- }
- }
- }
-
- /**
- * Replace all the parameters.
- *
- * @throws IllegalArgumentException if the parameters is not valid
- */
- public void replace(Parameters parameters)
- {
- if (parameters == null)
- {
- throw new IllegalArgumentException("parameters must not be null");
- }
- Map map = parameters.getMap();
- if (map == null)
- {
- map = Collections.EMPTY_MAP;
- }
- replace(map);
- }
-
- /**
* Set the a parameter value.
*
* @param name the parameter name
@@ -273,7 +229,15 @@
}
}
- public void mergeWith(Parameters params)
+ /**
+ * Append the parameters to this object. All the entries will be inserted
+ * in the current map. If a collision occurs then the new values will be
+ * appended to the existing ones.
+ *
+ * @param params
+ * @throws IllegalArgumentException if the params is null
+ */
+ public void append(Parameters params) throws IllegalArgumentException
{
if (params == null)
{
@@ -288,17 +252,74 @@
}
else
{
- for (Iterator entries = other.entrySet().iterator(); entries.hasNext();)
+ for (Iterator entries = other.entrySet().iterator();entries.hasNext();)
{
Map.Entry entry = (Map.Entry)entries.next();
String name = (String)entry.getKey();
- if (map.containsKey(name))
+ String[] appendedValues = (String[])entry.getValue();
+
+ // Merge or use appended values
+ String[] values = (String[])map.get(name);
+ if (values != null)
+ {
+ String[] tmp = new String[values.length + appendedValues.length];
+ System.arraycopy(values, 0, tmp, 0, values.length);
+ System.arraycopy(appendedValues, 0, tmp, values.length, appendedValues.length);
+ values = tmp;
+ }
+ else
+ {
+ values = appendedValues;
+ }
+
+ //
+ map.put(name, values);
+ }
+ }
+ }
+
+ /**
+ * Replace all the parameters.
+ *
+ * @throws IllegalArgumentException if the map is not valid
+ */
+ public void replace(Map map)
+ {
+ validateMap(map);
+ if (this.map != null)
+ {
+ this.map.clear();
+ if (map.isEmpty() == false)
+ {
+ this.map.putAll(map);
+ }
+ }
+ else
{
- throw new IllegalArgumentException("Parameters name conflict: '" + name + "' exists in both. Aborting merge.");
+ if (map.isEmpty() == false)
+ {
+ this.map = new HashMap(map);
}
- setValues(name, (String[])entry.getValue());
}
}
+
+ /**
+ * Replace all the parameters.
+ *
+ * @throws IllegalArgumentException if the parameters is not valid
+ */
+ public void replace(Parameters parameters)
+ {
+ if (parameters == null)
+ {
+ throw new IllegalArgumentException("parameters must not be null");
+ }
+ Map map = parameters.getMap();
+ if (map == null)
+ {
+ map = Collections.EMPTY_MAP;
+ }
+ replace(map);
}
/** Return the size. */
More information about the jboss-cvs-commits
mailing list