public final class NaturalStrings
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static int |
compareNatural(java.text.Collator collator,
java.lang.String s,
java.lang.String t)
Compares two strings using the given collator and comparing contained numbers based on their
numeric values.
|
static int |
compareNatural(java.lang.String s,
java.lang.String t)
Compares two strings using the current locale's rules and comparing contained numbers based
on their numeric values.
|
static int |
compareNaturalAscii(java.lang.String s,
java.lang.String t)
Compares two strings using each character's Unicode value for non-digit characters and the
numeric values off any contained numbers.
|
static int |
compareNaturalIgnoreCaseAscii(java.lang.String s,
java.lang.String t)
Compares two strings using each character's Unicode value - ignoring upper/lower case - for
non-digit characters and the numeric values of any contained numbers.
|
static java.util.Comparator<java.lang.String> |
getNaturalComparator()
Returns a comparator that compares contained numbers based on their numeric values and
compares other parts using the current locale's order rules.
|
static java.util.Comparator<java.lang.String> |
getNaturalComparator(java.text.Collator collator)
Returns a comparator that compares contained numbers based on their numeric values and
compares other parts using the given collator.
|
static java.util.Comparator<java.lang.String> |
getNaturalComparatorAscii()
Returns a comparator that compares contained numbers based on their numeric values and
compares other parts based on each character's Unicode value.
|
static java.util.Comparator<java.lang.String> |
getNaturalComparatorIgnoreCaseAscii()
Returns a comparator that compares contained numbers based on their numeric values and
compares other parts based on each character's Unicode value while ignore upper/lower case
differences.
|
public static java.util.Comparator<java.lang.String> getNaturalComparator()
For example in German locale this will be a comparator that handles umlauts correctly and ignores upper/lower case differences.
A string comparator that uses the current locale's order rules and handles embedded numbers correctly.
getNaturalComparator(java.text.Collator)
public static java.util.Comparator<java.lang.String> getNaturalComparator(java.text.Collator collator)
collator
- used for locale specific comparison of text (non-number) subwords - must not
be nullA string comparator that uses the given Collator to compare subwords and handles embedded numbers correctly.
getNaturalComparator()
public static java.util.Comparator<java.lang.String> getNaturalComparatorAscii()
a string comparator that does case sensitive comparisons on pure ascii strings and handles embedded numbers correctly.
Do not use if your app might ever run on any locale that uses more than 7-bit ascii characters.getNaturalComparator()
,
getNaturalComparator(java.text.Collator)
public static java.util.Comparator<java.lang.String> getNaturalComparatorIgnoreCaseAscii()
a string comparator that does case insensitive comparisons on pure ascii strings and handles embedded numbers correctly.
getNaturalComparator()
,
getNaturalComparator(java.text.Collator)
public static int compareNatural(java.lang.String s, java.lang.String t)
Compares two strings using the current locale's rules and comparing contained numbers based on their numeric values.
This is probably the best default comparison to use.
If you know that the texts to be compared are in a certain language that differs from the
default locale's langage, then get a collator for the desired locale (
Collator.getInstance(java.util.Locale)
) and pass it to
compareNatural(java.text.Collator, String, String)
s
- first stringt
- second strings
and t
are equal, a value less than zero iff
s
lexicographically precedes t
and a value larger than zero
iff s
lexicographically follows t
public static int compareNatural(java.text.Collator collator, java.lang.String s, java.lang.String t)
Compares two strings using the given collator and comparing contained numbers based on their numeric values.
s
- first stringt
- second strings
and t
are equal, a value less than zero iff
s
lexicographically precedes t
and a value larger than zero
iff s
lexicographically follows t
public static int compareNaturalAscii(java.lang.String s, java.lang.String t)
Compares two strings using each character's Unicode value for non-digit characters and the numeric values off any contained numbers.
(This will probably make sense only for strings containing 7-bit ascii characters only.)
s
and t
are equal, a value less than zero iff
s
lexicographically precedes t
and a value larger than zero
iff s
lexicographically follows t
public static int compareNaturalIgnoreCaseAscii(java.lang.String s, java.lang.String t)
Compares two strings using each character's Unicode value - ignoring upper/lower case - for non-digit characters and the numeric values of any contained numbers.
(This will probably make sense only for strings containing 7-bit ascii characters only.)
s
and t
are equal, a value less than zero iff
s
lexicographically precedes t
and a value larger than zero
iff s
lexicographically follows t
Copyright © 2018 OpenMRS Inc.. All Rights Reserved.