Source code
Description: source: package: org.apache.commons.lang3.function, interface: ByteConsumer

    001/*
    002 * Licensed to the Apache Software Foundation (ASF) under one or more
    003 * contributor license agreements.  See the NOTICE file distributed with
    004 * this work for additional information regarding copyright ownership.
    005 * The ASF licenses this file to You under the Apache License, Version 2.0
    006 * (the "License"); you may not use this file except in compliance with
    007 * the License.  You may obtain a copy of the License at
    008 *
    009 *      https://www.apache.org/licenses/LICENSE-2.0
    010 *
    011 * Unless required by applicable law or agreed to in writing, software
    012 * distributed under the License is distributed on an "AS IS" BASIS,
    013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    014 * See the License for the specific language governing permissions and
    015 * limitations under the License.
    016 */
    017
    018package org.apache.commons.lang3.function;
    019
    020import java.util.Objects;
    021import java.util.function.IntConsumer;
    022
    023/**
    024 * A functional interface like {@link IntConsumer} but for {@code byte}.
    025 *
    026 * @see IntConsumer
    027 * @since 3.19.0
    028 */
    029@FunctionalInterface
    030public interface ByteConsumer {
    031
    032    /** NOP singleton */
    033    ByteConsumer NOP = t -> {
    034        /* NOP */ };
    035
    036    /**
    037     * Gets the NOP singleton.
    038     *
    039     * @return The NOP singleton.
    040     */
    041    static ByteConsumer nop() {
    042        return NOP;
    043    }
    044
    045    /**
    046     * Accepts the given arguments.
    047     *
    048     * @param value the input argument
    049     */
    050    void accept(byte value);
    051
    052    /**
    053     * Returns a composed {@link ByteConsumer} that performs, in sequence, this operation followed by the {@code after} operation. If performing either
    054     * operation throws an exception, it is relayed to the caller of the composed operation. If performing this operation throws an exception, the {@code after}
    055     * operation will not be performed.
    056     *
    057     * @param after the operation to perform after this operation
    058     * @return a composed {@link ByteConsumer} that performs in sequence this operation followed by the {@code after} operation
    059     * @throws NullPointerException if {@code after} is null
    060     */
    061    default ByteConsumer andThen(final ByteConsumer after) {
    062        Objects.requireNonNull(after);
    063        return (final byte t) -> {
    064            accept(t);
    065            after.accept(t);
    066        };
    067    }
    068}