Search this API

y.util
Class Comparators

java.lang.Object
  extended by y.util.Comparators

public class Comparators
extends java.lang.Object

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 java.util.Comparator createComparableComparator()
          Returns a Comparator that compares to Objects of type Comparable.
static java.util.Comparator createComparableDataComparator(DataProvider dp)
          Returns a Comparator that compares objects of arbitrary type.
static java.util.Comparator createDoubleDataComparator(DataProvider dp)
          Returns a Comparator that compares objects of arbitrary type.
static java.util.Comparator createDoubleDataSourceComparator(DataProvider dp)
          Returns a Comparator that compares objects of type Edge.
static java.util.Comparator createDoubleDataTargetComparator(DataProvider dp)
          Returns a Comparator that compares objects of type Edge.
static java.util.Comparator createIntDataComparator(DataProvider dp)
          Returns a Comparator that compares objects of arbitrary type.
static java.util.Comparator createIntDataSourceComparator(DataProvider dp)
          Returns a Comparator that compares objects of type Edge.
static java.util.Comparator createIntDataTargetComparator(DataProvider dp)
          Returns a Comparator that compares objects of type Edge.
static void sort(java.util.List data, java.util.Comparator c)
          Sorts the specified list of objects according to the order induced by the specified Comparator.
static void sort(java.lang.Object[] data, java.util.Comparator c)
          Sorts the specified array of objects according to the order induced by the specified Comparator.
static void sort(java.lang.Object[] data, int fromIndex, int toIndex, java.util.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

Comparators

public Comparators()
Method Detail

createIntDataSourceComparator

public static java.util.Comparator createIntDataSourceComparator(DataProvider dp)
Returns a Comparator that compares objects of type 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()).

Parameters:
dp - a data provider that must return an int value for the source node of each edge being compared.
Returns:
a Comparator that compares edges.

createIntDataTargetComparator

public static java.util.Comparator createIntDataTargetComparator(DataProvider dp)
Returns a Comparator that compares objects of type 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()).

Parameters:
dp - a data provider that must return an int value for the target node of each edge being compared.
Returns:
a Comparator that compares edges.

createDoubleDataSourceComparator

public static java.util.Comparator createDoubleDataSourceComparator(DataProvider dp)
Returns a Comparator that compares objects of type 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()).

Parameters:
dp - a data provider that must return a double value for the source node of each edge being compared.
Returns:
a Comparator that compares edges.

createDoubleDataTargetComparator

public static java.util.Comparator createDoubleDataTargetComparator(DataProvider dp)
Returns a Comparator that compares objects of type 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()).

Parameters:
dp - a data provider that must return a double value for the target node of each edge being compared.
Returns:
a Comparator that compares edges.

createIntDataComparator

public static java.util.Comparator createIntDataComparator(DataProvider dp)
Returns a Comparator that compares objects of arbitrary type. Two objects are compared by comparing the int value the given data provider returns for each of these objects.

Parameters:
dp - a data provider that must return an int value for each object that is being compared by this comparator.
Returns:
a Comparator that compares arbitrary objects.

createDoubleDataComparator

public static java.util.Comparator createDoubleDataComparator(DataProvider dp)
Returns a Comparator that compares objects of arbitrary type. Two objects are compared by comparing the double value the given data provider returns for each of these objects.

Parameters:
dp - a data provider that must return a double value for each object that is being compared by this comparator.
Returns:
a Comparator that compares arbitrary objects.

createComparableComparator

public static java.util.Comparator createComparableComparator()
Returns a Comparator that compares to Objects of type Comparable.


createComparableDataComparator

public static java.util.Comparator createComparableDataComparator(DataProvider dp)
Returns a Comparator that compares objects of arbitrary type. Two objects are compared by comparing the Comparable instances the given data provider returns for each of these objects.

Parameters:
dp - a data provider that must return a Comparable for each object that is being compared by this comparator.
Returns:
a Comparator that compares arbitrary objects.

compare

public static int compare(int i1,
                          int i2)
Compares the specified integral numbers. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

Parameters:
i1 - the first number to compare.
i2 - the second number to compare.
Returns:
a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.
See Also:
Comparator.compare(Object, Object)

compare

public static int compare(long l1,
                          long l2)
Compares the specified integral numbers. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

Parameters:
l1 - the first number to compare.
l2 - the second number to compare.
Returns:
a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.
See Also:
Comparator.compare(Object, Object)

compare

public static int compare(float f1,
                          float f2)
Compares the specified floating point numbers. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

Warning: This method does not handle NaN! If you need NaN-safe comparison, use Float.compare(float, float) instead.

Parameters:
f1 - the first number to compare.
f2 - the second number to compare.
Returns:
a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.
See Also:
Comparator.compare(Object, Object)

compare

public static int compare(double d1,
                          double d2)
Compares the specified floating point numbers. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

Warning: This method does not handle NaN! If you need NaN-safe comparison, use Double.compare(double, double) instead.

Parameters:
d1 - the first number to compare.
d2 - the second number to compare.
Returns:
a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.
See Also:
Comparator.compare(Object, Object)

sort

public static void sort(java.util.List data,
                        java.util.Comparator c)
Sorts the specified list of objects according to the order induced by the specified Comparator.

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.

Parameters:
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.
See Also:
Comparators.PartialOrder

sort

public static void sort(java.lang.Object[] data,
                        java.util.Comparator c)
Sorts the specified array of objects according to the order induced by the specified Comparator.

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.

Parameters:
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.
See Also:
Comparators.PartialOrder

sort

public static void sort(java.lang.Object[] data,
                        int fromIndex,
                        int toIndex,
                        java.util.Comparator c)
Sorts the specified array of objects according to the order induced by the specified Comparator.

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.

Parameters:
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.
Throws:
java.lang.IllegalArgumentException - if fromIndex > toIndex.
java.lang.ArrayIndexOutOfBoundsException - if fromIndex < 0 or toIndex > a.length.
See Also:
Comparators.PartialOrder

© Copyright 2000-2022,
yWorks GmbH.
All rights reserved.