Java Boolean From toBoolean(final String booleanString, final boolean defaultValue)

Here you can find the source of toBoolean(final String booleanString, final boolean defaultValue)

Description

Retrieves whether the given value is true

License

Open Source License

Parameter

Parameter Description
booleanString the value
defaultValue the default if the value is unspecified or not a boolean value

Return

whether the given value is true

Declaration

public final static boolean toBoolean(final String booleanString, final boolean defaultValue) 

Method Source Code

//package com.java2s;
/**//from   ww w  . j  a  va  2  s  .c o  m
 * The contents of this file are subject to the Regenstrief Public License
 * Version 1.0 (the "License"); you may not use this file except in compliance with the License.
 * Please contact Regenstrief Institute if you would like to obtain a copy of the license.
 *
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
 * License for the specific language governing rights and limitations
 * under the License.
 *
 * Copyright (C) Regenstrief Institute.  All Rights Reserved.
 */

public class Main {
    public final static String TRUE = Boolean.toString(true);
    public final static String FALSE = Boolean.toString(false);

    /**
     * Retrieves whether the given value is true
     * 
     * @param booleanString the value
     * @param defaultValue the default if the value is unspecified or not a boolean value
     * @return whether the given value is true
     **/
    public final static boolean toBoolean(final String booleanString, final boolean defaultValue) {
        return toBoolean(booleanString, TRUE, FALSE, defaultValue);
    }

    public final static boolean toBoolean(final String in, final String tru, final String fls,
            final boolean defVal) {
        return defVal ? !fls.equalsIgnoreCase(in) : tru.equalsIgnoreCase(in);
    }

    /**
     * Determines if two Strings are equal, ignoring case (true if both are null)
     * 
     * @param s1 String 1
     * @param s2 String 2
     * @return whether s1 equals s2, ignoring case
     **/
    public final static boolean equalsIgnoreCase(final String s1, final String s2) {
        return s1 == null ? s2 == null : s1.equalsIgnoreCase(s2);
    }
}

Related

  1. toBoolean(final byte[] b)
  2. toBoolean(final Object obj, final boolean defaultValue)
  3. toBoolean(final Object value)
  4. toBoolean(final Object value, final boolean defaultValue)
  5. toBoolean(final Object valueRep)
  6. toBoolean(final String s)
  7. toBoolean(final String s)
  8. toBoolean(final String source)
  9. toBoolean(final String string)