Example usage for java.lang Integer TYPE

List of usage examples for java.lang Integer TYPE

Introduction

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

Prototype

Class TYPE

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

Click Source Link

Document

The Class instance representing the primitive type int .

Usage

From source file:org.enerj.apache.commons.beanutils.locale.LocaleBeanificationTestCase.java

/** Tests whether calls are independent for different classloaders */
public void testContextClassloaderIndependence() throws Exception {

    class TestIndependenceThread extends Thread {
        private Signal signal;
        private PrimitiveBean bean;

        TestIndependenceThread(Signal signal, PrimitiveBean bean) {
            this.signal = signal;
            this.bean = bean;
        }/*from  w w w. j  a v a2 s. c  o  m*/

        public void run() {
            try {
                signal.setSignal(3);
                LocaleConvertUtils.register(new LocaleConverter() {
                    public Object convert(Class type, Object value) {
                        return new Integer(9);
                    }

                    public Object convert(Class type, Object value, String pattern) {
                        return new Integer(9);
                    }
                }, Integer.TYPE, Locale.getDefault());
                LocaleBeanUtils.setProperty(bean, "int", "1");
            } catch (Exception e) {
                e.printStackTrace();
                signal.setException(e);
            }
        }

        public String toString() {
            return "TestIndependenceThread";
        }
    }

    PrimitiveBean bean = new PrimitiveBean();
    LocaleBeanUtils.setProperty(bean, "int", new Integer(1));
    assertEquals("Wrong property value (1)", 1, bean.getInt());

    LocaleConvertUtils.register(new LocaleConverter() {
        public Object convert(Class type, Object value) {
            return new Integer(5);
        }

        public Object convert(Class type, Object value, String pattern) {
            return new Integer(5);
        }
    }, Integer.TYPE, Locale.getDefault());
    LocaleBeanUtils.setProperty(bean, "int", "1");
    assertEquals("Wrong property value(2)", 5, bean.getInt());

    Signal signal = new Signal();
    signal.setSignal(1);
    TestIndependenceThread thread = new TestIndependenceThread(signal, bean);
    thread.setContextClassLoader(new TestClassLoader());

    thread.start();
    thread.join();

    assertNull("Exception thrown by test thread:" + signal.getException(), signal.getException());
    assertEquals("Signal not set by test thread", 3, signal.getSignal());
    assertEquals("Wrong property value(3)", 9, bean.getInt());

}

From source file:org.brekka.stillingar.spring.bpp.ConfigurationBeanPostProcessorTest.java

@Test
public void primitiveDefaultInteger() {
    assertEquals(ConfigurationBeanPostProcessor.primitiveDefault(Integer.TYPE), Integer.valueOf(0));
}

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

/** Tests whether calls are independent for different classloaders */
public void testContextClassloaderIndependence() throws Exception {

    class TestIndependenceThread extends Thread {
        private Signal signal;
        private PrimitiveBean bean;

        TestIndependenceThread(Signal signal, PrimitiveBean bean) {
            this.signal = signal;
            this.bean = bean;
        }/*  w w  w . ja v  a  2 s  .  co  m*/

        public void run() {
            try {
                signal.setSignal(3);
                ConvertUtils.register(new Converter() {
                    public Object convert(Class type, Object value) {
                        return new Integer(9);
                    }
                }, Integer.TYPE);
                BeanUtils.setProperty(bean, "int", new Integer(1));
            } catch (Exception e) {
                e.printStackTrace();
                signal.setException(e);
            }
        }

        public String toString() {
            return "TestIndependenceThread";
        }
    }

    PrimitiveBean bean = new PrimitiveBean();
    BeanUtils.setProperty(bean, "int", new Integer(1));
    assertEquals("Wrong property value (1)", 1, bean.getInt());

    ConvertUtils.register(new Converter() {
        public Object convert(Class type, Object value) {
            return new Integer(5);
        }
    }, Integer.TYPE);
    BeanUtils.setProperty(bean, "int", new Integer(1));
    assertEquals("Wrong property value(2)", 5, bean.getInt());

    Signal signal = new Signal();
    signal.setSignal(1);
    TestIndependenceThread thread = new TestIndependenceThread(signal, bean);
    thread.setContextClassLoader(new TestClassLoader());

    thread.start();
    thread.join();

    assertNull("Exception thrown by test thread:" + signal.getException(), signal.getException());
    assertEquals("Signal not set by test thread", 3, signal.getSignal());
    assertEquals("Wrong property value(3)", 9, bean.getInt());

}

