Here you can find the source of getBoolean(Dictionary p, Object key, Boolean defaultValue)
public static Boolean getBoolean(Dictionary p, Object key, Boolean defaultValue)
//package com.java2s; /*/*from ww w.j a v a2 s . co m*/ * Copyright 2012 The Solmix Project * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.gnu.org/licenses/ * or see the FSF site: http://www.fsf.org. */ import java.util.Dictionary; import java.util.Map; public class Main { public static boolean getBoolean(Map map, Object key) { Object value = map.get(key); return asBoolean(value); } public static Boolean getBoolean(Dictionary p, Object key, Boolean defaultValue) { Object value = p.get(key); if (value == null) return defaultValue; if (value instanceof Boolean) return (Boolean) value; String s = value.toString().toLowerCase().trim(); if (s.equals("true") || s.equals("yes")) return new Boolean(true); if (s.equals("false") || s.equals("no")) return new Boolean(false); else return defaultValue; } /** * convert a object value to boolean value. * * @param value * @return */ public static boolean asBoolean(Object value) { if (value instanceof Boolean) return ((Boolean) value).booleanValue(); if (value instanceof Number) { return ((Number) value).intValue() > 0; } else { String boolString = (String) value; return boolString != null && !boolString.equals("") && !boolString.equalsIgnoreCase("false"); } } /** * Return the boolean value. if value is null return false. * * @param value * @return */ public static boolean booleanValue(Boolean value) { if (value == null) return false; else return value.booleanValue(); } /** * If not equal return true.else return false. used {@link #isNotEqual(Object, Object)} * * @param <T> * @param actual * @param expect * @return */ public static boolean booleanValue(String booleanValue) { if ("true".equalsIgnoreCase(booleanValue)) return true; else return false; } }