|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| package org.rblasch.convert.type; |
|
17 |
| |
|
18 |
| import org.rblasch.convert.assertion.Assertion; |
|
19 |
| |
|
20 |
| import java.util.HashMap; |
|
21 |
| import java.util.Map; |
|
22 |
| |
|
23 |
| |
|
24 |
| |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| public class PrimitiveType extends AbstractType { |
|
31 |
| final static Map valueOfMap = new HashMap(); |
|
32 |
| static { |
|
33 |
8
| valueOfMap.put("byte", new PrimitiveType(Byte.TYPE));
|
|
34 |
8
| valueOfMap.put("short", new PrimitiveType(Short.TYPE));
|
|
35 |
8
| valueOfMap.put("int", new PrimitiveType(Integer.TYPE));
|
|
36 |
8
| valueOfMap.put("long", new PrimitiveType(Long.TYPE));
|
|
37 |
8
| valueOfMap.put("float", new PrimitiveType(Float.TYPE));
|
|
38 |
8
| valueOfMap.put("double", new PrimitiveType(Double.TYPE));
|
|
39 |
| } |
|
40 |
| |
|
41 |
25
| static PrimitiveType valueOf(final String s) throws UnknownTypeException {
|
|
42 |
25
| final PrimitiveType type = (PrimitiveType) valueOfMap.get(s);
|
|
43 |
25
| if (type != null) {
|
|
44 |
19
| return type;
|
|
45 |
| } else { |
|
46 |
6
| throw new UnknownTypeException(s + " is not a known primitive type");
|
|
47 |
| } |
|
48 |
| } |
|
49 |
| |
|
50 |
| private final Class t; |
|
51 |
| |
|
52 |
60
| PrimitiveType(final Class t) {
|
|
53 |
60
| Assertion.ensure(t.isPrimitive(), "t must be primitive");
|
|
54 |
60
| this.t = t;
|
|
55 |
| } |
|
56 |
| |
|
57 |
1
| public Class getTheClass() {
|
|
58 |
1
| return t;
|
|
59 |
| } |
|
60 |
| |
|
61 |
205540
| public String getName() {
|
|
62 |
205540
| return t.getName();
|
|
63 |
| } |
|
64 |
| } |