Clover coverage report -
Coverage timestamp: Thu Jul 5 2007 20:02:32 EDT
file stats: LOC: 135   Methods: 8
NCLOC: 64   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
Null.java 100% 94.1% 87.5% 94.3%
coverage coverage
 1    /*
 2    * JBoss, the OpenSource J2EE webOS
 3    *
 4    * Distributable under LGPL license.
 5    * See terms of license at gnu.org.
 6    */
 7    package org.jboss.cache.pojo.util;
 8   
 9    import java.io.Serializable;
 10   
 11    /**
 12    * Represent null values (based on org.jboss.util.Null)
 13    *
 14    * @author Scott Marlow
 15    */
 16    public final class Null implements Serializable
 17    {
 18    static final long serialVersionUID = -402153636437493134L;
 19    /**
 20    * singleton instance of Null.
 21    */
 22    private static final Null NULL_OBJECT_MARKER = new Null();
 23   
 24    // String representation of Null
 25    private static final String NULL_AS_STRING_REPRESENTATION = "jboss.cache._NULL_";
 26   
 27    /**
 28    * Do not allow public construction.
 29    */
 30  56 private Null()
 31    {
 32    }
 33   
 34   
 35    /**
 36    * Represents null as a special Null object marker.
 37    *
 38    * @param aObject
 39    * @return if aObject is null, return Null.NULL_OBJECT_MARKER otherwise return aObject.
 40    */
 41  3783 public final static Object toNullObject(Object aObject)
 42    {
 43  3783 if (aObject == null)
 44    {
 45  24 return NULL_OBJECT_MARKER;
 46    } else
 47    {
 48  3759 return aObject;
 49    }
 50    }
 51   
 52    /**
 53    * Represents null key as a special string value.
 54    *
 55    * @param aObject
 56    * @return if aObject is null, return Null.NULL_AS_STRING_REPRESENTATION otherwise return aObject.
 57    */
 58  517 public final static Object toNullKeyObject(Object aObject)
 59    {
 60  517 if (aObject == null)
 61    {
 62  38 return NULL_AS_STRING_REPRESENTATION;
 63    } else
 64    {
 65  479 return aObject;
 66    }
 67    }
 68   
 69    /**
 70    * If the passed object represents null (instance of Null.NULL_OBJECT_MARKER), will replace with null value.
 71    *
 72    * @param aObject
 73    * @return null if aObject is instance of Null.NULL_OBJECT_MARKER, otherwise return aObject.
 74    */
 75  4091 public final static Object toNullValue(Object aObject)
 76    {
 77  4091 if (NULL_OBJECT_MARKER.equals(aObject))
 78    {
 79  49 return null;
 80    } else
 81    {
 82  4042 return aObject;
 83    }
 84    }
 85   
 86    /**
 87    * Converts Null string representation back to null value.
 88    *
 89    * @param aObject
 90    * @return null if aObject represents a null, otherwise return aObject.
 91    */
 92  110 public final static Object toNullKeyValue(Object aObject)
 93    {
 94  110 if (NULL_AS_STRING_REPRESENTATION.equals(aObject))
 95    {
 96  8 return null;
 97    } else
 98    {
 99  102 return aObject;
 100    }
 101    }
 102   
 103   
 104    /**
 105    * Return a string representation of null value.
 106    *
 107    * @return Null.NULL_AS_STRING_REPRESENTATION;
 108    */
 109  0 public String toString()
 110    {
 111  0 return NULL_AS_STRING_REPRESENTATION;
 112    }
 113   
 114    /**
 115    * Hashcode of unknown (null) value will be zero.
 116    *
 117    * @return Zero.
 118    */
 119  32 public int hashCode()
 120    {
 121  32 return 0;
 122    }
 123   
 124    /**
 125    * Check if the given object is a Null instance or <tt>null</tt>.
 126    *
 127    * @param obj Object to test.
 128    * @return True if the given object is a Null instance or <tt>null</tt>.
 129    */
 130  4106 public boolean equals(final Object obj)
 131    {
 132  21 if (obj == this) return true;
 133  4085 return (obj == null || obj.getClass() == getClass() || NULL_AS_STRING_REPRESENTATION.equals(obj));
 134    }
 135    }