Example usage for java.lang Short TYPE

List of usage examples for java.lang Short TYPE

Introduction

In this page you can find the example usage for java.lang Short TYPE.

Prototype

Class TYPE

To view the source code for java.lang Short TYPE.

Click Source Link

Document

The Class instance representing the primitive type short .

Usage

From source file:com.mawujun.util.AnnotationUtils.java

/**
 * Helper method for comparing two objects of an array type.
 *
 * @param componentType the component type of the array
 * @param o1 the first object/*from   ww w. ja v  a 2  s.com*/
 * @param o2 the second object
 * @return a flag whether these objects are equal
 */
private static boolean arrayMemberEquals(Class<?> componentType, Object o1, Object o2) {
    if (componentType.isAnnotation()) {
        return annotationArrayMemberEquals((Annotation[]) o1, (Annotation[]) o2);
    }
    if (componentType.equals(Byte.TYPE)) {
        return Arrays.equals((byte[]) o1, (byte[]) o2);
    }
    if (componentType.equals(Short.TYPE)) {
        return Arrays.equals((short[]) o1, (short[]) o2);
    }
    if (componentType.equals(Integer.TYPE)) {
        return Arrays.equals((int[]) o1, (int[]) o2);
    }
    if (componentType.equals(Character.TYPE)) {
        return Arrays.equals((char[]) o1, (char[]) o2);
    }
    if (componentType.equals(Long.TYPE)) {
        return Arrays.equals((long[]) o1, (long[]) o2);
    }
    if (componentType.equals(Float.TYPE)) {
        return Arrays.equals((float[]) o1, (float[]) o2);
    }
    if (componentType.equals(Double.TYPE)) {
        return Arrays.equals((double[]) o1, (double[]) o2);
    }
    if (componentType.equals(Boolean.TYPE)) {
        return Arrays.equals((boolean[]) o1, (boolean[]) o2);
    }
    return Arrays.equals((Object[]) o1, (Object[]) o2);
}

From source file:com.haulmont.restapi.service.QueriesControllerManager.java

protected Object toObject(Class clazz, String value) throws ParseException {
    if (clazz.isArray()) {
        Class componentType = clazz.getComponentType();
        JsonParser jsonParser = new JsonParser();
        JsonArray jsonArray = jsonParser.parse(value).getAsJsonArray();
        List result = new ArrayList();
        for (JsonElement jsonElement : jsonArray) {
            String stringValue = (jsonElement.isJsonPrimitive() && jsonElement.getAsJsonPrimitive().isString())
                    ? jsonElement.getAsJsonPrimitive().getAsString()
                    : jsonElement.toString();
            Object arrayElementValue = toObject(componentType, stringValue);
            result.add(arrayElementValue);
        }/*from  w w w.java  2  s .  c  om*/
        return result;
    }
    if (String.class == clazz)
        return value;
    if (Integer.class == clazz || Integer.TYPE == clazz || Byte.class == clazz || Byte.TYPE == clazz
            || Short.class == clazz || Short.TYPE == clazz)
        return Datatypes.getNN(Integer.class).parse(value);
    if (Date.class == clazz) {
        try {
            return Datatypes.getNN(Date.class).parse(value);
        } catch (ParseException e) {
            try {
                return Datatypes.getNN(java.sql.Date.class).parse(value);
            } catch (ParseException e1) {
                return Datatypes.getNN(Time.class).parse(value);
            }
        }
    }
    if (BigDecimal.class == clazz)
        return Datatypes.getNN(BigDecimal.class).parse(value);
    if (Boolean.class == clazz || Boolean.TYPE == clazz)
        return Datatypes.getNN(Boolean.class).parse(value);
    if (Long.class == clazz || Long.TYPE == clazz)
        return Datatypes.getNN(Long.class).parse(value);
    if (Double.class == clazz || Double.TYPE == clazz || Float.class == clazz || Float.TYPE == clazz)
        return Datatypes.getNN(Double.class).parse(value);
    if (UUID.class == clazz)
        return UUID.fromString(value);
    throw new IllegalArgumentException("Parameters of type " + clazz.getName() + " are not supported");
}

From source file:us.mn.state.health.lims.testanalyte.form.TestAnalyteTestResultActionForm.java

/**
 * <p>/*from  w  w w .ja  va  2s. c o m*/
 * Return the value of a simple property with the specified name.
 * </p>
 * 
 * @param name
 *            Name of the property whose value is to be retrieved
 * 
 * @exception IllegalArgumentException
 *                if there is no property of the specified name
 * @exception NullPointerException
 *                if the type specified for the property is invalid
 */
