1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * https://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 package org.apache.commons.lang3.function; 19 20 import java.util.Objects; 21 import java.util.function.IntConsumer; 22 23 /** 24 * A functional interface like {@link IntConsumer} but for {@code byte}. 25 * 26 * @see IntConsumer 27 * @since 3.19.0 28 */ 29 @FunctionalInterface 30 public interface ByteConsumer { 31 32 /** NOP singleton */ 33 ByteConsumer NOP = t -> { 34 /* NOP */ }; 35 36 /** 37 * Gets the NOP singleton. 38 * 39 * @return The NOP singleton. 40 */ 41 static ByteConsumer nop() { 42 return NOP; 43 } 44 45 /** 46 * Accepts the given arguments. 47 * 48 * @param value the input argument 49 */ 50 void accept(byte value); 51 52 /** 53 * Returns a composed {@link ByteConsumer} that performs, in sequence, this operation followed by the {@code after} operation. If performing either 54 * operation throws an exception, it is relayed to the caller of the composed operation. If performing this operation throws an exception, the {@code after} 55 * operation will not be performed. 56 * 57 * @param after the operation to perform after this operation 58 * @return a composed {@link ByteConsumer} that performs in sequence this operation followed by the {@code after} operation 59 * @throws NullPointerException if {@code after} is null 60 */ 61 default ByteConsumer andThen(final ByteConsumer after) { 62 Objects.requireNonNull(after); 63 return (final byte t) -> { 64 accept(t); 65 after.accept(t); 66 }; 67 } 68 }