View Javadoc
1   /**
2    *    Copyright 2009-2017 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.apache.ibatis.executor.resultset;
17  
18  import java.util.HashMap;
19  import java.util.Map;
20  
21  public class PrimitiveTypes {
22    private final Map<Class<?>, Class<?>> primitiveToWrappers;
23    private final Map<Class<?>, Class<?>> wrappersToPrimitives;
24  
25    public PrimitiveTypes() {
26      this.primitiveToWrappers = new HashMap<Class<?>, Class<?>>();
27      this.wrappersToPrimitives = new HashMap<Class<?>, Class<?>>();
28  
29      add(boolean.class, Boolean.class);
30      add(byte.class, Byte.class);
31      add(char.class, Character.class);
32      add(double.class, Double.class);
33      add(float.class, Float.class);
34      add(int.class, Integer.class);
35      add(long.class, Long.class);
36      add(short.class, Short.class);
37      add(void.class, Void.class);
38    }
39  
40    private void add(final Class<?> primitiveType, final Class<?> wrapperType) {
41      primitiveToWrappers.put(primitiveType, wrapperType);
42      wrappersToPrimitives.put(wrapperType, primitiveType);
43    }
44  
45    public Class<?> getWrapper(final Class<?> primitiveType) {
46      return primitiveToWrappers.get(primitiveType);
47    }
48  
49    public Class<?> getPrimitive(final Class<?> wrapperType) {
50      return wrappersToPrimitives.get(wrapperType);
51    }
52  }