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.jdal.hibernate.HibernateUtils.java

/**
 * Get a hibernate Example object that excludes zeroes values and excludes
 * all boolean -primitive and wrapper class- attributes of a given object.  
 * @param instance given object for a build a Example object.
 * @return a hibernate Example object.//from w  ww  .j a  v a2  s.  co  m
 */
public static Example excludeBooleanFields(Object instance) {
    Example result = Example.create(instance).excludeZeroes();
    Set<String> fieldNames = getFieldNamesByType(instance, Boolean.class);
    fieldNames.addAll(getFieldNamesByType(instance, Boolean.TYPE));
    for (String fieldName : fieldNames) {
        result.excludeProperty(fieldName);
    }
    return result;
}

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

/**
 * Sets the default value for Boolean conversions.
 * @deprecated Register replacement converters for Boolean.TYPE and
 *  Boolean.class instead//from w w w . j av  a 2s .  c om
 */
public void setDefaultBoolean(boolean newDefaultBoolean) {
    defaultBoolean = new Boolean(newDefaultBoolean);
    register(new BooleanConverter(defaultBoolean), Boolean.TYPE);
    register(new BooleanConverter(defaultBoolean), Boolean.class);
}

From source file:com.cyclopsgroup.waterview.utils.TypeUtils.java

private static synchronized Map getTypeMap() {
    if (typeMap == null) {
        typeMap = new Hashtable();
        typeMap.put("boolean", Boolean.TYPE);
        typeMap.put("byte", Byte.TYPE);
        typeMap.put("char", Character.TYPE);
        typeMap.put("short", Short.TYPE);
        typeMap.put("int", Integer.TYPE);
        typeMap.put("long", Long.TYPE);
        typeMap.put("float", Float.TYPE);
        typeMap.put("double", Double.TYPE);
        typeMap.put("string", String.class);
        typeMap.put("date", Date.class);
    }/*from   w w  w .ja  v a  2s.c  o  m*/

    return typeMap;
}

From source file:org.kuali.rice.krad.data.jpa.Filter.java

/**
 * Coerces the {@code attributeValue} using the given {@code type}.
 *
 * @param type the type to use to coerce the value.
 * @param attributeName the attribute name of the field to coerce.
 * @param attributeValue the value to coerce.
 * @return the coerced value.//from w  w  w . j a  v a 2s .  c om
 */
private static Object coerceValue(Class<?> type, String attributeName, String attributeValue) {
    try {
        if (Character.TYPE.equals(type) || Character.class.isAssignableFrom(type)) {
            return Character.valueOf(attributeValue.charAt(0));
        } else if (Boolean.TYPE.equals(type) || Boolean.class.isAssignableFrom(type)) {
            return Boolean.valueOf(attributeValue);
        } else if (Short.TYPE.equals(type) || Short.class.isAssignableFrom(type)) {
            return Short.valueOf(attributeValue);
        } else if (Integer.TYPE.equals(type) || Integer.class.isAssignableFrom(type)) {
            return Integer.valueOf(attributeValue);
        } else if (Long.TYPE.equals(type) || Long.class.isAssignableFrom(type)) {
            return Long.valueOf(attributeValue);
        } else if (Double.TYPE.equals(type) || Double.class.isAssignableFrom(type)) {
            return Double.valueOf(attributeValue);
        } else if (Float.TYPE.equals(type) || Float.class.isAssignableFrom(type)) {
            return Float.valueOf(attributeValue);
        }
    } catch (NumberFormatException nfe) {
        LOG.error("Could not coerce the value " + attributeValue + " for the field " + attributeName, nfe);
    }

    return attributeValue;
}

From source file:com.enonic.cms.business.portal.datasource.methodcall.MethodCallFactory.java

