List of usage examples for java.lang Integer TYPE
Class TYPE
To view the source code for java.lang Integer TYPE.
Click Source Link
From source file:Main.java
public static String getTypeForField(Field field) { Class type = field.getType(); // Animation/*from www.j ava2 s . co m*/ if (type.isAssignableFrom(Animation.class)) return "anim"; // Color State List else if (type.isAssignableFrom(ColorStateList.class)) return "color"; // Drawable else if (type.isAssignableFrom(Drawable.class)) return "drawable"; // String else if (type.isAssignableFrom(String.class)) return "string"; // String Array else if (type.isArray()) return "array"; // TODO: Recognize plural strings if possible // else if (type.isAssignableFrom(String.class)) // return "plural"; // Boolean else if (type.isAssignableFrom(Boolean.TYPE) || type.isAssignableFrom(Boolean.class)) return "bool"; // Integer else if (type.isAssignableFrom(Integer.TYPE) || type.isAssignableFrom(Integer.class)) return "integer"; // Dimen else if (type.isAssignableFrom(Float.TYPE) || type.isAssignableFrom(Float.class)) return "dimen"; throw new RuntimeException("No suitable type found for " + field.getName() + "of class " + type.getName()); }
From source file:Main.java
public static String getPrimitiveLetter(Class<?> paramClass) { if (Integer.TYPE.equals(paramClass)) { return "I"; }/*from w w w .j a va 2 s . co m*/ if (Void.TYPE.equals(paramClass)) { return "V"; } if (Boolean.TYPE.equals(paramClass)) { return "Z"; } if (Character.TYPE.equals(paramClass)) { return "C"; } if (Byte.TYPE.equals(paramClass)) { return "B"; } if (Short.TYPE.equals(paramClass)) { return "S"; } if (Float.TYPE.equals(paramClass)) { return "F"; } if (Long.TYPE.equals(paramClass)) { return "J"; } if (Double.TYPE.equals(paramClass)) { return "D"; } throw new IllegalStateException("Type: " + paramClass.getCanonicalName() + " is not a primitive type"); }
From source file:Util.java
/** * Is the given {@code object} a primitive type or wrapper for a primitive * type?//from www . java 2 s. co m * * @param object * The object to check for primitive-ness. * @return {@code true} if {@code object} is a primitive type or wrapper for * a primitive type, {@code false} otherwise. */ public static boolean isPrimitive(Object object) { if (object == null) return false; Class<?> type = object.getClass(); return object instanceof String || (object instanceof Integer || Integer.TYPE.equals(type)) || (object instanceof Boolean || Boolean.TYPE.equals(type)) || (object instanceof Long || Long.TYPE.equals(type)) || (object instanceof Double || Double.TYPE.equals(type)) || (object instanceof Float || Float.TYPE.equals(type)) || (object instanceof Byte || Byte.TYPE.equals(type)) || (object instanceof Short || Short.TYPE.equals(type)) || (object instanceof Character || Character.TYPE.equals(type)); }
From source file:Main.java
private static Class<?> getPrimitive(Class<?> argClass) { if (argClass == Boolean.class) return Boolean.TYPE; else if (argClass == Character.class) return Character.TYPE; else if (argClass == Byte.class) return Byte.TYPE; else if (argClass == Short.class) return Short.TYPE; else if (argClass == Integer.class) return Integer.TYPE; else if (argClass == Long.class) return Long.TYPE; else if (argClass == Float.class) return Float.TYPE; else if (argClass == Double.class) return Double.TYPE; else//from w ww .ja v a 2s . c o m return null; }
From source file:com.browseengine.bobo.serialize.JSONSerializer.java
private static void loadObject(Object array, Class type, int index, JSONArray jsonArray) throws JSONSerializationException, JSONException { if (type.isPrimitive()) { if (type == Integer.TYPE) { Array.setInt(array, index, jsonArray.getInt(index)); } else if (type == Long.TYPE) { Array.setLong(array, index, jsonArray.getInt(index)); } else if (type == Short.TYPE) { Array.setShort(array, index, (short) jsonArray.getInt(index)); } else if (type == Boolean.TYPE) { Array.setBoolean(array, index, jsonArray.getBoolean(index)); } else if (type == Double.TYPE) { Array.setDouble(array, index, jsonArray.getDouble(index)); } else if (type == Float.TYPE) { Array.setFloat(array, index, (float) jsonArray.getDouble(index)); } else if (type == Character.TYPE) { char ch = jsonArray.getString(index).charAt(0); Array.setChar(array, index, ch); } else if (type == Byte.TYPE) { Array.setByte(array, index, (byte) jsonArray.getInt(index)); } else {/*w w w .j a v a 2 s .c o m*/ throw new JSONSerializationException("Unknown primitive: " + type); } } else if (type == String.class) { Array.set(array, index, jsonArray.getString(index)); } else if (JSONSerializable.class.isAssignableFrom(type)) { JSONObject jObj = jsonArray.getJSONObject(index); JSONSerializable serObj = deSerialize(type, jObj); Array.set(array, index, serObj); } else if (type.isArray()) { Class componentClass = type.getComponentType(); JSONArray subArray = jsonArray.getJSONArray(index); int len = subArray.length(); Object newArray = Array.newInstance(componentClass, len); for (int k = 0; k < len; ++k) { loadObject(newArray, componentClass, k, subArray); } } }
From source file:org.jtwig.util.ArrayUtil.java
public static Object[] toArray(Object obj) { if (!obj.getClass().isArray()) { throw new IllegalArgumentException("Argument is not an array"); }/* w w w . ja v a2s . c om*/ Class<?> type = obj.getClass().getComponentType(); if (!type.isPrimitive()) { return (Object[]) obj; } if (Byte.TYPE.isAssignableFrom(type)) { return toArray((byte[]) obj); } if (Short.TYPE.isAssignableFrom(type)) { return toArray((short[]) obj); } if (Integer.TYPE.isAssignableFrom(obj.getClass().getComponentType())) { return toArray((int[]) obj); } if (Long.TYPE.isAssignableFrom(obj.getClass().getComponentType())) { return toArray((long[]) obj); } if (Boolean.TYPE.isAssignableFrom(obj.getClass().getComponentType())) { return toArray((boolean[]) obj); } if (Character.TYPE.isAssignableFrom(obj.getClass().getComponentType())) { return toArray((char[]) obj); } if (Float.TYPE.isAssignableFrom(obj.getClass().getComponentType())) { return toArray((float[]) obj); } if (Double.TYPE.isAssignableFrom(obj.getClass().getComponentType())) { return toArray((double[]) obj); } throw new IllegalArgumentException("Unsupported argument type: " + type.getName()); }
From source file:io.amira.zen.layout.ZenViewProxy.java
private void _fill_classes() { class_convert = new HashMap<Class, Class>(); class_convert.put(Integer.class, Integer.TYPE); class_convert.put(Float.class, Float.TYPE); class_convert.put(Double.class, Double.TYPE); class_convert.put(Boolean.class, Boolean.TYPE); }
From source file:com.autonomy.aci.client.annotations.ConversionServiceImpl.java
public ConversionServiceImpl() { registerConverter(new StringToDoubleConverter(), String.class, Double.class); registerConverter(new StringToDoubleConverter(), String.class, Double.TYPE); registerConverter(new StringToByteConverter(), String.class, Byte.class); registerConverter(new StringToByteConverter(), String.class, Byte.TYPE); registerConverter(new StringToIntegerConverter(), String.class, Integer.class); registerConverter(new StringToIntegerConverter(), String.class, Integer.TYPE); registerConverter(new StringToFloatConverter(), String.class, Float.class); registerConverter(new StringToFloatConverter(), String.class, Float.TYPE); registerConverter(new StringToShortConverter(), String.class, Short.class); registerConverter(new StringToShortConverter(), String.class, Short.TYPE); registerConverter(new StringToCharacterConverter(), String.class, Character.class); registerConverter(new StringToCharacterConverter(), String.class, Character.TYPE); registerConverter(new StringToBooleanConverter(), String.class, Boolean.class); registerConverter(new StringToBooleanConverter(), String.class, Boolean.TYPE); registerConverter(new StringToLongConverter(), String.class, Long.class); registerConverter(new StringToLongConverter(), String.class, Long.TYPE); }
From source file:org.dhatim.javabean.BeanUtils.java
/** * Create the bean setter method instance for this visitor. * * @param setterName The setter method name. * @param setterParamType/*from www.j a v a 2 s . co m*/ * @return The bean setter method. */ public static Method createSetterMethod(String setterName, Object bean, Class<?> setterParamType) { Method beanSetterMethod = ClassUtil.getSetterMethod(setterName, bean, setterParamType); // Try it as a list... if (beanSetterMethod == null && List.class.isAssignableFrom(setterParamType)) { String setterNamePlural = setterName + "s"; // Try it as a List using the plural name... beanSetterMethod = ClassUtil.getSetterMethod(setterNamePlural, bean, setterParamType); if (beanSetterMethod == null) { // Try it as an array using the non-plural name... } } // Try it as a primitive... if (beanSetterMethod == null && Integer.class.isAssignableFrom(setterParamType)) { beanSetterMethod = ClassUtil.getSetterMethod(setterName, bean, Integer.TYPE); } if (beanSetterMethod == null && Long.class.isAssignableFrom(setterParamType)) { beanSetterMethod = ClassUtil.getSetterMethod(setterName, bean, Long.TYPE); } if (beanSetterMethod == null && Float.class.isAssignableFrom(setterParamType)) { beanSetterMethod = ClassUtil.getSetterMethod(setterName, bean, Float.TYPE); } if (beanSetterMethod == null && Double.class.isAssignableFrom(setterParamType)) { beanSetterMethod = ClassUtil.getSetterMethod(setterName, bean, Double.TYPE); } if (beanSetterMethod == null && Character.class.isAssignableFrom(setterParamType)) { beanSetterMethod = ClassUtil.getSetterMethod(setterName, bean, Character.TYPE); } if (beanSetterMethod == null && Short.class.isAssignableFrom(setterParamType)) { beanSetterMethod = ClassUtil.getSetterMethod(setterName, bean, Short.TYPE); } if (beanSetterMethod == null && Byte.class.isAssignableFrom(setterParamType)) { beanSetterMethod = ClassUtil.getSetterMethod(setterName, bean, Byte.TYPE); } if (beanSetterMethod == null && Boolean.class.isAssignableFrom(setterParamType)) { beanSetterMethod = ClassUtil.getSetterMethod(setterName, bean, Boolean.TYPE); } return beanSetterMethod; }
From source file:com.csipsimple.utils.Columns.java
public Columns(String[] names, Class<?>[] classes) { this.names = names; types = new Type[names.length]; for (int i = 0; i < names.length; i++) { if (classes[i] == String.class) { types[i] = Type.STRING; } else if (classes[i] == Integer.TYPE || classes[i] == Integer.class) { types[i] = Type.INT;//from www. ja v a 2 s . c om } else if (classes[i] == Long.TYPE || classes[i] == Long.class) { types[i] = Type.LONG; } else if (classes[i] == Float.TYPE || classes[i] == Float.class) { types[i] = Type.FLOAT; } else if (classes[i] == Double.TYPE || classes[i] == Double.class) { types[i] = Type.DOUBLE; } else if (classes[i] == Boolean.TYPE || classes[i] == Boolean.class) { types[i] = Type.BOOLEAN; } } }