1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package fulmine;
17
18 import static fulmine.util.Utils.string;
19 import fulmine.util.reference.AutoCreatingStore;
20 import fulmine.util.reference.IAutoCreatingStore;
21 import fulmine.util.reference.IObjectBuilder;
22 import fulmine.util.reference.is;
23
24
25
26
27
28
29
30
31
32 public final class Domain implements IDomain
33 {
34
35 private static final class DomainBuilder implements
36 IObjectBuilder<Byte, Domain>
37 {
38 public Domain create(Byte key)
39 {
40 return new Domain(key.byteValue());
41 }
42 }
43
44
45 private final static IAutoCreatingStore<Byte, Domain> store =
46 new AutoCreatingStore<Byte, Domain>(new DomainBuilder());
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61 public static final IDomain get(int code, String... name)
62 {
63 final Byte byteCode = Byte.valueOf((byte) code);
64 if (store.containsKey(byteCode))
65 {
66 return store.get(byteCode);
67 }
68 final Domain domain = store.get(byteCode);
69 if (name.length == 1)
70 {
71 domain.setName(name[0]);
72 }
73 return domain;
74 }
75
76
77 private final byte code;
78
79
80 private String name;
81
82
83 public static final IDomain FRAMEWORK = get(0, "framework");
84
85 private Domain(byte code)
86 {
87 this.code = code;
88 }
89
90 public byte value()
91 {
92 return this.code;
93 }
94
95 public String getName()
96 {
97 return this.name;
98 }
99
100 void setName(String name)
101 {
102 this.name = name;
103 }
104
105 @Override
106 public final String toString()
107 {
108 return string(this, this.code + "," + this.name);
109 }
110
111 @Override
112 public int hashCode()
113 {
114 return this.code;
115 }
116
117 @Override
118 public boolean equals(Object obj)
119 {
120 if (is.same(this, obj))
121 {
122 return true;
123 }
124 if (is.differentClass(this, obj))
125 {
126 return false;
127 }
128 final Domain other = (Domain) obj;
129 return is.eq(this.code, other.code);
130 }
131 }