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:org.liveSense.api.beanprocessors.DbStandardBeanProcessor.java

/**
 * Convert a <code>ResultSet</code> column into an object.  Simple 
 * implementations could just call <code>rs.getObject(index)</code> while
 * more complex implementations could perform type manipulation to match 
 * the column's type to the bean property type.
 * //w  w  w  .  j av  a 2 s  .c  o m
 * <p>
 * This implementation calls the appropriate <code>ResultSet</code> getter 
 * method for the given property type to perform the type conversion.  If 
 * the property type doesn't match one of the supported 
 * <code>ResultSet</code> types, <code>getObject</code> is called.
 * </p>
 * 
 * @param rs The <code>ResultSet</code> currently being processed.  It is
 * positioned on a valid row before being passed into this method.
 * 
 * @param index The current column index being processed.
 * 
 * @param propType The bean property type that this column needs to be
 * converted into.
 * 
 * @throws SQLException if a database access error occurs
 * 
 * @return The object from the <code>ResultSet</code> at the given column
 * index after optional type processing or <code>null</code> if the column
 * value was SQL NULL.
 */
protected Object processColumn(ResultSet rs, int index, Class<?> propType) throws SQLException {

    if (!propType.isPrimitive() && rs.getObject(index) == null) {
        return null;
    }

    if (!propType.isPrimitive() && rs.getObject(index) == null) {
        return null;
    }

    if (propType.equals(String.class)) {
        return rs.getString(index);

    } else if (propType.equals(Integer.TYPE) || propType.equals(Integer.class)) {
        return (rs.getInt(index));

    } else if (propType.equals(Boolean.TYPE) || propType.equals(Boolean.class)) {
        return (rs.getBoolean(index));

    } else if (propType.equals(Long.TYPE) || propType.equals(Long.class)) {
        return (rs.getLong(index));

    } else if (propType.equals(Double.TYPE) || propType.equals(Double.class)) {
        return (rs.getDouble(index));

    } else if (propType.equals(Float.TYPE) || propType.equals(Float.class)) {
        return (rs.getFloat(index));

    } else if (propType.equals(Short.TYPE) || propType.equals(Short.class)) {
        return (rs.getShort(index));

    } else if (propType.equals(Byte.TYPE) || propType.equals(Byte.class)) {
        return (rs.getByte(index));

    } else if (propType.equals(Timestamp.class)) {
        return rs.getTimestamp(index);

    } else {
        return rs.getObject(index);
    }

}

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>/* www .  ja v a 2s .  c  om*/
 *
 * <p>If the input array is {@code null}, 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}
 * @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, Short.valueOf(element), Short.TYPE);
}

From source file:org.enerj.apache.commons.beanutils.ConvertUtilsBean.java

/**
 * Remove all registered {@link Converter}s, and re-establish the
 * standard Converters.//from  w w w .j ava 2 s.  co m
 */
public void deregister() {

    boolean booleanArray[] = new boolean[0];
    byte byteArray[] = new byte[0];
    char charArray[] = new char[0];
    double doubleArray[] = new double[0];
    float floatArray[] = new float[0];
    int intArray[] = new int[0];
    long longArray[] = new long[0];
    short shortArray[] = new short[0];
    String stringArray[] = new String[0];

    converters.clear();
    register(BigDecimal.class, new BigDecimalConverter());
    register(BigInteger.class, new BigIntegerConverter());
    register(Boolean.TYPE, new BooleanConverter(defaultBoolean));
    register(Boolean.class, new BooleanConverter(defaultBoolean));
    register(booleanArray.getClass(), new BooleanArrayConverter(booleanArray));
    register(Byte.TYPE, new ByteConverter(defaultByte));
    register(Byte.class, new ByteConverter(defaultByte));
    register(byteArray.getClass(), new ByteArrayConverter(byteArray));
    register(Character.TYPE, new CharacterConverter(defaultCharacter));
    register(Character.class, new CharacterConverter(defaultCharacter));
    register(charArray.getClass(), new CharacterArrayConverter(charArray));
    register(Class.class, new ClassConverter());
    register(Double.TYPE, new DoubleConverter(defaultDouble));
    register(Double.class, new DoubleConverter(defaultDouble));
    register(doubleArray.getClass(), new DoubleArrayConverter(doubleArray));
    register(Float.TYPE, new FloatConverter(defaultFloat));
    register(Float.class, new FloatConverter(defaultFloat));
    register(floatArray.getClass(), new FloatArrayConverter(floatArray));
    register(Integer.TYPE, new IntegerConverter(defaultInteger));
    register(Integer.class, new IntegerConverter(defaultInteger));
    register(intArray.getClass(), new IntegerArrayConverter(intArray));
    register(Long.TYPE, new LongConverter(defaultLong));
    register(Long.class, new LongConverter(defaultLong));
    register(longArray.getClass(), new LongArrayConverter(longArray));
    register(Short.TYPE, new ShortConverter(defaultShort));
    register(Short.class, new ShortConverter(defaultShort));
    register(shortArray.getClass(), new ShortArrayConverter(shortArray));
    register(String.class, new StringConverter());
    register(stringArray.getClass(), new StringArrayConverter(stringArray));
    register(Date.class, new SqlDateConverter());
    register(Time.class, new SqlTimeConverter());
    register(Timestamp.class, new SqlTimestampConverter());
    register(File.class, new FileConverter());
    register(URL.class, new URLConverter());

}

