Java Boolean From toBoolean(Object object, Boolean defaultValue)

Here you can find the source of toBoolean(Object object, Boolean defaultValue)

Description

to Boolean

License

Open Source License

Declaration

public static Boolean toBoolean(Object object, Boolean defaultValue) 

Method Source Code

//package com.java2s;
/**********************************************************************************************
 *
 * Asprise Scanning and Imaging API/*w  w  w  .j a  v a2  s. c o m*/
 * Copyright (C) 1998-2016. Asprise Inc. <asprise.com>
 *
 * This file is licensed under the GNU Affero General Public License version 3 as published by
 * the Free Software Foundation.
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the
 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 * either express or implied. See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * You should have received a copy of the GNU Affero General Public License.  If not, please
 * visit <http://www.gnu.org/licenses/agpl-3.0.html>.
 *
 **********************************************************************************************/

public class Main {
    public static Boolean toBoolean(Object object, Boolean defaultValue) {
        if (object == null) {
            return defaultValue;
        }
        if (object instanceof Boolean) {
            return ((Boolean) object).booleanValue();
        }

        try {
            Boolean value = Boolean.valueOf(object.toString().trim());
            return value;
        } catch (Throwable e) {
            return defaultValue;
        }
    }
}

Related

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