src/share/classes/java/util/function/Block.java
Print this page
rev 6273 : 8004561: Additional functional interfaces, extension methods and name changes
Summary: Adds additional functional interfaces for primitives and "Bi" (two operand). Adds utility extension methods. Includes some name changes for existing functional interfaces per EG decisions.
Reviewed-by: briangoetz
@@ -22,13 +22,15 @@
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.util.function;
+import java.util.Objects;
+
/**
- * An operation upon an input object. The operation may modify that object or
- * external state (other objects).
+ * An operation upon an input object. Unlike most other functional interfaces,
+ * {@code Block} is expected to operate via side-effects.
*
* @param <T> The type of input objects to {@code accept}
*
* @since 1.8
*/
@@ -39,6 +41,20 @@
* external state (other objects).
*
* @param t the input object
*/
public void accept(T t);
+
+ /**
+ * Returns a Block which performs in sequence the {@code apply} methods of
+ * multiple Blocks. This Block's {@code apply} method is performed followed
+ * by the {@code apply} method of the specified Block operation.
+ *
+ * @param other an additional Block which will be chained after this Block
+ * @return a Block which performs in sequence the {@code apply} method of
+ * this Block and the {@code apply} method of the specified Block operation
+ */
+ public default Block<T> chain(Block<? super T> other) {
+ Objects.requireNonNull(other);
+ return (T t) -> { accept(t); other.accept(t); };
+ }
}