java.lang.Object
net.i2p.util.VersionComparator
- All Implemented Interfaces:
Serializable, Comparator<String>
Compares versions. Characters other than [0-9.-_] are ignored. I2P only uses '.' but Sun Java uses '_' and plugins may use any of '.-_' Moved from TrustedUpdate.java.
- See Also:
Constructor Summary
ConstructorsConstructorDescriptionA stateless comparator -compare(String, String)just delegates to comp() - so a bare instance behaves exactly like any other.Method Summary
Modifier and TypeMethodDescriptionstatic intTo avoid churning comparators.intprivate static intgetDigit(char c) The value of a decimal digit.private static booleanisDigit(char c) True for a decimal digit.private static booleanisSeparator(char c) True for a character that separates version parts.private static intnextSeparator(String s, int start) Index of the next separator character, or the end of the string.private static longParses a long, ignoring any non-digit characters.Methods inherited from class Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Comparator
equals, max, min, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
Constructor Details
VersionComparator
public VersionComparator()A stateless comparator -compare(String, String)just delegates to comp() - so a bare instance behaves exactly like any other.
Method Details
compare
- Specified by:
comparein interfaceComparator<String>
comp
isSeparator
private static boolean isSeparator(char c) True for a character that separates version parts.- Parameters:
c- the character to test- Returns:
- true if it separates parts
isDigit
private static boolean isDigit(char c) True for a decimal digit.- Parameters:
c- the character to test- Returns:
- true if it is a digit
getDigit
private static int getDigit(char c) The value of a decimal digit.- Parameters:
c- the character to convert- Returns:
- its value
nextSeparator
Index of the next separator character, or the end of the string.- Parameters:
s- string to processstart- starting index in the string to process- Returns:
- the index of the next separator character, or end of string
parseLong
Parses a long, ignoring any non-digit characters.- Parameters:
s- string to parse fromstart- index in the string to startend- index in the string to stop at- Returns:
- the parsed value, or -1 if nothing was parsed or there was a problem.