@Test public void getTheLastVersionOfRegularVersions() throws IncomparableException { final List<String> versions = new ArrayList<String>(); versions.add("0.1.0-1"); versions.add("0.1.0-SNAPSHOT"); assertEquals("0.1.0-SNAPSHOT", versionsHandler.getLastVersion(versions)); versions.clear(); versions.add("2.1.0-1"); versions.add("0.1.0-SNAPSHOT"); versions.add("1.1.0-SNAPSHOT"); versions.add("2.0.0-SNAPSHOT"); assertEquals("2.1.0-1", versionsHandler.getLastVersion(versions)); }
public String getLastVersion(final Collection<String> versions) { final List<Version> sorted = versions.stream() .filter(Version::isValid) .map(Version::make) .filter(Optional::isPresent) .map(Optional::get) .sorted((v1, v2) -> { try { return v1.compare(v2); } catch (IncomparableException e) { return 0; } }) .collect(Collectors.toList()); if(sorted.isEmpty()) { if(LOG.isWarnEnabled()) { LOG.warn(String.format("Cannot obtain last version from collection %s", versions.toString())); } return null; } return sorted.get(sorted.size() - 1).toString(); }
VersionsHandler { public String getLastVersion(final Collection<String> versions) { final List<Version> sorted = versions.stream() .filter(Version::isValid) .map(Version::make) .filter(Optional::isPresent) .map(Optional::get) .sorted((v1, v2) -> { try { return v1.compare(v2); } catch (IncomparableException e) { return 0; } }) .collect(Collectors.toList()); if(sorted.isEmpty()) { if(LOG.isWarnEnabled()) { LOG.warn(String.format("Cannot obtain last version from collection %s", versions.toString())); } return null; } return sorted.get(sorted.size() - 1).toString(); } }
VersionsHandler { public String getLastVersion(final Collection<String> versions) { final List<Version> sorted = versions.stream() .filter(Version::isValid) .map(Version::make) .filter(Optional::isPresent) .map(Optional::get) .sorted((v1, v2) -> { try { return v1.compare(v2); } catch (IncomparableException e) { return 0; } }) .collect(Collectors.toList()); if(sorted.isEmpty()) { if(LOG.isWarnEnabled()) { LOG.warn(String.format("Cannot obtain last version from collection %s", versions.toString())); } return null; } return sorted.get(sorted.size() - 1).toString(); } VersionsHandler(final RepositoryHandler repoHandler); }
VersionsHandler { public String getLastVersion(final Collection<String> versions) { final List<Version> sorted = versions.stream() .filter(Version::isValid) .map(Version::make) .filter(Optional::isPresent) .map(Optional::get) .sorted((v1, v2) -> { try { return v1.compare(v2); } catch (IncomparableException e) { return 0; } }) .collect(Collectors.toList()); if(sorted.isEmpty()) { if(LOG.isWarnEnabled()) { LOG.warn(String.format("Cannot obtain last version from collection %s", versions.toString())); } return null; } return sorted.get(sorted.size() - 1).toString(); } VersionsHandler(final RepositoryHandler repoHandler); boolean isUpToDate(final DbArtifact artifact); String getLastRelease(final Collection<String> versions); String getLastVersion(final Collection<String> versions); }
VersionsHandler { public String getLastVersion(final Collection<String> versions) { final List<Version> sorted = versions.stream() .filter(Version::isValid) .map(Version::make) .filter(Optional::isPresent) .map(Optional::get) .sorted((v1, v2) -> { try { return v1.compare(v2); } catch (IncomparableException e) { return 0; } }) .collect(Collectors.toList()); if(sorted.isEmpty()) { if(LOG.isWarnEnabled()) { LOG.warn(String.format("Cannot obtain last version from collection %s", versions.toString())); } return null; } return sorted.get(sorted.size() - 1).toString(); } VersionsHandler(final RepositoryHandler repoHandler); boolean isUpToDate(final DbArtifact artifact); String getLastRelease(final Collection<String> versions); String getLastVersion(final Collection<String> versions);  }