scolebourne 2002/09/18 13:11:53
Modified: lang/src/java/org/apache/commons/lang ObjectUtils.java
Log:
Add Null placeholder singleton
Revision Changes Path
1.3 +42 -3
jakarta-commons/lang/src/java/org/apache/commons/lang/ObjectUtils.java
Index: ObjectUtils.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/lang/src/java/org/apache/commons/lang/ObjectUtils.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ObjectUtils.java 18 Sep 2002 19:49:08 -0000 1.2
+++ ObjectUtils.java 18 Sep 2002 20:11:53 -0000 1.3
@@ -1,5 +1,3 @@
-package org.apache.commons.lang;
-
/* ====================================================================
* The Apache Software License, Version 1.1
*
@@ -53,7 +51,9 @@
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
+package org.apache.commons.lang;
+import java.io.Serializable;
/**
* Common <code>Object</code> manipulation routines.
*
@@ -66,6 +66,20 @@
public class ObjectUtils {
/**
+ * Singleton used as a null placeholder where null has another meaning.
+ * <p>
+ * For example, in a <code>HashMap</code> the get(key) method returns null
+ * if the Map contains null or if there is no matching key. The Null
+ * placeholder can be used to distinguish between these two cases.
+ * <p>
+ * Another example is <code>HashTable</code>, where <code>null</code>
+ * cannot be stored.
+ * <p>
+ * This instance is Serializable.
+ */
+ public static final Null NULL = new Null();
+
+ /**
* ObjectUtils instances should NOT be constructed in standard programming.
* Instead, the class should be used as
<code>ObjectUtils.defaultIfNull("a","b");</code>.
* This constructor is public to permit tools that require a JavaBean instance
@@ -121,6 +135,31 @@
.append('@')
.append(Integer.toHexString(System.identityHashCode(object)))
.toString();
+ }
+
+ /**
+ * Class used as a null placeholder where null has another meaning.
+ * <p>
+ * For example, in a <code>HashMap</code> the get(key) method returns null
+ * if the Map contains null or if there is no matching key. The Null
+ * placeholder can be used to distinguish between these two cases.
+ * <p>
+ * Another example is <code>HashTable</code>, where <code>null</code>
+ * cannot be stored.
+ */
+ public static class Null implements Serializable {
+ /**
+ * Restricted constructor - singleton
+ */
+ private Null() {
+ }
+
+ /**
+ * Ensure singleton
+ */
+ private Object readResolve() {
+ return ObjectUtils.NULL;
+ }
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>