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.seasar.mayaa.impl.cycle.script.rhino.RhinoUtil.java

/**
 * Rhino??Java????????//from   w  w  w  .  ja  va2s .  co  m
 * ?????3
 * <ul><li>boolean???JavaScript??undefined???=true?
 * ????????</li>
 * <li>??void?????undefined???null?</li>
 * <li>??????????? (Rhino?Double??????)</li>
 * </ul>
 *
 * @param cx ??
 * @param expectedClass ?
 * @param jsRet Rhino?
 * @return jsRetJava????????
 */
public static Object convertResult(Context cx, Class expectedClass, Object jsRet) {
    Object ret;
    if (expectedClass.equals(Boolean.TYPE)) {
        // workaround to ECMA1.3
        ret = JavaAdapter.convertResult(jsRet, Object.class);
    } else if (expectedClass == Void.class || expectedClass == void.class || jsRet == Undefined.instance) {
        ret = null;
    } else {
        if (isNumber(expectedClass, jsRet)) {
            ret = jsRet;
        } else {
            ret = JavaAdapter.convertResult(jsRet, expectedClass);
        }
    }

    return ret;
}

From source file:net.yck.wkrdb.common.shared.PropertyConverter.java

/**
 * Performs a data type conversion from the specified value object to the
 * given target data class. If additional information is required for this
 * conversion, it is obtained from {@code DefaultConversionHandler.INSTANCE}
 * object. If the class is a primitive type (Integer.TYPE, Boolean.TYPE,
 * etc), the value returned will use the wrapper type (Integer.class,
 * Boolean.class, etc)./*from   w  w w . jav  a  2 s  .c o  m*/
 *
 * @param cls
 *            the target class of the converted value
 * @param value
 *            the value to convert
 * @return the converted value
 * @throws ConversionException
 *             if the value is not compatible with the requested type
 */
public static Object to(Class<?> cls, Object value) throws ConversionException {
    if (cls.isInstance(value)) {
        return value; // no conversion needed
    }

    if (String.class.equals(cls)) {
        return String.valueOf(value);
    }
    if (Boolean.class.equals(cls) || Boolean.TYPE.equals(cls)) {
        return toBoolean(value);
    } else if (Character.class.equals(cls) || Character.TYPE.equals(cls)) {
        return toCharacter(value);
    } else if (Number.class.isAssignableFrom(cls) || cls.isPrimitive()) {
        if (Integer.class.equals(cls) || Integer.TYPE.equals(cls)) {
            return toInteger(value);
        } else if (Long.class.equals(cls) || Long.TYPE.equals(cls)) {
            return toLong(value);
        } else if (Byte.class.equals(cls) || Byte.TYPE.equals(cls)) {
            return toByte(value);
        } else if (Short.class.equals(cls) || Short.TYPE.equals(cls)) {
            return toShort(value);
        } else if (Float.class.equals(cls) || Float.TYPE.equals(cls)) {
            return toFloat(value);
        } else if (Double.class.equals(cls) || Double.TYPE.equals(cls)) {
            return toDouble(value);
        } else if (BigInteger.class.equals(cls)) {
            return toBigInteger(value);
        } else if (BigDecimal.class.equals(cls)) {
            return toBigDecimal(value);
        }
    } else if (Date.class.equals(cls)) {
        return toDate(value, DefaultConversionHandler.INSTANCE.getDateFormat());
    } else if (Calendar.class.equals(cls)) {
        return toCalendar(value, DefaultConversionHandler.INSTANCE.getDateFormat());
    } else if (URL.class.equals(cls)) {
        return toURL(value);
    } else if (Locale.class.equals(cls)) {
        return toLocale(value);
    } else if (isEnum(cls)) {
        return convertToEnum(cls, value);
    } else if (Color.class.equals(cls)) {
        return toColor(value);
    } else if (cls.getName().equals(INTERNET_ADDRESS_CLASSNAME)) {
        return toInternetAddress(value);
    } else if (InetAddress.class.isAssignableFrom(cls)) {
        return toInetAddress(value);
    }

    throw new ConversionException("The value '" + value + "' (" + value.getClass() + ")"
            + " can't be converted to a " + cls.getName() + " object");
}

From source file:springfox.documentation.schema.property.PojoPropertyBuilderFactory.java

/**
 * Applies to constructor//from  w  w  w . ja  v a  2  s.  c om
   new POJOPropertyBuilder(new PropertyName(beanProperty.getName()),  annotationIntrospector,  true);
 */
private Optional<POJOPropertyBuilder> jackson26Instance(BeanPropertyDefinition beanProperty,
        AnnotationIntrospector annotationIntrospector, boolean forSerialization) {
    try {
        Constructor<POJOPropertyBuilder> constructor = constructorWithParams(PropertyName.class,
                AnnotationIntrospector.class, Boolean.TYPE);

        return Optional.of(constructor.newInstance(new PropertyName(beanProperty.getName()),
                annotationIntrospector, forSerialization));
    } catch (Exception e) {
        LOG.debug("Unable to instantiate jackson 26 object", e);
    }
    return Optional.absent();
}

