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.enerj.apache.commons.beanutils.locale.LocaleConvertUtilsBean.java
/** * Create all {@link LocaleConverter} types for specified locale. * * @param locale The Locale//w w w .j a v a 2s . c o m * @return The FastHashMap instance contains the all {@link LocaleConverter} types * for the specified locale. */ protected FastHashMap create(Locale locale) { FastHashMap converter = new FastHashMap(); converter.setFast(false); converter.put(BigDecimal.class, new BigDecimalLocaleConverter(locale, applyLocalized)); converter.put(BigInteger.class, new BigIntegerLocaleConverter(locale, applyLocalized)); converter.put(Byte.class, new ByteLocaleConverter(locale, applyLocalized)); converter.put(Byte.TYPE, new ByteLocaleConverter(locale, applyLocalized)); converter.put(Double.class, new DoubleLocaleConverter(locale, applyLocalized)); converter.put(Double.TYPE, new DoubleLocaleConverter(locale, applyLocalized)); converter.put(Float.class, new FloatLocaleConverter(locale, applyLocalized)); converter.put(Float.TYPE, new FloatLocaleConverter(locale, applyLocalized)); converter.put(Integer.class, new IntegerLocaleConverter(locale, applyLocalized)); converter.put(Integer.TYPE, new IntegerLocaleConverter(locale, applyLocalized)); converter.put(Long.class, new LongLocaleConverter(locale, applyLocalized)); converter.put(Long.TYPE, new LongLocaleConverter(locale, applyLocalized)); converter.put(Short.class, new ShortLocaleConverter(locale, applyLocalized)); converter.put(Short.TYPE, new ShortLocaleConverter(locale, applyLocalized)); converter.put(String.class, new StringLocaleConverter(locale, applyLocalized)); // conversion format patterns of java.sql.* types should correspond to default // behaviour of toString and valueOf methods of these classes converter.put(java.sql.Date.class, new SqlDateLocaleConverter(locale, "yyyy-MM-dd")); converter.put(java.sql.Time.class, new SqlTimeLocaleConverter(locale, "HH:mm:ss")); converter.put(java.sql.Timestamp.class, new SqlTimestampLocaleConverter(locale, "yyyy-MM-dd HH:mm:ss.S")); converter.setFast(true); return converter; }
From source file:javadz.beanutils.ConvertUtilsBean.java
/** * Sets the default value for Short conversions. * @param newDefaultShort The default Short value * @deprecated Register replacement converters for Short.TYPE and * Short.class instead//from w w w .j a va 2 s.c o m */ public void setDefaultShort(short newDefaultShort) { defaultShort = new Short(newDefaultShort); register(new ShortConverter(defaultShort), Short.TYPE); register(new ShortConverter(defaultShort), Short.class); }
From source file:org.lunarray.model.descriptor.scanner.AnnotationMetaModelProcessor.java
/** * Copy array values.// w ww. j a v a2 s. com * * @param values * The array values. * @param name * The property name. * @param obj * The object value. * @param type * The array type. * @param compType * The component type. * @throws MappingException * Thrown if the mapping was unsuccessful. */ private void copyShortNumbers(final AnnotationMetaValues values, final String name, final Object obj, final Class<?> type, final Class<?> compType) throws MappingException { try { if (Short.TYPE.equals(compType)) { final short[] array = short[].class.cast(obj); for (final short a : array) { values.getMetaValueList(name).add(this.converterTool.convertToString(Short.TYPE, a)); } } else if (Byte.TYPE.equals(compType)) { final byte[] array = byte[].class.cast(obj); for (final byte a : array) { values.getMetaValueList(name).add(this.converterTool.convertToString(Byte.TYPE, a)); } } else { this.copyNonDiscreteNumbers(values, name, obj, type, compType); } } catch (final ConverterException e) { throw new MappingException(e); } }
From source file:org.kuali.rice.krad.uif.util.ObjectPropertyUtils.java
/** * Convert to a primitive type if available. * /*from w ww . j a va 2 s . c om*/ * @param type The type to convert. * @return A primitive type, if available, that corresponds to the type. */ public static Class<?> getPrimitiveType(Class<?> type) { if (Byte.class.equals(type)) { return Byte.TYPE; } else if (Short.class.equals(type)) { return Short.TYPE; } else if (Integer.class.equals(type)) { return Integer.TYPE; } else if (Long.class.equals(type)) { return Long.TYPE; } else if (Boolean.class.equals(type)) { return Boolean.TYPE; } else if (Float.class.equals(type)) { return Float.TYPE; } else if (Double.class.equals(type)) { return Double.TYPE; } return type; }
From source file:com.flexive.faces.renderer.FxSelectRenderer.java
/** * Convert select many values to given array class * * @param context faces context// ww w. ja v a2 s.co m * @param uiSelectMany select many component * @param arrayClass the array class * @param newValues new values to convert * @return converted values * @throws ConverterException on errors */ protected Object convertSelectManyValues(FacesContext context, UISelectMany uiSelectMany, Class arrayClass, String[] newValues) throws ConverterException { Object result; Converter converter; int len = (null != newValues ? newValues.length : 0); Class elementType = arrayClass.getComponentType(); // Optimization: If the elementType is String, we don't need // conversion. Just return newValues. if (elementType.equals(String.class)) return newValues; try { result = Array.newInstance(elementType, len); } catch (Exception e) { throw new ConverterException(e); } // bail out now if we have no new values, returning our // oh-so-useful zero-length array. if (null == newValues) return result; // obtain a converter. // attached converter takes priority if (null == (converter = uiSelectMany.getConverter())) { // Otherwise, look for a by-type converter if (null == (converter = FxJsfComponentUtils.getConverterForClass(elementType, context))) { // if that fails, and the attached values are of Object type, // we don't need conversion. if (elementType.equals(Object.class)) return newValues; StringBuffer valueStr = new StringBuffer(); for (int i = 0; i < len; i++) { if (i == 0) valueStr.append(newValues[i]); else valueStr.append(' ').append(newValues[i]); } throw new ConverterException("Could not get a converter for " + String.valueOf(valueStr)); } } if (elementType.isPrimitive()) { for (int i = 0; i < len; i++) { if (elementType.equals(Boolean.TYPE)) { Array.setBoolean(result, i, ((Boolean) converter.getAsObject(context, uiSelectMany, newValues[i]))); } else if (elementType.equals(Byte.TYPE)) { Array.setByte(result, i, ((Byte) converter.getAsObject(context, uiSelectMany, newValues[i]))); } else if (elementType.equals(Double.TYPE)) { Array.setDouble(result, i, ((Double) converter.getAsObject(context, uiSelectMany, newValues[i]))); } else if (elementType.equals(Float.TYPE)) { Array.setFloat(result, i, ((Float) converter.getAsObject(context, uiSelectMany, newValues[i]))); } else if (elementType.equals(Integer.TYPE)) { Array.setInt(result, i, ((Integer) converter.getAsObject(context, uiSelectMany, newValues[i]))); } else if (elementType.equals(Character.TYPE)) { Array.setChar(result, i, ((Character) converter.getAsObject(context, uiSelectMany, newValues[i]))); } else if (elementType.equals(Short.TYPE)) { Array.setShort(result, i, ((Short) converter.getAsObject(context, uiSelectMany, newValues[i]))); } else if (elementType.equals(Long.TYPE)) { Array.setLong(result, i, ((Long) converter.getAsObject(context, uiSelectMany, newValues[i]))); } } } else { for (int i = 0; i < len; i++) Array.set(result, i, converter.getAsObject(context, uiSelectMany, newValues[i])); } return result; }
From source file:com.nway.spring.jdbc.bean.JavassistBeanProcessor.java
private Object processColumn(ResultSet rs, int index, Class<?> propType, String writer, StringBuilder handler) throws SQLException { if (propType.equals(String.class)) { handler.append("bean.").append(writer).append("(").append("$1.getString(").append(index).append("));"); return rs.getString(index); } else if (propType.equals(Integer.TYPE)) { handler.append("bean.").append(writer).append("(").append("$1.getInt(").append(index).append("));"); return rs.getInt(index); } else if (propType.equals(Integer.class)) { handler.append("bean.").append(writer).append("(").append("integerValue($1.getInt(").append(index) .append("),$1.wasNull()));"); return JdbcUtils.getResultSetValue(rs, index, Integer.class); } else if (propType.equals(Long.TYPE)) { handler.append("bean.").append(writer).append("(").append("$1.getLong(").append(index).append("));"); return rs.getLong(index); } else if (propType.equals(Long.class)) { handler.append("bean.").append(writer).append("(").append("longValue($1.getLong(").append(index) .append("),$1.wasNull()));"); return JdbcUtils.getResultSetValue(rs, index, Long.class); } else if (propType.equals(java.sql.Date.class)) { handler.append("bean.").append(writer).append("(").append("$1.getDate(").append(index).append("));"); return rs.getDate(index); } else if (propType.equals(java.util.Date.class) || propType.equals(Timestamp.class)) { handler.append("bean.").append(writer).append("(").append("$1.getTimestamp(").append(index) .append("));"); return rs.getTimestamp(index); } else if (propType.equals(Double.TYPE)) { handler.append("bean.").append(writer).append("(").append("$1.getDouble(").append(index).append("));"); return rs.getDouble(index); } else if (propType.equals(Double.class)) { handler.append("bean.").append(writer).append("(").append("doubleValue($1.getDouble(").append(index) .append("),$1.wasNull()));"); return JdbcUtils.getResultSetValue(rs, index, Double.class); } else if (propType.equals(Float.TYPE)) { handler.append("bean.").append(writer).append("(").append("$1.getFloat(").append(index).append("));"); return rs.getFloat(index); } else if (propType.equals(Float.class)) { handler.append("bean.").append(writer).append("(").append("floatValue($1.getFloat(").append(index) .append("),$1.wasNull()));"); return JdbcUtils.getResultSetValue(rs, index, Float.class); } else if (propType.equals(Time.class)) { handler.append("bean.").append(writer).append("(").append("$1.getTime(").append(index).append("));"); return rs.getTime(index); } else if (propType.equals(Boolean.TYPE)) { handler.append("bean.").append(writer).append("(").append("$1.getBoolean(").append(index).append("));"); return rs.getBoolean(index); } else if (propType.equals(Boolean.class)) { handler.append("bean.").append(writer).append("(").append("booleanValue($1.getBoolean(").append(index) .append("),$1.wasNull()));"); return JdbcUtils.getResultSetValue(rs, index, Boolean.class); } else if (propType.equals(byte[].class)) { handler.append("bean.").append(writer).append("(").append("$1.getBytes(").append(index).append("));"); return rs.getBytes(index); } else if (BigDecimal.class.equals(propType)) { handler.append("bean.").append(writer).append("(").append("$1.getBigDecimal(").append(index) .append("));"); return rs.getBigDecimal(index); } else if (Blob.class.equals(propType)) { handler.append("bean.").append(writer).append("(").append("$1.getBlob(").append(index).append("));"); return rs.getBlob(index); } else if (Clob.class.equals(propType)) { handler.append("bean.").append(writer).append("(").append("$1.getClob(").append(index).append("));"); return rs.getClob(index); } else if (propType.equals(Short.TYPE)) { handler.append("bean.").append(writer).append("(").append("$1.getShort(").append(index).append("));"); return rs.getShort(index); } else if (propType.equals(Short.class)) { handler.append("bean.").append(writer).append("(").append("shortValue($1.getShort(").append(index) .append("),$1.wasNull()));"); return JdbcUtils.getResultSetValue(rs, index, Short.class); } else if (propType.equals(Byte.TYPE)) { handler.append("bean.").append(writer).append("(").append("$1.getByte(").append(index).append("));"); return rs.getByte(index); } else if (propType.equals(Byte.class)) { handler.append("bean.").append(writer).append("(").append("byteValue($1.getByte(").append(index) .append("),$1.wasNull()));"); return JdbcUtils.getResultSetValue(rs, index, Byte.class); } else {//from w w w. j a v a 2 s . com handler.append("bean.").append(writer).append("(").append("(").append(propType.getName()).append(")") .append("$1.getObject(").append(index).append("));"); return rs.getObject(index); } }
From source file:org.evosuite.testcarver.testcase.EvoTestCaseCodeGenerator.java
private final Class<?> getClassFromType(final org.objectweb.asm.Type type) { if (type.equals(org.objectweb.asm.Type.BOOLEAN_TYPE)) { return Boolean.TYPE; } else if (type.equals(org.objectweb.asm.Type.BYTE_TYPE)) { return Byte.TYPE; } else if (type.equals(org.objectweb.asm.Type.CHAR_TYPE)) { return Character.TYPE; } else if (type.equals(org.objectweb.asm.Type.DOUBLE_TYPE)) { return Double.TYPE; } else if (type.equals(org.objectweb.asm.Type.FLOAT_TYPE)) { return Float.TYPE; } else if (type.equals(org.objectweb.asm.Type.INT_TYPE)) { return Integer.TYPE; } else if (type.equals(org.objectweb.asm.Type.LONG_TYPE)) { return Long.TYPE; } else if (type.equals(org.objectweb.asm.Type.SHORT_TYPE)) { return Short.TYPE; } else if (type.getSort() == org.objectweb.asm.Type.ARRAY) { final org.objectweb.asm.Type elementType = type.getElementType(); int[] dimensions = new int[type.getDimensions()]; if (elementType.equals(org.objectweb.asm.Type.BOOLEAN_TYPE)) { return Array.newInstance(boolean.class, dimensions).getClass(); } else if (elementType.equals(org.objectweb.asm.Type.BYTE_TYPE)) { return Array.newInstance(byte.class, dimensions).getClass(); } else if (elementType.equals(org.objectweb.asm.Type.CHAR_TYPE)) { return Array.newInstance(char.class, dimensions).getClass(); } else if (elementType.equals(org.objectweb.asm.Type.DOUBLE_TYPE)) { return Array.newInstance(double.class, dimensions).getClass(); } else if (elementType.equals(org.objectweb.asm.Type.FLOAT_TYPE)) { return Array.newInstance(float.class, dimensions).getClass(); } else if (elementType.equals(org.objectweb.asm.Type.INT_TYPE)) { return Array.newInstance(int.class, dimensions).getClass(); } else if (elementType.equals(org.objectweb.asm.Type.LONG_TYPE)) { return Array.newInstance(long.class, dimensions).getClass(); } else if (elementType.equals(org.objectweb.asm.Type.SHORT_TYPE)) { return Array.newInstance(short.class, dimensions).getClass(); }//from w w w . ja va 2s .c om } // try // { return getClassForName(type.getClassName()); // return Class.forName(type.getClassName(), true, StaticTestCluster.classLoader); // } // catch (final ClassNotFoundException e) // { // throw new RuntimeException(e); // } }
From source file:org.pentaho.reporting.engine.classic.core.util.beans.BeanUtility.java
public static boolean isSameType(final Class declared, final Class object) { if (declared.equals(object)) { return true; }/*from w ww . j a v a 2 s. c om*/ if (Float.TYPE.equals(declared) && Float.class.equals(object)) { return true; } if (Double.TYPE.equals(declared) && Double.class.equals(object)) { return true; } if (Byte.TYPE.equals(declared) && Byte.class.equals(object)) { return true; } if (Character.TYPE.equals(declared) && Character.class.equals(object)) { return true; } if (Short.TYPE.equals(declared) && Short.class.equals(object)) { return true; } if (Integer.TYPE.equals(declared) && Integer.class.equals(object)) { return true; } if (Long.TYPE.equals(declared) && Long.class.equals(object)) { return true; } return false; }
From source file:org.xmlsh.util.JavaUtils.java
public static <T> T convert(Object value, Class<T> targetClass) throws InvalidArgumentException { assert (targetClass != null); assert (value != null); if (targetClass.isInstance(value)) return targetClass.cast(value); Class<?> sourceClass = value.getClass(); // Asking for an XdmValue class if (XdmValue.class.isAssignableFrom(targetClass)) { if (value instanceof XdmNode) return (T) (XdmValue) value; if (targetClass.isAssignableFrom(XdmAtomicValue.class)) { // Try some smart conversions of all types XdmAtomicValue knows if (value instanceof Boolean) return (T) new XdmAtomicValue(((Boolean) value).booleanValue()); else if (value instanceof Double) return (T) new XdmAtomicValue(((Double) value).doubleValue()); else if (value instanceof Float) return (T) new XdmAtomicValue(((Float) value).floatValue()); else if (value instanceof BigDecimal) return (T) new XdmAtomicValue((BigDecimal) value); else if (value instanceof BigDecimal) return (T) new XdmAtomicValue((BigDecimal) value); else if (value instanceof URI) return (T) new XdmAtomicValue((URI) value); else if (value instanceof Long) return (T) new XdmAtomicValue((Long) value); else if (value instanceof QName) return (T) new XdmAtomicValue((QName) value); // Still wanting an xdm value }/* w ww. jav a 2s . co m*/ if (isAtomic(value)) return (T) new XdmAtomicValue(value.toString()); } boolean bAtomic = isAtomic(value); Class<?> vclass = value.getClass(); if (targetClass.isPrimitive() && bAtomic) { /* Try to match non-primative types */ if (targetClass == Integer.TYPE) { if (vclass == Long.class) value = Integer.valueOf(((Long) value).intValue()); else if (vclass == Short.class) value = Integer.valueOf(((Short) value).intValue()); else if (vclass == Byte.class) value = Integer.valueOf(((Byte) value).intValue()); else value = Integer.valueOf(value.toString()); } else if (targetClass == Long.TYPE) { if (vclass == Integer.class) value = Long.valueOf(((Integer) value).intValue()); else if (vclass == Short.class) value = Long.valueOf(((Short) value).intValue()); else if (vclass == Byte.class) value = Long.valueOf(((Byte) value).intValue()); value = Long.valueOf(value.toString()); } else if (targetClass == Short.TYPE) { if (vclass == Integer.class) value = Short.valueOf((short) ((Integer) value).intValue()); else if (vclass == Long.class) value = Short.valueOf((short) ((Long) value).intValue()); else if (vclass == Byte.class) value = Short.valueOf((short) ((Byte) value).intValue()); value = Short.valueOf(value.toString()); } else if (targetClass == Byte.TYPE) { if (vclass == Integer.class) value = Byte.valueOf((byte) ((Integer) value).intValue()); else if (vclass == Long.class) value = Byte.valueOf((byte) ((Long) value).intValue()); else if (vclass == Short.class) value = Byte.valueOf((byte) ((Short) value).intValue()); value = Byte.valueOf(value.toString()); } else ; // skip return (T) value; } // Bean constructor Constructor<?> cnst = getBeanConstructor(targetClass, sourceClass); if (cnst != null) try { return (T) cnst.newInstance(convert(value, cnst.getParameterTypes()[0])); } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { mLogger.debug("Exception converting argument for constructor", e); } // Cast through string String svalue = value.toString(); if (targetClass == Integer.class) value = Integer.valueOf(svalue); else if (targetClass == Long.class) value = Long.valueOf(svalue); else if (targetClass == Short.class) value = Short.valueOf(svalue); else if (targetClass == Float.class) value = Float.valueOf(svalue); else if (targetClass == Double.class) value = Double.valueOf(svalue); else value = null; return (T) value; }
From source file:org.crank.javax.faces.component.MenuRenderer.java
protected Object convertSelectManyValues(FacesContext context, UISelectMany uiSelectMany, Class<?> arrayClass, String[] newValues) throws ConverterException { Object result = null;/*www . j a va 2 s .c o m*/ Converter converter = null; int len = (null != newValues ? newValues.length : 0); Class<?> elementType = arrayClass.getComponentType(); // Optimization: If the elementType is String, we don't need // conversion. Just return newValues. if (elementType.equals(String.class)) { return newValues; } try { result = Array.newInstance(elementType, len); } catch (Exception e) { throw new ConverterException(e); } // bail out now if we have no new values, returning our // oh-so-useful zero-length array. if (null == newValues) { return result; } // obtain a converter. // attached converter takes priority if (null == (converter = uiSelectMany.getConverter())) { // Otherwise, look for a by-type converter if (null == (converter = Util.getConverterForClass(elementType, context))) { // if that fails, and the attached values are of Object type, // we don't need conversion. if (elementType.equals(Object.class)) { return newValues; } StringBuffer valueStr = new StringBuffer(); for (int i = 0; i < len; i++) { if (i == 0) { valueStr.append(newValues[i]); } else { valueStr.append(' ').append(newValues[i]); } } Object[] params = { valueStr.toString(), "null Converter" }; throw new ConverterException( MessageUtils.getExceptionMessage(MessageUtils.CONVERSION_ERROR_MESSAGE_ID, params)); } } assert (null != result); if (elementType.isPrimitive()) { for (int i = 0; i < len; i++) { if (elementType.equals(Boolean.TYPE)) { Array.setBoolean(result, i, ((Boolean) converter.getAsObject(context, uiSelectMany, newValues[i]))); } else if (elementType.equals(Byte.TYPE)) { Array.setByte(result, i, ((Byte) converter.getAsObject(context, uiSelectMany, newValues[i]))); } else if (elementType.equals(Double.TYPE)) { Array.setDouble(result, i, ((Double) converter.getAsObject(context, uiSelectMany, newValues[i]))); } else if (elementType.equals(Float.TYPE)) { Array.setFloat(result, i, ((Float) converter.getAsObject(context, uiSelectMany, newValues[i]))); } else if (elementType.equals(Integer.TYPE)) { Array.setInt(result, i, ((Integer) converter.getAsObject(context, uiSelectMany, newValues[i]))); } else if (elementType.equals(Character.TYPE)) { Array.setChar(result, i, ((Character) converter.getAsObject(context, uiSelectMany, newValues[i]))); } else if (elementType.equals(Short.TYPE)) { Array.setShort(result, i, ((Short) converter.getAsObject(context, uiSelectMany, newValues[i]))); } else if (elementType.equals(Long.TYPE)) { Array.setLong(result, i, ((Long) converter.getAsObject(context, uiSelectMany, newValues[i]))); } } } else { for (int i = 0; i < len; i++) { if (logger.isLoggable(Level.FINE)) { Object converted = converter.getAsObject(context, uiSelectMany, newValues[i]); logger.fine("String value: " + newValues[i] + " converts to : " + converted.toString()); } Array.set(result, i, converter.getAsObject(context, uiSelectMany, newValues[i])); } } return result; }