`

apache.commons.lang2.3学习笔记-BooleanUtils

 
阅读更多

public class TestBooleanUtils {

	public void test() {
		boolean b = false;
		Boolean B = false;
		int i = 0;
		String s = null;
		/** isFalse:判断布尔对象是否为false */
		//(Boolean)当且仅当给定的布尔对象的值为false时返回true,给null返回false
		//		b = BooleanUtils.isFalse(new Boolean(false));//true
		/** isNotFalse:判断布尔对象是否不为false */
		//(Boolean)当且仅当给定的布尔对象的值为false时返回false,给null返回true
		//		b = BooleanUtils.isNotFalse(new Boolean(false));//false
		/** isNotTrue:判断布尔对象是否不为true */
		//(Boolean)当且仅当给定的布尔对象的值为true时返回false,给null返回true
		//		b = BooleanUtils.isNotTrue(new Boolean(true));//false
		/** isTrue:判断布尔对象是否为true */
		//(Boolean)当且仅当给定的布尔对象的值为true时返回true,给null返回false
		//		b = BooleanUtils.isTrue(new Boolean(true));//true
		/** toBoolean:通过判断给定的参数返回布尔值 */
		//(int)判断给定的int值后返回一个布尔值,当且仅当给定的int值为0时返回false,
		//其余返回true
		//		b = BooleanUtils.toBoolean(-1);//true

		//(Boolean)将给定的布尔高级对象卸载为基础布尔值,其值与给定的布尔对象相同
		//		b = BooleanUtils.toBoolean(new Boolean(false));//false

		//(String)判断给定的String对象返回一个布尔值,
		//当且仅当给定的String对象为"true"时返回true
		//		b = BooleanUtils.toBoolean("123");//false

		//(int, int, int)判断给定的int值参数返回一个布尔值,
		//当第一参数与第二参数相等时返回true,
		//当第一参数与第二参数不等且等于第三参数时,返回false
		//当第一参数与第二及第三参数都不等时,抛出java.lang.IllegalArgumentException异常
		//		b = BooleanUtils.toBoolean(0, 0, 0);//true

		//(Integer, Integer, Integer)判断给定的Integer对象的值,返回一个布尔值
		//判定方式同上
		//		b = BooleanUtils.toBoolean(new Integer(0), new Integer(0), new Integer(0));//true

		//(String, String, String)判断给定的String值参数返回一个布尔值,
		//当第一参数与第二参数equals时返回true,
		//当第一参数与第二参数不equals且equals第三参数时,返回false
		//当第一参数与第二及第三参数都不equals时,抛出java.lang.IllegalArgumentException异常
		//		b = BooleanUtils.toBoolean("a", "A", "1");//异常
		/** toBooleanDefaultIfNull:判断给定的布尔对象的值并返回 */
		//(Boolean, boolean)当Boolean对象不为null时,返回Boolean对象的值;
		//当Boolean对象为null时,返回第二个boolean值
		//		b = BooleanUtils.toBooleanDefaultIfNull(null, false);//false
		/** toBooleanObject:通过判断给定的参数返回布尔对象 */
		//(boolean)将给定的boolean值装配成高级布尔对象,其值为给定的boolean值
		//		b = BooleanUtils.toBooleanObject(true);//true

		//(int)判断给定的int值后返回一个布尔对象,当且仅当给定的int值为0时返回false,
		//其余返回true
		//		b = BooleanUtils.toBooleanObject(-1);//true

		//(Integer)判断给定的Integer对象的值后返回一个布尔对象,
		//当且仅当给定的Integer对象的值为0时返回false,其余返回true
		//		b = BooleanUtils.toBooleanObject(new Integer(0));//false

		//(String)判断给定的String对象返回一个布尔对象,
		//当且仅当给定的String对象为"true"时返回true
		//		b = BooleanUtils.toBooleanObject("true");//true

		//(int, int, int)判断给定的int值参数返回一个布尔对象,
		//当第一参数与第二参数相等时返回true,
		//当第一参数与第二参数不等且等于第三参数时,返回false
		//当第一参数与第二及第三参数不等且等于第四参数时,返回null
		//当第一参数与第二及第三参数都不等时,抛出java.lang.IllegalArgumentException异常
		//		B = BooleanUtils.toBooleanObject(0, 1, 1, 0);//null

		//(String, String, String)判断给定的String值参数返回一个布尔值,
		//当第一参数与第二参数equals时返回true,
		//当第一参数与第二参数不equals且equals第三参数时,返回false
		//当第一参数与第二及第三参数不equals且equals于第四参数时,返回null
		//当第一参数与第二及第三参数都不equals时,抛出java.lang.IllegalArgumentException异常
		//		B = BooleanUtils.toBooleanObject("1", "2", "1", "3");//false
		/** toInteger:判断给定的布尔值后返回一个int值 */
		//(boolean)当给false时返回0,当给true时返回1
		//		i = BooleanUtils.toInteger(true);//1

		//(boolean, int, int)当给true时返回第一个int值,当给false时返回第二个int值
		//		i = BooleanUtils.toInteger(true, 2, 3);//2

		//(Boolean, int, int, int)当给定的布尔对象的值为true时,返回第一个int值
		//当给定的布尔对象的值为false时,返回第二个int值
		//当给定的布尔对象为null时,返回第三个int值
		//		i = BooleanUtils.toInteger(null, 1, 2, -1);//-1

		//(Boolean)当给定的布尔对象的值为true时返回1
		//当给定的布尔对象的值为false时返回0
		//当给定的布尔对象为null时抛出 java.lang.NullPointerException异常
		//		i = BooleanUtils.toIntegerObject(null);//异常

		//(boolean)当给false时返回0,当给true时返回1
		//		i = BooleanUtils.toIntegerObject(false);//0

		//(boolean, int, int)当给定的boolean值为true时返回第一个int值
		//当给定的boolean值为false时返回第二个int值
		//		i = BooleanUtils.toIntegerObject(false, 1, 2);//2

		//(Boolean, int, int, int)当给定的Boolean值为true时返回第一个int值
		//当给定的Boolean值为false时返回第二个int值
		//当给定的Boolean为null时返回第三个int值
		//		i = BooleanUtils.toIntegerObject(null, 1, 2, 3);
		/** toString:判断给定的参数返回String */
		//(boolean, String, String)当给定的boolean值为true时返回第一个String值
		//当给定的boolean值为false时返回第二个String值
		//		s = BooleanUtils.toString(true, "a", "b");//"a"

		//(Boolean, String, String, String)当给定的Boolean值为true时返回第一个String值
		//当给定的Boolean值为false时返回第二个String值
		//当给定的Boolean为null时返回第三个String值
		//		s = BooleanUtils.toString(null, "a", "b", "c");//"c"

		/** toStringOnOff:判断给定的布尔值,返回"on"或"off" */
		//(boolean)当给true时返回"on",当给false时返回"off"
		//		s = BooleanUtils.toStringOnOff(true);//"on"

		//(Boolean)当给定的Boolean为true时返回"on"
		//当给定的Boolean为false时返回"off"
		//当给定的Boolean为null时返回null
		//		s = BooleanUtils.toStringOnOff(null);//null
		/** toStringTrueFalse:判断给定的布尔值,返回"true"或"false" */
		//(boolean)当给true时返回"true",当给false时返回"false"
		//		s = BooleanUtils.toStringTrueFalse(true);//"true"

		//(Boolean)当给定的Boolean为true时返回"true"
		//当给定的Boolean为false时返回"false"
		//当给定的Boolean为null时返回null
		//		s = BooleanUtils.toStringTrueFalse(null);//null
		/** toStringYesNo:判断给定的布尔值,返回"yes"或"no" */
		//(boolean)当给true时返回"yes",当给false时返回"no"
		//		s = BooleanUtils.toStringYesNo(true);//"yes"

		//(Boolean)当给定的Boolean为true时返回"yes"
		//当给定的Boolean为false时返回"no"
		//当给定的Boolean为null时返回null
		//		s = BooleanUtils.toStringYesNo(null);//null
		/** xor:判断给定的布尔数组,返回一个布尔值 */
		//		Boolean[] array = { false, true, false };
		//(Boolean[])当给定的布尔对象数组中包含任一true值时返回true
		//当给定的布尔对象数组中包含任一null值时抛出java.lang.IllegalArgumentException异常
		//		b = BooleanUtils.xor(array);//true

		//		boolean[] array = { false, true, false };
		//(Boolean[])当给定的布尔对象数组中包含任一true值时返回true
		//		b = BooleanUtils.xor(array);//true
		System.err.println(b);
	}

	/**
	 * @author cuiweiqing 2011-12-6
	 * @param args
	 */
	public static void main(String[] args) {
		new TestBooleanUtils().test();
	}

}
 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics