1/* 2 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24/** 25 * Performs operations upon an input object which may modify that object and/or 26 * external state (other objects). 27 * 28 * <p>All block implementations are expected to: 29 * <ul> 30 * <li>When used for aggregate operations upon many elements blocks 31 * should not assume that the {@code apply} operation will be called upon 32 * elements in any specific order.</li> 33 * </ul> 34 * 35 * @param <T> The type of input objects to {@code apply}. 36 */ 37public interface TBlock<T> { 38 39 /** 40 * Performs operations upon the provided object which may modify that object 41 * and/or external state. 42 * 43 * @param t an input object 44 */ 45 void apply(T t); 46 47 /** 48 * Returns a Block which performs in sequence the {@code apply} methods of 49 * multiple Blocks. This Block's {@code apply} method is performed followed 50 * by the {@code apply} method of the specified Block operation. 51 * 52 * @param other an additional Block which will be chained after this Block 53 * @return a Block which performs in sequence the {@code apply} method of 54 * this Block and the {@code apply} method of the specified Block operation 55 */ 56 public default TBlock<T> chain(TBlock<? super T> other) { 57 return (T t) -> { apply(t); other.apply(t); }; 58 } 59} 60