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.apache.maven.plugin.javadoc.AbstractFixJavadocMojo.java

/**
 * Add a default Javadoc for the given field, i.e.:
 * <br/>/*from w w  w .  ja  v  a2  s  .  co m*/
 * <code>
 * <font color="#808080">1</font>&nbsp;<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font>
 * <font color="#3f5fbf">&#47;&#42;&#42;&nbsp;Constant&nbsp;</font><font color="#7f7f9f">&lt;code&gt;</font>
 * <font color="#3f5fbf">MY_STRING_CONSTANT=&#34;value&#34;</font>
 * <font color="#7f7f9f">&lt;/code&gt;&nbsp;</font><font color="#3f5fbf">&#42;&#47;</font><br />
 * <font color="#808080">2</font>&nbsp;<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font>
 * <font color="#7f0055"><b>public&nbsp;static&nbsp;final&nbsp;</b></font>
 * <font color="#000000">String&nbsp;MY_STRING_CONSTANT&nbsp;=&nbsp;</font>
 * <font color="#2a00ff">&#34;value&#34;</font><font color="#000000">;</font>
 * </code>
 *
 * @param stringWriter not null
 * @param field        not null
 * @param indent       not null
 * @throws IOException if any
 */
private void addDefaultFieldComment(final StringWriter stringWriter, final JavaField field, final String indent)
        throws IOException {
    StringBuilder sb = new StringBuilder();

    sb.append(indent).append(START_JAVADOC).append(" ");
    sb.append("Constant <code>").append(field.getName());

    if (StringUtils.isNotEmpty(field.getInitializationExpression())) {
        String qualifiedName = field.getType().getJavaClass().getFullyQualifiedName();

        if (qualifiedName.equals(Byte.TYPE.toString()) || qualifiedName.equals(Short.TYPE.toString())
                || qualifiedName.equals(Integer.TYPE.toString()) || qualifiedName.equals(Long.TYPE.toString())
                || qualifiedName.equals(Float.TYPE.toString()) || qualifiedName.equals(Double.TYPE.toString())
                || qualifiedName.equals(Boolean.TYPE.toString())
                || qualifiedName.equals(Character.TYPE.toString())) {
            sb.append("=");
            sb.append(field.getInitializationExpression().trim());
        }

        if (qualifiedName.equals(String.class.getName())) {
            StringBuilder value = new StringBuilder();
            String[] lines = getLines(field.getInitializationExpression());
            for (String line : lines) {
                StringTokenizer token = new StringTokenizer(line.trim(), "\"\n\r");
                while (token.hasMoreTokens()) {
                    String s = token.nextToken();

                    if (s.trim().equals("+")) {
                        continue;
                    }
                    if (s.trim().endsWith("\\")) {
                        s += "\"";
                    }
                    value.append(s);
                }
            }

            sb.append("=\"");
            // reduce the size
            if (value.length() < 40) {
                sb.append(value.toString()).append("\"");
            } else {
                sb.append(value.toString().substring(0, 39)).append("\"{trunked}");
            }
        }
    }

    sb.append("</code> ").append(END_JAVADOC);
    sb.append(EOL);

    stringWriter.write(sb.toString());
}

From source file:cn.sinobest.jzpt.framework.utils.string.StringUtils.java

/**
 *  obj isArrayJoin/*from   ww w . j  a v a2  s . c om*/
 *
 * @Title: join
 * @return String 
 * @throws
 */
public static String join(Object obj, String dchar) {
    Assert.notNull(obj);
    if (!obj.getClass().isArray()) {
        throw new IllegalArgumentException("The input object to join must be a Array and not null.");
    }
    Class<?> priType = obj.getClass().getComponentType();
    if (priType == Boolean.TYPE) {
        return join((boolean[]) obj, dchar);
    } else if (priType == Byte.TYPE) {
        return join((byte[]) obj, dchar);
    } else if (priType == Character.TYPE) {
        return join((char[]) obj, dchar);
    } else if (priType == Integer.TYPE) {
        return join((int[]) obj, dchar);
    } else if (priType == Long.TYPE) {
        return join((long[]) obj, dchar);
    } else if (priType == Float.TYPE) {
        return join((float[]) obj, dchar);
    } else if (priType == Double.TYPE) {
        return join((double[]) obj, dchar);
    } else if (priType == Short.TYPE) {
        return join((short[]) obj, dchar);
    } else {
        return join((Object[]) obj, dchar);
    }
}

From source file:org.getobjects.eoaccess.EOSQLExpression.java

/**
 * Returns the SQL String representation of the given value Object.
 * <ul>//from  ww w.j  a  v  a 2 s  . c om
 *   <li>'null' will be rendered as the SQL 'NULL'
 *   <li>String values are rendered using formatStringValue()
 *   <li>Number values are rendered using sqlStringForNumber()
 *   <li>Date values are rendered using formatDateValue()
 *   <li>toString() is called on EORawSQLValue values
 *   <li>arrays and Collections are rendered in "( )"
 *   <li>EOKeyGlobalID objects with one value are rendered as their value
 * </ul>
 * When an EOQualifierVariable is encountered an error is logged and null is
 * returned.
 * For unknown objects the string representation is rendered.
 * 
 * @param _v - some value to be formatted for inclusion in the SQL
 * @return a String representing the value
 */
