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:org.briljantframework.data.resolver.Resolve.java
private static Resolver<Integer> initializeIntegerResolver() { Resolver<Integer> resolver = new Resolver<>(Integer.class); resolver.put(Number.class, Number::intValue); resolver.put(Double.class, Number::intValue); resolver.put(Double.TYPE, Number::intValue); resolver.put(Float.class, Number::intValue); resolver.put(Float.TYPE, Number::intValue); resolver.put(Long.class, Number::intValue); resolver.put(Long.TYPE, Number::intValue); resolver.put(Integer.class, Number::intValue); resolver.put(Integer.TYPE, Number::intValue); resolver.put(Short.class, Number::intValue); resolver.put(Short.TYPE, Number::intValue); resolver.put(Byte.class, Number::intValue); resolver.put(Byte.TYPE, Number::intValue); resolver.put(String.class, s -> { try {//from ww w .jav a 2 s.c om return NumberUtils.createNumber(s).intValue(); } catch (Exception e) { return null; } }); return resolver; }
From source file:com.projity.util.ClassUtils.java
/** * Get the corresponding object class from a primitive class * @param clazz primitive class//from w w w .j a va 2s . co m * @return Object class. * @throws ClassCastException if class is unknown primitive */ public static Class primitiveToObjectClass(Class clazz) { // return MethodUtils.toNonPrimitiveClass(clazz); if (clazz == Boolean.TYPE) return Boolean.class; else if (clazz == Character.TYPE) return Character.class; else if (clazz == Byte.TYPE) return Byte.class; else if (clazz == Short.TYPE) return Short.class; else if (clazz == Integer.TYPE) return Integer.class; else if (clazz == Long.TYPE) return Long.class; else if (clazz == Float.TYPE) return Float.class; else if (clazz == Double.TYPE) return Double.class; throw new ClassCastException("Cannot convert class" + clazz + " to an object class"); }
From source file:org.seasar.struts.lessconfig.factory.AbstractValidatorAnnotationHandler.java
protected String getAutoTypeValidatorName(PropertyDesc propDesc) { Class paramType = propDesc.getPropertyType(); if (paramType.isArray()) { paramType = paramType.getComponentType(); }/*from ww w. jav a 2 s. co m*/ if (paramType.equals(Byte.class) || paramType.equals(Byte.TYPE)) { return "byte"; } else if (Date.class.isAssignableFrom(paramType)) { return "date"; } else if (paramType.equals(Double.class) || paramType.equals(Double.TYPE)) { return "double"; } else if (paramType.equals(Float.class) || paramType.equals(Float.TYPE)) { return "float"; } else if (paramType.equals(Integer.class) || paramType.equals(Integer.TYPE)) { return "integer"; } else if (paramType.equals(Long.class) || paramType.equals(Long.TYPE)) { return "long"; } else if (paramType.equals(Short.class) || paramType.equals(Short.TYPE)) { return "short"; } return null; }
From source file:org.eiichiro.bootleg.AbstractRequest.java
/** * Returns the default value of the specified primitive type. * //from w ww . ja va 2 s.co m * @param type The primitive type. * @return The default value of the specified primitive type. */ protected Object primitive(Type type) { Class<?> rawType = Types.getRawType(type); if (rawType.equals(Boolean.TYPE)) { return (boolean) false; } else if (rawType.equals(Character.TYPE)) { return (char) 0; } else if (rawType.equals(Byte.TYPE)) { return (byte) 0; } else if (rawType.equals(Double.TYPE)) { return (double) 0.0; } else if (rawType.equals(Float.TYPE)) { return (float) 0.0; } else if (rawType.equals(Integer.TYPE)) { return (int) 0; } else { // short. return (short) 0; } }
From source file:pe.com.mmh.sisgap.utils.BasicDynaBean.java
/** * Return the value of a simple property with the specified name. * * @param name Name of the property whose value is to be retrieved * * @exception IllegalArgumentException if there is no property * of the specified name/*from w w w.j a v a 2 s . co m*/ */ public Object get(String name) { // Return any non-null value for the specified property Object value = values.get(name); if (value != null) { return (value); } // Return a null value for a non-primitive property Class type = getDynaProperty(name).getType(); if (!type.isPrimitive()) { return (value); } // Manufacture default values for primitive properties if (type == Boolean.TYPE) { return (Boolean.FALSE); } else if (type == Byte.TYPE) { return (new Byte((byte) 0)); } else if (type == Character.TYPE) { return (new Character((char) 0)); } else if (type == Double.TYPE) { return (new Double((double) 0.0)); } else if (type == Float.TYPE) { return (new Float((float) 0.0)); } else if (type == Integer.TYPE) { return (new Integer((int) 0)); } else if (type == Long.TYPE) { return (new Long((int) 0)); } else if (type == Short.TYPE) { return (new Short((short) 0)); } else { return (null); } }
From source file:com.nfwork.dbfound.json.JSONDynaBean.java
private boolean isByte(Class clazz) { return Byte.class.isAssignableFrom(clazz) || clazz == Byte.TYPE; }
From source file:org.briljantframework.data.vector.ConvertTest.java
@Test public void testTo_convertToByte() throws Exception { assertEquals(10, (byte) Convert.to(Byte.class, 10)); assertEquals(10, (byte) Convert.to(Byte.class, 10.0)); assertEquals(10, (byte) Convert.to(Byte.class, 10.0f)); assertEquals(10, (byte) Convert.to(Byte.class, 10l)); assertEquals(10, (byte) Convert.to(Byte.class, (short) 10)); assertEquals(10, (byte) Convert.to(Byte.class, (byte) 10)); assertEquals(10, (byte) Convert.to(Byte.class, Complex.valueOf(10))); assertEquals(1, (byte) Convert.to(Byte.class, Logical.TRUE)); assertEquals(1, (byte) Convert.to(Byte.class, true)); assertEquals(10, (byte) Convert.to(Byte.TYPE, 10)); assertEquals(10, (byte) Convert.to(Byte.TYPE, 10.0)); assertEquals(10, (byte) Convert.to(Byte.TYPE, 10.0f)); assertEquals(10, (byte) Convert.to(Byte.TYPE, 10l)); assertEquals(10, (byte) Convert.to(Byte.TYPE, (short) 10)); assertEquals(10, (byte) Convert.to(Byte.TYPE, (byte) 10)); assertEquals(10, (byte) Convert.to(Byte.TYPE, Complex.valueOf(10))); assertEquals(1, (byte) Convert.to(Byte.TYPE, Logical.TRUE)); assertEquals(1, (byte) Convert.to(Byte.TYPE, true)); }
From source file:org.romaframework.core.schema.SchemaField.java
protected Object convertValue(Object iFieldValue) { if (type == null || isArray()) return iFieldValue; SchemaClass typeClass = getType().getSchemaClass(); if (typeClass.equals(Roma.schema().getSchemaClass(iFieldValue))) return iFieldValue; String textValue = null;/*w w w .j ava 2 s.com*/ if (iFieldValue instanceof String) { textValue = (String) iFieldValue; } else if (iFieldValue != null) { textValue = iFieldValue.toString(); } Object value = null; if (textValue != null) { // TRY A SOFT CONVERSION if (typeClass.isOfType(Integer.class) || typeClass.isOfType(Integer.TYPE)) { try { value = textValue.equals("") ? null : Integer.parseInt(textValue); } catch (Exception e) { value = textValue.equals("") ? null : Double.valueOf(textValue).intValue(); } } else if (typeClass.isOfType(Long.class) || typeClass.isOfType(Long.TYPE)) { value = textValue.equals("") ? null : Long.parseLong(textValue); } else if (typeClass.isOfType(Short.class) || typeClass.isOfType(Short.TYPE)) { value = textValue.equals("") ? null : Short.parseShort(textValue); } else if (typeClass.isOfType(Byte.class) || typeClass.isOfType(Byte.TYPE)) { value = textValue.equals("") ? null : Byte.parseByte(textValue); } else if (typeClass.isOfType(Character.class) || typeClass.isOfType(Character.TYPE)) { if (textValue.length() > 0) { value = new Character(textValue.charAt(0)); } } else if (typeClass.isOfType(Float.class) || typeClass.isOfType(Float.TYPE)) { value = textValue.equals("") ? null : Float.parseFloat(textValue); } else if (typeClass.isOfType(Double.class) || typeClass.isOfType(Double.TYPE)) { value = textValue.equals("") ? null : Double.parseDouble(textValue); } else if (typeClass.isOfType(BigDecimal.class)) { value = textValue.equals("") ? null : new BigDecimal(textValue); } else if (iFieldValue != null && !typeClass.isArray() && iFieldValue.getClass().isArray()) { // DESTINATION VALUE IS NOT AN ARRAY: ASSIGN THE FIRST ONE ELEMENT value = ((Object[]) iFieldValue)[0]; } else { value = iFieldValue; } } if (value != null) { // TODO is this the right place to do this...? Class<?> valueClass = value.getClass(); // SUCH A MONSTER!!! MOVE THIS LOGIC IN SchemaClass.isAssignableFrom... if (value instanceof VirtualObject && !(typeClass.getLanguageType() instanceof Class<?> && ((Class<?>) typeClass.getLanguageType()).isAssignableFrom(VirtualObject.class)) && ((VirtualObject) value).getSuperClassObject() != null) { if (ComposedEntity.class .isAssignableFrom(((VirtualObject) value).getSuperClassObject().getClass())) { value = ((VirtualObject) value).getSuperClassObject(); valueClass = value.getClass(); } } if (value instanceof ComposedEntity<?> && !typeClass.isAssignableFrom(valueClass)) { value = ((ComposedEntity<?>) value).getEntity(); } } if (value == null && typeClass.isPrimitive()) { log.warn("Cannot set the field value to null for primitive types! Field: " + getEntity() + "." + name + " of class " + getType().getName() + ". Setting value to 0."); // SET THE VALUE TO 0 value = SchemaHelper.assignDefaultValueToLiteral(typeClass); } return value; }
From source file:org.openspaces.rest.utils.ControllerUtils.java
public static Object convertPropertyToPrimitiveType(String object, Class type, String propKey) { if (type.equals(Long.class) || type.equals(Long.TYPE)) return Long.valueOf(object); if (type.equals(Boolean.class) || type.equals(Boolean.TYPE)) return Boolean.valueOf(object); if (type.equals(Integer.class) || type.equals(Integer.TYPE)) return Integer.valueOf(object); if (type.equals(Byte.class) || type.equals(Byte.TYPE)) return Byte.valueOf(object); if (type.equals(Short.class) || type.equals(Short.TYPE)) return Short.valueOf(object); if (type.equals(Float.class) || type.equals(Float.TYPE)) return Float.valueOf(object); if (type.equals(Double.class) || type.equals(Double.TYPE)) return Double.valueOf(object); if (type.isEnum()) return Enum.valueOf(type, object); if (type.equals(String.class) || type.equals(Object.class)) return String.valueOf(object); if (type.equals(java.util.Date.class)) { try {/*www . j av a 2 s . c o m*/ return simpleDateFormat.parse(object); } catch (ParseException e) { throw new RestException( "Unable to parse date [" + object + "]. Make sure it matches the format: " + date_format); } } //unknown type throw new UnsupportedTypeException("Non primitive type when converting property [" + propKey + "]:" + type); }
From source file:org.opoo.util.ClassUtils.java
public static boolean isCompatibleType(Object value, Class type) { // Do object check first, then primitives if (value == null || type.isInstance(value)) { return true; } else if (type.equals(Integer.TYPE) && Integer.class.isInstance(value)) { return true; } else if (type.equals(Long.TYPE) && Long.class.isInstance(value)) { return true; } else if (type.equals(Double.TYPE) && Double.class.isInstance(value)) { return true; } else if (type.equals(Float.TYPE) && Float.class.isInstance(value)) { return true; } else if (type.equals(Short.TYPE) && Short.class.isInstance(value)) { return true; } else if (type.equals(Byte.TYPE) && Byte.class.isInstance(value)) { return true; } else if (type.equals(Character.TYPE) && Character.class.isInstance(value)) { return true; } else if (type.equals(Boolean.TYPE) && Boolean.class.isInstance(value)) { return true; } else {//from w ww .j av a 2 s . c o m return false; } }