1 dojo.provide("calitha.collections.util");
  2 
  3 /**
  4  * @name calitha.collections.util
  5  * @namespace
  6  * @description This is a collection of misc convenience methods. They primarily try to prevent extra
  7  * parameter validation (for example for null) in code.
  8  *
  9  */
 10 
 11 /**
 12  * @function
 13  * @param value1 a value
 14  * @param value2 another value
 15  * @returns {Boolean} true if the values are equal
 16  * @description Determines if two values are equal. Values are strictly equal if the strictly equals operator ===
 17  * return true, or if the equals method on the object return true. Of course object must have such a method.
 18  * Otherwise it returns false.
 19  */
 20 calitha.collections.util.equals = function(/**Object*/ value1, /**Object*/ value2)
 21 {
 22     if (value1 === value2)
 23         return true;
 24     if (value1 === null)
 25         return false;
 26     if (value2 === null)
 27         return false;
 28     if (value1.equals)
 29         return value1.equals(value2);
 30     return false;
 31 };
 32 
 33 /**
 34  * @function
 35  * @param obj object
 36  * @returns {Number} hash code
 37  * @description Determines the hashcode for an object. The object can be null in which case it returns 0.
 38  */
 39 calitha.collections.util.hashCode = function(/**Object*/ obj)
 40 {
 41     if (obj == null)
 42     {
 43         return 0;
 44     }
 45     else if (obj.hashCode)
 46     {
 47         return obj.hashCode();
 48     }
 49     throw new calitha.exception.IllegalArgumentException(Error("no hashCode available"));
 50 };
 51 
 52 /**
 53  * @function
 54  * @param obj object
 55  * @param clazz class
 56  * @returns {Boolean} true if the object is an instance of the class
 57  * @description Determines if the object is an instance of a class (which is a function in javascript).
 58  * <p>This function uses the special dojo isInstanceOf function, so it can deal with multiple inheritance.
 59  */
 60 calitha.collections.util.isObjectInstanceOf = function(/**Object*/ obj, /**Function*/ clazz)
 61 {
 62     if (obj == null)
 63     {
 64         return false;
 65     }
 66     if (obj.isInstanceOf)
 67     {
 68         return obj.isInstanceOf(clazz);
 69     }
 70     return obj instanceof clazz;
 71 };
 72 
 73 /**
 74  * @function
 75  * @param obj object
 76  * @param property property name
 77  * @returns {Boolean} true if it has the property
 78  * @description Determines if the object has a property with this name
 79  */
 80 calitha.collections.util.has = function(obj, property)
 81 {
 82     return (typeof obj[name] !== 'undefined');
 83 };
 84