Skip to content

Commit 4c1cbdb

Browse files
committed
Flip args on new API
1 parent a37e8de commit 4c1cbdb

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

src/main/java/org/apache/commons/lang3/function/Consumers.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ public class Consumers {
3434
/**
3535
* Applies the given {@link Consumer} action to the object if the consumer is not {@code null}. Otherwise, does
3636
* nothing.
37-
*
38-
* @param object the object to be consumed.
3937
* @param consumer the consumer to consume.
38+
* @param object the object to be consumed.
39+
*
4040
* @param <T> the type of the argument the consumer accepts.
4141
* @since 3.15.0
4242
*/
43-
public static <T> void accept(final T object, final Consumer<T> consumer) {
43+
public static <T> void accept(final Consumer<T> consumer, final T object) {
4444
if (consumer != null) {
4545
consumer.accept(object);
4646
}

src/main/java/org/apache/commons/lang3/function/Functions.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ public final class Functions {
2929
/**
3030
* Applies the {@link Function} on the object if the function is not {@code null}. Otherwise, does nothing and
3131
* returns {@code null}.
32-
*
33-
* @param object the object to apply the function.
3432
* @param function the function to apply.
33+
* @param object the object to apply the function.
34+
*
3535
* @param <T> the type of the argument the function applies.
3636
* @param <R> the type of the result the function returns.
3737
* @return the value the function returns if the function is not {@code null}; {@code null} otherwise.
3838
* @since 3.15.0
3939
*/
40-
public static <T, R> R apply(final T object, final Function<T, R> function) {
40+
public static <T, R> R apply(final Function<T, R> function, final T object) {
4141
return function != null ? function.apply(object) : null;
4242
}
4343

src/test/java/org/apache/commons/lang3/function/ConsumersTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,20 @@ public void accept(T t) {
4141
}
4242

4343
/**
44-
* Tests {@link Consumers#accept(Object, Consumer)}.
44+
* Tests {@link Consumers#accept(Consumer, Object)}.
4545
*/
4646
@Test
4747
public void testAccept() {
4848
final StringBuilder builder = new StringBuilder("foo");
49-
Consumers.accept(builder, sb -> sb.append("-bar"));
49+
Consumers.accept(sb -> sb.append("-bar"), builder);
5050
assertEquals("foo-bar", builder.toString());
5151

5252
final TestConsumer<String> consumer = new TestConsumer<>();
53-
Consumers.accept(null, consumer);
53+
Consumers.accept(consumer, null);
5454
assertTrue(consumer.isCalled);
5555

5656
final StringBuilder builder2 = new StringBuilder("foo");
57-
Consumers.accept(builder2, null);
57+
Consumers.accept(null, builder2);
5858
assertEquals("foo", builder2.toString());
5959
}
6060

src/test/java/org/apache/commons/lang3/function/FunctionsTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@
3030
public class FunctionsTest {
3131

3232
/**
33-
* Tests {@link Functions#apply(Object, Function)}.
33+
* Tests {@link Functions#apply(Function, Object)}.
3434
*/
3535
@Test
3636
public void testApply() {
37-
assertEquals("foo-bar", Functions.apply("foo", string -> string.concat("-bar")));
38-
assertEquals("foo-bar", Functions.apply(null, object -> "foo-bar"));
39-
assertNull(Functions.apply("foo", null));
37+
assertEquals("foo-bar", Functions.apply(string -> string.concat("-bar"), "foo"));
38+
assertEquals("foo-bar", Functions.apply(object -> "foo-bar", null));
39+
assertNull(Functions.apply(null, "foo"));
4040
}
4141

4242
/**

0 commit comments

Comments
 (0)