List of usage examples for java.lang Byte TYPE
Class TYPE
To view the source code for java.lang Byte TYPE.
Click Source Link
From source file:com.xwtec.xwserver.util.json.util.JSONUtils.java
/** * Tests if Class represents a primitive number or wrapper.<br> *///w w w. ja va 2s. c om public static boolean isNumber(Class clazz) { return clazz != null && (Byte.TYPE.isAssignableFrom(clazz) || Short.TYPE.isAssignableFrom(clazz) || Integer.TYPE.isAssignableFrom(clazz) || Long.TYPE.isAssignableFrom(clazz) || Float.TYPE.isAssignableFrom(clazz) || Double.TYPE.isAssignableFrom(clazz) || Number.class.isAssignableFrom(clazz)); }
From source file:net.sf.json.JSONDynaBean.java
/** * DOCUMENT ME!/*from w ww.j av a 2 s . com*/ * * @param dest DOCUMENT ME! * @param src DOCUMENT ME! * * @return DOCUMENT ME! */ protected boolean isDynaAssignable(Class dest, Class src) { boolean assignable = dest.isAssignableFrom(src); assignable = ((dest == Boolean.TYPE) && (src == Boolean.class)) ? true : assignable; assignable = ((dest == Byte.TYPE) && (src == Byte.class)) ? true : assignable; assignable = ((dest == Character.TYPE) && (src == Character.class)) ? true : assignable; assignable = ((dest == Short.TYPE) && (src == Short.class)) ? true : assignable; assignable = ((dest == Integer.TYPE) && (src == Integer.class)) ? true : assignable; assignable = ((dest == Long.TYPE) && (src == Long.class)) ? true : assignable; assignable = ((dest == Float.TYPE) && (src == Float.class)) ? true : assignable; assignable = ((dest == Double.TYPE) && (src == Double.class)) ? true : assignable; if ((src == Double.TYPE) || Double.class.isAssignableFrom(src)) { assignable = (isByte(dest) || isShort(dest) || isInteger(dest) || isLong(dest) || isFloat(dest)) ? true : assignable; } if ((src == Float.TYPE) || Float.class.isAssignableFrom(src)) { assignable = (isByte(dest) || isShort(dest) || isInteger(dest) || isLong(dest)) ? true : assignable; } if ((src == Long.TYPE) || Long.class.isAssignableFrom(src)) { assignable = (isByte(dest) || isShort(dest) || isInteger(dest)) ? true : assignable; } if ((src == Integer.TYPE) || Integer.class.isAssignableFrom(src)) { assignable = (isByte(dest) || isShort(dest)) ? true : assignable; } if ((src == Short.TYPE) || Short.class.isAssignableFrom(src)) { assignable = (isByte(dest)) ? true : assignable; } return assignable; }
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;//from w ww.j ava2 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] = 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.lunarray.model.descriptor.converter.def.AbstractDefaultConverterTool.java
/** * Populates the simple converters./* w w w . ja v a 2s .c om*/ */ private void populateSimpleConverters() { // Primitives. this.converters.put(Integer.TYPE, new IntegerConverter()); this.converters.put(Double.TYPE, new DoubleConverter()); this.converters.put(Float.TYPE, new FloatConverter()); this.converters.put(Long.TYPE, new LongConverter()); this.converters.put(Byte.TYPE, new ByteConverter()); this.converters.put(Short.TYPE, new ShortConverter()); this.converters.put(Character.TYPE, new CharacterConverter()); this.converters.put(Boolean.TYPE, new BooleanConverter()); // Date types. this.addConverter(new CalendarConverter()); this.addConverter(new DateConverter()); // SQL Date types. this.addConverter(new SqlDateConverter()); this.addConverter(new SqlTimeConverter()); this.addConverter(new SqlTimestampConverter()); // String. this.addConverter(new IdempotentConverter()); // Numbers. this.addConverter(new IntegerConverter()); this.addConverter(new DoubleConverter()); this.addConverter(new FloatConverter()); this.addConverter(new LongConverter()); this.addConverter(new ByteConverter()); this.addConverter(new ShortConverter()); // Character. this.addConverter(new CharacterConverter()); // Math types. this.addConverter(new BigDecimalConverter()); this.addConverter(new BigIntegerConverter()); // Boolean. this.addConverter(new BooleanConverter()); }
From source file:com.xwtec.xwserver.util.json.util.JSONUtils.java
/** * Tests if obj is a primitive number or wrapper.<br> *//*from w w w .j av a 2s . c om*/ 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.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; }/*from w w w .j a v a 2s . c o m*/ // 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.openlegacy.db.mvc.rest.DefaultDbRestController.java
private static Object toObject(Class<?> clazz, String value) { if (Boolean.class == clazz || Boolean.TYPE == clazz) { return Boolean.parseBoolean(value); }/*w w w . jav a2 s .c om*/ if (Byte.class == clazz || Byte.TYPE == clazz) { return Byte.parseByte(value); } if (Short.class == clazz || Short.TYPE == clazz) { return Short.parseShort(value); } if (Integer.class == clazz || Integer.TYPE == clazz) { return Integer.parseInt(value); } if (Long.class == clazz || Long.TYPE == clazz) { return Long.parseLong(value); } if (Float.class == clazz || Float.TYPE == clazz) { return Float.parseFloat(value); } if (Double.class == clazz || Double.TYPE == clazz) { return Double.parseDouble(value); } return value; }
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 ww .j a v a2s . c o 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.sun.faces.renderkit.html_basic.MenuRenderer.java
protected Object handleArrayCase(FacesContext context, UISelectMany uiSelectMany, Class arrayClass, String[] newValues) throws ConverterException { Object result = null;//from ww w . j av a 2 s . com Class elementType = null; Converter converter = null; int i = 0, len = (null != newValues ? newValues.length : 0); elementType = arrayClass.getComponentType(); // Optimization: If the elementType is String, we don't need // conversion. Just return newValues. if (elementType.equals(String.class)) { return newValues; } try { result = Array.newInstance(elementType, len); } catch (Exception e) { throw new ConverterException(e); } // bail out now if we have no new values, returning our // oh-so-useful zero-length array. if (null == newValues) { return result; } // obtain a converter. // attached converter takes priority if (null == (converter = uiSelectMany.getConverter())) { // Otherwise, look for a by-type converter if (null == (converter = Util.getConverterForClass(elementType, context))) { // if that fails, and the attached values are of Object type, // we don't need conversion. if (elementType.equals(Object.class)) { return newValues; } String valueStr = ""; for (i = 0; i < newValues.length; i++) { valueStr = valueStr + " " + newValues[i]; } Object[] params = { valueStr, "null Converter" }; throw new ConverterException(Util.getExceptionMessage(Util.CONVERSION_ERROR_MESSAGE_ID, params)); } } Util.doAssert(null != result); if (elementType.isPrimitive()) { for (i = 0; i < len; i++) { if (elementType.equals(Boolean.TYPE)) { Array.setBoolean(result, i, ((Boolean) converter.getAsObject(context, uiSelectMany, newValues[i])).booleanValue()); } else if (elementType.equals(Byte.TYPE)) { Array.setByte(result, i, ((Byte) converter.getAsObject(context, uiSelectMany, newValues[i])).byteValue()); } else if (elementType.equals(Double.TYPE)) { Array.setDouble(result, i, ((Double) converter.getAsObject(context, uiSelectMany, newValues[i])).doubleValue()); } else if (elementType.equals(Float.TYPE)) { Array.setFloat(result, i, ((Float) converter.getAsObject(context, uiSelectMany, newValues[i])).floatValue()); } else if (elementType.equals(Integer.TYPE)) { Array.setInt(result, i, ((Integer) converter.getAsObject(context, uiSelectMany, newValues[i])).intValue()); } else if (elementType.equals(Character.TYPE)) { Array.setChar(result, i, ((Character) converter.getAsObject(context, uiSelectMany, newValues[i])).charValue()); } else if (elementType.equals(Short.TYPE)) { Array.setShort(result, i, ((Short) converter.getAsObject(context, uiSelectMany, newValues[i])).shortValue()); } else if (elementType.equals(Long.TYPE)) { Array.setLong(result, i, ((Long) converter.getAsObject(context, uiSelectMany, newValues[i])).longValue()); } } } else { for (i = 0; i < len; i++) { if (log.isDebugEnabled()) { Object converted = converter.getAsObject(context, uiSelectMany, newValues[i]); log.debug("String value: " + newValues[i] + " converts to : " + converted.toString()); } Array.set(result, i, converter.getAsObject(context, uiSelectMany, newValues[i])); } } 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();/* w ww .j a va2s . c o 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(); }