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 static com.android.internal.util.function.pooled.PooledLambdaImpl.acquire; 20 import static com.android.internal.util.function.pooled.PooledLambdaImpl.acquireConstSupplier; 21 22 import android.os.Message; 23 24 import com.android.internal.util.function.HeptConsumer; 25 import com.android.internal.util.function.HeptFunction; 26 import com.android.internal.util.function.HexConsumer; 27 import com.android.internal.util.function.HexFunction; 28 import com.android.internal.util.function.NonaConsumer; 29 import com.android.internal.util.function.NonaFunction; 30 import com.android.internal.util.function.OctConsumer; 31 import com.android.internal.util.function.OctFunction; 32 import com.android.internal.util.function.QuadConsumer; 33 import com.android.internal.util.function.QuadFunction; 34 import com.android.internal.util.function.QuintConsumer; 35 import com.android.internal.util.function.QuintFunction; 36 import com.android.internal.util.function.TriConsumer; 37 import com.android.internal.util.function.TriFunction; 38 import com.android.internal.util.function.pooled.PooledLambdaImpl.LambdaType.ReturnType; 39 40 import java.util.function.BiConsumer; 41 import java.util.function.BiFunction; 42 import java.util.function.BiPredicate; 43 import java.util.function.Consumer; 44 import java.util.function.Function; 45 import java.util.function.Predicate; 46 import java.util.function.Supplier; 47 48 /** 49 * A recyclable anonymous function. 50 * Allows obtaining {@link Function}s/{@link Runnable}s/{@link Supplier}s/etc. without allocating a 51 * new instance each time 52 * 53 * This exploits the mechanic that stateless lambdas (such as plain/non-bound method references) 54 * get translated into a singleton instance, making it possible to create a recyclable container 55 * ({@link PooledLambdaImpl}) holding a reference to such a singleton function, as well as 56 * (possibly partial) arguments required for its invocation. 57 * 58 * To obtain an instance, use one of the factory methods in this class. 59 * 60 * You can call {@link #recycleOnUse} to make the instance automatically recycled upon invocation, 61 * making if effectively <b>one-time use</b>. 62 * This is often the behavior you want, as it allows to not worry about manual recycling. 63 * Some notable examples: {@link android.os.Handler#post(Runnable)}, 64 * {@link android.app.Activity#runOnUiThread(Runnable)}, {@link android.view.View#post(Runnable)} 65 * 66 * For factories of functions that take further arguments, the corresponding 'missing' argument's 67 * position is marked by an argument of type {@link ArgumentPlaceholder} with the type parameter 68 * corresponding to missing argument's type. 69 * You can fill the 'missing argument' spot with {@link #__()} 70 * (which is the factory function for {@link ArgumentPlaceholder}) 71 * 72 * NOTE: It is highly recommended to <b>only</b> use {@code ClassName::methodName} 73 * (aka unbounded method references) as the 1st argument for any of the 74 * factories ({@code obtain*(...)}) to avoid unwanted allocations. 75 * This means <b>not</b> using: 76 * <ul> 77 * <li>{@code someVar::methodName} or {@code this::methodName} as it captures the reference 78 * on the left of {@code ::}, resulting in an allocation on each evaluation of such 79 * bounded method references</li> 80 * 81 * <li>A lambda expression, e.g. {@code () -> toString()} due to how easy it is to accidentally 82 * capture state from outside. In the above lambda expression for example, no variable from 83 * outer scope is explicitly mentioned, yet one is still captured due to {@code toString()} 84 * being an equivalent of {@code this.toString()}</li> 85 * </ul> 86 * 87 * @hide 88 */ 89 @SuppressWarnings({"unchecked", "unused", "WeakerAccess"}) 90 public interface PooledLambda { 91 92 /** 93 * Recycles this instance. No-op if already recycled. 94 */ recycle()95 void recycle(); 96 97 /** 98 * Makes this instance automatically {@link #recycle} itself after the first call. 99 * 100 * @return this instance for convenience 101 */ recycleOnUse()102 PooledLambda recycleOnUse(); 103 104 105 // Factories 106 107 /** 108 * @return {@link ArgumentPlaceholder} with the inferred type parameter value 109 */ __()110 static <R> ArgumentPlaceholder<R> __() { 111 return (ArgumentPlaceholder<R>) ArgumentPlaceholder.INSTANCE; 112 } 113 114 /** 115 * @param typeHint the explicitly specified type of the missing argument 116 * @return {@link ArgumentPlaceholder} with the specified type parameter value 117 */ __(Class<R> typeHint)118 static <R> ArgumentPlaceholder<R> __(Class<R> typeHint) { 119 return __(); 120 } 121 122 /** 123 * Wraps the given value into a {@link PooledSupplier} 124 * 125 * @param value a value to wrap 126 * @return a pooled supplier of {@code value} 127 */ obtainSupplier(R value)128 static <R> PooledSupplier<R> obtainSupplier(R value) { 129 PooledLambdaImpl r = acquireConstSupplier(ReturnType.OBJECT); 130 r.mFunc = value; 131 return r; 132 } 133 134 /** 135 * Wraps the given value into a {@link PooledSupplier} 136 * 137 * @param value a value to wrap 138 * @return a pooled supplier of {@code value} 139 */ obtainSupplier(int value)140 static PooledSupplier.OfInt obtainSupplier(int value) { 141 PooledLambdaImpl r = acquireConstSupplier(ReturnType.INT); 142 r.mConstValue = value; 143 return r; 144 } 145 146 /** 147 * Wraps the given value into a {@link PooledSupplier} 148 * 149 * @param value a value to wrap 150 * @return a pooled supplier of {@code value} 151 */ obtainSupplier(long value)152 static PooledSupplier.OfLong obtainSupplier(long value) { 153 PooledLambdaImpl r = acquireConstSupplier(ReturnType.LONG); 154 r.mConstValue = value; 155 return r; 156 } 157 158 /** 159 * Wraps the given value into a {@link PooledSupplier} 160 * 161 * @param value a value to wrap 162 * @return a pooled supplier of {@code value} 163 */ obtainSupplier(double value)164 static PooledSupplier.OfDouble obtainSupplier(double value) { 165 PooledLambdaImpl r = acquireConstSupplier(ReturnType.DOUBLE); 166 r.mConstValue = Double.doubleToRawLongBits(value); 167 return r; 168 } 169 170 /** 171 * {@link PooledRunnable} factory 172 * 173 * @param function non-capturing lambda(typically an unbounded method reference) 174 * to be invoked on call 175 * @param arg1 parameter supplied to {@code function} on call 176 * @return a {@link PooledRunnable}, equivalent to lambda: 177 * {@code () -> function(arg1) } 178 */ obtainRunnable( Consumer<? super A> function, A arg1)179 static <A> PooledRunnable obtainRunnable( 180 Consumer<? super A> function, 181 A arg1) { 182 return acquire(PooledLambdaImpl.sPool, 183 function, 1, 0, ReturnType.VOID, arg1, null, null, null, null, null, null, null, 184 null); 185 } 186 187 /** 188 * {@link PooledSupplier} factory 189 * 190 * @param function non-capturing lambda(typically an unbounded method reference) 191 * to be invoked on call 192 * @param arg1 parameter supplied to {@code function} on call 193 * @return a {@link PooledSupplier}, equivalent to lambda: 194 * {@code () -> function(arg1) } 195 */ obtainSupplier( Predicate<? super A> function, A arg1)196 static <A> PooledSupplier<Boolean> obtainSupplier( 197 Predicate<? super A> function, 198 A arg1) { 199 return acquire(PooledLambdaImpl.sPool, 200 function, 1, 0, ReturnType.BOOLEAN, arg1, null, null, null, null, null, null, null, 201 null); 202 } 203 204 /** 205 * {@link PooledSupplier} factory 206 * 207 * @param function non-capturing lambda(typically an unbounded method reference) 208 * to be invoked on call 209 * @param arg1 parameter supplied to {@code function} on call 210 * @return a {@link PooledSupplier}, equivalent to lambda: 211 * {@code () -> function(arg1) } 212 */ obtainSupplier( Function<? super A, ? extends R> function, A arg1)213 static <A, R> PooledSupplier<R> obtainSupplier( 214 Function<? super A, ? extends R> function, 215 A arg1) { 216 return acquire(PooledLambdaImpl.sPool, 217 function, 1, 0, ReturnType.OBJECT, arg1, null, null, null, null, null, null, null, 218 null); 219 } 220 221 /** 222 * Factory of {@link Message}s that contain an 223 * ({@link PooledLambda#recycleOnUse auto-recycling}) {@link PooledRunnable} as its 224 * {@link Message#getCallback internal callback}. 225 * 226 * The callback is equivalent to one obtainable via 227 * {@link #obtainRunnable(Consumer, Object)} 228 * 229 * Note that using this method with {@link android.os.Handler#handleMessage} 230 * is more efficient than the alternative of {@link android.os.Handler#post} 231 * with a {@link PooledRunnable} due to the lack of 2 separate synchronization points 232 * when obtaining {@link Message} and {@link PooledRunnable} from pools separately 233 * 234 * You may optionally set a {@link Message#what} for the message if you want to be 235 * able to cancel it via {@link android.os.Handler#removeMessages}, but otherwise 236 * there's no need to do so 237 * 238 * @param function non-capturing lambda(typically an unbounded method reference) 239 * to be invoked on call 240 * @param arg1 parameter supplied to {@code function} on call 241 * @return a {@link Message} invoking {@code function(arg1) } when handled 242 */ obtainMessage( Consumer<? super A> function, A arg1)243 static <A> Message obtainMessage( 244 Consumer<? super A> function, 245 A arg1) { 246 synchronized (Message.sPoolSync) { 247 PooledRunnable callback = acquire(PooledLambdaImpl.sMessageCallbacksPool, 248 function, 1, 0, ReturnType.VOID, arg1, null, null, null, null, null, null, null, 249 null); 250 return Message.obtain().setCallback(callback.recycleOnUse()); 251 } 252 } 253 254 /** 255 * {@link PooledRunnable} factory 256 * 257 * @param function non-capturing lambda(typically an unbounded method reference) 258 * to be invoked on call 259 * @param arg1 parameter supplied to {@code function} on call 260 * @param arg2 parameter supplied to {@code function} on call 261 * @return a {@link PooledRunnable}, equivalent to lambda: 262 * {@code () -> function(arg1, arg2) } 263 */ obtainRunnable( BiConsumer<? super A, ? super B> function, A arg1, B arg2)264 static <A, B> PooledRunnable obtainRunnable( 265 BiConsumer<? super A, ? super B> function, 266 A arg1, B arg2) { 267 return acquire(PooledLambdaImpl.sPool, 268 function, 2, 0, ReturnType.VOID, arg1, arg2, null, null, null, null, null, null, 269 null); 270 } 271 272 /** 273 * {@link PooledSupplier} factory 274 * 275 * @param function non-capturing lambda(typically an unbounded method reference) 276 * to be invoked on call 277 * @param arg1 parameter supplied to {@code function} on call 278 * @param arg2 parameter supplied to {@code function} on call 279 * @return a {@link PooledSupplier}, equivalent to lambda: 280 * {@code () -> function(arg1, arg2) } 281 */ obtainSupplier( BiPredicate<? super A, ? super B> function, A arg1, B arg2)282 static <A, B> PooledSupplier<Boolean> obtainSupplier( 283 BiPredicate<? super A, ? super B> function, 284 A arg1, B arg2) { 285 return acquire(PooledLambdaImpl.sPool, 286 function, 2, 0, ReturnType.BOOLEAN, arg1, arg2, null, null, null, null, null, null, 287 null); 288 } 289 290 /** 291 * {@link PooledSupplier} factory 292 * 293 * @param function non-capturing lambda(typically an unbounded method reference) 294 * to be invoked on call 295 * @param arg1 parameter supplied to {@code function} on call 296 * @param arg2 parameter supplied to {@code function} on call 297 * @return a {@link PooledSupplier}, equivalent to lambda: 298 * {@code () -> function(arg1, arg2) } 299 */ obtainSupplier( BiFunction<? super A, ? super B, ? extends R> function, A arg1, B arg2)300 static <A, B, R> PooledSupplier<R> obtainSupplier( 301 BiFunction<? super A, ? super B, ? extends R> function, 302 A arg1, B arg2) { 303 return acquire(PooledLambdaImpl.sPool, 304 function, 2, 0, ReturnType.OBJECT, arg1, arg2, null, null, null, null, null, null, 305 null); 306 } 307 308 /** 309 * {@link PooledConsumer} factory 310 * 311 * @param function non-capturing lambda(typically an unbounded method reference) 312 * to be invoked on call 313 * @param arg1 placeholder for a missing argument. Use {@link #__} to get one 314 * @param arg2 parameter supplied to {@code function} on call 315 * @return a {@link PooledConsumer}, equivalent to lambda: 316 * {@code (arg1) -> function(arg1, arg2) } 317 */ obtainConsumer( BiConsumer<? super A, ? super B> function, ArgumentPlaceholder<A> arg1, B arg2)318 static <A, B> PooledConsumer<A> obtainConsumer( 319 BiConsumer<? super A, ? super B> function, 320 ArgumentPlaceholder<A> arg1, B arg2) { 321 return acquire(PooledLambdaImpl.sPool, 322 function, 2, 1, ReturnType.VOID, arg1, arg2, null, null, null, null, null, null, 323 null); 324 } 325 326 /** 327 * {@link PooledPredicate} factory 328 * 329 * @param function non-capturing lambda(typically an unbounded method reference) 330 * to be invoked on call 331 * @param arg1 placeholder for a missing argument. Use {@link #__} to get one 332 * @param arg2 parameter supplied to {@code function} on call 333 * @return a {@link PooledPredicate}, equivalent to lambda: 334 * {@code (arg1) -> function(arg1, arg2) } 335 */ obtainPredicate( BiPredicate<? super A, ? super B> function, ArgumentPlaceholder<A> arg1, B arg2)336 static <A, B> PooledPredicate<A> obtainPredicate( 337 BiPredicate<? super A, ? super B> function, 338 ArgumentPlaceholder<A> arg1, B arg2) { 339 return acquire(PooledLambdaImpl.sPool, 340 function, 2, 1, ReturnType.BOOLEAN, arg1, arg2, null, null, null, null, null, null, 341 null); 342 } 343 344 /** 345 * {@link PooledFunction} factory 346 * 347 * @param function non-capturing lambda(typically an unbounded method reference) 348 * to be invoked on call 349 * @param arg1 placeholder for a missing argument. Use {@link #__} to get one 350 * @param arg2 parameter supplied to {@code function} on call 351 * @return a {@link PooledFunction}, equivalent to lambda: 352 * {@code (arg1) -> function(arg1, arg2) } 353 */ obtainFunction( BiFunction<? super A, ? super B, ? extends R> function, ArgumentPlaceholder<A> arg1, B arg2)354 static <A, B, R> PooledFunction<A, R> obtainFunction( 355 BiFunction<? super A, ? super B, ? extends R> function, 356 ArgumentPlaceholder<A> arg1, B arg2) { 357 return acquire(PooledLambdaImpl.sPool, 358 function, 2, 1, ReturnType.OBJECT, arg1, arg2, null, null, null, null, null, null, 359 null); 360 } 361 362 /** 363 * {@link PooledConsumer} factory 364 * 365 * @param function non-capturing lambda(typically an unbounded method reference) 366 * to be invoked on call 367 * @param arg1 parameter supplied to {@code function} on call 368 * @param arg2 placeholder for a missing argument. Use {@link #__} to get one 369 * @return a {@link PooledConsumer}, equivalent to lambda: 370 * {@code (arg2) -> function(arg1, arg2) } 371 */ obtainConsumer( BiConsumer<? super A, ? super B> function, A arg1, ArgumentPlaceholder<B> arg2)372 static <A, B> PooledConsumer<B> obtainConsumer( 373 BiConsumer<? super A, ? super B> function, 374 A arg1, ArgumentPlaceholder<B> arg2) { 375 return acquire(PooledLambdaImpl.sPool, 376 function, 2, 1, ReturnType.VOID, arg1, arg2, null, null, null, null, null, null, 377 null); 378 } 379 380 /** 381 * {@link PooledPredicate} factory 382 * 383 * @param function non-capturing lambda(typically an unbounded method reference) 384 * to be invoked on call 385 * @param arg1 parameter supplied to {@code function} on call 386 * @param arg2 placeholder for a missing argument. Use {@link #__} to get one 387 * @return a {@link PooledPredicate}, equivalent to lambda: 388 * {@code (arg2) -> function(arg1, arg2) } 389 */ obtainPredicate( BiPredicate<? super A, ? super B> function, A arg1, ArgumentPlaceholder<B> arg2)390 static <A, B> PooledPredicate<B> obtainPredicate( 391 BiPredicate<? super A, ? super B> function, 392 A arg1, ArgumentPlaceholder<B> arg2) { 393 return acquire(PooledLambdaImpl.sPool, 394 function, 2, 1, ReturnType.BOOLEAN, arg1, arg2, null, null, null, null, null, null, 395 null); 396 } 397 398 /** 399 * {@link PooledFunction} factory 400 * 401 * @param function non-capturing lambda(typically an unbounded method reference) 402 * to be invoked on call 403 * @param arg1 parameter supplied to {@code function} on call 404 * @param arg2 placeholder for a missing argument. Use {@link #__} to get one 405 * @return a {@link PooledFunction}, equivalent to lambda: 406 * {@code (arg2) -> function(arg1, arg2) } 407 */ obtainFunction( BiFunction<? super A, ? super B, ? extends R> function, A arg1, ArgumentPlaceholder<B> arg2)408 static <A, B, R> PooledFunction<B, R> obtainFunction( 409 BiFunction<? super A, ? super B, ? extends R> function, 410 A arg1, ArgumentPlaceholder<B> arg2) { 411 return acquire(PooledLambdaImpl.sPool, 412 function, 2, 1, ReturnType.OBJECT, arg1, arg2, null, null, null, null, null, null, 413 null); 414 } 415 416 /** 417 * Factory of {@link Message}s that contain an 418 * ({@link PooledLambda#recycleOnUse auto-recycling}) {@link PooledRunnable} as its 419 * {@link Message#getCallback internal callback}. 420 * 421 * The callback is equivalent to one obtainable via 422 * {@link #obtainRunnable(BiConsumer, Object, Object)} 423 * 424 * Note that using this method with {@link android.os.Handler#handleMessage} 425 * is more efficient than the alternative of {@link android.os.Handler#post} 426 * with a {@link PooledRunnable} due to the lack of 2 separate synchronization points 427 * when obtaining {@link Message} and {@link PooledRunnable} from pools separately 428 * 429 * You may optionally set a {@link Message#what} for the message if you want to be 430 * able to cancel it via {@link android.os.Handler#removeMessages}, but otherwise 431 * there's no need to do so 432 * 433 * @param function non-capturing lambda(typically an unbounded method reference) 434 * to be invoked on call 435 * @param arg1 parameter supplied to {@code function} on call 436 * @param arg2 parameter supplied to {@code function} on call 437 * @return a {@link Message} invoking {@code function(arg1, arg2) } when handled 438 */ obtainMessage( BiConsumer<? super A, ? super B> function, A arg1, B arg2)439 static <A, B> Message obtainMessage( 440 BiConsumer<? super A, ? super B> function, 441 A arg1, B arg2) { 442 synchronized (Message.sPoolSync) { 443 PooledRunnable callback = acquire(PooledLambdaImpl.sMessageCallbacksPool, 444 function, 2, 0, ReturnType.VOID, arg1, arg2, null, null, null, null, null, null, 445 null); 446 return Message.obtain().setCallback(callback.recycleOnUse()); 447 } 448 } 449 450 /** 451 * {@link PooledRunnable} factory 452 * 453 * @param function non-capturing lambda(typically an unbounded method reference) 454 * to be invoked on call 455 * @param arg1 parameter supplied to {@code function} on call 456 * @param arg2 parameter supplied to {@code function} on call 457 * @param arg3 parameter supplied to {@code function} on call 458 * @return a {@link PooledRunnable}, equivalent to lambda: 459 * {@code () -> function(arg1, arg2, arg3) } 460 */ obtainRunnable( TriConsumer<? super A, ? super B, ? super C> function, A arg1, B arg2, C arg3)461 static <A, B, C> PooledRunnable obtainRunnable( 462 TriConsumer<? super A, ? super B, ? super C> function, 463 A arg1, B arg2, C arg3) { 464 return acquire(PooledLambdaImpl.sPool, 465 function, 3, 0, ReturnType.VOID, arg1, arg2, arg3, null, null, null, null, null, 466 null); 467 } 468 469 /** 470 * {@link PooledSupplier} factory 471 * 472 * @param function non-capturing lambda(typically an unbounded method reference) 473 * to be invoked on call 474 * @param arg1 parameter supplied to {@code function} on call 475 * @param arg2 parameter supplied to {@code function} on call 476 * @param arg3 parameter supplied to {@code function} on call 477 * @return a {@link PooledSupplier}, equivalent to lambda: 478 * {@code () -> function(arg1, arg2, arg3) } 479 */ obtainSupplier( TriFunction<? super A, ? super B, ? super C, ? extends R> function, A arg1, B arg2, C arg3)480 static <A, B, C, R> PooledSupplier<R> obtainSupplier( 481 TriFunction<? super A, ? super B, ? super C, ? extends R> function, 482 A arg1, B arg2, C arg3) { 483 return acquire(PooledLambdaImpl.sPool, 484 function, 3, 0, ReturnType.OBJECT, arg1, arg2, arg3, null, null, null, null, null, 485 null); 486 } 487 488 /** 489 * {@link PooledConsumer} factory 490 * 491 * @param function non-capturing lambda(typically an unbounded method reference) 492 * to be invoked on call 493 * @param arg1 placeholder for a missing argument. Use {@link #__} to get one 494 * @param arg2 parameter supplied to {@code function} on call 495 * @param arg3 parameter supplied to {@code function} on call 496 * @return a {@link PooledConsumer}, equivalent to lambda: 497 * {@code (arg1) -> function(arg1, arg2, arg3) } 498 */ obtainConsumer( TriConsumer<? super A, ? super B, ? super C> function, ArgumentPlaceholder<A> arg1, B arg2, C arg3)499 static <A, B, C> PooledConsumer<A> obtainConsumer( 500 TriConsumer<? super A, ? super B, ? super C> function, 501 ArgumentPlaceholder<A> arg1, B arg2, C arg3) { 502 return acquire(PooledLambdaImpl.sPool, 503 function, 3, 1, ReturnType.VOID, arg1, arg2, arg3, null, null, null, null, null, 504 null); 505 } 506 507 /** 508 * {@link PooledFunction} factory 509 * 510 * @param function non-capturing lambda(typically an unbounded method reference) 511 * to be invoked on call 512 * @param arg1 placeholder for a missing argument. Use {@link #__} to get one 513 * @param arg2 parameter supplied to {@code function} on call 514 * @param arg3 parameter supplied to {@code function} on call 515 * @return a {@link PooledFunction}, equivalent to lambda: 516 * {@code (arg1) -> function(arg1, arg2, arg3) } 517 */ obtainFunction( TriFunction<? super A, ? super B, ? super C, ? extends R> function, ArgumentPlaceholder<A> arg1, B arg2, C arg3)518 static <A, B, C, R> PooledFunction<A, R> obtainFunction( 519 TriFunction<? super A, ? super B, ? super C, ? extends R> function, 520 ArgumentPlaceholder<A> arg1, B arg2, C arg3) { 521 return acquire(PooledLambdaImpl.sPool, 522 function, 3, 1, ReturnType.OBJECT, arg1, arg2, arg3, null, null, null, null, null, 523 null); 524 } 525 526 /** 527 * {@link PooledConsumer} factory 528 * 529 * @param function non-capturing lambda(typically an unbounded method reference) 530 * to be invoked on call 531 * @param arg1 parameter supplied to {@code function} on call 532 * @param arg2 placeholder for a missing argument. Use {@link #__} to get one 533 * @param arg3 parameter supplied to {@code function} on call 534 * @return a {@link PooledConsumer}, equivalent to lambda: 535 * {@code (arg2) -> function(arg1, arg2, arg3) } 536 */ obtainConsumer( TriConsumer<? super A, ? super B, ? super C> function, A arg1, ArgumentPlaceholder<B> arg2, C arg3)537 static <A, B, C> PooledConsumer<B> obtainConsumer( 538 TriConsumer<? super A, ? super B, ? super C> function, 539 A arg1, ArgumentPlaceholder<B> arg2, C arg3) { 540 return acquire(PooledLambdaImpl.sPool, 541 function, 3, 1, ReturnType.VOID, arg1, arg2, arg3, null, null, null, null, null, 542 null); 543 } 544 545 /** 546 * {@link PooledFunction} factory 547 * 548 * @param function non-capturing lambda(typically an unbounded method reference) 549 * to be invoked on call 550 * @param arg1 parameter supplied to {@code function} on call 551 * @param arg2 placeholder for a missing argument. Use {@link #__} to get one 552 * @param arg3 parameter supplied to {@code function} on call 553 * @return a {@link PooledFunction}, equivalent to lambda: 554 * {@code (arg2) -> function(arg1, arg2, arg3) } 555 */ obtainFunction( TriFunction<? super A, ? super B, ? super C, ? extends R> function, A arg1, ArgumentPlaceholder<B> arg2, C arg3)556 static <A, B, C, R> PooledFunction<B, R> obtainFunction( 557 TriFunction<? super A, ? super B, ? super C, ? extends R> function, 558 A arg1, ArgumentPlaceholder<B> arg2, C arg3) { 559 return acquire(PooledLambdaImpl.sPool, 560 function, 3, 1, ReturnType.OBJECT, arg1, arg2, arg3, null, null, null, null, null, 561 null); 562 } 563 564 /** 565 * {@link PooledConsumer} factory 566 * 567 * @param function non-capturing lambda(typically an unbounded method reference) 568 * to be invoked on call 569 * @param arg1 parameter supplied to {@code function} on call 570 * @param arg2 parameter supplied to {@code function} on call 571 * @param arg3 placeholder for a missing argument. Use {@link #__} to get one 572 * @return a {@link PooledConsumer}, equivalent to lambda: 573 * {@code (arg3) -> function(arg1, arg2, arg3) } 574 */ obtainConsumer( TriConsumer<? super A, ? super B, ? super C> function, A arg1, B arg2, ArgumentPlaceholder<C> arg3)575 static <A, B, C> PooledConsumer<C> obtainConsumer( 576 TriConsumer<? super A, ? super B, ? super C> function, 577 A arg1, B arg2, ArgumentPlaceholder<C> arg3) { 578 return acquire(PooledLambdaImpl.sPool, 579 function, 3, 1, ReturnType.VOID, arg1, arg2, arg3, null, null, null, null, null, 580 null); 581 } 582 583 /** 584 * {@link PooledFunction} factory 585 * 586 * @param function non-capturing lambda(typically an unbounded method reference) 587 * to be invoked on call 588 * @param arg1 parameter supplied to {@code function} on call 589 * @param arg2 parameter supplied to {@code function} on call 590 * @param arg3 placeholder for a missing argument. Use {@link #__} to get one 591 * @return a {@link PooledFunction}, equivalent to lambda: 592 * {@code (arg3) -> function(arg1, arg2, arg3) } 593 */ obtainFunction( TriFunction<? super A, ? super B, ? super C, ? extends R> function, A arg1, B arg2, ArgumentPlaceholder<C> arg3)594 static <A, B, C, R> PooledFunction<C, R> obtainFunction( 595 TriFunction<? super A, ? super B, ? super C, ? extends R> function, 596 A arg1, B arg2, ArgumentPlaceholder<C> arg3) { 597 return acquire(PooledLambdaImpl.sPool, 598 function, 3, 1, ReturnType.OBJECT, arg1, arg2, arg3, null, null, null, null, null, 599 null); 600 } 601 602 /** 603 * Factory of {@link Message}s that contain an 604 * ({@link PooledLambda#recycleOnUse auto-recycling}) {@link PooledRunnable} as its 605 * {@link Message#getCallback internal callback}. 606 * 607 * The callback is equivalent to one obtainable via 608 * {@link #obtainRunnable(TriConsumer, Object, Object, Object)} 609 * 610 * Note that using this method with {@link android.os.Handler#handleMessage} 611 * is more efficient than the alternative of {@link android.os.Handler#post} 612 * with a {@link PooledRunnable} due to the lack of 2 separate synchronization points 613 * when obtaining {@link Message} and {@link PooledRunnable} from pools separately 614 * 615 * You may optionally set a {@link Message#what} for the message if you want to be 616 * able to cancel it via {@link android.os.Handler#removeMessages}, but otherwise 617 * there's no need to do so 618 * 619 * @param function non-capturing lambda(typically an unbounded method reference) 620 * to be invoked on call 621 * @param arg1 parameter supplied to {@code function} on call 622 * @param arg2 parameter supplied to {@code function} on call 623 * @param arg3 parameter supplied to {@code function} on call 624 * @return a {@link Message} invoking {@code function(arg1, arg2, arg3) } when handled 625 */ obtainMessage( TriConsumer<? super A, ? super B, ? super C> function, A arg1, B arg2, C arg3)626 static <A, B, C> Message obtainMessage( 627 TriConsumer<? super A, ? super B, ? super C> function, 628 A arg1, B arg2, C arg3) { 629 synchronized (Message.sPoolSync) { 630 PooledRunnable callback = acquire(PooledLambdaImpl.sMessageCallbacksPool, 631 function, 3, 0, ReturnType.VOID, arg1, arg2, arg3, null, null, null, null, null, 632 null); 633 return Message.obtain().setCallback(callback.recycleOnUse()); 634 } 635 } 636 637 /** 638 * {@link PooledRunnable} factory 639 * 640 * @param function non-capturing lambda(typically an unbounded method reference) 641 * to be invoked on call 642 * @param arg1 parameter supplied to {@code function} on call 643 * @param arg2 parameter supplied to {@code function} on call 644 * @param arg3 parameter supplied to {@code function} on call 645 * @param arg4 parameter supplied to {@code function} on call 646 * @return a {@link PooledRunnable}, equivalent to lambda: 647 * {@code () -> function(arg1, arg2, arg3, arg4) } 648 */ obtainRunnable( QuadConsumer<? super A, ? super B, ? super C, ? super D> function, A arg1, B arg2, C arg3, D arg4)649 static <A, B, C, D> PooledRunnable obtainRunnable( 650 QuadConsumer<? super A, ? super B, ? super C, ? super D> function, 651 A arg1, B arg2, C arg3, D arg4) { 652 return acquire(PooledLambdaImpl.sPool, 653 function, 4, 0, ReturnType.VOID, arg1, arg2, arg3, arg4, null, null, null, null, 654 null); 655 } 656 657 /** 658 * {@link PooledSupplier} factory 659 * 660 * @param function non-capturing lambda(typically an unbounded method reference) 661 * to be invoked on call 662 * @param arg1 parameter supplied to {@code function} on call 663 * @param arg2 parameter supplied to {@code function} on call 664 * @param arg3 parameter supplied to {@code function} on call 665 * @param arg4 parameter supplied to {@code function} on call 666 * @return a {@link PooledSupplier}, equivalent to lambda: 667 * {@code () -> function(arg1, arg2, arg3, arg4) } 668 */ obtainSupplier( QuadFunction<? super A, ? super B, ? super C, ? super D, ? extends R> function, A arg1, B arg2, C arg3, D arg4)669 static <A, B, C, D, R> PooledSupplier<R> obtainSupplier( 670 QuadFunction<? super A, ? super B, ? super C, ? super D, ? extends R> function, 671 A arg1, B arg2, C arg3, D arg4) { 672 return acquire(PooledLambdaImpl.sPool, 673 function, 4, 0, ReturnType.OBJECT, arg1, arg2, arg3, arg4, null, null, null, null, 674 null); 675 } 676 677 /** 678 * {@link PooledConsumer} factory 679 * 680 * @param function non-capturing lambda(typically an unbounded method reference) 681 * to be invoked on call 682 * @param arg1 placeholder for a missing argument. Use {@link #__} to get one 683 * @param arg2 parameter supplied to {@code function} on call 684 * @param arg3 parameter supplied to {@code function} on call 685 * @param arg4 parameter supplied to {@code function} on call 686 * @return a {@link PooledConsumer}, equivalent to lambda: 687 * {@code (arg1) -> function(arg1, arg2, arg3, arg4) } 688 */ obtainConsumer( QuadConsumer<? super A, ? super B, ? super C, ? super D> function, ArgumentPlaceholder<A> arg1, B arg2, C arg3, D arg4)689 static <A, B, C, D> PooledConsumer<A> obtainConsumer( 690 QuadConsumer<? super A, ? super B, ? super C, ? super D> function, 691 ArgumentPlaceholder<A> arg1, B arg2, C arg3, D arg4) { 692 return acquire(PooledLambdaImpl.sPool, 693 function, 4, 1, ReturnType.VOID, arg1, arg2, arg3, arg4, null, null, null, null, 694 null); 695 } 696 697 /** 698 * {@link PooledFunction} factory 699 * 700 * @param function non-capturing lambda(typically an unbounded method reference) 701 * to be invoked on call 702 * @param arg1 placeholder for a missing argument. Use {@link #__} to get one 703 * @param arg2 parameter supplied to {@code function} on call 704 * @param arg3 parameter supplied to {@code function} on call 705 * @param arg4 parameter supplied to {@code function} on call 706 * @return a {@link PooledFunction}, equivalent to lambda: 707 * {@code (arg1) -> function(arg1, arg2, arg3, arg4) } 708 */ obtainFunction( QuadFunction<? super A, ? super B, ? super C, ? super D, ? extends R> function, ArgumentPlaceholder<A> arg1, B arg2, C arg3, D arg4)709 static <A, B, C, D, R> PooledFunction<A, R> obtainFunction( 710 QuadFunction<? super A, ? super B, ? super C, ? super D, ? extends R> function, 711 ArgumentPlaceholder<A> arg1, B arg2, C arg3, D arg4) { 712 return acquire(PooledLambdaImpl.sPool, 713 function, 4, 1, ReturnType.OBJECT, arg1, arg2, arg3, arg4, null, null, null, null, 714 null); 715 } 716 717 /** 718 * {@link PooledConsumer} factory 719 * 720 * @param function non-capturing lambda(typically an unbounded method reference) 721 * to be invoked on call 722 * @param arg1 parameter supplied to {@code function} on call 723 * @param arg2 placeholder for a missing argument. Use {@link #__} to get one 724 * @param arg3 parameter supplied to {@code function} on call 725 * @param arg4 parameter supplied to {@code function} on call 726 * @return a {@link PooledConsumer}, equivalent to lambda: 727 * {@code (arg2) -> function(arg1, arg2, arg3, arg4) } 728 */ obtainConsumer( QuadConsumer<? super A, ? super B, ? super C, ? super D> function, A arg1, ArgumentPlaceholder<B> arg2, C arg3, D arg4)729 static <A, B, C, D> PooledConsumer<B> obtainConsumer( 730 QuadConsumer<? super A, ? super B, ? super C, ? super D> function, 731 A arg1, ArgumentPlaceholder<B> arg2, C arg3, D arg4) { 732 return acquire(PooledLambdaImpl.sPool, 733 function, 4, 1, ReturnType.VOID, arg1, arg2, arg3, arg4, null, null, null, null, 734 null); 735 } 736 737 /** 738 * {@link PooledFunction} factory 739 * 740 * @param function non-capturing lambda(typically an unbounded method reference) 741 * to be invoked on call 742 * @param arg1 parameter supplied to {@code function} on call 743 * @param arg2 placeholder for a missing argument. Use {@link #__} to get one 744 * @param arg3 parameter supplied to {@code function} on call 745 * @param arg4 parameter supplied to {@code function} on call 746 * @return a {@link PooledFunction}, equivalent to lambda: 747 * {@code (arg2) -> function(arg1, arg2, arg3, arg4) } 748 */ obtainFunction( QuadFunction<? super A, ? super B, ? super C, ? super D, ? extends R> function, A arg1, ArgumentPlaceholder<B> arg2, C arg3, D arg4)749 static <A, B, C, D, R> PooledFunction<B, R> obtainFunction( 750 QuadFunction<? super A, ? super B, ? super C, ? super D, ? extends R> function, 751 A arg1, ArgumentPlaceholder<B> arg2, C arg3, D arg4) { 752 return acquire(PooledLambdaImpl.sPool, 753 function, 4, 1, ReturnType.OBJECT, arg1, arg2, arg3, arg4, null, null, null, null, 754 null); 755 } 756 757 /** 758 * {@link PooledConsumer} factory 759 * 760 * @param function non-capturing lambda(typically an unbounded method reference) 761 * to be invoked on call 762 * @param arg1 parameter supplied to {@code function} on call 763 * @param arg2 parameter supplied to {@code function} on call 764 * @param arg3 placeholder for a missing argument. Use {@link #__} to get one 765 * @param arg4 parameter supplied to {@code function} on call 766 * @return a {@link PooledConsumer}, equivalent to lambda: 767 * {@code (arg3) -> function(arg1, arg2, arg3, arg4) } 768 */ obtainConsumer( QuadConsumer<? super A, ? super B, ? super C, ? super D> function, A arg1, B arg2, ArgumentPlaceholder<C> arg3, D arg4)769 static <A, B, C, D> PooledConsumer<C> obtainConsumer( 770 QuadConsumer<? super A, ? super B, ? super C, ? super D> function, 771 A arg1, B arg2, ArgumentPlaceholder<C> arg3, D arg4) { 772 return acquire(PooledLambdaImpl.sPool, 773 function, 4, 1, ReturnType.VOID, arg1, arg2, arg3, arg4, null, null, null, null, 774 null); 775 } 776 777 /** 778 * {@link PooledFunction} factory 779 * 780 * @param function non-capturing lambda(typically an unbounded method reference) 781 * to be invoked on call 782 * @param arg1 parameter supplied to {@code function} on call 783 * @param arg2 parameter supplied to {@code function} on call 784 * @param arg3 placeholder for a missing argument. Use {@link #__} to get one 785 * @param arg4 parameter supplied to {@code function} on call 786 * @return a {@link PooledFunction}, equivalent to lambda: 787 * {@code (arg3) -> function(arg1, arg2, arg3, arg4) } 788 */ obtainFunction( QuadFunction<? super A, ? super B, ? super C, ? super D, ? extends R> function, A arg1, B arg2, ArgumentPlaceholder<C> arg3, D arg4)789 static <A, B, C, D, R> PooledFunction<C, R> obtainFunction( 790 QuadFunction<? super A, ? super B, ? super C, ? super D, ? extends R> function, 791 A arg1, B arg2, ArgumentPlaceholder<C> arg3, D arg4) { 792 return acquire(PooledLambdaImpl.sPool, 793 function, 4, 1, ReturnType.OBJECT, arg1, arg2, arg3, arg4, null, null, null, null, 794 null); 795 } 796 797 /** 798 * {@link PooledConsumer} factory 799 * 800 * @param function non-capturing lambda(typically an unbounded method reference) 801 * to be invoked on call 802 * @param arg1 parameter supplied to {@code function} on call 803 * @param arg2 parameter supplied to {@code function} on call 804 * @param arg3 parameter supplied to {@code function} on call 805 * @param arg4 placeholder for a missing argument. Use {@link #__} to get one 806 * @return a {@link PooledConsumer}, equivalent to lambda: 807 * {@code (arg4) -> function(arg1, arg2, arg3, arg4) } 808 */ obtainConsumer( QuadConsumer<? super A, ? super B, ? super C, ? super D> function, A arg1, B arg2, C arg3, ArgumentPlaceholder<D> arg4)809 static <A, B, C, D> PooledConsumer<D> obtainConsumer( 810 QuadConsumer<? super A, ? super B, ? super C, ? super D> function, 811 A arg1, B arg2, C arg3, ArgumentPlaceholder<D> arg4) { 812 return acquire(PooledLambdaImpl.sPool, 813 function, 4, 1, ReturnType.VOID, arg1, arg2, arg3, arg4, null, null, null, null, 814 null); 815 } 816 817 /** 818 * {@link PooledFunction} factory 819 * 820 * @param function non-capturing lambda(typically an unbounded method reference) 821 * to be invoked on call 822 * @param arg1 parameter supplied to {@code function} on call 823 * @param arg2 parameter supplied to {@code function} on call 824 * @param arg3 parameter supplied to {@code function} on call 825 * @param arg4 placeholder for a missing argument. Use {@link #__} to get one 826 * @return a {@link PooledFunction}, equivalent to lambda: 827 * {@code (arg4) -> function(arg1, arg2, arg3, arg4) } 828 */ obtainFunction( QuadFunction<? super A, ? super B, ? super C, ? super D, ? extends R> function, A arg1, B arg2, C arg3, ArgumentPlaceholder<D> arg4)829 static <A, B, C, D, R> PooledFunction<D, R> obtainFunction( 830 QuadFunction<? super A, ? super B, ? super C, ? super D, ? extends R> function, 831 A arg1, B arg2, C arg3, ArgumentPlaceholder<D> arg4) { 832 return acquire(PooledLambdaImpl.sPool, 833 function, 4, 1, ReturnType.OBJECT, arg1, arg2, arg3, arg4, null, null, null, null, 834 null); 835 } 836 837 /** 838 * Factory of {@link Message}s that contain an 839 * ({@link PooledLambda#recycleOnUse auto-recycling}) {@link PooledRunnable} as its 840 * {@link Message#getCallback internal callback}. 841 * 842 * The callback is equivalent to one obtainable via 843 * {@link #obtainRunnable(QuadConsumer, Object, Object, Object, Object)} 844 * 845 * Note that using this method with {@link android.os.Handler#handleMessage} 846 * is more efficient than the alternative of {@link android.os.Handler#post} 847 * with a {@link PooledRunnable} due to the lack of 2 separate synchronization points 848 * when obtaining {@link Message} and {@link PooledRunnable} from pools separately 849 * 850 * You may optionally set a {@link Message#what} for the message if you want to be 851 * able to cancel it via {@link android.os.Handler#removeMessages}, but otherwise 852 * there's no need to do so 853 * 854 * @param function non-capturing lambda(typically an unbounded method reference) 855 * to be invoked on call 856 * @param arg1 parameter supplied to {@code function} on call 857 * @param arg2 parameter supplied to {@code function} on call 858 * @param arg3 parameter supplied to {@code function} on call 859 * @param arg4 parameter supplied to {@code function} on call 860 * @return a {@link Message} invoking {@code function(arg1, arg2, arg3, arg4) } when handled 861 */ obtainMessage( QuadConsumer<? super A, ? super B, ? super C, ? super D> function, A arg1, B arg2, C arg3, D arg4)862 static <A, B, C, D> Message obtainMessage( 863 QuadConsumer<? super A, ? super B, ? super C, ? super D> function, 864 A arg1, B arg2, C arg3, D arg4) { 865 synchronized (Message.sPoolSync) { 866 PooledRunnable callback = acquire(PooledLambdaImpl.sMessageCallbacksPool, 867 function, 4, 0, ReturnType.VOID, arg1, arg2, arg3, arg4, null, null, null, null, 868 null); 869 return Message.obtain().setCallback(callback.recycleOnUse()); 870 } 871 } 872 873 /** 874 * {@link PooledRunnable} factory 875 * 876 * @param function non-capturing lambda(typically an unbounded method reference) 877 * to be invoked on call 878 * @param arg1 parameter supplied to {@code function} on call 879 * @param arg2 parameter supplied to {@code function} on call 880 * @param arg3 parameter supplied to {@code function} on call 881 * @param arg4 parameter supplied to {@code function} on call 882 * @param arg5 parameter supplied to {@code function} on call 883 * @return a {@link PooledRunnable}, equivalent to lambda: 884 * {@code () -> function(arg1, arg2, arg3, arg4, arg5) } 885 */ obtainRunnable( QuintConsumer<? super A, ? super B, ? super C, ? super D, ? super E> function, A arg1, B arg2, C arg3, D arg4, E arg5)886 static <A, B, C, D, E> PooledRunnable obtainRunnable( 887 QuintConsumer<? super A, ? super B, ? super C, ? super D, ? super E> function, 888 A arg1, B arg2, C arg3, D arg4, E arg5) { 889 return acquire(PooledLambdaImpl.sPool, 890 function, 5, 0, ReturnType.VOID, arg1, arg2, arg3, arg4, arg5, null, null, null, 891 null); 892 } 893 894 /** 895 * {@link PooledSupplier} factory 896 * 897 * @param function non-capturing lambda(typically an unbounded method reference) 898 * to be invoked on call 899 * @param arg1 parameter supplied to {@code function} on call 900 * @param arg2 parameter supplied to {@code function} on call 901 * @param arg3 parameter supplied to {@code function} on call 902 * @param arg4 parameter supplied to {@code function} on call 903 * @param arg5 parameter supplied to {@code function} on call 904 * @return a {@link PooledSupplier}, equivalent to lambda: 905 * {@code () -> function(arg1, arg2, arg3, arg4, arg5) } 906 */ obtainSupplier( QuintFunction<? super A, ? super B, ? super C, ? super D, ? super E, ? extends R> function, A arg1, B arg2, C arg3, D arg4, E arg5)907 static <A, B, C, D, E, R> PooledSupplier<R> obtainSupplier( 908 QuintFunction<? super A, ? super B, ? super C, ? super D, ? super E, ? extends R> 909 function, A arg1, B arg2, C arg3, D arg4, E arg5) { 910 return acquire(PooledLambdaImpl.sPool, 911 function, 5, 0, ReturnType.OBJECT, arg1, arg2, arg3, arg4, arg5, null, null, null, 912 null); 913 } 914 915 /** 916 * Factory of {@link Message}s that contain an 917 * ({@link PooledLambda#recycleOnUse auto-recycling}) {@link PooledRunnable} as its 918 * {@link Message#getCallback internal callback}. 919 * 920 * The callback is equivalent to one obtainable via 921 * {@link #obtainRunnable(QuintConsumer, Object, Object, Object, Object, Object)} 922 * 923 * Note that using this method with {@link android.os.Handler#handleMessage} 924 * is more efficient than the alternative of {@link android.os.Handler#post} 925 * with a {@link PooledRunnable} due to the lack of 2 separate synchronization points 926 * when obtaining {@link Message} and {@link PooledRunnable} from pools separately 927 * 928 * You may optionally set a {@link Message#what} for the message if you want to be 929 * able to cancel it via {@link android.os.Handler#removeMessages}, but otherwise 930 * there's no need to do so 931 * 932 * @param function non-capturing lambda(typically an unbounded method reference) 933 * to be invoked on call 934 * @param arg1 parameter supplied to {@code function} on call 935 * @param arg2 parameter supplied to {@code function} on call 936 * @param arg3 parameter supplied to {@code function} on call 937 * @param arg4 parameter supplied to {@code function} on call 938 * @param arg5 parameter supplied to {@code function} on call 939 * @return a {@link Message} invoking {@code function(arg1, arg2, arg3, arg4, arg5) } when 940 * handled 941 */ obtainMessage( QuintConsumer<? super A, ? super B, ? super C, ? super D, ? super E> function, A arg1, B arg2, C arg3, D arg4, E arg5)942 static <A, B, C, D, E> Message obtainMessage( 943 QuintConsumer<? super A, ? super B, ? super C, ? super D, ? super E> function, 944 A arg1, B arg2, C arg3, D arg4, E arg5) { 945 synchronized (Message.sPoolSync) { 946 PooledRunnable callback = acquire(PooledLambdaImpl.sMessageCallbacksPool, 947 function, 5, 0, ReturnType.VOID, arg1, arg2, arg3, arg4, arg5, null, null, null, 948 null); 949 return Message.obtain().setCallback(callback.recycleOnUse()); 950 } 951 } 952 953 /** 954 * {@link PooledRunnable} factory 955 * 956 * @param function non-capturing lambda(typically an unbounded method reference) 957 * to be invoked on call 958 * @param arg1 parameter supplied to {@code function} on call 959 * @param arg2 parameter supplied to {@code function} on call 960 * @param arg3 parameter supplied to {@code function} on call 961 * @param arg4 parameter supplied to {@code function} on call 962 * @param arg5 parameter supplied to {@code function} on call 963 * @param arg6 parameter supplied to {@code function} on call 964 * @return a {@link PooledRunnable}, equivalent to lambda: 965 * {@code () -> function(arg1, arg2, arg3, arg4, arg5, arg6) } 966 */ obtainRunnable( HexConsumer<? super A, ? super B, ? super C, ? super D, ? super E, ? super F> function, A arg1, B arg2, C arg3, D arg4, E arg5, F arg6)967 static <A, B, C, D, E, F> PooledRunnable obtainRunnable( 968 HexConsumer<? super A, ? super B, ? super C, ? super D, ? super E, ? super F> function, 969 A arg1, B arg2, C arg3, D arg4, E arg5, F arg6) { 970 return acquire(PooledLambdaImpl.sPool, 971 function, 6, 0, ReturnType.VOID, arg1, arg2, arg3, arg4, arg5, arg6, null, null, 972 null); 973 } 974 975 /** 976 * {@link PooledSupplier} factory 977 * 978 * @param function non-capturing lambda(typically an unbounded method reference) 979 * to be invoked on call 980 * @param arg1 parameter supplied to {@code function} on call 981 * @param arg2 parameter supplied to {@code function} on call 982 * @param arg3 parameter supplied to {@code function} on call 983 * @param arg4 parameter supplied to {@code function} on call 984 * @param arg5 parameter supplied to {@code function} on call 985 * @param arg6 parameter supplied to {@code function} on call 986 * @return a {@link PooledSupplier}, equivalent to lambda: 987 * {@code () -> function(arg1, arg2, arg3, arg4, arg5, arg6) } 988 */ obtainSupplier( HexFunction<? super A, ? super B, ? super C, ? super D, ? super E, ? super F, ? extends R> function, A arg1, B arg2, C arg3, D arg4, E arg5, F arg6)989 static <A, B, C, D, E, F, R> PooledSupplier<R> obtainSupplier( 990 HexFunction<? super A, ? super B, ? super C, ? super D, ? super E, ? super F, 991 ? extends R> function, A arg1, B arg2, C arg3, D arg4, E arg5, F arg6) { 992 return acquire(PooledLambdaImpl.sPool, 993 function, 6, 0, ReturnType.OBJECT, arg1, arg2, arg3, arg4, arg5, arg6, null, null, 994 null); 995 } 996 997 /** 998 * Factory of {@link Message}s that contain an 999 * ({@link PooledLambda#recycleOnUse auto-recycling}) {@link PooledRunnable} as its 1000 * {@link Message#getCallback internal callback}. 1001 * 1002 * The callback is equivalent to one obtainable via 1003 * {@link #obtainRunnable(QuintConsumer, Object, Object, Object, Object, Object)} 1004 * 1005 * Note that using this method with {@link android.os.Handler#handleMessage} 1006 * is more efficient than the alternative of {@link android.os.Handler#post} 1007 * with a {@link PooledRunnable} due to the lack of 2 separate synchronization points 1008 * when obtaining {@link Message} and {@link PooledRunnable} from pools separately 1009 * 1010 * You may optionally set a {@link Message#what} for the message if you want to be 1011 * able to cancel it via {@link android.os.Handler#removeMessages}, but otherwise 1012 * there's no need to do so 1013 * 1014 * @param function non-capturing lambda(typically an unbounded method reference) 1015 * to be invoked on call 1016 * @param arg1 parameter supplied to {@code function} on call 1017 * @param arg2 parameter supplied to {@code function} on call 1018 * @param arg3 parameter supplied to {@code function} on call 1019 * @param arg4 parameter supplied to {@code function} on call 1020 * @param arg5 parameter supplied to {@code function} on call 1021 * @param arg6 parameter supplied to {@code function} on call 1022 * @return a {@link Message} invoking {@code function(arg1, arg2, arg3, arg4, arg5, arg6) } 1023 * when handled 1024 */ obtainMessage( HexConsumer<? super A, ? super B, ? super C, ? super D, ? super E, ? super F> function, A arg1, B arg2, C arg3, D arg4, E arg5, F arg6)1025 static <A, B, C, D, E, F> Message obtainMessage( 1026 HexConsumer<? super A, ? super B, ? super C, ? super D, ? super E, ? super F> function, 1027 A arg1, B arg2, C arg3, D arg4, E arg5, F arg6) { 1028 synchronized (Message.sPoolSync) { 1029 PooledRunnable callback = acquire(PooledLambdaImpl.sMessageCallbacksPool, 1030 function, 6, 0, ReturnType.VOID, arg1, arg2, arg3, arg4, arg5, arg6, null, null, 1031 null); 1032 return Message.obtain().setCallback(callback.recycleOnUse()); 1033 } 1034 } 1035 1036 /** 1037 * {@link PooledRunnable} factory 1038 * 1039 * @param function non-capturing lambda(typically an unbounded method reference) 1040 * to be invoked on call 1041 * @param arg1 parameter supplied to {@code function} on call 1042 * @param arg2 parameter supplied to {@code function} on call 1043 * @param arg3 parameter supplied to {@code function} on call 1044 * @param arg4 parameter supplied to {@code function} on call 1045 * @param arg5 parameter supplied to {@code function} on call 1046 * @param arg6 parameter supplied to {@code function} on call 1047 * @param arg7 parameter supplied to {@code function} on call 1048 * @return a {@link PooledRunnable}, equivalent to lambda: 1049 * {@code () -> function(arg1, arg2, arg3, arg4, arg5, arg6, arg7) } 1050 */ obtainRunnable( HeptConsumer<? super A, ? super B, ? super C, ? super D, ? super E, ? super F, ? super G> function, A arg1, B arg2, C arg3, D arg4, E arg5, F arg6, G arg7)1051 static <A, B, C, D, E, F, G> PooledRunnable obtainRunnable( 1052 HeptConsumer<? super A, ? super B, ? super C, ? super D, ? super E, ? super F, 1053 ? super G> function, A arg1, B arg2, C arg3, D arg4, E arg5, F arg6, G arg7) { 1054 return acquire(PooledLambdaImpl.sPool, 1055 function, 7, 0, ReturnType.VOID, arg1, arg2, arg3, arg4, arg5, arg6, arg7, null, 1056 null); 1057 } 1058 1059 /** 1060 * {@link PooledSupplier} factory 1061 * 1062 * @param function non-capturing lambda(typically an unbounded method reference) 1063 * to be invoked on call 1064 * @param arg1 parameter supplied to {@code function} on call 1065 * @param arg2 parameter supplied to {@code function} on call 1066 * @param arg3 parameter supplied to {@code function} on call 1067 * @param arg4 parameter supplied to {@code function} on call 1068 * @param arg5 parameter supplied to {@code function} on call 1069 * @param arg6 parameter supplied to {@code function} on call 1070 * @param arg7 parameter supplied to {@code function} on call 1071 * @return a {@link PooledSupplier}, equivalent to lambda: 1072 * {@code () -> function(arg1, arg2, arg3, arg4, arg5, arg6, arg7) } 1073 */ obtainSupplier( HeptFunction<? super A, ? super B, ? super C, ? super D, ? super E, ? super F, ? super G, ? extends R> function, A arg1, B arg2, C arg3, D arg4, E arg5, F arg6, G arg7)1074 static <A, B, C, D, E, F, G, R> PooledSupplier<R> obtainSupplier( 1075 HeptFunction<? super A, ? super B, ? super C, ? super D, ? super E, ? super F, 1076 ? super G, ? extends R> function, 1077 A arg1, B arg2, C arg3, D arg4, E arg5, F arg6, G arg7) { 1078 return acquire(PooledLambdaImpl.sPool, 1079 function, 7, 0, ReturnType.OBJECT, arg1, arg2, arg3, arg4, arg5, arg6, arg7, null, 1080 null); 1081 } 1082 1083 /** 1084 * Factory of {@link Message}s that contain an 1085 * ({@link PooledLambda#recycleOnUse auto-recycling}) {@link PooledRunnable} as its 1086 * {@link Message#getCallback internal callback}. 1087 * 1088 * The callback is equivalent to one obtainable via 1089 * {@link #obtainRunnable(QuintConsumer, Object, Object, Object, Object, Object)} 1090 * 1091 * Note that using this method with {@link android.os.Handler#handleMessage} 1092 * is more efficient than the alternative of {@link android.os.Handler#post} 1093 * with a {@link PooledRunnable} due to the lack of 2 separate synchronization points 1094 * when obtaining {@link Message} and {@link PooledRunnable} from pools separately 1095 * 1096 * You may optionally set a {@link Message#what} for the message if you want to be 1097 * able to cancel it via {@link android.os.Handler#removeMessages}, but otherwise 1098 * there's no need to do so 1099 * 1100 * @param function non-capturing lambda(typically an unbounded method reference) 1101 * to be invoked on call 1102 * @param arg1 parameter supplied to {@code function} on call 1103 * @param arg2 parameter supplied to {@code function} on call 1104 * @param arg3 parameter supplied to {@code function} on call 1105 * @param arg4 parameter supplied to {@code function} on call 1106 * @param arg5 parameter supplied to {@code function} on call 1107 * @param arg6 parameter supplied to {@code function} on call 1108 * @param arg7 parameter supplied to {@code function} on call 1109 * @return a {@link Message} invoking {@code function(arg1, arg2, arg3, arg4, arg5, arg6, 1110 * arg7) } when handled 1111 */ obtainMessage( HeptConsumer<? super A, ? super B, ? super C, ? super D, ? super E, ? super F, ? super G> function, A arg1, B arg2, C arg3, D arg4, E arg5, F arg6, G arg7)1112 static <A, B, C, D, E, F, G> Message obtainMessage( 1113 HeptConsumer<? super A, ? super B, ? super C, ? super D, ? super E, ? super F, 1114 ? super G> function, A arg1, B arg2, C arg3, D arg4, E arg5, F arg6, G arg7) { 1115 synchronized (Message.sPoolSync) { 1116 PooledRunnable callback = acquire(PooledLambdaImpl.sMessageCallbacksPool, 1117 function, 7, 0, ReturnType.VOID, arg1, arg2, arg3, arg4, arg5, arg6, arg7, null, 1118 null); 1119 return Message.obtain().setCallback(callback.recycleOnUse()); 1120 } 1121 } 1122 1123 /** 1124 * {@link PooledRunnable} factory 1125 * 1126 * @param function non-capturing lambda(typically an unbounded method reference) 1127 * to be invoked on call 1128 * @param arg1 parameter supplied to {@code function} on call 1129 * @param arg2 parameter supplied to {@code function} on call 1130 * @param arg3 parameter supplied to {@code function} on call 1131 * @param arg4 parameter supplied to {@code function} on call 1132 * @param arg5 parameter supplied to {@code function} on call 1133 * @param arg6 parameter supplied to {@code function} on call 1134 * @param arg7 parameter supplied to {@code function} on call 1135 * @param arg8 parameter supplied to {@code function} on call 1136 * @return a {@link PooledRunnable}, equivalent to lambda: 1137 * {@code () -> function(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) } 1138 */ obtainRunnable( OctConsumer<? super A, ? super B, ? super C, ? super D, ? super E, ? super F, ? super G, ? super H> function, A arg1, B arg2, C arg3, D arg4, E arg5, F arg6, G arg7, H arg8)1139 static <A, B, C, D, E, F, G, H> PooledRunnable obtainRunnable( 1140 OctConsumer<? super A, ? super B, ? super C, ? super D, ? super E, ? super F, ? super G, 1141 ? super H> function, A arg1, B arg2, C arg3, D arg4, E arg5, F arg6, G arg7, 1142 H arg8) { 1143 return acquire(PooledLambdaImpl.sPool, 1144 function, 8, 0, ReturnType.VOID, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, 1145 null); 1146 } 1147 1148 /** 1149 * {@link PooledSupplier} factory 1150 * 1151 * @param function non-capturing lambda(typically an unbounded method reference) 1152 * to be invoked on call 1153 * @param arg1 parameter supplied to {@code function} on call 1154 * @param arg2 parameter supplied to {@code function} on call 1155 * @param arg3 parameter supplied to {@code function} on call 1156 * @param arg4 parameter supplied to {@code function} on call 1157 * @param arg5 parameter supplied to {@code function} on call 1158 * @param arg6 parameter supplied to {@code function} on call 1159 * @param arg7 parameter supplied to {@code function} on call 1160 * @param arg8 parameter supplied to {@code function} on call 1161 * @return a {@link PooledSupplier}, equivalent to lambda: 1162 * {@code () -> function(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) } 1163 */ obtainSupplier( OctFunction<? super A, ? super B, ? super C, ? super D, ? super E, ? super F, ? super G, ? super H, ? extends R> function, A arg1, B arg2, C arg3, D arg4, E arg5, F arg6, G arg7, H arg8)1164 static <A, B, C, D, E, F, G, H, R> PooledSupplier<R> obtainSupplier( 1165 OctFunction<? super A, ? super B, ? super C, ? super D, ? super E, ? super F, 1166 ? super G, ? super H, ? extends R> function, 1167 A arg1, B arg2, C arg3, D arg4, E arg5, F arg6, G arg7, H arg8) { 1168 return acquire(PooledLambdaImpl.sPool, 1169 function, 8, 0, ReturnType.OBJECT, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, 1170 null); 1171 } 1172 1173 /** 1174 * Factory of {@link Message}s that contain an 1175 * ({@link PooledLambda#recycleOnUse auto-recycling}) {@link PooledRunnable} as its 1176 * {@link Message#getCallback internal callback}. 1177 * 1178 * The callback is equivalent to one obtainable via 1179 * {@link #obtainRunnable(QuintConsumer, Object, Object, Object, Object, Object)} 1180 * 1181 * Note that using this method with {@link android.os.Handler#handleMessage} 1182 * is more efficient than the alternative of {@link android.os.Handler#post} 1183 * with a {@link PooledRunnable} due to the lack of 2 separate synchronization points 1184 * when obtaining {@link Message} and {@link PooledRunnable} from pools separately 1185 * 1186 * You may optionally set a {@link Message#what} for the message if you want to be 1187 * able to cancel it via {@link android.os.Handler#removeMessages}, but otherwise 1188 * there's no need to do so 1189 * 1190 * @param function non-capturing lambda(typically an unbounded method reference) 1191 * to be invoked on call 1192 * @param arg1 parameter supplied to {@code function} on call 1193 * @param arg2 parameter supplied to {@code function} on call 1194 * @param arg3 parameter supplied to {@code function} on call 1195 * @param arg4 parameter supplied to {@code function} on call 1196 * @param arg5 parameter supplied to {@code function} on call 1197 * @param arg6 parameter supplied to {@code function} on call 1198 * @param arg7 parameter supplied to {@code function} on call 1199 * @param arg8 parameter supplied to {@code function} on call 1200 * @return a {@link Message} invoking {@code function(arg1, arg2, arg3, arg4, arg5, arg6, 1201 * arg7, arg8) } when handled 1202 */ obtainMessage( OctConsumer<? super A, ? super B, ? super C, ? super D, ? super E, ? super F, ? super G, ? super H> function, A arg1, B arg2, C arg3, D arg4, E arg5, F arg6, G arg7, H arg8)1203 static <A, B, C, D, E, F, G, H> Message obtainMessage( 1204 OctConsumer<? super A, ? super B, ? super C, ? super D, ? super E, ? super F, ? super G, 1205 ? super H> function, A arg1, B arg2, C arg3, D arg4, E arg5, F arg6, G arg7, 1206 H arg8) { 1207 synchronized (Message.sPoolSync) { 1208 PooledRunnable callback = acquire(PooledLambdaImpl.sMessageCallbacksPool, 1209 function, 8, 0, ReturnType.VOID, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, 1210 null); 1211 return Message.obtain().setCallback(callback.recycleOnUse()); 1212 } 1213 } 1214 1215 /** 1216 * {@link PooledRunnable} factory 1217 * 1218 * @param function non-capturing lambda(typically an unbounded method reference) 1219 * to be invoked on call 1220 * @param arg1 parameter supplied to {@code function} on call 1221 * @param arg2 parameter supplied to {@code function} on call 1222 * @param arg3 parameter supplied to {@code function} on call 1223 * @param arg4 parameter supplied to {@code function} on call 1224 * @param arg5 parameter supplied to {@code function} on call 1225 * @param arg6 parameter supplied to {@code function} on call 1226 * @param arg7 parameter supplied to {@code function} on call 1227 * @param arg8 parameter supplied to {@code function} on call 1228 * @param arg9 parameter supplied to {@code function} on call 1229 * @return a {@link PooledRunnable}, equivalent to lambda: 1230 * {@code () -> function(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) } 1231 */ obtainRunnable( NonaConsumer<? super A, ? super B, ? super C, ? super D, ? super E, ? super F, ? super G, ? super H, ? super I> function, A arg1, B arg2, C arg3, D arg4, E arg5, F arg6, G arg7, H arg8, I arg9)1232 static <A, B, C, D, E, F, G, H, I> PooledRunnable obtainRunnable( 1233 NonaConsumer<? super A, ? super B, ? super C, ? super D, ? super E, ? super F, 1234 ? super G, ? super H, ? super I> function, A arg1, B arg2, C arg3, D arg4, 1235 E arg5, F arg6, G arg7, H arg8, I arg9) { 1236 return acquire(PooledLambdaImpl.sPool, 1237 function, 9, 0, ReturnType.VOID, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, 1238 arg9); 1239 } 1240 1241 /** 1242 * {@link PooledSupplier} factory 1243 * 1244 * @param function non-capturing lambda(typically an unbounded method reference) 1245 * to be invoked on call 1246 * @param arg1 parameter supplied to {@code function} on call 1247 * @param arg2 parameter supplied to {@code function} on call 1248 * @param arg3 parameter supplied to {@code function} on call 1249 * @param arg4 parameter supplied to {@code function} on call 1250 * @param arg5 parameter supplied to {@code function} on call 1251 * @param arg6 parameter supplied to {@code function} on call 1252 * @param arg7 parameter supplied to {@code function} on call 1253 * @param arg8 parameter supplied to {@code function} on call 1254 * @param arg9 parameter supplied to {@code function} on call 1255 * @return a {@link PooledSupplier}, equivalent to lambda: 1256 * {@code () -> function(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) } 1257 */ obtainSupplier( NonaFunction<? super A, ? super B, ? super C, ? super D, ? super E, ? super F, ? super G, ? super H, ? super I, ? extends R> function, A arg1, B arg2, C arg3, D arg4, E arg5, F arg6, G arg7, H arg8, I arg9)1258 static <A, B, C, D, E, F, G, H, I, R> PooledSupplier<R> obtainSupplier( 1259 NonaFunction<? super A, ? super B, ? super C, ? super D, ? super E, ? super F, 1260 ? super G, ? super H, ? super I, ? extends R> function, 1261 A arg1, B arg2, C arg3, D arg4, E arg5, F arg6, G arg7, H arg8, I arg9) { 1262 return acquire(PooledLambdaImpl.sPool, 1263 function, 9, 0, ReturnType.OBJECT, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, 1264 arg9); 1265 } 1266 1267 /** 1268 * Factory of {@link Message}s that contain an 1269 * ({@link PooledLambda#recycleOnUse auto-recycling}) {@link PooledRunnable} as its 1270 * {@link Message#getCallback internal callback}. 1271 * 1272 * The callback is equivalent to one obtainable via 1273 * {@link #obtainRunnable(QuintConsumer, Object, Object, Object, Object, Object)} 1274 * 1275 * Note that using this method with {@link android.os.Handler#handleMessage} 1276 * is more efficient than the alternative of {@link android.os.Handler#post} 1277 * with a {@link PooledRunnable} due to the lack of 2 separate synchronization points 1278 * when obtaining {@link Message} and {@link PooledRunnable} from pools separately 1279 * 1280 * You may optionally set a {@link Message#what} for the message if you want to be 1281 * able to cancel it via {@link android.os.Handler#removeMessages}, but otherwise 1282 * there's no need to do so 1283 * 1284 * @param function non-capturing lambda(typically an unbounded method reference) 1285 * to be invoked on call 1286 * @param arg1 parameter supplied to {@code function} on call 1287 * @param arg2 parameter supplied to {@code function} on call 1288 * @param arg3 parameter supplied to {@code function} on call 1289 * @param arg4 parameter supplied to {@code function} on call 1290 * @param arg5 parameter supplied to {@code function} on call 1291 * @param arg6 parameter supplied to {@code function} on call 1292 * @param arg7 parameter supplied to {@code function} on call 1293 * @param arg8 parameter supplied to {@code function} on call 1294 * @param arg9 parameter supplied to {@code function} on call 1295 * @return a {@link Message} invoking {@code function(arg1, arg2, arg3, arg4, arg5, arg6, 1296 * arg7, arg8, arg9) } when handled 1297 */ obtainMessage( NonaConsumer<? super A, ? super B, ? super C, ? super D, ? super E, ? super F, ? super G, ? super H, ? super I> function, A arg1, B arg2, C arg3, D arg4, E arg5, F arg6, G arg7, H arg8, I arg9)1298 static <A, B, C, D, E, F, G, H, I> Message obtainMessage( 1299 NonaConsumer<? super A, ? super B, ? super C, ? super D, ? super E, ? super F, 1300 ? super G, ? super H, ? super I> function, A arg1, B arg2, C arg3, D arg4, 1301 E arg5, F arg6, G arg7, H arg8, I arg9) { 1302 synchronized (Message.sPoolSync) { 1303 PooledRunnable callback = acquire(PooledLambdaImpl.sMessageCallbacksPool, 1304 function, 9, 0, ReturnType.VOID, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, 1305 arg9); 1306 return Message.obtain().setCallback(callback.recycleOnUse()); 1307 } 1308 } 1309 } 1310