|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object prefuse.data.util.Sort
public class Sort
Utility class representing sorting criteria, this can be given as
input to the TupleSet.tuples(Predicate, Sort)
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
add(String, boolean)
method.
Alternatively, one can also specify the sorting criteria using a
single string, which is parsed using the 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
expression
language 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.
Constructor Summary | |
---|---|
Sort()
Creates a new, empty Sort specification. |
|
Sort(java.lang.String[] fields)
Creates a new Sort specification that sorts on the given fields, all in ascending order. |
|
Sort(java.lang.String[] fields,
boolean[] ascend)
Creates a new Sort specification that sorts on the given fields in the given orders. |
Method Summary | |
---|---|
void |
add(java.lang.String field,
boolean ascend)
Adds a new field to this Sort specification. |
java.util.Comparator |
getComparator(TupleSet ts)
Generates a Comparator to be used for sorting tuples drawn from the given tuple set. |
java.lang.String |
getField(int i)
Returns the sort field at the given index. |
boolean |
isAscending(int i)
Returns the ascending modifier as the given index. |
static Sort |
parse(java.lang.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. |
int |
size()
Returns the number of fields in this Sort specification. |
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public Sort()
public Sort(java.lang.String[] fields)
fields
- the fields to sort on, in order of precedencepublic Sort(java.lang.String[] fields, boolean[] ascend)
fields
- the fields to sort on, in order of precedenceascend
- for each field, indicates if the field should
be sorted in ascending (true) or descending (false) orderMethod Detail |
---|
public void add(java.lang.String field, boolean ascend)
field
- the additional field to sort onascend
- indicates if the field should
be sorted in ascending (true) or descending (false) orderpublic int size()
public java.lang.String getField(int i)
i
- the index to look up
public boolean isAscending(int i)
i
- the index to look up
public java.util.Comparator getComparator(TupleSet ts)
ts
- the TupleSet whose Tuples are to be sorted
public static Sort parse(java.lang.String s)
expression
language 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.
s
- the sort specification String
public java.lang.String toString()
toString
in class java.lang.Object
Object.toString()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |