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.jcommon.com.util.JsonUtils.java

public static String toJson(Object o, boolean encode) {
    StringBuilder sb = new StringBuilder();
    Class<?> type = null;//from   w  w w .ja v  a 2 s.  c  om
    sb.append("{");
    try {
        java.lang.reflect.Field[] fs = o.getClass().getDeclaredFields();
        String name, value;
        for (java.lang.reflect.Field f : fs) {
            value = null;
            name = f.getName();
            type = f.getType();
            java.lang.reflect.Method m = getMethod(o.getClass(), "get" + name);
            if (m == null)
                m = getMethod(o.getClass(), "is" + name);
            if (m != null) {
                if (String.class == type) {
                    value = (String) m.invoke(o);
                } else if (java.lang.Integer.class == type || Integer.TYPE == type) {
                    value = String.valueOf((Integer) m.invoke(o));
                } else if (java.lang.Boolean.class == type || Boolean.TYPE == type) {
                    value = String.valueOf((Boolean) m.invoke(o));
                } else if (java.lang.Long.class == type || Long.TYPE == type) {
                    value = String.valueOf((Long) m.invoke(o));
                } else if (java.lang.Float.class == type || Float.TYPE == type) {
                    value = String.valueOf((Float) m.invoke(o));
                } else if (java.lang.Long.class == type || Long.TYPE == type) {
                    logger.info("not map Class:" + type);
                }
            }
            if (value != null) {
                if (encode)
                    sb.append("\"" + CoderUtils.encode(name) + "\"" + ":\"" + CoderUtils.encode(value) + "\"");
                else
                    sb.append("\"" + name + "\"" + ":\"" + value + "\"");
                sb.append(",");
            }
        }
    } catch (Throwable t) {
        logger.error("", t);
    }
    if (sb.lastIndexOf(",") == sb.length() - 1)
        sb.deleteCharAt(sb.length() - 1);
    sb.append("}");
    return sb.toString();
}

From source file:mangotiger.poker.channel.EventMatcherImpl.java

Object convert(final Class<?> parameterType, final String value) {
    if (value == null)
        return value;
    if (String.class.equals(parameterType))
        return value;
    if (Integer.class.equals(parameterType))
        return Integer.parseInt(value);
    if (Integer.TYPE.equals(parameterType))
        return Integer.parseInt(value);
    if (Date.class.equals(parameterType))
        return toDate(value);
    final String message = "unsupported parameter type: " + parameterType;
    log().error(message);/*from   w  ww .  j  ava 2 s .  co  m*/
    throw new IllegalStateException(message);
}

From source file:org.zlogic.vogon.web.TomcatConfigurer.java

/**
 * Configures SSL for Tomcat container//from   ww  w. j  av a  2 s  .com
 *
 * @param container ConfigurableEmbeddedServletContainer instance to
 * configure
 */
