@Test public void testParseNew() { assertEquals(JavaVersion.parse("9-ea+19"), new JavaVersion(9, 0)); assertEquals(JavaVersion.parse("9+100"), new JavaVersion(9, 0)); assertEquals(JavaVersion.parse("9.0.1+20"), new JavaVersion(9, 0)); assertEquals(JavaVersion.parse("9.1.1+20"), new JavaVersion(9, 1)); }
public static JavaVersion parse(String version) { Matcher matcher = LEGACY_PATTERN.matcher(version); if (matcher.matches()) { int major = Integer.parseInt(matcher.group("MAJOR")); int minor = Optional.ofNullable(matcher.group("MINOR")) .map(Integer::parseInt) .orElse(0); String update = matcher.group("UPDATE"); if (update == null) { return new JavaVersion(major, minor); } return new JavaVersion(major, minor, OptionalInt.of(Integer.parseInt(update))); } matcher = PATTERN.matcher(version); if (matcher.matches()) { int major = Integer.parseInt(matcher.group("MAJOR")); int minor = Optional.ofNullable(matcher.group("MINOR")) .map(Integer::parseInt) .orElse(0); return new JavaVersion(major, minor); } throw new IllegalArgumentException(format("Cannot parse version %s", version)); }
JavaVersion { public static JavaVersion parse(String version) { Matcher matcher = LEGACY_PATTERN.matcher(version); if (matcher.matches()) { int major = Integer.parseInt(matcher.group("MAJOR")); int minor = Optional.ofNullable(matcher.group("MINOR")) .map(Integer::parseInt) .orElse(0); String update = matcher.group("UPDATE"); if (update == null) { return new JavaVersion(major, minor); } return new JavaVersion(major, minor, OptionalInt.of(Integer.parseInt(update))); } matcher = PATTERN.matcher(version); if (matcher.matches()) { int major = Integer.parseInt(matcher.group("MAJOR")); int minor = Optional.ofNullable(matcher.group("MINOR")) .map(Integer::parseInt) .orElse(0); return new JavaVersion(major, minor); } throw new IllegalArgumentException(format("Cannot parse version %s", version)); } }
JavaVersion { public static JavaVersion parse(String version) { Matcher matcher = LEGACY_PATTERN.matcher(version); if (matcher.matches()) { int major = Integer.parseInt(matcher.group("MAJOR")); int minor = Optional.ofNullable(matcher.group("MINOR")) .map(Integer::parseInt) .orElse(0); String update = matcher.group("UPDATE"); if (update == null) { return new JavaVersion(major, minor); } return new JavaVersion(major, minor, OptionalInt.of(Integer.parseInt(update))); } matcher = PATTERN.matcher(version); if (matcher.matches()) { int major = Integer.parseInt(matcher.group("MAJOR")); int minor = Optional.ofNullable(matcher.group("MINOR")) .map(Integer::parseInt) .orElse(0); return new JavaVersion(major, minor); } throw new IllegalArgumentException(format("Cannot parse version %s", version)); } JavaVersion(int major, int minor, OptionalInt update);  JavaVersion(int major, int minor); }
JavaVersion { public static JavaVersion parse(String version) { Matcher matcher = LEGACY_PATTERN.matcher(version); if (matcher.matches()) { int major = Integer.parseInt(matcher.group("MAJOR")); int minor = Optional.ofNullable(matcher.group("MINOR")) .map(Integer::parseInt) .orElse(0); String update = matcher.group("UPDATE"); if (update == null) { return new JavaVersion(major, minor); } return new JavaVersion(major, minor, OptionalInt.of(Integer.parseInt(update))); } matcher = PATTERN.matcher(version); if (matcher.matches()) { int major = Integer.parseInt(matcher.group("MAJOR")); int minor = Optional.ofNullable(matcher.group("MINOR")) .map(Integer::parseInt) .orElse(0); return new JavaVersion(major, minor); } throw new IllegalArgumentException(format("Cannot parse version %s", version)); } JavaVersion(int major, int minor, OptionalInt update);  JavaVersion(int major, int minor); static JavaVersion current(); static JavaVersion parse(String version); int getMajor(); int getMinor(); OptionalInt getUpdate(); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); }
JavaVersion { public static JavaVersion parse(String version) { Matcher matcher = LEGACY_PATTERN.matcher(version); if (matcher.matches()) { int major = Integer.parseInt(matcher.group("MAJOR")); int minor = Optional.ofNullable(matcher.group("MINOR")) .map(Integer::parseInt) .orElse(0); String update = matcher.group("UPDATE"); if (update == null) { return new JavaVersion(major, minor); } return new JavaVersion(major, minor, OptionalInt.of(Integer.parseInt(update))); } matcher = PATTERN.matcher(version); if (matcher.matches()) { int major = Integer.parseInt(matcher.group("MAJOR")); int minor = Optional.ofNullable(matcher.group("MINOR")) .map(Integer::parseInt) .orElse(0); return new JavaVersion(major, minor); } throw new IllegalArgumentException(format("Cannot parse version %s", version)); } JavaVersion(int major, int minor, OptionalInt update);  JavaVersion(int major, int minor); static JavaVersion current(); static JavaVersion parse(String version); int getMajor(); int getMinor(); OptionalInt getUpdate(); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString();  }