| java.lang.Object prefuse.data.util.Sort
Sort | public class Sort (Code) | | Utility class representing sorting criteria, this can be given as
input to the
TupleSet.tuples(PredicateSort) method to
get a sorted iteration of tuples.
Sort criteria consists of an ordered list of data field names to
sort by, along with an indication to sort tuples in either ascending
or descending order. These criteria can be passed in to the
constructor or added incrementally using the
Sort.add(String,boolean) method.
Alternatively, one can also specify the sorting criteria using a
single string, which is parsed using the
Sort.parse(String) method.
This string should consist
of a comma-delimited list of field names, which optional "ASC" or
"DESC" modifiers to specify ascending or descending sorts. If no
modifier is given, ascending order is assumed. Field
names which include spaces or other non-standard characters should
be written in brackets ([]), just as is done in
prefuse.data.expression.parser.ExpressionParser expressionlanguage statements . For example, the
following string
"Profit DESC, [Product Type]"
sorts first by the data field "Profit" in descending order,
additionally sorting in ascending order by the data field
"Product Type" for tuples which have identical values in the
"Profit" field.
author: jeffrey heer |
Constructor Summary | |
public | Sort() Creates a new, empty Sort specification. | public | Sort(String[] fields) Creates a new Sort specification that sorts on the
given fields, all in ascending order. | public | Sort(String[] fields, boolean[] ascend) Creates a new Sort specification that sorts on the
given fields in the given orders. |
Method Summary | |
public void | add(String field, boolean ascend) Adds a new field to this Sort specification. | public Comparator | getComparator(TupleSet ts) Generates a Comparator to be used for sorting tuples drawn from
the given tuple set. | public String | getField(int i) Returns the sort field at the given index. | public boolean | isAscending(int i) Returns the ascending modifier as the given index. | public static Sort | parse(String s) Parse a comma-delimited String of data fields to sort on, along
with optional ASC or DESC modifiers, to generate a new Sort
specification. | public int | size() Returns the number of fields in this Sort specification. | public String | toString() |
Sort | public Sort()(Code) | | Creates a new, empty Sort specification.
|
Sort | public Sort(String[] fields)(Code) | | Creates a new Sort specification that sorts on the
given fields, all in ascending order.
Parameters: fields - the fields to sort on, in order of precedence |
Sort | public Sort(String[] fields, boolean[] ascend)(Code) | | Creates a new Sort specification that sorts on the
given fields in the given orders.
Parameters: fields - the fields to sort on, in order of precedence Parameters: ascend - for each field, indicates if the field shouldbe sorted in ascending (true) or descending (false) order |
add | public void add(String field, boolean ascend)(Code) | | Adds a new field to this Sort specification.
Parameters: field - the additional field to sort on Parameters: ascend - indicates if the field shouldbe sorted in ascending (true) or descending (false) order |
getComparator | public Comparator getComparator(TupleSet ts)(Code) | | Generates a Comparator to be used for sorting tuples drawn from
the given tuple set.
Parameters: ts - the TupleSet whose Tuples are to be sorted a Comparator instance for sorting tuples from the givenset using the sorting criteria given in this specification |
getField | public String getField(int i)(Code) | | Returns the sort field at the given index.
Parameters: i - the index to look up the sort field at the given index |
isAscending | public boolean isAscending(int i)(Code) | | Returns the ascending modifier as the given index.
Parameters: i - the index to look up true if the field at the given index is to be sortedin ascending order, false for descending order |
parse | public static Sort parse(String s)(Code) | | Parse a comma-delimited String of data fields to sort on, along
with optional ASC or DESC modifiers, to generate a new Sort
specification. This string should consist
of a comma-delimited list of field names, which optional "ASC" or
"DESC" modifiers to specify ascending or descending sorts. If no
modifier is given, ascending order is assumed. Field
names which include spaces or other non-standard characters should
be written in brackets ([]), just as is done in
prefuse.data.expression.parser.ExpressionParser expressionlanguage statements . For example, the
following string
"Profit DESC, [Product Type]"
sorts first by the data field "Profit" in descending order,
additionally sorting in ascending order by the data field
"Product Type" for tuples which have identical values in the
"Profit" field.
Parameters: s - the sort specification String a new Sort specification |
size | public int size()(Code) | | Returns the number of fields in this Sort specification.
the number of fields to sort on |
|
|