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:Main.java
public static String getPrimitiveLetter(Class<?> paramClass) { if (Integer.TYPE.equals(paramClass)) { return "I"; }//from ww w . j ava 2 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:io.github.benas.jpopulator.randomizers.validation.MaxValueRandomizer.java
/** * Generate a random value for the given type. * * @param type the type for which a random value will be generated * @param maxValue the maximum threshold for the generated value * @return a random value (lower than maxValue) for the given type or null if the type is not supported *///from w w w . j av a2 s . co m public static Object getRandomValue(final Class type, final long maxValue) { if (type.equals(Byte.TYPE) || type.equals(Byte.class)) { return (byte) randomDataGenerator.nextLong(Byte.MIN_VALUE, maxValue); } if (type.equals(Short.TYPE) || type.equals(Short.class)) { return (short) randomDataGenerator.nextLong(Short.MIN_VALUE, maxValue); } if (type.equals(Integer.TYPE) || type.equals(Integer.class)) { return (int) randomDataGenerator.nextLong(Integer.MIN_VALUE, maxValue); } if (type.equals(Long.TYPE) || type.equals(Long.class)) { return randomDataGenerator.nextLong(Long.MIN_VALUE, maxValue); } if (type.equals(BigInteger.class)) { return new BigInteger(String.valueOf(randomDataGenerator.nextLong(Long.MIN_VALUE, maxValue))); } if (type.equals(BigDecimal.class)) { return new BigDecimal(randomDataGenerator.nextLong(Long.MIN_VALUE, maxValue)); } return null; }
From source file:io.github.benas.jpopulator.randomizers.validation.MinValueRandomizer.java
/** * Generate a random value for the given type. * * @param type the type for which a random value will be generated * @param minValue the minimum threshold for the generated value * @return a random value (greater than maxValue) for the given type or null if the type is not supported *//* ww w . j a va2 s . c o m*/ public static Object getRandomValue(final Class type, final long minValue) { if (type.equals(Byte.TYPE) || type.equals(Byte.class)) { return (byte) randomDataGenerator.nextLong(minValue, Byte.MAX_VALUE); } if (type.equals(Short.TYPE) || type.equals(Short.class)) { return (short) randomDataGenerator.nextLong(minValue, Short.MAX_VALUE); } if (type.equals(Integer.TYPE) || type.equals(Integer.class)) { return (int) randomDataGenerator.nextLong(minValue, Integer.MAX_VALUE); } if (type.equals(Long.TYPE) || type.equals(Long.class)) { return randomDataGenerator.nextLong(minValue, Long.MAX_VALUE); } if (type.equals(BigInteger.class)) { return new BigInteger(String.valueOf(randomDataGenerator.nextLong(minValue, Long.MAX_VALUE))); } if (type.equals(BigDecimal.class)) { return new BigDecimal(randomDataGenerator.nextLong(minValue, Long.MAX_VALUE)); } return null; }
From source file:Util.java
/** * Is the given {@code object} a primitive type or wrapper for a primitive * type?// w ww . jav a 2s . 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:org.impalaframework.spring.DebuggingInterceptor.java
public Object invoke(MethodInvocation invocation) throws Throwable { logger.debug("Calling method " + invocation); Class<?> returnType = invocation.getMethod().getReturnType(); if (Void.TYPE.equals(returnType)) return null; if (Byte.TYPE.equals(returnType)) return (byte) 0; if (Short.TYPE.equals(returnType)) return (short) 0; if (Integer.TYPE.equals(returnType)) return (int) 0; if (Long.TYPE.equals(returnType)) return 0L; if (Float.TYPE.equals(returnType)) return 0f; if (Double.TYPE.equals(returnType)) return 0d; if (Boolean.TYPE.equals(returnType)) return false; return null;//w w w .ja v a 2s . c o m }
From source file:com.github.dozermapper.core.converters.EnumConverter.java
@SuppressWarnings({ "unchecked", "rawtypes" }) public Object convert(Class destClass, Object srcObj) { if (null == srcObj) { MappingUtils.throwMappingException("Cannot convert null to enum of type " + destClass); }//from www . jav a 2 s . com try { if ((srcObj.getClass().equals(Byte.class)) || (srcObj.getClass().equals(Byte.TYPE))) { return EnumUtils.getEnumList(destClass).get(((Byte) srcObj).intValue()); } else if ((srcObj.getClass().equals(Short.class)) || (srcObj.getClass().equals(Short.TYPE))) { return EnumUtils.getEnumList(destClass).get(((Short) srcObj).intValue()); } else if ((srcObj.getClass().equals(Integer.class)) || (srcObj.getClass().equals(Integer.TYPE))) { return EnumUtils.getEnumList(destClass).get((Integer) srcObj); } else if ((srcObj.getClass().equals(Long.class)) || (srcObj.getClass().equals(Long.TYPE))) { return EnumUtils.getEnumList(destClass).get(((Long) srcObj).intValue()); } else { return Enum.valueOf(destClass, srcObj.toString()); } } catch (Exception e) { MappingUtils.throwMappingException("Cannot convert [" + srcObj + "] to enum of type " + destClass, e); } return srcObj; }
From source file:com.ms.commons.summer.web.util.json.JsonNumberMorpher.java
/** * Creates a new morpher for the target type. * //from w w w . j av a 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:org.fhcrc.cpl.toolbox.AbstractConvertHelper.java
protected void register() { _register(new NullSafeConverter(new BigDecimalConverter()), BigDecimal.class); _register(new NullSafeConverter(new BigIntegerConverter()), BigInteger.class); _register(new NullSafeConverter(new BooleanArrayConverter()), boolean[].class); _register(new ByteConverter(), Byte.TYPE); _register(new NullSafeConverter(new ByteConverter()), Byte.class); _register(new CharacterConverter(), Character.TYPE); _register(new NullSafeConverter(new CharacterConverter()), Character.class); _register(new NullSafeConverter(new CharacterArrayConverter()), char[].class); _register(new NullSafeConverter(new ClassConverter()), Class.class); _register(new NullSafeConverter(new DoubleArrayConverter()), double[].class); _register(new FloatArrayConverter(), float[].class); _register(new NullSafeConverter(new IntegerArrayConverter()), int[].class); _register(new LongConverter(), Long.TYPE); _register(new NullSafeConverter(new LongConverter()), Long.class); _register(new NullSafeConverter(new LongArrayConverter()), long[].class); _register(new ShortConverter(), Short.TYPE); _register(new NullSafeConverter(new ShortConverter()), Short.class); _register(new NullSafeConverter(new ShortArrayConverter()), short[].class); _register(new NullSafeConverter(new StringArrayConverter()), String[].class); _register(new NullSafeConverter(new SqlDateConverter()), java.sql.Date.class); _register(new NullSafeConverter(new SqlTimeConverter()), java.sql.Time.class); _register(new NullSafeConverter(new SqlTimestampConverter()), java.sql.Time.class); }
From source file:Main.java
/** * <p>Copies the given array and adds the given element at the end of the new array.</p> * * <p>The new array contains the same elements of the input * array plus the given element in the last position. The component type of * the new array is the same as that of the input array.</p> * * <p>If the input array is <code>null</code>, a new one element array is returned * whose component type is the same as the element.</p> * /*from w ww .jav a 2 s. c o m*/ * <pre> * ArrayUtils.add(null, 0) = [0] * ArrayUtils.add([1], 0) = [1, 0] * ArrayUtils.add([1, 0], 1) = [1, 0, 1] * </pre> * * @param array the array to copy and add the element to, may be <code>null</code> * @param element the object to add at the last index of the new array * @return A new array containing the existing elements plus the new element * @since 2.1 */ public static byte[] add(byte[] array, byte element) { byte[] newArray = (byte[]) copyArrayGrow1(array, Byte.TYPE); newArray[newArray.length - 1] = element; return newArray; }
From source file:com.bedatadriven.rebar.persistence.mapping.PrimitiveMapping.java
public PrimitiveMapping(MethodInfo getter) { super(getter); TypeInfo type = getter.getReturnType(); Class primitive = type.isPrimitive(); this.boxed = (primitive == null); if (primitive != null) { this.nullable = false; }//from w ww. j a v a 2 s .co m if (primitive == Integer.TYPE || type.getQualifiedName().equals(Integer.class.getName()) || primitive == Short.TYPE || type.getQualifiedName().equals(Short.class.getName()) || primitive == Long.TYPE || type.getQualifiedName().equals(Long.class.getName()) || primitive == Byte.TYPE || type.getQualifiedName().equals(Byte.class.getName()) || primitive == Boolean.TYPE || type.getQualifiedName().equals(Boolean.class.getName())) { sqlTypeName = SqliteTypes.integer; } else if (primitive == Float.TYPE || type.getQualifiedName().equals(Float.class.getName()) || primitive == Double.TYPE || type.getQualifiedName().equals(Double.class.getName())) { sqlTypeName = SqliteTypes.real; } else if (primitive == Character.TYPE || type.getQualifiedName().equals(Character.class.getName())) { sqlTypeName = SqliteTypes.text; } String suffix = type.getSimpleName(); if (suffix.equals("Integer")) { suffix = "Int"; } else if (suffix.equals("Character")) { suffix = "Char"; } suffix = suffix.substring(0, 1).toUpperCase() + suffix.substring(1); readerName = "Readers.read" + suffix; stmtSetter = "set" + suffix; }