private void configureSSL(ConfigurableEmbeddedServletContainer container) {
    if (serverTypeDetector.getKeystoreFile().isEmpty() || serverTypeDetector.getKeystorePassword().isEmpty()) {
        log.debug(messages.getString("KEYSTORE_FILE_OR_PASSWORD_NOT_DEFINED"));
        return;
    }

    log.info(MessageFormat.format(messages.getString("USING_KEYSTORE_WITH_PASSWORD"),
            new Object[] { serverTypeDetector.getKeystoreFile(),
                    serverTypeDetector.getKeystorePassword().replaceAll(".{1}", "*") })); //NOI18N
    Object connector;
    Class connectorClass = null;
    try {
        log.debug(messages.getString("CONFIGURING_CONNECTOR"));
        connectorClass = getClass().getClassLoader().loadClass("org.apache.catalina.connector.Connector"); //NOI18N
        connector = connectorClass.newInstance();
        connectorClass.getMethod("setPort", Integer.TYPE).invoke(connector, 8443); //NOI18N
        connectorClass.getMethod("setSecure", Boolean.TYPE).invoke(connector, true); //NOI18N
        connectorClass.getMethod("setScheme", String.class).invoke(connector, "https"); //NOI18N
        connectorClass.getMethod("setURIEncoding", String.class).invoke(connector, utf8Charset.name()); //NOI18N
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | NoSuchMethodException
            | SecurityException | IllegalArgumentException | InvocationTargetException ex) {
        throw new RuntimeException(messages.getString("CANNOT_CONFIGURE_CONNECTOR"), ex);
    }

    Object proto;
    try {
        log.debug(messages.getString("CONFIGURING_PROTOCOLHANDLER_PARAMETERS"));
        proto = connectorClass.getMethod("getProtocolHandler").invoke(connector); //NOI18N
        Class protoClass = proto.getClass();
        log.debug(java.text.MessageFormat.format(messages.getString("CONFIGURING_PROTOCOLHANDLER_CLASS"),
                new Object[] { protoClass.getCanonicalName() }));
        protoClass.getMethod("setSSLEnabled", Boolean.TYPE).invoke(proto, true); //NOI18N
        protoClass.getMethod("setKeystorePass", String.class).invoke(proto,
                serverTypeDetector.getKeystorePassword()); //NOI18N
        protoClass.getMethod("setKeystoreType", String.class).invoke(proto, "JKS"); //NOI18N
        protoClass.getMethod("setKeyAlias", String.class).invoke(proto, "vogonkey"); //NOI18N
        protoClass.getMethod("setKeystoreFile", String.class).invoke(proto,
                new File(serverTypeDetector.getKeystoreFile()).getAbsolutePath()); //NOI18N
    } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException
            | InvocationTargetException ex) {
        throw new RuntimeException(messages.getString("CANNOT_CONFIGURE_PROTOCOLHANDLER"), ex);
    }

    try {
        log.debug(messages.getString("ADDING_CONNECTOR_TO_TOMCATEMBEDDEDSERVLETCONTAINERFACTORY"));
        Object connectors = Array.newInstance(connectorClass, 1);
        Array.set(connectors, 0, connector);
        container.getClass().getMethod("addAdditionalTomcatConnectors", connectors.getClass()).invoke(container,
                connectors); //NOI18N
    } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException
            | InvocationTargetException ex) {
        throw new RuntimeException(
                messages.getString("CANNOT_ADD_CONNECTOR_TO_TOMCATEMBEDDEDSERVLETCONTAINERFACTORY"), ex);
    }
}

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

/**
 * DOCUMENT ME!//from  w  ww.  j a  va2 s. c  om
 *
 * @param name DOCUMENT ME!
 *
 * @return DOCUMENT ME!
 */
public Object get(String name) {
    Object value = dynaValues.get(name);

    if (value != null) {
        return value;
    }

    Class type = getDynaProperty(name).getType();

    if (type == null) {
        throw new NullPointerException("Unspecified property type for " + name);
    }

    if (!type.isPrimitive()) {
        return value;
    }

    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 == Short.TYPE) {
        return new Short((short) 0);
    } else if (type == Integer.TYPE) {
        return new Integer(0);
    } else if (type == Long.TYPE) {
        return new Long(0);
    } else if (type == Float.TYPE) {
        return new Float(0.0);
    } else if (type == Double.TYPE) {
        return new Double(0);
    }

    return null;
}

From source file:eu.unifiedviews.plugins.extractor.filesdownload.ReflectionSocketFactory.java

/**
 * This method attempts to execute Socket method available since Java 1.4
 * using reflection. If the methods are not available or could not be executed <tt>null</tt> is returned
 * //from  w w w.  ja  v a  2 s  .  c o  m
 * @param socketfactoryName
 *            name of the socket factory class
 * @param host
 *            the host name/IP
 * @param port
 *            the port on the host
 * @param localAddress
 *            the local host name/IP to bind the socket to
 * @param localPort
 *            the port on the local machine
 * @param timeout
 *            the timeout value to be used in milliseconds. If the socket cannot be
 *            completed within the given time limit, it will be abandoned
 * @return a connected Socket
 * @throws IOException
 *             if an I/O error occurs while creating the socket
 * @throws UnknownHostException
 *             if the IP address of the host cannot be
 *             determined
 * @throws ConnectTimeoutException
 *             if socket cannot be connected within the
 *             given time limit
 */
