@Test public void testStringVersionComparator_isTransitive() { assertThat(VersionComparator.INSTANCE.compare("1.0", "1.1"), lessThan(0)); assertThat(VersionComparator.INSTANCE.compare("1.1", "1.2"), lessThan(0)); assertThat(VersionComparator.INSTANCE.compare("1.0", "1.2"), lessThan(0)); assertThat(VersionComparator.INSTANCE.compare("1.1", "1.0"), greaterThan(0)); assertThat(VersionComparator.INSTANCE.compare("1.2", "1.1"), greaterThan(0)); assertThat(VersionComparator.INSTANCE.compare("1.2", "1.0"), greaterThan(0)); }
@Override public int compare(final String o1, final String o2) { boolean firstObjectLooksLikeVersion = isVersionLike(o1); boolean secondObjectLooksLikeVersion = isVersionLike(o2); if (firstObjectLooksLikeVersion ^ secondObjectLooksLikeVersion) { if (firstObjectLooksLikeVersion) { return 1; } else { return -1; } } else if (firstObjectLooksLikeVersion) { Version v1 = version(o1); Version v2 = version(o2); return v1.compareTo(v2); } else { return o1.compareTo(o2); } }
VersionComparator implements Comparator<String> { @Override public int compare(final String o1, final String o2) { boolean firstObjectLooksLikeVersion = isVersionLike(o1); boolean secondObjectLooksLikeVersion = isVersionLike(o2); if (firstObjectLooksLikeVersion ^ secondObjectLooksLikeVersion) { if (firstObjectLooksLikeVersion) { return 1; } else { return -1; } } else if (firstObjectLooksLikeVersion) { Version v1 = version(o1); Version v2 = version(o2); return v1.compareTo(v2); } else { return o1.compareTo(o2); } } }
VersionComparator implements Comparator<String> { @Override public int compare(final String o1, final String o2) { boolean firstObjectLooksLikeVersion = isVersionLike(o1); boolean secondObjectLooksLikeVersion = isVersionLike(o2); if (firstObjectLooksLikeVersion ^ secondObjectLooksLikeVersion) { if (firstObjectLooksLikeVersion) { return 1; } else { return -1; } } else if (firstObjectLooksLikeVersion) { Version v1 = version(o1); Version v2 = version(o2); return v1.compareTo(v2); } else { return o1.compareTo(o2); } }  }
VersionComparator implements Comparator<String> { @Override public int compare(final String o1, final String o2) { boolean firstObjectLooksLikeVersion = isVersionLike(o1); boolean secondObjectLooksLikeVersion = isVersionLike(o2); if (firstObjectLooksLikeVersion ^ secondObjectLooksLikeVersion) { if (firstObjectLooksLikeVersion) { return 1; } else { return -1; } } else if (firstObjectLooksLikeVersion) { Version v1 = version(o1); Version v2 = version(o2); return v1.compareTo(v2); } else { return o1.compareTo(o2); } }  static Version version(final String version); @Override int compare(final String o1, final String o2); }
VersionComparator implements Comparator<String> { @Override public int compare(final String o1, final String o2) { boolean firstObjectLooksLikeVersion = isVersionLike(o1); boolean secondObjectLooksLikeVersion = isVersionLike(o2); if (firstObjectLooksLikeVersion ^ secondObjectLooksLikeVersion) { if (firstObjectLooksLikeVersion) { return 1; } else { return -1; } } else if (firstObjectLooksLikeVersion) { Version v1 = version(o1); Version v2 = version(o2); return v1.compareTo(v2); } else { return o1.compareTo(o2); } }  static Version version(final String version); @Override int compare(final String o1, final String o2); static final Comparator<String> INSTANCE; }