garydgregory commented on code in PR #1215:
URL: https://github.com/apache/commons-lang/pull/1215#discussion_r1598843211


##########
src/test/java/org/apache/commons/lang3/function/ConsumersTest.java:
##########
@@ -46,4 +50,15 @@ public void testNop() {
         Consumers.nop().accept("");
     }
 
+    /**
+     * Tests {@link Consumers#acceptIfNotNull(Object, Consumer)}.
+     */
+    @Test
+    public void testAcceptIfNotNull() {
+        StringBuilder builder = new StringBuilder("jay");
+        Consumers.acceptIfNotNull(builder, sb -> sb.append("-bae"));
+        assertEquals("jay-bae", builder.toString());
+
+        assertDoesNotThrow(() -> Consumers.acceptIfNotNull((String) null, 
string -> fail()));

Review Comment:
   No need for `assertDoesNotThrow`



##########
src/main/java/org/apache/commons/lang3/function/Functions.java:
##########
@@ -41,4 +41,18 @@ public static <T, R> Function<T, R> function(final 
Function<T, R> function) {
     private Functions() {
         // no instances needed.
     }
+
+    /**
+     * Applies the {@link Function} on the object if the object is not {@code 
null}. If the object is {@code null}, it
+     * does nothing.
+     *
+     * @param object the object to apply the function.
+     * @param function the function to apply.
+     * @param <T> the type of the argument the function applies.
+     * @param <R> the type of the result the function returns.
+     * @return the value the function returns If the object is null; null 
otherwise.

Review Comment:
   - The name can just be `apply`.
   - Add a Javadoc since tag.
   - Add null-check for `function`, see `Suppliers.get()`



##########
src/main/java/org/apache/commons/lang3/function/Consumers.java:
##########
@@ -21,7 +21,7 @@
 import java.util.function.Function;
 
 /**
- * Provides {@link Consumer} instances.
+ * Provides {@link Consumer} instances and utilities for working with {@link 
Consumer}.

Review Comment:
   Unnecessary edit.
   



##########
src/main/java/org/apache/commons/lang3/function/Consumers.java:
##########
@@ -46,4 +46,17 @@ private Consumers() {
         // No instances.
     }
 
+    /**
+     * Applies the given {@link Consumer} action to the object if the object 
is not null. If the object is null, it does
+     * nothing.
+     *
+     * @param object the object to be consumed.
+     * @param consumer the consumer to consume.
+     * @param <T> the type of the argument the consumer accepts.
+     */
+    public static <T> void acceptIfNotNull(final T object, final Consumer<T> 
consumer) {

Review Comment:
   - The name can just be `accept`.
   - Add a Javadoc since tag.
   - Add null-check for consumer, see `Suppliers.get()`



##########
src/test/java/org/apache/commons/lang3/function/ConsumersTest.java:
##########
@@ -46,4 +50,15 @@ public void testNop() {
         Consumers.nop().accept("");
     }
 
+    /**
+     * Tests {@link Consumers#acceptIfNotNull(Object, Consumer)}.
+     */
+    @Test
+    public void testAcceptIfNotNull() {
+        StringBuilder builder = new StringBuilder("jay");
+        Consumers.acceptIfNotNull(builder, sb -> sb.append("-bae"));

Review Comment:
   Don't use your name as test data, just use data like foo and bar like you 
did in the other test.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to