SimpleTypeRegistry.java

  1. /*
  2.  *    Copyright 2009-2023 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.  *       https://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. import java.math.BigDecimal;
  18. import java.math.BigInteger;
  19. import java.util.Date;
  20. import java.util.HashSet;
  21. import java.util.Set;

  22. /**
  23.  * @author Clinton Begin
  24.  */
  25. public class SimpleTypeRegistry {

  26.   private static final Set<Class<?>> SIMPLE_TYPE_SET = new HashSet<>();

  27.   static {
  28.     SIMPLE_TYPE_SET.add(String.class);
  29.     SIMPLE_TYPE_SET.add(Byte.class);
  30.     SIMPLE_TYPE_SET.add(Short.class);
  31.     SIMPLE_TYPE_SET.add(Character.class);
  32.     SIMPLE_TYPE_SET.add(Integer.class);
  33.     SIMPLE_TYPE_SET.add(Long.class);
  34.     SIMPLE_TYPE_SET.add(Float.class);
  35.     SIMPLE_TYPE_SET.add(Double.class);
  36.     SIMPLE_TYPE_SET.add(Boolean.class);
  37.     SIMPLE_TYPE_SET.add(Date.class);
  38.     SIMPLE_TYPE_SET.add(Class.class);
  39.     SIMPLE_TYPE_SET.add(BigInteger.class);
  40.     SIMPLE_TYPE_SET.add(BigDecimal.class);
  41.   }

  42.   private SimpleTypeRegistry() {
  43.     // Prevent Instantiation
  44.   }

  45.   /*
  46.    * Tells us if the class passed in is a known common type
  47.    * @param clazz The class to check
  48.    * @return True if the class is known
  49.    */
  50.   public static boolean isSimpleType(Class<?> clazz) {
  51.     return SIMPLE_TYPE_SET.contains(clazz);
  52.   }

  53. }