List of usage examples for java.lang Short TYPE
Class TYPE
To view the source code for java.lang Short TYPE.
Click Source Link
From source file:org.kuali.kfs.sys.context.DocumentSerializabilityTest.java
/** * Determines if the given class represents one of the eight Java primitives * @param clazz the class to check/*from w w w.j av a 2 s .c o m*/ * @return true if the class represents a byte, short, int, long, char, double, float, or boolean; false otherwise */ protected boolean isPrimitive(Class<?> clazz) { return Byte.TYPE.isAssignableFrom(clazz) || Short.TYPE.isAssignableFrom(clazz) || Integer.TYPE.isAssignableFrom(clazz) || Long.TYPE.isAssignableFrom(clazz) || Float.TYPE.isAssignableFrom(clazz) || Double.TYPE.isAssignableFrom(clazz) || Character.TYPE.isAssignableFrom(clazz) || Boolean.TYPE.isAssignableFrom(clazz); }
From source file:org.briljantframework.data.resolver.Resolve.java
private static Resolver<Double> initializeDoubleResolver() { Resolver<Double> doubleResolver = new Resolver<>(Double.class); doubleResolver.put(Number.class, Number::doubleValue); doubleResolver.put(Double.class, Number::doubleValue); doubleResolver.put(Double.TYPE, Number::doubleValue); doubleResolver.put(Float.class, Number::doubleValue); doubleResolver.put(Float.TYPE, Number::doubleValue); doubleResolver.put(Long.class, Number::doubleValue); doubleResolver.put(Long.TYPE, Number::doubleValue); doubleResolver.put(Integer.class, Number::doubleValue); doubleResolver.put(Integer.TYPE, Number::doubleValue); doubleResolver.put(Short.class, Number::doubleValue); doubleResolver.put(Short.TYPE, Number::doubleValue); doubleResolver.put(Byte.class, Number::doubleValue); doubleResolver.put(Byte.TYPE, Number::doubleValue); doubleResolver.put(String.class, s -> { Number n = toNumber(s);/* w w w. j a v a2 s . c o m*/ return n != null ? n.doubleValue() : Na.BOXED_DOUBLE; }); return doubleResolver; }
From source file:com.nonninz.robomodel.RoboModel.java
private void loadField(Field field, Cursor query) throws DatabaseNotUpToDateException { final Class<?> type = field.getType(); final boolean wasAccessible = field.isAccessible(); final int columnIndex = query.getColumnIndex(field.getName()); field.setAccessible(true);/* www .ja v a 2 s. c o m*/ /* * TODO: There is the potential of a problem here: * What happens if the developer changes the type of a field between releases? * * If he saves first, then the column type will be changed (In the future). * If he loads first, we don't know if an Exception will be thrown if the * types are incompatible, because it's undocumented in the Cursor documentation. */ try { if (type == String.class) { field.set(this, query.getString(columnIndex)); } else if (type == Boolean.TYPE) { final boolean value = query.getInt(columnIndex) == 1 ? true : false; field.setBoolean(this, value); } else if (type == Byte.TYPE) { field.setByte(this, (byte) query.getShort(columnIndex)); } else if (type == Double.TYPE) { field.setDouble(this, query.getDouble(columnIndex)); } else if (type == Float.TYPE) { field.setFloat(this, query.getFloat(columnIndex)); } else if (type == Integer.TYPE) { field.setInt(this, query.getInt(columnIndex)); } else if (type == Long.TYPE) { field.setLong(this, query.getLong(columnIndex)); } else if (type == Short.TYPE) { field.setShort(this, query.getShort(columnIndex)); } else if (type.isEnum()) { final String string = query.getString(columnIndex); if (string != null && string.length() > 0) { final Object[] constants = type.getEnumConstants(); final Method method = type.getMethod("valueOf", Class.class, String.class); final Object value = method.invoke(constants[0], type, string); field.set(this, value); } } else { // Try to de-json it (db column must be of type text) try { final Object value = mMapper.readValue(query.getString(columnIndex), field.getType()); field.set(this, value); } catch (final Exception e) { final String msg = String.format("Type %s is not supported for field %s", type, field.getName()); Ln.w(e, msg); throw new IllegalArgumentException(msg); } } } catch (final IllegalAccessException e) { final String msg = String.format("Field %s is not accessible", type, field.getName()); throw new IllegalArgumentException(msg); } catch (final NoSuchMethodException e) { // Should not happen throw new RuntimeException(e); } catch (final InvocationTargetException e) { // Should not happen throw new RuntimeException(e); } catch (IllegalStateException e) { // This is when there is no column in db, but there is in the model throw new DatabaseNotUpToDateException(e); } finally { field.setAccessible(wasAccessible); } }
From source file:com.cyclopsgroup.waterview.utils.TypeUtils.java
private static Map getNonePrimitiveTypeMap() { if (nonePrimitiveTypeMap == null) { nonePrimitiveTypeMap = new Hashtable(); nonePrimitiveTypeMap.put(Boolean.TYPE, Boolean.class); nonePrimitiveTypeMap.put(Byte.TYPE, Byte.class); nonePrimitiveTypeMap.put(Character.TYPE, Character.class); nonePrimitiveTypeMap.put(Short.TYPE, Short.class); nonePrimitiveTypeMap.put(Integer.TYPE, Integer.class); nonePrimitiveTypeMap.put(Long.TYPE, Long.class); nonePrimitiveTypeMap.put(Float.TYPE, Float.class); nonePrimitiveTypeMap.put(Double.TYPE, Double.class); }/* w w w . ja v a 2s . com*/ return nonePrimitiveTypeMap; }
From source file:org.seedstack.seed.core.internal.application.ConfigurationMembersInjector.java
@SuppressWarnings("unchecked") private void writeArrayField(T instance) { ConfigurationConverter<?> converter; Class<?> componentType = field.getType().getComponentType(); converter = findConverter(instance, componentType); String[] values = configuration.getStringArray(annotation.value()); if ((values == null || values.length == 0) && annotation.defaultValue().length > 0) { values = annotation.defaultValue(); }//from w w w . j av a 2 s . c o m if (values != null && values.length > 0) { if (componentType.isPrimitive()) { if (componentType == Short.TYPE) { writeField(instance, convertToShortValues(values, (ConfigurationConverter<Short>) converter)); } if (componentType == Integer.TYPE) { writeField(instance, convertToIntegerValues(values, (ConfigurationConverter<Integer>) converter)); } if (componentType == Boolean.TYPE) { writeField(instance, convertToBooleanValues(values, (ConfigurationConverter<Boolean>) converter)); } if (componentType == Byte.TYPE) { writeField(instance, convertToByteValues(values, (ConfigurationConverter<Byte>) converter)); } if (componentType == Long.TYPE) { writeField(instance, convertToLongValues(values, (ConfigurationConverter<Long>) converter)); } if (componentType == Float.TYPE) { writeField(instance, convertToFloatValues(values, (ConfigurationConverter<Float>) converter)); } if (componentType == Double.TYPE) { writeField(instance, convertToDoubleValues(values, (ConfigurationConverter<Double>) converter)); } if (componentType == Character.TYPE) { writeField(instance, convertToCharacterValues(values, (ConfigurationConverter<Character>) converter)); } } else { Object[] convertedValues; try { convertedValues = (Object[]) Array.newInstance(field.getType().getComponentType(), values.length); } catch (Exception e) { throw SeedException.wrap(e, ApplicationErrorCode.UNABLE_TO_INSTANTIATE_CONFIGURATION_ARRAY); } for (int i = 0; i < values.length; i++) { convertedValues[i] = converter.convert(values[i]); } writeField(instance, convertedValues); } } else { LOGGER.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, annotation.value()); } }
From source file:org.cloudata.core.common.io.CObjectWritable.java
/** Write a {@link CWritable}, {@link String}, primitive type, or an array of * the preceding. *//* ww w . ja v a 2s . c o m*/ public static void writeObject(DataOutput out, Object instance, Class declaredClass, CloudataConf conf, boolean arrayComponent) throws IOException { if (instance == null) { // null instance = new NullInstance(declaredClass, conf); declaredClass = CWritable.class; arrayComponent = false; } if (!arrayComponent) { CUTF8.writeString(out, declaredClass.getName()); // always write declared //System.out.println("Write:declaredClass.getName():" + declaredClass.getName()); } if (declaredClass.isArray()) { // array int length = Array.getLength(instance); out.writeInt(length); //System.out.println("Write:length:" + length); if (declaredClass.getComponentType() == Byte.TYPE) { out.write((byte[]) instance); } else if (declaredClass.getComponentType() == ColumnValue.class) { //ColumnValue? Deserialize? ?? ? ?? ? . writeColumnValue(out, instance, declaredClass, conf, length); } else { for (int i = 0; i < length; i++) { writeObject(out, Array.get(instance, i), declaredClass.getComponentType(), conf, !declaredClass.getComponentType().isArray()); } } } else if (declaredClass == String.class) { // String CUTF8.writeString(out, (String) instance); } else if (declaredClass.isPrimitive()) { // primitive type if (declaredClass == Boolean.TYPE) { // boolean out.writeBoolean(((Boolean) instance).booleanValue()); } else if (declaredClass == Character.TYPE) { // char out.writeChar(((Character) instance).charValue()); } else if (declaredClass == Byte.TYPE) { // byte out.writeByte(((Byte) instance).byteValue()); } else if (declaredClass == Short.TYPE) { // short out.writeShort(((Short) instance).shortValue()); } else if (declaredClass == Integer.TYPE) { // int out.writeInt(((Integer) instance).intValue()); } else if (declaredClass == Long.TYPE) { // long out.writeLong(((Long) instance).longValue()); } else if (declaredClass == Float.TYPE) { // float out.writeFloat(((Float) instance).floatValue()); } else if (declaredClass == Double.TYPE) { // double out.writeDouble(((Double) instance).doubleValue()); } else if (declaredClass == Void.TYPE) { // void } else { throw new IllegalArgumentException("Not a primitive: " + declaredClass); } } else if (declaredClass.isEnum()) { // enum CUTF8.writeString(out, ((Enum) instance).name()); } else if (CWritable.class.isAssignableFrom(declaredClass)) { // Writable if (instance.getClass() == declaredClass) { out.writeShort(TYPE_SAME); // ? ?? ? ?? //System.out.println("Write:TYPE_SAME:" + TYPE_SAME); } else { out.writeShort(TYPE_DIFF); //System.out.println("Write:TYPE_DIFF:" + TYPE_DIFF); CUTF8.writeString(out, instance.getClass().getName()); //System.out.println("Write:instance.getClass().getName():" + instance.getClass().getName()); } ((CWritable) instance).write(out); //System.out.println("Write:instance value"); } else { throw new IOException("Can't write: " + instance + " as " + declaredClass); } }
From source file:org.openflexo.antar.binding.TypeUtils.java
public static boolean isShort(Type type) { if (type == null) { return false; }/* www . jav a 2 s . co m*/ return type.equals(Short.class) || type.equals(Short.TYPE); }
From source file:org.apache.sling.models.impl.model.AbstractInjectableElement.java
private static Object getDefaultValue(AnnotatedElement element, Type type, InjectAnnotationProcessor2 annotationProcessor) { if (annotationProcessor != null && annotationProcessor.hasDefault()) { return annotationProcessor.getDefault(); }//from ww w .j a va2 s.c o m Default defaultAnnotation = element.getAnnotation(Default.class); if (defaultAnnotation == null) { return null; } Object value = null; if (type instanceof Class) { Class<?> injectedClass = (Class<?>) type; if (injectedClass.isArray()) { Class<?> componentType = injectedClass.getComponentType(); if (componentType == String.class) { value = defaultAnnotation.values(); } else if (componentType == Integer.TYPE) { value = defaultAnnotation.intValues(); } else if (componentType == Integer.class) { value = ArrayUtils.toObject(defaultAnnotation.intValues()); } else if (componentType == Long.TYPE) { value = defaultAnnotation.longValues(); } else if (componentType == Long.class) { value = ArrayUtils.toObject(defaultAnnotation.longValues()); } else if (componentType == Boolean.TYPE) { value = defaultAnnotation.booleanValues(); } else if (componentType == Boolean.class) { value = ArrayUtils.toObject(defaultAnnotation.booleanValues()); } else if (componentType == Short.TYPE) { value = defaultAnnotation.shortValues(); } else if (componentType == Short.class) { value = ArrayUtils.toObject(defaultAnnotation.shortValues()); } else if (componentType == Float.TYPE) { value = defaultAnnotation.floatValues(); } else if (componentType == Float.class) { value = ArrayUtils.toObject(defaultAnnotation.floatValues()); } else if (componentType == Double.TYPE) { value = defaultAnnotation.doubleValues(); } else if (componentType == Double.class) { value = ArrayUtils.toObject(defaultAnnotation.doubleValues()); } else { log.warn("Default values for {} are not supported", componentType); } } else { if (injectedClass == String.class) { value = defaultAnnotation.values().length == 0 ? "" : defaultAnnotation.values()[0]; } else if (injectedClass == Integer.class) { value = defaultAnnotation.intValues().length == 0 ? 0 : defaultAnnotation.intValues()[0]; } else if (injectedClass == Long.class) { value = defaultAnnotation.longValues().length == 0 ? 0l : defaultAnnotation.longValues()[0]; } else if (injectedClass == Boolean.class) { value = defaultAnnotation.booleanValues().length == 0 ? false : defaultAnnotation.booleanValues()[0]; } else if (injectedClass == Short.class) { value = defaultAnnotation.shortValues().length == 0 ? ((short) 0) : defaultAnnotation.shortValues()[0]; } else if (injectedClass == Float.class) { value = defaultAnnotation.floatValues().length == 0 ? 0f : defaultAnnotation.floatValues()[0]; } else if (injectedClass == Double.class) { value = defaultAnnotation.doubleValues().length == 0 ? 0d : defaultAnnotation.doubleValues()[0]; } else { log.warn("Default values for {} are not supported", injectedClass); } } } else { log.warn("Cannot provide default for {}", type); } return value; }
From source file:com.adobe.acs.commons.mcp.util.AnnotatedFieldDeserializer.java
@SuppressWarnings("squid:S3776") private static Object convertPrimitiveValue(String value, Class<?> type) throws ParseException { if (type.equals(Boolean.class) || type.equals(Boolean.TYPE)) { return value.toLowerCase().trim().equals("true"); } else {// w w w .j a v a2s. c o m NumberFormat numberFormat = NumberFormat.getNumberInstance(); Number num = numberFormat.parse(value); if (type.equals(Byte.class) || type.equals(Byte.TYPE)) { return num.byteValue(); } else if (type.equals(Double.class) || type.equals(Double.TYPE)) { return num.doubleValue(); } else if (type.equals(Float.class) || type.equals(Float.TYPE)) { return num.floatValue(); } else if (type.equals(Integer.class) || type.equals(Integer.TYPE)) { return num.intValue(); } else if (type.equals(Long.class) || type.equals(Long.TYPE)) { return num.longValue(); } else if (type.equals(Short.class) || type.equals(Short.TYPE)) { return num.shortValue(); } else { return null; } } }
From source file:org.cocoa4android.util.sbjson.SBJsonWriter.java
/** * // w w w .ja v a 2 s.com * @param clazz * @return */ public static boolean isNumber(Class<?> clazz) { return (clazz != null) && ((Byte.TYPE.isAssignableFrom(clazz)) || (Short.TYPE.isAssignableFrom(clazz)) || (Integer.TYPE.isAssignableFrom(clazz)) || (Long.TYPE.isAssignableFrom(clazz)) || (Float.TYPE.isAssignableFrom(clazz)) || (Double.TYPE.isAssignableFrom(clazz)) || (Number.class.isAssignableFrom(clazz))); }