Java Boolean From toBoolean(Object val)

Here you can find the source of toBoolean(Object val)

Description

to Boolean

License

Open Source License

Declaration

public static boolean toBoolean(Object val) 

Method Source Code

//package com.java2s;
/*/*from   w w w.j  ava  2s.  c om*/
 * Scriptographer
 *
 * This file is part of Scriptographer, a Scripting Plugin for Adobe Illustrator
 * http://scriptographer.org/
 *
 * Copyright (c) 2002-2010, Juerg Lehni
 * http://scratchdisk.com/
 *
 * All rights reserved. See LICENSE file for details.
 * 
 * File created on May 23, 2007.
 */

public class Main {
    public static boolean toBoolean(Object val) {
        return toBoolean(val, false);
    }

    public static boolean toBoolean(Object val, boolean defaultValue) {
        if (val instanceof Boolean)
            return ((Boolean) val).booleanValue();
        if (val == null)
            return defaultValue;
        if (val instanceof String)
            return ((String) val).length() != 0;
        if (val instanceof Number) {
            double d = ((Number) val).doubleValue();
            return d != 0.0 && !Double.isNaN(d);
        }
        return true;
    }
}

Related

  1. toBoolean(Object object)
  2. toBoolean(Object object, Boolean defaultValue)
  3. toBoolean(Object property, boolean defaultValue)
  4. toBoolean(Object s)
  5. toBoolean(Object v)
  6. toBoolean(Object val, boolean defValue)
  7. toBoolean(Object value)
  8. toBoolean(Object value)
  9. toBoolean(Object value)