List of usage examples for java.lang Double TYPE
Class TYPE
To view the source code for java.lang Double TYPE.
Click Source Link
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 {//from w w w.j av a 2s. c o m return o.getClass(); } }
From source file:com.projity.util.ClassUtils.java
/** * Given a type, return its default value. If type is unknown, a new one is constructed * @param clazz//from w ww. jav a 2 s . c om * @return */ public static Object getDefaultValueForType(Class clazz) { if (clazz == String.class) return defaultString; else if (clazz == Double.class || clazz == Double.TYPE) return defaultDouble; else if (clazz == Integer.class || clazz == Integer.TYPE) return defaultInteger; else if (clazz == Long.class || clazz == Long.TYPE) return defaultLong; else if (clazz == Float.class || clazz == Float.TYPE) return defaultFloat; else if (clazz == Boolean.class) return defaultBoolean; else if (clazz == Rate.class) return defaultRate; else { try { System.out.println("making default for class" + clazz); return clazz.newInstance(); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } return null; } }
From source file:org.apache.click.util.RequestTypeConverter.java
/** * Return the converted value for the given value object and target type. * * @param value the value object to convert * @param toType the target class type to convert the value to * @return a converted value into the specified type *//*from www .ja v a 2 s . c om*/ protected Object convertValue(Object value, Class<?> toType) { Object result = null; if (value != null) { // If array -> array then convert components of array individually if (value.getClass().isArray() && toType.isArray()) { Class<?> componentType = toType.getComponentType(); result = Array.newInstance(componentType, Array.getLength(value)); for (int i = 0, icount = Array.getLength(value); i < icount; i++) { Array.set(result, i, convertValue(Array.get(value, i), componentType)); } } else { if ((toType == Integer.class) || (toType == Integer.TYPE)) { result = Integer.valueOf((int) OgnlOps.longValue(value)); } else if ((toType == Double.class) || (toType == Double.TYPE)) { result = new Double(OgnlOps.doubleValue(value)); } else if ((toType == Boolean.class) || (toType == Boolean.TYPE)) { result = Boolean.valueOf(value.toString()); } else if ((toType == Byte.class) || (toType == Byte.TYPE)) { result = Byte.valueOf((byte) OgnlOps.longValue(value)); } else if ((toType == Character.class) || (toType == Character.TYPE)) { result = Character.valueOf((char) OgnlOps.longValue(value)); } else if ((toType == Short.class) || (toType == Short.TYPE)) { result = Short.valueOf((short) OgnlOps.longValue(value)); } else if ((toType == Long.class) || (toType == Long.TYPE)) { result = Long.valueOf(OgnlOps.longValue(value)); } else if ((toType == Float.class) || (toType == Float.TYPE)) { result = new Float(OgnlOps.doubleValue(value)); } else if (toType == BigInteger.class) { result = OgnlOps.bigIntValue(value); } else if (toType == BigDecimal.class) { result = bigDecValue(value); } else if (toType == String.class) { result = OgnlOps.stringValue(value); } else if (toType == java.util.Date.class) { long time = getTimeFromDateString(value.toString()); if (time > Long.MIN_VALUE) { result = new java.util.Date(time); } } else if (toType == java.sql.Date.class) { long time = getTimeFromDateString(value.toString()); if (time > Long.MIN_VALUE) { result = new java.sql.Date(time); } } else if (toType == java.sql.Time.class) { long time = getTimeFromDateString(value.toString()); if (time > Long.MIN_VALUE) { result = new java.sql.Time(time); } } else if (toType == java.sql.Timestamp.class) { long time = getTimeFromDateString(value.toString()); if (time > Long.MIN_VALUE) { result = new java.sql.Timestamp(time); } } } } else { if (toType.isPrimitive()) { result = OgnlRuntime.getPrimitiveDefaultValue(toType); } } return result; }
From source file:org.evosuite.testcase.fm.MethodDescriptor.java
private String initMatchers(GenericMethod method, GenericClass retvalType) { String matchers = ""; Type[] types = method.getParameterTypes(); List<GenericClass> parameterClasses = method.getParameterClasses(); for (int i = 0; i < types.length; i++) { if (i > 0) { matchers += " , "; }/*from www . j a v a 2 s. co m*/ Type type = types[i]; GenericClass genericParameter = parameterClasses.get(i); if (type.equals(Integer.TYPE) || type.equals(Integer.class)) { matchers += "anyInt()"; } else if (type.equals(Long.TYPE) || type.equals(Long.class)) { matchers += "anyLong()"; } else if (type.equals(Boolean.TYPE) || type.equals(Boolean.class)) { matchers += "anyBoolean()"; } else if (type.equals(Double.TYPE) || type.equals(Double.class)) { matchers += "anyDouble()"; } else if (type.equals(Float.TYPE) || type.equals(Float.class)) { matchers += "anyFloat()"; } else if (type.equals(Short.TYPE) || type.equals(Short.class)) { matchers += "anyShort()"; } else if (type.equals(Character.TYPE) || type.equals(Character.class)) { matchers += "anyChar()"; } else if (type.equals(String.class)) { matchers += "anyString()"; } else { if (type.getTypeName().equals(Object.class.getName())) { /* Ideally here we should use retvalType to understand if the target class is using generics and if this method parameters would need to be handled accordingly. However, doing it does not seem so trivial... so a current workaround is that, when a method takes an Object as input (which is that would happen in case of Generics T), we use the undetermined "any()" */ matchers += "any()"; } else { if (type instanceof Class) { matchers += "any(" + ((Class) type).getCanonicalName() + ".class)"; } else { //what to do here? is it even possible? matchers += "any(" + genericParameter.getRawClass().getCanonicalName() + ".class)"; // matchers += "any(" + type.getTypeName() + ".class)"; } } } } return matchers; }
From source file:com.alibaba.doris.admin.service.impl.ValueParseUtil.java
/** * ?String ?:/* w ww .j a v a 2 s. c o m*/ * * <pre> * short, int, long, float : 0 * char, byte: 0 * String: null * Map, List: null * Integer, Long, Float : null * Date: null * array: null * </pre> * * @param strValue * @param clazz * @return */ @SuppressWarnings("unchecked") public static <T> T parseStringValue(String strValue, Class<T> clazz, boolean autoDefault) { if (DEF_NULL.equals(strValue)) { if (!clazz.isPrimitive()) { return null; } if (autoDefault) { return (T) getInternalDefaultValue(clazz); } else { return null; } } if (DEF_EMPTY.equals(strValue)) { if (clazz.isArray()) { return (T) Array.newInstance(clazz.getComponentType(), 0); } if (Map.class.isAssignableFrom(clazz)) { return (T) Collections.EMPTY_MAP; } if (List.class.isAssignableFrom(clazz)) { return (T) new ArrayList<Object>(); } if (Set.class.isAssignableFrom(clazz)) { return (T) new HashSet<Object>(); } if (String.class.equals(clazz)) { return (T) StringUtils.EMPTY; } if (Character.TYPE.equals(clazz) || Character.class.equals(clazz)) { return (T) Character.valueOf(' '); } if (autoDefault) { return (T) getInternalDefaultValue(clazz); } else { return null; } } if (StringUtils.isBlank(strValue)) {// ? if (autoDefault) { return (T) getInternalDefaultValue(clazz); } else { return null; } } else { if (String.class.equals(clazz)) { return (T) strValue; } if (Short.TYPE.equals(clazz) || Short.class.equals(clazz)) { return (T) Short.valueOf(strValue); } if (Integer.TYPE.equals(clazz) || Integer.class.equals(clazz)) { return (T) Integer.valueOf(strValue); } if (Long.TYPE.equals(clazz) || Long.class.equals(clazz)) { return (T) Long.valueOf(strValue); } if (Boolean.TYPE.equals(clazz) || Boolean.class.equals(clazz)) { return (T) Boolean.valueOf(strValue); } if (Float.TYPE.equals(clazz) || Float.class.equals(clazz)) { return (T) Float.valueOf(strValue); } if (Double.TYPE.equals(clazz) || Double.class.equals(clazz)) { return (T) Double.valueOf(strValue); } if (Byte.TYPE.equals(clazz) || Byte.class.equals(clazz)) { return (T) Byte.valueOf(strValue); } if (Character.TYPE.equals(clazz) || Character.class.equals(clazz)) { return (T) Character.valueOf(strValue.charAt(0)); } if (clazz.isArray()) { final Class<?> componentType = clazz.getComponentType(); // String[] if (String.class.equals(componentType)) { return (T) StringUtils.split(strValue, ','); } // ?char[] if (Character.TYPE.equals(componentType)) { return (T) strValue.toCharArray(); } if (Character.class.equals(componentType)) { final char[] tmp = strValue.toCharArray(); final Character[] result = new Character[tmp.length]; for (int i = 0; i < result.length; i++) { result[i] = tmp[i]; } return (T) result; } if (Byte.TYPE.equals(componentType) || Byte.class.equals(componentType)) { return (T) (strValue == null ? null : strValue.getBytes()); } } } return null; }
From source file:com.flipkart.polyguice.config.ApacheCommonsConfigProvider.java
@Override public Object getValue(String path, Class<?> type) { if (!rootConfig.containsKey(path)) { return null; }// w w w . j a v a 2 s . c o m 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.briljantframework.data.vector.Convert.java
@SuppressWarnings("unchecked") private static <T> T convertLogical(Class<T> cls, Logical log) { if (cls.equals(Double.class) || cls.equals(Double.TYPE)) { return (T) (Double) (log == Logical.TRUE ? 1.0 : 0.0); } else if (cls.equals(Float.class) || cls.equals(Float.TYPE)) { return (T) (Float) (log == Logical.TRUE ? 1.0f : 0.0f); } else if (cls.equals(Long.class) || cls.equals(Long.TYPE)) { return (T) (Long) (log == Logical.TRUE ? 1l : 0l); } else if (cls.equals(Integer.class) || cls.equals(Integer.TYPE)) { return (T) (Integer) (log == Logical.TRUE ? 1 : 0); } else if (cls.equals(Short.class) || cls.equals(Short.TYPE)) { return (T) (Short) (log == Logical.TRUE ? (short) 1 : (short) 0); } else if (cls.equals(Byte.class) || cls.equals(Byte.TYPE)) { return (T) (Byte) (log == Logical.TRUE ? (byte) 1 : (byte) 0); } else if (Complex.class.equals(cls)) { return cls.cast(log == Logical.TRUE ? Complex.ONE : Complex.ZERO); } else if (Boolean.class.equals(cls)) { return cls.cast(log == Logical.TRUE); } else {//from www.j a v a2 s.co m return Na.of(cls); } }
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 . j ava2 s . com * * @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); }/*from www. ja v a2 s.c o 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.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;/* w w w. j a va 2s. 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; }