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 Details

    • from

      public static NaturalSort.NaturalKey from(String s)
      Creates a NaturalKey from 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 is null.
      Parameters:
      s - the input string to be parsed into a NaturalKey
      Returns:
      a NaturalKey constructed from the given string's prefix and suffix; if the trailing digit run is too long to parse as an int, the whole string is used as the prefix (never throws)
    • compareTo

      public int compareTo(NaturalSort.NaturalKey o)
      Specified by:
      compareTo in interface Comparable<NaturalSort.NaturalKey>