1
2
3
4
5
6
7 package ca.uhn.cache;
8
9 import java.util.List;
10
11 import org.apache.commons.lang.enum.Enum;
12
13
14 /***
15 * Type safe codes for data volatility.
16 *
17 * @author <a href="mailto:bryan.tripp@uhn.on.ca">Bryan Tripp</a>
18 * @version $Revision: 1.1 $ updated on $Date: 2005/01/24 22:52:04 $ by $Author: bryan_tripp $
19 */
20 public class VolatilityEnum extends Enum implements Comparable {
21
22 /***
23 * Describes data that are unlikely to change (e.g. have been labelled
24 * "final").
25 */
26 public static final VolatilityEnum STABLE = new VolatilityEnum("STABLE", 10);
27
28 /***
29 * Describes data that are likely to change (e.g. have been labelled
30 * "incomplete").
31 */
32 public static final VolatilityEnum VOLATILE = new VolatilityEnum("VOLATILE", 0);
33
34 private Integer myLevel;
35
36 /***
37 * @param theName text code for volatility
38 * @param theLevel level of volatility, for ordering purposes (lower means more volatile)
39 */
40 protected VolatilityEnum(String theName, int theLevel) {
41 super(theName);
42 myLevel = new Integer(theLevel);
43 }
44
45 /***
46 * @return an Integer level for ordering (lower means more volatile)
47 */
48 protected Integer getLevel() {
49 return myLevel;
50 }
51
52 /***
53 * @param theName name of desired <code>VolatilityEnum</code>
54 * @return <code>VolatilityEnum</code> that has the given name.
55 */
56 public static VolatilityEnum getEnum(String theName) {
57 return (VolatilityEnum) getEnum(
58 VolatilityEnum.class, theName);
59 }
60
61 /***
62 * @return List of all <code>VolatilityEnum</code>.
63 */
64 public static List getEnumList() {
65 return getEnumList(VolatilityEnum.class);
66 }
67
68 /***
69 * Ordering from most to least volatile.
70 *
71 * @see java.lang.Comparable#compareTo(java.lang.Object)
72 */
73 public int compareTo(Object theObject) {
74 if ( !(theObject instanceof VolatilityEnum) ) {
75 throw new ClassCastException("Can't compare to " + theObject.getClass().getName());
76 }
77
78 VolatilityEnum enum = (VolatilityEnum) theObject;
79 return this.getLevel().compareTo(enum.getLevel());
80 }
81
82 }