Class Overview
Compares dotted version strings of varying length. Makes a best effort with
other delimiters and non-numeric versions.
For dotted decimals, comparison is as you'd expect: 0.1 is before 0.2 is before
1.0 is before 2.0. This works for any number of dots.
More complicated version numbers are compared by splitting the version strings
into components using the
DELIMITER_PATTERN
and comparing each
component in order. The first difference found when comparing components
left-to-right is returned.
Two numeric components (containing only digits) are compared as integers. A
numeric component comes after any non-numeric one. Two non-numeric components
are ordered by
compareToIgnoreCase(String)
.
Summary
[Expand]
Inherited Methods |
From class
java.lang.Object
Object
|
clone()
|
boolean
|
equals(Object arg0)
|
void
|
finalize()
|
final
Class<?>
|
getClass()
|
int
|
hashCode()
|
final
void
|
notify()
|
final
void
|
notifyAll()
|
String
|
toString()
|
final
void
|
wait()
|
final
void
|
wait(long arg0, int arg1)
|
final
void
|
wait(long arg0)
|
|
From interface
java.util.Comparator
abstract
int
|
compare(T arg0, T arg1)
|
abstract
boolean
|
equals(Object arg0)
|
|
Constants
public
static
final
String
COMPONENT_PATTERN
Constant Value:
"[\d\w]+"
public
static
final
String
DELIMITER_PATTERN
public
static
final
String
VALID_VERSION_PATTERN
Constant Value:
"[\d\w]+([\.,-][\d\w]+)*"
Public Constructors
public
VersionStringComparator
()
Public Methods
public
int
compare
(String version1, String version2)
Compares two version strings using the algorithm described above.
Returns
- -1 if version1 is before version2, 1 if version2 is before
version1, or 0 if the versions are equal.
public
static
boolean
isValidVersionString
(String version)