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