01: /*
02: * Copyright (C) 2004, 2005 Joe Walnes.
03: * Copyright (C) 2006, 2007 XStream Committers.
04: * All rights reserved.
05: *
06: * The software in this package is published under the terms of the BSD
07: * style license a copy of which has been included with this distribution in
08: * the LICENSE.txt file.
09: *
10: * Created on 30. May 2004 by Joe Walnes
11: */
12: package com.thoughtworks.acceptance.objects;
13:
14: import java.io.Serializable;
15: import java.util.Arrays;
16: import java.util.Collections;
17: import java.util.List;
18:
19: public class StatusEnum implements Serializable, Comparable {
20:
21: private static int nextOrdinal = 0;
22: private int ordinal = nextOrdinal++;
23:
24: public static final StatusEnum STARTED = new StatusEnum("STARTED");
25:
26: public static final StatusEnum FINISHED = new StatusEnum("FINISHED");
27:
28: private static final StatusEnum[] PRIVATE_VALUES = { STARTED,
29: FINISHED };
30:
31: public static final List VALUES = Collections
32: .unmodifiableList(Arrays.asList(PRIVATE_VALUES));
33:
34: private String name; // for debug only
35:
36: private StatusEnum() {
37: }
38:
39: private StatusEnum(String name) {
40: this .name = name;
41: }
42:
43: public String toString() {
44: return name;
45: }
46:
47: public int compareTo(Object o) {
48: return ordinal - ((StatusEnum) o).ordinal;
49: }
50:
51: private Object readResolve() {
52: return PRIVATE_VALUES[ordinal]; //Canonicalize
53: }
54: }
|