VersionUtil { public static List<Version> getMaxVersionSequence(final List<Version> ocurrencesVersions, final List<Version> allVersions) { final List<Version> maxSequence = new ArrayList<>(); final List<Version> currentSequence = new ArrayList<>(); final VersionComparator versionComparator = new VersionComparator(); Collections.sort(ocurrencesVersions, versionComparator); Collections.sort(allVersions, versionComparator); int previousVersionIndex = -1; for (Version version : ocurrencesVersions) { final int currentVersionIndex = allVersions.indexOf(version); if (previousVersionIndex + 1 != currentVersionIndex) { currentSequence.clear(); } currentSequence.add(version); if (currentSequence.size() >= maxSequence.size()) { maxSequence.clear(); maxSequence.addAll(currentSequence); } previousVersionIndex = currentVersionIndex; } return maxSequence; }  static List<Version> getMaxVersionSequence(final List<Version> ocurrencesVersions, final List<Version> allVersions); static List<Version> getMaxVersionSequence(final Map<Version, AtomicInteger> ocurrencesVersions, final List<Version> allVersions, final int minOccurrencesInOneVersion); static List<Version> listStringToListVersion(final List<String> versions);  }
@Test public void testGetMaxVersionSequenceMaxIsEqual() { List<Version> occurrencesVersions = VersionTestHelper.getVersionsAsList("1.1", "1.2", "1.4", "1.5"); Assert.assertEquals(VersionTestHelper.getVersionsAsList("1.4", "1.5"), VersionUtil.getMaxVersionSequence(occurrencesVersions, allVersions)); }
@Test public void testGetMaxVersionSequenceMaxIsInEnd() { List<Version> occurrencesVersions = VersionTestHelper.getVersionsAsList("1.1", "1.2", "1.4", "1.5", "1.6"); Assert.assertEquals(VersionTestHelper.getVersionsAsList("1.4", "1.5", "1.6"), VersionUtil.getMaxVersionSequence(occurrencesVersions, allVersions)); }
@Test public void testGetMaxVersionSequenceMaxIsInBegin() { List<Version> occurrencesVersions = VersionTestHelper.getVersionsAsList("1.1", "1.2", "1.3", "1.5", "1.6"); Assert.assertEquals(VersionTestHelper.getVersionsAsList("1.1", "1.2", "1.3"), VersionUtil.getMaxVersionSequence(occurrencesVersions, allVersions)); }
@Test public void testGetMaxVersionSequenceMaxIsAll() { List<Version> occurrencesVersions = VersionTestHelper.getVersionsAsList("1.1", "1.2", "1.3", "1.4", "1.5", "1.6"); Assert.assertEquals(VersionTestHelper.getVersionsAsList("1.1", "1.2", "1.3", "1.4", "1.5", "1.6"), VersionUtil.getMaxVersionSequence(occurrencesVersions, allVersions)); }
@Test public void testGetMaxVersionSequenceMaxIsOne() { List<Version> occurrencesVersions = VersionTestHelper.getVersionsAsList("1.1", "1.3", "1.5"); Assert.assertEquals(VersionTestHelper.getVersionsAsList("1.5"), VersionUtil.getMaxVersionSequence(occurrencesVersions, allVersions)); }
@Test public void testGetMaxVersionSequenceMaxIsNone() { List<Version> occurrencesVersions = VersionTestHelper.getVersionsAsList(); Assert.assertEquals(VersionTestHelper.getVersionsAsList(), VersionUtil.getMaxVersionSequence(occurrencesVersions, allVersions)); }
@Test public void testGetMaxVersionSequenceMaxIsEqualWithMinOccurrencesInVersion() { Map<Version, AtomicInteger> occurrencesVersions = VersionTestHelper.getVersionsAsMap(2, "1.1", "1.2", "1.4", "1.5"); Assert.assertEquals(VersionTestHelper.getVersionsAsList("1.4", "1.5"), VersionUtil.getMaxVersionSequence(occurrencesVersions, allVersions, minOccurrences)); }
@Test public void testGetMaxVersionSequenceMaxIsInEndWithMinOccurrencesInVersion() { Map<Version, AtomicInteger> occurrencesVersions = VersionTestHelper.getVersionsAsMap(2, "1.1", "1.2", "1.4", "1.5", "1.6"); Assert.assertEquals(VersionTestHelper.getVersionsAsList("1.4", "1.5", "1.6"), VersionUtil.getMaxVersionSequence(occurrencesVersions, allVersions, minOccurrences)); }
@Test public void testGetMaxVersionSequenceMaxIsInBeginWithMinOccurrencesInVersion() { Map<Version, AtomicInteger> occurrencesVersions = VersionTestHelper.getVersionsAsMap(2, "1.1", "1.2", "1.3", "1.5", "1.6"); Assert.assertEquals(VersionTestHelper.getVersionsAsList("1.1", "1.2", "1.3"), VersionUtil.getMaxVersionSequence(occurrencesVersions, allVersions, minOccurrences)); }
@Test public void testGetMaxVersionSequenceMaxIsAllWithMinOccurrencesInVersion() { Map<Version, AtomicInteger> occurrencesVersions = VersionTestHelper.getVersionsAsMap(2, "1.1", "1.2", "1.3", "1.4", "1.5", "1.6"); Assert.assertEquals(VersionTestHelper.getVersionsAsList("1.1", "1.2", "1.3", "1.4", "1.5", "1.6"), VersionUtil.getMaxVersionSequence(occurrencesVersions, allVersions, minOccurrences)); }
@Test public void testGetMaxVersionSequenceMaxIsOneWithMinOccurrencesInVersion() { Map<Version, AtomicInteger> occurrencesVersions = VersionTestHelper.getVersionsAsMap(2, "1.1", "1.3", "1.5"); Assert.assertEquals(VersionTestHelper.getVersionsAsList("1.5"), VersionUtil.getMaxVersionSequence(occurrencesVersions, allVersions, minOccurrences)); }
@Test public void testGetMaxVersionSequenceMaxIsNoneWithMinOccurrencesInVersion() { Map<Version, AtomicInteger> occurrencesVersions = VersionTestHelper.getVersionsAsMap(); Assert.assertEquals(VersionTestHelper.getVersionsAsList(), VersionUtil.getMaxVersionSequence(occurrencesVersions, allVersions, minOccurrences)); }