scolebourne 2004/07/17 14:23:59
Modified: collections/src/java/org/apache/commons/collections
MapUtils.java
Log:
Javadoc safeAddToMap
Revision Changes Path
1.47 +14 -11
jakarta-commons/collections/src/java/org/apache/commons/collections/MapUtils.java
Index: MapUtils.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/MapUtils.java,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -r1.46 -r1.47
--- MapUtils.java 21 Apr 2004 20:34:11 -0000 1.46
+++ MapUtils.java 17 Jul 2004 21:23:59 -0000 1.47
@@ -1074,24 +1074,27 @@
}
/**
- * Nice method for adding data to a map in such a way
- * as to not get NPE's. The point being that if the
- * value is null, map.put() will throw an exception.
- * That blows in the case of this class cause you may want to
- * essentially treat put("Not Null", null ) == put("Not Null", "")
- * We will still throw a NPE if the key is null cause that should
- * never happen.
+ * Protects against adding null values to a map.
+ * <p>
+ * This method checks the value being added to the map, and if it is null
+ * it is replaced by an empty string.
+ * <p>
+ * This could be useful if the map does not accept null values, or for
+ * receiving data from a source that may provide null or empty string
+ * which should be held in the same way in the map.
+ * <p>
+ * Keys are not validated.
*
* @param map the map to add to, may not be null
* @param key the key
- * @param value the value
+ * @param value the value, null converted to ""
* @throws NullPointerException if the map is null
*/
public static void safeAddToMap(Map map, Object key, Object value) throws
NullPointerException {
if (value == null) {
- map.put ( key, "" );
+ map.put(key, "");
} else {
- map.put ( key, value );
+ map.put(key, value);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]