Java Boolean Value From booleanValue(Object associationValue)

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

Description

boolean Value

License

Open Source License

Declaration

public static boolean booleanValue(Object associationValue) 

Method Source Code

//package com.java2s;
/*// w w w .  j  av  a 2s .  c  o m
 * _WOJExtensionsUtil.java
 * (c) Copyright 2001 Apple Computer, Inc. All rights reserved.
 * This a modified version.
 * Original license: http://www.opensource.apple.com/apsl/
 */

public class Main {
    public static boolean booleanValue(Object associationValue) {
        boolean associationEvaluation = true;
        if (associationValue != null) {
            // is this a number. If it is, evaluate it.
            if (associationValue instanceof Number) {
                if (((Number) associationValue).intValue() == 0) {
                    associationEvaluation = false;
                }
            } else if (associationValue instanceof String) {
                String associationValueString = (String) associationValue;
                // is this no or false ?
                if (associationValueString.equalsIgnoreCase("no")
                        || associationValueString.equalsIgnoreCase("false")) {
                    associationEvaluation = false;
                } else {
                    // is this a string representing a number ? Try to evaluate it.
                    try {
                        if (Integer.parseInt(associationValueString) == 0) {
                            associationEvaluation = false;
                        }
                    } catch (NumberFormatException e) {
                        throw new RuntimeException(
                                "error parsing boolean from value "
                                        + associationValueString);
                    }
                }
            } else if (associationValue instanceof Boolean) {
                associationEvaluation = ((Boolean) associationValue)
                        .booleanValue();
            } else {
                // do nothing, it's non-null, so it's true !
            }
        } else {
            associationEvaluation = false;
        }

        return associationEvaluation;
    }
}

Related

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