/** * Compared the value represented by element and the one of row number <code>pos</code>. <code> * elements</code> will be converted to a compatible type to this column. if element > pos returns * 1. if element < pos retruns -1. if the are equal returns 0. if one of the representation does * not hold a value, it is considered smaller than the other. */ public int compareRows(Object element, int pos) { // validating the objects to be compared int val = validate(element, pos); if (val <= 1) { return val; } // retrieving the object from pos Object obj = getObject(pos); // if they are of the smae type - comparing them if (element.getClass().equals(obj.getClass())) { return compareObjects(element, obj); } // if both are numbers - comparing them as doubles. if (element instanceof Number && obj instanceof Number) { return SparseDoubleColumn.compareDoubles( SparseDoubleColumn.toDouble(element), SparseDoubleColumn.toDouble(obj)); } // they are probably not mutually comparable... // if this is an object column, i.e. the type of the objects is unknown // converting both of the objects into strings and comparing them if (ColumnTypes.OBJECT == getType()) { return SparseStringColumn.toStringObject(element) .compareTo(SparseStringColumn.toStringObject(obj)); } // this is not an object column - converting element to the type of this // column, and comparing the objects. switch (getType()) { case (ColumnTypes.BYTE_ARRAY): element = SparseByteArrayColumn.toByteArray(element); break; case (ColumnTypes.CHAR_ARRAY): element = SparseCharArrayColumn.toCharArray(element); break; case (ColumnTypes.STRING): element = SparseStringColumn.toStringObject(element); break; default: break; } return compareObjects(element, obj); }
/** * If the item at pos is a Number, return its double value. Otherwise if the item is a char[] or * any other type of Object, convert the item to a String and return its double value by calling * Double.parseDouble() * * @param row the row number * @return the double value of the item at row # row. if no such item exists returns a value * signifying the position is empty, as defined by SparseDoubleColumn. */ public double getDouble(int row) { Object obj = elements.get(row); if (obj != null && isDataNumeric(row)) { return SparseDoubleColumn.toDouble(obj); } return SparseDefaultValues.getDefaultDouble(); }