Class DatedStringComparator

java.lang.Object
com.nt.udc.util.DatedStringComparator
All Implemented Interfaces:
Comparator

public class DatedStringComparator extends Object implements Comparator
Compares two dated Strings. The strings must adhere to the following format: _Mar_19__2001_17_18_38_501_ OR _Mar_19__2001_17_18_38_501. where, the prefix fields may be separated by a "_" character, and the extensions are user-defined. The most important part of the string is the date/time, which allows for time-based sorting. The date/time String can be generated with the: com.nt.udc.util.FilenameGenerator class.
  • Constructor Details

    • DatedStringComparator

      public DatedStringComparator(int prefixFieldsNum)
      Constructs a DatedStringComparator Object with the number of "_" seperated fields as the string prefix.
      Parameters:
      prefixFieldsNum - Number of prefix fields, separated by "_"
  • Method Details

    • compareStrings

      public int compareStrings(String str1, String str2) throws NumberFormatException
      Compares 2 Dated Strings.
      Parameters:
      str1 - First string
      str2 - Second string
      Returns:
      -1, if string1 invalid input: '<' string2 0 , if string1 == string2 1 , if string1 > string2
      Throws:
      NumberFormatException
    • compare

      public int compare(Object obj1, Object obj2)
      Compares 2 dated strings, as described in compareStrings(x,y). If the NumberFormatException is caught, this method will return 0 to ensure no sorting is done.
      Specified by:
      compare in interface Comparator