protected String formatValue(Object _v) {
    // own method for basic stuff
    if (_v == null)
        return "NULL";

    if (_v instanceof String)
        return this.formatStringValue((String) _v);

    if (_v instanceof Number)
        return this.sqlStringForNumber((Number) _v);

    if (_v instanceof Boolean)
        return this.sqlStringForBoolean((Boolean) _v);

    if (_v instanceof Date)
        return this.formatDateValue((Date) _v, null /* attribute */);

    if (_v instanceof EORawSQLValue)
        return _v.toString();

    /* process lists */

    final Class itemClazz = _v.getClass().getComponentType();
    if (itemClazz != null) { /* array */
        if (itemClazz == java.lang.Integer.TYPE) {
            int[] nums = (int[]) _v;
            if (nums.length <= 0)
                return "( )"; /* empty list */

            StringBuilder sql = new StringBuilder(256);
            sql.append("( ");
            boolean isFirst = true;
            for (int o : nums) {
                if (isFirst)
                    isFirst = false;
                else
                    sql.append(", ");

                sql.append(o);
            }
            sql.append(" )");
            return sql.toString();
        }

        _v = Arrays.asList((Object[]) _v);
    }

    if (_v instanceof Collection) {
        final Collection c = (Collection) _v;
        if (c.size() <= 0)
            return "( )"; /* empty list */

        final StringBuilder sql = new StringBuilder(256);
        sql.append("( ");
        boolean isFirst = true;
        for (Object o : c) {
            if (isFirst)
                isFirst = false;
            else
                sql.append(", ");

            sql.append(this.formatValue(o));
        }
        sql.append(" )");
        return sql.toString();
    }

    if (_v instanceof EOKeyGlobalID) {
        final Object[] vals = ((EOKeyGlobalID) _v).keyValues();
        if (vals == null || vals.length == 0) {
            log.error("got EOKeyGlobalID w/o values: " + _v);
            return null;
        }
        if (vals.length > 1) {
            log.error("cannot format EOKeyGlobalID with more than one value: " + _v);
            return null;
        }

        return this.formatValue(vals[0]);
    }

    /* warn about qualifier variables */

    if (_v instanceof EOQualifierVariable) {
        log.error("detected unresolved qualifier variable: " + _v);
        return null;
    }

    /* fallback to string representation */

    log.warn("unexpected SQL value, rendering as string: " + _v);
    return this.formatStringValue(_v.toString());
}

From source file:org.eclipse.jubula.rc.swt.driver.RobotSwtImpl.java

/**
 * @param key the key to toggle//from w  ww  .ja v a2 s. c  o  m
 * @return true, if <b>windows</b> key is already locked
 */
private boolean isActivatedWIN(int key)
        throws ClassNotFoundException, IllegalArgumentException, SecurityException, IllegalAccessException,
        NoSuchFieldException, NoSuchMethodException, InvocationTargetException {

    // Use reflection so that this compiles on all platforms
    String className = "org.eclipse.swt.internal.win32.OS"; //$NON-NLS-1$
    Class clazz = Class.forName(className);
    int osSpecificKey = -1;
    switch (key) {
    case SWT.NUM_LOCK:
        osSpecificKey = clazz.getDeclaredField("VK_NUMLOCK").getInt(null); //$NON-NLS-1$
        break;
    case SWT.CAPS_LOCK:
        osSpecificKey = clazz.getDeclaredField("VK_CAPITAL").getInt(null); //$NON-NLS-1$
        break;
    case SWT.SCROLL_LOCK:
        osSpecificKey = clazz.getDeclaredField("VK_SCROLL").getInt(null); //$NON-NLS-1$
        break;
    default:
        break;
    }

    // Call org.eclipse.swt.internal.win32.OS.GetKeyState
    String methodName = "GetKeyState"; //$NON-NLS-1$
    Class[] params = new Class[] { Integer.TYPE, };
    Object[] args = new Object[] { new Integer(osSpecificKey), };
    Method method = clazz.getMethod(methodName, params);
    short keyState = ((Short) method.invoke(clazz, args)).shortValue();

    if (keyState == 1) {
        return true;
    }
    return false;
}

From source file:com.taobao.adfs.util.Utilities.java

