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 17 package com.android.internal.util.function.pooled; 18 19 import com.android.internal.util.FunctionalUtils.ThrowingRunnable; 20 import com.android.internal.util.FunctionalUtils.ThrowingSupplier; 21 import com.android.internal.util.function.HexConsumer; 22 import com.android.internal.util.function.HexFunction; 23 import com.android.internal.util.function.QuadConsumer; 24 import com.android.internal.util.function.QuadFunction; 25 import com.android.internal.util.function.QuintConsumer; 26 import com.android.internal.util.function.QuintFunction; 27 import com.android.internal.util.function.TriConsumer; 28 import com.android.internal.util.function.TriFunction; 29 30 import java.util.function.BiConsumer; 31 import java.util.function.BiFunction; 32 import java.util.function.BiPredicate; 33 import java.util.function.Function; 34 35 /** 36 * An interface implementing all supported function interfaces, delegating each to {@link #invoke} 37 * 38 * @hide 39 */ 40 abstract class OmniFunction<A, B, C, D, E, F, R> implements 41 PooledFunction<A, R>, BiFunction<A, B, R>, TriFunction<A, B, C, R>, 42 QuadFunction<A, B, C, D, R>, QuintFunction<A, B, C, D, E, R>, 43 HexFunction<A, B, C, D, E, F, R>, PooledConsumer<A>, BiConsumer<A, B>, 44 TriConsumer<A, B, C>, QuadConsumer<A, B, C, D>, QuintConsumer<A, B, C, D, E>, 45 HexConsumer<A, B, C, D, E, F>, PooledPredicate<A>, BiPredicate<A, B>, 46 PooledSupplier<R>, PooledRunnable, ThrowingRunnable, ThrowingSupplier<R>, 47 PooledSupplier.OfInt, PooledSupplier.OfLong, PooledSupplier.OfDouble { 48 invoke(A a, B b, C c, D d, E e, F f)49 abstract R invoke(A a, B b, C c, D d, E e, F f); 50 51 @Override apply(A o, B o2)52 public R apply(A o, B o2) { 53 return invoke(o, o2, null, null, null, null); 54 } 55 56 @Override apply(A o)57 public R apply(A o) { 58 return invoke(o, null, null, null, null, null); 59 } 60 andThen( Function<? super R, ? extends V> after)61 abstract public <V> OmniFunction<A, B, C, D, E, F, V> andThen( 62 Function<? super R, ? extends V> after); negate()63 abstract public OmniFunction<A, B, C, D, E, F, R> negate(); 64 65 @Override accept(A o, B o2)66 public void accept(A o, B o2) { 67 invoke(o, o2, null, null, null, null); 68 } 69 70 @Override accept(A o)71 public void accept(A o) { 72 invoke(o, null, null, null, null, null); 73 } 74 75 @Override run()76 public void run() { 77 invoke(null, null, null, null, null, null); 78 } 79 80 @Override get()81 public R get() { 82 return invoke(null, null, null, null, null, null); 83 } 84 85 @Override test(A o, B o2)86 public boolean test(A o, B o2) { 87 return (Boolean) invoke(o, o2, null, null, null, null); 88 } 89 90 @Override test(A o)91 public boolean test(A o) { 92 return (Boolean) invoke(o, null, null, null, null, null); 93 } 94 95 @Override asRunnable()96 public PooledRunnable asRunnable() { 97 return this; 98 } 99 100 @Override asConsumer()101 public PooledConsumer<A> asConsumer() { 102 return this; 103 } 104 105 @Override apply(A a, B b, C c)106 public R apply(A a, B b, C c) { 107 return invoke(a, b, c, null, null, null); 108 } 109 110 @Override accept(A a, B b, C c)111 public void accept(A a, B b, C c) { 112 invoke(a, b, c, null, null, null); 113 } 114 115 @Override apply(A a, B b, C c, D d)116 public R apply(A a, B b, C c, D d) { 117 return invoke(a, b, c, d, null, null); 118 } 119 120 @Override apply(A a, B b, C c, D d, E e)121 public R apply(A a, B b, C c, D d, E e) { 122 return invoke(a, b, c, d, e, null); 123 } 124 125 @Override apply(A a, B b, C c, D d, E e, F f)126 public R apply(A a, B b, C c, D d, E e, F f) { 127 return invoke(a, b, c, d, e, f); 128 } 129 130 @Override accept(A a, B b, C c, D d)131 public void accept(A a, B b, C c, D d) { 132 invoke(a, b, c, d, null, null); 133 } 134 135 @Override accept(A a, B b, C c, D d, E e)136 public void accept(A a, B b, C c, D d, E e) { 137 invoke(a, b, c, d, e, null); 138 } 139 140 @Override accept(A a, B b, C c, D d, E e, F f)141 public void accept(A a, B b, C c, D d, E e, F f) { 142 invoke(a, b, c, d, e, f); 143 } 144 145 @Override runOrThrow()146 public void runOrThrow() throws Exception { 147 run(); 148 } 149 150 @Override getOrThrow()151 public R getOrThrow() throws Exception { 152 return get(); 153 } 154 155 @Override recycleOnUse()156 abstract public OmniFunction<A, B, C, D, E, F, R> recycleOnUse(); 157 } 158