View Javadoc
1   /**
2    *    Copyright 2009-2015 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.type;
17  
18  import java.math.BigDecimal;
19  import java.math.BigInteger;
20  import java.util.Date;
21  import java.util.HashSet;
22  import java.util.Set;
23  
24  /**
25   * @author Clinton Begin
26   */
27  public class SimpleTypeRegistry {
28  
29    private static final Set<Class<?>> SIMPLE_TYPE_SET = new HashSet<Class<?>>();
30  
31    static {
32      SIMPLE_TYPE_SET.add(String.class);
33      SIMPLE_TYPE_SET.add(Byte.class);
34      SIMPLE_TYPE_SET.add(Short.class);
35      SIMPLE_TYPE_SET.add(Character.class);
36      SIMPLE_TYPE_SET.add(Integer.class);
37      SIMPLE_TYPE_SET.add(Long.class);
38      SIMPLE_TYPE_SET.add(Float.class);
39      SIMPLE_TYPE_SET.add(Double.class);
40      SIMPLE_TYPE_SET.add(Boolean.class);
41      SIMPLE_TYPE_SET.add(Date.class);
42      SIMPLE_TYPE_SET.add(Class.class);
43      SIMPLE_TYPE_SET.add(BigInteger.class);
44      SIMPLE_TYPE_SET.add(BigDecimal.class);
45    }
46  
47    private SimpleTypeRegistry() {
48      // Prevent Instantiation
49    }
50  
51    /*
52     * Tells us if the class passed in is a known common type
53     *
54     * @param clazz The class to check
55     * @return True if the class is known
56     */
57    public static boolean isSimpleType(Class<?> clazz) {
58      return SIMPLE_TYPE_SET.contains(clazz);
59    }
60  
61  }