Add negate(Boolean) method
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/lang/trunk@137204 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
24968c2cfa
commit
af15108a55
|
@ -58,7 +58,7 @@ package org.apache.commons.lang;
|
||||||
* boolean and Boolean objects.</p>
|
* boolean and Boolean objects.</p>
|
||||||
*
|
*
|
||||||
* @author Stephen Colebourne
|
* @author Stephen Colebourne
|
||||||
* @version $Id: BooleanUtils.java,v 1.1 2002/12/15 16:55:32 scolebourne Exp $
|
* @version $Id: BooleanUtils.java,v 1.2 2002/12/22 21:33:12 scolebourne Exp $
|
||||||
*/
|
*/
|
||||||
public class BooleanUtils {
|
public class BooleanUtils {
|
||||||
|
|
||||||
|
@ -72,6 +72,24 @@ public class BooleanUtils {
|
||||||
public BooleanUtils() {
|
public BooleanUtils() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Boolean utilities
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>Negates the specified boolean.</p>
|
||||||
|
*
|
||||||
|
* <p>If <code>null</code> is passed in, <code>null</code> will be returned.</p>
|
||||||
|
*
|
||||||
|
* @param bool the Boolean to negate, may be null
|
||||||
|
* @return the negated Boolean, or <code>null</code> if <code>null</code> passed in
|
||||||
|
*/
|
||||||
|
public static Boolean negate(Boolean bool) {
|
||||||
|
if (bool == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return (bool.booleanValue() ? Boolean.FALSE : Boolean.TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
// boolean Boolean methods
|
// boolean Boolean methods
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
|
@ -61,7 +61,7 @@ import junit.textui.TestRunner;
|
||||||
* Unit tests {@link org.apache.commons.lang.BooleanUtils}.
|
* Unit tests {@link org.apache.commons.lang.BooleanUtils}.
|
||||||
*
|
*
|
||||||
* @author Stephen Colebourne
|
* @author Stephen Colebourne
|
||||||
* @version $Id: BooleanUtilsTest.java,v 1.1 2002/12/15 16:55:32 scolebourne Exp $
|
* @version $Id: BooleanUtilsTest.java,v 1.2 2002/12/22 21:33:12 scolebourne Exp $
|
||||||
*/
|
*/
|
||||||
public class BooleanUtilsTest extends TestCase {
|
public class BooleanUtilsTest extends TestCase {
|
||||||
|
|
||||||
|
@ -87,6 +87,13 @@ public class BooleanUtilsTest extends TestCase {
|
||||||
super.tearDown();
|
super.tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------
|
||||||
|
public void test_negate_Boolean() {
|
||||||
|
assertSame(null, BooleanUtils.negate(null));
|
||||||
|
assertSame(Boolean.TRUE, BooleanUtils.negate(Boolean.FALSE));
|
||||||
|
assertSame(Boolean.FALSE, BooleanUtils.negate(Boolean.TRUE));
|
||||||
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
public void test_toBooleanObject_boolean() {
|
public void test_toBooleanObject_boolean() {
|
||||||
assertSame(Boolean.TRUE, BooleanUtils.toBooleanObject(true));
|
assertSame(Boolean.TRUE, BooleanUtils.toBooleanObject(true));
|
||||||
|
|
Loading…
Reference in New Issue