List of usage examples for java.lang Class isPrimitive
@HotSpotIntrinsicCandidate public native boolean isPrimitive();
From source file:com.github.ibole.infrastructure.persistence.db.mybatis.pagination.PagingParametersFinder.java
/** * primitive?String//from www. ja va 2 s .co m * <p/> * fixed:paramter string type. * * @param clazz ? * @return <code>null</code>?primitive<code>false</code>?<code>true</code> */ @SuppressWarnings("rawtypes") public static boolean isPrimitiveType(Class clazz) { return clazz != null && (clazz.isPrimitive() || clazz.equals(Long.class) || clazz.equals(Integer.class) || clazz.equals(Short.class) || clazz.equals(Byte.class) || clazz.equals(Double.class) || clazz.equals(Float.class) || clazz.equals(Boolean.class) || clazz.equals(Character.class) || clazz.equals(String.class)); }
From source file:Main.java
/** * Checks if the given class can be wrapped directly * @param clazz The given class/* ww w .java2 s. c o m*/ * @return true if the given class is an autoboxed class e.g., Integer */ private static boolean isWrapperType(Class clazz) { return WRAPPER_TYPES.contains(clazz) || clazz.isPrimitive(); }
From source file:com.haulmont.cuba.core.config.type.TypeFactory.java
/** * Get a TypeFactory instance appropriate for the return type of the * specified configuration interface method. * * @param configInterface The configuration interface. * @param method The method.// w ww . j a v a 2 s.co m * @return An appropriate TypeFactory. * @throws IllegalArgumentException If the type is not supported. */ public static TypeFactory getInstance(Class<?> configInterface, Method method) { Class<?> returnType = method.getReturnType(); if (returnType.isPrimitive()) { returnType = ClassUtils.primitiveToWrapper(returnType); } Factory factory = ConfigUtil.getAnnotation(configInterface, method, Factory.class, true); if (factory != null) { try { if ("".equals(factory.method())) { return factory.factory().newInstance(); } else { String methodName = factory.method(); Method factoryMethod = returnType.getMethod(methodName, String.class); if (!isAcceptableMethod(returnType, factoryMethod)) { throw new IllegalArgumentException("Invalid factory method: " + factoryMethod); } return new StaticTypeFactory(factoryMethod); } } catch (NoSuchMethodException | InstantiationException | IllegalAccessException e) { throw new RuntimeException("Unable to instantiate an type factory", e); } } else { if (Entity.class.isAssignableFrom(returnType)) { return AppBeans.get(ENTITY_FACTORY_BEAN_NAME, TypeFactory.class); } else { if (EnumClass.class.isAssignableFrom(returnType)) { EnumStore mode = ConfigUtil.getAnnotation(configInterface, method, EnumStore.class, true); if (mode != null && EnumStoreMode.ID == mode.value()) { @SuppressWarnings("unchecked") Class<EnumClass> enumeration = (Class<EnumClass>) returnType; Class<?> idType = ConfigUtil.getEnumIdType(enumeration); TypeFactory idFactory = getInferred(idType); try { Method fromIdMethod = returnType.getMethod("fromId", idType); if (!isAcceptableMethod(returnType, fromIdMethod) || idFactory == null) { throw new IllegalArgumentException( "Cannot use method as factory method: " + method); } return new EnumClassFactory(idFactory, fromIdMethod); } catch (NoSuchMethodException e) { throw new IllegalArgumentException( "fromId method is not found for " + enumeration.getName()); } } } TypeFactory factoryT = getInferred(returnType); if (factoryT == null) { throw new IllegalArgumentException("Unsupported return type for " + method); } return factoryT; } } }
From source file:com.alibaba.dubbo.governance.web.common.module.screen.Restful.java
private static boolean isPrimitive(Class<?> cls) { return cls.isPrimitive() || cls == Boolean.class || cls == Byte.class || cls == Character.class || cls == Short.class || cls == Integer.class || cls == Long.class || cls == Float.class || cls == Double.class || cls == String.class; }
From source file:com.alibaba.doris.admin.service.impl.ValueParseUtil.java
/** * ?,?,/* w ww. java2s . c o m*/ * * @param clazz * @return */ @SuppressWarnings("unchecked") private static <T> T getInternalDefaultValue(Class<T> clazz) { if (!clazz.isPrimitive()) { return null; } if (Short.TYPE.equals(clazz)) { return (T) Short.valueOf((short) 0); } if (Integer.TYPE.equals(clazz)) { return (T) Integer.valueOf(0); } if (Long.TYPE.equals(clazz)) { return (T) Long.valueOf(0); } if (Boolean.TYPE.equals(clazz)) { return (T) Boolean.valueOf(false); } if (Float.TYPE.equals(clazz)) { return (T) Float.valueOf(0); } if (Double.TYPE.equals(clazz)) { return (T) Double.valueOf(0); } if (Byte.TYPE.equals(clazz)) { return (T) Byte.valueOf((byte) 0); } if (Character.TYPE.equals(clazz)) { return (T) Character.valueOf('\0'); } return null; }
From source file:org.solmix.runtime.support.spring.AbstractRootBeanDefinitionParser.java
protected static boolean isPrimitive(Class<?> cls) { return cls.isPrimitive() || cls == Boolean.class || cls == Byte.class || cls == Character.class || cls == Short.class || cls == Integer.class || cls == Long.class || cls == Float.class || cls == Double.class || cls == String.class || cls == Date.class || cls == Class.class; }
From source file:Main.java
private static boolean isTypeMatch(Class<?> one, Class<?> two) { if (one.equals(two)) { return true; }//from w ww .j a v a 2 s .c o m if (one.isPrimitive()) { if (one.getName().equals("int") && two.getName().equals("java.lang.Integer")) { return true; } if (one.getName().equals("long") && two.getName().equals("java.lang.Long")) { return true; } if (one.getName().equals("float") && two.getName().equals("java.lang.Float")) { return true; } if (one.getName().equals("double") && two.getName().equals("java.lang.Double")) { return true; } if (one.getName().equals("char") && two.getName().equals("java.lang.Character")) { return true; } if (one.getName().equals("byte") && two.getName().equals("java.lang.Byte")) { return true; } if (one.getName().equals("short") && two.getName().equals("java.lang.Short")) { return true; } if (one.getName().equals("boolean") && two.getName().equals("java.lang.Boolean")) { return true; } } return false; }
From source file:com.wrmsr.search.dsl.util.DerivedSuppliers.java
private static java.lang.reflect.Type boxType(java.lang.reflect.Type type) { if (type instanceof Class) { Class<?> clazz = (Class<?>) type; if (clazz.isPrimitive()) { return requireNonNull(ClassUtils.primitiveToWrapper(clazz)); }/* ww w . ja v a 2 s . c o m*/ } return type; }
From source file:Main.java
/** * Checks if the given class can be wrapped directly * @param clazz The given class/* w w w .j ava 2 s . c o m*/ * @return true if the given class is an autoboxed class e.g., Integer */ private static boolean isWrapperType(Class clazz) { return WRAPPER_TYPES.contains(clazz) || clazz.isPrimitive() || clazz.isEnum(); }
From source file:nz.co.senanque.validationengine.ConvertUtils.java
public static Object convertToObject(Class<?> clazz) { if (clazz.isPrimitive()) { if (clazz.equals(Long.TYPE)) { return new Long(0L); } else if (clazz.equals(Integer.TYPE)) { return new Integer(0); } else if (clazz.equals(Float.TYPE)) { return new Float(0F); } else if (clazz.equals(Double.TYPE)) { return new Double(0D); } else if (clazz.equals(Boolean.TYPE)) { return new Boolean(false); }/*from ww w. j a va 2 s . c o m*/ } return null; }