From source file:org.cloudata.core.common.io.CObjectWritable.java

/** Read a {@link CWritable}, {@link String}, primitive type, or an array of
 * the preceding. *///from  w  ww .  j  a  v a2s  .co m
@SuppressWarnings("unchecked")
public static Object readObject(DataInput in, CObjectWritable objectWritable, CloudataConf conf,
        boolean arrayComponent, Class componentClass) throws IOException {
    String className;
    if (arrayComponent) {
        className = componentClass.getName();
    } else {
        className = CUTF8.readString(in);
        //SANGCHUL
        //   System.out.println("SANGCHUL] className:" + className);
    }

    Class<?> declaredClass = PRIMITIVE_NAMES.get(className);
    if (declaredClass == null) {
        try {
            declaredClass = conf.getClassByName(className);
        } catch (ClassNotFoundException e) {
            //SANGCHUL
            e.printStackTrace();
            throw new RuntimeException("readObject can't find class[className=" + className + "]", e);
        }
    }

    Object instance;

    if (declaredClass.isPrimitive()) { // primitive types

        if (declaredClass == Boolean.TYPE) { // boolean
            instance = Boolean.valueOf(in.readBoolean());
        } else if (declaredClass == Character.TYPE) { // char
            instance = Character.valueOf(in.readChar());
        } else if (declaredClass == Byte.TYPE) { // byte
            instance = Byte.valueOf(in.readByte());
        } else if (declaredClass == Short.TYPE) { // short
            instance = Short.valueOf(in.readShort());
        } else if (declaredClass == Integer.TYPE) { // int
            instance = Integer.valueOf(in.readInt());
        } else if (declaredClass == Long.TYPE) { // long
            instance = Long.valueOf(in.readLong());
        } else if (declaredClass == Float.TYPE) { // float
            instance = Float.valueOf(in.readFloat());
        } else if (declaredClass == Double.TYPE) { // double
            instance = Double.valueOf(in.readDouble());
        } else if (declaredClass == Void.TYPE) { // void
            instance = null;
        } else {
            throw new IllegalArgumentException("Not a primitive: " + declaredClass);
        }

    } else if (declaredClass.isArray()) { // array
        //System.out.println("SANGCHUL] is array");
        int length = in.readInt();
        //System.out.println("SANGCHUL] array length : " + length);
        //System.out.println("Read:in.readInt():" + length);
        if (declaredClass.getComponentType() == Byte.TYPE) {
            byte[] bytes = new byte[length];
            in.readFully(bytes);
            instance = bytes;
        } else if (declaredClass.getComponentType() == ColumnValue.class) {
            instance = readColumnValue(in, conf, declaredClass, length);
        } else {
            Class componentType = declaredClass.getComponentType();

            // SANGCHUL
            //System.out.println("SANGCHUL] componentType : " + componentType.getName());

            instance = Array.newInstance(componentType, length);
            for (int i = 0; i < length; i++) {
                Object arrayComponentInstance = readObject(in, null, conf, !componentType.isArray(),
                        componentType);
                Array.set(instance, i, arrayComponentInstance);
                //Array.set(instance, i, readObject(in, conf));
            }
        }
    } else if (declaredClass == String.class) { // String
        instance = CUTF8.readString(in);
    } else if (declaredClass.isEnum()) { // enum
        instance = Enum.valueOf((Class<? extends Enum>) declaredClass, CUTF8.readString(in));
    } else if (declaredClass == ColumnValue.class) {
        //ColumnValue?  ?? ?? ?  ? ?.
        //? ?   ? ? ? ? . 
        Class instanceClass = null;
        try {
            short typeDiff = in.readShort();
            if (typeDiff == TYPE_DIFF) {
                instanceClass = conf.getClassByName(CUTF8.readString(in));
            } else {
                instanceClass = declaredClass;
            }
        } catch (ClassNotFoundException e) {
            throw new RuntimeException("readObject can't find class", e);
        }
        ColumnValue columnValue = new ColumnValue();
        columnValue.readFields(in);
        instance = columnValue;
    } else { // Writable

        Class instanceClass = null;
        try {
            short typeDiff = in.readShort();
            // SANGCHUL
            //System.out.println("SANGCHUL] typeDiff : " + typeDiff);
            //System.out.println("Read:in.readShort():" + typeDiff);
            if (typeDiff == TYPE_DIFF) {
                // SANGCHUL
                String classNameTemp = CUTF8.readString(in);
                //System.out.println("SANGCHUL] typeDiff : " + classNameTemp);
                instanceClass = conf.getClassByName(classNameTemp);
                //System.out.println("Read:UTF8.readString(in):" + instanceClass.getClass());
            } else {
                instanceClass = declaredClass;
            }
        } catch (ClassNotFoundException e) {

            // SANGCHUL
            e.printStackTrace();
            throw new RuntimeException("readObject can't find class", e);
        }

        CWritable writable = CWritableFactories.newInstance(instanceClass, conf);
        writable.readFields(in);
        //System.out.println("Read:writable.readFields(in)");
        instance = writable;

        if (instanceClass == NullInstance.class) { // null
            declaredClass = ((NullInstance) instance).declaredClass;
            instance = null;
        }
    }

    if (objectWritable != null) { // store values
        objectWritable.declaredClass = declaredClass;
        objectWritable.instance = instance;
    }

    return instance;
}

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

