/** * Compares 2 Objects. Both must be of the same type or mutually comparable. * * <p>If they are Comparable - calling compareTo method of <code>val1</code> on <code>val2</code> * If not: constructing 2 strings from val1 and val2 and calling compareTo method of String. * * @param val1 first object to be compared. * @param val2 second object to be compared. * @return If the objects are compared as Strings - the returned value is the same as String's * compareTo(Object) would return. else: 1 if val1 is greater than val2. -1 if val1 is smaller * than vla2. 0 if they are equal. */ public int compareObjects(Object val1, Object val2) { // if they are comparable using the compareTo method if (val1 instanceof Comparable) { return ((Comparable) val1).compareTo(val2); } if (val1 instanceof Boolean) { return SparseBooleanColumn.compareBooleans( ((Boolean) val1).booleanValue(), ((Boolean) val2).booleanValue()); } String str1, str2; if (val1 instanceof byte[]) { str1 = new String((byte[]) val1); str2 = new String((byte[]) val2); } else if (val1 instanceof char[]) { str1 = new String((char[]) val1); str2 = new String((char[]) val2); } else { str1 = val1.toString(); str2 = val2.toString(); } // converting to strings and comparing return str1.compareTo(str2); }
/** * Returns the item at pos as a boolean. If the item is a Boolean, return its boolean value, * otherwise construct a new Boolean by calling the toString() method on the item and return its * boolean value. * * @param row the row number * @return the item as pos as a boolean value. If no such item exists returns false. */ public boolean getBoolean(int row) { Object obj = elements.get(row); if (obj != null) { return SparseBooleanColumn.toBoolean(obj); } return SparseDefaultValues.getDefaultBoolean(); }