public static Socket createSocket(final Object socketfactory, final String host, final int port,
        final InetAddress localAddress, final int localPort, int timeout)
        throws IOException, UnknownHostException, ConnectTimeoutException {
    if (REFLECTION_FAILED) {
        //This is known to have failed before. Do not try it again
        return null;
    }
    // This code uses reflection to essentially do the following:
    //
    //  SocketFactory socketFactory = Class.forName(socketfactoryName).getDefault();
    //  Socket socket = socketFactory.createSocket();
    //  SocketAddress localaddr = new InetSocketAddress(localAddress, localPort);
    //  SocketAddress remoteaddr = new InetSocketAddress(host, port);
    //  socket.bind(localaddr);
    //  socket.connect(remoteaddr, timeout);
    //  return socket;
    try {
        Class socketfactoryClass = socketfactory.getClass();//Class.forName(socketfactoryName);
        Method method = socketfactoryClass.getMethod("getDefault", new Class[] {});
        //            Object socketfactory = method.invoke(null, 
        //                new Object[] {});
        method = socketfactoryClass.getMethod("createSocket", new Class[] {});
        Socket socket = (Socket) method.invoke(socketfactory, new Object[] {});

        if (INETSOCKETADDRESS_CONSTRUCTOR == null) {
            Class addressClass = Class.forName("java.net.InetSocketAddress");
            INETSOCKETADDRESS_CONSTRUCTOR = addressClass
                    .getConstructor(new Class[] { InetAddress.class, Integer.TYPE });
        }

        Object remoteaddr = INETSOCKETADDRESS_CONSTRUCTOR
                .newInstance(new Object[] { InetAddress.getByName(host), new Integer(port) });

        Object localaddr = INETSOCKETADDRESS_CONSTRUCTOR
                .newInstance(new Object[] { localAddress, new Integer(localPort) });

        if (SOCKETCONNECT_METHOD == null) {
            SOCKETCONNECT_METHOD = Socket.class.getMethod("connect",
                    new Class[] { Class.forName("java.net.SocketAddress"), Integer.TYPE });
        }

        if (SOCKETBIND_METHOD == null) {
            SOCKETBIND_METHOD = Socket.class.getMethod("bind",
                    new Class[] { Class.forName("java.net.SocketAddress") });
        }
        SOCKETBIND_METHOD.invoke(socket, new Object[] { localaddr });
        SOCKETCONNECT_METHOD.invoke(socket, new Object[] { remoteaddr, new Integer(timeout) });
        return socket;
    } catch (InvocationTargetException e) {
        Throwable cause = e.getTargetException();
        if (SOCKETTIMEOUTEXCEPTION_CLASS == null) {
            try {
                SOCKETTIMEOUTEXCEPTION_CLASS = Class.forName("java.net.SocketTimeoutException");
            } catch (ClassNotFoundException ex) {
                // At this point this should never happen. Really.
                REFLECTION_FAILED = true;
                return null;
            }
        }
        if (SOCKETTIMEOUTEXCEPTION_CLASS.isInstance(cause)) {
            throw new ConnectTimeoutException(
                    "The host did not accept the connection within timeout of " + timeout + " ms", cause);
        }
        if (cause instanceof IOException) {
            throw (IOException) cause;
        }
        return null;
    } catch (Exception e) {
        REFLECTION_FAILED = true;
        return null;
    }
}

From source file:io.openmessaging.rocketmq.utils.BeanUtils.java

public static void setProperties(Class<?> clazz, Object obj, String methodName, Object value)
        throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
    Class<?> parameterClass = getMethodClass(clazz, methodName);
    Method setterMethod = clazz.getMethod(methodName, parameterClass);
    if (parameterClass == Boolean.TYPE) {
        setterMethod.invoke(obj, Boolean.valueOf(value.toString()));
    } else if (parameterClass == Integer.TYPE) {
        setterMethod.invoke(obj, Integer.valueOf(value.toString()));
    } else if (parameterClass == Double.TYPE) {
        setterMethod.invoke(obj, Double.valueOf(value.toString()));
    } else if (parameterClass == Float.TYPE) {
        setterMethod.invoke(obj, Float.valueOf(value.toString()));
    } else if (parameterClass == Long.TYPE) {
        setterMethod.invoke(obj, Long.valueOf(value.toString()));
    } else//from w w w.  ja v a 2  s.  c  om
        setterMethod.invoke(obj, value);
}

From source file:org.batoo.common.reflect.ReflectHelper.java

private static ConstructorAccessor createConstructorImpl(Constructor<?> constructor) {
    try {// w  w w. j  a  va  2 s .  c  om
        final Class<?> magClass = Class.forName("sun.reflect.MethodAccessorGenerator");
        final Constructor<?> c = magClass.getDeclaredConstructors()[0];
        final Method generateMethod = magClass.getMethod("generateConstructor", Class.class, Class[].class,
                Class[].class, Integer.TYPE);

        ReflectHelper.setAccessible(c, true);
        ReflectHelper.setAccessible(generateMethod, true);

        try {
            final Object mag = c.newInstance();

            return new SunConstructorAccessor(
                    generateMethod.invoke(mag, constructor.getDeclaringClass(), constructor.getParameterTypes(),
                            constructor.getExceptionTypes(), constructor.getModifiers()));
        } finally {
            ReflectHelper.setAccessible(c, false);
            ReflectHelper.setAccessible(generateMethod, false);
        }
    } catch (final Exception e) {
        throw new RuntimeException("Constructor generation failed", e);
    }
}

