/**
   * Compares 2 values that are in this column. Retruns an int representation of the relation
   * between the values.
   *
   * @param pos1 - the row number of the first value to be compared
   * @param pos2 - the row number of the second value to be compared
   * @return int - representing the relation between the values at row # <code>pos1</code> and row #
   *     <code>pos2</code>. if pos1's value > pos2' value returns 1. if pos1's value < pos2' value
   *     returns -1. returns 0 if they are equal.
   */
  public int compareRows(int pos1, int pos2) {
    // validating the objects in the given rows.
    int val = validate(pos1, pos2);
    if (val <= 1) {
      return val;
    }

    Object obj1 = getObject(pos1);
    Object obj2 = getObject(pos2);

    // if both are of the same class - comparing them
    if (obj1.getClass().equals(obj2.getClass())) {
      return compareObjects(obj1, obj2);
    }

    // if all the elements in this column are numeric - converting
    // the objects to doubles and comparing them.
    if (isNumeric()) {
      return SparseDoubleColumn.compareDoubles(getDouble(pos1), getDouble(pos2));
    }

    // if not all of the elements are numeric - coverting the objects to strings
    // and comparing them.
    return SparseStringColumn.toStringObject(obj1)
        .compareTo(SparseStringColumn.toStringObject(obj2));
  }
  /**
   * 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);
  }
 private void toComparableArray(Object[] array) {
   for (int i = 0; i < array.length; i++) {
     if (type == ColumnTypes.CHAR_ARRAY || type == ColumnTypes.BYTE_ARRAY) {
       array[i] = SparseStringColumn.toStringObject(array[i]);
     }
   }
 }
  /**
   * 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);
  }
 /**
  * Returns the value at row # row, represented as a String.
  *
  * @param row the row number
  * @return a String Object representing the value at row # row. if no such value exists returns
  *     null
  */
 public String getString(int row) {
   Object obj = elements.get(row);
   return SparseStringColumn.toStringObject(obj);
 }