From source file:wicket.util.lang.Objects.java

/**
 * Returns the value converted numerically to the given class type
 * //from  www .  ja  va2  s  .  c o m
 * This method also detects when arrays are being converted and converts the
 * components of one array to the type of the other.
 * 
 * @param value
 *            an object to be converted to the given type
 * @param toType
 *            class type to be converted to
 * @return converted value of the type given, or value if the value cannot
 *         be converted to the given type.
 */
public static Object convertValue(Object value, Class toType) {
    Object result = null;

    if (value != null) {
        /* If array -> array then convert components of array individually */
        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 = new Integer((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 = new Byte((byte) longValue(value));
            }
            if ((toType == Character.class) || (toType == Character.TYPE)) {
                result = new Character((char) longValue(value));
            }
            if ((toType == Short.class) || (toType == Short.TYPE)) {
                result = new Short((short) longValue(value));
            }
            if ((toType == Long.class) || (toType == Long.TYPE)) {
                result = new Long(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);
            }
        }
    } else {
        if (toType.isPrimitive()) {
            result = primitiveDefaults.get(toType);
        }
    }
    return result;
}

From source file:org.evosuite.testcarver.testcase.EvoTestCaseCodeGenerator.java

private final Class<?> getClassForName(String type) {
    try {//from   w w  w.  j a  v a 2 s  .c  om
        if (type.equals("boolean") || type.equals("java.lang.Boolean")) {
            return Boolean.TYPE;
        } else if (type.equals("byte") || type.equals("java.lang.Byte")) {
            return Byte.TYPE;
        } else if (type.equals("char") || type.equals("java.lang.Character")) {
            return Character.TYPE;
        } else if (type.equals("double") || type.equals("java.lang.Double")) {
            return Double.TYPE;
        } else if (type.equals("float") || type.equals("java.lang.Float")) {
            return Float.TYPE;
        } else if (type.equals("int") || type.equals("java.lang.Integer")) {
            return Integer.TYPE;
        } else if (type.equals("long") || type.equals("java.lang.Long")) {
            return Long.TYPE;
        } else if (type.equals("short") || type.equals("java.lang.Short")) {
            return Short.TYPE;
        } else if (type.equals("String")) {
            return Class.forName("java.lang." + type, true,
                    TestGenerationContext.getInstance().getClassLoaderForSUT());
        }

        if (type.endsWith("[]")) {
            // see http://stackoverflow.com/questions/3442090/java-what-is-this-ljava-lang-object

            final StringBuilder arrayTypeNameBuilder = new StringBuilder(30);

            int index = 0;
            while ((index = type.indexOf('[', index)) != -1) {
                arrayTypeNameBuilder.append('[');
                index++;
            }

            arrayTypeNameBuilder.append('L'); // always needed for Object arrays

            // remove bracket from type name get array component type
            type = type.replace("[]", "");
            arrayTypeNameBuilder.append(type);

            arrayTypeNameBuilder.append(';'); // finalize object array name

            return Class.forName(arrayTypeNameBuilder.toString(), true,
                    TestGenerationContext.getInstance().getClassLoaderForSUT());
        } else {
            return Class.forName(ResourceList.getClassNameFromResourcePath(type), true,
                    TestGenerationContext.getInstance().getClassLoaderForSUT());
        }
    } catch (final ClassNotFoundException e) {
        throw new RuntimeException(e);
    }
}

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>/*ww w.j  av  a2  s  . com*/
 *
 * <p>If the input array is {@code null}, 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}
 * @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(final short[] array, final int index, final short element) {
    return (short[]) add(array, index, Short.valueOf(element), Short.TYPE);
}

From source file:com.wavemaker.json.JSONMarshallerTest.java

