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:de.micromata.genome.util.strings.converter.StandardStringConverter.java
@Override public char getTypeChar(Object value) { if (value == null) { return ConvertedStringTypes.NULL.getShortType(); }/* ww w . ja v a 2 s . co m*/ Class<?> cls = value.getClass(); if (value instanceof String) { return ConvertedStringTypes.STRING.getShortType(); } Class<?> vclass = value.getClass(); if (value instanceof Boolean || vclass == Boolean.TYPE) { return ConvertedStringTypes.BOOLEAN.getShortType(); } if (value instanceof Byte || vclass == Byte.TYPE) { return ConvertedStringTypes.BYTE.getShortType(); } if (value instanceof Short || vclass == Short.TYPE) { return ConvertedStringTypes.SHORT.getShortType(); } if (value instanceof Integer || vclass == Integer.TYPE) { return ConvertedStringTypes.INTEGER.getShortType(); } if (value instanceof Long || vclass == Long.TYPE) { return ConvertedStringTypes.LONG.getShortType(); } if (value instanceof Float || vclass == Float.TYPE) { return ConvertedStringTypes.FLOAT.getShortType(); } if (value instanceof Double || vclass == Double.TYPE) { return ConvertedStringTypes.DOUBLE.getShortType(); } if (value instanceof Character || vclass == Character.TYPE) { return ConvertedStringTypes.CHAR.getShortType(); } if (value instanceof Date) { return ConvertedStringTypes.DATE.getShortType(); } if (value instanceof BigDecimal) { return ConvertedStringTypes.BIGDECIMAL.getShortType(); } if (value instanceof Character) { return ConvertedStringTypes.CHAR.getShortType(); } if (value instanceof byte[]) { return ConvertedStringTypes.BYTEARRAY.getShortType(); } if (value instanceof String[]) { return ConvertedStringTypes.STRINGARRAY.getShortType(); } if (value instanceof Long[]) { return ConvertedStringTypes.LONGARRAY.getShortType(); } // if (value instanceof Serializable) // return ConvertedStringTypes.XMLOBJECT; return ConvertedStringTypes.CUSTOM.getShortType(); }
From source file:ClassUtils.java
/** * Helper for invoking an instance method that takes a single parameter. * This method also handles parameters of primitive type. * // ww w.ja va 2s .c o m * @param cl * The class that the instance belongs to * @param instance * The object on which we will invoke the method * @param methodName * The method name * @param param * The parameter * @throws Throwable */ public static Object invokeMethod(Class cl, Object instance, String methodName, Object param) throws Throwable { Class paramClass; if (param instanceof Integer) paramClass = Integer.TYPE; else if (param instanceof Long) paramClass = Long.TYPE; else if (param instanceof Short) paramClass = Short.TYPE; else if (param instanceof Boolean) paramClass = Boolean.TYPE; else if (param instanceof Double) paramClass = Double.TYPE; else if (param instanceof Float) paramClass = Float.TYPE; else if (param instanceof Character) paramClass = Character.TYPE; else if (param instanceof Byte) paramClass = Byte.TYPE; else paramClass = param.getClass(); Method method = cl.getMethod(methodName, new Class[] { paramClass }); try { return method.invoke(instance, new Object[] { param }); } catch (InvocationTargetException e) { throw e.getCause(); } }
From source file:org.kordamp.ezmorph.object.NumberMorpher.java
/** * Creates a new morpher for the target type with a default value.<br> * The defaultValue should be of the same class as the target type. * * @param type must be a primitive or wrapper type. BigDecimal and BigInteger * are also supported. * @param defaultValue return value if the value to be morphed is null *///from w w w .j a v a 2 s .c o m public NumberMorpher(Class type, Number defaultValue) { super(true); 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"); } if (defaultValue != null && !type.isInstance(defaultValue)) { throw new MorphException("Default value must be of type " + type); } this.type = type; setDefaultValue(defaultValue); }
From source file:com.browseengine.bobo.serialize.JSONSerializer.java
private static void loadObject(Object retObj, Field f, JSONObject jsonObj) throws JSONSerializationException { String key = f.getName();//from www .j av a 2s. c o m Class type = f.getType(); try { if (type.isPrimitive()) { if (type == Integer.TYPE) { f.setInt(retObj, jsonObj.getInt(key)); } else if (type == Long.TYPE) { f.setLong(retObj, jsonObj.getInt(key)); } else if (type == Short.TYPE) { f.setShort(retObj, (short) jsonObj.getInt(key)); } else if (type == Boolean.TYPE) { f.setBoolean(retObj, jsonObj.getBoolean(key)); } else if (type == Double.TYPE) { f.setDouble(retObj, jsonObj.getDouble(key)); } else if (type == Float.TYPE) { f.setFloat(retObj, (float) jsonObj.getDouble(key)); } else if (type == Character.TYPE) { char ch = jsonObj.getString(key).charAt(0); f.setChar(retObj, ch); } else if (type == Byte.TYPE) { f.setByte(retObj, (byte) jsonObj.getInt(key)); } else { throw new JSONSerializationException("Unknown primitive: " + type); } } else if (type == String.class) { f.set(retObj, jsonObj.getString(key)); } else if (JSONSerializable.class.isAssignableFrom(type)) { JSONObject jObj = jsonObj.getJSONObject(key); JSONSerializable serObj = deSerialize(type, jObj); f.set(retObj, serObj); } } catch (Exception e) { throw new JSONSerializationException(e.getMessage(), e); } }
From source file:org.openTwoFactor.clientExt.net.sf.ezmorph.primitive.ShortMorpher.java
public Class morphsTo() { return Short.TYPE; }
From source file:foundation.stack.datamill.configuration.impl.Classes.java
public static boolean isAssignable(Class<?> clazz, final Class<?> toClass) { if (toClass == null) { return false; }/*w w w . jav a 2s.c om*/ if (clazz == null) { return !toClass.isPrimitive(); } if (clazz.isPrimitive() && !toClass.isPrimitive()) { clazz = primitiveToWrapper(clazz); if (clazz == null) { return false; } } if (toClass.isPrimitive() && !clazz.isPrimitive()) { clazz = wrapperToPrimitive(clazz); if (clazz == null) { return false; } } if (clazz.equals(toClass)) { return true; } if (clazz.isPrimitive()) { if (!toClass.isPrimitive()) { return false; } if (Integer.TYPE.equals(clazz)) { return Long.TYPE.equals(toClass) || Float.TYPE.equals(toClass) || Double.TYPE.equals(toClass); } if (Long.TYPE.equals(clazz)) { return Float.TYPE.equals(toClass) || Double.TYPE.equals(toClass); } if (Boolean.TYPE.equals(clazz)) { return false; } if (Double.TYPE.equals(clazz)) { return false; } if (Float.TYPE.equals(clazz)) { return Double.TYPE.equals(toClass); } if (Character.TYPE.equals(clazz)) { return Integer.TYPE.equals(toClass) || Long.TYPE.equals(toClass) || Float.TYPE.equals(toClass) || Double.TYPE.equals(toClass); } if (Short.TYPE.equals(clazz)) { return Integer.TYPE.equals(toClass) || Long.TYPE.equals(toClass) || Float.TYPE.equals(toClass) || Double.TYPE.equals(toClass); } if (Byte.TYPE.equals(clazz)) { return Short.TYPE.equals(toClass) || Integer.TYPE.equals(toClass) || Long.TYPE.equals(toClass) || Float.TYPE.equals(toClass) || Double.TYPE.equals(toClass); } // should never get here return false; } return toClass.isAssignableFrom(clazz); }
From source file:org.briljantframework.data.vector.Convert.java
@SuppressWarnings("unchecked") private static <T> T convertNumber(Class<T> cls, Number num) { if (cls.equals(Double.class) || cls.equals(Double.TYPE)) { return (T) (Double) num.doubleValue(); } else if (cls.equals(Float.class) || cls.equals(Float.TYPE)) { return (T) (Float) num.floatValue(); } else if (cls.equals(Long.class) || cls.equals(Long.TYPE)) { return (T) (Long) num.longValue(); } else if (cls.equals(Integer.class) || cls.equals(Integer.TYPE)) { return (T) (Integer) num.intValue(); } else if (cls.equals(Short.class) || cls.equals(Short.TYPE)) { return (T) (Short) num.shortValue(); } else if (cls.equals(Byte.class) || cls.equals(Byte.TYPE)) { return (T) (Byte) num.byteValue(); } else if (Complex.class.equals(cls)) { return cls.cast(Complex.valueOf(num.doubleValue())); } else if (Logical.class.equals(cls)) { return cls.cast(num.intValue() == 1 ? Logical.TRUE : Logical.FALSE); } else if (Boolean.class.equals(cls)) { return cls.cast(num.intValue() == 1); } else {/* w w w. j a va 2 s . c o m*/ return Na.of(cls); } }
From source file:com.alibaba.doris.admin.service.impl.ValueParseUtil.java
/** * ?String ?://ww w . ja v a 2 s . c o m * * <pre> * short, int, long, float : 0 * char, byte: 0 * String: null * Map, List: null * Integer, Long, Float : null * Date: null * array: null * </pre> * * @param strValue * @param clazz * @return */ @SuppressWarnings("unchecked") public static <T> T parseStringValue(String strValue, Class<T> clazz, boolean autoDefault) { if (DEF_NULL.equals(strValue)) { if (!clazz.isPrimitive()) { return null; } if (autoDefault) { return (T) getInternalDefaultValue(clazz); } else { return null; } } if (DEF_EMPTY.equals(strValue)) { if (clazz.isArray()) { return (T) Array.newInstance(clazz.getComponentType(), 0); } if (Map.class.isAssignableFrom(clazz)) { return (T) Collections.EMPTY_MAP; } if (List.class.isAssignableFrom(clazz)) { return (T) new ArrayList<Object>(); } if (Set.class.isAssignableFrom(clazz)) { return (T) new HashSet<Object>(); } if (String.class.equals(clazz)) { return (T) StringUtils.EMPTY; } if (Character.TYPE.equals(clazz) || Character.class.equals(clazz)) { return (T) Character.valueOf(' '); } if (autoDefault) { return (T) getInternalDefaultValue(clazz); } else { return null; } } if (StringUtils.isBlank(strValue)) {// ? if (autoDefault) { return (T) getInternalDefaultValue(clazz); } else { return null; } } else { if (String.class.equals(clazz)) { return (T) strValue; } if (Short.TYPE.equals(clazz) || Short.class.equals(clazz)) { return (T) Short.valueOf(strValue); } if (Integer.TYPE.equals(clazz) || Integer.class.equals(clazz)) { return (T) Integer.valueOf(strValue); } if (Long.TYPE.equals(clazz) || Long.class.equals(clazz)) { return (T) Long.valueOf(strValue); } if (Boolean.TYPE.equals(clazz) || Boolean.class.equals(clazz)) { return (T) Boolean.valueOf(strValue); } if (Float.TYPE.equals(clazz) || Float.class.equals(clazz)) { return (T) Float.valueOf(strValue); } if (Double.TYPE.equals(clazz) || Double.class.equals(clazz)) { return (T) Double.valueOf(strValue); } if (Byte.TYPE.equals(clazz) || Byte.class.equals(clazz)) { return (T) Byte.valueOf(strValue); } if (Character.TYPE.equals(clazz) || Character.class.equals(clazz)) { return (T) Character.valueOf(strValue.charAt(0)); } if (clazz.isArray()) { final Class<?> componentType = clazz.getComponentType(); // String[] if (String.class.equals(componentType)) { return (T) StringUtils.split(strValue, ','); } // ?char[] if (Character.TYPE.equals(componentType)) { return (T) strValue.toCharArray(); } if (Character.class.equals(componentType)) { final char[] tmp = strValue.toCharArray(); final Character[] result = new Character[tmp.length]; for (int i = 0; i < result.length; i++) { result[i] = tmp[i]; } return (T) result; } if (Byte.TYPE.equals(componentType) || Byte.class.equals(componentType)) { return (T) (strValue == null ? null : strValue.getBytes()); } } } return null; }
From source file:com.link_intersystems.lang.Conversions.java
/** * byte to short, int, long, float, or double *///ww w. j av a 2 s . c o m private static boolean isPrimitiveByteWidening(Class<?> to) { boolean isWidening = isPrimitiveShortWidening(to); isWidening |= isIdentity(to, Short.TYPE); return isWidening; }
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.// w w w .ja v a2 s . c om * * @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()); }