1 package org.apache.maven.plugins.ear.util;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.HashMap;
23 import java.util.Map;
24
25
26
27
28
29
30 public class JavaEEVersion
31 implements Comparable<JavaEEVersion>
32 {
33
34 private static final String VERSION_1_3 = "1.3";
35
36 private static final String VERSION_1_4 = "1.4";
37
38 private static final String VERSION_5 = "5";
39
40 private static final String VERSION_6 = "6";
41
42 private static final String VERSION_7 = "7";
43
44 private static final String VERSION_8 = "8";
45
46 private static final String VERSION_9 = "9";
47
48 private static final String VERSION_10 = "10";
49
50 private static final Map<String, JavaEEVersion> VERSION_MAP = new HashMap<String, JavaEEVersion>();
51
52
53
54
55 public static final JavaEEVersion ONE_DOT_THREE = new JavaEEVersion( Integer.valueOf( 0 ), VERSION_1_3 );
56
57
58
59
60 public static final JavaEEVersion ONE_DOT_FOUR = new JavaEEVersion( Integer.valueOf( 1 ), VERSION_1_4 );
61
62
63
64
65 public static final JavaEEVersion FIVE = new JavaEEVersion( Integer.valueOf( 2 ), VERSION_5 );
66
67
68
69
70 public static final JavaEEVersion SIX = new JavaEEVersion( Integer.valueOf( 3 ), VERSION_6 );
71
72
73
74
75 public static final JavaEEVersion SEVEN = new JavaEEVersion( Integer.valueOf( 4 ), VERSION_7 );
76
77
78
79
80 public static final JavaEEVersion EIGHT = new JavaEEVersion( Integer.valueOf( 5 ), VERSION_8 );
81
82
83
84
85 public static final JavaEEVersion NINE = new JavaEEVersion( Integer.valueOf( 6 ), VERSION_9 );
86
87
88
89
90 public static final JavaEEVersion TEN = new JavaEEVersion( Integer.valueOf( 7 ), VERSION_10 );
91
92 private final Integer index;
93
94 private final String version;
95
96 private JavaEEVersion( Integer index, String version )
97 {
98 this.index = index;
99 this.version = version;
100 VERSION_MAP.put( version, this );
101 }
102
103
104
105
106
107
108 public static JavaEEVersion getJavaEEVersion( String paramVersion )
109 throws InvalidJavaEEVersion
110 {
111 if ( !isValid( paramVersion ) )
112 {
113 throw new InvalidJavaEEVersion( "Invalid version [" + paramVersion + "]", paramVersion );
114 }
115 return VERSION_MAP.get( paramVersion );
116 }
117
118
119
120
121
122
123 public String getVersion()
124 {
125 return version;
126 }
127
128
129
130
131
132
133
134 public boolean ge( JavaEEVersion paramVersion )
135 {
136 return this.compareTo( paramVersion ) >= 0;
137 }
138
139
140
141
142
143
144
145 public boolean gt( JavaEEVersion paramVersion )
146 {
147 return this.compareTo( paramVersion ) > 0;
148 }
149
150
151
152
153
154
155
156 public boolean eq( JavaEEVersion paramVersion )
157 {
158 return this.compareTo( paramVersion ) == 0;
159 }
160
161
162
163
164
165
166
167 public boolean le( JavaEEVersion paramVersion )
168 {
169 return this.compareTo( paramVersion ) <= 0;
170 }
171
172
173
174
175
176
177
178 public boolean lt( JavaEEVersion paramVersion )
179 {
180 return this.compareTo( paramVersion ) < 0;
181 }
182
183
184
185
186
187
188
189 private static boolean isValid( String paramVersion )
190 {
191 if ( paramVersion == null )
192 {
193 throw new NullPointerException( "version cannot be null." );
194 }
195
196 return VERSION_1_3.equals( paramVersion )
197 || VERSION_1_4.equals( paramVersion )
198 || VERSION_5.equals( paramVersion )
199 || VERSION_6.equals( paramVersion )
200 || VERSION_7.equals( paramVersion )
201 || VERSION_8.equals( paramVersion )
202 || VERSION_9.equals( paramVersion )
203 || VERSION_10.equals( paramVersion );
204
205 }
206
207
208 public int compareTo( JavaEEVersion otherVersion )
209 {
210 if ( otherVersion == null )
211 {
212 throw new NullPointerException( "other object to compare to could not be null." );
213 }
214 return index.compareTo( otherVersion.index );
215 }
216 }