KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > portal > common > util > Version


1 /*****************************************
2  * *
3  * JBoss Portal: The OpenSource Portal *
4  * *
5  * Distributable under LGPL license. *
6  * See terms of license at gnu.org. *
7  * *
8  *****************************************/

9 package org.jboss.portal.common.util;
10
11 /**
12  * @author <a HREF="mailto:julien@jboss.org">Julien Viet</a>
13  * @version $Revision: 1.1 $
14  */

15 public class Version
16 {
17
18    private String JavaDoc toString;
19    private final String JavaDoc name;
20    private final int major;
21    private final int minor;
22    private final int patch;
23    private final IntermediateMajor intermediateMajor;
24    private final int intermediateMinor;
25
26    public Version(String JavaDoc name, int major, int minor, int patch, IntermediateMajor intermediateMajor, int intermediateMinor)
27    {
28       this.name = name;
29       this.major = major;
30       this.minor = minor;
31       this.patch = patch;
32       this.intermediateMajor = intermediateMajor;
33       this.intermediateMinor = intermediateMinor;
34       this.toString = buildToString();
35    }
36
37    /**
38     * Return the name;
39     */

40    public String JavaDoc getName()
41    {
42       return name;
43    }
44
45    /**
46     * Return the major.
47     */

48    public int getMajor()
49    {
50       return major;
51    }
52
53    /**
54     * Return the minor.
55     */

56    public int getMinor()
57    {
58       return minor;
59    }
60
61    /**
62     * Return the pacht.
63     */

64    public int getPatch()
65    {
66       return patch;
67    }
68
69    /**
70     * Return the intermediate major.
71     */

72    public IntermediateMajor getIntermediateMajor()
73    {
74       return intermediateMajor;
75    }
76
77    /**
78     * Return the intermediate minor. If the value is zero or less, that number has no specific meaning
79     * and should be ignored.
80     */

81    public int getIntermediateMinor()
82    {
83       return intermediateMinor;
84    }
85
86    public String JavaDoc toString()
87    {
88       return toString;
89    }
90
91    private String JavaDoc buildToString()
92    {
93       StringBuffer JavaDoc buffer = new StringBuffer JavaDoc("JBoss Portal ");
94       buffer.append(getMajor()).append('.');
95       buffer.append(getMinor()).append('.');
96       buffer.append(getPatch()).append('-');
97       buffer.append(getIntermediateMajor());
98       if (getIntermediateMinor() >= 1)
99       {
100          buffer.append(getIntermediateMinor());
101       }
102       return buffer.toString();
103    }
104
105    /**
106     * Type safe enum for intermediate major.
107     */

108    public static class IntermediateMajor implements Comparable JavaDoc
109    {
110
111       public static final IntermediateMajor DR = new IntermediateMajor("DR", "Developer release");
112       public static final IntermediateMajor ALPHA = new IntermediateMajor("ALPHA", "Alpha");
113       public static final IntermediateMajor BETA = new IntermediateMajor("BETA", "Beta");
114       public static final IntermediateMajor RC = new IntermediateMajor("RC", "Release candidate");
115       public static final IntermediateMajor FINAL = new IntermediateMajor("FINAL", "Final");
116       public static final IntermediateMajor SP = new IntermediateMajor("SP", "Service pack");
117
118       private static int nextOrdinal = 0;
119
120       private final int ordinal;
121
122       private final String JavaDoc name;
123
124       private final String JavaDoc description;
125
126       private IntermediateMajor(String JavaDoc name, String JavaDoc description)
127       {
128          this.ordinal = nextOrdinal++;
129          this.name = name;
130          this.description = description;
131       }
132
133       public String JavaDoc getName()
134       {
135          return name;
136       }
137
138       public String JavaDoc getDescription()
139       {
140          return description;
141       }
142
143       public int compareTo(Object JavaDoc o)
144       {
145          return ordinal - ((IntermediateMajor)o).ordinal;
146       }
147
148       public String JavaDoc toString()
149       {
150          return name;
151       }
152    }
153 }
154
Popular Tags