1 package org.apache.maven.plugins.javadoc;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.codehaus.plexus.util.StringUtils;
23
24
25
26
27
28
29
30
31
32
33
34 public class JavadocVersion implements Comparable<JavadocVersion>
35 {
36 private String rawVersion;
37
38 private JavadocVersion( String rawVersion )
39 {
40 if ( StringUtils.isEmpty( rawVersion ) )
41 {
42 throw new IllegalArgumentException( "The rawVersion could not be null." );
43 }
44 this.rawVersion = rawVersion;
45 }
46
47
48
49
50
51
52
53 static JavadocVersion parse( String s )
54 {
55 return new JavadocVersion( s );
56 }
57
58 @Override
59 public int compareTo( JavadocVersion other )
60 {
61 String[] thisSegments = this.rawVersion.split( "\\." );
62 String[] otherSegments = other.rawVersion.split( "\\." );
63
64 int minSegments = Math.min( thisSegments.length, otherSegments.length );
65
66 for ( int index = 0; index < minSegments; index++ )
67 {
68 int thisValue = Integer.parseInt( thisSegments[index] );
69 int otherValue = Integer.parseInt( otherSegments[index] );
70
71 int compareValue = Integer.compare( thisValue, otherValue );
72
73 if ( compareValue != 0 )
74 {
75 return compareValue;
76 }
77 }
78
79 return ( thisSegments.length - otherSegments.length );
80 }
81
82 @Override
83 public String toString()
84 {
85 return rawVersion;
86 }
87 }