/**
 * DOCUMENT ME!//from  w w  w .  j a va2 s  . co m
 *
 * @param clazz DOCUMENT ME!
 *
 * @return DOCUMENT ME!
 */
private boolean isInteger(Class clazz) {
    return Integer.class.isAssignableFrom(clazz) || (clazz == Integer.TYPE);
}

From source file:org.broadleafcommerce.openadmin.server.service.persistence.module.BasicPersistenceModule.java

protected Class<?> getBasicBroadleafType(SupportedFieldType fieldType) {
    Class<?> response;/* w ww .j  a v  a 2 s  . co  m*/
    switch (fieldType) {
    case BOOLEAN:
        response = Boolean.TYPE;
        break;
    case DATE:
        response = Date.class;
        break;
    case DECIMAL:
        response = BigDecimal.class;
        break;
    case MONEY:
        response = Money.class;
        break;
    case INTEGER:
        response = Integer.TYPE;
        break;
    case UNKNOWN:
        response = null;
        break;
    default:
        response = String.class;
        break;
    }

    return response;
}

From source file:org.hyperic.hq.product.jmx.MxUtil.java

static String getUrlFromPid(String ptql) throws IOException {
    Sigar sigar = new Sigar();
    String address;//  w  w  w .ja v a 2s  .  c  o  m
    long pid;

    try {
        pid = new ProcessFinder(sigar).findSingleProcess(ptql);

        Class caddrLinkClass = Class.forName("sun.management.ConnectorAddressLink");

        Method importFrom = caddrLinkClass.getMethod("importFrom", new Class[] { Integer.TYPE });

        address = (String) importFrom.invoke(caddrLinkClass, new Object[] { new Integer((int) pid) });
    } catch (ClassNotFoundException e) {
        String jvm = System.getProperty("java.vm.name") + " " + System.getProperty("java.vm.version");
        throw new IOException(ptql + " " + e.getMessage() + " not supported by " + jvm);
    } catch (InvocationTargetException e) {
        throw new IOException(ptql + " " + e.getCause());
    } catch (Exception e) {
        throw new IOException(ptql + " " + e);
    } finally {
        sigar.close();
    }

    if (address == null) {
        throw new IOException("Unable to determine " + PROP_JMX_URL + " using vmid=" + pid
                + ".  Server must be started with: " + "-Dcom.sun.management.jmxremote");
    }
    log.debug(PTQL_PREFIX + ptql + " resolved to vmid=" + pid + ", " + PROP_JMX_URL + "=" + address);

    return address;
}

