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 * Created by IntelliJ IDEA.
25 * User: rb
26 * Date: Oct 27, 2004
27 * Time: 10:26:35 PM
28 * To change this template use File | Settings | File Templates.
29 */
30 public class PrimitiveType extends AbstractType {
31 final static Map valueOfMap = new HashMap();
32 static {
33 valueOfMap.put("byte", new PrimitiveType(Byte.TYPE));
34 valueOfMap.put("short", new PrimitiveType(Short.TYPE));
35 valueOfMap.put("int", new PrimitiveType(Integer.TYPE));
36 valueOfMap.put("long", new PrimitiveType(Long.TYPE));
37 valueOfMap.put("float", new PrimitiveType(Float.TYPE));
38 valueOfMap.put("double", new PrimitiveType(Double.TYPE));
39 }
40
41 static PrimitiveType valueOf(final String s) throws UnknownTypeException {
42 final PrimitiveType type = (PrimitiveType) valueOfMap.get(s);
43 if (type != null) {
44 return type;
45 } else {
46 throw new UnknownTypeException(s + " is not a known primitive type");
47 }
48 }
49
50 private final Class t;
51
52 PrimitiveType(final Class t) {
53 Assertion.ensure(t.isPrimitive(), "t must be primitive");
54 this.t = t;
55 }
56
57 public Class getTheClass() {
58 return t;
59 }
60
61 public String getName() {
62 return t.getName();
63 }
64 }