private static Object convertParameter(Class type, String value) {

    if (type == Integer.TYPE) {
        try {/* ww  w. ja va  2 s. c  o  m*/
            return new Integer(value);
        } catch (NumberFormatException e) {
            throw new IllegalArgumentException("Expected value of type Integer, got: " + value, e);
        }
    } else if (type == String.class) {
        return value;
    } else if (type == Boolean.TYPE) {
        return Boolean.valueOf(value);
    } else if (type == String[].class) {
        if (value == null) {
            return null;
        }

        TStringArrayList arrayList = new TStringArrayList();
        String[] stringArray = StringUtil.splitString(value, ',');
        for (String strValue : stringArray) {
            strValue = strValue.trim();
            if (!StringUtils.isEmpty(strValue)) {
                arrayList.add(strValue);
            }
        }

        return arrayList.toNativeArray();
    } else if (type == int[].class) {
        if (value == null) {
            return null;
        }

        String[] tmpArray = StringUtil.splitString(value, ',');
        int[] intArray = new int[tmpArray.length];
        int index = 0;
        for (String tmp : tmpArray) {
            intArray[index++] = Integer.parseInt(tmp.trim());
        }

        return intArray;
    } else {
        return null;
    }
}

From source file:org.impalaframework.spring.service.proxy.ServiceEndpointInterceptor.java

public Object invokeDummy(MethodInvocation invocation) throws Throwable {

    log.debug("Calling method " + invocation);
    Class<?> returnType = invocation.getMethod().getReturnType();

    if (Void.TYPE.equals(returnType))
        return null;
    if (Byte.TYPE.equals(returnType))
        return (byte) 0;
    if (Short.TYPE.equals(returnType))
        return (short) 0;
    if (Integer.TYPE.equals(returnType))
        return (int) 0;
    if (Long.TYPE.equals(returnType))
        return 0L;
    if (Float.TYPE.equals(returnType))
        return 0f;
    if (Double.TYPE.equals(returnType))
        return 0d;
    if (Boolean.TYPE.equals(returnType))
        return false;

    return null;/*from  ww  w.j a  v a  2  s .  c  om*/
}

From source file:net.testdriven.psiprobe.Tomcat70ContainerAdaptor.java

@Override
protected JspCompilationContext createJspCompilationContext(String name, boolean isErrPage, Options opt,
        ServletContext sctx, JspRuntimeContext jrctx, ClassLoader cl) {
    JspCompilationContext jcctx;/*w ww  .ja  v  a 2s  .  co  m*/
    try {
        jcctx = new JspCompilationContext(name, opt, sctx, null, jrctx);
    } catch (NoSuchMethodError err) {
        /*
         * The above constructor's signature changed in Tomcat 7.0.16:
         * http://svn.apache.org/viewvc?view=revision&revision=1124719
         * 
         * If we reach this point, we are running on a prior version of
         * Tomcat 7 and must use reflection to create this object.
         */
        try {
            jcctx = (JspCompilationContext) ConstructorUtils.invokeConstructor(JspCompilationContext.class,
                    new Object[] { name, false, opt, sctx, null, jrctx },
                    new Class[] { String.class, Boolean.TYPE, Options.class, ServletContext.class,
                            JspServletWrapper.class, JspRuntimeContext.class });
        } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException
                | InstantiationException ex) {
            throw new RuntimeException(ex);
        }
    }
    if (cl != null) {
        jcctx.setClassLoader(cl);
    }
    return jcctx;
}

From source file:com.xwtec.xwserver.util.json.JSONArray.java

/**
 * Creates a JSONArray.<br>//from   w  ww  . java 2s.c o  m
 * Inspects the object type to call the correct JSONArray factory method.
 * Accepts JSON formatted strings, arrays, Collections and Enums.
 *
 * @param object
 * @throws JSONException if the object can not be converted to a proper
 *         JSONArray.
 */
