|
Search this API | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object y.util.Comparators
public class Comparators
This class provides access to some Comparator instances that are commonly used in yFiles.
Nested Class Summary | |
---|---|
static interface |
Comparators.PartialOrder
Tag interface to mark comparator or comparable implementations that do not define a total order but only a partial order. |
Constructor Summary | |
---|---|
Comparators()
|
Method Summary | |
---|---|
static int |
compare(double d1,
double d2)
Compares the specified floating point numbers. |
static int |
compare(float f1,
float f2)
Compares the specified floating point numbers. |
static int |
compare(int i1,
int i2)
Compares the specified integral numbers. |
static int |
compare(long l1,
long l2)
Compares the specified integral numbers. |
static Comparator |
createComparableComparator()
Returns a comparator that compares to Objects of type Comparable. |
static Comparator |
createComparableDataComparator(DataProvider dp)
Returns a comparator that compares objects of arbitrary type. |
static Comparator |
createDoubleDataComparator(DataProvider dp)
Returns a comparator that compares objects of arbitrary type. |
static Comparator |
createDoubleDataSourceComparator(DataProvider dp)
Returns a comparator that compares objects of type Edge . |
static Comparator |
createDoubleDataTargetComparator(DataProvider dp)
Returns a comparator that compares objects of type Edge . |
static Comparator |
createIntDataComparator(DataProvider dp)
Returns a comparator that compares objects of arbitrary type. |
static Comparator |
createIntDataSourceComparator(DataProvider dp)
Returns a comparator that compares objects of type Edge . |
static Comparator |
createIntDataTargetComparator(DataProvider dp)
Returns a comparator that compares objects of type Edge . |
static void |
sort(List data,
Comparator c)
Sorts the specified list of objects according to the order induced by the specified comparator. |
static void |
sort(Object[] data,
Comparator c)
Sorts the specified array of objects according to the order induced by the specified comparator. |
static void |
sort(Object[] data,
int fromIndex,
int toIndex,
Comparator c)
Sorts the specified array of objects according to the order induced by the specified comparator. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Comparators()
Method Detail |
---|
public static Comparator createIntDataSourceComparator(DataProvider dp)
Edge
. Two edges are compared by comparing their
source nodes. Each source node e.source()
in turn
is compared by the int value provided by the given data provider:
dp.getInt(e.source())
.
dp
- a data provider that must return an int value for
the source node of each edge being compared.
public static Comparator createIntDataTargetComparator(DataProvider dp)
Edge
. Two edges are compared by comparing their
target nodes. Each target node e.target()
in turn
is compared by the int value provided by the given data provider:
dp.getInt(e.target())
.
dp
- a data provider that must return an int value for
the target node of each edge being compared.
public static Comparator createDoubleDataSourceComparator(DataProvider dp)
Edge
. Two edges are compared by comparing their
source nodes. Each source node e.source()
in turn
is compared by the double value provided by the given data provider:
dp.getDouble(e.source())
.
dp
- a data provider that must return a double value for
the source node of each edge being compared.
public static Comparator createDoubleDataTargetComparator(DataProvider dp)
Edge
. Two edges are compared by comparing their
target nodes. Each target node e.target()
in turn
is compared by the double value provided by the given data provider:
dp.getDouble(e.target())
.
dp
- a data provider that must return a double value for
the target node of each edge being compared.
public static Comparator createIntDataComparator(DataProvider dp)
dp
- a data provider that must return an int value for
each object that is being compared by this comparator.
public static Comparator createDoubleDataComparator(DataProvider dp)
dp
- a data provider that must return a double value for
each object that is being compared by this comparator.
public static Comparator createComparableComparator()
public static Comparator createComparableDataComparator(DataProvider dp)
Comparable
instances
the given data provider returns for each of these objects.
dp
- a data provider that must return a Comparable for
each object that is being compared by this comparator.
public static int compare(int i1, int i2)
i1
- the first number to compare.i2
- the second number to compare.
Comparator.compare(Object, Object)
public static int compare(long l1, long l2)
l1
- the first number to compare.l2
- the second number to compare.
Comparator.compare(Object, Object)
public static int compare(float f1, float f2)
Warning: This method does not handle NaN
!
If you need NaN
-safe comparison, use
Float.compare(float, float)
instead.
f1
- the first number to compare.f2
- the second number to compare.
Comparator.compare(Object, Object)
public static int compare(double d1, double d2)
Warning: This method does not handle NaN
!
If you need NaN
-safe comparison, use
Double.compare(double, double)
instead.
d1
- the first number to compare.d2
- the second number to compare.
Comparator.compare(Object, Object)
public static void sort(List data, Comparator c)
This sort is guaranteed to be stable: Equal elements will not be reordered as a result of the sort.
Implementation note:
If the comparator is marked with the Comparators.PartialOrder
interface,
this implementation is behavior-compatible with the pre-Java-7 version of
Collections.sort(java.util.List, java.util.Comparator)
in the sense that it does not throw IllegalArgumentException
if the specified comparator used for sorting does not define a total order.
data
- the list to be sorted.c
- the comparator to determine the order of the list.
A null
value indicates that the elements'
natural ordering
should be used.Comparators.PartialOrder
public static void sort(Object[] data, Comparator c)
This sort is guaranteed to be stable: Equal elements will not be reordered as a result of the sort.
Implementation note:
If the comparator is marked with the Comparators.PartialOrder
interface,
this implementation is behavior-compatible with the pre-Java-7 version of
Arrays.sort(Object[], java.util.Comparator)
in the sense
that it does not throw IllegalArgumentException
if the
specified comparator used for sorting does not define a total order.
data
- the array to be sorted.c
- the comparator to determine the order of the array.
A null
value indicates that the elements'
natural ordering
should be used.Comparators.PartialOrder
public static void sort(Object[] data, int fromIndex, int toIndex, Comparator c)
This sort is guaranteed to be stable: Equal elements will not be reordered as a result of the sort.
Implementation note:
If the comparator is marked with the Comparators.PartialOrder
interface,
this implementation is behavior-compatible with the pre-Java-7 version of
Arrays.sort(Object[], int, int, java.util.Comparator)
in the sense that it does not throw IllegalArgumentException
if the specified comparator used for sorting does not define a total order.
IllegalArgumentException
- if fromIndex > toIndex
.
ArrayIndexOutOfBoundsException
- if fromIndex < 0
or
toIndex > a.length
.data
- the array to be sorted.fromIndex
- the index of the first element (inclusive) to be sorted.toIndex
- the index of the last element (exclusive) to be sorted.c
- the comparator to determine the order of the array.
A null
value indicates that the elements'
natural ordering
should be used.Comparators.PartialOrder
|
© Copyright 2000-2013, yWorks GmbH. All rights reserved. |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |