aboutsummaryrefslogtreecommitdiff
path: root/api/src/main/java/io/opencensus/common/Functions.java
diff options
context:
space:
mode:
Diffstat (limited to 'api/src/main/java/io/opencensus/common/Functions.java')
-rw-r--r--api/src/main/java/io/opencensus/common/Functions.java18
1 files changed, 18 insertions, 0 deletions
diff --git a/api/src/main/java/io/opencensus/common/Functions.java b/api/src/main/java/io/opencensus/common/Functions.java
index eb5984af..ea3457ca 100644
--- a/api/src/main/java/io/opencensus/common/Functions.java
+++ b/api/src/main/java/io/opencensus/common/Functions.java
@@ -53,6 +53,14 @@ public final class Functions {
}
};
+ private static final Function<Object, /*@Nullable*/ String> RETURN_TO_STRING =
+ new Function<Object, /*@Nullable*/ String>() {
+ @Override
+ public /*@Nullable*/ String apply(Object input) {
+ return input == null ? null : input.toString();
+ }
+ };
+
/**
* A {@code Function} that always ignores its argument and returns {@code null}.
*
@@ -82,6 +90,16 @@ public final class Functions {
}
/**
+ * A {@code Function} that always returns the {@link #toString()} value of the input.
+ *
+ * @return a {@code Function} that always returns the {@link #toString()} value of the input.
+ * @since 0.17
+ */
+ public static Function<Object, /*@Nullable*/ String> returnToString() {
+ return RETURN_TO_STRING;
+ }
+
+ /**
* A {@code Function} that always ignores its argument and throws an {@link
* IllegalArgumentException}.
*