View Javadoc

1   /*
2    *  Copyright 2004-2006 Stefan Reuter
3    *
4    *  Licensed under the Apache License, Version 2.0 (the "License");
5    *  you may not use this file except in compliance with the License.
6    *  You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *  Unless required by applicable law or agreed to in writing, software
11   *  distributed under the License is distributed on an "AS IS" BASIS,
12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *  See the License for the specific language governing permissions and
14   *  limitations under the License.
15   *
16   */
17  package org.asteriskjava;
18  
19  import java.io.Serializable;
20  
21  /***
22   * Represents the version of an Asterisk server.
23   * 
24   * @since 0.2
25   * @author srt
26   * @version $Id: AsteriskVersion.java 729 2007-05-26 05:16:57Z sprior $
27   */
28  public class AsteriskVersion implements Comparable<AsteriskVersion>, Serializable
29  {
30      private final int version;
31      private final String versionString;
32  
33      /***
34       * Represents the Asterisk 1.0 series.
35       */
36      public static final AsteriskVersion ASTERISK_1_0 = new AsteriskVersion(100,
37              "Asterisk 1.0");
38  
39      /***
40       * Represents the Asterisk 1.2 series.
41       */
42      public static final AsteriskVersion ASTERISK_1_2 = new AsteriskVersion(120,
43              "Asterisk 1.2");
44  
45      /***
46       * Represents the Asterisk 1.4 series.
47       *
48       * @since 0.3
49       */
50      public static final AsteriskVersion ASTERISK_1_4 = new AsteriskVersion(140,
51              "Asterisk 1.4");
52  
53      /***
54       * Serial version identifier.
55       */
56      private static final long serialVersionUID = -5696160640576385797L;
57  
58      private AsteriskVersion(int version, String versionString)
59      {
60          this.version = version;
61          this.versionString = versionString;
62      }
63  
64      /***
65       * Returns <code>true</code> if this version is equal to or higher than
66       * the given version.
67       * 
68       * @param o the version to compare to
69       * @return <code>true</code> if this version is equal to or higher than
70       *         the given version.
71       */
72      public boolean isAtLeast(AsteriskVersion o)
73      {
74          if (version >= o.version)
75          {
76              return true;
77          }
78          else
79          {
80              return false;
81          }
82      }
83  
84      public int compareTo(AsteriskVersion o)
85      {
86          int otherVersion;
87  
88          otherVersion = o.version;
89          if (version < otherVersion)
90          {
91              return -1;
92          }
93          else if (version > otherVersion)
94          {
95              return 1;
96          }
97          else
98          {
99              return 0;
100         }
101     }
102 
103 
104     @Override
105    public boolean equals(Object o)
106     {
107         if (this == o)
108         {
109             return true;
110         }
111         if (o == null || getClass() != o.getClass())
112         {
113             return false;
114         }
115 
116         AsteriskVersion that = (AsteriskVersion) o;
117 
118         if (version != that.version)
119         {
120             return false;
121         }
122 
123         return true;
124     }
125 
126     @Override
127    public int hashCode()
128     {
129         return version;
130     }
131 
132     @Override
133    public String toString()
134     {
135         return versionString;
136     }
137 }