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:Main.java
/** * This method parses the given value into the specified primitive or wrapper class. * @param clazz - primitive or wrapper class used to parse * @param value - string to be parsed/*from w ww . jav a 2 s . c o m*/ * @return object of type clazz parsed from the string * @author Trisan Bepler */ public static Object toObject(Class<?> clazz, String value) { if (Boolean.TYPE == clazz) return Boolean.parseBoolean(value); if (Byte.TYPE == clazz) return Byte.parseByte(value); if (Short.TYPE == clazz) return Short.parseShort(value); if (Integer.TYPE == clazz) return Integer.parseInt(value); if (Long.TYPE == clazz) return Long.parseLong(value); if (Float.TYPE == clazz) return Float.parseFloat(value); if (Double.TYPE == clazz) return Double.parseDouble(value); if (Boolean.class == clazz) return Boolean.parseBoolean(value); if (Byte.class == clazz) return Byte.parseByte(value); if (Short.class == clazz) return Short.parseShort(value); if (Integer.class == clazz) return Integer.parseInt(value); if (Long.class == clazz) return Long.parseLong(value); if (Float.class == clazz) return Float.parseFloat(value); if (Double.class == clazz) return Double.parseDouble(value); if (Character.class == clazz) return value.charAt(0); if (Character.TYPE == clazz) return value.charAt(0); return value; }
From source file:Main.java
public static ContentValues objectToContentValues(Object object) { if (object == null) { throw new IllegalArgumentException("please check your argument"); }// w w w. j a v a2s . c o m ContentValues contentValues = new ContentValues(); try { Field[] fields = object.getClass().getDeclaredFields(); for (Field field : fields) { String fieldName = field.getName(); Type type = field.getType(); field.setAccessible(true); if (type.equals(String.class)) { contentValues.put(fieldName, field.get(object).toString()); } else if (type.equals(Integer.class) || type.equals(Integer.TYPE)) { contentValues.put(fieldName, field.getInt(object)); } else if (type.equals(Float.class) || type.equals(Float.TYPE)) { contentValues.put(fieldName, field.getFloat(object)); } else if (type.equals(Long.class) || type.equals(Long.TYPE)) { contentValues.put(fieldName, field.getLong(object)); } else if (type.equals(Double.class) || type.equals(Double.TYPE)) { contentValues.put(fieldName, field.getDouble(object)); } else if (type.equals(Boolean.class) || type.equals(Boolean.TYPE)) { contentValues.put(fieldName, field.getBoolean(object)); } } } catch (IllegalAccessException | IllegalArgumentException e) { e.printStackTrace(); } return contentValues; }
From source file:Main.java
private static String getColumnType(Class<?> fieldType) { if (String.class == fieldType) { return "TEXT"; }/*from w w w. j av a 2s .co m*/ if ((Integer.TYPE == fieldType) || (Integer.class == fieldType)) { return "INTEGER"; } if ((Long.TYPE == fieldType) || (Long.class == fieldType)) { return "BIGINT"; } if ((Float.TYPE == fieldType) || (Float.class == fieldType)) { return "FLOAT"; } if ((Short.TYPE == fieldType) || (Short.class == fieldType)) { return "INT"; } if ((Double.TYPE == fieldType) || (Double.class == fieldType)) { return "DOUBLE"; } if (Blob.class == fieldType) { return "BLOB"; } return "TEXT"; }
From source file:Main.java
private static boolean isWideningPrimitiveNumberConversion(final Class source, final Class target) { if (target == Short.TYPE && (source == Byte.TYPE)) { return true; } else if (target == Integer.TYPE && (source == Short.TYPE || source == Byte.TYPE)) { return true; } else if (target == Long.TYPE && (source == Integer.TYPE || source == Short.TYPE || source == Byte.TYPE)) { return true; } else if (target == Float.TYPE && (source == Long.TYPE || source == Integer.TYPE || source == Short.TYPE || source == Byte.TYPE)) { return true; } else if (target == Double.TYPE && (source == Float.TYPE || source == Long.TYPE || source == Integer.TYPE || source == Short.TYPE || source == Byte.TYPE)) { return true; } else {/*from w w w. j ava 2 s . c o m*/ return false; } }
From source file:PrimitiveUtils.java
public static Object read(String value, Class type) { Object ret = value;/* ww w . java 2 s. com*/ if (Integer.TYPE.equals(type)) { ret = Integer.valueOf(value); } if (Byte.TYPE.equals(type)) { ret = Byte.valueOf(value); } if (Short.TYPE.equals(type)) { ret = Short.valueOf(value); } if (Long.TYPE.equals(type)) { ret = Long.valueOf(value); } if (Float.TYPE.equals(type)) { ret = Float.valueOf(value); } if (Double.TYPE.equals(type)) { ret = Double.valueOf(value); } if (Boolean.TYPE.equals(type)) { ret = Boolean.valueOf(value); } if (Character.TYPE.equals(type)) { ret = value.charAt(0); } // TODO others. return ret; }
From source file:Main.java
/** * Creates a class identifier of form Labc/abc;, from a Class. */// w w w . j a v a 2 s . c o m public static String ci(Class n) { if (n.isArray()) { n = n.getComponentType(); if (n.isPrimitive()) { if (n == Byte.TYPE) { return "[B"; } else if (n == Boolean.TYPE) { return "[Z"; } else if (n == Short.TYPE) { return "[S"; } else if (n == Character.TYPE) { return "[C"; } else if (n == Integer.TYPE) { return "[I"; } else if (n == Float.TYPE) { return "[F"; } else if (n == Double.TYPE) { return "[D"; } else if (n == Long.TYPE) { return "[J"; } else { throw new RuntimeException("Unrecognized type in compiler: " + n.getName()); } } else { return "[" + ci(n); } } else { if (n.isPrimitive()) { if (n == Byte.TYPE) { return "B"; } else if (n == Boolean.TYPE) { return "Z"; } else if (n == Short.TYPE) { return "S"; } else if (n == Character.TYPE) { return "C"; } else if (n == Integer.TYPE) { return "I"; } else if (n == Float.TYPE) { return "F"; } else if (n == Double.TYPE) { return "D"; } else if (n == Long.TYPE) { return "J"; } else if (n == Void.TYPE) { return "V"; } else { throw new RuntimeException("Unrecognized type in compiler: " + n.getName()); } } else { return "L" + p(n) + ";"; } } }
From source file:com.swtxml.util.types.SimpleTypes.java
public static void addSimpleTypes(PropertyRegistry inj) { inj.add(new PropertyMatcher(Boolean.class, Boolean.TYPE), BOOLEAN); inj.add(new PropertyMatcher(Integer.class, Integer.TYPE), INTEGER); inj.add(new PropertyMatcher(Float.class, Float.TYPE), FLOAT); inj.add(new PropertyMatcher(Character.class, Character.TYPE), CHARACTER); inj.add(new PropertyMatcher(String.class), STRING); inj.add(new PropertyMatcher(int[].class), INT_ARRAY); }
From source file:sim.portrayal.inspector.TimeSeriesChartingPropertyInspector.java
public static Class[] types() { return new Class[] { Number.class, Boolean.TYPE, Byte.TYPE, Short.TYPE, Integer.TYPE, Long.TYPE, Float.TYPE, Double.TYPE, Valuable.class }; }
From source file:Main.java
public static boolean isConvertible(Class<?> srcPrimitive, Class<?> tgtPrimitive) { if (Boolean.TYPE.equals(srcPrimitive)) { return Boolean.TYPE.equals(tgtPrimitive); } else if (Byte.TYPE.equals(tgtPrimitive)) { return Byte.TYPE.equals(tgtPrimitive) || Short.TYPE.equals(tgtPrimitive) || Integer.TYPE.equals(tgtPrimitive) || Long.TYPE.equals(tgtPrimitive) || Float.TYPE.equals(tgtPrimitive) || Double.TYPE.equals(tgtPrimitive); } else if (Character.TYPE.equals(srcPrimitive)) { return Character.TYPE.equals(tgtPrimitive) || Integer.TYPE.equals(tgtPrimitive) || Long.TYPE.equals(tgtPrimitive) || Float.TYPE.equals(tgtPrimitive) || Double.TYPE.equals(tgtPrimitive); } else if (Double.TYPE.equals(srcPrimitive)) { return Double.TYPE.equals(tgtPrimitive); } else if (Float.TYPE.equals(srcPrimitive)) { return Float.TYPE.equals(tgtPrimitive) || Double.TYPE.equals(tgtPrimitive); } else if (Integer.TYPE.equals(srcPrimitive)) { return Integer.TYPE.equals(tgtPrimitive) || Long.TYPE.equals(tgtPrimitive) || Float.TYPE.equals(tgtPrimitive) || Double.TYPE.equals(tgtPrimitive); } else if (Long.TYPE.equals(srcPrimitive)) { return Long.TYPE.equals(tgtPrimitive) || Float.TYPE.equals(tgtPrimitive) || Double.TYPE.equals(tgtPrimitive); } else if (Short.TYPE.equals(srcPrimitive)) { return Short.TYPE.equals(tgtPrimitive) || Integer.TYPE.equals(tgtPrimitive) || Long.TYPE.equals(tgtPrimitive) || Float.TYPE.equals(tgtPrimitive) || Double.TYPE.equals(tgtPrimitive); }// ww w . j ava2 s . c o m return false; }
From source file:Main.java
public static Object getResource(Context context, Field field, int value) { Resources resources = context.getResources(); Class type = field.getType(); if (type.isAssignableFrom(Boolean.TYPE) || type.isAssignableFrom(Boolean.class)) return resources.getBoolean(value); else if (type.isAssignableFrom(Integer.TYPE) || type.isAssignableFrom(Integer.class)) { return resources.getInteger(value); } else if (type.isAssignableFrom(ColorStateList.class)) return resources.getColorStateList(value); else if (type.isAssignableFrom(XmlResourceParser.class)) return resources.getXml(value); else if (type.isAssignableFrom(Float.TYPE) || type.isAssignableFrom(Float.class)) return resources.getDimension(value); else if (type.isAssignableFrom(Drawable.class)) return resources.getDrawable(value); else if (type.isAssignableFrom(Animation.class)) return AnimationUtils.loadAnimation(context, value); else if (type.isAssignableFrom(Movie.class)) return resources.getMovie(value); else if (type.isAssignableFrom(String.class)) return resources.getString(value); else if (type.isArray()) { if (type.getName().equals("[I")) { return resources.getIntArray(value); } else if (type.isAssignableFrom(String[].class)) { return resources.getStringArray(value); }/*from w w w . j av a 2 s . com*/ } return null; }