VersionHelper { public static int[] extractVersion(String input) { if (DataHelper.isNullOrEmpty(input)) { return null; } Pattern pattern = Pattern.compile("[-\\.]*(\\d+)\\.(\\d+)\\.(\\d+)[-\\.]*"); int[] version = null; Matcher matcher = pattern.matcher(input); while (matcher.find()) { if (version == null) { version = new int[3]; } version[0] = Integer.parseInt(matcher.group(1)); version[1] = Integer.parseInt(matcher.group(2)); version[2] = Integer.parseInt(matcher.group(3)); } return version; } private  VersionHelper(); static int[] extractVersion(String input); static boolean isVersion(int[] version); static boolean isBefore(int[] version, int[] referenceVersion); static boolean isAfter(int[] version, int[] referenceVersion); static boolean isEqual(int[] version, int[] referenceVersion);  }
@Test public void testExtractVersion() { assertArrayEquals(new int[] { 0, 23, 0 }, VersionHelper.extractVersion("0.23.0")); assertArrayEquals(new int[] { 0, 23, 1 }, VersionHelper.extractVersion("0.23.1")); assertArrayEquals(new int[] { 0, 23, 1 }, VersionHelper.extractVersion("0.23.1-SNAPSHOT")); assertArrayEquals(new int[] { 1, 0, 0 }, VersionHelper.extractVersion("1.0.0")); assertArrayEquals(new int[] { 1, 0, 0 }, VersionHelper.extractVersion("1.0.0-SNAPSHOT")); assertArrayEquals(new int[] { 1, 0, 12 }, VersionHelper.extractVersion("1.0.12")); assertNull(VersionHelper.extractVersion("1.0.")); assertNull(VersionHelper.extractVersion("1.0")); assertNull(VersionHelper.extractVersion("1.0-SNAPSHOT")); assertNull(VersionHelper.extractVersion("1.0-SNAPSHOT.12")); assertNull(VersionHelper.extractVersion("https: assertArrayEquals(new int[] { 1, 0, 0 }, VersionHelper.extractVersion("https: assertArrayEquals(new int[] { 1, 0, 0 }, VersionHelper.extractVersion("https: assertArrayEquals(new int[] { 1, 0, 0 }, VersionHelper.extractVersion("https: assertArrayEquals(new int[] { 11, 13, 15 }, VersionHelper.extractVersion("https: }