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:ca.psiphon.tunneledwebview.WebViewProxySettings.java

@TargetApi(Build.VERSION_CODES.KITKAT)
@SuppressWarnings("rawtypes")
private static boolean setWebkitProxyKitKat(Context appContext, String host, int port) {
    System.setProperty("http.proxyHost", host);
    System.setProperty("http.proxyPort", port + "");
    System.setProperty("https.proxyHost", host);
    System.setProperty("https.proxyPort", port + "");
    try {//  w  w w .j  ava2 s  .  c om
        Class applicationClass = Class.forName("android.app.Application");
        Field loadedApkField = applicationClass.getDeclaredField("mLoadedApk");
        loadedApkField.setAccessible(true);
        Object loadedApk = loadedApkField.get(appContext);
        Class loadedApkClass = Class.forName("android.app.LoadedApk");
        Field receiversField = loadedApkClass.getDeclaredField("mReceivers");
        receiversField.setAccessible(true);
        ArrayMap receivers = (ArrayMap) receiversField.get(loadedApk);
        for (Object receiverMap : receivers.values()) {
            for (Object receiver : ((ArrayMap) receiverMap).keySet()) {
                Class receiverClass = receiver.getClass();
                if (receiverClass.getName().contains("ProxyChangeListener")) {
                    Method onReceiveMethod = receiverClass.getDeclaredMethod("onReceive", Context.class,
                            Intent.class);
                    Intent intent = new Intent(Proxy.PROXY_CHANGE_ACTION);

                    final String CLASS_NAME = "android.net.ProxyProperties";
                    Class proxyPropertiesClass = Class.forName(CLASS_NAME);
                    Constructor constructor = proxyPropertiesClass.getConstructor(String.class, Integer.TYPE,
                            String.class);
                    constructor.setAccessible(true);
                    Object proxyProperties = constructor.newInstance(host, port, null);
                    intent.putExtra("proxy", (Parcelable) proxyProperties);

                    onReceiveMethod.invoke(receiver, appContext, intent);
                }
            }
        }
        return true;
    } catch (ClassNotFoundException e) {
    } catch (NoSuchFieldException e) {
    } catch (IllegalAccessException e) {
    } catch (IllegalArgumentException e) {
    } catch (NoSuchMethodException e) {
    } catch (InvocationTargetException e) {
    } catch (InstantiationException e) {
    }
    return false;
}

From source file:org.apache.ode.il.DynamicService.java