From source file:com.github.gekoh.yagen.util.FieldInfo.java

private static List<FieldInfo> convertFields(List<FieldInfo> fields, Class baseEntity) {

    for (Field field : baseEntity.getDeclaredFields()) {
        FieldInfo fi;//from w  w w .ja v  a  2s  .  c om
        Class type = field.getType();
        String name = field.getName();
        Column column = field.getAnnotation(Column.class);
        if (field.isAnnotationPresent(Embedded.class)) {
            if (field.isAnnotationPresent(AttributeOverride.class)) {
                fi = new FieldInfo(type, name, field.getAnnotation(AttributeOverride.class));
            } else {
                fi = new FieldInfo(type, name, field.getAnnotation(AttributeOverrides.class));
            }
        } else if (field.isAnnotationPresent(Enumerated.class)) {
            fi = new FieldInfo(type, name, true, column);
        } else if (column != null && !field.isAnnotationPresent(CollectionTable.class)) {
            if (type.isPrimitive()) {
                if (type.equals(Boolean.TYPE)) {
                    type = Boolean.class;
                } else if (type.equals(Long.TYPE)) {
                    type = Long.class;
                } else if (type.equals(Integer.TYPE)) {
                    type = Integer.class;
                } else if (type.equals(Short.TYPE)) {
                    type = Short.class;
                } else if (type.equals(Byte.TYPE)) {
                    type = Byte.class;
                } else if (type.equals(Double.TYPE)) {
                    type = Double.class;
                } else if (type.equals(Float.TYPE)) {
                    type = Float.class;
                } else if (type.equals(Character.TYPE)) {
                    type = Character.class;
                }
            }
            fi = new FieldInfo(type, name, false, column);
        } else if ((field.isAnnotationPresent(ManyToOne.class) && !field.isAnnotationPresent(JoinTable.class))
                || (field.isAnnotationPresent(OneToOne.class)
                        && StringUtils.isEmpty(field.getAnnotation(OneToOne.class).mappedBy()))) {
            String columnName = field.isAnnotationPresent(JoinColumn.class)
                    ? field.getAnnotation(JoinColumn.class).name()
                    : field.getName();
            fi = getIdFieldInfo(type, name, columnName);
        } else if (!field.isAnnotationPresent(Transient.class)
                && (Collection.class.isAssignableFrom(type) || Map.class.isAssignableFrom(type))
                && (field.isAnnotationPresent(JoinColumn.class) || field.isAnnotationPresent(JoinTable.class)
                        || field.isAnnotationPresent(CollectionTable.class))) {
            fi = new FieldInfo(type, name);
        } else {
            continue;
        }
        if (field.isAnnotationPresent(Type.class)) {
            fi.addAnnotation(field.getAnnotation(Type.class));
        }
        fi.setField(field);
        fields.add(fi);
    }

    return fields;
}

From source file:iing.uabc.edu.mx.persistencia.util.JSON.java

private static void stringifyObject(JsonGenerator generator, BeanManager manager) {

    String keyName;/*from www.  j a  va2 s .  co  m*/

    Field[] fields = manager.getFields();

    //Read every field and transform  it to a json property string
    for (Field field : fields) {
        Class fieldType = manager.getType(field.getName());
        keyName = field.getName();
        Object value = manager.getProperty(keyName);

        System.out.println("KeyName: " + keyName);
        System.out.println("Valor " + keyName + ": " + value);

        if (value == null) {
            //Set to null the property
            generator.writeNull(keyName);
            continue;
        }
        //Is a String
        if (fieldType == String.class) {
            generator.write(keyName, String.valueOf(value));
        } //Is a Date
        else if (fieldType == Date.class) {
            String date = DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(value);

            generator.write(keyName, date);

        } //Is a integer
        else if (fieldType == Integer.class || fieldType == Integer.TYPE) {
            generator.write(keyName, (int) value);
        } //Is a double
        else if (fieldType == Double.class || fieldType == Double.TYPE) {
            generator.write(keyName, (double) value);
        } //Is boolean
        else if (fieldType == Boolean.class || fieldType == Boolean.TYPE) {
            generator.write(keyName, (boolean) value);
        } //Is a collection
        else if (value instanceof Collection) {
            Class elementClass = manager.getCollectionElementType(keyName);

            System.out.println("Nueva Colleccion [] de clase: " + elementClass.getSimpleName());

            generator.writeStartArray(keyName);

            //Create new collection manager with the given class
            CollectionManager collectionManager = new CollectionManager((Collection) value, elementClass);

            stringifyArray(generator, collectionManager);

            generator.writeEnd();
        } else {
            //Is a object... probably
            BeanManager objectManager = new BeanManager(value);

            System.out.println("Nuevo Objecto {}: " + value.getClass().getSimpleName());
            generator.writeStartObject(keyName);

            stringifyObject(generator, objectManager);

            generator.writeEnd();
        }
    }

}