public static String getSqlTypeForJavaType(Class<?> type) throws IOException {
    if (type == null)
        throw new IOException("type is null");
    if (type.equals(Byte.TYPE) || type.equals(Byte.class))
        return "TINYINT";
    if (type.equals(Short.TYPE) || type.equals(Short.class))
        return "SMALLINT";
    if (type.equals(Integer.TYPE) || type.equals(Integer.class))
        return "INT";
    if (type.equals(Long.TYPE) || type.equals(Long.class))
        return "BIGINT";
    if (type.equals(Float.TYPE) || type.equals(Float.class))
        return "FLOAT";
    if (type.equals(Double.TYPE) || type.equals(Double.class))
        return "DOUBLE";
    if (type.equals(String.class))
        return "VARCHAR";
    else//from  w w w.j av  a  2  s  .c  om
        throw new IOException("unsupportted type=" + type.getSimpleName());
}

From source file:alice.tuprolog.lib.OOLibrary.java

/**
 * /*  www  . j  av  a2  s  . co  m*/
 * parsing 'as' operator, which makes it possible to define the specific
 * class of an argument
 * 
 */
private boolean parse_as(Object[] values, Class<?>[] types, int i, PTerm castWhat, PTerm castTo) {
    try {
        if (!(castWhat instanceof Number)) {
            String castTo_name = alice.util.Tools.removeApices(((Struct) castTo).getName());
            String castWhat_name = alice.util.Tools.removeApices(castWhat.getTerm().toString());
            // System.out.println(castWhat_name+" "+castTo_name);
            if (castTo_name.equals("java.lang.String") && castWhat_name.equals("true")) {
                values[i] = "true";
                types[i] = String.class;
                return true;
            } else if (castTo_name.equals("java.lang.String") && castWhat_name.equals("false")) {
                values[i] = "false";
                types[i] = String.class;
                return true;
            } else if (castTo_name.endsWith("[]")) {
                switch (castTo_name) {
                case "boolean[]":
                    castTo_name = "[Z";
                    break;
                case "byte[]":
                    castTo_name = "[B";
                    break;
                case "short[]":
                    castTo_name = "[S";
                    break;
                case "char[]":
                    castTo_name = "[C";
                    break;
                case "int[]":
                    castTo_name = "[I";
                    break;
                case "long[]":
                    castTo_name = "[L";
                    break;
                case "float[]":
                    castTo_name = "[F";
                    break;
                case "double[]":
                    castTo_name = "[D";
                    break;
                default:
                    castTo_name = "[L" + castTo_name.substring(0, castTo_name.length() - 2) + ';';
                    break;
                }
            }
            if (!castWhat_name.equals("null")) {
                Object obj_to_cast = currentObjects.get(castWhat_name);
                if (obj_to_cast == null) {
                    if (castTo_name.equals("boolean")) {
                        switch (castWhat_name) {
                        case "true":
                            values[i] = new Boolean(true);
                            break;
                        case "false":
                            values[i] = new Boolean(false);
                            break;
                        default:
                            return false;
                        }
                        types[i] = Boolean.TYPE;
                    } else {
                        // conversion to array
                        return false;
                    }
                } else {
                    values[i] = obj_to_cast;
                    try {
                        types[i] = Class.forName(castTo_name, true, dynamicLoader);
                    } catch (ClassNotFoundException ex) {
                        getEngine().logger.warn("Java class not found: " + castTo_name);
                        return false;
                    }
                }
            } else {
                values[i] = null;
                switch (castTo_name) {
                case "byte":
                    types[i] = Byte.TYPE;
                    break;
                case "short":
                    types[i] = Short.TYPE;
                    break;
                case "char":
                    types[i] = Character.TYPE;
                    break;
                case "int":
                    types[i] = Integer.TYPE;
                    break;
                case "long":
                    types[i] = java.lang.Long.TYPE;
                    break;
                case "float":
                    types[i] = java.lang.Float.TYPE;
                    break;
                case "double":
                    types[i] = java.lang.Double.TYPE;
                    break;
                case "boolean":
                    types[i] = Boolean.TYPE;
                    break;
                default:
                    try {
                        types[i] = Class.forName(castTo_name, true, dynamicLoader);
                    } catch (ClassNotFoundException ex) {
                        getEngine().logger.warn("Java class not found: " + castTo_name);
                        return false;
                    }
                    break;
                }
            }
        } else {
            Number num = (Number) castWhat;
            String castTo_name = ((Struct) castTo).getName();
            switch (castTo_name) {
            case "byte":
                values[i] = new Byte((byte) num.intValue());
                types[i] = Byte.TYPE;
                break;
            case "short":
                values[i] = new Short((short) num.intValue());
                types[i] = Short.TYPE;
                break;
            case "int":
                values[i] = new Integer(num.intValue());
                types[i] = Integer.TYPE;
                break;
            case "long":
                values[i] = new java.lang.Long(num.longValue());
                types[i] = java.lang.Long.TYPE;
                break;
            case "float":
                values[i] = new java.lang.Float(num.floatValue());
                types[i] = java.lang.Float.TYPE;
                break;
            case "double":
                values[i] = new java.lang.Double(num.doubleValue());
                types[i] = java.lang.Double.TYPE;
                break;
            default:
                return false;
            }
        }
    } catch (Exception ex) {
        getEngine().logger.warn("Casting " + castWhat + " to " + castTo + " failed");
        return false;
    }
    return true;
}

