001// ***************************************************************************************************************************
002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.  See the NOTICE file *
003// * distributed with this work for additional information regarding copyright ownership.  The ASF licenses this file        *
004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance            *
005// * with the License.  You may obtain a copy of the License at                                                              *
006// *                                                                                                                         *
007// *  http://www.apache.org/licenses/LICENSE-2.0                                                                             *
008// *                                                                                                                         *
009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an  *
010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the        *
011// * specific language governing permissions and limitations under the License.                                              *
012// ***************************************************************************************************************************
013package org.apache.juneau.utils;
014
015import static org.apache.juneau.common.internal.ThrowableUtils.*;
016
017import java.util.function.*;
018
019/**
020 * A subclass of {@link Consumer} that allows for thrown exceptions.
021 *
022 * <h5 class='section'>See Also:</h5><ul>
023 * </ul>
024 *
025 * @param <T> the type of the input to the consumer.
026 */
027@FunctionalInterface
028public interface ThrowingConsumer<T> extends Consumer<T> {
029
030   @Override
031   default void accept(T t) {
032      try {
033         acceptThrows(t);
034      } catch (Exception e) {
035         throw asRuntimeException(e);
036      }
037   }
038
039   /**
040    * The functional method to implement.
041    *
042    * @param t The type of the input to the consumer.
043    * @throws Exception Any exception.
044    */
045   void acceptThrows(T t) throws Exception;
046}