public final class NaturalStrings extends Object
Modifier and Type | Method and Description |
---|---|
static int |
compareNatural(Collator collator,
String s,
String t)
Compares two strings using the given collator and comparing contained numbers based on their
numeric values.
|
static int |
compareNatural(String s,
String t)
Compares two strings using the current locale's rules and comparing contained numbers based
on their numeric values.
|
static int |
compareNaturalAscii(String s,
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(String s,
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 Comparator<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 Comparator<String> |
getNaturalComparator(Collator collator)
Returns a comparator that compares contained numbers based on their numeric values and
compares other parts using the given collator.
|
static Comparator<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 Comparator<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 Comparator<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 Comparator<String> getNaturalComparator(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 Comparator<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 Comparator<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(String s, 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 language, 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(Collator collator, String s, 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(String s, 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(String s, 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 © 2024 OpenMRS Inc.. All rights reserved.