You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by dg...@apache.org on 2003/05/25 20:18:31 UTC
cvs commit: jakarta-commons/validator/src/share/org/apache/commons/validator Msg.java
dgraham 2003/05/25 11:18:31
Modified: validator/src/share/org/apache/commons/validator/util
ValidatorUtils.java
validator/src/share/org/apache/commons/validator Msg.java
Log:
Strings do not need to be copied in clone() methods because whenever
you change the value it points to a separate String instance and doesn't
modify the other pointers.
Revision Changes Path
1.2 +6 -10 jakarta-commons/validator/src/share/org/apache/commons/validator/util/ValidatorUtils.java
Index: ValidatorUtils.java
===================================================================
RCS file: /home/cvs/jakarta-commons/validator/src/share/org/apache/commons/validator/util/ValidatorUtils.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ValidatorUtils.java 2 May 2003 23:39:31 -0000 1.1
+++ ValidatorUtils.java 25 May 2003 18:18:31 -0000 1.2
@@ -148,7 +148,7 @@
/**
* Makes a deep copy of a <code>FastHashMap</code> if the values
- * are <code>String</code>, <code>Msg</code>, <code>Arg</code>,
+ * are <code>Msg</code>, <code>Arg</code>,
* or <code>Var</code>. Otherwise it is a shallow copy.
*
* @param map <code>FastHashMap</code> to copy.
@@ -163,11 +163,7 @@
String key = (String) i.next();
Object value = map.get(key);
- // TODO I don't think Strings need to be copied and do we really need to cast
- // before cloning?
- if (value instanceof String) {
- results.put(key, new String((String) value));
- } else if (value instanceof Msg) {
+ if (value instanceof Msg) {
results.put(key, ((Msg) value).clone());
} else if (value instanceof Arg) {
results.put(key, ((Arg) value).clone());
1.6 +5 -14 jakarta-commons/validator/src/share/org/apache/commons/validator/Msg.java
Index: Msg.java
===================================================================
RCS file: /home/cvs/jakarta-commons/validator/src/share/org/apache/commons/validator/Msg.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- Msg.java 22 May 2003 03:28:05 -0000 1.5
+++ Msg.java 25 May 2003 18:18:31 -0000 1.6
@@ -119,17 +119,8 @@
*/
public Object clone() {
try {
- Msg msg = (Msg)super.clone();
-
- if (key != null) {
- msg.setName(new String(name));
- }
-
- if (key != null) {
- msg.setKey(new String(key));
- }
+ return super.clone();
- return msg;
} catch (CloneNotSupportedException e) {
throw new InternalError(e.toString());
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org