List of usage examples for java.lang Float TYPE
Class TYPE
To view the source code for java.lang Float TYPE.
Click Source Link
From source file:nz.ac.otago.psyanlab.common.model.util.ModelUtils.java
/** * Checks to see the given ored set of return types intersects with the * given method's return type./*from w w w . ja va 2 s.c om*/ * * @param method Method to test. * @param returnTypes Ored set of return types. * @return True if intersection. */ public static boolean returnTypeIntersects(Method method, int returnTypes) { if ((returnTypes & Type.TYPE_BOOLEAN) != 0 && method.getReturnType().equals(Boolean.TYPE)) { return true; } if ((returnTypes & Type.TYPE_INTEGER) != 0 && method.getReturnType().equals(Integer.TYPE)) { return true; } if ((returnTypes & Type.TYPE_FLOAT) != 0 && method.getReturnType().equals(Float.TYPE)) { return true; } if ((returnTypes & Type.TYPE_STRING) != 0 && method.getReturnType().equals(String.class)) { return true; } if (returnTypes == 0 && method.getReturnType().equals(Void.TYPE)) { return true; } return false; }
From source file:org.getobjects.appserver.publisher.GoJavaMethod.java
@SuppressWarnings("unchecked") public Object coerceFormValueToArgumentType(final Object[] _v, final Class<?> _argType) { // FIXME: All this isn't nice. Cleanup and do it properly. // FIXME: Cache all the dynamic lookup if (_v == null) return null; if (_argType.isAssignableFrom(_v.getClass())) return _v; int vCount = _v.length; /* check whether the argument is some array-ish thing */ if (_argType.isArray()) { final Class<?> itemType = _argType.getComponentType(); final Object typedArray = java.lang.reflect.Array.newInstance(itemType, vCount); for (int i = 0; i < vCount; i++) { Object[] v = { _v[i] }; Object sv = this.coerceFormValueToArgumentType(v, itemType); java.lang.reflect.Array.set(typedArray, i, sv); }// w ww . j a v a 2 s . c o m return typedArray; } if (_argType.isAssignableFrom(List.class)) return UList.asList(_v); if (_argType.isAssignableFrom(Set.class)) return new HashSet(UList.asList(_v)); if (_argType.isAssignableFrom(Collection.class)) return UList.asList(_v); /* empty assignment */ if (vCount == 0) { if (!_argType.isPrimitive()) return null; // all objects, return null if (_argType == Boolean.TYPE) return new Boolean(false); if (_argType == Integer.TYPE) return new Integer(-1); if (_argType == Double.TYPE) return new Double(-1.0); if (_argType == Float.TYPE) return new Float(-1.0); if (_argType == Short.TYPE) return new Integer(-1); if (_argType == Long.TYPE) return new Long(-1); log.error("Unexpected primitive arg type: " + _argType); return new GoInternalErrorException("Unexpected primitive type!"); } /* check whether it is a directly assignable type */ if (vCount == 1) { /* some type coercion. Can we reuse anything from KVC here? */ // Note: Go supports various Zope form value formats, e.g. 'age:int' // Check WOServletRequest for more. final Object v = _v[0]; if (_argType.isAssignableFrom(v.getClass())) return v; /* some basic coercion */ if (_argType.isPrimitive()) { if (_argType == Boolean.TYPE) return new Boolean(UObject.boolValue(v)); if (_argType == Integer.TYPE || _argType == Short.TYPE) return new Integer(UObject.intValue(v)); if (_argType == Long.TYPE) return new Long(UObject.intOrLongValue(v).longValue()); } else if (_argType.isAssignableFrom(String.class)) return v.toString(); return v; // might crash } /* error out, return exception as value */ log.error("Cannot convert form value to Java argument " + _argType + ": " + _v); return new GoInternalErrorException("Cannot convert form value to Java parameter"); }
From source file:Main.java
/** * <p>Copies the given array and adds the given element at the end of the new array.</p> * * <p>The new array contains the same elements of the input * array plus the given element in the last position. The component type of * the new array is the same as that of the input array.</p> * * <p>If the input array is {@code null}, a new one element array is returned * whose component type is the same as the element.</p> * * <pre>/*ww w. ja v a2 s . c om*/ * ArrayUtils.add(null, 0) = [0] * ArrayUtils.add([1], 0) = [1, 0] * ArrayUtils.add([1, 0], 1) = [1, 0, 1] * </pre> * * @param array the array to copy and add the element to, may be {@code null} * @param element the object to add at the last index of the new array * @return A new array containing the existing elements plus the new element * @since 2.1 */ public static float[] add(float[] array, float element) { float[] newArray = (float[]) copyArrayGrow1(array, Float.TYPE); newArray[newArray.length - 1] = element; return newArray; }
From source file:com.xwtec.xwserver.util.json.JSONArray.java
/** * Creates a JSONArray.<br>/* w ww.jav a 2s .c o m*/ * Inspects the object type to call the correct JSONArray factory method. * Accepts JSON formatted strings, arrays, Collections and Enums. * * @param object * @throws JSONException if the object can not be converted to a proper * JSONArray. */ public static JSONArray fromObject(Object object, JsonConfig jsonConfig) { if (object instanceof JSONString) { return _fromJSONString((JSONString) object, jsonConfig); } else if (object instanceof JSONArray) { return _fromJSONArray((JSONArray) object, jsonConfig); } else if (object instanceof Collection) { return _fromCollection((Collection) object, jsonConfig); } else if (object instanceof JSONTokener) { return _fromJSONTokener((JSONTokener) object, jsonConfig); } else if (object instanceof String) { return _fromString((String) object, jsonConfig); } else if (object != null && object.getClass().isArray()) { Class type = object.getClass().getComponentType(); if (!type.isPrimitive()) { return _fromArray((Object[]) object, jsonConfig); } else { if (type == Boolean.TYPE) { return _fromArray((boolean[]) object, jsonConfig); } else if (type == Byte.TYPE) { return _fromArray((byte[]) object, jsonConfig); } else if (type == Short.TYPE) { return _fromArray((short[]) object, jsonConfig); } else if (type == Integer.TYPE) { return _fromArray((int[]) object, jsonConfig); } else if (type == Long.TYPE) { return _fromArray((long[]) object, jsonConfig); } else if (type == Float.TYPE) { return _fromArray((float[]) object, jsonConfig); } else if (type == Double.TYPE) { return _fromArray((double[]) object, jsonConfig); } else if (type == Character.TYPE) { return _fromArray((char[]) object, jsonConfig); } else { throw new JSONException("Unsupported type"); } } } else if (JSONUtils.isBoolean(object) || JSONUtils.isFunction(object) || JSONUtils.isNumber(object) || JSONUtils.isNull(object) || JSONUtils.isString(object) || object instanceof JSON) { fireArrayStartEvent(jsonConfig); JSONArray jsonArray = new JSONArray().element(object, jsonConfig); fireElementAddedEvent(0, jsonArray.get(0), jsonConfig); fireArrayStartEvent(jsonConfig); return jsonArray; } else if (object instanceof Enum) { return _fromArray((Enum) object, jsonConfig); } else if (object instanceof Annotation || (object != null && object.getClass().isAnnotation())) { throw new JSONException("Unsupported type"); } else if (JSONUtils.isObject(object)) { fireArrayStartEvent(jsonConfig); JSONArray jsonArray = new JSONArray().element(JSONObject.fromObject(object, jsonConfig)); fireElementAddedEvent(0, jsonArray.get(0), jsonConfig); fireArrayStartEvent(jsonConfig); return jsonArray; } else { throw new JSONException("Unsupported type"); } }
From source file:Main.java
/** * <p>Copies the given array and adds the given element at the end of the new array.</p> * * <p>The new array contains the same elements of the input * array plus the given element in the last position. The component type of * the new array is the same as that of the input array.</p> * * <p>If the input array is {@code null}, a new one element array is returned * whose component type is the same as the element.</p> * * <pre>//from w ww .java 2 s .c o m * ArrayUtils.add(null, 0) = [0] * ArrayUtils.add([1], 0) = [1, 0] * ArrayUtils.add([1, 0], 1) = [1, 0, 1] * </pre> * * @param array the array to copy and add the element to, may be {@code null} * @param element the object to add at the last index of the new array * @return A new array containing the existing elements plus the new element * @since 2.1 */ public static float[] add(final float[] array, final float element) { final float[] newArray = (float[]) copyArrayGrow1(array, Float.TYPE); newArray[newArray.length - 1] = element; return newArray; }
From source file:org.apache.struts.config.FormPropertyConfig.java
/** * Return a Class corresponds to the value specified for the * <code>type</code> property, taking into account the trailing "[]" for * arrays (as well as the ability to specify primitive Java types). */// w ww .j a v a 2s .c o m public Class getTypeClass() { // Identify the base class (in case an array was specified) String baseType = getType(); boolean indexed = false; if (baseType.endsWith("[]")) { baseType = baseType.substring(0, baseType.length() - 2); indexed = true; } // Construct an appropriate Class instance for the base class Class baseClass = null; if ("boolean".equals(baseType)) { baseClass = Boolean.TYPE; } else if ("byte".equals(baseType)) { baseClass = Byte.TYPE; } else if ("char".equals(baseType)) { baseClass = Character.TYPE; } else if ("double".equals(baseType)) { baseClass = Double.TYPE; } else if ("float".equals(baseType)) { baseClass = Float.TYPE; } else if ("int".equals(baseType)) { baseClass = Integer.TYPE; } else if ("long".equals(baseType)) { baseClass = Long.TYPE; } else if ("short".equals(baseType)) { baseClass = Short.TYPE; } else { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); if (classLoader == null) { classLoader = this.getClass().getClassLoader(); } try { baseClass = classLoader.loadClass(baseType); } catch (ClassNotFoundException ex) { log.error("Class '" + baseType + "' not found for property '" + name + "'"); baseClass = null; } } // Return the base class or an array appropriately if (indexed) { return (Array.newInstance(baseClass, 0).getClass()); } else { return (baseClass); } }
From source file:org.kuali.rice.krad.data.jpa.Filter.java
/** * Coerces the {@code attributeValue} using the given {@code type}. * * @param type the type to use to coerce the value. * @param attributeName the attribute name of the field to coerce. * @param attributeValue the value to coerce. * @return the coerced value.//from w ww . j a v a 2 s. c o m */ private static Object coerceValue(Class<?> type, String attributeName, String attributeValue) { try { if (Character.TYPE.equals(type) || Character.class.isAssignableFrom(type)) { return Character.valueOf(attributeValue.charAt(0)); } else if (Boolean.TYPE.equals(type) || Boolean.class.isAssignableFrom(type)) { return Boolean.valueOf(attributeValue); } else if (Short.TYPE.equals(type) || Short.class.isAssignableFrom(type)) { return Short.valueOf(attributeValue); } else if (Integer.TYPE.equals(type) || Integer.class.isAssignableFrom(type)) { return Integer.valueOf(attributeValue); } else if (Long.TYPE.equals(type) || Long.class.isAssignableFrom(type)) { return Long.valueOf(attributeValue); } else if (Double.TYPE.equals(type) || Double.class.isAssignableFrom(type)) { return Double.valueOf(attributeValue); } else if (Float.TYPE.equals(type) || Float.class.isAssignableFrom(type)) { return Float.valueOf(attributeValue); } } catch (NumberFormatException nfe) { LOG.error("Could not coerce the value " + attributeValue + " for the field " + attributeName, nfe); } return attributeValue; }
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); }/*from w ww.ja va 2s .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:RealFunctionValidation.java
public static Object readAndWritePrimitiveValue(final DataInputStream in, final DataOutputStream out, final Class<?> type) throws IOException { if (!type.isPrimitive()) { throw new IllegalArgumentException("type must be primitive"); }//from w ww .j a v a 2 s .c o m if (type.equals(Boolean.TYPE)) { final boolean x = in.readBoolean(); out.writeBoolean(x); return Boolean.valueOf(x); } else if (type.equals(Byte.TYPE)) { final byte x = in.readByte(); out.writeByte(x); return Byte.valueOf(x); } else if (type.equals(Character.TYPE)) { final char x = in.readChar(); out.writeChar(x); return Character.valueOf(x); } else if (type.equals(Double.TYPE)) { final double x = in.readDouble(); out.writeDouble(x); return Double.valueOf(x); } else if (type.equals(Float.TYPE)) { final float x = in.readFloat(); out.writeFloat(x); return Float.valueOf(x); } else if (type.equals(Integer.TYPE)) { final int x = in.readInt(); out.writeInt(x); return Integer.valueOf(x); } else if (type.equals(Long.TYPE)) { final long x = in.readLong(); out.writeLong(x); return Long.valueOf(x); } else if (type.equals(Short.TYPE)) { final short x = in.readShort(); out.writeShort(x); return Short.valueOf(x); } else { // This should never occur. throw new IllegalStateException(); } }
From source file:com.projity.util.ClassUtils.java
/** * Get the corresponding object class from a primitive class * @param clazz primitive class/* w ww . j a v a2s .c om*/ * @return Object class. * @throws ClassCastException if class is unknown primitive */ public static Class primitiveToObjectClass(Class clazz) { // return MethodUtils.toNonPrimitiveClass(clazz); if (clazz == Boolean.TYPE) return Boolean.class; else if (clazz == Character.TYPE) return Character.class; else if (clazz == Byte.TYPE) return Byte.class; else if (clazz == Short.TYPE) return Short.class; else if (clazz == Integer.TYPE) return Integer.class; else if (clazz == Long.TYPE) return Long.class; else if (clazz == Float.TYPE) return Float.class; else if (clazz == Double.TYPE) return Double.class; throw new ClassCastException("Cannot convert class" + clazz + " to an object class"); }