public static Version parseVersion ( String versionString ) { final Matcher versionMatcher = VERSION_PATTERN . matcher ( versionString ) ; if ( ! versionMatcher . matches ( ) ) { return null ; } final int major = Integer . parseInt ( versionMatcher . group ( 1 ) ) ; final int minor = Integer . parseInt ( versionMatcher . group ( 2 ) ) ; final int patch = Integer . parseInt ( versionMatcher . group ( 3 ) ) ; final String local = versionMatcher . group ( 4 ) ; if ( local != null ) { return new SimpleVersion ( major , minor , patch , Integer . valueOf ( local ) ) ; } return new SimpleVersion ( major , minor , patch ) ; }
Parse a version string into a Version object if the string doesn t match the pattern null is returned .