/**
   * 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);
  }
  /**
   * Inserts a new entry in the Column at position <code>pos</code>. All entries at row numbers
   * greater than <codE>pos</code> are moved down the column to the next row.
   *
   * @param newEntry the newEntry to insert
   * @param pos the position to insert at
   */
  public void insertRow(Object newEntry, int pos) {

    switch (getType()) {
      case ColumnTypes.BYTE_ARRAY:
        newEntry = SparseByteArrayColumn.toByteArray(newEntry);
        break;
      case ColumnTypes.CHAR_ARRAY:
        newEntry = SparseCharArrayColumn.toCharArray(newEntry);
        break;
      case ColumnTypes.STRING:
        newEntry = SparseStringColumn.toStringObject(newEntry);
        break;
    }

    super.insertRow(newEntry, pos);
  }
 /**
  * If the item at pos is a char[], return it. Otherwise converts it to a char[] using
  * SparseCharArrayColumn's method.
  *
  * @param row the row number
  * @return the value at row # row represented with a chars array. If no such value exists returns
  *     null.
  */
 public char[] getChars(int row) {
   Object obj = elements.get(row);
   return SparseCharArrayColumn.toCharArray(obj);
 }