Skip to content

Commit

Permalink
Add BooleanUtils.booleanValues().
Browse files Browse the repository at this point in the history
Add BooleanUtils.primitiveValues().

Handy for tools and tests.
Make next release version 3.12.0.
  • Loading branch information
garydgregory committed Sep 28, 2020
1 parent a3e5a01 commit b2e7374
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 5 deletions.
8 changes: 4 additions & 4 deletions pom.xml
Expand Up @@ -26,7 +26,7 @@
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>commons-lang3</artifactId>
<version>3.12-SNAPSHOT</version>
<version>3.12.0-SNAPSHOT</version>
<name>Apache Commons Lang</name>

<inceptionYear>2001</inceptionYear>
Expand All @@ -47,7 +47,7 @@
<connection>scm:git:http://gitbox.apache.org/repos/asf/commons-lang.git</connection>
<developerConnection>scm:git:https://gitbox.apache.org/repos/asf/commons-lang.git</developerConnection>
<url>https://gitbox.apache.org/repos/asf?p=commons-lang.git</url>
<tag>commons-lang-3.12</tag>
<tag>commons-lang-3.12.0</tag>
</scm>

<developers>
Expand Down Expand Up @@ -587,7 +587,7 @@
<commons.packageId>lang3</commons.packageId>
<commons.module.name>org.apache.commons.lang3</commons.module.name>
<!-- Current 3.x release series -->
<commons.release.version>3.12</commons.release.version>
<commons.release.version>3.12.0</commons.release.version>
<commons.release.desc>(Java 8+)</commons.release.desc>
<!-- Previous 2.x release series -->
<commons.release.2.version>2.6</commons.release.2.version>
Expand Down Expand Up @@ -624,7 +624,7 @@
<commons.japicmp.version>0.14.3</commons.japicmp.version>

<!-- Commons Release Plugin -->
<commons.bc.version>3.10</commons.bc.version>
<commons.bc.version>3.11</commons.bc.version>
<commons.rc.version>RC2</commons.rc.version>
<commons.release.isDistModule>true</commons.release.isDistModule>
<commons.distSvnStagingUrl>scm:svn:https://dist.apache.org/repos/dist/dev/commons/lang</commons.distSvnStagingUrl>
Expand Down
5 changes: 4 additions & 1 deletion src/changes/changes.xml
Expand Up @@ -45,11 +45,14 @@ The <action> type attribute can be add,update,fix,remove.
</properties>
<body>

<release version="3.12" date="2020-MM-DD" description="New features and bug fixes.">
<release version="3.12.0" date="2020-MM-DD" description="New features and bug fixes.">
<!-- FIXES -->
<action issue="LANG-1592" type="fix" dev="aherbert" due-to="Huang Pingcai, Alex Herbert">Correct implementation of RandomUtils.nextLong(long, long)</action>
<action issue="LANG-1600" type="fix" dev="ggregory" due-to="Michael F">Restore handling of collections for non-JSON ToStringStyle #610.</action>
<action type="fix" dev="ggregory" due-to="iamchao1129">ContextedException Javadoc add missing semicolon #581.</action>
<!-- ADDS -->
<action type="add" dev="ggregory" due-to="Gary Gregory">Add BooleanUtils.booleanValues().</action>
<action type="add" dev="ggregory" due-to="Gary Gregory">Add BooleanUtils.primitiveValues().</action>
<!-- UPDATES -->
<action issue="LANG-1606" type="update" dev="sebb" due-to="Rustem Galiev">StringUtils.countMatches - clarify Javadoc.</action>
<action issue="LANG-1591" type="update" dev="kinow" due-to="bhawna94">Remove redundant argument from substring call.</action>
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/org/apache/commons/lang3/BooleanUtils.java
Expand Up @@ -99,6 +99,15 @@ public static Boolean and(final Boolean... array) {
}
}

/**
* Returns a new array of possible values (like an enum would).
* @return a new array of possible values (like an enum would).
* @since 3.12.0
*/
public static Boolean[] booleanValues() {
return new Boolean[] {Boolean.FALSE, Boolean.TRUE};
}

/**
* <p>Compares two {@code boolean} values. This is the same functionality as provided in Java 7.</p>
*
Expand Down Expand Up @@ -280,6 +289,15 @@ public static Boolean or(final Boolean... array) {
}
}

/**
* Returns a new array of possible values (like an enum would).
* @return a new array of possible values (like an enum would).
* @since 3.12.0
*/
public static boolean[] primitiveValues() {
return new boolean[] {false, true};
}

/**
* <p>Converts a Boolean to a boolean handling {@code null}
* by returning {@code false}.</p>
Expand Down
14 changes: 14 additions & 0 deletions src/test/java/org/apache/commons/lang3/BooleanUtilsTest.java
Expand Up @@ -16,6 +16,7 @@
*/
package org.apache.commons.lang3;

import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
Expand All @@ -26,6 +27,7 @@

import java.lang.reflect.Constructor;
import java.lang.reflect.Modifier;
import java.util.Arrays;

import org.junit.jupiter.api.Test;

Expand All @@ -34,6 +36,13 @@
*/
public class BooleanUtilsTest {

@Test
public void test_booleanValues() {
final Boolean[] expected = new Boolean[] {false, true};
Arrays.sort(expected);
assertArrayEquals(expected, BooleanUtils.booleanValues());
}

@Test
public void test_isFalse_Boolean() {
assertFalse(BooleanUtils.isFalse(Boolean.TRUE));
Expand Down Expand Up @@ -69,6 +78,11 @@ public void test_negate_Boolean() {
assertSame(Boolean.FALSE, BooleanUtils.negate(Boolean.TRUE));
}

@Test
public void test_primitiveValues() {
assertArrayEquals(new boolean[] {false, true}, BooleanUtils.primitiveValues());
}

@Test
public void test_toBoolean_Boolean() {
assertTrue(BooleanUtils.toBoolean(Boolean.TRUE));
Expand Down

0 comments on commit b2e7374

Please sign in to comment.