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.yccheok.jstock.gui.POIUtils.java
private static void handlePrimitive(Method method, Class<?> clazz) { if (clazz == Boolean.TYPE) { parameterTypeMap.put(Boolean.class, method); } else if (clazz == Character.TYPE) { parameterTypeMap.put(Character.class, method); } else if (clazz == Byte.TYPE) { parameterTypeMap.put(Byte.class, method); } else if (clazz == Short.TYPE) { parameterTypeMap.put(Short.class, method); } else if (clazz == Integer.TYPE) { parameterTypeMap.put(Integer.class, method); } else if (clazz == Long.TYPE) { parameterTypeMap.put(Long.class, method); } else if (clazz == Float.TYPE) { parameterTypeMap.put(Float.class, method); } else if (clazz == Double.TYPE) { parameterTypeMap.put(Double.class, method); } // ... and so on for the other six primitive types (void doesn't matter) }
From source file:org.romaframework.core.schema.SchemaClassElement.java
@SuppressWarnings({ "rawtypes", "unchecked" }) protected Object convertValue(Object iFieldValue, SchemaClassDefinition expectedType) { if (expectedType == null || expectedType.getSchemaClass().isArray()) return iFieldValue; SchemaClass typeClass = expectedType.getSchemaClass(); if (typeClass.equals(Roma.schema().getSchemaClass(iFieldValue))) return iFieldValue; String textValue = null;/*from w w w . j a v a 2 s .co m*/ if (iFieldValue instanceof String) { textValue = (String) iFieldValue; } else if (iFieldValue != null) { textValue = iFieldValue.toString(); } Object value = null; if (textValue != null) { // TRY A SOFT CONVERSION if (typeClass.isOfType(Integer.class) || typeClass.isOfType(Integer.TYPE)) { try { value = textValue.equals("") ? null : Integer.parseInt(textValue); } catch (Exception e) { value = textValue.equals("") ? null : Double.valueOf(textValue).intValue(); } } else if (typeClass.isOfType(Long.class) || typeClass.isOfType(Long.TYPE)) { value = textValue.equals("") ? null : Long.parseLong(textValue); } else if (typeClass.isOfType(Short.class) || typeClass.isOfType(Short.TYPE)) { value = textValue.equals("") ? null : Short.parseShort(textValue); } else if (typeClass.isOfType(Byte.class) || typeClass.isOfType(Byte.TYPE)) { value = textValue.equals("") ? null : Byte.parseByte(textValue); } else if (typeClass.isOfType(Character.class) || typeClass.isOfType(Character.TYPE)) { if (textValue.length() > 0) { value = new Character(textValue.charAt(0)); } } else if (typeClass.isOfType(Float.class) || typeClass.isOfType(Float.TYPE)) { value = textValue.equals("") ? null : Float.parseFloat(textValue); } else if (typeClass.isOfType(Double.class) || typeClass.isOfType(Double.TYPE)) { value = textValue.equals("") ? null : Double.parseDouble(textValue); } else if (typeClass.isOfType(BigDecimal.class)) { value = textValue.equals("") ? null : new BigDecimal(textValue); } else if (iFieldValue != null && !typeClass.isArray() && iFieldValue.getClass().isArray()) { // DESTINATION VALUE IS NOT AN ARRAY: ASSIGN THE FIRST ONE ELEMENT value = ((Object[]) iFieldValue)[0]; } else if (typeClass.isEnum()) { value = Enum.valueOf((Class) typeClass.getLanguageType(), textValue.toUpperCase()); } else { value = iFieldValue; } } if (value != null) { // TODO is this the right place to do this...? Class<?> valueClass = value.getClass(); // SUCH A MONSTER!!! MOVE THIS LOGIC IN SchemaClass.isAssignableFrom... if (value instanceof VirtualObject && !(typeClass.getLanguageType() instanceof Class<?> && ((Class<?>) typeClass.getLanguageType()).isAssignableFrom(VirtualObject.class)) && ((VirtualObject) value).getSuperClassObject() != null) { if (ComposedEntity.class .isAssignableFrom(((VirtualObject) value).getSuperClassObject().getClass())) { value = ((VirtualObject) value).getSuperClassObject(); valueClass = value.getClass(); } } if (value instanceof ComposedEntity<?> && !typeClass.isAssignableFrom(valueClass)) { value = ((ComposedEntity<?>) value).getEntity(); } } if (value == null && typeClass.isPrimitive()) { log.warn("Cannot set the field value to null for primitive types! Field: " + getEntity() + "." + name + " of class " + expectedType.getName() + ". Setting value to 0."); // SET THE VALUE TO 0 value = SchemaHelper.assignDefaultValueToLiteral(typeClass); } return value; }
From source file:com.flipkart.polyguice.config.ApacheCommonsConfigProvider.java
@Override public Object getValue(String path, Class<?> type) { if (!rootConfig.containsKey(path)) { return null; }/*from ww w.j av a 2s .c om*/ if (type.equals(Byte.TYPE) || type.equals(Byte.class)) { return rootConfig.getByte(path, null); } else if (type.equals(Short.TYPE) || type.equals(Short.class)) { return rootConfig.getShort(path, null); } else if (type.equals(Integer.TYPE) || type.equals(Integer.class)) { return rootConfig.getInteger(path, null); } else if (type.equals(Long.TYPE) || type.equals(Long.class)) { return rootConfig.getLong(path, null); } else if (type.equals(Float.TYPE) || type.equals(Float.class)) { return rootConfig.getFloat(path, null); } else if (type.equals(Double.TYPE) || type.equals(Double.class)) { return rootConfig.getDouble(path, null); } else if (type.equals(Boolean.TYPE) || type.equals(Boolean.class)) { return rootConfig.getBoolean(path, null); } else if (type.equals(String.class)) { return rootConfig.getString(path); } else if (type.equals(BigInteger.class)) { return rootConfig.getBigInteger(path); } else if (type.equals(BigDecimal.class)) { return rootConfig.getBigDecimal(path); } else if (type.equals(Properties.class)) { return rootConfig.getProperties(path); } else if (type.equals(String[].class)) { return rootConfig.getStringArray(path); } else if (type.equals(TimeInterval.class)) { String interval = rootConfig.getString(path); if (interval == null) { return null; } return new TimeInterval(interval); } return null; }
From source file:org.eclipse.gyrex.monitoring.internal.mbeans.MetricSetMBean.java
private OpenType detectType(final Class type) { if ((Long.class == type) || (Long.TYPE == type)) { return SimpleType.LONG; } else if ((Integer.class == type) || (Integer.TYPE == type)) { return SimpleType.INTEGER; } else if ((Double.class == type) || (Double.TYPE == type)) { return SimpleType.DOUBLE; } else if ((Float.class == type) || (Float.TYPE == type)) { return SimpleType.FLOAT; } else if ((Byte.class == type) || (Byte.TYPE == type)) { return SimpleType.BYTE; } else if ((Short.class == type) || (Short.TYPE == type)) { return SimpleType.SHORT; } else if ((Boolean.class == type) || (Boolean.TYPE == type)) { return SimpleType.BOOLEAN; } else if (BigDecimal.class == type) { return SimpleType.BIGDECIMAL; } else if (BigInteger.class == type) { return SimpleType.BIGINTEGER; } else if ((Character.class == type) || (Character.TYPE == type)) { return SimpleType.CHARACTER; }/*from w w w .j a v a2 s . c om*/ // last fallback to strings if (isConvertibleToString(type)) { return SimpleType.STRING; } // give up return null; }
From source file:net.yck.wkrdb.common.shared.PropertyConverter.java
/** * Performs a data type conversion from the specified value object to the * given target data class. If additional information is required for this * conversion, it is obtained from {@code DefaultConversionHandler.INSTANCE} * object. If the class is a primitive type (Integer.TYPE, Boolean.TYPE, * etc), the value returned will use the wrapper type (Integer.class, * Boolean.class, etc).// w w w .ja va 2s . co m * * @param cls * the target class of the converted value * @param value * the value to convert * @return the converted value * @throws ConversionException * if the value is not compatible with the requested type */ public static Object to(Class<?> cls, Object value) throws ConversionException { if (cls.isInstance(value)) { return value; // no conversion needed } if (String.class.equals(cls)) { return String.valueOf(value); } if (Boolean.class.equals(cls) || Boolean.TYPE.equals(cls)) { return toBoolean(value); } else if (Character.class.equals(cls) || Character.TYPE.equals(cls)) { return toCharacter(value); } else if (Number.class.isAssignableFrom(cls) || cls.isPrimitive()) { if (Integer.class.equals(cls) || Integer.TYPE.equals(cls)) { return toInteger(value); } else if (Long.class.equals(cls) || Long.TYPE.equals(cls)) { return toLong(value); } else if (Byte.class.equals(cls) || Byte.TYPE.equals(cls)) { return toByte(value); } else if (Short.class.equals(cls) || Short.TYPE.equals(cls)) { return toShort(value); } else if (Float.class.equals(cls) || Float.TYPE.equals(cls)) { return toFloat(value); } else if (Double.class.equals(cls) || Double.TYPE.equals(cls)) { return toDouble(value); } else if (BigInteger.class.equals(cls)) { return toBigInteger(value); } else if (BigDecimal.class.equals(cls)) { return toBigDecimal(value); } } else if (Date.class.equals(cls)) { return toDate(value, DefaultConversionHandler.INSTANCE.getDateFormat()); } else if (Calendar.class.equals(cls)) { return toCalendar(value, DefaultConversionHandler.INSTANCE.getDateFormat()); } else if (URL.class.equals(cls)) { return toURL(value); } else if (Locale.class.equals(cls)) { return toLocale(value); } else if (isEnum(cls)) { return convertToEnum(cls, value); } else if (Color.class.equals(cls)) { return toColor(value); } else if (cls.getName().equals(INTERNET_ADDRESS_CLASSNAME)) { return toInternetAddress(value); } else if (InetAddress.class.isAssignableFrom(cls)) { return toInetAddress(value); } throw new ConversionException("The value '" + value + "' (" + value.getClass() + ")" + " can't be converted to a " + cls.getName() + " object"); }
From source file:org.rhq.core.domain.server.PersistenceUtility.java
@SuppressWarnings("unchecked") // used in hibernate.jsp public static Object cast(String value, Type hibernateType) { if (hibernateType instanceof PrimitiveType) { Class<?> type = ((PrimitiveType) hibernateType).getPrimitiveClass(); if (type.equals(Byte.TYPE)) { return Byte.valueOf(value); } else if (type.equals(Short.TYPE)) { return Short.valueOf(value); } else if (type.equals(Integer.TYPE)) { return Integer.valueOf(value); } else if (type.equals(Long.TYPE)) { return Long.valueOf(value); } else if (type.equals(Float.TYPE)) { return Float.valueOf(value); } else if (type.equals(Double.TYPE)) { return Double.valueOf(value); } else if (type.equals(Boolean.TYPE)) { return Boolean.valueOf(value); }/* w ww.ja v a2 s . co m*/ } else if (hibernateType instanceof EntityType) { String entityName = ((EntityType) hibernateType).getAssociatedEntityName(); try { Class<?> entityClass = Class.forName(entityName); Object entity = entityClass.newInstance(); Field primaryKeyField = entityClass.getDeclaredField("id"); primaryKeyField.setAccessible(true); primaryKeyField.setInt(entity, Integer.valueOf(value)); return entity; } catch (Throwable t) { throw new IllegalArgumentException("Type[" + entityName + "] must have PK field named 'id'"); } } else if (hibernateType instanceof CustomType) { if (Enum.class.isAssignableFrom(hibernateType.getReturnedClass())) { Class<? extends Enum<?>> enumClass = hibernateType.getReturnedClass(); Enum<?>[] enumValues = enumClass.getEnumConstants(); try { int enumOrdinal = Integer.valueOf(value); try { return enumValues[enumOrdinal]; } catch (ArrayIndexOutOfBoundsException aioobe) { throw new IllegalArgumentException("There is no " + enumClass.getSimpleName() + " enum with ordinal '" + enumOrdinal + "'"); } } catch (NumberFormatException nfe) { String ucaseValue = value.toUpperCase(); for (Enum<?> nextEnum : enumValues) { if (nextEnum.name().toUpperCase().equals(ucaseValue)) { return nextEnum; } } throw new IllegalArgumentException( "There is no " + enumClass.getSimpleName() + " enum with name '" + value + "'"); } } } return value; }
From source file:org.pentaho.ui.xul.binding.BindingUtil.java
private static Class getObjectClassOrType(Object o) { if (o instanceof Boolean) { return Boolean.TYPE; } else if (o instanceof Integer) { return Integer.TYPE; } else if (o instanceof Float) { return Float.TYPE; } else if (o instanceof Double) { return Double.TYPE; } else if (o instanceof Short) { return Short.TYPE; } else if (o instanceof Long) { return Long.TYPE; } else {/*ww w .j a v a 2s. c o m*/ return o.getClass(); } }
From source file:org.openflexo.antar.binding.TypeUtils.java
public static Class toPrimitive(Class<?> aClass) { if (isDouble(aClass)) { return Double.TYPE; }/* www . j a v a2 s .c om*/ if (isFloat(aClass)) { return Float.TYPE; } if (isLong(aClass)) { return Long.TYPE; } if (isInteger(aClass)) { return Integer.TYPE; } if (isShort(aClass)) { return Short.TYPE; } if (isByte(aClass)) { return Byte.TYPE; } if (isBoolean(aClass)) { return Boolean.TYPE; } if (isChar(aClass)) { return Character.TYPE; } return aClass; }
From source file:org.apache.hadoop.hbase.regionserver.wal.SequenceFileLogWriter.java
@Override public void init(FileSystem fs, Path path, Configuration conf, boolean overwritable) throws IOException { super.init(fs, path, conf, overwritable); boolean compress = initializeCompressionContext(conf, path); // Create a SF.Writer instance. try {/*w ww . ja va 2s.c om*/ // reflection for a version of SequenceFile.createWriter that doesn't // automatically create the parent directory (see HBASE-2312) this.writer = (SequenceFile.Writer) SequenceFile.class .getMethod("createWriter", new Class[] { FileSystem.class, Configuration.class, Path.class, Class.class, Class.class, Integer.TYPE, Short.TYPE, Long.TYPE, Boolean.TYPE, CompressionType.class, CompressionCodec.class, Metadata.class }) .invoke(null, new Object[] { fs, conf, path, HLogKey.class, WALEdit.class, Integer.valueOf(FSUtils.getDefaultBufferSize(fs)), Short.valueOf((short) conf.getInt("hbase.regionserver.hlog.replication", FSUtils.getDefaultReplication(fs, path))), Long.valueOf(conf.getLong("hbase.regionserver.hlog.blocksize", FSUtils.getDefaultBlockSize(fs, path))), Boolean.valueOf(false) /*createParent*/, SequenceFile.CompressionType.NONE, new DefaultCodec(), createMetadata(conf, compress) }); } catch (InvocationTargetException ite) { // function was properly called, but threw it's own exception throw new IOException(ite.getCause()); } catch (Exception e) { // ignore all other exceptions. related to reflection failure } // if reflection failed, use the old createWriter if (this.writer == null) { LOG.debug("new createWriter -- HADOOP-6840 -- not available"); this.writer = SequenceFile.createWriter(fs, conf, path, HLogKey.class, WALEdit.class, FSUtils.getDefaultBufferSize(fs), (short) conf.getInt("hbase.regionserver.hlog.replication", FSUtils.getDefaultReplication(fs, path)), conf.getLong("hbase.regionserver.hlog.blocksize", FSUtils.getDefaultBlockSize(fs, path)), SequenceFile.CompressionType.NONE, new DefaultCodec(), null, createMetadata(conf, compress)); } else { if (LOG.isTraceEnabled()) LOG.trace("Using new createWriter -- HADOOP-6840"); } this.writer_out = getSequenceFilePrivateFSDataOutputStreamAccessible(); if (LOG.isTraceEnabled()) LOG.trace("Path=" + path + ", compression=" + compress); }
From source file:com.github.jknack.handlebars.helper.MethodHelper.java
/** * Wrap (if possible) a primitive type to their wrapper. * * @param type The candidate type.//from w w w . ja va2 s . c o m * @return A wrapper for the primitive type or the original type. */ private static Class<?> wrap(final Class<?> type) { if (type.isPrimitive()) { if (type == Integer.TYPE) { return Integer.class; } else if (type == Boolean.TYPE) { return Boolean.class; } else if (type == Character.TYPE) { return Character.class; } else if (type == Double.TYPE) { return Double.class; } else if (type == Long.TYPE) { return Long.class; } else if (type == Float.TYPE) { return Float.class; } else if (type == Short.TYPE) { return Short.class; } else if (type == Byte.TYPE) { return Byte.class; } } return type; }