* Compares two tuples. If either input Object is not a Tuple,
* a ClassCastException will be thrown.
* @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
*/
public int compare(Object o1, Object o2) {
Tuple t1 = (Tuple)o1, t2 = (Tuple)o2;
int c = 0;
if ( m_col == -1 ) {
if ( m_type == int.class || m_type == byte.class ) {
c = ((LiteralComparator)m_cmp).compare(
t1.getInt(m_field), t2.getInt(m_field));
} else if ( m_type == double.class ) {
c = ((LiteralComparator)m_cmp).compare(
t1.getDouble(m_field), t2.getDouble(m_field));
} else if ( m_type == long.class ) {
c = ((LiteralComparator)m_cmp).compare(
t1.getLong(m_field), t2.getLong(m_field));
} else if ( m_type == float.class ) {
c = ((LiteralComparator)m_cmp).compare(
t1.getFloat(m_field), t2.getFloat(m_field));
} else if ( m_type == boolean.class ) {
c = ((LiteralComparator)m_cmp).compare(
t1.getBoolean(m_field), t2.getBoolean(m_field));
} else if ( !m_type.isPrimitive() ) {
c = m_cmp.compare(t1.get(m_field), t2.get(m_field));
} else {
throw new IllegalStateException(
"Unsupported type: " + m_type.getName());
}
} else {
if ( m_type == int.class || m_type == byte.class ) {
c = ((LiteralComparator)m_cmp).compare(
t1.getInt(m_col), t2.getInt(m_col));
} else if ( m_type == double.class ) {
c = ((LiteralComparator)m_cmp).compare(
t1.getDouble(m_col), t2.getDouble(m_col));
} else if ( m_type == long.class ) {
c = ((LiteralComparator)m_cmp).compare(
t1.getLong(m_col), t2.getLong(m_col));
} else if ( m_type == float.class ) {
c = ((LiteralComparator)m_cmp).compare(
t1.getFloat(m_col), t2.getFloat(m_col));
} else if ( m_type == boolean.class ) {
c = ((LiteralComparator)m_cmp).compare(
t1.getBoolean(m_col), t2.getBoolean(m_col));
} else if ( !m_type.isPrimitive() ) {
c = m_cmp.compare(t1.get(m_col), t2.get(m_col));
} else {
throw new IllegalStateException(
"Unsupported type: " + m_type.getName());
}
}