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:com.projity.util.ClassUtils.java

/**
 * Get the corresponding object class from a primitive class
 * @param clazz primitive class//from   w  w w. j a  va 2s  . c  o  m
 * @return Object class.
 * @throws ClassCastException if class is unknown primitive
 */
public static Class primitiveToObjectClass(Class clazz) {
    //      return MethodUtils.toNonPrimitiveClass(clazz);
    if (clazz == Boolean.TYPE)
        return Boolean.class;
    else if (clazz == Character.TYPE)
        return Character.class;
    else if (clazz == Byte.TYPE)
        return Byte.class;
    else if (clazz == Short.TYPE)
        return Short.class;
    else if (clazz == Integer.TYPE)
        return Integer.class;
    else if (clazz == Long.TYPE)
        return Long.class;
    else if (clazz == Float.TYPE)
        return Float.class;
    else if (clazz == Double.TYPE)
        return Double.class;
    throw new ClassCastException("Cannot convert class" + clazz + " to an object class");
}

From source file:org.apache.tomcat.util.mx.DynamicMBeanProxy.java

private boolean supportedType(Class ret) {
    return ret == String.class || ret == Integer.class || ret == Integer.TYPE || ret == Long.class
            || ret == Long.TYPE || ret == java.io.File.class || ret == Boolean.class || ret == Boolean.TYPE;
}

From source file:be.fedict.eid.applet.service.AppletServiceServlet.java

public static void injectInitParams(ServletConfig config, MessageHandler<?> messageHandler)
        throws ServletException, IllegalArgumentException, IllegalAccessException {
    Class<?> messageHandlerClass = messageHandler.getClass();
    Field[] fields = messageHandlerClass.getDeclaredFields();
    for (Field field : fields) {
        InitParam initParamAnnotation = field.getAnnotation(InitParam.class);
        if (null == initParamAnnotation) {
            continue;
        }//from ww w  . j ava 2 s  .c o  m
        String initParamName = initParamAnnotation.value();
        Class<?> fieldType = field.getType();
        field.setAccessible(true);
        if (ServiceLocator.class.equals(fieldType)) {
            /*
             * We always inject a service locator.
             */
            ServiceLocator<Object> fieldValue = new ServiceLocator<Object>(initParamName, config);
            field.set(messageHandler, fieldValue);
            continue;
        }
        String initParamValue = config.getInitParameter(initParamName);
        if (initParamAnnotation.required() && null == initParamValue) {
            throw new ServletException("missing required init-param: " + initParamName + " for message handler:"
                    + messageHandlerClass.getName());
        }
        if (null == initParamValue) {
            continue;
        }
        if (Boolean.TYPE.equals(fieldType)) {
            LOG.debug("injecting boolean: " + initParamValue);
            Boolean fieldValue = Boolean.parseBoolean(initParamValue);
            field.set(messageHandler, fieldValue);
            continue;
        }
        if (String.class.equals(fieldType)) {
            field.set(messageHandler, initParamValue);
            continue;
        }
        if (InetAddress.class.equals(fieldType)) {
            InetAddress inetAddress;
            try {
                inetAddress = InetAddress.getByName(initParamValue);
            } catch (UnknownHostException e) {
                throw new ServletException("unknown host: " + initParamValue);
            }
            field.set(messageHandler, inetAddress);
            continue;
        }
        if (Long.class.equals(fieldType)) {
            Long fieldValue = Long.parseLong(initParamValue);
            field.set(messageHandler, fieldValue);
            continue;
        }
        throw new ServletException("unsupported init-param field type: " + fieldType.getName());
    }
}

From source file:org.ow2.parscript.util.RLibPathConfigurator.java

private static void setEnvVar(String var, String value) {
    Class<?> clazz;/*from www.j a va 2s  .  c o m*/
    try {
        clazz = Class.forName("org.ow2.proactive.rm.util.process.Environment");
    } catch (Exception e) {
        // This can occur for scheduler > 3.4.0
        try {
            clazz = Class.forName("org.ow2.proactive.scheduler.util.process.Environment");
        } catch (Exception ee) {
            throw new IllegalStateException(
                    "Unable to load Environement class required to set the env variable " + var, e);
        }
    }
    try {
        Method method = clazz.getMethod("setenv", String.class, String.class, Boolean.TYPE);
        method.invoke(null, var, value, true);
    } catch (Exception e) {
        throw new IllegalStateException("Unable to set the env variable " + var, e);
    }
}

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

/**
 * Tests if Class represents a Boolean or primitive boolean
 *///  www  .  j  ava2s.  com
public static boolean isBoolean(Class clazz) {
    return clazz != null && (Boolean.TYPE.isAssignableFrom(clazz) || Boolean.class.isAssignableFrom(clazz));
}

From source file:org.jboss.dashboard.commons.misc.ReflectionUtils.java

/**
 * Checks if the given method is a 'is' method.
 *
 * @param method the Method to check/* w w w.  j  a  va 2  s.  c o m*/
 * @return true if it is a 'is' method
 */
