Example usage for java.lang Boolean TYPE

List of usage examples for java.lang Boolean TYPE

Introduction

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

Prototype

Class TYPE

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

Click Source Link

Document

The Class object representing the primitive type boolean.

Usage

From source file:org.quantumbadger.redreader.jsonwrap.JsonBufferedObject.java

public void populateObject(final Object o) throws InterruptedException, IOException, IllegalArgumentException,
        InstantiationException, NoSuchMethodException, InvocationTargetException {

    if (join() != STATUS_LOADED) {
        throwFailReasonException();//ww  w .  java2  s .  c o  m
    }

    final Field[] objectFields = o.getClass().getFields();

    try {

        for (final Field objectField : objectFields) {

            if ((objectField.getModifiers() & Modifier.TRANSIENT) != 0) {
                continue;
            }

            final JsonValue val;

            if (properties.containsKey(objectField.getName())) {
                val = properties.get(objectField.getName());

            } else if (objectField.getName().startsWith("_json_")) {
                val = properties.get(objectField.getName().substring("_json_".length()));
            } else {
                val = null;
            }

            if (val == null) {
                continue;
            }

            objectField.setAccessible(true);

            final Class<?> fieldType = objectField.getType();

            if (fieldType == Long.class || fieldType == Long.TYPE) {
                objectField.set(o, val.asLong());

            } else if (fieldType == Double.class || fieldType == Double.TYPE) {
                objectField.set(o, val.asDouble());

            } else if (fieldType == Integer.class || fieldType == Integer.TYPE) {
                objectField.set(o, val.isNull() ? null : val.asLong().intValue());

            } else if (fieldType == Float.class || fieldType == Float.TYPE) {
                objectField.set(o, val.isNull() ? null : val.asDouble().floatValue());

            } else if (fieldType == Boolean.class || fieldType == Boolean.TYPE) {
                objectField.set(o, val.asBoolean());

            } else if (fieldType == String.class) {
                objectField.set(o, val.asString());

            } else if (fieldType == JsonBufferedArray.class) {
                objectField.set(o, val.asArray());

            } else if (fieldType == JsonBufferedObject.class) {
                objectField.set(o, val.asObject());

            } else if (fieldType == JsonValue.class) {
                objectField.set(o, val);

            } else if (fieldType == Object.class) {

                final Object result;

                switch (val.getType()) {
                case JsonValue.TYPE_BOOLEAN:
                    result = val.asBoolean();
                    break;
                case JsonValue.TYPE_INTEGER:
                    result = val.asLong();
                    break;
                case JsonValue.TYPE_STRING:
                    result = val.asString();
                    break;
                case JsonValue.TYPE_FLOAT:
                    result = val.asDouble();
                    break;
                default:
                    result = val;
                }

                objectField.set(o, result);

            } else {
                objectField.set(o, val.asObject(fieldType));
            }
        }

    } catch (IllegalAccessException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.opengamma.language.definition.JavaTypeInfo.java

private static Class<?> findClass(final String className) throws ClassNotFoundException {
    if ("boolean".equals(className)) {
        return Boolean.TYPE;
    } else if ("char".equals(className)) {
        return Character.TYPE;
    } else if ("double".equals(className)) {
        return Double.TYPE;
    } else if ("float".equals(className)) {
        return Float.TYPE;
    } else if ("int".equals(className)) {
        return Integer.TYPE;
    } else if ("long".equals(className)) {
        return Long.TYPE;
    } else if ("short".equals(className)) {
        return Short.TYPE;
    } else {/*  w  w w  .j  a  v  a2s.  co  m*/
        return Class.forName(className);
    }
}

From source file:org.apache.tapestry.param.ParameterManager.java

private IParameterConnector createConnector(IComponent component, String parameterName, IBinding binding,
        Class propertyType, Class requiredType) {
    // Could convert this code to use a Decorator, but then I'd need
    // some kind of factory for these parameter connectors.

    if (propertyType.equals(Boolean.TYPE))
        return new BooleanParameterConnector(component, parameterName, binding);

    if (propertyType.equals(Integer.TYPE))
        return new IntParameterConnector(component, parameterName, binding);

    if (propertyType.equals(Double.TYPE))
        return new DoubleParameterConnector(component, parameterName, binding);

    if (propertyType.equals(String.class))
        return new StringParameterConnector(component, parameterName, binding);

    // The default is for any kind of object type

    return new ObjectParameterConnector(component, parameterName, binding, requiredType);
}

From source file:org.romaframework.core.schema.SchemaHelper.java

public static Object assignValueToLiteral(String v, Class<?> type) {
    Object value;/*from  ww w  .  java 2  s.  com*/
    if (v.length() == 0) {
        value = null;
    } else {
        if (type.equals(Integer.class) || type.equals(Integer.TYPE)) {
            value = Integer.parseInt(v);
        } else if (type.equals(Long.class) || type.equals(Long.TYPE)) {
            value = Long.parseLong(v);
        } else if (type.equals(Short.class) || type.equals(Short.TYPE)) {
            value = Short.parseShort(v);
        } else if (type.equals(Boolean.class) || type.equals(Boolean.TYPE)) {
            value = Boolean.parseBoolean(v);
        } else if (type.equals(Float.class) || type.equals(Float.TYPE)) {
            value = Float.parseFloat(v);
        } else if (type.equals(Double.class) || type.equals(Double.TYPE)) {
            value = Double.parseDouble(v);
        } else if (type.equals(Byte.class) || type.equals(Byte.TYPE)) {
            value = Byte.parseByte(v);
        } else if (type.equals(Character.class) || type.equals(Character.TYPE)) {
            value = v.charAt(0);
        } else {
            value = v;
        }
    }
    return value;
}

From source file:org.jcommon.com.util.config.ConfigLoader.java

@SuppressWarnings("unchecked")
private static StringBuilder updateString(InputStream is, BaseConfigMBean config) throws FileNotFoundException {
    StringBuilder sb = new StringBuilder();
    if (is == null)
        throw new FileNotFoundException();
    try {/*from  w  w  w .  j  a  v a2  s.  c om*/
        boolean empty = false;
        Document doc = null;
        try {
            doc = new SAXReader().read(is);
        } catch (Exception e) {
            empty = true;
            doc = DocumentHelper.createDocument();
        }

        Element root = doc.getRootElement();

        String element = null;
        Class<?> type = null;
        java.lang.reflect.Field[] fs = config.getClass().getDeclaredFields();
        sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n").append("<config>\n");
        for (java.lang.reflect.Field f : fs) {
            element = f.getName();
            if (getTextFromElement(root, element) == null && !empty)
                continue;
            Object value = null;
            type = f.getType();
            java.lang.reflect.Method m = getMethod(config.getClass(), "get" + element);
            if (m == null)
                m = getMethod(config.getClass(), "is" + element);
            if (m != null) {
                try {
                    value = m.invoke(config);
                    logger.info(element + ":" + value);
                } catch (Exception e) {
                    logger.warn(e);
                    continue;
                }
                if (String.class == type) {
                    String data = String.valueOf(value);
                    if (data.startsWith("{")) {
                        org.json.JSONObject jsonO = JsonUtils.getJSONObject(data);
                        if (jsonO != null) {
                            Iterator<String> it = jsonO.keys();
                            sb.append("   <" + element + " ");
                            for (; it != null && it.hasNext();) {
                                String k = it.next();
                                String v = jsonO.getString(k);
                                sb.append(k).append("=").append("\"" + v + "\" ");
                            }
                            sb.append("/>\n");
                            continue;
                        }
                    }
                    sb.append("   <" + element + ">").append(data).append("</" + element + ">\n");
                } else if ((java.lang.Integer.class == type || Integer.TYPE == type)
                        || (java.lang.Boolean.class == type || Boolean.TYPE == type)
                        || (java.lang.Long.class == type || Long.TYPE == type)
                        || (java.lang.Float.class == type || Float.TYPE == type)) {
                    sb.append("   <" + element + ">").append(String.valueOf(value))
                            .append("</" + element + ">\n");
                } else if (java.util.Collection.class.isAssignableFrom(type)) {
                    Collection<String> list = (Collection<String>) value;
                    for (String s : list) {
                        sb.append("   <" + element + ">").append(s).append("</" + element + ">\n");
                    }
                } else if (java.util.Map.class.isAssignableFrom(type)) {
                    Map<String, String> map = (Map<String, String>) value;
                    for (String s : map.keySet()) {
                        String v = map.get(s);
                        sb.append("   <" + element).append(" key=\"" + s + "\"").append(" value=\"" + v + "\"")
                                .append(" />\n");
                    }
                } else {
                    logger.info("not map Class:" + type);
                    continue;
                }
            } else
                logger.warn("can't find element:" + element);
        }
        sb.append("</config>");
        logger.info(String.format("Read config file:  %s", is));

    } catch (Throwable t) {
        //t.printStackTrace();
        logger.error("read config file error:" + is + "\n" + t.getMessage());
    }
    return sb;
}

From source file:com.sun.socialsite.util.DebugBeanJsonConverter.java

@SuppressWarnings("boxing")
private <T> void callSetterWithValue(T pojo, Method method, JSONObject jsonObject, String fieldName)
        throws IllegalAccessException, InvocationTargetException, NoSuchFieldException, JSONException {

    log.debug("Calling setter [" + method.getName() + "]");

    Class<?> expectedType = method.getParameterTypes()[0];
    Object value = null;/* w w  w  .ja  v  a  2 s.  c  om*/

    if (!jsonObject.has(fieldName)) {
        // Skip
    } else if (expectedType.equals(List.class)) {
        ParameterizedType genericListType = (ParameterizedType) method.getGenericParameterTypes()[0];
        Type type = genericListType.getActualTypeArguments()[0];
        Class<?> rawType;
        Class<?> listElementClass;
        if (type instanceof ParameterizedType) {
            listElementClass = (Class<?>) ((ParameterizedType) type).getActualTypeArguments()[0];
            rawType = (Class<?>) ((ParameterizedType) type).getRawType();
        } else {
            listElementClass = (Class<?>) type;
            rawType = listElementClass;
        }

        List<Object> list = Lists.newArrayList();
        JSONArray jsonArray = jsonObject.getJSONArray(fieldName);
        for (int i = 0; i < jsonArray.length(); i++) {
            if (org.apache.shindig.protocol.model.Enum.class.isAssignableFrom(rawType)) {
                list.add(convertEnum(listElementClass, jsonArray.getJSONObject(i)));
            } else {
                list.add(convertToObject(jsonArray.getString(i), listElementClass));
            }
        }

        value = list;

    } else if (expectedType.equals(Map.class)) {
        ParameterizedType genericListType = (ParameterizedType) method.getGenericParameterTypes()[0];
        Type[] types = genericListType.getActualTypeArguments();
        Class<?> valueClass = (Class<?>) types[1];

        // We only support keys being typed as Strings.
        // Nothing else really makes sense in json.
        Map<String, Object> map = Maps.newHashMap();
        JSONObject jsonMap = jsonObject.getJSONObject(fieldName);

        Iterator<?> keys = jsonMap.keys();
        while (keys.hasNext()) {
            String keyName = (String) keys.next();
            map.put(keyName, convertToObject(jsonMap.getString(keyName), valueClass));
        }

        value = map;

    } else if (org.apache.shindig.protocol.model.Enum.class.isAssignableFrom(expectedType)) {
        // TODO Need to stop using Enum as a class name :(
        value = convertEnum((Class<?>) ((ParameterizedType) method.getGenericParameterTypes()[0])
                .getActualTypeArguments()[0], jsonObject.getJSONObject(fieldName));
    } else if (expectedType.isEnum()) {
        if (jsonObject.has(fieldName)) {
            for (Object v : expectedType.getEnumConstants()) {
                if (v.toString().equals(jsonObject.getString(fieldName))) {
                    value = v;
                    break;
                }
            }
            if (value == null) {
                throw new IllegalArgumentException("No enum value  '" + jsonObject.getString(fieldName)
                        + "' in " + expectedType.getName());
            }
        }
    } else if (expectedType.equals(String.class)) {
        value = jsonObject.getString(fieldName);
    } else if (expectedType.equals(Date.class)) {
        // Use JODA ISO parsing for the conversion
        value = new DateTime(jsonObject.getString(fieldName)).toDate();
    } else if (expectedType.equals(Long.class) || expectedType.equals(Long.TYPE)) {
        value = jsonObject.getLong(fieldName);
    } else if (expectedType.equals(Integer.class) || expectedType.equals(Integer.TYPE)) {
        value = jsonObject.getInt(fieldName);
    } else if (expectedType.equals(Boolean.class) || expectedType.equals(Boolean.TYPE)) {
        value = jsonObject.getBoolean(fieldName);
    } else if (expectedType.equals(Float.class) || expectedType.equals(Float.TYPE)) {
        value = ((Double) jsonObject.getDouble(fieldName)).floatValue();
    } else if (expectedType.equals(Double.class) || expectedType.equals(Double.TYPE)) {
        value = jsonObject.getDouble(fieldName);
    } else {
        // Assume its an injected type
        value = convertToObject(jsonObject.getJSONObject(fieldName).toString(), expectedType);
    }

    if (value != null) {
        method.invoke(pojo, value);
    }
}

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

@SuppressWarnings("squid:S3776")
public <T> T asType(Class<T> type) {
    if (type == Byte.TYPE || type == Byte.class) {
        return (T) apply(toLong(), Long::byteValue);
    } else if (type == Integer.TYPE || type == Integer.class) {
        return (T) apply(toLong(), Long::intValue);
    } else if (type == Long.TYPE || type == Long.class) {
        return (T) toLong();
    } else if (type == Short.TYPE || type == Short.class) {
        return (T) apply(toLong(), Long::shortValue);
    } else if (type == Float.TYPE || type == Float.class) {
        return (T) apply(toDouble(), Double::floatValue);
    } else if (type == Double.TYPE || type == Double.class) {
        return (T) toDouble();
    } else if (type == Boolean.TYPE || type == Boolean.class) {
        return (T) toBoolean();
    } else if (type == String.class) {
        return (T) toString();
    } else if (type == Date.class) {
        return (T) toDate();
    } else if (type == Instant.class) {
        return (T) toDate().toInstant();
    } else if (type == Calendar.class) {
        Calendar c = Calendar.getInstance();
        c.setTime(toDate());/* w w w .  j a va 2 s  .c  o  m*/
        return (T) c;
    } else {
        return null;
    }
}

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

private Class getClassFromName(String typeStr) {
    switch (typeStr.toLowerCase()) {
    case "int":
    case "integer":
        return Integer.TYPE;
    case "long":
        return Long.TYPE;
    case "double":
    case "number":
        return Double.TYPE;
    case "date":
    case "calendar":
    case "cal":
    case "time":
        return Date.class;
    case "boolean":
    case "bool":
        return Boolean.TYPE;
    case "string":
    case "str":
    default:// w ww.  j a v  a 2s. c om
        return String.class;
    }
}

From source file:ezbake.services.search.SSRServiceHandler.java

@SuppressWarnings("unchecked")
public TProcessor getThriftProcessor() {
    EzElastic.Client documentClient = null;
    AuditEvent evt = null;/* www.  j a v a 2s  .  c o m*/
    try {
        EzProperties props = new EzProperties(getConfigurationProperties(), true);
        pool = new ThriftClientPool(props);
        documentClient = getDocumentClient();
        security = new EzbakeSecurityClient(props);
        EzSecurityToken ssrServiceToken = security.fetchAppToken();
        evt = event(AuditEventType.ApplicationInitialization.getName(), ssrServiceToken).arg("event", "init");

        isGeoEnabled = props.getBoolean(ENABLE_GEO_KEY, true);
        percolatorInboxLimit = props.getInteger(PERCOLATOR_INBOX_LIMIT, 500); // default to 500

        // Update the index to ignore malformed values coming in. The malformed values will still be added
        // to _all, but they won't be searchable in their field.
        securityId = new EzBakeApplicationConfigurationHelper(props).getSecurityID();
        documentClient.closeIndex(ssrServiceToken);
        documentClient.applySettings("{\"index\" : {\"mapping\" : {\"ignore_malformed\" : true}}}",
                ssrServiceToken);
        documentClient.openIndex(ssrServiceToken);
        gson = new GsonBuilder().registerTypeAdapter(Date.class, new DateSerializer())
                .registerTypeAdapter(Boolean.TYPE, new BooleanSerializer()).create();

        AuditLoggerConfigurator.setAdditivity(true);
        auditLogger = AuditLogger.getAuditLogger(SSRServiceHandler.class);

        // setup type mappings
        setupTypeMappings(documentClient, ssrServiceToken);

        return new ssrService.Processor(this);
    } catch (AppNotRegisteredException e) {
        logError(e, evt, "SSR Service not registered in ezsecurity. Exiting.");
        throw new RuntimeException("Could not initialize SSR service", e);
    } catch (TException e) {
        logError(e, evt, "Error starting SSR Service.");
        throw new RuntimeException("Could not initialize SSR service", e);
    } finally {
        if (evt != null)
            auditLogger.logEvent(evt);
        returnAndNullClient(documentClient);
    }
}

From source file:nl.strohalm.cyclos.controls.customization.fields.EditCustomFieldAction.java

@SuppressWarnings("unchecked")
public DataBinder<MemberCustomField> getMemberCustomFieldBinder() {
    final BeanBinder<MemberCustomField> memberFieldBinder = (BeanBinder<MemberCustomField>) getBasicDataBinder(
            CustomField.Nature.MEMBER);//from   w ww.  j a  v  a2s  .  co m
    memberFieldBinder.registerBinder("visibilityAccess",
            PropertyBinder.instance(MemberCustomField.Access.class, "visibilityAccess"));
    memberFieldBinder.registerBinder("updateAccess",
            PropertyBinder.instance(MemberCustomField.Access.class, "updateAccess"));
    memberFieldBinder.registerBinder("memberSearchAccess",
            PropertyBinder.instance(MemberCustomField.Access.class, "memberSearchAccess"));
    memberFieldBinder.registerBinder("adSearchAccess",
            PropertyBinder.instance(MemberCustomField.Access.class, "adSearchAccess"));
    memberFieldBinder.registerBinder("indexing",
            PropertyBinder.instance(MemberCustomField.Indexing.class, "indexing"));
    memberFieldBinder.registerBinder("loanSearchAccess",
            PropertyBinder.instance(MemberCustomField.Access.class, "loanSearchAccess"));
    memberFieldBinder.registerBinder("memberCanHide", PropertyBinder.instance(Boolean.TYPE, "memberCanHide"));
    memberFieldBinder.registerBinder("showInPrint", PropertyBinder.instance(Boolean.TYPE, "showInPrint"));
    memberFieldBinder.registerBinder("groups", SimpleCollectionBinder.instance(MemberGroup.class, "groups"));
    return memberFieldBinder;
}