public final void parseVersion( String version )
    {
        unparsed = version;

        int index = version.indexOf( "-" );

        String part1;
        String part2 = null;

        if ( index < 0 )
        {
            part1 = version;
        }
        else
        {
            part1 = version.substring( 0, index );
            part2 = version.substring( index + 1 );
        }

        if ( part2 != null )
        {
            try
            {
                if ( ( part2.length() == 1 ) || !part2.startsWith( "0" ) )
                {
                    buildNumber = Integer.valueOf( part2 );
                }
                else
                {
                    qualifier = part2;
                }
            }
            catch ( NumberFormatException e )
            {
                qualifier = part2;
            }
        }

        if ( !part1.contains(".") && !part1.startsWith( "0" ) )
        {
            try
            {
                majorVersion = Integer.valueOf( part1 );
            }
            catch ( NumberFormatException e )
            {
                // qualifier is the whole version, including "-"
                qualifier = version;
                buildNumber = null;
            }
        }
        else
        {
            boolean fallback = false;

            StringTokenizer tok = new StringTokenizer( part1, "." );
            try
            {
                majorVersion = getNextIntegerToken( tok );
                if ( tok.hasMoreTokens() )
                {
                    minorVersion = getNextIntegerToken( tok );
                }
                if ( tok.hasMoreTokens() )
                {
                    incrementalVersion = getNextIntegerToken( tok );
                }
                if ( tok.hasMoreTokens() )
                {
                    fallback = true;
                }

                // string tokenzier won't detect these and ignores them
                if (part1.contains("..") || part1.startsWith( "." ) || part1.endsWith( "." ) )
                {
                    fallback = true;
                }
            }
            catch ( NumberFormatException e )
            {
                fallback = true;
            }

            if ( fallback )
            {
                // qualifier is the whole version, including "-"
                qualifier = version;
                majorVersion = null;
                minorVersion = null;
                incrementalVersion = null;
                buildNumber = null;
            }
        }
    }
public final void parseVersion( String version )
    {
        unparsed = version;

        int index = version.indexOf( "-" );

        String part1;
        String part2 = null;

        if ( index < 0 )
        {
            part1 = version;
        }
        else
        {
            part1 = version.substring( 0, index );
            part2 = version.substring( index + 1 );
        }

        if ( part2 != null )
        {
            try
            {
                if ( ( part2.length() == 1 ) || !part2.startsWith( "0" ) )
                {
                    buildNumber = Integer.valueOf( part2 );
                }
                else
                {
                    qualifier = part2;
                }
            }
            catch ( NumberFormatException e )
            {
                qualifier = part2;
            }
        }

        if ( !part1.contains(".") && !part1.startsWith( "0" ) )
        {
            try
            {
                majorVersion = Integer.valueOf( part1 );
            }
            catch ( NumberFormatException e )
            {
                
                qualifier = version;
                buildNumber = null;
            }
        }
        else
        {
            boolean fallback = false;

            StringTokenizer tok = new StringTokenizer( part1, "." );
            try
            {
                majorVersion = getNextIntegerToken( tok );
                if ( tok.hasMoreTokens() )
                {
                    minorVersion = getNextIntegerToken( tok );
                }
                if ( tok.hasMoreTokens() )
                {
                    incrementalVersion = getNextIntegerToken( tok );
                }
                if ( tok.hasMoreTokens() )
                {
                    fallback = true;
                }

                
                if (part1.contains("..") || part1.startsWith( "." ) || part1.endsWith( "." ) )
                {
                    fallback = true;
                }
            }
            catch ( NumberFormatException e )
            {
                fallback = true;
            }

            if ( fallback )
            {
                
                qualifier = version;
                majorVersion = null;
                minorVersion = null;
                incrementalVersion = null;
                buildNumber = null;
            }
        }
    }
public final void parseVersion ( String version ) { unparsed = version ; int index = version . indexOf ( "-" ) ; String part1 ; String part2 = null ; if ( index < 0 ) { part1 = version ; } else { part1 = version . substring ( 0 , index ) ; part2 = version . substring ( index + 1 ) ; } if ( part2 != null ) { try { if ( ( part2 . length ( ) == 1 ) || ! part2 . startsWith ( "0" ) ) { buildNumber = Integer . valueOf ( part2 ) ; } else { qualifier = part2 ; } } catch ( NumberFormatException e ) { qualifier = part2 ; } } if ( ! part1 . contains ( "." ) && ! part1 . startsWith ( "0" ) ) { try { majorVersion = Integer . valueOf ( part1 ) ; } catch ( NumberFormatException e ) { // qualifier is the whole version, including "-" qualifier = version ; buildNumber = null ; } } else { boolean fallback = false ; StringTokenizer tok = new StringTokenizer ( part1 , "." ) ; try { majorVersion = getNextIntegerToken ( tok ) ; if ( tok . hasMoreTokens ( ) ) { minorVersion = getNextIntegerToken ( tok ) ; } if ( tok . hasMoreTokens ( ) ) { incrementalVersion = getNextIntegerToken ( tok ) ; } if ( tok . hasMoreTokens ( ) ) { fallback = true ; } // string tokenzier won't detect these and ignores them if ( part1 . contains ( ".." ) || part1 . startsWith ( "." ) || part1 . endsWith ( "." ) ) { fallback = true ; } } catch ( NumberFormatException e ) { fallback = true ; } if ( fallback ) { // qualifier is the whole version, including "-" qualifier = version ; majorVersion = null ; minorVersion = null ; incrementalVersion = null ; buildNumber = null ; } } }
解析版本字符串
1.0.1-1
1.0.1-snapshot

@param version 字符串
解析版本字符串 1 . 0 . 1 - 1 1 . 0 . 1 - snapshot