@Test public void testVersionNewer() { VersionComparator vc = new VersionComparator(); assertTrue(1 == vc.compare("0.1.0", "0.0.1"), "0.1.0 > 0.0.1"); assertTrue(1 == vc.compare("0.10.0", "0.1.1"), "0.10.0 > 0.1.1"); assertTrue(1 == vc.compare("0.1.1", "0.1.0"), "0.1.1 > 0.1.0"); assertTrue(1 == vc.compare("1.0.0", "0.5.9"), "1.0.0 > 0.5.9"); assertTrue(1 == vc.compare("1.0.0", "0.5.9"), "1.0.0 > 0.5.9"); assertTrue(1 == vc.compare("1.0.0", ""), "1.0.0 > -"); }
@Override public int compare(String o1, String o2) { int[] v1components = parseVersion(o1); int[] v2components = parseVersion(o2); int num = Math.max(v1components.length, v2components.length); for (int i = 0; i < num; ++i) { int v1 = i < v1components.length ? v1components[i] : 0; int v2 = i < v2components.length ? v2components[i] : 0; if (v1 > v2) { return 1; } if (v1 < v2) { return -1; } } return 0; }
VersionComparator implements Comparator<String> { @Override public int compare(String o1, String o2) { int[] v1components = parseVersion(o1); int[] v2components = parseVersion(o2); int num = Math.max(v1components.length, v2components.length); for (int i = 0; i < num; ++i) { int v1 = i < v1components.length ? v1components[i] : 0; int v2 = i < v2components.length ? v2components[i] : 0; if (v1 > v2) { return 1; } if (v1 < v2) { return -1; } } return 0; } }
VersionComparator implements Comparator<String> { @Override public int compare(String o1, String o2) { int[] v1components = parseVersion(o1); int[] v2components = parseVersion(o2); int num = Math.max(v1components.length, v2components.length); for (int i = 0; i < num; ++i) { int v1 = i < v1components.length ? v1components[i] : 0; int v2 = i < v2components.length ? v2components[i] : 0; if (v1 > v2) { return 1; } if (v1 < v2) { return -1; } } return 0; }  }
VersionComparator implements Comparator<String> { @Override public int compare(String o1, String o2) { int[] v1components = parseVersion(o1); int[] v2components = parseVersion(o2); int num = Math.max(v1components.length, v2components.length); for (int i = 0; i < num; ++i) { int v1 = i < v1components.length ? v1components[i] : 0; int v2 = i < v2components.length ? v2components[i] : 0; if (v1 > v2) { return 1; } if (v1 < v2) { return -1; } } return 0; }  @Override int compare(String o1, String o2); }
VersionComparator implements Comparator<String> { @Override public int compare(String o1, String o2) { int[] v1components = parseVersion(o1); int[] v2components = parseVersion(o2); int num = Math.max(v1components.length, v2components.length); for (int i = 0; i < num; ++i) { int v1 = i < v1components.length ? v1components[i] : 0; int v2 = i < v2components.length ? v2components[i] : 0; if (v1 > v2) { return 1; } if (v1 < v2) { return -1; } } return 0; }  @Override int compare(String o1, String o2);  }