You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by rp...@apache.org on 2016/03/31 09:58:00 UTC
[16/50] logging-log4j2 git commit: LOG4J2-1278 Added convenience
method to LambdaUtil to evaluate lambda Objects (that implement Supplier)
LOG4J2-1278 Added convenience method to LambdaUtil to evaluate lambda Objects (that implement Supplier)
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/e08160eb
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/e08160eb
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/e08160eb
Branch: refs/heads/master
Commit: e08160eb23a8e9d8950ebe8feb65f2edd5d0a521
Parents: 1c6030d
Author: rpopma <rp...@apache.org>
Authored: Fri Mar 18 00:22:35 2016 +1100
Committer: rpopma <rp...@apache.org>
Committed: Fri Mar 18 00:22:35 2016 +1100
----------------------------------------------------------------------
.../java/org/apache/logging/log4j/util/LambdaUtil.java | 11 +++++++++++
1 file changed, 11 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/e08160eb/log4j-api/src/main/java/org/apache/logging/log4j/util/LambdaUtil.java
----------------------------------------------------------------------
diff --git a/log4j-api/src/main/java/org/apache/logging/log4j/util/LambdaUtil.java b/log4j-api/src/main/java/org/apache/logging/log4j/util/LambdaUtil.java
index 33b0d2a..95dc265 100644
--- a/log4j-api/src/main/java/org/apache/logging/log4j/util/LambdaUtil.java
+++ b/log4j-api/src/main/java/org/apache/logging/log4j/util/LambdaUtil.java
@@ -91,4 +91,15 @@ public final class LambdaUtil {
final Object result = supplier.get();
return result instanceof Message ? (Message) result : messageFactory.newMessage(result);
}
+
+ /**
+ * If the specified object is a {@code Supplier} then returns the result of calling its {@link Supplier#get()}
+ * method, otherwise returns the specified object itself.
+ *
+ * @param maybe the object to evaluate if it is a lambda, or return as is if it is not
+ * @return the result of evaluating the specified lambda, or the specified object itself it not a lambda
+ */
+ public static Object maybeLambda(final Object maybe) {
+ return maybe instanceof Supplier<?> ? ((Supplier<?>) maybe).get() : maybe;
+ }
}