@Test public void compareCloudbreakVersions() { VersionComparator comparator = new VersionComparator(); assertEquals("dev major desc", 1L, comparator.compare(() -> "2.0.0-rc.1", () -> "2.0.0-dev.1")); assertEquals("major desc", 1L, comparator.compare(() -> "2.0.0", () -> "1.0.0")); assertEquals("minor desc", 1L, comparator.compare(() -> "2.1.0", () -> "2.0.0")); assertEquals("patch desc", 1L, comparator.compare(() -> "2.1.1", () -> "2.1.0")); assertEquals("equals", 0L, comparator.compare(() -> "2.0.0", () -> "2.0.0")); assertEquals("major asc", -1L, comparator.compare(() -> "1.0.0", () -> "2.0.0")); assertEquals("minor asc", -1L, comparator.compare(() -> "2.0.0", () -> "2.1.0")); assertEquals("patch asc", -1L, comparator.compare(() -> "2.1.0", () -> "2.1.1")); assertEquals("dev major desc", 1L, comparator.compare(() -> "2.0.0-dev.1", () -> "1.0.0-dev.1")); assertEquals("dev minor desc", 1L, comparator.compare(() -> "2.1.0-dev.1", () -> "2.0.0-dev.1")); assertEquals("dev patch desc", 1L, comparator.compare(() -> "2.1.1-dev.1", () -> "2.1.0-dev.1")); assertEquals("dev desc", 1L, comparator.compare(() -> "2.1.1-dev.2", () -> "2.1.1-dev.1")); assertEquals("dev equals", 0L, comparator.compare(() -> "2.0.0-dev.1", () -> "2.0.0-dev.1")); assertEquals("dev major asc", -1L, comparator.compare(() -> "1.0.0-dev.1", () -> "2.0.0-dev.1")); assertEquals("dev minor asc", -1L, comparator.compare(() -> "2.0.0-dev.1", () -> "2.1.0-dev.1")); assertEquals("dev patch asc", -1L, comparator.compare(() -> "2.1.0-dev.1", () -> "2.1.1-dev.1")); assertEquals("dev asc", -1L, comparator.compare(() -> "2.1.1-dev.1", () -> "2.1.1-dev.2")); }
@Override public int compare(Versioned o1, Versioned o2) { String[] vals1 = o1.getVersion().split(VERSION_SPLITTER_REGEX); String[] vals2 = o2.getVersion().split(VERSION_SPLITTER_REGEX); int i = 0; while (i < vals1.length && i < vals2.length && vals1[i].equals(vals2[i])) { i++; } if (i < vals1.length && i < vals2.length) { int diff = StringUtils.isNumeric(vals1[i]) && StringUtils.isNumeric(vals2[i]) ? Integer.valueOf(vals1[i]).compareTo(Integer.valueOf(vals2[i])) : getDiffByPreReleaseIdPrecedence(vals1[i], vals2[i]); return Integer.signum(diff); } return Integer.signum(vals2.length - vals1.length); }
VersionComparator implements Comparator<Versioned>, Serializable { @Override public int compare(Versioned o1, Versioned o2) { String[] vals1 = o1.getVersion().split(VERSION_SPLITTER_REGEX); String[] vals2 = o2.getVersion().split(VERSION_SPLITTER_REGEX); int i = 0; while (i < vals1.length && i < vals2.length && vals1[i].equals(vals2[i])) { i++; } if (i < vals1.length && i < vals2.length) { int diff = StringUtils.isNumeric(vals1[i]) && StringUtils.isNumeric(vals2[i]) ? Integer.valueOf(vals1[i]).compareTo(Integer.valueOf(vals2[i])) : getDiffByPreReleaseIdPrecedence(vals1[i], vals2[i]); return Integer.signum(diff); } return Integer.signum(vals2.length - vals1.length); } }
VersionComparator implements Comparator<Versioned>, Serializable { @Override public int compare(Versioned o1, Versioned o2) { String[] vals1 = o1.getVersion().split(VERSION_SPLITTER_REGEX); String[] vals2 = o2.getVersion().split(VERSION_SPLITTER_REGEX); int i = 0; while (i < vals1.length && i < vals2.length && vals1[i].equals(vals2[i])) { i++; } if (i < vals1.length && i < vals2.length) { int diff = StringUtils.isNumeric(vals1[i]) && StringUtils.isNumeric(vals2[i]) ? Integer.valueOf(vals1[i]).compareTo(Integer.valueOf(vals2[i])) : getDiffByPreReleaseIdPrecedence(vals1[i], vals2[i]); return Integer.signum(diff); } return Integer.signum(vals2.length - vals1.length); }  }
VersionComparator implements Comparator<Versioned>, Serializable { @Override public int compare(Versioned o1, Versioned o2) { String[] vals1 = o1.getVersion().split(VERSION_SPLITTER_REGEX); String[] vals2 = o2.getVersion().split(VERSION_SPLITTER_REGEX); int i = 0; while (i < vals1.length && i < vals2.length && vals1[i].equals(vals2[i])) { i++; } if (i < vals1.length && i < vals2.length) { int diff = StringUtils.isNumeric(vals1[i]) && StringUtils.isNumeric(vals2[i]) ? Integer.valueOf(vals1[i]).compareTo(Integer.valueOf(vals2[i])) : getDiffByPreReleaseIdPrecedence(vals1[i], vals2[i]); return Integer.signum(diff); } return Integer.signum(vals2.length - vals1.length); }  @Override int compare(Versioned o1, Versioned o2); }
VersionComparator implements Comparator<Versioned>, Serializable { @Override public int compare(Versioned o1, Versioned o2) { String[] vals1 = o1.getVersion().split(VERSION_SPLITTER_REGEX); String[] vals2 = o2.getVersion().split(VERSION_SPLITTER_REGEX); int i = 0; while (i < vals1.length && i < vals2.length && vals1[i].equals(vals2[i])) { i++; } if (i < vals1.length && i < vals2.length) { int diff = StringUtils.isNumeric(vals1[i]) && StringUtils.isNumeric(vals2[i]) ? Integer.valueOf(vals1[i]).compareTo(Integer.valueOf(vals2[i])) : getDiffByPreReleaseIdPrecedence(vals1[i], vals2[i]); return Integer.signum(diff); } return Integer.signum(vals2.length - vals1.length); }  @Override int compare(Versioned o1, Versioned o2);  }