public static final boolean isIsMethod(final Method method) {
    if (method == null) {
        return false;
    }
    if (!method.getName().startsWith(PREFIX_IS)) {
        return false;
    }
    if (method.getParameterTypes().length != 0) {
        return false;
    }
    if ((method.getReturnType().isPrimitive()) && (method.getReturnType() != Boolean.TYPE)) {
        return false;
    }
    if ((!method.getReturnType().isPrimitive()) && (method.getReturnType() != Boolean.class)) {
        return false;
    }
    return true;
}

From source file:org.eiichiro.bootleg.AbstractRequest.java

/**
 * Returns the default value of the specified primitive type.
 * //from www  . java2  s.c  om
 * @param type The primitive type.
 * @return The default value of the specified primitive type.
 */
protected Object primitive(Type type) {
    Class<?> rawType = Types.getRawType(type);

    if (rawType.equals(Boolean.TYPE)) {
        return (boolean) false;
    } else if (rawType.equals(Character.TYPE)) {
        return (char) 0;
    } else if (rawType.equals(Byte.TYPE)) {
        return (byte) 0;
    } else if (rawType.equals(Double.TYPE)) {
        return (double) 0.0;
    } else if (rawType.equals(Float.TYPE)) {
        return (float) 0.0;
    } else if (rawType.equals(Integer.TYPE)) {
        return (int) 0;
    } else {
        // short.
        return (short) 0;
    }
}

From source file:org.seasar.mayaa.impl.cycle.script.rhino.RhinoUtil.java

/**
 * getter??????/*  w w  w.  j a va2  s. c  o m*/
 * JavaBean????????
 *
 * @param bean ?
 * @param propertyName ??
 * @return ?????????null
 * @throws NoSuchMethodException getter??????
 */
protected static Object getWithGetterMethod(Object bean, String propertyName) throws NoSuchMethodException {
    Class beanClass = bean.getClass();
    String baseName = capitalizePropertyName(propertyName);
    Method getter = null;
    try {
        getter = beanClass.getMethod("get" + baseName, VOID_ARGS_CLASS);
    } catch (NoSuchMethodException ignore) {
        // try boolean
    }
    if (getter == null) {
        try {
            // TODO Method
            Method booleanGetter = beanClass.getMethod("is" + baseName, VOID_ARGS_CLASS);
            if (booleanGetter != null) {
                Class returnType = booleanGetter.getReturnType();
                if (returnType.equals(Boolean.class) || returnType.equals(Boolean.TYPE)) {
                    getter = booleanGetter;
                }
            }
        } catch (NoSuchMethodException ignore) {
            // throw new exception for "getXxx"
        }
    }
    if (getter == null || Modifier.isPublic(getter.getModifiers()) == false) {
        throw new NoSuchMethodException(beanClass.toString() + ".get" + baseName + "()");
    }

    if (getter.isAccessible() == false) {
        getter.setAccessible(true);
    }
    try {
        return getter.invoke(bean, null);
    } catch (IllegalAccessException e) {
        LOG.debug(StringUtil.getMessage(RhinoUtil.class, 1, propertyName, beanClass.getName()));
    } catch (InvocationTargetException e) {
        LOG.debug(StringUtil.getMessage(RhinoUtil.class, 1, propertyName, beanClass.getName()));
    }
    return null;
}

From source file:org.evosuite.testcase.fm.MethodDescriptor.java

public Object executeMatcher(int i) throws IllegalArgumentException {
    if (i < 0 || i >= getNumberOfInputParameters()) {
        throw new IllegalArgumentException("Invalid index: " + i);
    }/*from ww  w  . java 2 s  .co m*/

    Type[] types = method.getParameterTypes();
    Type type = types[i];

    try {
        if (type.equals(Integer.TYPE) || type.equals(Integer.class)) {
            return Mockito.anyInt();
        } else if (type.equals(Long.TYPE) || type.equals(Long.class)) {
            return Mockito.anyLong();
        } else if (type.equals(Boolean.TYPE) || type.equals(Boolean.class)) {
            return Mockito.anyBoolean();
        } else if (type.equals(Double.TYPE) || type.equals(Double.class)) {
            return Mockito.anyDouble();
        } else if (type.equals(Float.TYPE) || type.equals(Float.class)) {
            return Mockito.anyFloat();
        } else if (type.equals(Short.TYPE) || type.equals(Short.class)) {
            return Mockito.anyShort();
        } else if (type.equals(Character.TYPE) || type.equals(Character.class)) {
            return Mockito.anyChar();
        } else if (type.equals(String.class)) {
            return Mockito.anyString();
        } else {
            return Mockito.any(type.getClass());
        }
    } catch (Exception e) {
        logger.error("Failed to executed Mockito matcher n{} of type {} in {}.{}: {}", i, type, className,
                methodName, e.getMessage());
        throw new EvosuiteError(e);
    }
}

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

/**
 * Tests if obj is a Boolean or primitive boolean
 */// www .j  ava2 s.  c om
public static boolean isBoolean(Object obj) {
    if ((obj instanceof Boolean) || (obj != null && obj.getClass() == Boolean.TYPE)) {
        return true;
    }
    return false;
}