Package jmri.util
Class PreferNumericComparator
- java.lang.Object
-
- jmri.util.AlphanumComparator
-
- jmri.util.PreferNumericComparator
-
- All Implemented Interfaces:
java.util.Comparator<java.lang.String>
public class PreferNumericComparator extends AlphanumComparator
Perform an comparison usingAlphanumComparator
, followed up with a standard String comparison ifAlphanumComparator.compare(String, String)
returns 0.If the requirement is that
Comparator.compare(Object, Object)
return 0 for two numerically identical Strings (i.e.42 == 0042
), useAlphanumComparator
, but if the requirement is that Strings should be numerically ordered, but that non-identical representations should be different, (i.e.42 != 0042
, but order should be3, 4, 5, 42, 0042, 50
), use this Comparator, since the standard String comparator will not order numbers correctly.
-
-
Field Summary
-
Fields inherited from class jmri.util.AlphanumComparator
skip
-
-
Constructor Summary
Constructors Constructor Description PreferNumericComparator()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
compare(java.lang.String s1, java.lang.String s2)
-
-
-
Constructor Detail
-
PreferNumericComparator
public PreferNumericComparator()
-
-
Method Detail
-
compare
public int compare(java.lang.String s1, java.lang.String s2)
- Specified by:
compare
in interfacejava.util.Comparator<java.lang.String>
- Overrides:
compare
in classAlphanumComparator
-
-