public class VersionComparator extends Object implements Comparator<String>
Technique.
* Split the version strings into parts by splitting on "-._"
first, then breaking apart words from numbers.
"1.0" = "1", "0"
"1.0-alpha-1" = "1", "0", "alpha", "1"
"2.0-rc2" = "2", "0", "rc", "2"
"1.3-m2" = "1", "3", "m", "3"
compare each part individually, and when they do not match, perform the following test.
Numbers are calculated per normal comparison rules. Words that are part of the "special word list" will be treated as their index within that heirarchy. Words that cannot be identified as special, are treated using normal case-insensitive comparison rules.
Modifier and Type | Field and Description |
---|---|
private static Comparator<String> |
INSTANCE |
private List<String> |
specialWords |
Constructor and Description |
---|
VersionComparator() |
Modifier and Type | Method and Description |
---|---|
int |
compare(String o1,
String o2) |
private int |
comparePart(String s1,
String s2) |
static Comparator<String> |
getInstance() |
private String |
safePart(String[] parts,
int idx) |
static String[] |
toParts(String version) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
comparing, comparing, comparingDouble, comparingInt, comparingLong, equals, naturalOrder, nullsFirst, nullsLast, reversed, reverseOrder, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
private static final Comparator<String> INSTANCE
private final List<String> specialWords
public VersionComparator()
public static Comparator<String> getInstance()
public int compare(String o1, String o2)
compare
in interface Comparator<String>
private int comparePart(String s1, String s2)
Copyright © 2006–2022 The Apache Software Foundation. All rights reserved.