View Javadoc
1   /**
2    *    Copyright 2006-2016 the original author or authors.
3    *
4    *    Licensed under the Apache License, Version 2.0 (the "License");
5    *    you may not use this file except in compliance with the License.
6    *    You may obtain a copy of the License at
7    *
8    *       http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *    Unless required by applicable law or agreed to in writing, software
11   *    distributed under the License is distributed on an "AS IS" BASIS,
12   *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *    See the License for the specific language governing permissions and
14   *    limitations under the License.
15   */
16  package org.mybatis.generator.api.dom.java;
17  
18  /**
19   * @author Jeff Butler
20   * 
21   */
22  public class PrimitiveTypeWrapper extends FullyQualifiedJavaType {
23      private static PrimitiveTypeWrapper booleanInstance;
24      private static PrimitiveTypeWrapper byteInstance;
25      private static PrimitiveTypeWrapper characterInstance;
26      private static PrimitiveTypeWrapper doubleInstance;
27      private static PrimitiveTypeWrapper floatInstance;
28      private static PrimitiveTypeWrapper integerInstance;
29      private static PrimitiveTypeWrapper longInstance;
30      private static PrimitiveTypeWrapper shortInstance;
31  
32      private String toPrimitiveMethod;
33  
34      /**
35       * Use the static getXXXInstance methods to gain access to one of the type
36       * wrappers.
37       * 
38       * @param fullyQualifiedName
39       *            fully qualified name of the wrapper type
40       * @param toPrimitiveMethod
41       *            the method that returns the wrapped primitive
42       */
43      private PrimitiveTypeWrapper(String fullyQualifiedName,
44              String toPrimitiveMethod) {
45          super(fullyQualifiedName);
46          this.toPrimitiveMethod = toPrimitiveMethod;
47      }
48  
49      public String getToPrimitiveMethod() {
50          return toPrimitiveMethod;
51      }
52  
53      public static PrimitiveTypeWrapper getBooleanInstance() {
54          if (booleanInstance == null) {
55              booleanInstance = new PrimitiveTypeWrapper("java.lang.Boolean", //$NON-NLS-1$
56                      "booleanValue()"); //$NON-NLS-1$
57          }
58  
59          return booleanInstance;
60      }
61  
62      public static PrimitiveTypeWrapper getByteInstance() {
63          if (byteInstance == null) {
64              byteInstance = new PrimitiveTypeWrapper("java.lang.Byte", //$NON-NLS-1$
65                      "byteValue()"); //$NON-NLS-1$
66          }
67  
68          return byteInstance;
69      }
70  
71      public static PrimitiveTypeWrapper getCharacterInstance() {
72          if (characterInstance == null) {
73              characterInstance = new PrimitiveTypeWrapper("java.lang.Character", //$NON-NLS-1$
74                      "charValue()"); //$NON-NLS-1$
75          }
76  
77          return characterInstance;
78      }
79  
80      public static PrimitiveTypeWrapper getDoubleInstance() {
81          if (doubleInstance == null) {
82              doubleInstance = new PrimitiveTypeWrapper("java.lang.Double", //$NON-NLS-1$
83                      "doubleValue()"); //$NON-NLS-1$
84          }
85  
86          return doubleInstance;
87      }
88  
89      public static PrimitiveTypeWrapper getFloatInstance() {
90          if (floatInstance == null) {
91              floatInstance = new PrimitiveTypeWrapper("java.lang.Float", //$NON-NLS-1$
92                      "floatValue()"); //$NON-NLS-1$
93          }
94  
95          return floatInstance;
96      }
97  
98      public static PrimitiveTypeWrapper getIntegerInstance() {
99          if (integerInstance == null) {
100             integerInstance = new PrimitiveTypeWrapper("java.lang.Integer", //$NON-NLS-1$
101                     "intValue()"); //$NON-NLS-1$
102         }
103 
104         return integerInstance;
105     }
106 
107     public static PrimitiveTypeWrapper getLongInstance() {
108         if (longInstance == null) {
109             longInstance = new PrimitiveTypeWrapper("java.lang.Long", //$NON-NLS-1$
110                     "longValue()"); //$NON-NLS-1$
111         }
112 
113         return longInstance;
114     }
115 
116     public static PrimitiveTypeWrapper getShortInstance() {
117         if (shortInstance == null) {
118             shortInstance = new PrimitiveTypeWrapper("java.lang.Short", //$NON-NLS-1$
119                     "shortValue()"); //$NON-NLS-1$
120         }
121 
122         return shortInstance;
123     }
124 }