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));
    }
@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));
        assertEquals(JavaVersion.parse("11.0.7.0.4"), new JavaVersion(11, 0));
    }