@SuppressWarnings("unchecked")
private static Object convertFromOM(Class<?> clazz, OMElement elmt) {
    // Here comes the nasty code...
    if (elmt == null || elmt.getText().length() == 0 && !elmt.getChildElements().hasNext())
        return null;
    else if (clazz.equals(String.class)) {
        return elmt.getText();
    } else if (clazz.equals(Boolean.class) || clazz.equals(Boolean.TYPE)) {
        return (elmt.getText().equals("true") || elmt.getText().equals("yes")) ? Boolean.TRUE : Boolean.FALSE;
    } else if (clazz.equals(QName.class)) {
        // The getTextAsQName is buggy, it sometimes return the full text without extracting namespace
        return OMUtils.getTextAsQName(elmt);
    } else if (clazz.equals(ProcessInfoCustomizer.class)) {
        return new ProcessInfoCustomizer(elmt.getText());
    } else if (Node.class.isAssignableFrom(clazz)) {
        return OMUtils.toDOM(elmt.getFirstElement());
    } else if (clazz.equals(Long.TYPE) || clazz.equals(Long.class)) {
        return Long.parseLong(elmt.getText());
    } else if (clazz.equals(Integer.TYPE) || clazz.equals(Integer.class)) {
        return Integer.parseInt(elmt.getText());
    } else if (clazz.isArray()) {
        ArrayList<Object> alist = new ArrayList<Object>();
        Iterator<OMElement> children = elmt.getChildElements();
        Class<?> targetClazz = clazz.getComponentType();
        while (children.hasNext())
            alist.add(parseType(targetClazz, ((OMElement) children.next()).getText()));
        return alist.toArray((Object[]) Array.newInstance(targetClazz, alist.size()));
    } else if (XmlObject.class.isAssignableFrom(clazz)) {
        try {//  ww  w  .  j  av a 2 s.  c  o  m
            Class beanFactory = clazz.forName(clazz.getCanonicalName() + "$Factory");
            elmt.setNamespace(elmt.declareDefaultNamespace(""));
            elmt.setLocalName("xml-fragment");
            return beanFactory.getMethod("parse", XMLStreamReader.class).invoke(null,
                    elmt.getXMLStreamReaderWithoutCaching());
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(
                    "Couldn't find class " + clazz.getCanonicalName() + ".Factory to instantiate xml bean", e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(
                    "Couldn't access class " + clazz.getCanonicalName() + ".Factory to instantiate xml bean",
                    e);
        } catch (InvocationTargetException e) {
            throw new RuntimeException("Couldn't access xml bean parse method on class "
                    + clazz.getCanonicalName() + ".Factory " + "to instantiate xml bean", e);
        } catch (NoSuchMethodException e) {
            throw new RuntimeException("Couldn't find xml bean parse method on class "
                    + clazz.getCanonicalName() + ".Factory " + "to instantiate xml bean", e);
        }
    } else
        throw new RuntimeException(
                "Couldn't use element " + elmt + " to obtain a management method parameter.");
}

From source file:org.apache.struts2.s1.DynaBeanPropertyAccessorTest.java

/**
 * Create and return a <code>DynaClass</code> instance for our test
 * <code>DynaBean</code>.//from  w  ww .  j av  a 2  s.c  o m
 */
protected DynaClass createDynaClass() {

    int intArray[] = new int[0];
    String stringArray[] = new String[0];

    DynaClass dynaClass = new BasicDynaClass("TestDynaClass", null, new DynaProperty[] {
            new DynaProperty("booleanProperty", Boolean.TYPE), new DynaProperty("booleanSecond", Boolean.TYPE),
            new DynaProperty("doubleProperty", Double.TYPE), new DynaProperty("floatProperty", Float.TYPE),
            new DynaProperty("intArray", intArray.getClass()),
            new DynaProperty("intIndexed", intArray.getClass()), new DynaProperty("intProperty", Integer.TYPE),
            new DynaProperty("listIndexed", List.class), new DynaProperty("longProperty", Long.TYPE),
            new DynaProperty("mappedProperty", Map.class), new DynaProperty("mappedIntProperty", Map.class),
            new DynaProperty("nullProperty", String.class), new DynaProperty("shortProperty", Short.TYPE),
            new DynaProperty("stringArray", stringArray.getClass()),
            new DynaProperty("stringIndexed", stringArray.getClass()),
            new DynaProperty("stringProperty", String.class), });
    return (dynaClass);

}

From source file:cc.aileron.accessor.TypeConvertorImpl.java

/**
 * default constractor/*from   www . j a v  a  2s  .  c o m*/
 */
@Inject
public TypeConvertorImpl() {
    map.put(Boolean.TYPE, new C() {
        @Override
        public Boolean convert(final java.lang.Number number) {
            return number.intValue() != 0;
        }
    });
    map.put(Byte.TYPE, new C() {

        @Override
        public Byte convert(final java.lang.Number number) {
            return number.byteValue();
        }
    });
    map.put(Short.TYPE, new C() {

        @Override
        public Short convert(final java.lang.Number number) {
            return number.shortValue();
        }
    });
    map.put(Integer.TYPE, new C() {
        @Override
        public Integer convert(final java.lang.Number number) {
            return number.intValue();
        }

    });
    map.put(Long.TYPE, new C() {

        @Override
        public Long convert(final java.lang.Number number) {
            return number.longValue();
        }
    });
    map.put(Float.TYPE, new C() {

        @Override
        public Float convert(final java.lang.Number number) {
            return number.floatValue();
        }
    });
    map.put(Double.TYPE, new C() {

        @Override
        public Double convert(final java.lang.Number number) {
            return number.doubleValue();
        }
    });
}

From source file:com.epam.catgenome.manager.externaldb.bindings.ExternalDBBindingTest.java

private Object createParam(Class type)
        throws IllegalAccessException, InvocationTargetException, InstantiationException {
    Object param;/*from  w ww  . j  a v  a  2s  .com*/
    if (type == String.class) {
        param = "test";
    } else if (type == Integer.class || type == Integer.TYPE) {
        param = RandomUtils.nextInt();
    } else if (type == Long.class || type == Long.TYPE) {
        param = RandomUtils.nextLong();
    } else if (type == Float.class || type == Float.TYPE) {
        param = RandomUtils.nextFloat();
    } else if (type == Double.class || type == Double.TYPE) {
        param = RandomUtils.nextDouble();
    } else if (type == Boolean.class || type == Boolean.TYPE) {
        param = RandomUtils.nextBoolean();
    } else if (type == BigInteger.class) {
        param = new BigInteger(TEST_BIGINTEGER);
    } else if (type == List.class) {
        param = new ArrayList<>();
    } else if (type == XMLGregorianCalendar.class) {
        try {
            param = DatatypeFactory.newInstance().newXMLGregorianCalendar();
        } catch (DatatypeConfigurationException e) {
            throw new IllegalArgumentException(e.getMessage(), e);
        }
    } else {
        Constructor[] constructors = type.getConstructors();
        param = constructors[0].newInstance();
    }

    return param;
}

From source file:nl.strohalm.cyclos.dao.ads.AdDAOImpl.java

@Override
public int delete(final boolean flush, final Long... ids) {
    if (ids != null && ids.length > 0) {
        final Map<String, Object> namedParameters = new HashMap<String, Object>();
        namedParameters.put("ids", Arrays.asList(ids));
        bulkUpdate("delete from " + AdCustomFieldValue.class.getName() + " v where v.ad.id in (:ids)",
                namedParameters);//  w w  w.j a v a2s .c o  m
        bulkUpdate("delete from " + AdImage.class.getName() + " ai where ai.ad.id in (:ids)", namedParameters);
        final Integer results = CoercionHelper.coerce(Integer.TYPE, bulkUpdate(
                "update Ad ad set ad.deleteDate = current_date(), ad.description = null where ad.id in (:ids)",
                namedParameters));
        if (flush) {
            flush();
        }
        return results;
    } else {
        return 0;
    }
}

From source file:com.manydesigns.elements.util.Util.java

public static boolean isNumericType(Class type) {
    return Number.class.isAssignableFrom(type) || type == Integer.TYPE || type == Byte.TYPE
            || type == Short.TYPE || type == Long.TYPE || type == Float.TYPE || type == Double.TYPE;
}

From source file:com.adobe.acs.commons.data.Variant.java

@SuppressWarnings("squid:S3776")
public final <T> void setValue(T val) {
    if (val == null) {
        return;/*from   w w  w  .ja  v a 2 s.  c  om*/
    }
    Class type = val.getClass();
    if (type == Variant.class) {
        Variant v = (Variant) val;
        longVal = v.longVal;
        doubleVal = v.doubleVal;
        stringVal = v.stringVal;
        booleanVal = v.booleanVal;
        dateVal = v.dateVal;
    } else if (type == Byte.TYPE || type == Byte.class) {
        setLongVal(((Byte) val).longValue());
    } else if (type == Integer.TYPE || type == Integer.class) {
        setLongVal(((Integer) val).longValue());
    } else if (type == Long.TYPE || type == Long.class) {
        setLongVal((Long) val);
    } else if (type == Short.TYPE || type == Short.class) {
        setLongVal(((Short) val).longValue());
    } else if (type == Float.TYPE || type == Float.class) {
        setDoubleVal((Double) val);
    } else if (type == Double.TYPE || type == Double.class) {
        setDoubleVal((Double) val);
    } else if (type == Boolean.TYPE || type == Boolean.class) {
        setBooleanVal((Boolean) val);
    } else if (type == String.class) {
        setStringVal((String) val);
    } else if (type == Date.class) {
        setDateVal((Date) val);
    } else if (type == Instant.class) {
        setDateVal(new Date(((Instant) val).toEpochMilli()));
    } else if (type == Calendar.class) {
        setDateVal(((Calendar) val).getTime());
    } else {
        setStringVal(String.valueOf(val));
    }
}

From source file:com.curl.orb.context.Seasar2ApplicationContext.java

private void addComponentName(Object container, List<String> componentNames)
        throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
    Integer componentSize = (Integer) MethodUtils.invokeMethod(container, "getComponentDefSize", new Object[0]);
    Method getComponentDefMethod = container.getClass().getMethod("getComponentDef", Integer.TYPE);
    for (int i = 0; i < componentSize; i++) {
        Object componentDef = getComponentDefMethod.invoke(container, new Object[] { i });
        String componentName = (String) MethodUtils.invokeMethod(componentDef, "getComponentName",
                new Object[0]);
        if (StringUtils.isEmpty(componentName) == false) {
            componentNames.add(componentName);
        }/*from w  w  w.jav  a  2s .  com*/
    }
    Integer childSize = (Integer) MethodUtils.invokeMethod(container, "getChildSize", new Object[0]);
    for (int i = 0; i < childSize; i++) {
        Object child = MethodUtils.invokeMethod(container, "getChild", new Object[] { i });
        addComponentName(child, componentNames);
    }
}

From source file:com.github.michalbednarski.intentslab.Utils.java

public static Object getDefaultValueForPrimitveClass(Class<?> aClass) {
    if (aClass == Boolean.TYPE) {
        return false;
    } else if (aClass == Byte.TYPE) {
        return (byte) 0;
    } else if (aClass == Character.TYPE) {
        return 0;
    } else if (aClass == Short.TYPE) {
        return (short) 0;
    } else if (aClass == Integer.TYPE) {
        return 0;
    } else if (aClass == Long.TYPE) {
        return (long) 0;
    } else if (aClass == Float.TYPE) {
        return 0;
    } else if (aClass == Double.TYPE) {
        return 0;
    } else {//from w  w w .  j  av a  2 s. co m
        throw new RuntimeException("Not primitive type");
    }
}