blob: cdef97e84f62933800950ffa7c76982d2f35dcb3 [file] [log] [blame]
Eugene Suslacf00ade2017-04-10 11:51:58 -07001/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.internal.util;
18
19import java.util.function.Supplier;
20
21/**
22 * Utilities specific to functional programming
23 */
24public class FunctionalUtils {
25 private FunctionalUtils() {}
26
27 /**
28 * An equivalent of {@link Runnable} that allows throwing checked exceptions
29 *
30 * This can be used to specify a lambda argument without forcing all the checked exceptions
31 * to be handled within it
32 */
33 @FunctionalInterface
34 public interface ThrowingRunnable {
35 void run() throws Exception;
36 }
37
38 /**
39 * An equivalent of {@link Supplier} that allows throwing checked exceptions
40 *
41 * This can be used to specify a lambda argument without forcing all the checked exceptions
42 * to be handled within it
43 */
44 @FunctionalInterface
45 public interface ThrowingSupplier<T> {
46 T get() throws Exception;
47 }
Eugene Susla612311e2017-07-06 11:12:52 -070048
49 /**
50 * An equivalent of {@link java.util.function.Consumer} that allows throwing checked exceptions
51 *
52 * This can be used to specify a lambda argument without forcing all the checked exceptions
53 * to be handled within it
54 */
55 @FunctionalInterface
56 public interface ThrowingConsumer<T> {
57 void accept(T t) throws Exception;
58 }
Eugene Suslacf00ade2017-04-10 11:51:58 -070059}