TBlock.java revision 3346:bcf9765e73b1
14Srgrimes/* 24Srgrimes * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. 34Srgrimes * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 44Srgrimes * 54Srgrimes * This code is free software; you can redistribute it and/or modify it 64Srgrimes * under the terms of the GNU General Public License version 2 only, as 74Srgrimes * published by the Free Software Foundation. 84Srgrimes * 94Srgrimes * This code is distributed in the hope that it will be useful, but WITHOUT 104Srgrimes * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 114Srgrimes * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 124Srgrimes * version 2 for more details (a copy is included in the LICENSE file that 134Srgrimes * accompanied this code). 144Srgrimes * 154Srgrimes * You should have received a copy of the GNU General Public License version 164Srgrimes * 2 along with this work; if not, write to the Free Software Foundation, 174Srgrimes * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 184Srgrimes * 194Srgrimes * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 204Srgrimes * or visit www.oracle.com if you need additional information or have any 214Srgrimes * questions. 224Srgrimes */ 234Srgrimes 244Srgrimes/** 254Srgrimes * Performs operations upon an input object which may modify that object and/or 264Srgrimes * external state (other objects). 274Srgrimes * 284Srgrimes * <p>All block implementations are expected to: 294Srgrimes * <ul> 304Srgrimes * <li>When used for aggregate operations upon many elements blocks 314Srgrimes * should not assume that the {@code apply} operation will be called upon 324Srgrimes * elements in any specific order.</li> 334Srgrimes * </ul> 344Srgrimes * 354Srgrimes * @param <T> The type of input objects to {@code apply}. 36556Srgrimes */ 371321Sdgpublic interface TBlock<T> { 384Srgrimes 394Srgrimes /** 404Srgrimes * Performs operations upon the provided object which may modify that object 41757Sdg * and/or external state. 42757Sdg * 43757Sdg * @param t an input object 44757Sdg */ 45757Sdg void apply(T t); 464Srgrimes 474Srgrimes /** 48757Sdg * Returns a Block which performs in sequence the {@code apply} methods of 49757Sdg * multiple Blocks. This Block's {@code apply} method is performed followed 50757Sdg * by the {@code apply} method of the specified Block operation. 51757Sdg * 52757Sdg * @param other an additional Block which will be chained after this Block 53757Sdg * @return a Block which performs in sequence the {@code apply} method of 54757Sdg * this Block and the {@code apply} method of the specified Block operation 55757Sdg */ 56757Sdg public default TBlock<T> chain(TBlock<? super T> other) { 574Srgrimes return (T t) -> { apply(t); other.apply(t); }; 584Srgrimes } 59757Sdg} 60757Sdg