List of usage examples for java.lang Byte TYPE
Class TYPE
To view the source code for java.lang Byte TYPE.
Click Source Link
From source file:Main.java
/** * renderArray returns an array similar to a List. If the array type is an * object they are rendered with "render(object)" for each. If the array * type is a primitive each element is added directly to the string buffer * collecting the result.// w w w . java2 s . c o m * * @param o * @param objectClass * @return */ private static StringBuffer renderArray(Object o, Class<?> objectClass) { Class<?> componentType = objectClass.getComponentType(); StringBuffer sb = new StringBuffer(ARRAY_PREFIX); if (componentType.isPrimitive() == false) { Object[] oa = (Object[]) o; for (int i = 0; i < oa.length; i++) { if (i > 0) { sb.append(ELEMENT_SEPARATOR); } sb.append(render(oa[i])); } } else { if (Boolean.TYPE.equals(componentType)) { boolean[] ba = (boolean[]) o; for (int i = 0; i < ba.length; i++) { if (i > 0) { sb.append(ELEMENT_SEPARATOR); } sb.append(ba[i]); } } else if (Integer.TYPE.equals(componentType)) { int[] ia = (int[]) o; for (int i = 0; i < ia.length; i++) { if (i > 0) { sb.append(ELEMENT_SEPARATOR); } sb.append(ia[i]); } } else if (Long.TYPE.equals(componentType)) { long[] ia = (long[]) o; for (int i = 0; i < ia.length; i++) { if (i > 0) { sb.append(ELEMENT_SEPARATOR); } sb.append(ia[i]); } } else if (Double.TYPE.equals(componentType)) { double[] ia = (double[]) o; for (int i = 0; i < ia.length; i++) { if (i > 0) { sb.append(ELEMENT_SEPARATOR); } sb.append(ia[i]); } } else if (Float.TYPE.equals(componentType)) { float[] ia = (float[]) o; for (int i = 0; i < ia.length; i++) { if (i > 0) { sb.append(ELEMENT_SEPARATOR); } sb.append(ia[i]); } } else if (Character.TYPE.equals(componentType)) { char[] ia = (char[]) o; for (int i = 0; i < ia.length; i++) { if (i > 0) { sb.append(ELEMENT_SEPARATOR); } sb.append(ia[i]); } } else if (Short.TYPE.equals(componentType)) { short[] ia = (short[]) o; for (int i = 0; i < ia.length; i++) { if (i > 0) { sb.append(ELEMENT_SEPARATOR); } sb.append(ia[i]); } } else if (Byte.TYPE.equals(componentType)) { byte[] ia = (byte[]) o; for (int i = 0; i < ia.length; i++) { if (i > 0) { sb.append(ELEMENT_SEPARATOR); } sb.append(ia[i]); } } } sb.append(ARRAY_SUFFIX); return sb; }
From source file:org.kordamp.ezmorph.object.NumberMorpher.java
public Object morph(Object value) { if (value != null && type.isAssignableFrom(value.getClass())) { // no conversion needed return value; }/*from w ww . j ava 2 s. com*/ String str = String.valueOf(value).trim(); if (!type.isPrimitive() && (value == null || str.length() == 0 || "null".equalsIgnoreCase(str))) { // if empty string and class != primitive treat it like null return null; } if (isDecimalNumber(type)) { if (Float.class.isAssignableFrom(type) || Float.TYPE == type) { return morphToFloat(str); } else if (Double.class.isAssignableFrom(type) || Double.TYPE == type) { return morphToDouble(str); } else { return morphToBigDecimal(str); } } else { if (Byte.class.isAssignableFrom(type) || Byte.TYPE == type) { return morphToByte(str); } else if (Short.class.isAssignableFrom(type) || Short.TYPE == type) { return morphToShort(str); } else if (Integer.class.isAssignableFrom(type) || Integer.TYPE == type) { return morphToInteger(str); } else if (Long.class.isAssignableFrom(type) || Long.TYPE == type) { return morphToLong(str); } else { return morphToBigInteger(str); } } }
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); }/* ww w . ja v a 2 s .c o m*/ return nonePrimitiveTypeMap; }
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 ww w. jav a2 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:io.nuun.plugin.configuration.common.ConfigurationMembersInjector.java
@Override public void injectMembers(T instance) { NuunProperty injectConfigAnnotation = null; // The annotation is actual NuunProperty.class if (clonedAnno.annotationType() == NuunProperty.class) { injectConfigAnnotation = field.getAnnotation(NuunProperty.class); } else { // The annotation has the NuunProperty annotation on it we proxy it injectConfigAnnotation = AssertUtils.annotationProxyOf(NuunProperty.class, clonedAnno); }/* w w w . ja v a 2 s. c om*/ String configurationParameterName = injectConfigAnnotation.value(); // Pre verification // if (StringUtils.isEmpty(configurationParameterName)) { log.error("Value for annotation {} on field {} can not be null or empty.", clonedAnno.annotationType(), field.toGenericString()); throw new PluginException("Value for annotation %s on field %s can not be null or empty.", clonedAnno.annotationType(), field.toGenericString()); } if (!configuration.containsKey(configurationParameterName) && injectConfigAnnotation.mandatory()) { throw new PluginException("\"%s\" must be in one properties file for field %s.", configurationParameterName, field.toGenericString()); } try { this.field.setAccessible(true); Class<?> type = field.getType(); if (type == Integer.TYPE) { if (configuration.containsKey(configurationParameterName)) { field.setInt(instance, configuration.getInt(configurationParameterName)); } else { log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName); field.setInt(instance, injectConfigAnnotation.defaultIntValue()); } } else if (type == Integer.class) { if (configuration.containsKey(configurationParameterName)) { field.set(instance, new Integer(configuration.getInt(configurationParameterName))); } else { log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName); field.set(instance, new Integer(injectConfigAnnotation.defaultIntValue())); } } else if (type == Boolean.TYPE) { if (configuration.containsKey(configurationParameterName)) { field.setBoolean(instance, configuration.getBoolean(configurationParameterName)); } else { log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName); field.setBoolean(instance, injectConfigAnnotation.defaultBooleanValue()); } } else if (type == Boolean.class) { if (configuration.containsKey(configurationParameterName)) { field.set(instance, new Boolean(configuration.getBoolean(configurationParameterName))); } else { log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName); field.set(instance, new Boolean(injectConfigAnnotation.defaultBooleanValue())); } } else if (type == Short.TYPE) { if (configuration.containsKey(configurationParameterName)) { field.setShort(instance, configuration.getShort(configurationParameterName)); } else { log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName); field.setShort(instance, injectConfigAnnotation.defaultShortValue()); } } else if (type == Short.class) { if (configuration.containsKey(configurationParameterName)) { field.set(instance, new Short(configuration.getShort(configurationParameterName))); } else { log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName); field.set(instance, new Short(injectConfigAnnotation.defaultShortValue())); } } else if (type == Byte.TYPE) { if (configuration.containsKey(configurationParameterName)) { field.setByte(instance, configuration.getByte(configurationParameterName)); } else { log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName); field.setByte(instance, injectConfigAnnotation.defaultByteValue()); } } else if (type == Byte.class) { if (configuration.containsKey(configurationParameterName)) { field.set(instance, new Byte(configuration.getByte(configurationParameterName))); } else { log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName); field.set(instance, new Byte(injectConfigAnnotation.defaultByteValue())); } } else if (type == Long.TYPE) { if (configuration.containsKey(configurationParameterName)) { field.setLong(instance, configuration.getLong(configurationParameterName)); } else { log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName); field.setLong(instance, injectConfigAnnotation.defaultLongValue()); } } else if (type == Long.class) { if (configuration.containsKey(configurationParameterName)) { field.set(instance, new Long(configuration.getLong(configurationParameterName))); } else { log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName); field.set(instance, new Long(injectConfigAnnotation.defaultLongValue())); } } else if (type == Float.TYPE) { if (configuration.containsKey(configurationParameterName)) { field.setFloat(instance, configuration.getFloat(configurationParameterName)); } else { log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName); field.setFloat(instance, injectConfigAnnotation.defaultFloatValue()); } } else if (type == Float.class) { if (configuration.containsKey(configurationParameterName)) { field.set(instance, new Float(configuration.getFloat(configurationParameterName))); } else { log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName); field.set(instance, new Float(injectConfigAnnotation.defaultFloatValue())); } } else if (type == Double.TYPE) { if (configuration.containsKey(configurationParameterName)) { field.setDouble(instance, configuration.getDouble(configurationParameterName)); } else { log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName); field.setDouble(instance, injectConfigAnnotation.defaultDoubleValue()); } } else if (type == Double.class) { if (configuration.containsKey(configurationParameterName)) { field.set(instance, new Double(configuration.getDouble(configurationParameterName))); } else { log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName); field.set(instance, new Double(injectConfigAnnotation.defaultDoubleValue())); } } else if (type == Character.TYPE) { if (configuration.containsKey(configurationParameterName)) { field.setChar(instance, configuration.getString(configurationParameterName).charAt(0)); } } else if (type == Character.class) { if (configuration.containsKey(configurationParameterName)) { field.set(instance, new Character(configuration.getString(configurationParameterName).charAt(0))); } } else { Object property = getProperty(configurationParameterName, injectConfigAnnotation); field.set(instance, property); } } catch (IllegalArgumentException ex) { log.error("Wrong argument or argument type during configuration injection", ex); } catch (IllegalAccessException ex) { log.error("Illegal access during configuration injection", ex); } catch (InstantiationException ex) { log.error("Impossible to instantiate value converter", ex); } finally { this.field.setAccessible(false); } }
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 . java 2 s . com*/ return n != null ? n.doubleValue() : Na.BOXED_DOUBLE; }); return doubleResolver; }
From source file:org.cocoa4android.util.sbjson.SBJsonWriter.java
/** * /*from w w w . j a v a2s. c o m*/ * @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))); }
From source file:com.link_intersystems.lang.Conversions.java
/** * short to byte or char/* www. ja va 2 s . co m*/ */ private static boolean isPrimitiveShortNarrowing(Class<?> to) { boolean isNarrowing = false; isNarrowing |= isIdentity(to, Byte.TYPE); isNarrowing |= isIdentity(to, Character.TYPE); return isNarrowing; }
From source file:com.nfwork.dbfound.json.JSONDynaBean.java
protected boolean isDynaAssignable(Class dest, Class src) { boolean assignable = dest.isAssignableFrom(src); assignable = (dest == Boolean.TYPE && src == Boolean.class) ? true : assignable; assignable = (dest == Byte.TYPE && src == Byte.class) ? true : assignable; assignable = (dest == Character.TYPE && src == Character.class) ? true : assignable; assignable = (dest == Short.TYPE && src == Short.class) ? true : assignable; assignable = (dest == Integer.TYPE && src == Integer.class) ? true : assignable; assignable = (dest == Long.TYPE && src == Long.class) ? true : assignable; assignable = (dest == Float.TYPE && src == Float.class) ? true : assignable; assignable = (dest == Double.TYPE && src == Double.class) ? true : assignable; if (src == Double.TYPE || Double.class.isAssignableFrom(src)) { assignable = (isByte(dest) || isShort(dest) || isInteger(dest) || isLong(dest) || isFloat(dest)) ? true : assignable;/* w ww . j av a2s . c o m*/ } if (src == Float.TYPE || Float.class.isAssignableFrom(src)) { assignable = (isByte(dest) || isShort(dest) || isInteger(dest) || isLong(dest)) ? true : assignable; } if (src == Long.TYPE || Long.class.isAssignableFrom(src)) { assignable = (isByte(dest) || isShort(dest) || isInteger(dest)) ? true : assignable; } if (src == Integer.TYPE || Integer.class.isAssignableFrom(src)) { assignable = (isByte(dest) || isShort(dest)) ? true : assignable; } if (src == Short.TYPE || Short.class.isAssignableFrom(src)) { assignable = (isByte(dest)) ? true : assignable; } return assignable; }
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(); }//www .j av a 2 s . c om 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()); } }