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.brekka.phalanx.core.services.impl.AbstractCryptoService.java
@SuppressWarnings("unchecked") protected <T> T toType(byte[] data, Class<T> expectedType, UUID idOfData, CryptoProfile cryptoProfile) { if (expectedType == null) { throw new NullPointerException("An expected type is required"); }//from w w w .j ava 2s . c om Object retVal; if (expectedType.isArray() && expectedType.getComponentType() == Byte.TYPE) { retVal = data; } else if (expectedType == InternalPrivateKeyToken.class) { retVal = decodePrivateKey(data, idOfData, cryptoProfile); } else if (expectedType == InternalSecretKeyToken.class) { retVal = decodeSecretKey(data, idOfData); } else { throw new IllegalArgumentException( String.format("Unsupport type conversion to '%s'", expectedType.getName())); } return (T) retVal; }
From source file:com.base.dao.sql.ReflectionUtils.java
public static Object convertValue(Object value, Class toType) { Object result = null;/*www . j ava 2 s .c o m*/ if (value != null) { if (value.getClass().isArray() && toType.isArray()) { Class componentType = toType.getComponentType(); result = Array.newInstance(componentType, Array.getLength(value)); for (int i = 0, icount = Array.getLength(value); i < icount; i++) { Array.set(result, i, convertValue(Array.get(value, i), componentType)); } } else { if ((toType == Integer.class) || (toType == Integer.TYPE)) result = Integer.valueOf((int) longValue(value)); if ((toType == Double.class) || (toType == Double.TYPE)) result = new Double(doubleValue(value)); if ((toType == Boolean.class) || (toType == Boolean.TYPE)) result = booleanValue(value) ? Boolean.TRUE : Boolean.FALSE; if ((toType == Byte.class) || (toType == Byte.TYPE)) result = Byte.valueOf((byte) longValue(value)); if ((toType == Character.class) || (toType == Character.TYPE)) result = new Character((char) longValue(value)); if ((toType == Short.class) || (toType == Short.TYPE)) result = Short.valueOf((short) longValue(value)); if ((toType == Long.class) || (toType == Long.TYPE)) result = Long.valueOf(longValue(value)); if ((toType == Float.class) || (toType == Float.TYPE)) result = new Float(doubleValue(value)); if (toType == BigInteger.class) result = bigIntValue(value); if (toType == BigDecimal.class) result = bigDecValue(value); if (toType == String.class) result = stringValue(value); if (toType == Date.class) { result = DateUtils.toDate(stringValue(value)); } if (Enum.class.isAssignableFrom(toType)) result = enumValue((Class<Enum>) toType, value); } } else { if (toType.isPrimitive()) { result = primitiveDefaults.get(toType); } } return result; }
From source file:it.greenvulcano.gvesb.http.ProtocolFactory.java
/** * * @param objectClass/*from ww w. j a va 2 s .c o m*/ * Object class to instantiate * @param node * The configuration of constructor parameters. * @return */ private static Object createObjectUsingConstructor(Class<?> objectClass, Node node) throws Exception { NodeList paramList = XMLConfig.getNodeList(node, "constructor-param"); Class<?>[] types = new Class[paramList.getLength()]; Object[] params = new Object[types.length]; for (int i = 0; i < types.length; ++i) { Node paramNode = paramList.item(i); String type = XMLConfig.get(paramNode, "@type"); String value = XMLConfig.getDecrypted(paramNode, "@value"); Class<?> cls = null; if (type.equals("byte")) { cls = Byte.TYPE; } else if (type.equals("boolean")) { cls = Boolean.TYPE; } else if (type.equals("char")) { cls = Character.TYPE; } else if (type.equals("double")) { cls = Double.TYPE; } else if (type.equals("float")) { cls = Float.TYPE; } else if (type.equals("int")) { cls = Integer.TYPE; } else if (type.equals("long")) { cls = Long.TYPE; } else if (type.equals("short")) { cls = Short.TYPE; } else if (type.equals("String")) { cls = String.class; } types[i] = cls; params[i] = cast(value, cls); } Constructor<?> constr = objectClass.getConstructor(types); return constr.newInstance(params); }
From source file:org.wso2.carbon.analytics.spark.core.util.AnalyticsCommonUtils.java
public static DataType getDataType(Type returnType) throws AnalyticsUDFException { DataType udfReturnType = null;/*from w w w . j a v a 2 s. c o m*/ if (returnType == Integer.TYPE || returnType == Integer.class) { udfReturnType = DataTypes.IntegerType; } else if (returnType == Double.TYPE || returnType == Double.class) { udfReturnType = DataTypes.DoubleType; } else if (returnType == Float.TYPE || returnType == Float.class) { udfReturnType = DataTypes.FloatType; } else if (returnType == Long.TYPE || returnType == Long.class) { udfReturnType = DataTypes.LongType; } else if (returnType == Boolean.TYPE || returnType == Boolean.class) { udfReturnType = DataTypes.BooleanType; } else if (returnType == String.class) { udfReturnType = DataTypes.StringType; } else if (returnType == Short.TYPE || returnType == Short.class) { udfReturnType = DataTypes.ShortType; } else if (returnType == NullType.class) { udfReturnType = DataTypes.NullType; } else if (returnType == Byte.TYPE || returnType == Byte.class) { udfReturnType = DataTypes.ByteType; } else if (returnType == byte[].class || returnType == Byte[].class) { udfReturnType = DataTypes.BinaryType; } else if (returnType == Date.class) { udfReturnType = DataTypes.DateType; } else if (returnType == Timestamp.class) { udfReturnType = DataTypes.TimestampType; } else if (returnType == BigDecimal.class) { udfReturnType = DataTypes.createDecimalType(); } else if (returnType instanceof ParameterizedType) { ParameterizedType type = (ParameterizedType) returnType; /*if return type is a List types will contain only 1 element, if return type is Map it will have 2 elements types representing key and the value.*/ Type[] types = type.getActualTypeArguments(); if (types != null && types.length > 0) { switch (types.length) { case 1: { udfReturnType = DataTypes.createArrayType(getDataType(types[0])); break; } case 2: { udfReturnType = DataTypes.createMapType(getDataType(types[0]), getDataType(types[1])); break; } default: throw new AnalyticsUDFException("Cannot Map the return type either to ArrayType or MapType"); } } } else { throw new AnalyticsUDFException("Cannot determine the return DataType"); } return udfReturnType; }
From source file:org.openTwoFactor.clientExt.net.sf.ezmorph.object.NumberMorpher.java
/** * Creates a new morpher for the target type. * * @param type must be a primitive or wrapper type. BigDecimal and BigInteger * are also supported./*from w w w . ja v a 2 s. c o m*/ */ public NumberMorpher(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:com.puppycrawl.tools.checkstyle.api.AutomaticBean.java
/** * Creates a BeanUtilsBean that is configured to use * type converters that throw a ConversionException * instead of using the default value when something * goes wrong.//from w w w .j a va 2 s . c o m * * @return a configured BeanUtilsBean */ private static BeanUtilsBean createBeanUtilsBean() { final ConvertUtilsBean cub = new ConvertUtilsBean(); cub.register(new BooleanConverter(), Boolean.TYPE); cub.register(new BooleanConverter(), Boolean.class); cub.register(new ArrayConverter(boolean[].class, new BooleanConverter()), boolean[].class); cub.register(new ByteConverter(), Byte.TYPE); cub.register(new ByteConverter(), Byte.class); cub.register(new ArrayConverter(byte[].class, new ByteConverter()), byte[].class); cub.register(new CharacterConverter(), Character.TYPE); cub.register(new CharacterConverter(), Character.class); cub.register(new ArrayConverter(char[].class, new CharacterConverter()), char[].class); cub.register(new DoubleConverter(), Double.TYPE); cub.register(new DoubleConverter(), Double.class); cub.register(new ArrayConverter(double[].class, new DoubleConverter()), double[].class); cub.register(new FloatConverter(), Float.TYPE); cub.register(new FloatConverter(), Float.class); cub.register(new ArrayConverter(float[].class, new FloatConverter()), float[].class); cub.register(new IntegerConverter(), Integer.TYPE); cub.register(new IntegerConverter(), Integer.class); cub.register(new ArrayConverter(int[].class, new IntegerConverter()), int[].class); cub.register(new LongConverter(), Long.TYPE); cub.register(new LongConverter(), Long.class); cub.register(new ArrayConverter(long[].class, new LongConverter()), long[].class); cub.register(new ShortConverter(), Short.TYPE); cub.register(new ShortConverter(), Short.class); cub.register(new ArrayConverter(short[].class, new ShortConverter()), short[].class); cub.register(new RelaxedStringArrayConverter(), String[].class); // BigDecimal, BigInteger, Class, Date, String, Time, TimeStamp // do not use defaults in the default configuration of ConvertUtilsBean return new BeanUtilsBean(cub, new PropertyUtilsBean()); }
From source file:com.nfwork.dbfound.json.JSONDynaBean.java
public Object get(String name) { Object value = dynaValues.get(name); if (value != null) { return value; }/*from w ww . j a va 2 s. c o m*/ Class type = getDynaProperty(name).getType(); if (type == null) { throw new NullPointerException("Unspecified property type for " + name); } if (!type.isPrimitive()) { return value; } 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 == Short.TYPE) { return new Short((short) 0); } else if (type == Integer.TYPE) { return new Integer(0); } else if (type == Long.TYPE) { return new Long(0); } else if (type == Float.TYPE) { return new Float(0.0); } else if (type == Double.TYPE) { return new Double(0); } return null; }
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// w w w .j av a 2s . c o 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:org.ldp4j.server.sdk.StringContent.java
@Override public <S> S serialize(Class<S> clazz) throws IOException { Object result = null;/*from w w w .j a va 2 s . c o m*/ if (clazz.isInstance(source)) { result = source; } else if (clazz.isAssignableFrom(InputStream.class)) { result = IOUtils.toBufferedInputStream(new ByteArrayInputStream(source.getBytes(charset))); } else if (clazz.isAssignableFrom(Reader.class)) { result = new StringReader(source); } else if (clazz.isAssignableFrom(CharSequence.class)) { result = CharSequence.class.cast(source); } else if (clazz.getClass().isArray() && Byte.TYPE.isAssignableFrom(clazz.getComponentType())) { result = (byte[]) source.getBytes(charset); } else { throw new IOException( String.format("Could not serialize String content to '%s'", clazz.getCanonicalName())); } return clazz.cast(result); }
From source file:org.lunarray.model.descriptor.builder.annotation.util.RenderDefaultsUtil.java
/** * Fills the defaults.// w w w. ja v a2s. c o m */ private RenderDefaultsUtil() { this.renderDefaults = new HashMap<Class<?>, RenderType>(); this.renderDefaults.put(Calendar.class, RenderType.DATE_PICKER); this.renderDefaults.put(Date.class, RenderType.DATE_PICKER); this.renderDefaults.put(java.sql.Date.class, RenderType.DATE_PICKER); this.renderDefaults.put(String.class, RenderType.TEXT); this.renderDefaults.put(Integer.class, RenderType.TEXT); this.renderDefaults.put(Double.class, RenderType.TEXT); this.renderDefaults.put(Float.class, RenderType.TEXT); this.renderDefaults.put(Long.class, RenderType.TEXT); this.renderDefaults.put(Byte.class, RenderType.TEXT); this.renderDefaults.put(Short.class, RenderType.TEXT); this.renderDefaults.put(Character.class, RenderType.TEXT); this.renderDefaults.put(Integer.TYPE, RenderType.TEXT); this.renderDefaults.put(Double.TYPE, RenderType.TEXT); this.renderDefaults.put(Float.TYPE, RenderType.TEXT); this.renderDefaults.put(Long.TYPE, RenderType.TEXT); this.renderDefaults.put(Byte.TYPE, RenderType.TEXT); this.renderDefaults.put(Short.TYPE, RenderType.TEXT); this.renderDefaults.put(Character.TYPE, RenderType.TEXT); this.renderDefaults.put(BigDecimal.class, RenderType.TEXT); this.renderDefaults.put(BigInteger.class, RenderType.TEXT); this.renderDefaults.put(Boolean.class, RenderType.CHECKBOX); this.renderDefaults.put(Boolean.TYPE, RenderType.CHECKBOX); }