Repository: commons-lang
Updated Branches:
  refs/heads/master b60ca26a2 -> c70e05ae4


[LANG-1422] Add null-safe StringUtils.valueOf(char[]) to delegate to
String.valueOf(char[])

Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/c70e05ae
Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/c70e05ae
Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/c70e05ae

Branch: refs/heads/master
Commit: c70e05ae41b4990a9d1e5f442219411abc6b2afb
Parents: b60ca26
Author: Gary Gregory <garydgreg...@gmail.com>
Authored: Thu Oct 25 08:52:48 2018 -0600
Committer: Gary Gregory <garydgreg...@gmail.com>
Committed: Thu Oct 25 08:52:48 2018 -0600

----------------------------------------------------------------------
 src/changes/changes.xml                         |  1 +
 .../org/apache/commons/lang3/StringUtils.java   | 13 ++++++
 .../commons/lang3/StringUtilsValueOfTest.java   | 43 ++++++++++++++++++++
 3 files changed, 57 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-lang/blob/c70e05ae/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 0b6352b..ec5555d 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -50,6 +50,7 @@ The <action> type attribute can be add,update,fix,remove.
     <action issue="LANG-1417" type="update" dev="britter">Add 
@FunctionalInterface to ThreadPredicate and ThreadGroupPredicate</action>
     <action issue="LANG-1415" type="update" dev="britter">Update Java Language 
requirement to 1.8</action>
     <action issue="LANG-1411" type="add" dev="britter" due-to="Alexander 
Tsvetkov">Add isEmpty method to ObjectUtils</action>
+    <action issue="LANG-1422" type="add" dev="ggregory">Add null-safe 
StringUtils.valueOf(char[]) to delegate to String.valueOf(char[])</action>
   </release>
 
   <release version="3.8.1" date="2018-09-19" description="This release is a 
bugfix for Restoring Bundle-SymbolicName in the MANIFEST.mf file.">

http://git-wip-us.apache.org/repos/asf/commons-lang/blob/c70e05ae/src/main/java/org/apache/commons/lang3/StringUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/lang3/StringUtils.java 
b/src/main/java/org/apache/commons/lang3/StringUtils.java
index f96c7c5..e4e7453 100644
--- a/src/main/java/org/apache/commons/lang3/StringUtils.java
+++ b/src/main/java/org/apache/commons/lang3/StringUtils.java
@@ -9413,4 +9413,17 @@ public class StringUtils {
         }
         return result;
     }
+    
+    /**
+     *  Returns the string representation of the {@code char} array or null.
+     *  
+     * @param value the character array.
+     * @return a String or null
+     * @see String#valueOf(char[])
+     * @since 3.9
+     */
+    public static String valueOf(final char[] value) {
+        return value == null ? null : String.valueOf(value);
+    }
+    
 }

http://git-wip-us.apache.org/repos/asf/commons-lang/blob/c70e05ae/src/test/java/org/apache/commons/lang3/StringUtilsValueOfTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/lang3/StringUtilsValueOfTest.java 
b/src/test/java/org/apache/commons/lang3/StringUtilsValueOfTest.java
new file mode 100644
index 0000000..ffa73ce
--- /dev/null
+++ b/src/test/java/org/apache/commons/lang3/StringUtilsValueOfTest.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.lang3;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests {@link StringUtils}'s valueOf() methods.
+ * 
+ * @since 3.9
+ */
+public class StringUtilsValueOfTest {
+
+    @Test
+    public void testValueOfChar() {
+        Assertions.assertEquals("ABC", StringUtils.valueOf(new char[] {'A', 
'B', 'C' }));
+    }
+
+    @Test
+    public void testValueOfCharEmpty() {
+        Assertions.assertEquals(StringUtils.EMPTY, 
StringUtils.valueOf(ArrayUtils.EMPTY_CHAR_ARRAY));
+    }
+
+    @Test
+    public void testValueOfCharNull() {
+        Assertions.assertNull(StringUtils.valueOf(null));
+    }
+}

Reply via email to