public void testValueTransformer() throws Exception {

    JSONState state = new JSONState();

    Map<String, Object> enclosed = new HashMap<String, Object>();
    enclosed.put("hi", "foo");

    Map<String, Object> map = new HashMap<String, Object>();
    map.put("bar", enclosed);

    assertEquals("{\"bar\":{\"hi\":\"foo\"}}", JSONMarshaller.marshal(map, state));

    state.setValueTransformer(new ValueTransformer() {

        @Override//  w w w  .  ja  v  a2  s  .c om
        public Tuple.Three<Object, FieldDefinition, Integer> transformToJSON(Object input,
                FieldDefinition fieldDefinition, int arrayLevel, Object root, String path,
                TypeState typeState) {

            if ("bar.hi".equals(path)) {
                GenericFieldDefinition fd = new GenericFieldDefinition();
                fd.setTypeDefinition(typeState.getType(String.class.getName()));
                return new Tuple.Three<Object, FieldDefinition, Integer>(
                        input + " transformed, root: " + root.hashCode(), fd, 0);
            } else if ("bar.bye".equals(path)) {
                GenericFieldDefinition fd = new GenericFieldDefinition();
                fd.setTypeDefinition(typeState.getType(Short.TYPE.getName()));
                return new Tuple.Three<Object, FieldDefinition, Integer>(12, fd, 0);
            } else {
                return null;
            }
        }

        @Override
        public Tuple.Three<Object, FieldDefinition, Integer> transformToJava(Object input,
                FieldDefinition fieldDefinition, int arrayLevel, Object root, String path,
                TypeState typeState) {

            // unused in this test
            return null;
        }
    });

    assertEquals("{\"bar\":{\"hi\":\"foo transformed, root: " + map.hashCode() + "\"}}",
            JSONMarshaller.marshal(map, state));

    enclosed.remove("hi");
    enclosed.put("bye", "fdks");
    assertEquals("{\"bar\":{\"bye\":12}}", JSONMarshaller.marshal(map, state));
}

From source file:at.ac.tuwien.infosys.jcloudscale.utility.ReflectionUtil.java

/**
 * Returns the virtual machine's Class object for the named primitive type.<br/>
 * If the type is not a primitive type, {@code null} is returned.
 *
 * @param name the name of the type/*from  ww  w. j  ava 2s . co m*/
 * @return the Class instance representing the primitive type
 */
private static Class<?> getPrimitiveType(String name) {
    name = StringUtils.defaultIfEmpty(name, "");
    if (name.equals("int"))
        return Integer.TYPE;
    if (name.equals("short"))
        return Short.TYPE;
    if (name.equals("long"))
        return Long.TYPE;
    if (name.equals("float"))
        return Float.TYPE;
    if (name.equals("double"))
        return Double.TYPE;
    if (name.equals("byte"))
        return Byte.TYPE;
    if (name.equals("char"))
        return Character.TYPE;
    if (name.equals("boolean"))
        return Boolean.TYPE;
    if (name.equals("void"))
        return Void.TYPE;

    return null;
}

From source file:org.apache.jasper.compiler.JspUtil.java

/**
 * Produces a String representing a call to the EL interpreter.
 * @param expression a String containing zero or more "${}" expressions
 * @param expectedType the expected type of the interpreted result
 * @param fnmapvar Variable pointing to a function map.
 * @param XmlEscape True if the result should do XML escaping
 * @return a String representing a call to the EL interpreter.
 *//*from w  ww  .  j  a v a 2s.co  m*/