public Object get(String name) {

    // Return any non-null value for the specified property
    Object value = dynaValues.get(name);

    //System.out.println("I am in get(String name) " + name + " " + value);
    if (value != null) {
        return (value);
    }

    // Return a null value for a non-primitive property
    Class type = getDynaProperty(name).getType();
    if (type == null) {
        throw new NullPointerException("The type for property " + name + " is invalid");
    }
    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(0.0));
    } else if (type == Float.TYPE) {
        return (new Float((float) 0.0));
    } else if (type == Integer.TYPE) {
        return (new Integer(0));
    } else if (type == Long.TYPE) {
        return (new Long(0));
    } else if (type == Short.TYPE) {
        return (new Short((short) 0));
    } else {
        return (null);
    }

}

From source file:com.opengamma.language.definition.JavaTypeInfo.java

private static Class<?> findClass(final String className) throws ClassNotFoundException {
    if ("boolean".equals(className)) {
        return Boolean.TYPE;
    } else if ("char".equals(className)) {
        return Character.TYPE;
    } else if ("double".equals(className)) {
        return Double.TYPE;
    } else if ("float".equals(className)) {
        return Float.TYPE;
    } else if ("int".equals(className)) {
        return Integer.TYPE;
    } else if ("long".equals(className)) {
        return Long.TYPE;
    } else if ("short".equals(className)) {
        return Short.TYPE;
    } else {//from ww  w  .  j  ava2s.  c  om
        return Class.forName(className);
    }
}

From source file:com.xwtec.xwserver.util.json.util.JSONUtils.java

/**
 * Tests if Class represents a primitive number or wrapper.<br>
 *///from  w w  w  .  j  a va  2  s . c  o m
public static boolean isNumber(Class clazz) {
    return clazz != null && (Byte.TYPE.isAssignableFrom(clazz) || Short.TYPE.isAssignableFrom(clazz)
            || Integer.TYPE.isAssignableFrom(clazz) || Long.TYPE.isAssignableFrom(clazz)
            || Float.TYPE.isAssignableFrom(clazz) || Double.TYPE.isAssignableFrom(clazz)
            || Number.class.isAssignableFrom(clazz));
}

From source file:org.openamf.io.AMFSerializer.java

protected Object[] convertPrimitiveArrayToObjectArray(Object array) throws IOException {
    Class componentType = array.getClass().getComponentType();

    Object[] result = null;//from  ww w  .  j av  a2 s. c o m

    if (componentType == null) {
        throw new NullPointerException("componentType is null");
    } else if (componentType == Character.TYPE) {
        char[] carray = (char[]) array;
        result = new Object[carray.length];
        for (int i = 0; i < carray.length; i++) {
            result[i] = new Character(carray[i]);
        }
    } else if (componentType == Byte.TYPE) {
        byte[] barray = (byte[]) array;
        result = new Object[barray.length];
        for (int i = 0; i < barray.length; i++) {
            result[i] = new Byte(barray[i]);
        }
    } else if (componentType == Short.TYPE) {
        short[] sarray = (short[]) array;
        result = new Object[sarray.length];
        for (int i = 0; i < sarray.length; i++) {
            result[i] = new Short(sarray[i]);
        }
    } else if (componentType == Integer.TYPE) {
        int[] iarray = (int[]) array;
        result = new Object[iarray.length];
        for (int i = 0; i < iarray.length; i++) {
            result[i] = new Integer(iarray[i]);
        }
    } else if (componentType == Long.TYPE) {
        long[] larray = (long[]) array;
        result = new Object[larray.length];
        for (int i = 0; i < larray.length; i++) {
            result[i] = new Long(larray[i]);
        }
    } else if (componentType == Double.TYPE) {
        double[] darray = (double[]) array;
        result = new Object[darray.length];
        for (int i = 0; i < darray.length; i++) {
            result[i] = new Double(darray[i]);
        }
    } else if (componentType == Float.TYPE) {
        float[] farray = (float[]) array;
        result = new Object[farray.length];
        for (int i = 0; i < farray.length; i++) {
            result[i] = new Float(farray[i]);
        }
    } else if (componentType == Boolean.TYPE) {
        boolean[] barray = (boolean[]) array;
        result = new Object[barray.length];
        for (int i = 0; i < barray.length; i++) {
            result[i] = new Boolean(barray[i]);
        }
    } else {
        throw new IllegalArgumentException("unexpected component type: " + componentType.getClass().getName());
    }

    return result;
}

From source file:net.sf.json.JSONDynaBean.java

/**
 * DOCUMENT ME!//from w ww .ja v  a2s  .co m
 *
 * @param dest DOCUMENT ME!
 * @param src DOCUMENT ME!
 *
 * @return DOCUMENT ME!
 */
