public class JavaStringComparator extends StringComparator.Base implements StringComparator
StringComparator
, this class is
merely a wrapper for the String.compareTo(java.lang.String)
method. It exists not only
as a trivial example, but also to provide a "standard" comparator for
situations in which a reference to a Comparator
instance is
necessary.StringComparator.Base
EVALUATION_INDETERMINATE
EQUAL, S1_IS_GREATER, S2_IS_GREATER
Constructor and Description |
---|
JavaStringComparator()
Default constructor.
|
JavaStringComparator(boolean bForceReturnConstants)
Allows the caller to request that the
StringComparator.Base.compare(java.lang.String, java.lang.String) method still
return the exact values that correspond to the semantic constants
available in StringComparator . |
Modifier and Type | Method and Description |
---|---|
protected int |
executeComparison(java.lang.String s1,
java.lang.String s2)
Wrapper for
String.compareTo(java.lang.String) , unless the instance was created
with the "force return constants" switch set, in which case the value is
coerced to one of the constants from StringComparator . |
compare, compareAsObjects
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
compare, comparing, comparing, comparingDouble, comparingInt, comparingLong, equals, naturalOrder, nullsFirst, nullsLast, reversed, reverseOrder, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
public JavaStringComparator()
StringComparator.Base.compare(java.lang.String, java.lang.String)
will be the value that would have
been returned by String.compareTo(java.lang.String)
. If you want to force the
comparator to use the semantic constants that are defined in
StringComparator
, then use the alternative
JavaStringComparator(boolean)
constructor and pass true
.public JavaStringComparator(boolean bForceReturnConstants)
StringComparator.Base.compare(java.lang.String, java.lang.String)
method still
return the exact values that correspond to the semantic constants
available in StringComparator
.bForceReturnConstants
- if true
, then the exact constants
from StringComparator
will be used; otherwise, the raw return
value of String.compareTo(java.lang.String)
will be returned.protected int executeComparison(java.lang.String s1, java.lang.String s2)
String.compareTo(java.lang.String)
, unless the instance was created
with the "force return constants" switch set, in which case the value is
coerced to one of the constants from StringComparator
.executeComparison
in class StringComparator.Base
s1
- the first string to compares2
- the second string to compareString.compareTo(java.lang.String)
would have returned, or
one of the constants from StringComparator
.