applied LGPLv3 and source code formatting.
[vamsas.git] / src / uk / ac / vamsas / objects / utils / document / VersionEntries.java
1 /*\r
2  * This file is part of the Vamsas Client version 0.1. \r
3  * Copyright 2009 by Jim Procter, Iain Milne, Pierre Marguerite, \r
4  *  Andrew Waterhouse and Dominik Lindner.\r
5  * \r
6  * Earlier versions have also been incorporated into Jalview version 2.4 \r
7  * since 2008, and TOPALi version 2 since 2007.\r
8  * \r
9  * The Vamsas Client is free software: you can redistribute it and/or modify\r
10  * it under the terms of the GNU Lesser General Public License as published by\r
11  * the Free Software Foundation, either version 3 of the License, or\r
12  * (at your option) any later version.\r
13  *  \r
14  * The Vamsas Client is distributed in the hope that it will be useful,\r
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
17  * GNU Lesser General Public License for more details.\r
18  * \r
19  * You should have received a copy of the GNU Lesser General Public License\r
20  * along with the Vamsas Client.  If not, see <http://www.gnu.org/licenses/>.\r
21  */\r
22 package uk.ac.vamsas.objects.utils.document;\r
23 \r
24 import java.util.Hashtable;\r
25 \r
26 /**\r
27  * enumerates versions for the VamsasDocument.Version string provides version\r
28  * comparison methods TODO: LATER: associate schema versions with these strings\r
29  */\r
30 public class VersionEntries {\r
31   public static final String ALPHA_VERSION = "alpha";\r
32 \r
33   public static final String BETA_VERSION = "beta";\r
34 \r
35   protected static Hashtable versions;\r
36   static {\r
37     versions = new Hashtable();\r
38     // integers represent version hierarchy - 0 precedes 1\r
39     versions.put(ALPHA_VERSION, new Integer(0));\r
40     versions.put(BETA_VERSION, new Integer(1));\r
41   }\r
42 \r
43   // TODO: LATER: decide on best pattern for enumeration classes (ie - need an\r
44   // ordered list of versions, and validator, plus explicit enum-strings)\r
45   public static boolean isVersion(String vstring) {\r
46     return versions.containsKey(vstring);\r
47   }\r
48 \r
49   /**\r
50    * returns 0 if levels are equivalent, 1 if higher is valid and higher, 2 if\r
51    * lower is valid and higher -1 if both levels are invalid\r
52    * \r
53    * @param higher\r
54    * @param lower\r
55    * @return\r
56    */\r
57   public static int compare(String higher, String lower) {\r
58     int v_1 = versions.containsKey(higher) ? ((Integer) versions.get(higher))\r
59         .intValue() : -1;\r
60     int v_2 = versions.containsKey(lower) ? ((Integer) versions.get(lower))\r
61         .intValue() : -1;\r
62     int comp = v_1 < v_2 ? 2 : v_1 == v_2 ? 0 : 1;\r
63     return (comp == 0) ? (v_1 != -1 ? 0 : -1) : comp;\r
64   }\r
65 \r
66   /**\r
67    * @return the latest version that this vamsas library supports\r
68    */\r
69   public static String latestVersion() {\r
70     return BETA_VERSION;\r
71   }\r
72 \r
73 }\r