From source file:org.fornax.cartridges.sculptor.smartclient.server.ScServlet.java

private void mapRequestToObj(HashMap<String, Object> data, Class expectedClass, Object obj) throws Exception {
    if (obj == null) {
        throw new ApplicationException("mapRequestToObj called on NULL obj", "ERR9001");
    }//  w ww.jav  a 2s  . c  o m

    try {
        Method versionMethod = expectedClass.getMethod("getVersion", (Class<?>[]) null);
        Long objVersion = (Long) versionMethod.invoke(obj, (Object[]) null);
        String clientVersion = (String) data.get("version");
        if (objVersion != null && clientVersion != null) {
            try {
                long clientVersionLong = Long.parseLong(clientVersion);
                if (!objVersion.equals(clientVersionLong)) {
                    throw makeApplicationException("Can't save object", "ERR9016", (Serializable[]) null);
                }
            } catch (NumberFormatException nfe) {
                // Version from client isn't number - ignore
            }
        }
    } catch (NoSuchMethodException nme) {
        // No version control
    }

    Method[] methods = expectedClass.getMethods();
    for (Method m : methods) {
        Class<?>[] paramTypes = m.getParameterTypes();

        Class persistentClass = null;
        if (paramTypes.length == 1) {
            if (paramTypes[0].getAnnotation(Entity.class) != null) {
                persistentClass = paramTypes[0];
            } else if (paramTypes[0].getAnnotation(Embeddable.class) != null) {
                persistentClass = paramTypes[0];
            }
        }
        ServiceDescription srvParam = paramTypes.length == 1 ? findServiceByClassName(paramTypes[0].getName())
                : null;
        if ((m.getName().startsWith(SET_PREFIX) && paramTypes.length == 1
                && (paramTypes[0].isAssignableFrom(String.class) || paramTypes[0].equals(Integer.class)
                        || paramTypes[0].equals(Integer.TYPE) || paramTypes[0].equals(Long.class)
                        || paramTypes[0].equals(Long.TYPE) || paramTypes[0].equals(Float.class)
                        || paramTypes[0].equals(Float.TYPE) || paramTypes[0].equals(Boolean.class)
                        || paramTypes[0].equals(Boolean.TYPE) || paramTypes[0].equals(Double.class)
                        || paramTypes[0].equals(Double.TYPE) || paramTypes[0].equals(Date.class)
                        || Enum.class.isAssignableFrom(paramTypes[0])
                        || (srvParam != null && srvParam.getFindById() != null) || persistentClass != null))
                || (m.getName().startsWith(GET_PREFIX) && paramTypes.length == 0
                        && (Set.class.isAssignableFrom(m.getReturnType())
                                || List.class.isAssignableFrom(m.getReturnType())))) {
            String fldName;
            if (m.getName().startsWith(GET_TRANSLATE)) {
                fldName = m.getName().substring(GET_TRANSLATE_LENGTH, GET_TRANSLATE_LENGTH + 1).toLowerCase()
                        + m.getName().substring(GET_TRANSLATE_LENGTH + 1);
            } else {
                fldName = m.getName().substring(3, 4).toLowerCase() + m.getName().substring(4);
            }
            Object value = data.get(fldName);
            if (value == null) {
                fldName = m.getName().substring(3);
                value = data.get(fldName);
            }
            if (value != null) {
                Object typedVal;
                String val = null;
                if (value instanceof String) {
                    val = (String) value;
                }
                log.log(Level.FINER, "        value = " + value);
                if (m.getName().startsWith(GET_PREFIX) && paramTypes.length == 0
                        && (Set.class.isAssignableFrom(m.getReturnType())
                                || List.class.isAssignableFrom(m.getReturnType()))) {
                    log.log(Level.FINER, "GET");

                    String attrName = m.getName().substring(3, 4).toLowerCase() + m.getName().substring(4);
                    Type[] actualTypeArguments = null;
                    Class iterClass = expectedClass;
                    while (iterClass != null) {
                        try {
                            Field field = iterClass.getDeclaredField(attrName);
                            ParameterizedType genericType = (ParameterizedType) field.getGenericType();
                            actualTypeArguments = genericType.getActualTypeArguments();
                            break;
                        } catch (NoSuchFieldException nsfe) {
                            // do nothing iterate again
                        }
                        iterClass = iterClass.getSuperclass();
                        iterClass = iterClass.equals(Object.class) ? null : iterClass;
                    }

                    if (actualTypeArguments != null && actualTypeArguments.length == 1
                            && actualTypeArguments[0] instanceof Class) {
                        Class assocClass = (Class) actualTypeArguments[0];
                        ServiceDescription assocService = findServiceByClassName(assocClass.getName());
                        Collection dbValueSet = (Collection) m.invoke(obj, (Object[]) null);
                        if (value == null || !(value instanceof HashMap)) {
                            log.log(Level.FINE, "No data for db property {0}", attrName);
                        } else if (assocService != null) {
                            HashMap<String, Object> guiValueMap = (HashMap<String, Object>) value;

                            ArrayList<Object> removeIt = new ArrayList<Object>();
                            Iterator dbIterator = dbValueSet.iterator();
                            while (dbIterator.hasNext()) {
                                Object dbVal = dbIterator.next();
                                String dbValId = getIdFromObj(dbVal);

                                if (dbValId != null) {
                                    boolean wasMatchingGuiVal = false;
                                    ArrayList<String> removeKeys = new ArrayList<String>();
                                    for (String key : guiValueMap.keySet()) {
                                        Object object = guiValueMap.get(key);
                                        if (object instanceof HashMap) {
                                            Object guiValue = ((HashMap<String, Object>) object).get("id");
                                            if (guiValue.equals(dbValId)) {
                                                removeKeys.add(key);
                                                wasMatchingGuiVal = true;
                                                mapRequestToObj((HashMap<String, Object>) guiValue, assocClass,
                                                        dbVal);
                                                break;
                                            }
                                        } else if (object instanceof String) {
                                            // Association
                                            if (dbValId.equals(object)) {
                                                removeKeys.add(key);
                                                wasMatchingGuiVal = true;
                                            }
                                        } else {
                                            log.log(Level.WARNING, "Wrong object type from GUI under key {0}",
                                                    key);
                                        }
                                    }
                                    // Remove processed elements
                                    // Direct remove is firing concurrent modification exception
                                    for (String removeKey : removeKeys) {
                                        guiValueMap.remove(removeKey);
                                    }

                                    if (!wasMatchingGuiVal) {
                                        // Is not in list comming from GUI - delete
                                        removeIt.add(dbVal);
                                    }
                                } else {
                                    log.log(Level.WARNING, "No ID in object {0}", dbVal);
                                }
                            }
                            dbValueSet.removeAll(removeIt);

                            // Rest are new records
                            for (String key : guiValueMap.keySet()) {
                                Object object = guiValueMap.get(key);
                                if (object instanceof HashMap) {
                                    Object subObj = makeNewInstance(assocClass,
                                            (HashMap<String, Object>) object);
                                    mapRequestToObj((HashMap<String, Object>) object, assocClass, subObj);
                                    dbValueSet.add(subObj);
                                } else if (object instanceof String) {
                                    // Association
                                    try {
                                        Long id = new Long((String) object);
                                        Object assocObj = assocService.getFindById().invoke(
                                                assocService.getInstance(), ServiceContextStore.get(), id);
                                        if (assocObj != null) {
                                            dbValueSet.add(assocObj);
                                        } else {
                                            log.log(Level.WARNING,
                                                    "Object with ID {0} not availabla via service {1}",
                                                    new Object[] { id, assocService.getName() });
                                        }
                                    } catch (Exception ex) {
                                        log.log(Level.WARNING, "No ID parsable from value {0} under key {1}",
                                                new Object[] { object, key });
                                    }
                                } else {
                                    log.log(Level.WARNING, "Wrong sub type {0}", attrName);
                                }
                            }
                        } else if (assocClass != null) {
                            HashMap<String, Object> guiValueMap = (HashMap<String, Object>) value;

                            ArrayList<Object> removeIt = new ArrayList<Object>();
                            Iterator dbIterator = dbValueSet.iterator();
                            while (dbIterator.hasNext()) {
                                Object dbVal = dbIterator.next();
                                String dbValId = getIdFromObj(dbVal);

                                if (dbValId != null) {
                                    Object matchingGuiVal = null;
                                    for (String key : guiValueMap.keySet()) {
                                        Object object = guiValueMap.get(key);
                                        if (object instanceof HashMap) {
                                            HashMap<String, Object> guiVal = (HashMap<String, Object>) object;
                                            if (dbValId.equals(guiVal.get("id"))) {
                                                guiValueMap.remove(key);
                                                matchingGuiVal = guiVal;
                                                break;
                                            }
                                        } else {
                                            log.log(Level.WARNING, "Wrong object type from GUI under key {0}",
                                                    key);
                                        }
                                    }
                                    if (matchingGuiVal != null) {
                                        // Coming from GUI - update
                                        mapRequestToObj((HashMap<String, Object>) matchingGuiVal, assocClass,
                                                dbVal);
                                    } else {
                                        // Not in GUI - delete
                                        removeIt.add(dbVal);
                                    }
                                } else {
                                    log.log(Level.WARNING, "No ID in object {0}", dbVal);
                                }
                            }
                            dbValueSet.removeAll(removeIt);

                            // Rest are new records
                            for (String key : guiValueMap.keySet()) {
                                Object object = guiValueMap.get(key);
                                if (object instanceof HashMap) {
                                    Object subObj = makeNewInstance(assocClass,
                                            (HashMap<String, Object>) object);
                                    mapRequestToObj((HashMap<String, Object>) object, assocClass, subObj);
                                    dbValueSet.add(subObj);
                                } else {
                                    log.log(Level.WARNING, "Wrong sub type {0}", attrName);
                                }
                            }
                        }
                    } else {
                        log.log(Level.WARNING, "No DB mapping or not of collection type: {0}", attrName);
                    }
                    typedVal = null;
                } else if (paramTypes[0].isAssignableFrom(String.class)) {
                    typedVal = val;
                } else if (paramTypes[0].equals(Integer.class) || paramTypes[0].equals(Integer.TYPE)) {
                    typedVal = Integer.parseInt(val);
                } else if (paramTypes[0].equals(Long.class) || paramTypes[0].equals(Long.TYPE)) {
                    typedVal = Long.parseLong(val);
                } else if (paramTypes[0].equals(Double.class) || paramTypes[0].equals(Double.TYPE)) {
                    typedVal = Double.parseDouble(val);
                } else if (paramTypes[0].equals(Float.class) || paramTypes[0].equals(Float.TYPE)) {
                    typedVal = Float.parseFloat(val);
                } else if (paramTypes[0].equals(Boolean.class) || paramTypes[0].equals(Boolean.TYPE)) {
                    typedVal = "true".equalsIgnoreCase(val) || "t".equalsIgnoreCase(val)
                            || "y".equalsIgnoreCase(val);
                } else if (paramTypes[0].isAssignableFrom(Date.class)) {
                    typedVal = dateFormat.parse(val);
                } else if (Enum.class.isAssignableFrom(paramTypes[0])) {
                    try {
                        Method fromValueMethod = paramTypes[0].getMethod("fromValue", String.class);
                        typedVal = fromValueMethod.invoke(null, val);
                    } catch (Exception ex) {
                        typedVal = null;
                    }

                    try {
                        if (typedVal == null) {
                            Method valueOfMethod = paramTypes[0].getMethod("valueOf", String.class);
                            typedVal = valueOfMethod.invoke(null, val);
                        }
                    } catch (Exception ex) {
                        typedVal = null;
                    }
                } else if (persistentClass != null && persistentClass.equals(FileUpload.class)) {
                    FileItem fileItem = uploadServlet.getFileItem(sessionId.get(), fldName, val);
                    if (fileItem != null) {
                        typedVal = fileUploadService.uploadFile(ServiceContextStore.get(), fileItem.getName(),
                                fileItem.getContentType(), fileItem.getInputStream());
                    } else {
                        typedVal = null;
                    }
                } else if (srvParam != null && srvParam.getFindById() != null) {
                    if (value instanceof HashMap) {
                        HashMap<String, Object> embeddedObj = (HashMap<String, Object>) value;
                        typedVal = srvParam.getFindById().invoke(srvParam.getInstance(),
                                ServiceContextStore.get(), new Long((String) embeddedObj.get("id")));
                        mapRequestToObj(embeddedObj, srvParam.getExpectedClass(), typedVal);
                    } else {
                        try {
                            Long parsedId = new Long(val);
                            typedVal = srvParam.getFindById().invoke(srvParam.getInstance(),
                                    ServiceContextStore.get(), parsedId);
                        } catch (NumberFormatException nfe) {
                            // wrong value
                            typedVal = null;
                        }
                    }
                } else if (persistentClass != null) {
                    String getMethodName = "g" + m.getName().substring(1);
                    try {
                        Method getMethod = obj.getClass().getMethod(getMethodName, (Class[]) null);
                        typedVal = getMethod.invoke(obj, (Object[]) null);
                    } catch (NoSuchMethodException nsme) {
                        typedVal = null;
                    }
                    if (typedVal == null) {
                        typedVal = makeNewInstance(persistentClass, (HashMap<String, Object>) value);
                    }
                    mapRequestToObj((HashMap<String, Object>) value, typedVal.getClass(), typedVal);
                } else {
                    log.log(Level.WARNING, "Can't convert value for: {0}.{1} ({2})", new Object[] {
                            expectedClass.getName(), m.getName(),
                            (paramTypes.length == 1 ? paramTypes[0].getName() : paramTypes.toString()) });
                    typedVal = null;
                }
                if (typedVal != null) {
                    m.invoke(obj, typedVal);
                }
            }
        } else if (m.getName().startsWith(SET_PREFIX)) {
            log.log(Level.WARNING, "Unusable setter method: {0}.{1} ({2})",
                    new Object[] { expectedClass.getName(), m.getName(),
                            (paramTypes.length == 1 ? paramTypes[0].getName() : paramTypes.toString()) });
        }
    }
}

