Java Boolean Value From booleanValue(Object value)

Here you can find the source of booleanValue(Object value)

Description

Convert an Object to a Boolean.

License

Apache License

Declaration

public static boolean booleanValue(Object value) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**/*  ww w  . j av a2 s.  com*/
     * Convert an Object to a Boolean.
     */
    public static boolean booleanValue(Object value) {
        if (value == null)
            return false;
        if (value instanceof Boolean)
            return ((Boolean) value).booleanValue();
        if (value instanceof Number)
            return ((Number) value).intValue() != 0;
        return "TRUE".equalsIgnoreCase(value.toString());
    }

    /**
     * Convert an Object to an int, or 0 if it is null.
     */
    public static int intValue(Object value) {
        if (value == null)
            return 0;
        return toInteger(value).intValue();
    }

    /**
     * Convert an Object to an Integer.
     */
    public static Integer toInteger(Object value) {
        if (value == null)
            return null;
        if (value instanceof Integer)
            return (Integer) value;
        if (value instanceof String) {
            if ("".equals((String) value))
                return null;
            return new Integer((String) value);
        }

        if (value instanceof Number)
            return new Integer(((Number) value).intValue());

        return new Integer(value.toString());
    }
}

Related

  1. booleanValue(final Boolean booleanValue)
  2. booleanValue(Object arg)
  3. booleanValue(Object associationValue)
  4. booleanValue(Object obj, boolean defaultValue)
  5. booleanValue(Object object)
  6. booleanValue(String s)
  7. booleanValue(String s)
  8. booleanValue(String s)
  9. booleanValue(String s)