List of usage examples for java.lang Short TYPE
Class TYPE
To view the source code for java.lang Short TYPE.
Click Source Link
From source file:com.autonomy.aci.client.annotations.ConversionServiceImpl.java
public ConversionServiceImpl() { registerConverter(new StringToDoubleConverter(), String.class, Double.class); registerConverter(new StringToDoubleConverter(), String.class, Double.TYPE); registerConverter(new StringToByteConverter(), String.class, Byte.class); registerConverter(new StringToByteConverter(), String.class, Byte.TYPE); registerConverter(new StringToIntegerConverter(), String.class, Integer.class); registerConverter(new StringToIntegerConverter(), String.class, Integer.TYPE); registerConverter(new StringToFloatConverter(), String.class, Float.class); registerConverter(new StringToFloatConverter(), String.class, Float.TYPE); registerConverter(new StringToShortConverter(), String.class, Short.class); registerConverter(new StringToShortConverter(), String.class, Short.TYPE); registerConverter(new StringToCharacterConverter(), String.class, Character.class); registerConverter(new StringToCharacterConverter(), String.class, Character.TYPE); registerConverter(new StringToBooleanConverter(), String.class, Boolean.class); registerConverter(new StringToBooleanConverter(), String.class, Boolean.TYPE); registerConverter(new StringToLongConverter(), String.class, Long.class); registerConverter(new StringToLongConverter(), String.class, Long.TYPE); }
From source file:com.github.steveash.typedconfig.resolver.type.simple.ShortValueResolverFactory.java
@Override public boolean canResolveFor(ConfigBinding configBinding) { return configBinding.getDataType().isAssignableFrom(Short.class) || configBinding.getDataType().isAssignableFrom(Short.TYPE); }
From source file:Main.java
private static boolean isAssignableFrom(Class<?> parameterType, Object value) { if (parameterType.isPrimitive()) { if (value == null) { return false; }/*from w w w.ja v a2s .com*/ Class<?> valueClass = value.getClass(); if (parameterType == Boolean.TYPE) { return valueClass == Boolean.class; } else if (parameterType == Byte.TYPE) { return valueClass == Byte.class; } else if (parameterType == Character.TYPE) { return valueClass == Character.class; } else if (parameterType == Short.TYPE) { return valueClass == Short.class || valueClass == Byte.class; } else if (parameterType == Integer.TYPE) { return valueClass == Integer.class || valueClass == Character.class || valueClass == Short.class || valueClass == Byte.class; } else if (parameterType == Long.TYPE) { return valueClass == Long.class || valueClass == Integer.class || valueClass == Character.class || valueClass == Short.class || valueClass == Byte.class; } else if (parameterType == Float.TYPE) { return valueClass == Float.class || valueClass == Long.class || valueClass == Integer.class || valueClass == Character.class || valueClass == Short.class || valueClass == Byte.class; } else if (parameterType == Double.TYPE) { return valueClass == Double.class || valueClass == Float.class || valueClass == Long.class || valueClass == Integer.class || valueClass == Character.class || valueClass == Short.class || valueClass == Byte.class; } else { return false; } } else { return value == null || parameterType.isAssignableFrom(value.getClass()); } }
From source file:org.openamf.util.OpenAMFUtils.java
public static boolean typesMatch(Class parameterType, Object parameter) { log.debug("expected class: " + parameterType.getName()); if (parameter == null) { log.debug("parameter is null"); } else {/*w w w . j ava 2s. co m*/ log.debug("parameter class: " + parameter.getClass().getName()); } boolean typesMatch = parameterType.isInstance(parameter); if (!typesMatch) { if (parameterType.equals(Boolean.TYPE) && parameter instanceof Boolean) { typesMatch = true; } else if (parameterType.equals(Character.TYPE) && parameter instanceof Character) { typesMatch = true; } else if (parameterType.equals(Byte.TYPE) && parameter instanceof Byte) { typesMatch = true; } else if (parameterType.equals(Short.TYPE) && parameter instanceof Short) { typesMatch = true; } else if (parameterType.equals(Integer.TYPE) && parameter instanceof Integer) { typesMatch = true; } else if (parameterType.equals(Long.TYPE) && parameter instanceof Long) { typesMatch = true; } else if (parameterType.equals(Float.TYPE) && parameter instanceof Float) { typesMatch = true; } else if (parameterType.equals(Double.TYPE) && parameter instanceof Double) { typesMatch = true; } } return typesMatch; }
From source file:Main.java
/** * <p>Inserts the specified element at the specified position in the array. * Shifts the element currently at that position (if any) and any subsequent * elements to the right (adds one to their indices).</p> * * <p>This method returns a new array with the same elements of the input * array plus the given element on the specified position. The component * type of the returned array is always the same as that of the input * array.</p>/*from ww w. j ava 2s . c om*/ * * <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> * * <pre> * ArrayUtils.add([1], 0, 2) = [2, 1] * ArrayUtils.add([2, 6], 2, 10) = [2, 6, 10] * ArrayUtils.add([2, 6], 0, -4) = [-4, 2, 6] * ArrayUtils.add([2, 6, 3], 2, 1) = [2, 6, 1, 3] * </pre> * * @param array the array to add the element to, may be <code>null</code> * @param index the position of the new object * @param element the object to add * @return A new array containing the existing elements and the new element * @throws IndexOutOfBoundsException if the index is out of range * (index < 0 || index > array.length). */ public static short[] add(short[] array, int index, short element) { return (short[]) add(array, index, new Short(element), Short.TYPE); }
From source file:Main.java
/** * This method converts a given number into a target class. This method does not change the value (except when * explicitly casting to a more general type, e.g. from double to int), just the internal type representation. While * this is unnecessary while using normal java code, reflection based access to method parameters is a bit more * difficult. As far as possible, this method will prevent the ArgumentMismatch error when passing numbers as * parameters.//from ww w .ja v a2 s.c om * <p/> * If the value can not be converted to the given target class, it will be returned unchanged. * * @param targetClass Class to which the number should be converted, if possible. * @param value Number value to convert. * @return 'value' converted to an instance of 'targetClass'. */ public static Object convertNumber(final Class targetClass, final Number value) { if (targetClass.equals(Double.class) || targetClass.equals(Double.TYPE)) return value.doubleValue(); if (targetClass.equals(Integer.class) || targetClass.equals(Integer.TYPE)) return value.intValue(); if (targetClass.equals(Long.class) || targetClass.equals(Long.TYPE)) return value.longValue(); if (targetClass.equals(Short.class) || targetClass.equals(Short.TYPE)) return value.shortValue(); if (targetClass.equals(Byte.class) || targetClass.equals(Byte.TYPE)) return value.byteValue(); if (targetClass.equals(Character.class) || targetClass.equals(Character.TYPE)) return value.intValue(); if (targetClass.equals(Float.class) || targetClass.equals(Float.TYPE)) return value.floatValue(); return value; }
From source file:io.github.benas.jpopulator.impl.DefaultRandomizer.java
/** * Generate a random value for the given type. * * @param type the type for which a random value will be generated * @return a random value for the given type or null if the type is not supported *///ww w . j a v a 2 s .c o m public static Object getRandomValue(final Class type) { /* * String and Character types */ if (type.equals(String.class)) { return RandomStringUtils.randomAlphabetic(ConstantsUtil.DEFAULT_STRING_LENGTH); } if (type.equals(Character.TYPE) || type.equals(Character.class)) { return RandomStringUtils.randomAlphabetic(1).charAt(0); } /* * Boolean type */ if (type.equals(Boolean.TYPE) || type.equals(Boolean.class)) { return ConstantsUtil.RANDOM.nextBoolean(); } /* * Numeric types */ if (type.equals(Byte.TYPE) || type.equals(Byte.class)) { return (byte) (ConstantsUtil.RANDOM.nextInt()); } if (type.equals(Short.TYPE) || type.equals(Short.class)) { return (short) (ConstantsUtil.RANDOM.nextInt()); } if (type.equals(Integer.TYPE) || type.equals(Integer.class)) { return ConstantsUtil.RANDOM.nextInt(); } if (type.equals(Long.TYPE) || type.equals(Long.class)) { return ConstantsUtil.RANDOM.nextLong(); } if (type.equals(Double.TYPE) || type.equals(Double.class)) { return ConstantsUtil.RANDOM.nextDouble(); } if (type.equals(Float.TYPE) || type.equals(Float.class)) { return ConstantsUtil.RANDOM.nextFloat(); } if (type.equals(BigInteger.class)) { return new BigInteger( Math.abs(ConstantsUtil.RANDOM.nextInt(ConstantsUtil.DEFAULT_BIG_INTEGER_NUM_BITS_LENGTH)), ConstantsUtil.RANDOM); } if (type.equals(BigDecimal.class)) { return new BigDecimal(ConstantsUtil.RANDOM.nextDouble()); } if (type.equals(AtomicLong.class)) { return new AtomicLong(ConstantsUtil.RANDOM.nextLong()); } if (type.equals(AtomicInteger.class)) { return new AtomicInteger(ConstantsUtil.RANDOM.nextInt()); } /* * Date and time types */ if (type.equals(java.util.Date.class)) { return ConstantsUtil.DATE_RANGE_RANDOMIZER.getRandomValue(); } if (type.equals(java.sql.Date.class)) { return new java.sql.Date(ConstantsUtil.DATE_RANGE_RANDOMIZER.getRandomValue().getTime()); } if (type.equals(java.sql.Time.class)) { return new java.sql.Time(ConstantsUtil.RANDOM.nextLong()); } if (type.equals(java.sql.Timestamp.class)) { return new java.sql.Timestamp(ConstantsUtil.DATE_RANGE_RANDOMIZER.getRandomValue().getTime()); } if (type.equals(Calendar.class)) { return Calendar.getInstance(); } if (type.equals(org.joda.time.DateTime.class)) { return new org.joda.time.DateTime(ConstantsUtil.DATE_RANGE_RANDOMIZER.getRandomValue().getTime()); } if (type.equals(org.joda.time.LocalDate.class)) { return new org.joda.time.LocalDate(ConstantsUtil.DATE_RANGE_RANDOMIZER.getRandomValue().getTime()); } if (type.equals(org.joda.time.LocalTime.class)) { return new org.joda.time.LocalTime(ConstantsUtil.DATE_RANGE_RANDOMIZER.getRandomValue().getTime()); } if (type.equals(org.joda.time.LocalDateTime.class)) { return new org.joda.time.LocalDateTime(ConstantsUtil.DATE_RANGE_RANDOMIZER.getRandomValue().getTime()); } if (type.equals(org.joda.time.Duration.class)) { return new org.joda.time.Duration(Math.abs(ConstantsUtil.RANDOM.nextLong())); } if (type.equals(org.joda.time.Period.class)) { return new org.joda.time.Period(Math.abs(ConstantsUtil.RANDOM.nextInt())); } if (type.equals(org.joda.time.Interval.class)) { long startDate = Math.abs(ConstantsUtil.RANDOM.nextInt()); long endDate = startDate + Math.abs(ConstantsUtil.RANDOM.nextInt()); return new org.joda.time.Interval(startDate, endDate); } /* * Enum type */ if (type.isEnum() && type.getEnumConstants().length > 0) { Object[] enumConstants = type.getEnumConstants(); return enumConstants[ConstantsUtil.RANDOM.nextInt(enumConstants.length)]; } /* * Return null for any unsupported type */ return null; }
From source file:org.lunarray.model.descriptor.util.PrimitiveUtil.java
/** * Default constructor./* w ww . ja v a2 s. c o m*/ */ private PrimitiveUtil() { this.primitivesToClasses = new HashMap<Class<?>, Class<?>>(); this.primitivesToClasses.put(Byte.TYPE, Byte.class); this.primitivesToClasses.put(Integer.TYPE, Integer.class); this.primitivesToClasses.put(Double.TYPE, Double.class); this.primitivesToClasses.put(Float.TYPE, Float.class); this.primitivesToClasses.put(Long.TYPE, Long.class); this.primitivesToClasses.put(Short.TYPE, Short.class); this.primitivesToClasses.put(Character.TYPE, Character.class); this.primitivesToClasses.put(Boolean.TYPE, Boolean.class); }
From source file:org.kordamp.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./* w ww . j a v a 2s. 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:org.wso2.carbon.analytics.spark.core.util.AnalyticsCommonUtils.java
public static DataType getDataType(Type returnType) throws AnalyticsUDFException { DataType udfReturnType = null;/*from w ww. j av 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; }