View Javadoc
1   package org.apache.maven.plugins.javadoc;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.codehaus.plexus.util.StringUtils;
23  
24  /**
25   * Once the plugin requires Java9, this class can be replaced with java.lang.Runtime.Version
26   * <p>
27   * <strong>Note: </strong> Ensure the methods match, although parse+compareTo+toString should be enough.
28   * </p>
29   * 
30   * 
31   * @author Robert Scholte
32   * @since 3.0.0
33   * @deprecated Use {@link org.codehaus.plexus.languages.java.version.JavaVersion} instead
34   */
35  @Deprecated
36  public class JavadocVersion implements Comparable<JavadocVersion>
37  {
38      private String rawVersion;
39  
40      private JavadocVersion( String rawVersion )
41      {
42          if ( StringUtils.isEmpty( rawVersion ) )
43          {
44              throw new IllegalArgumentException( "The rawVersion could not be null." );
45          }
46          this.rawVersion = rawVersion;
47      }
48  
49      /**
50       * Parser only the version-scheme.
51       * 
52       * @param s the version string
53       * @return the version wrapped in a JavadocVersion
54       */
55      static JavadocVersion parse( String s ) 
56      {
57          return new JavadocVersion( s );
58      }
59  
60      @Override
61      public int compareTo( JavadocVersion other )
62      {
63          String[] thisSegments = this.rawVersion.split( "\\." );
64          String[] otherSegments = other.rawVersion.split( "\\." );
65          
66          int minSegments = Math.min( thisSegments.length, otherSegments.length );
67          
68          for ( int index = 0; index < minSegments; index++ )
69          {
70              int thisValue = Integer.parseInt( thisSegments[index] );
71              int otherValue = Integer.parseInt( otherSegments[index] );
72              
73              int compareValue = Integer.compare( thisValue, otherValue );
74              
75              if ( compareValue != 0 )
76              {
77                  return compareValue;
78              }
79          }
80          
81          return ( thisSegments.length - otherSegments.length );
82      }
83  
84      @Override
85      public String toString()
86      {
87          return rawVersion;
88      }
89  }