jdk/src/share/classes/java/util/function/DoubleUnaryOperator.java
changeset 17695 032254f2467b
parent 16011 890a7ed97f6c
child 19040 7b25fde2a4ed
--- a/jdk/src/share/classes/java/util/function/DoubleUnaryOperator.java	Wed May 15 10:25:59 2013 +0200
+++ b/jdk/src/share/classes/java/util/function/DoubleUnaryOperator.java	Fri May 17 10:36:04 2013 -0700
@@ -24,6 +24,8 @@
  */
 package java.util.function;
 
+import java.util.Objects;
+
 /**
  * An operation on a {@code double} operand yielding a {@code double}
  * result. This is the primitive type specialization of {@link UnaryOperator}
@@ -42,5 +44,46 @@
      * @param operand the operand value
      * @return the operation result value
      */
-    public double applyAsDouble(double operand);
+    double applyAsDouble(double operand);
+
+    /**
+     * Compose a new function which applies the provided function followed by
+     * this function.  If either function throws an exception, it is relayed
+     * to the caller.
+     *
+     * @param before An additional function to be applied before this function
+     * is applied
+     * @return A function which performs the provided function followed by this
+     * function
+     * @throws NullPointerException if before is null
+     */
+    default DoubleUnaryOperator compose(DoubleUnaryOperator before) {
+        Objects.requireNonNull(before);
+        return (double v) -> applyAsDouble(before.applyAsDouble(v));
+    }
+
+    /**
+     * Compose a new function which applies this function followed by the
+     * provided function.  If either function throws an exception, it is relayed
+     * to the caller.
+     *
+     * @param after An additional function to be applied after this function is
+     * applied
+     * @return A function which performs this function followed by the provided
+     * function followed
+     * @throws NullPointerException if after is null
+     */
+    default DoubleUnaryOperator andThen(DoubleUnaryOperator after) {
+        Objects.requireNonNull(after);
+        return (double t) -> after.applyAsDouble(applyAsDouble(t));
+    }
+
+    /**
+     * Returns a unary operator that provides its input value as the result.
+     *
+     * @return a unary operator that provides its input value as the result
+     */
+    static DoubleUnaryOperator identity() {
+        return t -> t;
+    }
 }