Package com.nt.udc.util
Class DatedStringComparator
java.lang.Object
com.nt.udc.util.DatedStringComparator
- All Implemented Interfaces:
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 Summary
ConstructorsConstructorDescriptionDatedStringComparator
(int prefixFieldsNum) Constructs a DatedStringComparator Object with the number of "_" seperated fields as the string prefix. -
Method Summary
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.Comparator
equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
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
Compares 2 Dated Strings.- Parameters:
str1
- First stringstr2
- Second string- Returns:
- -1, if string1 invalid input: '<' string2 0 , if string1 == string2 1 , if string1 > string2
- Throws:
NumberFormatException
-
compare
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 interfaceComparator
-