scolebourne 2004/10/08 14:27:00
Modified: lang/src/test/org/apache/commons/lang BooleanUtilsTest.java
lang/src/java/org/apache/commons/lang BooleanUtils.java
Log:
Add isTrue and isFalse methods
Revision Changes Path
1.10 +14 -1
jakarta-commons/lang/src/test/org/apache/commons/lang/BooleanUtilsTest.java
Index: BooleanUtilsTest.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/lang/src/test/org/apache/commons/lang/BooleanUtilsTest.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- BooleanUtilsTest.java 18 Feb 2004 23:06:19 -0000 1.9
+++ BooleanUtilsTest.java 8 Oct 2004 21:27:00 -0000 1.10
@@ -72,6 +72,19 @@
}
//-----------------------------------------------------------------------
+ public void test_isTrue_Boolean() {
+ assertEquals(true, BooleanUtils.isTrue(Boolean.TRUE));
+ assertEquals(false, BooleanUtils.isTrue(Boolean.FALSE));
+ assertEquals(false, BooleanUtils.isTrue((Boolean) null));
+ }
+
+ public void test_isFalse_Boolean() {
+ assertEquals(false, BooleanUtils.isFalse(Boolean.TRUE));
+ assertEquals(true, BooleanUtils.isFalse(Boolean.FALSE));
+ assertEquals(false, BooleanUtils.isFalse((Boolean) null));
+ }
+
+ //-----------------------------------------------------------------------
public void test_toBooleanObject_boolean() {
assertSame(Boolean.TRUE, BooleanUtils.toBooleanObject(true));
assertSame(Boolean.FALSE, BooleanUtils.toBooleanObject(false));
1.19 +41 -1
jakarta-commons/lang/src/java/org/apache/commons/lang/BooleanUtils.java
Index: BooleanUtils.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/lang/src/java/org/apache/commons/lang/BooleanUtils.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- BooleanUtils.java 18 Feb 2004 22:59:50 -0000 1.18
+++ BooleanUtils.java 8 Oct 2004 21:27:00 -0000 1.19
@@ -68,6 +68,46 @@
// boolean Boolean methods
//-----------------------------------------------------------------------
/**
+ * <p>Is a Boolean value <code>true</code>, handling <code>null</code>.</p>
+ *
+ * <pre>
+ * BooleanUtils.isTrue(Boolean.TRUE) = true
+ * BooleanUtils.isTrue(Boolean.FALSE) = false
+ * BooleanUtils.isTrue(null) = false
+ * </pre>
+ *
+ * @param bool the boolean to convert
+ * @return <code>true</code> only if the input is non-null and true
+ * @since 2.1
+ */
+ public static boolean isTrue(Boolean bool) {
+ if (bool == null) {
+ return false;
+ }
+ return (bool.booleanValue() ? true : false);
+ }
+
+ /**
+ * <p>Is a Boolean value <code>false</code>, handling <code>null</code>.</p>
+ *
+ * <pre>
+ * BooleanUtils.isFalse(Boolean.TRUE) = false
+ * BooleanUtils.isFalse(Boolean.FALSE) = true
+ * BooleanUtils.isFalse(null) = false
+ * </pre>
+ *
+ * @param bool the boolean to convert
+ * @return <code>true</code> only if the input is non-null and false
+ * @since 2.1
+ */
+ public static boolean isFalse(Boolean bool) {
+ if (bool == null) {
+ return false;
+ }
+ return (bool.booleanValue() ? false : true);
+ }
+
+ /**
* <p>Boolean factory that avoids creating new Boolean objecs all the time.</p>
*
* <p>This method was added to JDK1.4 but is available here for earlier
JDKs.</p>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]