1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.mybatis.generator.api.dom.java;
17
18 public class PrimitiveTypeWrapper extends FullyQualifiedJavaType {
19 private static PrimitiveTypeWrapper booleanInstance;
20 private static PrimitiveTypeWrapper byteInstance;
21 private static PrimitiveTypeWrapper characterInstance;
22 private static PrimitiveTypeWrapper doubleInstance;
23 private static PrimitiveTypeWrapper floatInstance;
24 private static PrimitiveTypeWrapper integerInstance;
25 private static PrimitiveTypeWrapper longInstance;
26 private static PrimitiveTypeWrapper shortInstance;
27
28 private final String toPrimitiveMethod;
29
30
31
32
33
34
35
36
37
38
39 private PrimitiveTypeWrapper(String fullyQualifiedName,
40 String toPrimitiveMethod) {
41 super(fullyQualifiedName);
42 this.toPrimitiveMethod = toPrimitiveMethod;
43 }
44
45 public String getToPrimitiveMethod() {
46 return toPrimitiveMethod;
47 }
48
49 @Override
50 public boolean equals(Object obj) {
51 if (this == obj) {
52 return true;
53 }
54
55 if (!(obj instanceof PrimitiveTypeWrapper)) {
56 return false;
57 }
58
59 PrimitiveTypeWrapper other = (PrimitiveTypeWrapper) obj;
60
61 return getFullyQualifiedName().equals(other.getFullyQualifiedName());
62 }
63
64 @Override
65 public int hashCode() {
66 return getFullyQualifiedName().hashCode();
67 }
68
69 public static PrimitiveTypeWrapper getBooleanInstance() {
70 if (booleanInstance == null) {
71 booleanInstance = new PrimitiveTypeWrapper("java.lang.Boolean",
72 "booleanValue()");
73 }
74
75 return booleanInstance;
76 }
77
78 public static PrimitiveTypeWrapper getByteInstance() {
79 if (byteInstance == null) {
80 byteInstance = new PrimitiveTypeWrapper("java.lang.Byte",
81 "byteValue()");
82 }
83
84 return byteInstance;
85 }
86
87 public static PrimitiveTypeWrapper getCharacterInstance() {
88 if (characterInstance == null) {
89 characterInstance = new PrimitiveTypeWrapper("java.lang.Character",
90 "charValue()");
91 }
92
93 return characterInstance;
94 }
95
96 public static PrimitiveTypeWrapper getDoubleInstance() {
97 if (doubleInstance == null) {
98 doubleInstance = new PrimitiveTypeWrapper("java.lang.Double",
99 "doubleValue()");
100 }
101
102 return doubleInstance;
103 }
104
105 public static PrimitiveTypeWrapper getFloatInstance() {
106 if (floatInstance == null) {
107 floatInstance = new PrimitiveTypeWrapper("java.lang.Float",
108 "floatValue()");
109 }
110
111 return floatInstance;
112 }
113
114 public static PrimitiveTypeWrapper getIntegerInstance() {
115 if (integerInstance == null) {
116 integerInstance = new PrimitiveTypeWrapper("java.lang.Integer",
117 "intValue()");
118 }
119
120 return integerInstance;
121 }
122
123 public static PrimitiveTypeWrapper getLongInstance() {
124 if (longInstance == null) {
125 longInstance = new PrimitiveTypeWrapper("java.lang.Long",
126 "longValue()");
127 }
128
129 return longInstance;
130 }
131
132 public static PrimitiveTypeWrapper getShortInstance() {
133 if (shortInstance == null) {
134 shortInstance = new PrimitiveTypeWrapper("java.lang.Short",
135 "shortValue()");
136 }
137
138 return shortInstance;
139 }
140 }