Version implements Comparable<Version> { public static Version from(final String version) { final String[] fields = version.split("[.-]", 4); checkArgument(fields.length >= 3, "version number is invalid"); return new Version( parseInt(fields[0]), parseInt(fields[1]), parseInt(fields[2]), fields.length == 4 ? fields[3] : null); } private  Version(final int major, final int minor, final int patch, final String build); static Version from(final String version); static Version from(
      final int major, final int minor, final int patch, final String build); int major(); int minor(); int patch(); String build(); @Override int compareTo(final Version that); @Override int hashCode(); @Override boolean equals(final Object object); @Override String toString();  }
@Test public void testInvalidVersions() { assertIllegalArgument(() -> Version.from("1")); assertIllegalArgument(() -> Version.from("1.0")); assertIllegalArgument(() -> Version.from("1.0-beta1")); assertIllegalArgument(() -> Version.from("1.0.0.0")); assertIllegalArgument(() -> Version.from("1.0.0.0-beta1")); assertIllegalArgument(() -> Version.from("1.0.0-not1")); assertIllegalArgument(() -> Version.from("1.0.0-alpha")); assertIllegalArgument(() -> Version.from("1.0.0-beta")); assertIllegalArgument(() -> Version.from("1.0.0-rc")); }