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.lunarray.model.descriptor.scanner.AnnotationMetaModelProcessor.java
/** * Copy array values./*from ww w. j a va 2 s. c om*/ * * @param values * The array values. * @param name * The property name. * @param obj * The object value. * @param type * The array type. * @throws MappingException * Thrown if the mapping was unsuccessful. */ private void arrayCopy(final AnnotationMetaValues values, final String name, final Object obj, final Class<?> type) throws MappingException { try { final Class<?> compType = type.getComponentType(); if (Integer.TYPE.equals(compType)) { final int[] array = int[].class.cast(obj); for (final int a : array) { values.getMetaValueList(name).add(this.converterTool.convertToString(Integer.TYPE, a)); } } else if (Long.TYPE.equals(compType)) { final long[] array = long[].class.cast(obj); for (final long a : array) { values.getMetaValueList(name).add(this.converterTool.convertToString(Long.TYPE, a)); } } else { this.copyShortNumbers(values, name, obj, type, compType); } } catch (final ConverterException e) { throw new MappingException(e); } }
From source file:com.haulmont.restapi.service.QueriesControllerManager.java
protected Object toObject(Class clazz, String value) throws ParseException { if (clazz.isArray()) { Class componentType = clazz.getComponentType(); JsonParser jsonParser = new JsonParser(); JsonArray jsonArray = jsonParser.parse(value).getAsJsonArray(); List result = new ArrayList(); for (JsonElement jsonElement : jsonArray) { String stringValue = (jsonElement.isJsonPrimitive() && jsonElement.getAsJsonPrimitive().isString()) ? jsonElement.getAsJsonPrimitive().getAsString() : jsonElement.toString(); Object arrayElementValue = toObject(componentType, stringValue); result.add(arrayElementValue); }/*from ww w. j av a2s . c o m*/ return result; } if (String.class == clazz) return value; if (Integer.class == clazz || Integer.TYPE == clazz || Byte.class == clazz || Byte.TYPE == clazz || Short.class == clazz || Short.TYPE == clazz) return Datatypes.getNN(Integer.class).parse(value); if (Date.class == clazz) { try { return Datatypes.getNN(Date.class).parse(value); } catch (ParseException e) { try { return Datatypes.getNN(java.sql.Date.class).parse(value); } catch (ParseException e1) { return Datatypes.getNN(Time.class).parse(value); } } } if (BigDecimal.class == clazz) return Datatypes.getNN(BigDecimal.class).parse(value); if (Boolean.class == clazz || Boolean.TYPE == clazz) return Datatypes.getNN(Boolean.class).parse(value); if (Long.class == clazz || Long.TYPE == clazz) return Datatypes.getNN(Long.class).parse(value); if (Double.class == clazz || Double.TYPE == clazz || Float.class == clazz || Float.TYPE == clazz) return Datatypes.getNN(Double.class).parse(value); if (UUID.class == clazz) return UUID.fromString(value); throw new IllegalArgumentException("Parameters of type " + clazz.getName() + " are not supported"); }
From source file:com.jaliansystems.activeMQLite.impl.ObjectRepository.java
private boolean paramMatches(Method method, Object[] params) { Class<?>[] parameterTypes = method.getParameterTypes(); if (params != null && parameterTypes.length != params.length || params == null && parameterTypes.length != 0) return false; for (int i = 0; i < parameterTypes.length; i++) { Class<?> class1 = parameterTypes[i]; if (!class1.isPrimitive() && params[i] == null) continue; if (params[i] instanceof ObjectHandle) { params[i] = getObject(((ObjectHandle) params[i])); }/* w w w . j av a 2s . co m*/ if (class1.isPrimitive()) { if (params[i] instanceof Boolean && class1 != Boolean.TYPE) return false; if (params[i] instanceof Integer && class1 != Integer.TYPE) return false; if (params[i] instanceof Long && class1 != Long.TYPE) return false; if (params[i] instanceof Short && class1 != Short.TYPE) return false; if (params[i] instanceof Float && class1 != Float.TYPE) return false; if (params[i] instanceof Double && class1 != Double.TYPE) return false; if (params[i] instanceof Byte && class1 != Byte.TYPE) return false; } else if (!class1.isInstance(params[i])) return false; } return true; }
From source file:com.icesoft.faces.renderkit.dom_html_basic.MenuRenderer.java
protected Object convertArray(FacesContext facesContext, UISelectMany uiSelectMany, Class componentType, String[] newSubmittedValues) throws ConverterException { // component type of String means no conversion is necessary if (componentType.equals(String.class)) { return newSubmittedValues; }/*w w w.j a v a2s . c om*/ // if newSubmittedValue is null return zero-length array if (newSubmittedValues == null) { return Array.newInstance(componentType, 0); } // create the array with specified component length int numberOfValues = newSubmittedValues.length; Object convertedValues = Array.newInstance(componentType, numberOfValues); // Determine if a converter is explicitly registered with the component Converter converter = uiSelectMany.getConverter(); if (converter == null) { // Determine if there is a default converter for the class converter = getConverterForClass(componentType); } if (converter == null) { // we don't need to convert base Object types if (componentType.equals(Object.class)) { return newSubmittedValues; } else { throw new ConverterException("Converter is null"); } } for (int index = 0; index < numberOfValues; index++) { // convert the next element Object nextConvertedElement = converter.getAsObject(facesContext, uiSelectMany, newSubmittedValues[index]); if (!componentType.isPrimitive()) { Array.set(convertedValues, index, nextConvertedElement); } else if (componentType.equals(Boolean.TYPE)) { Array.setBoolean(convertedValues, index, ((Boolean) nextConvertedElement).booleanValue()); } else if (componentType.equals(Integer.TYPE)) { Array.setInt(convertedValues, index, ((Integer) nextConvertedElement).intValue()); } else if (componentType.equals(Long.TYPE)) { Array.setLong(convertedValues, index, ((Long) nextConvertedElement).longValue()); } else if (componentType.equals(Short.TYPE)) { Array.setShort(convertedValues, index, ((Short) nextConvertedElement).shortValue()); } else if (componentType.equals(Byte.TYPE)) { Array.setByte(convertedValues, index, ((Byte) nextConvertedElement).byteValue()); } else if (componentType.equals(Float.TYPE)) { Array.setFloat(convertedValues, index, ((Float) nextConvertedElement).floatValue()); } else if (componentType.equals(Double.TYPE)) { Array.setDouble(convertedValues, index, ((Double) nextConvertedElement).doubleValue()); } else if (componentType.equals(Character.TYPE)) { Array.setChar(convertedValues, index, ((Character) nextConvertedElement).charValue()); } } return convertedValues; }
From source file:org.openamf.io.AMFSerializer.java
protected Object[] convertPrimitiveArrayToObjectArray(Object array) throws IOException { Class componentType = array.getClass().getComponentType(); Object[] result = null;// w w w . j a v a2 s. c o m if (componentType == null) { throw new NullPointerException("componentType is null"); } else if (componentType == Character.TYPE) { char[] carray = (char[]) array; result = new Object[carray.length]; for (int i = 0; i < carray.length; i++) { result[i] = new Character(carray[i]); } } else if (componentType == Byte.TYPE) { byte[] barray = (byte[]) array; result = new Object[barray.length]; for (int i = 0; i < barray.length; i++) { result[i] = new Byte(barray[i]); } } else if (componentType == Short.TYPE) { short[] sarray = (short[]) array; result = new Object[sarray.length]; for (int i = 0; i < sarray.length; i++) { result[i] = new Short(sarray[i]); } } else if (componentType == Integer.TYPE) { int[] iarray = (int[]) array; result = new Object[iarray.length]; for (int i = 0; i < iarray.length; i++) { result[i] = new Integer(iarray[i]); } } else if (componentType == Long.TYPE) { long[] larray = (long[]) array; result = new Object[larray.length]; for (int i = 0; i < larray.length; i++) { result[i] = new Long(larray[i]); } } else if (componentType == Double.TYPE) { double[] darray = (double[]) array; result = new Object[darray.length]; for (int i = 0; i < darray.length; i++) { result[i] = new Double(darray[i]); } } else if (componentType == Float.TYPE) { float[] farray = (float[]) array; result = new Object[farray.length]; for (int i = 0; i < farray.length; i++) { result[i] = new Float(farray[i]); } } else if (componentType == Boolean.TYPE) { boolean[] barray = (boolean[]) array; result = new Object[barray.length]; for (int i = 0; i < barray.length; i++) { result[i] = new Boolean(barray[i]); } } else { throw new IllegalArgumentException("unexpected component type: " + componentType.getClass().getName()); } return result; }
From source file:com.xwtec.xwserver.util.json.util.JSONUtils.java
/** * Tests if obj is a primitive number or wrapper.<br> *///from w ww . j a v a 2s .c o m public static boolean isNumber(Object obj) { if ((obj != null && obj.getClass() == Byte.TYPE) || (obj != null && obj.getClass() == Short.TYPE) || (obj != null && obj.getClass() == Integer.TYPE) || (obj != null && obj.getClass() == Long.TYPE) || (obj != null && obj.getClass() == Float.TYPE) || (obj != null && obj.getClass() == Double.TYPE)) { return true; } return obj instanceof Number; }
From source file:com.aliyun.fs.oss.utils.OSSClientAgent.java
@SuppressWarnings("unchecked") private OSSObject getObject(String bucket, String key, long start, long end, Configuration conf, boolean retry) throws IOException, ServiceException, ClientException { InputStream inputStream;/*from w w w . j a v a2 s .c o m*/ try { Class GetObjectRequestClz = ResourceLoader.getInstance().getUrlClassLoader(conf) .loadClass("com.aliyun.oss.model.GetObjectRequest"); Constructor cons0 = GetObjectRequestClz.getConstructor(String.class, String.class); Object getObjRequest = cons0.newInstance(bucket, key); Method method0 = GetObjectRequestClz.getMethod("setRange", Long.TYPE, Long.TYPE); method0.invoke(getObjRequest, start, end); Method method = this.ossClientClz.getMethod("getObject", GetObjectRequestClz); Object ret = method.invoke(this.ossClient, getObjRequest); Class OSSObjectClz = ResourceLoader.getInstance().getUrlClassLoader(conf) .loadClass("com.aliyun.oss.model.OSSObject"); Method method1 = OSSObjectClz.getMethod("getObjectContent"); inputStream = (InputStream) method1.invoke(ret); GsonBuilder builder = new GsonBuilder(); builder.registerTypeAdapter(ObjectMetadata.class, new ObjectMetadataDeserializer()); Gson gson = builder.create(); Method method2 = OSSObjectClz.getMethod("getObjectMetadata"); Object metadata = method2.invoke(ret); ObjectMetadata objectMetadata = gson.fromJson(gson.toJson(metadata), ObjectMetadata.class); OSSObject ossObject = new OSSObject(); ossObject.setBucketName(bucket); ossObject.setKey(key); ossObject.setObjectContent(inputStream); ossObject.setObjectMetadata(objectMetadata); return ossObject; } catch (Exception e) { if (retry && updateOSSClient(e)) { return getObject(bucket, key, start, end, conf, false); } else { handleException(e); return null; } } }
From source file:net.sf.qooxdoo.rpc.RemoteCallUtils.java
/** * Converts "normal" java types to JSON stuff. * * @param obj the object to convert. */// w w w . j a v a 2 s . c om public Object fromJava(Object obj) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { if (obj == null) { return JSONObject.NULL; } if (obj instanceof String) { return obj; } if (obj instanceof Date) { return obj; } if (obj instanceof Integer || obj instanceof Double || obj instanceof Boolean) { return obj; } if (obj instanceof Float) { return new Double(((Float) obj).doubleValue()); } // FIXME: find a better way to handle longs if (obj instanceof Long) { return new Double(((Long) obj).doubleValue()); } if (obj instanceof Object[]) { Object[] objectArray = (Object[]) obj; JSONArray jsonArray = new JSONArray(); for (int i = 0; i < objectArray.length; ++i) { jsonArray.put(fromJava(objectArray[i])); } return jsonArray; } Class componentType = obj.getClass().getComponentType(); if (componentType == Integer.TYPE) { JSONArray jsonArray = new JSONArray(); int[] intArray = (int[]) obj; for (int i = 0; i < intArray.length; ++i) { jsonArray.put(intArray[i]); } return jsonArray; } if (componentType == Float.TYPE) { JSONArray jsonArray = new JSONArray(); float[] floatArray = (float[]) obj; for (int i = 0; i < floatArray.length; ++i) { jsonArray.put((double) (floatArray[i])); } return jsonArray; } // FIXME: find a better way to handle longs if (componentType == Long.TYPE) { JSONArray jsonArray = new JSONArray(); long[] longArray = (long[]) obj; for (int i = 0; i < longArray.length; ++i) { jsonArray.put((double) (longArray[i])); } return jsonArray; } if (componentType == Double.TYPE) { JSONArray jsonArray = new JSONArray(); double[] doubleArray = (double[]) obj; for (int i = 0; i < doubleArray.length; ++i) { jsonArray.put(doubleArray[i]); } return jsonArray; } if (componentType == Boolean.TYPE) { JSONArray jsonArray = new JSONArray(); boolean[] booleanArray = (boolean[]) obj; for (int i = 0; i < booleanArray.length; ++i) { jsonArray.put(booleanArray[i]); } return jsonArray; } if (obj instanceof Map) { Map map = (Map) obj; Iterator keyIterator = map.keySet().iterator(); JSONObject jsonObject = new JSONObject(); Object key; while (keyIterator.hasNext()) { key = keyIterator.next(); jsonObject.put((key == null ? null : key.toString()), fromJava(map.get(key))); } return jsonObject; } if (obj instanceof Set) { Set set = (Set) obj; Iterator iterator = set.iterator(); JSONObject jsonObject = new JSONObject(); Object key; while (iterator.hasNext()) { key = iterator.next(); jsonObject.put((key == null ? null : key.toString()), true); } return jsonObject; } return fromJava(filter(obj, PropertyUtils.describe(obj))); }
From source file:com.exadel.flamingo.flex.messaging.amf.io.AMF0Serializer.java
protected Object[] convertPrimitiveArrayToObjectArray(Object array) { Class<?> componentType = array.getClass().getComponentType(); Object[] result = null;/* w w w .j a va 2 s .co m*/ if (componentType == null) { throw new NullPointerException("componentType is null"); } else if (componentType == Character.TYPE) { char[] carray = (char[]) array; result = new Object[carray.length]; for (int i = 0; i < carray.length; i++) { result[i] = new Character(carray[i]); } } else if (componentType == Byte.TYPE) { byte[] barray = (byte[]) array; result = new Object[barray.length]; for (int i = 0; i < barray.length; i++) { result[i] = new Byte(barray[i]); } } else if (componentType == Short.TYPE) { short[] sarray = (short[]) array; result = new Object[sarray.length]; for (int i = 0; i < sarray.length; i++) { result[i] = new Short(sarray[i]); } } else if (componentType == Integer.TYPE) { int[] iarray = (int[]) array; result = new Object[iarray.length]; for (int i = 0; i < iarray.length; i++) { result[i] = Integer.valueOf(iarray[i]); } } else if (componentType == Long.TYPE) { long[] larray = (long[]) array; result = new Object[larray.length]; for (int i = 0; i < larray.length; i++) { result[i] = new Long(larray[i]); } } else if (componentType == Double.TYPE) { double[] darray = (double[]) array; result = new Object[darray.length]; for (int i = 0; i < darray.length; i++) { result[i] = new Double(darray[i]); } } else if (componentType == Float.TYPE) { float[] farray = (float[]) array; result = new Object[farray.length]; for (int i = 0; i < farray.length; i++) { result[i] = new Float(farray[i]); } } else if (componentType == Boolean.TYPE) { boolean[] barray = (boolean[]) array; result = new Object[barray.length]; for (int i = 0; i < barray.length; i++) { result[i] = new Boolean(barray[i]); } } else { throw new IllegalArgumentException("unexpected component type: " + componentType.getClass().getName()); } return result; }
From source file:org.nuxeo.ecm.automation.io.services.codec.ObjectCodecService.java
protected final void writeGenericObject(JsonGenerator jg, Class<?> clazz, Object object) throws IOException { jg.writeStartObject();//from ww w .j a v a 2 s. co m if (clazz.isPrimitive()) { if (clazz == Boolean.TYPE) { jg.writeStringField("entity-type", "boolean"); jg.writeBooleanField("value", (Boolean) object); } else if (clazz == Double.TYPE || clazz == Float.TYPE) { jg.writeStringField("entity-type", "number"); jg.writeNumberField("value", ((Number) object).doubleValue()); } else if (clazz == Integer.TYPE || clazz == Long.TYPE || clazz == Short.TYPE || clazz == Byte.TYPE) { jg.writeStringField("entity-type", "number"); jg.writeNumberField("value", ((Number) object).longValue()); } else if (clazz == Character.TYPE) { jg.writeStringField("entity-type", "string"); jg.writeStringField("value", object.toString()); } return; } if (jg.getCodec() == null) { jg.setCodec(new ObjectMapper()); } if (object instanceof Iterable && clazz.getName().startsWith("java.")) { jg.writeStringField("entity-type", "list"); } else if (object instanceof Map && clazz.getName().startsWith("java.")) { if (object instanceof LinkedHashMap) { jg.writeStringField("entity-type", "orderedMap"); } else { jg.writeStringField("entity-type", "map"); } } else { jg.writeStringField("entity-type", clazz.getName()); } jg.writeObjectField("value", object); jg.writeEndObject(); }