List of usage examples for java.lang Class isPrimitive
@HotSpotIntrinsicCandidate public native boolean isPrimitive();
From source file:org.brushingbits.jnap.common.bean.cloning.BeanCloner.java
protected boolean isStandardType(Class<?> type) { boolean standard = type.isPrimitive() || type.isEnum(); if (!standard) { for (Class<?> standardType : this.standardTypes) { standard = standardType.isAssignableFrom(type); if (standard) { break; }/*from ww w .j av a 2 s .c o m*/ } } return standard; }
From source file:de.ma.it.common.sm.transition.MethodTransition.java
private boolean match(Class<?> paramType, Object arg, Class<?> argType) { if (paramType.isPrimitive()) { if (paramType.equals(Boolean.TYPE)) { return arg instanceof Boolean; }/*w w w. j ava 2 s.com*/ if (paramType.equals(Integer.TYPE)) { return arg instanceof Integer; } if (paramType.equals(Long.TYPE)) { return arg instanceof Long; } if (paramType.equals(Short.TYPE)) { return arg instanceof Short; } if (paramType.equals(Byte.TYPE)) { return arg instanceof Byte; } if (paramType.equals(Double.TYPE)) { return arg instanceof Double; } if (paramType.equals(Float.TYPE)) { return arg instanceof Float; } if (paramType.equals(Character.TYPE)) { return arg instanceof Character; } } return argType.isAssignableFrom(paramType) && paramType.isAssignableFrom(arg.getClass()); }
From source file:org.motechproject.server.event.annotations.MotechListenerOrderedParametersProxy.java
@Override public void callHandler(MotechEvent event) { Map<String, Object> params = event.getParameters(); List<Object> args = new ArrayList<Object>(); int i = 0;//w w w . ja va2s . co m for (Class<?> t : method.getParameterTypes()) { Object param = params.get(Integer.toString(i)); if (param != null && t.isAssignableFrom(param.getClass())) { args.add(param); i++; } else if (params.containsKey(Integer.toString(i)) && !t.isPrimitive() && param == null) { args.add(param); i++; } else { logger.warn(String.format( "Method: %s parameter: #%d of type: %s is not available in the event: %s. Handler skiped...", method.toGenericString(), i, t.getName(), event)); return; } } ReflectionUtils.invokeMethod(method, bean, args.toArray()); }
From source file:org.crazydog.util.spring.ClassUtils.java
/** * Determine if the given type is assignable from the given value, * assuming setting by reflection. Considers primitive wrapper classes * as assignable to the corresponding primitive types. * @param type the target type/*from ww w . j av a 2s . com*/ * @param value the value that should be assigned to the type * @return if the type is assignable from the value */ public static boolean isAssignableValue(Class<?> type, Object value) { org.springframework.util.Assert.notNull(type, "Type must not be null"); return (value != null ? isAssignable(type, value.getClass()) : !type.isPrimitive()); }
From source file:com.bstek.dorado.data.type.EntityDataTypeSupport.java
protected void doCreatePropertyDefinitons() throws Exception { Class<?> type = getMatchType(); if (type == null) { type = getCreationType();//w w w . j a v a 2s . co m } if (type == null || type.isPrimitive() || type.isArray() || Map.class.isAssignableFrom(type)) { return; } PropertyDescriptor[] propertyDescriptors = PropertyUtils.getPropertyDescriptors(type); for (PropertyDescriptor propertyDescriptor : propertyDescriptors) { String name = propertyDescriptor.getName(); if (!BeanPropertyUtils.isValidProperty(type, name)) continue; PropertyDef propertyDef = getPropertyDef(name); DataType dataType = null; Class<?> propertyType = propertyDescriptor.getPropertyType(); if (Collection.class.isAssignableFrom(propertyType)) { ParameterizedType parameterizedType = (ParameterizedType) propertyDescriptor.getReadMethod() .getGenericReturnType(); if (parameterizedType != null) { dataType = DataUtils.getDataType(parameterizedType); } } if (dataType == null) { dataType = DataUtils.getDataType(propertyType); } if (propertyDef == null) { if (dataType != null) { propertyDef = new BasePropertyDef(name); propertyDef.setDataType(dataType); addPropertyDef(propertyDef); if (dataType instanceof EntityDataType || dataType instanceof AggregationDataType) { propertyDef.setIgnored(true); } } } else if (propertyDef.getDataType() == null) { if (dataType != null) propertyDef.setDataType(dataType); } } }
From source file:info.magnolia.jcr.node2bean.impl.TypeMappingImpl.java
/** * Resolves transformer from bean class or setter. *///ww w .j av a2s .c om private Node2BeanTransformer resolveTransformer(Class<?> beanClass, Method writeMethod) throws Node2BeanException { if (!beanClass.isArray() && !beanClass.isPrimitive()) { // don't bother looking for a transformer if the property is an array or a primitive type Class<Node2BeanTransformer> transformerClass = null; Node2BeanTransformer transformer = null; if (writeMethod != null) { TransformedBy transformerAnnotation = writeMethod.getAnnotation(TransformedBy.class); transformerClass = transformerAnnotation == null ? null : (Class<Node2BeanTransformer>) transformerAnnotation.value(); transformer = transformerClass == null ? null : Components.getComponentProvider().newInstance(transformerClass); } if (transformer == null) { try { transformerClass = (Class<Node2BeanTransformer>) Class .forName(beanClass.getName() + "Transformer"); transformer = Components.getComponent(transformerClass); } catch (ClassNotFoundException e) { log.debug("No transformer found for bean [{}]", beanClass); } } return transformer; } return null; }
From source file:mil.army.usace.data.dataquery.rdbms.implementations.OracleConverter.java
@Override public Object convertType(Object obj, Field field) throws ClassNotFoundException, ConversionException, SQLException { Class fieldParam = field.getType(); if (obj == null) return null; else if (obj instanceof oracle.sql.TIMESTAMPTZ) { java.sql.Date sqlDate = ((oracle.sql.TIMESTAMPTZ) obj).dateValue(oc); return ConversionUtility.convertType(sqlDate, fieldParam); } else {/*ww w . ja v a2 s.c om*/ if (fieldParam.isPrimitive()) { return obj; } else { return ConversionUtility.convertType(obj, fieldParam); } } }
From source file:com.jetyun.pgcd.rpc.serializer.impl.BeanSerializer.java
public boolean canSerialize(Class clazz, Class jsonClazz) { return (!clazz.isArray() && !clazz.isPrimitive() && !clazz.isInterface() && (jsonClazz == null || jsonClazz == JSONObject.class)); }
From source file:com.sinosoft.one.data.jade.rowmapper.DefaultRowMapperFactory.java
public RowMapper getRowMapper(StatementMetaData modifier) { RowHandler rowHandler = modifier.getAnnotation(RowHandler.class); if (rowHandler != null) { if (rowHandler.rowMapper() != RowHandler.ByDefault.class) { try { RowMapper rowMapper = rowHandler.rowMapper().newInstance(); if (logger.isInfoEnabled()) { logger.info("using rowMapper " + rowMapper + " for " + modifier); }//from w w w . j a v a 2 s.com return rowMapper; } catch (Exception ex) { throw new BeanInstantiationException(rowHandler.rowMapper(), ex.getMessage(), ex); } } } // Class<?> returnClassType = modifier.getMethod().getReturnType(); Class<?> rowType = getRowType(modifier); // BUGFIX: SingleColumnRowMapper ? Primitive Type if (rowType.isPrimitive()) { rowType = ClassUtils.primitiveToWrapper(rowType); } // ? RowMapper RowMapper rowMapper; // ?(?2Map) if (TypeUtils.isColumnType(rowType)) { if (returnClassType == Map.class) { rowMapper = new MapEntryColumnRowMapper(modifier, rowType); } else { rowMapper = new SingleColumnRowMapper(rowType); } } // Bean?????? else { if (rowType == Map.class) { rowMapper = new ColumnMapRowMapper(); } else if (rowType.isArray()) { rowMapper = new ArrayRowMapper(rowType); } else if ((rowType == List.class) || (rowType == Collection.class)) { rowMapper = new ListRowMapper(modifier); } else if (rowType == Set.class) { rowMapper = new SetRowMapper(modifier); } else { boolean checkColumns = (rowHandler == null) ? false : rowHandler.checkColumns(); boolean checkProperties = (rowHandler == null) ? false : rowHandler.checkProperties(); String key = rowType.getName() + "[checkColumns=" + checkColumns + "&checkProperties=" + checkProperties + "]"; rowMapper = rowMappers.get(key); if (rowMapper == null) { rowMapper = new BeanPropertyRowMapper(rowType, checkColumns, checkProperties); // jade's BeanPropertyRowMapper here rowMappers.put(key, rowMapper); } } // DAOMaprowMapper?Map.Entry if (returnClassType == Map.class) { rowMapper = new MapEntryRowMapper(modifier, rowMapper); } } if (logger.isInfoEnabled()) { logger.info("using rowMapper " + rowMapper + " for " + modifier); } return rowMapper; }
From source file:com.chinamobile.bcbsp.util.ObjectSizer.java
/** * Calculate the size of the object takes up space. * This object is an array or object./*from www .ja va 2s . c o m*/ * * @param object An object * @return The size of the object takes up space */ @SuppressWarnings("unchecked") private int calculate(Object object) { if (object == null) { return 0; } Ref r = new Ref(object); if (dedup.contains(r)) { return 0; } dedup.add(r); int varSize = 0; int objSize = 0; for (Class clazz = object.getClass(); clazz != Object.class; clazz = clazz.getSuperclass()) { if (clazz.isArray()) { varSize += emptyArrayVarSize; Class<?> componentType = clazz.getComponentType(); if (componentType.isPrimitive()) { varSize += lengthOfPrimitiveArray(object) * sizeofPrimitiveClass(componentType); return occupationSize(emptyObjectSize, varSize, 0); } Object[] array = (Object[]) object; varSize += nullReferenceSize * array.length; for (Object o : array) { objSize += calculate(o); } return occupationSize(emptyObjectSize, varSize, objSize); } Field[] fields = clazz.getDeclaredFields(); for (Field field : fields) { if (Modifier.isStatic(field.getModifiers())) { continue; } if (clazz != field.getDeclaringClass()) { continue; } Class<?> type = field.getType(); if (type.isPrimitive()) { varSize += sizeofPrimitiveClass(type); } else { varSize += nullReferenceSize; try { field.setAccessible(true); objSize += calculate(field.get(object)); } catch (Exception e) { LOG.error("[calculate]", e); objSize += occupyofConstructor(object, field); } } } } return occupationSize(emptyObjectSize, varSize, objSize); }