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.DecConsumer; 22 import com.android.internal.util.function.DecFunction; 23 import com.android.internal.util.function.HeptConsumer; 24 import com.android.internal.util.function.HeptFunction; 25 import com.android.internal.util.function.HexConsumer; 26 import com.android.internal.util.function.HexFunction; 27 import com.android.internal.util.function.NonaConsumer; 28 import com.android.internal.util.function.NonaFunction; 29 import com.android.internal.util.function.OctConsumer; 30 import com.android.internal.util.function.OctFunction; 31 import com.android.internal.util.function.QuadConsumer; 32 import com.android.internal.util.function.QuadFunction; 33 import com.android.internal.util.function.QuadPredicate; 34 import com.android.internal.util.function.QuintConsumer; 35 import com.android.internal.util.function.QuintFunction; 36 import com.android.internal.util.function.QuintPredicate; 37 import com.android.internal.util.function.TriConsumer; 38 import com.android.internal.util.function.TriFunction; 39 import com.android.internal.util.function.TriPredicate; 40 import com.android.internal.util.function.UndecConsumer; 41 import com.android.internal.util.function.UndecFunction; 42 43 import java.util.function.BiConsumer; 44 import java.util.function.BiFunction; 45 import java.util.function.BiPredicate; 46 import java.util.function.Function; 47 48 /** 49 * An interface implementing all supported function interfaces, delegating each to {@link #invoke} 50 * 51 * @hide 52 */ 53 abstract class OmniFunction<A, B, C, D, E, F, G, H, I, J, K, R> implements 54 BiFunction<A, B, R>, TriFunction<A, B, C, R>, 55 QuadFunction<A, B, C, D, R>, QuintFunction<A, B, C, D, E, R>, 56 HexFunction<A, B, C, D, E, F, R>, HeptFunction<A, B, C, D, E, F, G, R>, 57 OctFunction<A, B, C, D, E, F, G, H, R>, NonaFunction<A, B, C, D, E, F, G, H, I, R>, 58 DecFunction<A, B, C, D, E, F, G, H, I, J, R>, 59 UndecFunction<A, B, C, D, E, F, G, H, I, J, K, R>, 60 BiConsumer<A, B>, TriConsumer<A, B, C>, QuadConsumer<A, B, C, D>, 61 QuintConsumer<A, B, C, D, E>, HexConsumer<A, B, C, D, E, F>, 62 HeptConsumer<A, B, C, D, E, F, G>, OctConsumer<A, B, C, D, E, F, G, H>, 63 NonaConsumer<A, B, C, D, E, F, G, H, I>, DecConsumer<A, B, C, D, E, F, G, H, I, J>, 64 UndecConsumer<A, B, C, D, E, F, G, H, I, J, K>, 65 PooledPredicate<A>, BiPredicate<A, B>, TriPredicate<A, B, C>, QuadPredicate<A, B, C, D>, 66 QuintPredicate<A, B, C, D, E>, PooledSupplier<R>, PooledRunnable, ThrowingRunnable, 67 ThrowingSupplier<R>, PooledSupplier.OfInt, PooledSupplier.OfLong, PooledSupplier.OfDouble { 68 invoke(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k)69 abstract R invoke(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k); 70 71 @Override apply(A o, B o2)72 public R apply(A o, B o2) { 73 return invoke(o, o2, null, null, null, null, null, null, null, null, null); 74 } 75 andThen( Function<? super R, ? extends V> after)76 public abstract <V> OmniFunction<A, B, C, D, E, F, G, H, I, J, K, V> andThen( 77 Function<? super R, ? extends V> after); negate()78 public abstract OmniFunction<A, B, C, D, E, F, G, H, I, J, K, R> negate(); 79 80 @Override accept(A o, B o2)81 public void accept(A o, B o2) { 82 invoke(o, o2, null, null, null, null, null, null, null, null, null); 83 } 84 85 @Override run()86 public void run() { 87 invoke(null, null, null, null, null, null, null, null, null, null, null); 88 } 89 90 @Override get()91 public R get() { 92 return invoke(null, null, null, null, null, null, null, null, null, null, null); 93 } 94 95 @Override test(A o, B o2, C o3, D o4, E o5)96 public boolean test(A o, B o2, C o3, D o4, E o5) { 97 return (Boolean) invoke(o, o2, o3, o4, o5, null, null, null, null, null, null); 98 } 99 100 @Override test(A o, B o2, C o3, D o4)101 public boolean test(A o, B o2, C o3, D o4) { 102 return (Boolean) invoke(o, o2, o3, o4, null, null, null, null, null, null, null); 103 } 104 105 @Override test(A o, B o2, C o3)106 public boolean test(A o, B o2, C o3) { 107 return (Boolean) invoke(o, o2, o3, null, null, null, null, null, null, null, null); 108 } 109 110 @Override test(A o, B o2)111 public boolean test(A o, B o2) { 112 return (Boolean) invoke(o, o2, null, null, null, null, null, null, null, null, null); 113 } 114 115 @Override test(A o)116 public boolean test(A o) { 117 return (Boolean) invoke(o, null, null, null, null, null, null, null, null, null, null); 118 } 119 120 @Override asRunnable()121 public PooledRunnable asRunnable() { 122 return this; 123 } 124 125 @Override apply(A a, B b, C c)126 public R apply(A a, B b, C c) { 127 return invoke(a, b, c, null, null, null, null, null, null, null, null); 128 } 129 130 @Override accept(A a, B b, C c)131 public void accept(A a, B b, C c) { 132 invoke(a, b, c, null, null, null, null, null, null, null, null); 133 } 134 135 @Override apply(A a, B b, C c, D d)136 public R apply(A a, B b, C c, D d) { 137 return invoke(a, b, c, d, null, null, null, null, null, null, null); 138 } 139 140 @Override apply(A a, B b, C c, D d, E e)141 public R apply(A a, B b, C c, D d, E e) { 142 return invoke(a, b, c, d, e, null, null, null, null, null, null); 143 } 144 145 @Override apply(A a, B b, C c, D d, E e, F f)146 public R apply(A a, B b, C c, D d, E e, F f) { 147 return invoke(a, b, c, d, e, f, null, null, null, null, null); 148 } 149 150 @Override apply(A a, B b, C c, D d, E e, F f, G g)151 public R apply(A a, B b, C c, D d, E e, F f, G g) { 152 return invoke(a, b, c, d, e, f, g, null, null, null, null); 153 } 154 155 @Override apply(A a, B b, C c, D d, E e, F f, G g, H h)156 public R apply(A a, B b, C c, D d, E e, F f, G g, H h) { 157 return invoke(a, b, c, d, e, f, g, h, null, null, null); 158 } 159 160 @Override apply(A a, B b, C c, D d, E e, F f, G g, H h, I i)161 public R apply(A a, B b, C c, D d, E e, F f, G g, H h, I i) { 162 return invoke(a, b, c, d, e, f, g, h, i, null, null); 163 } 164 165 @Override apply(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j)166 public R apply(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j) { 167 return invoke(a, b, c, d, e, f, g, h, i, j, null); 168 } 169 170 @Override apply(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k)171 public R apply(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k) { 172 return invoke(a, b, c, d, e, f, g, h, i, j, k); 173 } 174 175 @Override accept(A a, B b, C c, D d)176 public void accept(A a, B b, C c, D d) { 177 invoke(a, b, c, d, null, null, null, null, null, null, null); 178 } 179 180 @Override accept(A a, B b, C c, D d, E e)181 public void accept(A a, B b, C c, D d, E e) { 182 invoke(a, b, c, d, e, null, null, null, null, null, null); 183 } 184 185 @Override accept(A a, B b, C c, D d, E e, F f)186 public void accept(A a, B b, C c, D d, E e, F f) { 187 invoke(a, b, c, d, e, f, null, null, null, null, null); 188 } 189 190 @Override accept(A a, B b, C c, D d, E e, F f, G g)191 public void accept(A a, B b, C c, D d, E e, F f, G g) { 192 invoke(a, b, c, d, e, f, g, null, null, null, null); 193 } 194 195 @Override accept(A a, B b, C c, D d, E e, F f, G g, H h)196 public void accept(A a, B b, C c, D d, E e, F f, G g, H h) { 197 invoke(a, b, c, d, e, f, g, h, null, null, null); 198 } 199 200 @Override accept(A a, B b, C c, D d, E e, F f, G g, H h, I i)201 public void accept(A a, B b, C c, D d, E e, F f, G g, H h, I i) { 202 invoke(a, b, c, d, e, f, g, h, i, null, null); 203 } 204 205 @Override accept(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j)206 public void accept(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j) { 207 invoke(a, b, c, d, e, f, g, h, i, j, null); 208 } 209 210 @Override accept(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k)211 public void accept(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k) { 212 invoke(a, b, c, d, e, f, g, h, i, j, k); 213 } 214 215 @Override runOrThrow()216 public void runOrThrow() throws Exception { 217 run(); 218 } 219 220 @Override getOrThrow()221 public R getOrThrow() throws Exception { 222 return get(); 223 } 224 225 @Override recycleOnUse()226 public abstract OmniFunction<A, B, C, D, E, F, G, H, I, J, K, R> recycleOnUse(); 227 } 228