From source file:org.appcelerator.titanium.util.TiUIHelper.java

public static void overridePendingTransition(final Activity activity) {
    if (overridePendingTransition == null) {
        try {// w  ww  .j  a  va2 s  . c om
            overridePendingTransition = Activity.class.getMethod("overridePendingTransition", Integer.TYPE,
                    Integer.TYPE);
        } catch (NoSuchMethodException e) {
            Log.w(TAG, "Activity.overridePendingTransition() not found");
        }

    }

    if (overridePendingTransition != null) {
        try {
            overridePendingTransition.invoke(activity, new Object[] { 0, 0 });
        } catch (InvocationTargetException e) {
            Log.e(TAG, "Called incorrectly: " + e.getMessage());
        } catch (IllegalAccessException e) {
            Log.e(TAG, "Illegal access: " + e.getMessage());
        }
    }
}

From source file:org.evosuite.testcase.TestCodeVisitor.java

private String getParameterStringForFMthatReturnPrimitive(Class<?> returnType,
        List<VariableReference> parameters) {

    assert returnType.isPrimitive();
    String parameterString = "";

    for (int i = 0; i < parameters.size(); i++) {
        if (i > 0) {
            parameterString += ", ";
        }/*from   w  ww  .j a  v a  2 s. c om*/
        String name = getVariableName(parameters.get(i));
        Class<?> parameterType = parameters.get(i).getVariableClass();

        if (returnType.equals(parameterType)) {
            parameterString += name;
            continue;
        }

        GenericClass parameterClass = new GenericClass(parameterType);
        if (parameterClass.isWrapperType()) {

            boolean isRightWrapper = false;

            if (Integer.class.equals(parameterClass.getRawClass())) {
                isRightWrapper = returnType.equals(Integer.TYPE);
            } else if (Character.class.equals(parameterClass.getRawClass())) {
                isRightWrapper = returnType.equals(Character.TYPE);
            } else if (Boolean.class.equals(parameterClass.getRawClass())) {
                isRightWrapper = returnType.equals(Boolean.TYPE);
            } else if (Float.class.equals(parameterClass.getRawClass())) {
                isRightWrapper = returnType.equals(Float.TYPE);
            } else if (Double.class.equals(parameterClass.getRawClass())) {
                isRightWrapper = returnType.equals(Double.TYPE);
            } else if (Long.class.equals(parameterClass.getRawClass())) {
                isRightWrapper = returnType.equals(Long.TYPE);
            } else if (Short.class.equals(parameterClass.getRawClass())) {
                isRightWrapper = returnType.equals(Short.TYPE);
            } else if (Byte.class.equals(parameterClass.getRawClass())) {
                isRightWrapper = returnType.equals(Byte.TYPE);
            }

            if (isRightWrapper) {
                parameterString += name;
                continue;
            }
        }

        //if we arrive here, it means types are different and not a right wrapper (eg Integer for int)
        parameterString += "(" + returnType.getName() + ")" + name;

        if (parameterClass.isWrapperType()) {
            if (Integer.class.equals(parameterClass.getRawClass())) {
                parameterString += ".intValue()";
            } else if (Character.class.equals(parameterClass.getRawClass())) {
                parameterString += ".charValue()";
            } else if (Boolean.class.equals(parameterClass.getRawClass())) {
                parameterString += ".booleanValue()";
            } else if (Float.class.equals(parameterClass.getRawClass())) {
                parameterString += ".floatValue()";
            } else if (Double.class.equals(parameterClass.getRawClass())) {
                parameterString += ".doubleValue()";
            } else if (Long.class.equals(parameterClass.getRawClass())) {
                parameterString += ".longValue()";
            } else if (Short.class.equals(parameterClass.getRawClass())) {
                parameterString += ".shortValue()";
            } else if (Byte.class.equals(parameterClass.getRawClass())) {
                parameterString += ".byteValue()";
            }
        }
    }

    return parameterString;
}

