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 Map<String, JavaEEVersion> VERSION_MAP = new HashMap<String, JavaEEVersion>();
47
48
49
50
51 public static final JavaEEVersion ONE_DOT_THREE = new JavaEEVersion( Integer.valueOf( 0 ), VERSION_1_3 );
52
53
54
55
56 public static final JavaEEVersion ONE_DOT_FOUR = new JavaEEVersion( Integer.valueOf( 1 ), VERSION_1_4 );
57
58
59
60
61 public static final JavaEEVersion FIVE = new JavaEEVersion( Integer.valueOf( 2 ), VERSION_5 );
62
63
64
65
66 public static final JavaEEVersion SIX = new JavaEEVersion( Integer.valueOf( 3 ), VERSION_6 );
67
68
69
70
71 public static final JavaEEVersion SEVEN = new JavaEEVersion( Integer.valueOf( 4 ), VERSION_7 );
72
73
74
75
76 public static final JavaEEVersion EIGHT = new JavaEEVersion( Integer.valueOf( 5 ), VERSION_8 );
77
78 private final Integer index;
79
80 private final String version;
81
82 private JavaEEVersion( Integer index, String version )
83 {
84 this.index = index;
85 this.version = version;
86 VERSION_MAP.put( version, this );
87 }
88
89
90
91
92
93
94 public static JavaEEVersion getJavaEEVersion( String paramVersion )
95 throws InvalidJavaEEVersion
96 {
97 if ( !isValid( paramVersion ) )
98 {
99 throw new InvalidJavaEEVersion( "Invalid version [" + paramVersion + "]", paramVersion );
100 }
101 return VERSION_MAP.get( paramVersion );
102 }
103
104
105
106
107
108
109 public String getVersion()
110 {
111 return version;
112 }
113
114
115
116
117
118
119
120 public boolean ge( JavaEEVersion parmVersion )
121 {
122 return this.compareTo( parmVersion ) >= 0;
123 }
124
125
126
127
128
129
130
131 public boolean gt( JavaEEVersion paramVersion )
132 {
133 return this.compareTo( paramVersion ) > 0;
134 }
135
136
137
138
139
140
141
142 public boolean eq( JavaEEVersion paramVersion )
143 {
144 return this.compareTo( paramVersion ) == 0;
145 }
146
147
148
149
150
151
152
153 public boolean le( JavaEEVersion paramVersion )
154 {
155 return this.compareTo( paramVersion ) <= 0;
156 }
157
158
159
160
161
162
163
164 public boolean lt( JavaEEVersion paramVersion )
165 {
166 return this.compareTo( paramVersion ) < 0;
167 }
168
169
170
171
172
173
174
175 private static boolean isValid( String paramVersion )
176 {
177 if ( paramVersion == null )
178 {
179 throw new IllegalArgumentException( "version could not be null." );
180 }
181
182 return VERSION_1_3.equals( paramVersion )
183 || VERSION_1_4.equals( paramVersion )
184 || VERSION_5.equals( paramVersion )
185 || VERSION_6.equals( paramVersion )
186 || VERSION_7.equals( paramVersion )
187 || VERSION_8.equals( paramVersion );
188
189 }
190
191
192 public int compareTo( JavaEEVersion otherVersion )
193 {
194 if ( otherVersion == null )
195 {
196 throw new IllegalArgumentException( "other object to compare to could not be null." );
197 }
198 return index.compareTo( otherVersion.index );
199 }
200 }