public static JSONArray fromObject(Object object, JsonConfig jsonConfig) {
    if (object instanceof JSONString) {
        return _fromJSONString((JSONString) object, jsonConfig);
    } else if (object instanceof JSONArray) {
        return _fromJSONArray((JSONArray) object, jsonConfig);
    } else if (object instanceof Collection) {
        return _fromCollection((Collection) object, jsonConfig);
    } else if (object instanceof JSONTokener) {
        return _fromJSONTokener((JSONTokener) object, jsonConfig);
    } else if (object instanceof String) {
        return _fromString((String) object, jsonConfig);
    } else if (object != null && object.getClass().isArray()) {
        Class type = object.getClass().getComponentType();
        if (!type.isPrimitive()) {
            return _fromArray((Object[]) object, jsonConfig);
        } else {
            if (type == Boolean.TYPE) {
                return _fromArray((boolean[]) object, jsonConfig);
            } else if (type == Byte.TYPE) {
                return _fromArray((byte[]) object, jsonConfig);
            } else if (type == Short.TYPE) {
                return _fromArray((short[]) object, jsonConfig);
            } else if (type == Integer.TYPE) {
                return _fromArray((int[]) object, jsonConfig);
            } else if (type == Long.TYPE) {
                return _fromArray((long[]) object, jsonConfig);
            } else if (type == Float.TYPE) {
                return _fromArray((float[]) object, jsonConfig);
            } else if (type == Double.TYPE) {
                return _fromArray((double[]) object, jsonConfig);
            } else if (type == Character.TYPE) {
                return _fromArray((char[]) object, jsonConfig);
            } else {
                throw new JSONException("Unsupported type");
            }
        }
    } else if (JSONUtils.isBoolean(object) || JSONUtils.isFunction(object) || JSONUtils.isNumber(object)
            || JSONUtils.isNull(object) || JSONUtils.isString(object) || object instanceof JSON) {
        fireArrayStartEvent(jsonConfig);
        JSONArray jsonArray = new JSONArray().element(object, jsonConfig);
        fireElementAddedEvent(0, jsonArray.get(0), jsonConfig);
        fireArrayStartEvent(jsonConfig);
        return jsonArray;
    } else if (object instanceof Enum) {
        return _fromArray((Enum) object, jsonConfig);
    } else if (object instanceof Annotation || (object != null && object.getClass().isAnnotation())) {
        throw new JSONException("Unsupported type");
    } else if (JSONUtils.isObject(object)) {
        fireArrayStartEvent(jsonConfig);
        JSONArray jsonArray = new JSONArray().element(JSONObject.fromObject(object, jsonConfig));
        fireElementAddedEvent(0, jsonArray.get(0), jsonConfig);
        fireArrayStartEvent(jsonConfig);
        return jsonArray;
    } else {
        throw new JSONException("Unsupported type");
    }
}

From source file:nz.ac.otago.psyanlab.common.model.util.ModelUtils.java

/**
 * Checks to see the given ored set of return types intersects with the
 * given method's return type.//w w  w .j av a 2 s  .  co m
 * 
 * @param method Method to test.
 * @param returnTypes Ored set of return types.
 * @return True if intersection.
 */
public static boolean returnTypeIntersects(Method method, int returnTypes) {
    if ((returnTypes & Type.TYPE_BOOLEAN) != 0 && method.getReturnType().equals(Boolean.TYPE)) {
        return true;
    }
    if ((returnTypes & Type.TYPE_INTEGER) != 0 && method.getReturnType().equals(Integer.TYPE)) {
        return true;
    }
    if ((returnTypes & Type.TYPE_FLOAT) != 0 && method.getReturnType().equals(Float.TYPE)) {
        return true;
    }
    if ((returnTypes & Type.TYPE_STRING) != 0 && method.getReturnType().equals(String.class)) {
        return true;
    }
    if (returnTypes == 0 && method.getReturnType().equals(Void.TYPE)) {
        return true;
    }
    return false;
}

From source file:nz.co.senanque.validationengine.ConvertUtils.java

public static Object getObjectForNull(Class<?> clazz) {
    if (clazz.equals(Long.TYPE)) {
        return new Long(0);
    } else if (clazz.equals(Integer.TYPE)) {
        return new Integer(0);
    } else if (clazz.equals(Float.TYPE)) {
        return new Float(0.0F);
    } else if (clazz.equals(Double.TYPE)) {
        return new Double(0.0D);
    } else if (clazz.equals(Boolean.TYPE)) {
        return new Boolean(false);
    }/*from   w  w  w  .j ava 2  s.co  m*/
    return null;
}