prefuse.data.util
Class TupleComparator<T extends Tuple>

java.lang.Object
  extended by prefuse.data.util.TupleComparator<T>
All Implemented Interfaces:
java.util.Comparator<T>

public class TupleComparator<T extends Tuple>
extends java.lang.Object
implements java.util.Comparator<T>

Comparator that compares Tuples based on the value of a single field.

Author:
jeffrey heer

Constructor Summary
TupleComparator(int col, java.lang.Class type, boolean ascend)
          Creates a new TupleComparator.
TupleComparator(int col, java.lang.Class type, boolean ascend, java.util.Comparator c)
          Creates a new TupleComparator.
TupleComparator(java.lang.String field, java.lang.Class type, boolean ascend)
          Creates a new TupleComparator.
TupleComparator(java.lang.String field, java.lang.Class type, boolean ascend, java.util.Comparator<java.lang.Object> c)
          Creates a new TupleComparator.
 
Method Summary
 int compare(Tuple t1, Tuple t2)
          Compares two tuples.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Comparator
equals
 

Constructor Detail

TupleComparator

public TupleComparator(java.lang.String field,
                       java.lang.Class type,
                       boolean ascend)
Creates a new TupleComparator.

Parameters:
field - the data field to compare
type - the expected type of the data field
ascend - true to sort in ascending order, false for descending

TupleComparator

public TupleComparator(java.lang.String field,
                       java.lang.Class type,
                       boolean ascend,
                       java.util.Comparator<java.lang.Object> c)
Creates a new TupleComparator.

Parameters:
field - the data field to compare
type - the expected type of the data field
ascend - true to sort in ascending order, false for descending
c - the comparator to use. Note that for primitive types, this should be an instance of LiteralComparator, otherwise subequent errors will occur.

TupleComparator

public TupleComparator(int col,
                       java.lang.Class type,
                       boolean ascend)
Creates a new TupleComparator.

Parameters:
col - the column number of the data field to compare
type - the expected type of the data field
ascend - true to sort in ascending order, false for descending

TupleComparator

public TupleComparator(int col,
                       java.lang.Class type,
                       boolean ascend,
                       java.util.Comparator c)
Creates a new TupleComparator.

Parameters:
col - the column number of the data field to compare
type - the expected type of the data field
ascend - true to sort in ascending order, false for descending
Method Detail

compare

public int compare(Tuple t1,
                   Tuple t2)
Compares two tuples. If either input Object is not a Tuple, a ClassCastException will be thrown.

Specified by:
compare in interface java.util.Comparator<T extends Tuple>
See Also:
Comparator.compare(java.lang.Object, java.lang.Object)


Copyright © 2008 Regents of the University of California