KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > thoughtworks > acceptance > objects > StatusEnum


1 package com.thoughtworks.acceptance.objects;
2
3 import java.io.ObjectStreamException JavaDoc;
4 import java.io.Serializable JavaDoc;
5 import java.util.Arrays JavaDoc;
6 import java.util.Collections JavaDoc;
7 import java.util.List JavaDoc;
8
9 public class StatusEnum implements Serializable JavaDoc, Comparable JavaDoc {
10
11     private static int nextOrdinal = 0;
12     private int ordinal = nextOrdinal++;
13
14     public static final StatusEnum STARTED = new StatusEnum("STARTED");
15
16     public static final StatusEnum FINISHED = new StatusEnum("FINISHED");
17
18     private static final StatusEnum[] PRIVATE_VALUES = {STARTED, FINISHED};
19
20     public static final List JavaDoc VALUES = Collections.unmodifiableList(Arrays.asList(PRIVATE_VALUES));
21
22     private String JavaDoc name; // for debug only
23

24     private StatusEnum() {
25     }
26
27     private StatusEnum(String JavaDoc name) {
28         this.name = name;
29     }
30
31     public String JavaDoc toString() {
32         return name;
33     }
34
35     public int compareTo(Object JavaDoc o) {
36         return ordinal - ((StatusEnum) o).ordinal;
37     }
38
39     private Object JavaDoc readResolve() throws ObjectStreamException JavaDoc {
40         return PRIVATE_VALUES[ordinal]; //Canonicalize
41
}
42 }
43
Popular Tags