List of usage examples for java.lang Class isPrimitive
@HotSpotIntrinsicCandidate public native boolean isPrimitive();
From source file:net.firejack.platform.core.validation.LessThanProcessor.java
@Override public List<ValidationMessage> validate(Method readMethod, String property, Object value, ValidationMode mode) throws RuleValidationException { LessThan greaterThanAnnotation = readMethod.getAnnotation(LessThan.class); List<ValidationMessage> messages = null; if (greaterThanAnnotation != null) { messages = new ArrayList<ValidationMessage>(); Class<?> returnType = readMethod.getReturnType(); String parameterName = StringUtils.isBlank(greaterThanAnnotation.parameterName()) ? property : greaterThanAnnotation.parameterName(); if (value != null) { if (returnType.getSuperclass() == Number.class || returnType.isPrimitive()) { boolean checkEquality = greaterThanAnnotation.checkEquality(); Number val = null; if (returnType == Float.class || returnType == float.class) { Float f = (Float) value; if (checkEquality && f > greaterThanAnnotation.floatVal() || !checkEquality && f >= greaterThanAnnotation.floatVal()) { val = greaterThanAnnotation.floatVal(); }// ww w . jav a 2s. co m } else if (returnType == Double.class || returnType == double.class) { Double d = (Double) value; if (checkEquality && d > greaterThanAnnotation.doubleVal() || !checkEquality && d >= greaterThanAnnotation.doubleVal()) { val = greaterThanAnnotation.doubleVal(); } } else { Long longValue = ((Number) value).longValue(); Long rangeValue = ((Integer) greaterThanAnnotation.intVal()).longValue(); if (checkEquality && longValue > rangeValue || !checkEquality && longValue >= rangeValue) { val = greaterThanAnnotation.intVal(); } } if (val != null) { messages.add(new ValidationMessage(property, checkEquality ? greaterThanAnnotation.equalityMsgKey() : greaterThanAnnotation.msgKey(), parameterName, val)); } } } } return messages; }
From source file:fr.obeo.emf.specimen.DirectWriteSpecimenGenerator.java
protected Object nextValue(Class<?> instanceClass) { final Object value; if (instanceClass.isPrimitive() || isWrapperType(instanceClass)) { value = nextPrimitive(unwrap(instanceClass)); } else {// ww w . j a v a 2 s . c om value = nextObject(instanceClass); } return value; }
From source file:com.vityuk.ginger.DefaultLocalization.java
private Callback createSelectorMessageLookupCallback(Method method, String key, int parameterIndex) { Class<?> parameterType = method.getParameterTypes()[parameterIndex]; if (parameterType.isPrimitive() || Primitives.isWrapperType(parameterType)) { // TODO: consider more informative exception throw new InvalidParameterTypeException(parameterType, method); }//w w w . jav a 2s .c o m return new SelectorMessageLookupCallback(localizationProvider, key, parameterIndex); }
From source file:eu.qualityontime.commons.MethodUtils.java
/** * Find a non primitive representation for given primitive class. * * @param clazz//from ww w . ja v a 2 s.c o m * the class to find a representation for, not null * @return the original class if it not a primitive. Otherwise the wrapper * class. Not null */ public static Class<?> toNonPrimitiveClass(final Class<?> clazz) { if (clazz.isPrimitive()) { final Class<?> primitiveClazz = MethodUtils.getPrimitiveWrapper(clazz); // the above method returns if (primitiveClazz != null) { return primitiveClazz; } else { return clazz; } } else { return clazz; } }
From source file:com.expressui.core.dao.query.EntityQuery.java
/** * Clear this query so that all filters (query parameters) and sort-criteria are removed (except for defaults). * The method uses reflection to clear any filters defined as bean properties by subclasses. Once cleared, * re-execution of query results in all records being found or a default list of default filters are specified. * * @see #initializeDefaults/*from w ww . j av a 2 s . c o m*/ */ public void clear() { try { for (PropertyDescriptor descriptor : descriptors) { Method writeMethod = descriptor.getWriteMethod(); Method readMethod = descriptor.getReadMethod(); if (readMethod != null && writeMethod != null && !writeMethod.getDeclaringClass().equals(EntityQuery.class) && !writeMethod.getDeclaringClass().equals(Object.class)) { Class type = descriptor.getPropertyType(); if (type.isPrimitive() && !type.isArray()) { if (ReflectionUtil.isNumberType(type)) { writeMethod.invoke(this, 0); } else if (Boolean.class.isAssignableFrom(type)) { writeMethod.invoke(this, false); } } else { writeMethod.invoke(this, new Object[] { null }); } } } } catch (IllegalAccessException e) { Assert.PROGRAMMING.fail(e); } catch (InvocationTargetException e) { Assert.PROGRAMMING.fail(e); } initializeDefaults(); }
From source file:com.xie.javacase.json.JSONObject.java
static boolean isStandardProperty(Class clazz) { return clazz.isPrimitive() || clazz.isAssignableFrom(Byte.class) || clazz.isAssignableFrom(Short.class) || clazz.isAssignableFrom(Integer.class) || clazz.isAssignableFrom(Long.class) || clazz.isAssignableFrom(Float.class) || clazz.isAssignableFrom(Double.class) || clazz.isAssignableFrom(Character.class) || clazz.isAssignableFrom(String.class) || clazz.isAssignableFrom(Boolean.class); }
From source file:com.dianping.resource.io.util.ClassUtils.java
/** * Check if the right-hand side type may be assigned to the left-hand side * type, assuming setting by reflection. Considers primitive wrapper * classes as assignable to the corresponding primitive types. * @param lhsType the target type/*from w w w .j av a 2 s. c om*/ * @param rhsType the value type that should be assigned to the target type * @return if the target type is assignable from the value type * @see TypeUtils#isAssignable */ public static boolean isAssignable(Class<?> lhsType, Class<?> rhsType) { Assert.notNull(lhsType, "Left-hand side type must not be null"); Assert.notNull(rhsType, "Right-hand side type must not be null"); if (lhsType.isAssignableFrom(rhsType)) { return true; } if (lhsType.isPrimitive()) { Class<?> resolvedPrimitive = primitiveWrapperTypeMap.get(rhsType); if (resolvedPrimitive != null && lhsType.equals(resolvedPrimitive)) { return true; } } else { Class<?> resolvedWrapper = primitiveTypeToWrapperMap.get(rhsType); if (resolvedWrapper != null && lhsType.isAssignableFrom(resolvedWrapper)) { return true; } } return false; }
From source file:eu.opensourceprojects.mondo.benchmarks.transformationzoo.instantiator.SpecimenGenerator.java
private Object nextValue(Class<?> instanceClass) { final Object value; if (instanceClass.isPrimitive() || isWrapperType(instanceClass)) { value = nextPrimitive(unwrap(instanceClass)); } else {/*from www . ja va2s .c o m*/ value = nextObject(instanceClass); } //System.out.println(value); return value; }
From source file:com.freetmp.common.util.ClassUtils.java
public static boolean isAssignable(Class<?> lhsType, Class<?> rhsType) { Assert.notNull(lhsType, "Left-hand side type must not be null"); Assert.notNull(rhsType, "Right-hand side type must not be null"); if (lhsType.isAssignableFrom(rhsType)) { return true; }/*from w w w.jav a 2 s.c om*/ if (lhsType.isPrimitive()) { Class<?> resolvedPrimitive = primitiveWrapperTypeMap.get(rhsType); if (resolvedPrimitive != null && lhsType.equals(resolvedPrimitive)) { return true; } } else { Class<?> resolvedWrapper = primitiveTypeToWrapperMap.get(rhsType); if (resolvedWrapper != null && lhsType.isAssignableFrom(resolvedWrapper)) { return true; } } return false; }