From source file:com.twitter.elephantbird.pig.piggybank.Invoker.java

private static Class<?> unPrimitivize(Class<?> klass) {
    if (klass.equals(Integer.TYPE)) {
        return Integer.class;
    }/*from w  w  w. j  a  va 2 s.c om*/
    if (klass.equals(Long.TYPE)) {
        return Long.class;
    } else if (klass.equals(Float.TYPE)) {
        return Float.class;
    } else if (klass.equals(Double.TYPE)) {
        return Double.class;
    } else if (klass.equals(DOUBLE_ARRAY_CLASS)) {
        return DOUBLE_ARRAY_CLASS;
    } else {
        return klass;
    }
}

From source file:org.hyperic.hq.plugin.jboss.MBeanUtil.java

private static void initConverters() {
    addConverter(Object.class, new Converter() {
        public Object convert(String param) {
            return param;
        }/*from  w w w  .  ja  va2  s .  co m*/
    });

    addConverter(Short.class, new Converter() {
        public Object convert(String param) {
            return Short.valueOf(param);
        }
    });

    addConverter(Integer.class, new Converter() {
        public Object convert(String param) {
            return Integer.valueOf(param);
        }
    });

    addConverter(Long.class, new Converter() {
        public Object convert(String param) {
            return Long.valueOf(param);
        }
    });

    addConverter(Double.class, new Converter() {
        public Object convert(String param) {
            return Double.valueOf(param);
        }
    });

    addConverter(Boolean.class, new Converter() {
        public Object convert(String param) {
            return Boolean.valueOf(param);
        }
    });

    addConverter(File.class, new Converter() {
        public Object convert(String param) {
            return new File(param);
        }
    });

    addConverter(URL.class, new Converter() {
        public Object convert(String param) {
            try {
                return new URL(param);
            } catch (MalformedURLException e) {
                throw invalid(param, e);
            }
        }
    });

    addConverter(ObjectName.class, new Converter() {
        public Object convert(String param) {
            try {
                return new ObjectName(param);
            } catch (MalformedObjectNameException e) {
                throw invalid(param, e);
            }
        }
    });

    addConverter(List.class, new ListConverter() {
        public Object convert(String[] params) {
            return Arrays.asList(params);
        }
    });

    addConverter(String[].class, new ListConverter() {
        public Object convert(String[] params) {
            return params;
        }
    });

    Class[][] aliases = { { String.class, Object.class }, { Short.TYPE, Short.class },
            { Integer.TYPE, Integer.class }, { Long.TYPE, Long.class }, { Double.TYPE, Double.class },
            { Boolean.TYPE, Boolean.class }, };

    for (int i = 0; i < aliases.length; i++) {
        addConverter(aliases[i][0], aliases[i][1]);
    }
}

From source file:rb.app.QNTransientSCMSystem.java

/**
 * Override eval_theta_q_a in order to account for the affine terms
 * related to basis functions//from   www.ja  va 2 s  .c  o m
 */
@Override
public double eval_theta_q_a(int q) {

    if (q < get_n_basis_functions()) {
        double theta_c_value = eval_theta_c();
        return current_RB_coeffs.getEntry(q) * theta_c_value;
    } else {

        Method meth;

        try {
            Class partypes[] = new Class[2];
            partypes[0] = Integer.TYPE;
            partypes[1] = double[].class;

            meth = mAffineFnsClass.getMethod("evaluateA", partypes);
        } catch (NoSuchMethodException nsme) {
            throw new RuntimeException("getMethod for evaluateA failed", nsme);
        }

        Double theta_val;
        try {
            Object arglist[] = new Object[2];
            arglist[0] = new Integer(q - get_n_basis_functions());
            arglist[1] = current_parameters.getArray();

            Object theta_obj = meth.invoke(mTheta, arglist);
            theta_val = (Double) theta_obj;
        } catch (IllegalAccessException iae) {
            throw new RuntimeException(iae);
        } catch (InvocationTargetException ite) {
            throw new RuntimeException(ite.getCause());
        }

        return theta_val.doubleValue();
    }
}