protected boolean isDynaAssignable(Class dest, Class src) {
    boolean assignable = dest.isAssignableFrom(src);
    assignable = ((dest == Boolean.TYPE) && (src == Boolean.class)) ? true : assignable;
    assignable = ((dest == Byte.TYPE) && (src == Byte.class)) ? true : assignable;
    assignable = ((dest == Character.TYPE) && (src == Character.class)) ? true : assignable;
    assignable = ((dest == Short.TYPE) && (src == Short.class)) ? true : assignable;
    assignable = ((dest == Integer.TYPE) && (src == Integer.class)) ? true : assignable;
    assignable = ((dest == Long.TYPE) && (src == Long.class)) ? true : assignable;
    assignable = ((dest == Float.TYPE) && (src == Float.class)) ? true : assignable;
    assignable = ((dest == Double.TYPE) && (src == Double.class)) ? true : assignable;

    if ((src == Double.TYPE) || Double.class.isAssignableFrom(src)) {
        assignable = (isByte(dest) || isShort(dest) || isInteger(dest) || isLong(dest) || isFloat(dest)) ? true
                : assignable;
    }

    if ((src == Float.TYPE) || Float.class.isAssignableFrom(src)) {
        assignable = (isByte(dest) || isShort(dest) || isInteger(dest) || isLong(dest)) ? true : assignable;
    }

    if ((src == Long.TYPE) || Long.class.isAssignableFrom(src)) {
        assignable = (isByte(dest) || isShort(dest) || isInteger(dest)) ? true : assignable;
    }

    if ((src == Integer.TYPE) || Integer.class.isAssignableFrom(src)) {
        assignable = (isByte(dest) || isShort(dest)) ? true : assignable;
    }

    if ((src == Short.TYPE) || Short.class.isAssignableFrom(src)) {
        assignable = (isByte(dest)) ? true : assignable;
    }

    return assignable;
}

From source file:org.acmsl.commons.utils.ConversionUtils.java

/**
 * Converts given String to short, if given value is not null.
 * @param value the value to convert.//from ww w. j ava  2  s. co  m
 * @return the converted value.
 */
@Nullable
public Short toShortIfNotNull(@Nullable final String value) {
    Short result = null;

    @Nullable
    final Converter t_Converter = ConvertUtils.lookup(Short.TYPE);

    if (t_Converter != null) {
        @Nullable
        final Object t_Result = t_Converter.convert(Short.TYPE, value);

        if (t_Result instanceof Short) {
            result = (Short) t_Result;
        }
    }

    return result;
}

From source file:org.lunarray.model.descriptor.converter.def.AbstractDefaultConverterTool.java

/**
 * Populates the simple converters.// ww w . ja  v  a  2 s.  c  o m
 */
private void populateSimpleConverters() {
    // Primitives.
    this.converters.put(Integer.TYPE, new IntegerConverter());
    this.converters.put(Double.TYPE, new DoubleConverter());
    this.converters.put(Float.TYPE, new FloatConverter());
    this.converters.put(Long.TYPE, new LongConverter());
    this.converters.put(Byte.TYPE, new ByteConverter());
    this.converters.put(Short.TYPE, new ShortConverter());
    this.converters.put(Character.TYPE, new CharacterConverter());
    this.converters.put(Boolean.TYPE, new BooleanConverter());
    // Date types.
    this.addConverter(new CalendarConverter());
    this.addConverter(new DateConverter());
    // SQL Date types.
    this.addConverter(new SqlDateConverter());
    this.addConverter(new SqlTimeConverter());
    this.addConverter(new SqlTimestampConverter());
    // String.
    this.addConverter(new IdempotentConverter());
    // Numbers.
    this.addConverter(new IntegerConverter());
    this.addConverter(new DoubleConverter());
    this.addConverter(new FloatConverter());
    this.addConverter(new LongConverter());
    this.addConverter(new ByteConverter());
    this.addConverter(new ShortConverter());
    // Character.
    this.addConverter(new CharacterConverter());
    // Math types.
    this.addConverter(new BigDecimalConverter());
    this.addConverter(new BigIntegerConverter());
    // Boolean.
    this.addConverter(new BooleanConverter());
}

From source file:com.xwtec.xwserver.util.json.util.JSONUtils.java

/**
 * Tests if obj is a primitive number or wrapper.<br>
 *//*from w ww .  j a  va  2  s  .c o  m*/
public static boolean isNumber(Object obj) {
    if ((obj != null && obj.getClass() == Byte.TYPE) || (obj != null && obj.getClass() == Short.TYPE)
            || (obj != null && obj.getClass() == Integer.TYPE) || (obj != null && obj.getClass() == Long.TYPE)
            || (obj != null && obj.getClass() == Float.TYPE)
            || (obj != null && obj.getClass() == Double.TYPE)) {
        return true;
    }

    return obj instanceof Number;
}