From source file:org.thingsplode.synapse.serializers.jackson.adapters.ParameterWrapperDeserializer.java

@Override
public ParameterWrapper deserialize(JsonParser jp, DeserializationContext ctxt)
        throws IOException, JsonProcessingException {
    JsonNode node = jp.readValueAsTree();
    if (node != null && node.size() > 0 && node.isContainerNode()) {
        ParameterWrapper pw = ParameterWrapper.create();
        ArrayNode paramsNode = (ArrayNode) node.get("params");
        Iterator<JsonNode> elemIterator = paramsNode.elements();
        while (elemIterator.hasNext()) {
            JsonNode currentNode = elemIterator.next();
            if (currentNode.getNodeType() == JsonNodeType.OBJECT) {
                try {
                    String paramid = ((ObjectNode) currentNode).get("paramid").asText();
                    String typeName = ((ObjectNode) currentNode).get("type").asText();
                    Class paramType = null;
                    if (null != typeName)
                        switch (typeName) {
                        case "long":
                            paramType = Long.TYPE;
                            break;
                        case "byte":
                            paramType = Byte.TYPE;
                            break;
                        case "short":
                            paramType = Short.TYPE;
                            break;
                        case "int":
                            paramType = Integer.TYPE;
                            break;
                        case "float":
                            paramType = Float.TYPE;
                            break;
                        case "double":
                            paramType = Double.TYPE;
                            break;
                        case "boolean":
                            paramType = Boolean.TYPE;
                            break;
                        case "char":
                            paramType = Character.TYPE;
                            break;
                        default:
                            paramType = Class.forName(typeName);
                            break;
                        }/*from  ww  w .  j a v a  2  s.  c  o  m*/
                    Object parameterObject = jp.getCodec().treeToValue(currentNode.get("value"), paramType);
                    pw.add(paramid, paramType, parameterObject);
                } catch (ClassNotFoundException ex) {
                    throw new JsonParseException(jp, ex.getMessage());
                }
            }
        }
        return pw;
    } else {
        return null;
    }
}

From source file:Main.java

/**
 * <p>Copies the given array and adds the given element at the end of the new array.</p>
 *
 * <p>The new array contains the same elements of the input
 * array plus the given element in the last position. The component type of
 * the new array is the same as that of the input array.</p>
 *
 * <p>If the input array is {@code null}, a new one element array is returned
 *  whose component type is the same as the element.</p>
 *
 * <pre>//from   w ww. j  av a 2 s .  co m
 * ArrayUtils.add(null, true)          = [true]
 * ArrayUtils.add([true], false)       = [true, false]
 * ArrayUtils.add([true, false], true) = [true, false, true]
 * </pre>
 *
 * @param array  the array to copy and add the element to, may be {@code null}
 * @param element  the object to add at the last index of the new array
 * @return A new array containing the existing elements plus the new element
 * @since 2.1
 */
public static boolean[] add(boolean[] array, boolean element) {
    boolean[] newArray = (boolean[]) copyArrayGrow1(array, Boolean.TYPE);
    newArray[newArray.length - 1] = element;
    return newArray;
}

From source file:Utils.java

/**
 * Returns true is the given method is a JMX attribute getter method
 *///from  w  w  w. j  a v a 2  s.  c o m
public static boolean isAttributeGetter(Method m) {
    if (m == null)
        return false;

    String name = m.getName();
    Class retType = m.getReturnType();
    Class[] params = m.getParameterTypes();
    if (retType != Void.TYPE && params.length == 0) {
        if (name.startsWith("get") && name.length() > 3)
            return true;
        else if (name.startsWith("is") && name.length() > 2 && retType == Boolean.TYPE)
            return true;
    }
    return false;
}

From source file:Main.java

/**
 * <p>Copies the given array and adds the given element at the end of the new array.</p>
 *
 * <p>The new array contains the same elements of the input
 * array plus the given element in the last position. The component type of
 * the new array is the same as that of the input array.</p>
 *
 * <p>If the input array is {@code null}, a new one element array is returned
 *  whose component type is the same as the element.</p>
 *
 * <pre>/*from  ww w  . ja va2  s  .  c  o  m*/
 * ArrayUtils.add(null, true)          = [true]
 * ArrayUtils.add([true], false)       = [true, false]
 * ArrayUtils.add([true, false], true) = [true, false, true]
 * </pre>
 *
 * @param array  the array to copy and add the element to, may be {@code null}
 * @param element  the object to add at the last index of the new array
 * @return A new array containing the existing elements plus the new element
 * @since 2.1
 */
