001package com.hfg.util; 002 003//------------------------------------------------------------------------------ 004/** 005 General boolean utility functions. 006 <div> 007 @author J. Alex Taylor, hairyfatguy.com 008 </div> 009 */ 010//------------------------------------------------------------------------------ 011// com.hfg XML/HTML Coding Library 012// 013// This library is free software; you can redistribute it and/or 014// modify it under the terms of the GNU Lesser General Public 015// License as published by the Free Software Foundation; either 016// version 2.1 of the License, or (at your option) any later version. 017// 018// This library is distributed in the hope that it will be useful, 019// but WITHOUT ANY WARRANTY; without even the implied warranty of 020// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 021// Lesser General Public License for more details. 022// 023// You should have received a copy of the GNU Lesser General Public 024// License along with this library; if not, write to the Free Software 025// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 026// 027// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com 028// jataylor@hairyfatguy.com 029//------------------------------------------------------------------------------ 030 031public class BooleanUtil 032{ 033 //--------------------------------------------------------------------------- 034 public static Boolean valueOf(Object inValue) 035 { 036 Boolean result = Boolean.FALSE; 037 038 if (inValue != null) 039 { 040 if (inValue instanceof Boolean) 041 { 042 result = (Boolean) inValue; 043 } 044 else 045 { 046 result = valueOf(inValue.toString()); 047 } 048 } 049 050 return result; 051 } 052 053 //--------------------------------------------------------------------------- 054 public static Boolean valueOf(String inValue) 055 { 056 Boolean result = Boolean.FALSE; 057 058 if (StringUtil.isSet(inValue)) 059 { 060 if (inValue.equalsIgnoreCase("true") 061 || inValue.equalsIgnoreCase("T") 062 || inValue.equalsIgnoreCase("yes") 063 || inValue.equalsIgnoreCase("Y") 064 || inValue.equalsIgnoreCase("1")) 065 { 066 result = Boolean.TRUE; 067 } 068 } 069 070 return result; 071 } 072 073 //--------------------------------------------------------------------------- 074 public static Boolean valueOf(Character inValue) 075 { 076 Boolean result = Boolean.FALSE; 077 078 if (inValue != null) 079 { 080 if (inValue.equals('T') 081 || inValue.equals('t') 082 || inValue.equals('Y') 083 || inValue.equals('y')) 084 { 085 result = Boolean.TRUE; 086 } 087 } 088 089 return result; 090 } 091 092 //--------------------------------------------------------------------------- 093 public static Boolean valueOf(Integer inValue) 094 { 095 Boolean result = Boolean.FALSE; 096 097 if (inValue != null) 098 { 099 if (inValue.equals(1)) 100 { 101 result = Boolean.TRUE; 102 } 103 } 104 105 return result; 106 } 107}