From source file:com.ikanow.infinit.e.harvest.extraction.document.file.FileHarvester.java

private void initializeTika(HarvestContext context, SourcePojo source) {
    AutoDetectParser autoDetectParser = new AutoDetectParser();

    if (null != source.getFileConfig().XmlRootLevelValues) {
        for (String s : source.getFileConfig().XmlRootLevelValues) {
            int separator = s.indexOf(':');
            String jsonStr = s.substring(separator + 1);

            if (separator > 0) {
                String mediaType = s.substring(0, separator);
                if (mediaType.equalsIgnoreCase("output")) { //special case, just going to configure output
                    if (jsonStr.equalsIgnoreCase("xml") || jsonStr.equalsIgnoreCase("xhtml")) {
                        _tikaXmlFormatWriter = new StringWriter();
                        _tikaOutputFormat = getTransformerHandler("xml", _tikaXmlFormatWriter);
                        _tikaOutputParseContext = new ParseContext();
                    }//from   w  w  w  .j a  v  a 2  s  . co  m
                    if (jsonStr.equalsIgnoreCase("html")) {
                        _tikaXmlFormatWriter = new StringWriter();
                        _tikaOutputFormat = getTransformerHandler("html", _tikaXmlFormatWriter);
                        _tikaOutputParseContext = new ParseContext();
                    }
                    continue;
                } //TESTED
                else if (mediaType.equalsIgnoreCase("bypass")) {
                    Map<MediaType, Parser> parsers = autoDetectParser.getParsers();
                    parsers.put(MediaType.parse(jsonStr), new TXTParser());
                    autoDetectParser.setParsers(parsers);
                    continue;
                }
                // Try to get media type parser:

                Parser p = autoDetectParser.getParsers().get(MediaType.parse(mediaType));
                while (p instanceof CompositeParser) {
                    p = ((CompositeParser) p).getParsers().get(MediaType.parse(mediaType));
                }
                if (null == p) {
                    context.getHarvestStatus().logMessage(
                            "Failed to find application type " + mediaType + " in tika option: " + s, true);
                    continue;
                } //TESTED

                // Get JSON objects and try to apply

                try {
                    JsonElement jsonObj = new JsonParser().parse(jsonStr);
                    for (Map.Entry<String, JsonElement> keyVal : jsonObj.getAsJsonObject().entrySet()) {
                        if (keyVal.getValue().getAsJsonPrimitive().isBoolean()) { //boolean
                            try {
                                Method method = p.getClass().getMethod(keyVal.getKey(), Boolean.class);
                                method.invoke(p,
                                        (Boolean) keyVal.getValue().getAsJsonPrimitive().getAsBoolean());
                            } catch (Exception e) {
                                try {
                                    Method method = p.getClass().getMethod(keyVal.getKey(), Boolean.TYPE);
                                    method.invoke(p, keyVal.getValue().getAsJsonPrimitive().getAsBoolean());
                                } catch (Exception e2) {
                                    context.getHarvestStatus().logMessage(
                                            "Failed to invoke " + keyVal.getKey() + " in tika option: " + s,
                                            true);
                                    continue;
                                } //TESTED
                            }
                        } //TESTED
                        if (keyVal.getValue().getAsJsonPrimitive().isString()) { //string
                            try {
                                Method method = p.getClass().getMethod(keyVal.getKey(), String.class);
                                method.invoke(p, keyVal.getValue().getAsJsonPrimitive().getAsString());
                            } catch (Exception e) {
                                context.getHarvestStatus().logMessage(
                                        "Failed to invoke " + keyVal.getKey() + " in tika option: " + s, true);
                                continue;
                            }
                        } //TESTED (cut and paste)
                        if (keyVal.getValue().getAsJsonPrimitive().isNumber()) { // number: int/long/double
                            // Loads of options: Integer.class, Integer.TYPE, Long.class, Long.TYPE, Double.long, Double.TYPE
                            boolean invoked = false;
                            if (!invoked) { // Int.class
                                try {
                                    Method method = p.getClass().getMethod(keyVal.getKey(), Integer.class);
                                    method.invoke(p,
                                            (Integer) keyVal.getValue().getAsJsonPrimitive().getAsInt());
                                    invoked = true;
                                } catch (Exception e) {
                                }
                            }
                            if (!invoked) { // Int.type
                                try {
                                    Method method = p.getClass().getMethod(keyVal.getKey(), Integer.TYPE);
                                    method.invoke(p, keyVal.getValue().getAsJsonPrimitive().getAsInt());
                                    invoked = true;
                                } catch (Exception e) {
                                }
                            }
                            if (!invoked) { // Long.class
                                try {
                                    Method method = p.getClass().getMethod(keyVal.getKey(), Long.class);
                                    method.invoke(p, (Long) keyVal.getValue().getAsJsonPrimitive().getAsLong());
                                    invoked = true;
                                } catch (Exception e) {
                                }
                            }
                            if (!invoked) { // Long.type
                                try {
                                    Method method = p.getClass().getMethod(keyVal.getKey(), Long.TYPE);
                                    method.invoke(p, keyVal.getValue().getAsJsonPrimitive().getAsLong());
                                    invoked = true;
                                } catch (Exception e) {
                                }
                            }
                            if (!invoked) { // Double.class
                                try {
                                    Method method = p.getClass().getMethod(keyVal.getKey(), Double.class);
                                    method.invoke(p,
                                            (Double) keyVal.getValue().getAsJsonPrimitive().getAsDouble());
                                    invoked = true;
                                } catch (Exception e) {
                                }
                            }
                            if (!invoked) { // Double.type
                                try {
                                    Method method = p.getClass().getMethod(keyVal.getKey(), Double.TYPE);
                                    method.invoke(p, keyVal.getValue().getAsJsonPrimitive().getAsDouble());
                                    invoked = true;
                                } catch (Exception e) {
                                }
                            }
                        } //TOTEST (all the different options)

                    } //(end loop over options)
                } catch (Exception e) {
                    context.getHarvestStatus().logMessage("Failed to parse JSON in tika option: " + s, true);
                } //TESTED
            } else {
                context.getHarvestStatus().logMessage("Failed to parse tika option: " + s, true);
            } //TESTED

        } //TESTED
    } //(end if has options)

    _tika = new Tika(TikaConfig.getDefaultConfig().getDetector(), autoDetectParser);

}