79723473c841391cb0c982a573339abb06a5b850
[vamsas.git] / src / uk / ac / vamsas / objects / utils / document / VersionEntries.java
1 /**
2  * 
3  */
4 package uk.ac.vamsas.objects.utils.document;
5
6 import java.util.Hashtable;
7
8 /**
9  *  enumerates versions for the VamsasDocument.Version string
10  *  provides version comparison methods
11  *  TODO: LATER: associate schema versions with these strings
12  */
13 public class VersionEntries {
14   public static final String ALPHA_VERSION="alpha";
15   public static final String BETA_VERSION="beta";
16   protected static Hashtable versions;
17   static {
18     versions = new Hashtable();
19     // integers represent version hierarchy - 0 precedes 1
20     versions.put(ALPHA_VERSION, new Integer(0)); 
21     versions.put(BETA_VERSION, new Integer(1));
22   }
23   // TODO: LATER: decide on best pattern for enumeration classes (ie - need an ordered list of versions, and validator, plus explicit enum-strings)
24   public static boolean isVersion(String vstring) {
25     return versions.containsKey(vstring);
26   }
27   /**
28    * returns 0 if levels are equivalent, 
29    * 1 if higher is valid and higher, 
30    * 2 if lower is valid and higher
31    * -1 if both levels are invalid
32    * @param higher
33    * @param lower
34    * @return
35    */
36   public static int compare(String higher, String lower) {
37     int v_1 = versions.containsKey(higher) ? ((Integer) versions.get(higher)).intValue() : -1;
38     int v_2 = versions.containsKey(lower) ? ((Integer) versions.get(lower)).intValue() : -1;
39     int comp = v_1<v_2 ? 2 : v_1 == v_2 ? 0 : 1;
40     return (comp==0) ? (v_1!=-1 ? 0 : -1) : comp;
41   }
42   /**
43    * @return the latest version that this vamsas library supports
44    */
45   public static String latestVersion() {
46     return BETA_VERSION;
47   }
48
49 }