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:org.yestech.jmlnitrate.transformation.inbound.BaseInboundTransformation.java
/** * Returns the Class Type for a Primitive type. * * @param classType Description of the Parameter * @return the Class Type//from w ww .jav a 2s . c om * @exception Exception Description of the Exception */ private Class getClass(String classType) throws Exception { TransformationParameter classParameter = TransformationParameter.getByName(classType); Class type = null; if (classParameter != null) { if (classParameter.equals(TransformationParameter.INT)) { //int type = Integer.TYPE; } else if (classParameter.equals(TransformationParameter.LONG)) { //long type = Long.TYPE; } else if (classParameter.equals(TransformationParameter.FLOAT)) { //float type = Float.TYPE; } else if (classParameter.equals(TransformationParameter.DOUBLE)) { //double type = Double.TYPE; } else if (classParameter.equals(TransformationParameter.BOOLEAN)) { //boolean type = Boolean.TYPE; } else if (classParameter.equals(TransformationParameter.CHAR)) { //char type = Character.TYPE; } else if (classParameter.equals(TransformationParameter.BYTE)) { //byte type = Byte.TYPE; } else { logger.error("Not a valid Class Type..."); throw new IllegalArgumentException("Not a valid Class Type..."); } } else { type = Clazz.getClass(classType); } return type; }
From source file:org.fhcrc.cpl.toolbox.filehandler.TabLoader.java
private void initColumnInfos(Class clazz) { PropertyDescriptor origDescriptors[] = PropertyUtils.getPropertyDescriptors(clazz); HashMap<String, PropertyDescriptor> mappedPropNames = new HashMap<String, PropertyDescriptor>(); for (PropertyDescriptor origDescriptor : origDescriptors) { if (origDescriptor.getName().equals("class")) continue; mappedPropNames.put(origDescriptor.getName().toLowerCase(), origDescriptor); }// w w w . j a v a 2 s .co m boolean isMapClass = java.util.Map.class.isAssignableFrom(clazz); for (ColumnDescriptor column : _columns) { PropertyDescriptor prop = mappedPropNames.get(column.name.toLowerCase()); if (null != prop) { column.name = prop.getName(); column.clazz = prop.getPropertyType(); column.isProperty = true; column.setter = prop.getWriteMethod(); if (column.clazz.isPrimitive()) { if (Float.TYPE.equals(column.clazz)) column.missingValues = 0.0F; else if (Double.TYPE.equals(column.clazz)) column.missingValues = 0.0; else if (Boolean.TYPE.equals(column.clazz)) column.missingValues = Boolean.FALSE; else column.missingValues = 0; //Will get converted. } } else if (isMapClass) { column.isProperty = false; } else { column.load = false; } } }
From source file:org.lunarray.model.descriptor.scanner.AnnotationMetaModelProcessor.java
/** * Copy array values.//from w w w .j ava2 s. co m * * @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 copyNonDiscreteNumbers(final AnnotationMetaValues values, final String name, final Object obj, final Class<?> type, final Class<?> compType) throws MappingException { try { if (Double.TYPE.equals(compType)) { final double[] array = double[].class.cast(obj); for (final double a : array) { values.getMetaValueList(name).add(this.converterTool.convertToString(Double.TYPE, a)); } } else if (Float.TYPE.equals(compType)) { final float[] array = float[].class.cast(obj); for (final float a : array) { values.getMetaValueList(name).add(this.converterTool.convertToString(Float.TYPE, a)); } } else { this.extractNonFloats(values, name, obj, type, compType); } } catch (final ConverterException e) { throw new MappingException(e); } }
From source file:org.xmlsh.util.JavaUtils.java
public static Class<?> fromPrimativeName(String name) { switch (name) { case "boolean": return java.lang.Boolean.TYPE; case "char": return java.lang.Character.TYPE; case "byte": return java.lang.Byte.TYPE; case "short": return java.lang.Short.TYPE; case "int": return java.lang.Integer.TYPE; case "long": return java.lang.Long.TYPE; case "float": return java.lang.Float.TYPE; case "double": return java.lang.Double.TYPE; case "void": return java.lang.Void.TYPE; default://from w w w . ja va 2s . c o m return null; } }
From source file:com.github.gekoh.yagen.util.FieldInfo.java
private static List<FieldInfo> convertFields(List<FieldInfo> fields, Class baseEntity) { for (Field field : baseEntity.getDeclaredFields()) { FieldInfo fi;/* w ww . j a va 2 s .c om*/ Class type = field.getType(); String name = field.getName(); Column column = field.getAnnotation(Column.class); if (field.isAnnotationPresent(Embedded.class)) { if (field.isAnnotationPresent(AttributeOverride.class)) { fi = new FieldInfo(type, name, field.getAnnotation(AttributeOverride.class)); } else { fi = new FieldInfo(type, name, field.getAnnotation(AttributeOverrides.class)); } } else if (field.isAnnotationPresent(Enumerated.class)) { fi = new FieldInfo(type, name, true, column); } else if (column != null && !field.isAnnotationPresent(CollectionTable.class)) { if (type.isPrimitive()) { if (type.equals(Boolean.TYPE)) { type = Boolean.class; } else if (type.equals(Long.TYPE)) { type = Long.class; } else if (type.equals(Integer.TYPE)) { type = Integer.class; } else if (type.equals(Short.TYPE)) { type = Short.class; } else if (type.equals(Byte.TYPE)) { type = Byte.class; } else if (type.equals(Double.TYPE)) { type = Double.class; } else if (type.equals(Float.TYPE)) { type = Float.class; } else if (type.equals(Character.TYPE)) { type = Character.class; } } fi = new FieldInfo(type, name, false, column); } else if ((field.isAnnotationPresent(ManyToOne.class) && !field.isAnnotationPresent(JoinTable.class)) || (field.isAnnotationPresent(OneToOne.class) && StringUtils.isEmpty(field.getAnnotation(OneToOne.class).mappedBy()))) { String columnName = field.isAnnotationPresent(JoinColumn.class) ? field.getAnnotation(JoinColumn.class).name() : field.getName(); fi = getIdFieldInfo(type, name, columnName); } else if (!field.isAnnotationPresent(Transient.class) && (Collection.class.isAssignableFrom(type) || Map.class.isAssignableFrom(type)) && (field.isAnnotationPresent(JoinColumn.class) || field.isAnnotationPresent(JoinTable.class) || field.isAnnotationPresent(CollectionTable.class))) { fi = new FieldInfo(type, name); } else { continue; } if (field.isAnnotationPresent(Type.class)) { fi.addAnnotation(field.getAnnotation(Type.class)); } fi.setField(field); fields.add(fi); } return fields; }
From source file:com.nonninz.robomodel.RoboModel.java
void saveField(Field field, TypedContentValues cv) { final Class<?> type = field.getType(); final boolean wasAccessible = field.isAccessible(); field.setAccessible(true);/*from w w w .j ava2 s. co m*/ try { if (type == String.class) { cv.put(field.getName(), (String) field.get(this)); } else if (type == Boolean.TYPE) { cv.put(field.getName(), field.getBoolean(this)); } else if (type == Byte.TYPE) { cv.put(field.getName(), field.getByte(this)); } else if (type == Double.TYPE) { cv.put(field.getName(), field.getDouble(this)); } else if (type == Float.TYPE) { cv.put(field.getName(), field.getFloat(this)); } else if (type == Integer.TYPE) { cv.put(field.getName(), field.getInt(this)); } else if (type == Long.TYPE) { cv.put(field.getName(), field.getLong(this)); } else if (type == Short.TYPE) { cv.put(field.getName(), field.getShort(this)); } else if (type.isEnum()) { final Object value = field.get(this); if (value != null) { final Method method = type.getMethod("name"); final String str = (String) method.invoke(value); cv.put(field.getName(), str); } } else { // Try to JSONify it (db column must be of type text) final String json = mMapper.writeValueAsString(field.get(this)); cv.put(field.getName(), json); } } catch (final IllegalAccessException e) { final String msg = String.format("Field %s is not accessible", type, field.getName()); throw new IllegalArgumentException(msg); } catch (final JsonProcessingException e) { Ln.w(e, "Error while dumping %s of type %s to Json", field.getName(), type); final String msg = String.format("Field %s is not accessible", type, field.getName()); throw new IllegalArgumentException(msg); } catch (final NoSuchMethodException e) { // Should not happen throw new RuntimeException(e); } catch (final InvocationTargetException e) { // Should not happen throw new RuntimeException(e); } finally { field.setAccessible(wasAccessible); } }
From source file:com.initialxy.cordova.themeablebrowser.ThemeableBrowserUnmarshaller.java
/** * Gracefully convert given Object to given class given the precondition * that both are primitives or one of the classes associated with * primitives. eg. If val is of type Double and cls is of type int, return * Integer type with appropriate value truncation so that it can be assigned * to field with field.set()./* w w w . j ava 2s .c o m*/ * * @param cls * @param val * @return * @throws com.initialxy.cordova.themeablebrowser.ThemeableBrowserUnmarshaller.TypeMismatchException */ private static Object convertToPrimitiveFieldObj(Object val, Class<?> cls) { Class<?> valClass = val.getClass(); Object result = null; try { Method getter = null; if (cls.isAssignableFrom(Byte.class) || cls.isAssignableFrom(Byte.TYPE)) { getter = valClass.getMethod("byteValue"); } else if (cls.isAssignableFrom(Short.class) || cls.isAssignableFrom(Short.TYPE)) { getter = valClass.getMethod("shortValue"); } else if (cls.isAssignableFrom(Integer.class) || cls.isAssignableFrom(Integer.TYPE)) { getter = valClass.getMethod("intValue"); } else if (cls.isAssignableFrom(Long.class) || cls.isAssignableFrom(Long.TYPE)) { getter = valClass.getMethod("longValue"); } else if (cls.isAssignableFrom(Float.class) || cls.isAssignableFrom(Float.TYPE)) { getter = valClass.getMethod("floatValue"); } else if (cls.isAssignableFrom(Double.class) || cls.isAssignableFrom(Double.TYPE)) { getter = valClass.getMethod("doubleValue"); } else if (cls.isAssignableFrom(Boolean.class) || cls.isAssignableFrom(Boolean.TYPE)) { if (val instanceof Boolean) { result = val; } else { throw new TypeMismatchException(cls, val.getClass()); } } else if (cls.isAssignableFrom(Character.class) || cls.isAssignableFrom(Character.TYPE)) { if (val instanceof String && ((String) val).length() == 1) { char c = ((String) val).charAt(0); result = Character.valueOf(c); } else if (val instanceof String) { throw new TypeMismatchException( "Expected Character, " + "but received String with length other than 1."); } else { throw new TypeMismatchException( String.format("Expected Character, accept String, but got %s.", val.getClass())); } } if (getter != null) { result = getter.invoke(val); } } catch (NoSuchMethodException e) { throw new TypeMismatchException(String.format("Cannot convert %s to %s.", val.getClass(), cls)); } catch (SecurityException e) { throw new TypeMismatchException(String.format("Cannot convert %s to %s.", val.getClass(), cls)); } catch (IllegalAccessException e) { throw new TypeMismatchException(String.format("Cannot convert %s to %s.", val.getClass(), cls)); } catch (InvocationTargetException e) { throw new TypeMismatchException(String.format("Cannot convert %s to %s.", val.getClass(), cls)); } return result; }
From source file:com.sun.faces.el.impl.Coercions.java
/** * Returns true if the given class is Byte, Short, Integer, Long, * Float, Double, BigInteger, or BigDecimal *///from w w w. j av a2s.c o m static boolean isNumberClass(Class pClass) { return pClass == Byte.class || pClass == Byte.TYPE || pClass == Short.class || pClass == Short.TYPE || pClass == Integer.class || pClass == Integer.TYPE || pClass == Long.class || pClass == Long.TYPE || pClass == Float.class || pClass == Float.TYPE || pClass == Double.class || pClass == Double.TYPE || pClass == BigInteger.class || pClass == BigDecimal.class; }
From source file:net.sourceforge.pmd.typeresolution.ClassTypeResolverTest.java
@Test public void testLiterals() throws JaxenException { ASTCompilationUnit acu = parseAndTypeResolveForClass15(Literals.class); List<ASTLiteral> literals = convertList(acu.findChildNodesWithXPath("//Literal"), ASTLiteral.class); int index = 0; // String s = "s"; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(String.class, literals.get(index++).getType()); // boolean boolean1 = false; assertEquals(Boolean.TYPE, literals.get(index).getFirstDescendantOfType(ASTBooleanLiteral.class).getType()); assertEquals(Boolean.TYPE, literals.get(index++).getType()); // boolean boolean2 = true; assertEquals(Boolean.TYPE, literals.get(index).getFirstDescendantOfType(ASTBooleanLiteral.class).getType()); assertEquals(Boolean.TYPE, literals.get(index++).getType()); // Object obj = null; assertNull(literals.get(index).getFirstDescendantOfType(ASTNullLiteral.class).getType()); assertNull(literals.get(index++).getType()); // byte byte1 = 0; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Integer.TYPE, literals.get(index++).getType()); // byte byte2 = 0x0F; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Integer.TYPE, literals.get(index++).getType()); // byte byte3 = -007; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Integer.TYPE, literals.get(index++).getType()); // short short1 = 0; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Integer.TYPE, literals.get(index++).getType()); // short short2 = 0x0F; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Integer.TYPE, literals.get(index++).getType()); // short short3 = -007; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Integer.TYPE, literals.get(index++).getType()); // char char1 = 0; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Integer.TYPE, literals.get(index++).getType()); // char char2 = 0x0F; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Integer.TYPE, literals.get(index++).getType()); // char char3 = 007; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Integer.TYPE, literals.get(index++).getType()); // char char4 = 'a'; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Character.TYPE, literals.get(index++).getType()); // int int1 = 0; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Integer.TYPE, literals.get(index++).getType()); // int int2 = 0x0F; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Integer.TYPE, literals.get(index++).getType()); // int int3 = -007; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Integer.TYPE, literals.get(index++).getType()); // int int4 = 'a'; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Character.TYPE, literals.get(index++).getType()); // long long1 = 0; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Integer.TYPE, literals.get(index++).getType()); // long long2 = 0x0F; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Integer.TYPE, literals.get(index++).getType()); // long long3 = -007; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Integer.TYPE, literals.get(index++).getType()); // long long4 = 0L; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Long.TYPE, literals.get(index++).getType()); // long long5 = 0x0Fl; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Long.TYPE, literals.get(index++).getType()); // long long6 = -007L; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Long.TYPE, literals.get(index++).getType()); // long long7 = 'a'; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Character.TYPE, literals.get(index++).getType()); // float float1 = 0.0f; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Float.TYPE, literals.get(index++).getType()); // float float2 = -10e+01f; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Float.TYPE, literals.get(index++).getType()); // float float3 = 0x08.08p3f; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Float.TYPE, literals.get(index++).getType()); // float float4 = 0xFF; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Integer.TYPE, literals.get(index++).getType()); // float float5 = 'a'; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Character.TYPE, literals.get(index++).getType()); // double double1 = 0.0; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Double.TYPE, literals.get(index++).getType()); // double double2 = -10e+01; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Double.TYPE, literals.get(index++).getType()); // double double3 = 0x08.08p3; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Double.TYPE, literals.get(index++).getType()); // double double4 = 0xFF; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Integer.TYPE, literals.get(index++).getType()); // double double5 = 'a'; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Character.TYPE, literals.get(index++).getType()); // Make sure we got them all. assertEquals("All literals not tested", index, literals.size()); }
From source file:at.alladin.rmbt.shared.hstoreparser.HstoreParser.java
/** * get a specific key from json by preserving the fields type * @param json//from www .ja v a 2s . com * @param key * @param toField * @return * @throws JSONException */ public static Object getFromJsonByField(JSONObject json, String key, Field toField) throws JSONException { final Object o = json.get(key); if (o != JSONObject.NULL) { if (toField.getType().equals(Integer.class) || toField.getType().equals(Integer.TYPE)) { return Integer.parseInt(String.valueOf(o)); } else if (toField.getType().equals(String.class)) { return o; } else if (toField.getType().equals(Long.class) || toField.getType().equals(Long.TYPE)) { return Long.parseLong(String.valueOf(o)); } else if (toField.getType().equals(Boolean.class) || toField.getType().equals(Boolean.TYPE)) { return Boolean.parseBoolean(String.valueOf(o)); } else if (toField.getType().equals(Float.class) || toField.getType().equals(Float.TYPE)) { return Float.parseFloat(String.valueOf(o)); } else if (toField.getType().equals(Double.class) || toField.getType().equals(Double.TYPE)) { return Double.parseDouble(String.valueOf(o)); } else { return o; } } return JSONObject.NULL; }