public static boolean[] add(final boolean[] array, final boolean element) {
    final boolean[] newArray = (boolean[]) copyArrayGrow1(array, Boolean.TYPE);
    newArray[newArray.length - 1] = element;
    return newArray;
}

From source file:com.browseengine.bobo.serialize.JSONSerializer.java

private static void loadObject(Object retObj, Field f, JSONObject jsonObj) throws JSONSerializationException {
    String key = f.getName();/*from w w  w.j  av a  2s. c o  m*/
    Class type = f.getType();
    try {
        if (type.isPrimitive()) {
            if (type == Integer.TYPE) {
                f.setInt(retObj, jsonObj.getInt(key));
            } else if (type == Long.TYPE) {
                f.setLong(retObj, jsonObj.getInt(key));
            } else if (type == Short.TYPE) {
                f.setShort(retObj, (short) jsonObj.getInt(key));
            } else if (type == Boolean.TYPE) {
                f.setBoolean(retObj, jsonObj.getBoolean(key));
            } else if (type == Double.TYPE) {
                f.setDouble(retObj, jsonObj.getDouble(key));
            } else if (type == Float.TYPE) {
                f.setFloat(retObj, (float) jsonObj.getDouble(key));
            } else if (type == Character.TYPE) {
                char ch = jsonObj.getString(key).charAt(0);
                f.setChar(retObj, ch);
            } else if (type == Byte.TYPE) {
                f.setByte(retObj, (byte) jsonObj.getInt(key));
            } else {
                throw new JSONSerializationException("Unknown primitive: " + type);
            }
        } else if (type == String.class) {
            f.set(retObj, jsonObj.getString(key));
        } else if (JSONSerializable.class.isAssignableFrom(type)) {
            JSONObject jObj = jsonObj.getJSONObject(key);
            JSONSerializable serObj = deSerialize(type, jObj);
            f.set(retObj, serObj);
        }
    } catch (Exception e) {
        throw new JSONSerializationException(e.getMessage(), e);
    }
}

From source file:org.pentaho.reporting.libraries.resourceloader.factory.drawable.DrawableWrapper.java

public DrawableWrapper(final Object maybeDrawable) {
    if (maybeDrawable == null) {
        throw new NullPointerException("Drawable must not be null");
    }//ww w.  j a  v  a 2 s. c  o m
    if (maybeDrawable instanceof DrawableWrapper) {
        throw new IllegalArgumentException("Cannot wrap around a drawable-wrapper");
    }
    final Class<?> aClass = maybeDrawable.getClass();
    try {
        drawMethod = aClass.getMethod("draw", PARAMETER_TYPES);
        final int modifiers = drawMethod.getModifiers();
        if (Modifier.isPublic(modifiers) == false || Modifier.isAbstract(modifiers)
                || Modifier.isStatic(modifiers)) {
            if (logger.isWarnEnabled()) {
                logger.warn(String.format("DrawMethod is not valid: %s#%s", aClass, drawMethod)); // NON-NLS
            }
            drawMethod = null;
        }
    } catch (NoSuchMethodException e) {
        // ignore exception
        if (logger.isWarnEnabled()) {
            logger.warn(String.format("The object is not a drawable: %s", aClass)); // NON-NLS
        }
        drawMethod = null;
    }

    if (drawMethod != null) {
        try {
            isKeepAspectRatioMethod = aClass.getMethod("isPreserveAspectRatio", EMPTY_PARAMS);
            final int modifiers = isKeepAspectRatioMethod.getModifiers();
            if (Modifier.isPublic(modifiers) == false || Modifier.isAbstract(modifiers)
                    || Modifier.isStatic(modifiers)
                    || Boolean.TYPE.equals(isKeepAspectRatioMethod.getReturnType()) == false) {
                isKeepAspectRatioMethod = null;
            }
        } catch (NoSuchMethodException e) {
            // ignored ..
        }

        try {
            getPreferredSizeMethod = aClass.getMethod("getPreferredSize", EMPTY_PARAMS);
            final int modifiers = getPreferredSizeMethod.getModifiers();
            if (Modifier.isPublic(modifiers) == false || Modifier.isAbstract(modifiers)
                    || Modifier.isStatic(modifiers)
                    || Dimension.class.isAssignableFrom(getPreferredSizeMethod.getReturnType()) == false) {
                getPreferredSizeMethod = null;
            }
        } catch (NoSuchMethodException e) {
            // ignored ..
        }
    }
    backend = maybeDrawable;
}

From source file:org.kuali.rice.krad.util.DataTypeUtil.java

/**
 * Determines if the given class is enough like a boolean, to index it as a String "Y" or "N"
 * @param type the class to determine the type of
 * @return true if it is like a boolean, false otherwise
 *//*w ww.j  av  a2 s  .  c o m*/
public static boolean isBooleanable(Class<?> type) {
    return java.lang.Boolean.class.isAssignableFrom(type) || type.equals(Boolean.TYPE);
}