001 package com.khubla.pragmatach.plugin.mongodb.util; 002 003 import java.lang.reflect.Type; 004 import java.util.HashSet; 005 006 /** 007 * TypeUtil for identifying atomic types 008 * 009 * @author tom 010 */ 011 public class AtomicTypeUtil { 012 private static final HashSet<String> WRAPPER_TYPES = getWrapperTypes(); 013 014 private static HashSet<String> getWrapperTypes() { 015 final HashSet<String> ret = new HashSet<String>(); 016 ret.add(Boolean.class.getName()); 017 ret.add(Character.class.getName()); 018 ret.add(Byte.class.getName()); 019 ret.add(Short.class.getName()); 020 ret.add(Integer.class.getName()); 021 ret.add(Long.class.getName()); 022 ret.add(Float.class.getName()); 023 ret.add(Double.class.getName()); 024 ret.add(Void.class.getName()); 025 return ret; 026 } 027 028 public static boolean isSimpleType(Type type) { 029 if (type.getClass().isInstance(Class.class)) { 030 final Class<?> clazz = (Class<?>) type; 031 return (clazz.isPrimitive() || AtomicTypeUtil.isWrapperType(clazz) || (clazz.getName().compareTo("java.lang.String") == 0)); 032 } else { 033 return false; 034 } 035 } 036 037 public static boolean isWrapperType(Class<?> clazz) { 038 return WRAPPER_TYPES.contains(clazz.getName()); 039 } 040 }