Java Boolean From toBooleanObject(int value, int trueValue, int falseValue, int nullValue)

Here you can find the source of toBooleanObject(int value, int trueValue, int falseValue, int nullValue)

Description

to Boolean Object

License

Mozilla Public License

Declaration

public static Boolean toBooleanObject(int value, int trueValue, int falseValue, int nullValue) 

Method Source Code

//package com.java2s;
//License from project: Mozilla Public License 

public class Main {
    public static Boolean toBooleanObject(boolean bool) {
        return bool ? Boolean.TRUE : Boolean.FALSE;
    }/*from  w  ww. ja  v a2 s .c  om*/

    public static Boolean toBooleanObject(int value) {
        return value == 0 ? Boolean.FALSE : Boolean.TRUE;
    }

    public static Boolean toBooleanObject(Integer value) {
        if (value == null) {
            return null;
        }

        return value == 0 ? Boolean.FALSE : Boolean.TRUE;
    }

    public static Boolean toBooleanObject(int value, int trueValue, int falseValue, int nullValue) {
        if (value == trueValue) {
            return Boolean.TRUE;
        } else if (value == falseValue) {
            return Boolean.FALSE;
        } else if (value == nullValue) {
            return null;
        }

        throw new IllegalArgumentException("The Integer did not match any specified value");
    }

    public static Boolean toBooleanObject(Integer value, Integer trueValue, Integer falseValue, Integer nullValue) {
        if (value == null) {
            if (trueValue == null) {
                return Boolean.TRUE;
            } else if (falseValue == null) {
                return Boolean.FALSE;
            } else if (nullValue == null) {
                return null;
            }
        } else if (value.equals(trueValue)) {
            return Boolean.TRUE;
        } else if (value.equals(falseValue)) {
            return Boolean.FALSE;
        } else if (value.equals(nullValue)) {
            return null;
        }

        throw new IllegalArgumentException("The Integer did not match any specified value");
    }

    public static Boolean toBooleanObject(String str) {
        if ("true".equalsIgnoreCase(str)) {
            return Boolean.TRUE;
        } else if ("false".equalsIgnoreCase(str)) {
            return Boolean.FALSE;
        } else if ("on".equalsIgnoreCase(str)) {
            return Boolean.TRUE;
        } else if ("off".equalsIgnoreCase(str)) {
            return Boolean.FALSE;
        } else if ("yes".equalsIgnoreCase(str)) {
            return Boolean.TRUE;
        } else if ("no".equalsIgnoreCase(str)) {
            return Boolean.FALSE;
        }

        return null;
    }

    public static Boolean toBooleanObject(String str, String trueString, String falseString, String nullString) {
        if (str == null) {
            if (trueString == null) {
                return Boolean.TRUE;
            } else if (falseString == null) {
                return Boolean.FALSE;
            } else if (nullString == null) {
                return null;
            }
        } else if (str.equals(trueString)) {
            return Boolean.TRUE;
        } else if (str.equals(falseString)) {
            return Boolean.FALSE;
        } else if (str.equals(nullString)) {
            return null;
        }

        throw new IllegalArgumentException("The String did not match any specified value");
    }
}

Related

  1. toBooleanDefaultIfNull(Boolean bool, boolean valueIfNull)
  2. toBooleanDefaultIfNull(Boolean bool, boolean valueIfNull)
  3. toBooleanObject(final int val)
  4. toBooleanObject(final String str)
  5. toBooleanObject(int value, int trueValue, int falseValue, int nullValue)
  6. toBooleanObject(String str)
  7. toBooleans(byte[] bytes)
  8. toBooleans(byte[] value, int offset, int num)
  9. toBooleanString(long value)