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:net.sf.jrf.domain.PersistentObjectDynaProperty.java
/** Constructs instance and property name and class. * @param name property name./* w ww . j ava 2 s .c o m*/ * @param cls value object <code>Class</code>. * @param readMethodName name of the read <code>Method</code> * @param writeMethodName name of the write <code>Method</code> */ public PersistentObjectDynaProperty(String name, Class cls, String readMethodName, String writeMethodName) { super(name, cls); this.readMethodName = readMethodName; this.writeMethodName = writeMethodName; if (cls.isPrimitive()) { if (cls.equals(Boolean.TYPE)) primitiveWrapperClass = Boolean.class; else if (cls.equals(Byte.TYPE)) primitiveWrapperClass = Byte.class; else if (cls.equals(Character.TYPE)) primitiveWrapperClass = Character.class; else if (cls.equals(Double.TYPE)) primitiveWrapperClass = Double.class; else if (cls.equals(Float.TYPE)) primitiveWrapperClass = Float.class; else if (cls.equals(Integer.TYPE)) primitiveWrapperClass = Integer.class; else if (cls.equals(Long.TYPE)) primitiveWrapperClass = Long.class; else if (cls.equals(Short.TYPE)) primitiveWrapperClass = Short.class; } else if (java.util.List.class.isAssignableFrom(cls) || cls.isArray()) { indexed = true; } else if (java.util.Map.class.isAssignableFrom(cls)) { mapped = true; } }
From source file:candr.yoclip.option.OptionSetter.java
@Override public void setOption(final T bean, final String value) { final Class<?> setterParameterType = getType(); try {/*from w ww .ja v a 2 s. c o m*/ if (Boolean.TYPE.equals(setterParameterType) || Boolean.class.isAssignableFrom(setterParameterType)) { setBooleanOption(bean, value); } else if (Byte.TYPE.equals(setterParameterType) || Byte.class.isAssignableFrom(setterParameterType)) { setByteOption(bean, value); } else if (Short.TYPE.equals(setterParameterType) || Short.class.isAssignableFrom(setterParameterType)) { setShortOption(bean, value); } else if (Integer.TYPE.equals(setterParameterType) || Integer.class.isAssignableFrom(setterParameterType)) { setIntegerOption(bean, value); } else if (Long.TYPE.equals(setterParameterType) || Long.class.isAssignableFrom(setterParameterType)) { setLongOption(bean, value); } else if (Character.TYPE.equals(setterParameterType) || Character.class.isAssignableFrom(setterParameterType)) { setCharacterOption(bean, value); } else if (Float.TYPE.equals(setterParameterType) || Float.class.isAssignableFrom(setterParameterType)) { setFloatOption(bean, value); } else if (Double.TYPE.equals(setterParameterType) || Double.class.isAssignableFrom(setterParameterType)) { setDoubleOption(bean, value); } else if (String.class.isAssignableFrom(setterParameterType)) { setStringOption(bean, value); } else { final String supportedTypes = "boolean, byte, short, int, long, char, float, double, and String"; throw new OptionsParseException( String.format("OptionParameter only supports %s types", supportedTypes)); } } catch (NumberFormatException e) { final String error = String.format("Error converting '%s' to %s", value, setterParameterType); throw new OptionsParseException(error, e); } }
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.//from ww w . j a va 2s .c om * * @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.evosuite.regression.ObjectFields.java
private static Object getFieldValue(Field field, Object p) { try {// w w w.j a v a 2s . co m /*Class objClass = p.getClass(); if(p instanceof java.lang.String){ ((String) p).hashCode(); }*/ Class<?> fieldType = field.getType(); field.setAccessible(true); if (fieldType.isPrimitive()) { if (fieldType.equals(Boolean.TYPE)) { return field.getBoolean(p); } if (fieldType.equals(Integer.TYPE)) { return field.getInt(p); } if (fieldType.equals(Byte.TYPE)) { return field.getByte(p); } if (fieldType.equals(Short.TYPE)) { return field.getShort(p); } if (fieldType.equals(Long.TYPE)) { return field.getLong(p); } if (fieldType.equals(Double.TYPE)) { return field.getDouble(p); } if (fieldType.equals(Float.TYPE)) { return field.getFloat(p); } if (fieldType.equals(Character.TYPE)) { return field.getChar(p); } throw new UnsupportedOperationException("Primitive type " + fieldType + " not implemented!"); } return field.get(p); } catch (IllegalAccessException exc) { throw new RuntimeException(exc); } catch (OutOfMemoryError e) { e.printStackTrace(); if (MAX_RECURSION != 0) MAX_RECURSION = 0; else throw new RuntimeErrorException(e); return getFieldValue(field, p); } }
From source file:candr.yoclip.option.OptionField.java
@Override public void setOption(final T bean, final String value) { final Class<?> fieldType = getField().getType(); try {/* w w w . j av a2 s.c o m*/ if (Boolean.TYPE.equals(fieldType) || Boolean.class.isAssignableFrom(fieldType)) { setBooleanOption(bean, value); } else if (Byte.TYPE.equals(fieldType) || Byte.class.isAssignableFrom(fieldType)) { setByteOption(bean, value); } else if (Short.TYPE.equals(fieldType) || Short.class.isAssignableFrom(fieldType)) { setShortOption(bean, value); } else if (Integer.TYPE.equals(fieldType) || Integer.class.isAssignableFrom(fieldType)) { setIntegerOption(bean, value); } else if (Long.TYPE.equals(fieldType) || Long.class.isAssignableFrom(fieldType)) { setLongOption(bean, value); } else if (Character.TYPE.equals(fieldType) || Character.class.isAssignableFrom(fieldType)) { setCharacterOption(bean, value); } else if (Float.TYPE.equals(fieldType) || Float.class.isAssignableFrom(fieldType)) { setFloatOption(bean, value); } else if (Double.TYPE.equals(fieldType) || Double.class.isAssignableFrom(fieldType)) { setDoubleOption(bean, value); } else if (String.class.isAssignableFrom(fieldType)) { setStringOption(bean, value); } else { final String supportedTypes = "boolean, byte, short, int, long, char, float, double, and String"; throw new OptionsParseException( String.format("OldOptionsParser only support %s types", supportedTypes)); } } catch (NumberFormatException e) { final String error = String.format("Error converting '%s' to %s", value, fieldType); throw new OptionsParseException(error, e); } }
From source file:jef.tools.ArrayUtils.java
/** * ?/*w w w. j av a2s. c o m*/ * * @param obj * @return */ public static Object[] toObject(Object obj) { Class<?> c = obj.getClass(); Assert.isTrue(c.isArray()); Class<?> priType = c.getComponentType(); if (!priType.isPrimitive()) return (Object[]) obj; if (priType == Boolean.TYPE) { return toObject((boolean[]) obj); } else if (priType == Byte.TYPE) { return toObject((byte[]) obj); } else if (priType == Character.TYPE) { return toObject((char[]) obj); } else if (priType == Integer.TYPE) { return toObject((int[]) obj); } else if (priType == Long.TYPE) { return toObject((long[]) obj); } else if (priType == Float.TYPE) { return toObject((float[]) obj); } else if (priType == Double.TYPE) { return toObject((double[]) obj); } else if (priType == Short.TYPE) { return toObject((short[]) obj); } throw new IllegalArgumentException(); }
From source file:org.onebusaway.gtfs_transformer.deferred.DeferredValueConverter.java
private boolean isPrimitiveAssignable(Class<?> expectedValueType, Class<?> actualValueType) { if (!expectedValueType.isPrimitive()) { return false; }/*from w w w. j av a 2 s . c om*/ return expectedValueType == Double.TYPE && (actualValueType == Double.class || actualValueType == Float.class) || expectedValueType == Long.TYPE && (actualValueType == Long.class || actualValueType == Integer.class || actualValueType == Short.class) || expectedValueType == Integer.TYPE && (actualValueType == Integer.class || actualValueType == Short.class) || expectedValueType == Short.TYPE && (actualValueType == Short.class) || expectedValueType == Boolean.TYPE && (actualValueType == Boolean.class); }
From source file:com.link_intersystems.lang.Conversions.java
/** * <em>java language specification - 5.1.3 Narrowing Primitive Conversions</em> * ./*ww w. jav a 2 s. c o m*/ * * <code> * <blockquote>The following 22 specific conversions on primitive types * are called the narrowing primitive conversions: * <ul> * <li>short to byte or char</li> * <li>char to byte or short</li> * <li>int to byte, short, or char</li> * <li>long to byte, short, char, or int</li> * <li>float to byte, short, char, int, or long</li> * <li>double to byte, short, char, int, long, or float </li> * </blockquote> * </code> * * @param from * the base type * @param to * the widening type * @return true if from to to is a primitive widening. * @since 1.0.0.0 */ public static boolean isPrimitiveNarrowing(Class<?> from, Class<?> to) { Assert.isTrue(Primitives.isPrimitive(from), "mustBeAPrimitive", "form"); Assert.isTrue(Primitives.isPrimitive(to), "mustBeAPrimitive", "to"); boolean isPrimitiveNarrowing = false; if (isIdentity(from, Double.TYPE)) { isPrimitiveNarrowing = isPrimitiveDoubleNarrowing(to); } else if (isIdentity(from, Short.TYPE)) { isPrimitiveNarrowing = isPrimitiveShortNarrowing(to); } else if (isIdentity(from, Character.TYPE)) { isPrimitiveNarrowing = isPrimitiveCharacterNarrowing(to); } else if (isIdentity(from, Integer.TYPE)) { isPrimitiveNarrowing = isPrimitiveIntegerNarrowing(to); } else if (isIdentity(from, Long.TYPE)) { isPrimitiveNarrowing = isPrimitiveLongNarrowing(to); } else if (isIdentity(from, Float.TYPE)) { isPrimitiveNarrowing = isPrimitiveFloatNarrowing(to); } /* * must be a byte */ return isPrimitiveNarrowing; }
From source file:org.projectforge.continuousdb.TableAttribute.java
/** * Creates a property and gets the information from the entity class. The JPA annotations Column, JoinColumn, Entity, * Table and ID are supported.// www. jav a 2 s .co m * * @param clazz * @param property */ public TableAttribute(final Class<?> clazz, final String property) { final Method getterMethod = BeanHelper.determineGetter(clazz, property, false); if (getterMethod == null) { throw new IllegalStateException("Can't determine getter: " + clazz + "." + property); } this.entityClass = clazz; this.property = property; this.name = property; this.propertyType = BeanHelper.determinePropertyType(getterMethod); // final boolean typePropertyPresent = false; // final String typePropertyValue = null; for (final TableAttributeHook hook : hooks) { this.type = hook.determineType(getterMethod); if (this.type != null) { break; } } final boolean primitive = this.propertyType.isPrimitive(); if (JPAHelper.isPersistenceAnnotationPresent(getterMethod) == false) { log.warn( "************** ProjectForge schema updater expect JPA annotations at getter method such as @Column for proper functioning!"); } if (this.type != null) { // Type is already determined. } else if (Boolean.class.isAssignableFrom(this.propertyType) == true || Boolean.TYPE.isAssignableFrom(this.propertyType) == true) { this.type = TableAttributeType.BOOLEAN; } else if (Integer.class.isAssignableFrom(this.propertyType) == true || Integer.TYPE.isAssignableFrom(this.propertyType) == true) { this.type = TableAttributeType.INT; } else if (Long.class.isAssignableFrom(this.propertyType) == true || Long.TYPE.isAssignableFrom(this.propertyType) == true) { this.type = TableAttributeType.LONG; } else if (Short.class.isAssignableFrom(this.propertyType) == true || Short.TYPE.isAssignableFrom(this.propertyType) == true) { this.type = TableAttributeType.SHORT; } else if (String.class.isAssignableFrom(this.propertyType) == true || this.propertyType.isEnum() == true) { this.type = TableAttributeType.VARCHAR; } else if (BigDecimal.class.isAssignableFrom(this.propertyType) == true) { this.type = TableAttributeType.DECIMAL; } else if (java.sql.Date.class.isAssignableFrom(this.propertyType) == true) { this.type = TableAttributeType.DATE; } else if (java.util.Date.class.isAssignableFrom(this.propertyType) == true) { this.type = TableAttributeType.TIMESTAMP; } else if (java.util.Locale.class.isAssignableFrom(this.propertyType) == true) { this.type = TableAttributeType.LOCALE; } else if (java.util.List.class.isAssignableFrom(this.propertyType) == true) { this.type = TableAttributeType.LIST; this.setGenericReturnType(getterMethod); } else if (java.util.Set.class.isAssignableFrom(this.propertyType) == true) { this.type = TableAttributeType.SET; this.setGenericReturnType(getterMethod); // } else if (typePropertyPresent == true && "binary".equals(typePropertyValue) == true) { // type = TableAttributeType.BINARY; } else { final Entity entity = this.propertyType.getAnnotation(Entity.class); if (entity != null) { final javax.persistence.Table table = this.propertyType .getAnnotation(javax.persistence.Table.class); if (table != null) { this.foreignTable = table.name(); } else { this.foreignTable = new Table(this.propertyType).getName(); } // if (entity != null && table != null && StringUtils.isNotEmpty(table.name()) == true) { final String idProperty = JPAHelper.getIdProperty(this.propertyType); if (idProperty == null) { log.info("Id property not found for class '" + this.propertyType + "'): " + clazz + "." + property); } this.foreignAttribute = idProperty; final Column column = JPAHelper.getColumnAnnotation(this.propertyType, idProperty); if (column != null && StringUtils.isNotEmpty(column.name()) == true) { this.foreignAttribute = column.name(); } } else { log.info("Unsupported property (@Entity expected for the destination class '" + this.propertyType + "'): " + clazz + "." + property); } this.type = TableAttributeType.INT; } this.annotations = JPAHelper.getPersistenceAnnotations(getterMethod); final Id id = JPAHelper.getIdAnnotation(clazz, property); if (id != null) { this.primaryKey = true; this.nullable = false; } if (primitive == true) { this.nullable = false; } final Column column = JPAHelper.getColumnAnnotation(clazz, property); if (column != null) { if (this.isPrimaryKey() == false && primitive == false) { this.nullable = column.nullable(); } if (StringUtils.isNotEmpty(column.name()) == true) { this.name = column.name(); } if (this.type.isIn(TableAttributeType.VARCHAR, TableAttributeType.CHAR) == true) { this.length = column.length(); } if (this.type == TableAttributeType.DECIMAL) { this.precision = column.precision(); this.scale = column.scale(); } this.unique = column.unique(); } if (this.type == TableAttributeType.DECIMAL && this.scale == 0 && this.precision == 0) { throw new UnsupportedOperationException( "Decimal values should have a precision and scale definition: " + clazz + "." + property); } final JoinColumn joinColumn = JPAHelper.getJoinColumnAnnotation(clazz, property); if (joinColumn != null) { if (StringUtils.isNotEmpty(joinColumn.name()) == true) { this.name = joinColumn.name(); } if (joinColumn.nullable() == false) { this.nullable = false; } } }
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; }//w w w . j a v a 2s. co m 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); } } }