|
LimeWire collection component api | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.limewire.collection.Comparators
public final class Comparators
Provides a way to compare various data types with static methods.
Comparators is a utility class that uses the strategy
pattern for Comparable instances. Many of these comparators
are only necessary because the Java 1.1.8 versions of their classes
did not implement the Comparable interface.
Comparators are helpful when using a FixedsizePriorityQueue.
FixedsizePriorityQueue<String> fpq =
new FixedsizePriorityQueue<String>(Comparators.stringComparator(), 3);
fpq.insert("Abby");
fpq.insert("Bob");
fpq.insert("Chris");
System.out.println(fpq);
String s = fpq.insert("Dan");
System.out.println("Inserting another String pushes out an element (" + s + ") since the max. size was reached.");
System.out.println(fpq);
System.out.println("Minimum element: " + fpq.getMin());
System.out.println("Maximum element: " + fpq.getMax());
fpq.extractMax();
System.out.println(fpq);
Output:
[Abby, Bob, Chris]
Inserting another String pushes out an element (Abby) since the max. size was reached.
[Bob, Chris, Dan]
Minimum element: Bob
Maximum element: Dan
[Bob, Chris]
| Nested Class Summary | |
|---|---|
static class |
Comparators.ByteArrayComparator
Compares two byte arrays. |
static class |
Comparators.CaseInsensitiveStringComparator
Compares String objects without regard to case. |
| Method Summary | |
|---|---|
static Comparator<String> |
caseInsensitiveStringComparator()
Instance assessor for the Comparator for case insensitive
Strings. |
static Comparator<File> |
fileComparator()
Instance assessor for the Comparator for Files. |
static int |
intCompareTo(Integer thisInt,
Integer anotherInt)
Compares two Integer objects numerically. |
static Comparator<Integer> |
integerComparator()
Instance assessor for the Comparator for Integers. |
static Comparator<Double> |
inverseDoubleComparator()
|
static Comparator<Integer> |
inverseIntegerComparator()
|
static Comparator<Long> |
inverseLongComparator()
Instance assessor for the inverse Comparator for Longs. |
static Comparator<Long> |
longComparator()
Instance assessor for the Comparator for Longs. |
static int |
longCompareTo(Long firstLong,
Long secondLong)
Compares two Long objects numerically. |
static Comparator<String> |
stringComparator()
Instance assessor for the Comparator for Strings. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static Comparator<Integer> integerComparator()
Comparator for Integers.
This is necessary because the Integer class did not implement
Comparable in Java 1.1.8. This is an instance because the
IntComparator has no state, allowing a single instance to be
used whenever a Comparator is needed for Integers.
IntComparator instancepublic static Comparator<Integer> inverseIntegerComparator()
public static Comparator<Long> longComparator()
Comparator for Longs. This
is necessary because the Long class did not implement
Comparable in Java 1.1.8. This is an instance because the
LongComparator has no state, allowing a single instance to be
used whenever a Comparator is needed for Longs.
LongComparator instancepublic static Comparator<Long> inverseLongComparator()
Comparator for Longs.
This is necessary because the Long class did not implement
Comparable in Java 1.1.8. This is an instance because the
LongComparator has no state, allowing a single instance to be
used whenever a Comparator is needed for Longs.
LongComparator instancepublic static Comparator<Double> inverseDoubleComparator()
public static Comparator<String> stringComparator()
Comparator for Strings. This
is necessary because the String class did not implement
Comparable in Java 1.1.8. This is an instance because the
StringComparator has no state, allowing a single instance to be
used whenever a Comparator is needed for Strings.
StringComparator instancepublic static Comparator<File> fileComparator()
Comparator for Files. This
is necessary because the File class did not implement
Comparable in Java 1.1.8. This is an instance because the
FileComparator has no state, allowing a single instance to be
used whenever a Comparator is needed for Files.
FileComparator instancepublic static Comparator<String> caseInsensitiveStringComparator()
Comparator for case insensitive
Strings. This is an instance because the
CaseInsensitiveStringComparator has no state, allowing a single
instance to be used whenever a Comparator is needed.
CaseInsensitiveStringComparator instance
public static int intCompareTo(Integer thisInt,
Integer anotherInt)
public static int longCompareTo(Long firstLong,
Long secondLong)
Long objects numerically. This function is
identical to the Long compareTo method. The Long compareTo method was
added in Java 1.2, however, so any app that is 1.1.8 compatible must use
this method.
firstLong - the first Long to be compared.secondLong - the second Long to be compared.
0 if the first Long
argument is equal to the second Long argument; a value
less than 0 if the first Long argument is
numerically less than the second Long; and a
value greater than 0 if the first Long
argument is numerically greater than the second Long
argument (signed comparison).
|
LimeWire collection component api | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||