public static String interpreterCall(boolean isTagFile, String expression, Class expectedType, String fnmapvar,
        boolean XmlEscape) {
    /*
     * Determine which context object to use.
     */
    String jspCtxt = null;
    if (isTagFile)
        jspCtxt = "this.getJspContext()";
    else
        jspCtxt = "pageContext";

    /*
          * Determine whether to use the expected type's textual name
     * or, if it's a primitive, the name of its correspondent boxed
     * type.
          */
    String targetType = expectedType.getName();
    String primitiveConverterMethod = null;
    if (expectedType.isPrimitive()) {
        if (expectedType.equals(Boolean.TYPE)) {
            targetType = Boolean.class.getName();
            primitiveConverterMethod = "booleanValue";
        } else if (expectedType.equals(Byte.TYPE)) {
            targetType = Byte.class.getName();
            primitiveConverterMethod = "byteValue";
        } else if (expectedType.equals(Character.TYPE)) {
            targetType = Character.class.getName();
            primitiveConverterMethod = "charValue";
        } else if (expectedType.equals(Short.TYPE)) {
            targetType = Short.class.getName();
            primitiveConverterMethod = "shortValue";
        } else if (expectedType.equals(Integer.TYPE)) {
            targetType = Integer.class.getName();
            primitiveConverterMethod = "intValue";
        } else if (expectedType.equals(Long.TYPE)) {
            targetType = Long.class.getName();
            primitiveConverterMethod = "longValue";
        } else if (expectedType.equals(Float.TYPE)) {
            targetType = Float.class.getName();
            primitiveConverterMethod = "floatValue";
        } else if (expectedType.equals(Double.TYPE)) {
            targetType = Double.class.getName();
            primitiveConverterMethod = "doubleValue";
        }
    }

    if (primitiveConverterMethod != null) {
        XmlEscape = false;
    }

    /*
          * Build up the base call to the interpreter.
          */
    // XXX - We use a proprietary call to the interpreter for now
    // as the current standard machinery is inefficient and requires
    // lots of wrappers and adapters.  This should all clear up once
    // the EL interpreter moves out of JSTL and into its own project.
    // In the future, this should be replaced by code that calls
    // ExpressionEvaluator.parseExpression() and then cache the resulting
    // expression objects.  The interpreterCall would simply select
    // one of the pre-cached expressions and evaluate it.
    // Note that PageContextImpl implements VariableResolver and
    // the generated Servlet/SimpleTag implements FunctionMapper, so
    // that machinery is already in place (mroth).
    targetType = toJavaSourceType(targetType);
    StringBuffer call = new StringBuffer(
            "(" + targetType + ") " + "org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate" + "("
                    + Generator.quote(expression) + ", " + targetType + ".class, " + "(PageContext)" + jspCtxt
                    + ", " + fnmapvar + ", " + XmlEscape + ")");

    /*
          * Add the primitive converter method if we need to.
          */
    if (primitiveConverterMethod != null) {
        call.insert(0, "(");
        call.append(")." + primitiveConverterMethod + "()");
    }

    return call.toString();
}

From source file:com.gdcn.modules.db.jdbc.processor.CamelBeanProcessor.java

/**
 * Convert a <code>ResultSet</code> column into an object.  Simple
 * implementations could just call <code>rs.getObject(index)</code> while
 * more complex implementations could perform type manipulation to match
 * the column's type to the bean property type.
 *
 * <p>/*ww  w  . j  av a  2s .  com*/
 * This implementation calls the appropriate <code>ResultSet</code> getter
 * method for the given property type to perform the type conversion.  If
 * the property type doesn't match one of the supported
 * <code>ResultSet</code> types, <code>getObject</code> is called.
 * </p>
 *
 * @param rs The <code>ResultSet</code> currently being processed.  It is
 * positioned on a valid row before being passed into this method.
 *
 * @param index The current column index being processed.
 *
 * @param propType The bean property type that this column needs to be
 * converted into.
 *
 * @throws SQLException if a database access error occurs
 *
 * @return The object from the <code>ResultSet</code> at the given column
 * index after optional type processing or <code>null</code> if the column
 * value was SQL NULL.
 */
protected Object processColumn(ResultSet rs, int index, Class<?> propType) throws SQLException {

    if (!propType.isPrimitive() && rs.getObject(index) == null) {
        return null;
    }

    if (propType.equals(String.class)) {
        return rs.getString(index);

    } else if (propType.equals(Integer.TYPE) || propType.equals(Integer.class)) {
        return Integer.valueOf(rs.getInt(index));

    } else if (propType.equals(Boolean.TYPE) || propType.equals(Boolean.class)) {
        return Boolean.valueOf(rs.getBoolean(index));

    } else if (propType.equals(Long.TYPE) || propType.equals(Long.class)) {
        return Long.valueOf(rs.getLong(index));

    } else if (propType.equals(Double.TYPE) || propType.equals(Double.class)) {
        return Double.valueOf(rs.getDouble(index));

    } else if (propType.equals(Float.TYPE) || propType.equals(Float.class)) {
        return Float.valueOf(rs.getFloat(index));

    } else if (propType.equals(Short.TYPE) || propType.equals(Short.class)) {
        return Short.valueOf(rs.getShort(index));

    } else if (propType.equals(Byte.TYPE) || propType.equals(Byte.class)) {
        return Byte.valueOf(rs.getByte(index));

    } else if (propType.equals(Timestamp.class)) {
        return rs.getTimestamp(index);

    } else if (propType.equals(SQLXML.class)) {
        return rs.getSQLXML(index);

    } else {
        return rs.getObject(index);
    }

}