FunctionalUtils.java revision cf00adebec29d4cdbec5bc0f004b26a09327c236
1/*
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    }
48}
49