From source file:com.initialxy.cordova.themeablebrowser.ThemeableBrowserUnmarshaller.java

/**
 * Gracefully convert given Object to given class given the precondition
 * that both are primitives or one of the classes associated with
 * primitives. eg. If val is of type Double and cls is of type int, return
 * Integer type with appropriate value truncation so that it can be assigned
 * to field with field.set()./*from  w ww.ja va2s . c om*/
 *
 * @param cls
 * @param val
 * @return
 * @throws com.initialxy.cordova.themeablebrowser.ThemeableBrowserUnmarshaller.TypeMismatchException
 */
private static Object convertToPrimitiveFieldObj(Object val, Class<?> cls) {
    Class<?> valClass = val.getClass();
    Object result = null;

    try {
        Method getter = null;
        if (cls.isAssignableFrom(Byte.class) || cls.isAssignableFrom(Byte.TYPE)) {
            getter = valClass.getMethod("byteValue");
        } else if (cls.isAssignableFrom(Short.class) || cls.isAssignableFrom(Short.TYPE)) {
            getter = valClass.getMethod("shortValue");
        } else if (cls.isAssignableFrom(Integer.class) || cls.isAssignableFrom(Integer.TYPE)) {
            getter = valClass.getMethod("intValue");
        } else if (cls.isAssignableFrom(Long.class) || cls.isAssignableFrom(Long.TYPE)) {
            getter = valClass.getMethod("longValue");
        } else if (cls.isAssignableFrom(Float.class) || cls.isAssignableFrom(Float.TYPE)) {
            getter = valClass.getMethod("floatValue");
        } else if (cls.isAssignableFrom(Double.class) || cls.isAssignableFrom(Double.TYPE)) {
            getter = valClass.getMethod("doubleValue");
        } else if (cls.isAssignableFrom(Boolean.class) || cls.isAssignableFrom(Boolean.TYPE)) {
            if (val instanceof Boolean) {
                result = val;
            } else {
                throw new TypeMismatchException(cls, val.getClass());
            }
        } else if (cls.isAssignableFrom(Character.class) || cls.isAssignableFrom(Character.TYPE)) {
            if (val instanceof String && ((String) val).length() == 1) {
                char c = ((String) val).charAt(0);
                result = Character.valueOf(c);
            } else if (val instanceof String) {
                throw new TypeMismatchException(
                        "Expected Character, " + "but received String with length other than 1.");
            } else {
                throw new TypeMismatchException(
                        String.format("Expected Character, accept String, but got %s.", val.getClass()));
            }
        }

        if (getter != null) {
            result = getter.invoke(val);
        }
    } catch (NoSuchMethodException e) {
        throw new TypeMismatchException(String.format("Cannot convert %s to %s.", val.getClass(), cls));
    } catch (SecurityException e) {
        throw new TypeMismatchException(String.format("Cannot convert %s to %s.", val.getClass(), cls));
    } catch (IllegalAccessException e) {
        throw new TypeMismatchException(String.format("Cannot convert %s to %s.", val.getClass(), cls));
    } catch (InvocationTargetException e) {
        throw new TypeMismatchException(String.format("Cannot convert %s to %s.", val.getClass(), cls));
    }

    return result;
}