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.model.field.containerdefinition.ContainerDefinitionField;
20 import fulmine.util.reference.AutoCreatingStore;
21 import fulmine.util.reference.IAutoCreatingStore;
22 import fulmine.util.reference.IObjectBuilder;
23 import fulmine.util.reference.is;
24
25
26
27
28
29
30
31
32
33
34
35
36
37 public final class Type implements IType
38 {
39
40
41
42
43
44 private static final class TypeBuilder implements
45 IObjectBuilder<Byte, Type>
46 {
47 public Type create(Byte key)
48 {
49 return new Type(key.byteValue());
50 }
51 }
52
53
54 private final static IAutoCreatingStore<Byte, Type> store =
55 new AutoCreatingStore<Byte, Type>(new TypeBuilder());
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70 public static final IType get(int code, String... name)
71 {
72 final Byte byteCode = Byte.valueOf((byte) code);
73 if (store.containsKey(byteCode))
74 {
75 return store.get(byteCode);
76 }
77 final Type type = store.get(byteCode);
78 if (name.length == 1)
79 {
80 type.setName(name[0]);
81 }
82 return type;
83 }
84
85
86 private final byte code;
87
88
89 private String name;
90
91
92 public static final IType UNSPECIFIED_TYPE = get(-2, "Unspecfied");
93
94
95 public static final IType REMOVED = get(-1, "Removed");
96
97
98 public static final IType SYSTEM = get(0, "System");
99
100
101
102
103
104 public static final
105 IType CONTAINER_DEFINITION = get(1, "ContainerDefinition");
106
107
108 public static final IType BOOLEAN_FIELD = get(3, "BooleanField");
109
110
111 public static final IType INTEGER_FIELD = get(4, "IntegerField");
112
113
114 public static final IType LONG_FIELD = get(5, "LongField");
115
116
117 public static final IType FLOAT_FIELD = get(6, "FloatField");
118
119
120 public static final IType DOUBLE_FIELD = get(7, "DoubleField");
121
122
123 public static final IType STRING_FIELD = get(8, "StringField");
124
125
126 public static final IType DESCRIPTOR_FIELD = get(9, "DescriptorField");
127
128
129 public static final IType RECORD = get(10, "Record");
130
131
132 public static final int BASE_USER_START = RECORD.value() + 1;
133
134 private Type(byte code)
135 {
136 this.code = code;
137 }
138
139 public byte value()
140 {
141 return this.code;
142 }
143
144 public String getName()
145 {
146 return this.name;
147 }
148
149 void setName(String name)
150 {
151 this.name = name;
152 }
153
154 @Override
155 public final String toString()
156 {
157 return string(this, this.code + "," + this.name);
158 }
159
160 @Override
161 public int hashCode()
162 {
163 return this.code;
164 }
165
166 @Override
167 public boolean equals(Object obj)
168 {
169 if (is.same(this, obj))
170 {
171 return true;
172 }
173 if (is.differentClass(this, obj))
174 {
175 return false;
176 }
177 final Type other = (Type) obj;
178 return is.eq(this.code, other.code);
179 }
180
181 }