List of usage examples for java.lang Class isPrimitive
@HotSpotIntrinsicCandidate public native boolean isPrimitive();
From source file:br.com.binarti.simplesearchexpr.converter.NumberSearchDataConverter.java
@SuppressWarnings("rawtypes") @Override/*from ww w .ja va 2 s . c o m*/ protected Object asSingleObject(SimpleSearchExpressionField field, String value, Map<String, Object> params, Class<?> targetType) { if (value == null) return null; if (targetType.isPrimitive()) { targetType = ClassUtils.primitiveToWrapper(targetType); } try { Constructor constructor = targetType.getConstructor(String.class); return constructor.newInstance(value.trim()); } catch (Exception e) { throw new SimpleSearchDataConverterException( "Error converter " + value + " to " + targetType.getClass()); } }
From source file:com.khubla.cbean.serializer.impl.SimpleFieldSerializer.java
@Override public boolean applies(Field field) { final Class<?> clazz = field.getType(); return isWrapperType(clazz) || clazz.isPrimitive() || clazz.equals(String.class); }
From source file:com.github.dozermapper.core.converters.PrimitiveOrWrapperConverter.java
public boolean accepts(Class<?> aClass) { return aClass.isPrimitive() || Number.class.isAssignableFrom(aClass) || String.class.equals(aClass) || Character.class.equals(aClass) || Boolean.class.equals(aClass) || java.util.Date.class.isAssignableFrom(aClass) || java.util.Calendar.class.isAssignableFrom(aClass) || aClass.isEnum(); }
From source file:info.magnolia.beanmerger.BeanMergerBase.java
protected boolean isSimpleType(Class type) { return type.isPrimitive() || type == Boolean.class || type == Byte.class || type == Character.class || type == Short.class || type == Integer.class || type == Long.class || type == Float.class || type == Double.class || type == Void.class || // well, at least property wise type == String.class || type == Class.class || // not mergable Content.class.isAssignableFrom(type) || Node.class.isAssignableFrom(type); }
From source file:com.alibaba.openapi.client.rpc.BasicHttpRequestBuilder.java
@Override protected List<NameValuePair> buildParams(InvokeContext context) { Map<String, Object> reqParams = context.getRequest().getParams(); final List<NameValuePair> params = new ArrayList<NameValuePair>(1); for (Map.Entry<String, Object> entry : reqParams.entrySet()) { Object value = entry.getValue(); if (value != null) { try { String valueStr;/*from w w w . j av a 2 s . c o m*/ Class<?> valueType = value.getClass(); if (valueType.isPrimitive() || CharSequence.class.isAssignableFrom(valueType) || Number.class.isAssignableFrom(valueType) || Boolean.class.equals(valueType) || Character.class.equals(valueType)) { valueStr = value.toString(); } else { valueStr = JsonSerializeHelper.object2json(entry.getValue()); } params.add(new BasicNameValuePair(entry.getKey(), valueStr)); } catch (JsonProcessingException e) { throw new IllegalArgumentException( "illegal argument " + entry.getKey() + ", error:" + e.getMessage(), e); } catch (IOException e) { throw new IllegalArgumentException( "illegal argument " + entry.getKey() + ", error:" + e.getMessage(), e); } } } return params; }
From source file:com.laxser.blitz.lama.provider.jdbc.PreparedStatementCallbackReturnId.java
public PreparedStatementCallbackReturnId(PreparedStatementSetter setter, Class<?> returnType) { this.setter = setter; if (returnType.isPrimitive()) { returnType = ClassUtils.primitiveToWrapper(returnType); }//from w w w . j a va 2s . c om this.returnType = returnType; Class<?> idType = returnType; if (returnType.isArray()) { idType = returnType.getComponentType(); } this.idType = idType; if (idType.isPrimitive()) { idType = ClassUtils.primitiveToWrapper(idType); } this.wrappedIdType = idType; this.mapper = new SingleColumnRowMapper(idType); if (wrappedIdType != Integer.class && wrappedIdType != Long.class) { throw new IllegalArgumentException( "wrong return type(int/long type or its array type only): " + returnType); } }
From source file:com.glaf.core.util.ReflectUtils.java
public static boolean isPrimitive(Class<?> cls) { return cls.isPrimitive() || cls == String.class || cls == Boolean.class || cls == Character.class || Number.class.isAssignableFrom(cls) || Date.class.isAssignableFrom(cls); }
From source file:de.openknowledge.cdi.common.property.PropertiesLoader.java
private void assertPrimitiveNotNull(InjectionPoint injectionPoint, String value, Class<?> expectedType) { if (expectedType.isPrimitive() && value == null) { throw buildIllegalArgumentException(injectionPoint, value, expectedType, null); }//from www . jav a2 s . c o m }
From source file:mil.army.usace.data.dataquery.utility.DefaultConverter.java
@Override public Object convertType(Object obj, Field field) throws ClassNotFoundException, ConversionException { Class fieldParam = field.getType(); if (obj == null) return null; else {// w w w. j a v a2 s . c o m if (fieldParam.isPrimitive()) { return obj; } else { return convertType(obj, fieldParam); } } }
From source file:com.bstek.dorado.data.method.MethodAutoMatchingUtils.java
private static int isTypesCompatible(Type targetType, Type sourceType) { Class<?> targetClass = toClass(targetType); Class<?> sourceClass = toClass(sourceType); boolean b = targetClass.isAssignableFrom(sourceClass) || sourceClass.isAssignableFrom(targetClass); if (!b && (targetClass.isPrimitive() || sourceClass.isPrimitive())) { targetClass = MethodUtils.toNonPrimitiveClass(targetClass); sourceClass = MethodUtils.toNonPrimitiveClass(sourceClass); b = targetClass.isAssignableFrom(sourceClass) || sourceClass.isAssignableFrom(targetClass); }// w w w.ja va 2s . c o m if (!b) { b = Number.class.isAssignableFrom(targetClass) && Number.class.isAssignableFrom(sourceClass); } return (b) ? 1 : 0; }