Class NaturalSort.NaturalKey
java.lang.Object
edu.cmu.tetrad.util.NaturalSort.NaturalKey
- All Implemented Interfaces:
Comparable<NaturalSort.NaturalKey>
- Enclosing class:
NaturalSort
public static final class NaturalSort.NaturalKey
extends Object
implements Comparable<NaturalSort.NaturalKey>
Represents a natural key, which consists of a string prefix and an optional numeric suffix.
This class facilitates natural ordering of strings, combining lexicographical sorting
of the prefix with numerical comparison of the suffix when present.
Instances of this class are immutable.
-
Method Summary
Modifier and TypeMethodDescriptionintstatic NaturalSort.NaturalKeyCreates aNaturalKeyfrom the given string.
-
Method Details
-
from
Creates aNaturalKeyfrom the given string. The input string is divided into a prefix consisting of non-numeric characters and an optional numeric suffix. If the string ends with numeric characters, they are extracted as the suffix; otherwise, the suffix isnull.- Parameters:
s- the input string to be parsed into aNaturalKey- Returns:
- a
NaturalKeyconstructed from the given string's prefix and suffix; if the trailing digit run is too long to parse as anint, the whole string is used as the prefix (never throws)
-
compareTo
- Specified by:
compareToin interfaceComparable<NaturalSort.NaturalKey>
-