1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package coras.structure;
22
23 import java.io.InvalidObjectException;
24 import java.io.ObjectStreamException;
25 import java.io.Serializable;
26 import java.util.ArrayList;
27 import java.util.Arrays;
28 import java.util.Collections;
29 import java.util.Iterator;
30 import java.util.List;
31
32 /***
33 *
34 * @author Fredrik Vraalsen
35 */
36 public final class ViewpointEnum implements Serializable {
37
38 public static final ViewpointEnum ENTERPRISE = new ViewpointEnum("Enterprise");
39 public static final ViewpointEnum INFORMATION = new ViewpointEnum("Information");
40 public static final ViewpointEnum COMPUTATIONAL = new ViewpointEnum("Computational");
41 public static final ViewpointEnum ENGINEERING = new ViewpointEnum("Engineering");
42 public static final ViewpointEnum TECHNOLOGY = new ViewpointEnum("Technology");
43 private static final ViewpointEnum[] VALS = {
44 ENTERPRISE,
45 INFORMATION,
46 COMPUTATIONAL,
47 ENGINEERING,
48 TECHNOLOGY };
49 public static final List VALUES = Collections.unmodifiableList(Arrays.asList(VALS));
50 private static final List NAMES = new ArrayList();
51 static {
52 for (Iterator i = VALUES.iterator(); i.hasNext();) {
53 NAMES.add(i.next().toString());
54 }
55 }
56
57 private final String name;
58
59 /***
60 * Private constructor.
61 *
62 * @param name
63 * the name of the viewpoint
64 */
65 private ViewpointEnum(String name) {
66 this.name = name;
67 }
68
69 /***
70 * Get the ViewpointEnum corresponding to the specified name.
71 *
72 * @param name
73 * the viewpoint name
74 * @return the ViewpointEnum, or null if not found
75 */
76 public static ViewpointEnum forName(String name) {
77 int index = NAMES.indexOf(name);
78 if (index < 0 || index >= VALS.length) {
79 return null;
80 } else {
81 return VALS[index];
82 }
83 }
84
85 /***
86 * Get the String representation.
87 *
88 * @return the name of the viewpoint
89 */
90 public String toString() {
91 return name;
92 }
93
94 /***
95 * Enumeration pattern: Ensure that a.equals(b) <=> (a == b) for all
96 * ViewpointEnums a and b when deserializing.
97 *
98 * @return the ViewpointEnum corresponding to the viewpoint string
99 * @throws ObjectStreamException
100 * if no ViewpointEnum can be found for that viewpoint string
101 */
102 private Object readResolve() throws ObjectStreamException {
103 ViewpointEnum result = forName(name);
104 if (result == null) {
105 throw new InvalidObjectException("Illegal ViewpointEnum instance: " + name);
106 }
107 return result;
108 }
109
110 }