List of usage examples for java.lang Long TYPE
Class TYPE
To view the source code for java.lang Long TYPE.
Click Source Link
From source file:org.mule.util.ArrayUtils.java
/** * Like {@link #toString(Object)} but considers at most <code>maxElements</code> * values; overflow is indicated by an appended "[..]" ellipsis. *///from w w w. j a v a 2 s . c o m public static String toString(Object array, int maxElements) { String result; Class componentType = array.getClass().getComponentType(); if (Object.class.isAssignableFrom(componentType)) { result = ArrayUtils.toString((ArrayUtils.subarray((Object[]) array, 0, maxElements))); } else if (componentType.equals(Boolean.TYPE)) { result = ArrayUtils.toString((ArrayUtils.subarray((boolean[]) array, 0, maxElements))); } else if (componentType.equals(Byte.TYPE)) { result = ArrayUtils.toString((ArrayUtils.subarray((byte[]) array, 0, maxElements))); } else if (componentType.equals(Character.TYPE)) { result = ArrayUtils.toString((ArrayUtils.subarray((char[]) array, 0, maxElements))); } else if (componentType.equals(Short.TYPE)) { result = ArrayUtils.toString((ArrayUtils.subarray((short[]) array, 0, maxElements))); } else if (componentType.equals(Integer.TYPE)) { result = ArrayUtils.toString((ArrayUtils.subarray((int[]) array, 0, maxElements))); } else if (componentType.equals(Long.TYPE)) { result = ArrayUtils.toString((ArrayUtils.subarray((long[]) array, 0, maxElements))); } else if (componentType.equals(Float.TYPE)) { result = ArrayUtils.toString((ArrayUtils.subarray((float[]) array, 0, maxElements))); } else if (componentType.equals(Double.TYPE)) { result = ArrayUtils.toString((ArrayUtils.subarray((double[]) array, 0, maxElements))); } else { throw new IllegalArgumentException("Unknown array service type: " + componentType.getName()); } if (Array.getLength(array) > maxElements) { StringBuffer buf = new StringBuffer(result); buf.insert(buf.length() - 1, " [..]"); result = buf.toString(); } return result; }
From source file:Util.java
/** * Is the given {@code object} a primitive type or wrapper for a primitive * type?/*from w ww . j a v a2s . c o 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 w w .j a va 2 s. com*/ 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 {/*from w w w . ja v a 2s . 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"); }//from w w w .j a v a 2s .c o m 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:com.inversoft.json.ZonedDateTimeDeserializer.java
public ZonedDateTimeDeserializer() { super(Long.TYPE); }
From source file:nz.co.senanque.validationengine.ConvertUtils.java
public static Comparable<?> convertTo(Class<?> clazz, Object obj) { if (obj == null) { return null; }/*from w w w. j av a 2 s. c o m*/ if (clazz.isAssignableFrom(obj.getClass())) { return (Comparable<?>) obj; } if (clazz.isPrimitive()) { if (clazz.equals(Long.TYPE)) { clazz = Long.class; } else if (clazz.equals(Integer.TYPE)) { clazz = Integer.class; } else if (clazz.equals(Float.TYPE)) { clazz = Float.class; } else if (clazz.equals(Double.TYPE)) { clazz = Double.class; } else if (clazz.equals(Boolean.TYPE)) { clazz = Boolean.class; } } if (Number.class.isAssignableFrom(clazz)) { if (obj.getClass().equals(String.class)) { obj = new Double((String) obj); } if (!Number.class.isAssignableFrom(obj.getClass())) { throw new RuntimeException( "Cannot convert from " + obj.getClass().getName() + " to " + clazz.getName()); } Number number = (Number) obj; if (clazz.equals(Long.class)) { return new Long(number.longValue()); } if (clazz.equals(Integer.class)) { return new Integer(number.intValue()); } if (clazz.equals(Float.class)) { return new Float(number.floatValue()); } if (clazz.equals(Double.class)) { return new Double(number.doubleValue()); } if (clazz.equals(BigDecimal.class)) { return new BigDecimal(number.doubleValue()); } } final String oStr = String.valueOf(obj); if (clazz.equals(String.class)) { return oStr; } if (clazz.equals(java.util.Date.class)) { return java.sql.Date.valueOf(oStr); } if (clazz.equals(java.sql.Date.class)) { return java.sql.Date.valueOf(oStr); } if (clazz.equals(Boolean.class)) { return new Boolean(oStr); } throw new RuntimeException("Cannot convert from " + obj.getClass().getName() + " to " + clazz.getName()); }
From source file:com.ms.commons.summer.web.util.json.JsonNumberMorpher.java
/** * Creates a new morpher for the target type. * /*from w w w.ja va 2 s .c o m*/ * @param type must be a primitive or wrapper type. BigDecimal and BigInteger are also supported. */ public JsonNumberMorpher(Class<?> type) { super(false); if (type == null) { throw new MorphException("Must specify a type"); } if (type != Byte.TYPE && type != Short.TYPE && type != Integer.TYPE && type != Long.TYPE && type != Float.TYPE && type != Double.TYPE && !Byte.class.isAssignableFrom(type) && !Short.class.isAssignableFrom(type) && !Integer.class.isAssignableFrom(type) && !Long.class.isAssignableFrom(type) && !Float.class.isAssignableFrom(type) && !Double.class.isAssignableFrom(type) && !BigInteger.class.isAssignableFrom(type) && !BigDecimal.class.isAssignableFrom(type)) { throw new MorphException("Must specify a Number subclass"); } this.type = type; }
From source file:Main.java
public static String getPrimitiveLetter(Class<?> paramClass) { if (Integer.TYPE.equals(paramClass)) { return "I"; }/*w w w. jav a2 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: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 w w w. j a v a2 s . c o m } 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; } } }