/** * Return a thread-safe version of a {@code Consumer} function. * If the function is guaranteed to be immutable (stateless) * then the function is returned, as it is thread safe, * otherwise a wrapper is returned that grabs synchronization * on {@code function} when calling {@link Consumer#accept(Object)}. * <BR> * If {@code function} implements {@code AutoCloseable} then * the function is assumed to be stateful and a thread-safe * version is returned. * @param <T> tuple type * @param function Function to return a thread-safe version of. * @return A thread-safe function */ public static <T> Consumer<T> synchronizedConsumer(final Consumer<T> function) { if (isImmutable(function) && !(function instanceof AutoCloseable)) return function; // Return a function that is synchronized on the passed in function reference. return new ThreadSafeConsumer<T>(function); }
/** * Return a thread-safe version of a {@code Consumer} function. * If the function is guaranteed to be immutable (stateless) * then the function is returned, as it is thread safe, * otherwise a wrapper is returned that grabs synchronization * on {@code function} when calling {@link Consumer#accept(Object)}. * <BR> * If {@code function} implements {@code AutoCloseable} then * the function is assumed to be stateful and a thread-safe * version is returned. * @param <T> tuple type * @param function Function to return a thread-safe version of. * @return A thread-safe function */ public static <T> Consumer<T> synchronizedConsumer(final Consumer<T> function) { if (isImmutable(function) && !(function instanceof AutoCloseable)) return function; // Return a function that is synchronized on the passed in function reference. return new ThreadSafeConsumer<T>(function); }
/** * Return a thread-safe version of a {@code Function} function. * If the function is guaranteed to be immutable (stateless) * then the function is returned, as it is thread safe, * otherwise a wrapper is returned that grabs synchronization * on {@code function} when calling {@link Function#apply(Object)}. * <BR> * If {@code function} implements {@code AutoCloseable} then * the function is assumed to be stateful and a thread-safe * version is returned. * @param <T> source tuple type * @param <R> result tuple type * @param function Function to return a thread-safe version of. * @return A thread-safe function */ public static <T,R> Function<T,R> synchronizedFunction(final Function<T,R> function) { if (isImmutable(function) && !(function instanceof AutoCloseable)) return function; // Return a function that is synchronized on the passed in function reference. return new ThreadSafeFunction<T,R>(function); }
/** * Return a thread-safe version of a {@code BiFunction} function. * If the function is guaranteed to be immutable (stateless) * then the function is returned, as it is thread safe, * otherwise a wrapper is returned that grabs synchronization * on {@code function} when calling {@link BiFunction#apply(Object, Object)}. * <BR> * If {@code function} implements {@code AutoCloseable} then * the function is assumed to be stateful and a thread-safe * version is returned. * @param <T> Type of function's first argument * @param <U> Type of function's second argument * @param <R> Type of function's third argument * @param function Function to return a thread-safe version of. * @return A thread-safe function */ public static <T,U,R> BiFunction<T,U,R> synchronizedBiFunction(final BiFunction<T,U,R> function) { if (isImmutable(function) && !(function instanceof AutoCloseable)) return function; // Return a function that is synchronized on the passed in function reference. return new ThreadSafeBiFunction<T,U,R>(function); }
/** * Return a thread-safe version of a {@code Supplier} function. * If the function is guaranteed to be immutable (stateless) * then the function is returned, as it is thread safe, * otherwise a wrapper is returned that grabs synchronization * on {@code function} when calling {@link Supplier#get()}. * <BR> * If {@code function} implements {@code AutoCloseable} then * the function is assumed to be stateful and a thread-safe * version is returned. * @param <T> tuple type * @param function Function to return a thread-safe version of. * @return A thread-safe function */ public static <T> Supplier<T> synchronizedSupplier(final Supplier<T> function) { if (isImmutable(function) && !(function instanceof AutoCloseable)) return function; // Return a function that is synchronized on the passed in function reference. return new ThreadSafeSupplier<T>(function); }
/** * Return a thread-safe version of a {@code Supplier} function. * If the function is guaranteed to be immutable (stateless) * then the function is returned, as it is thread safe, * otherwise a wrapper is returned that grabs synchronization * on {@code function} when calling {@link Supplier#get()}. * <BR> * If {@code function} implements {@code AutoCloseable} then * the function is assumed to be stateful and a thread-safe * version is returned. * @param <T> tuple type * @param function Function to return a thread-safe version of. * @return A thread-safe function */ public static <T> Supplier<T> synchronizedSupplier(final Supplier<T> function) { if (isImmutable(function) && !(function instanceof AutoCloseable)) return function; // Return a function that is synchronized on the passed in function reference. return new ThreadSafeSupplier<T>(function); }
/** * Return a thread-safe version of a {@code Function} function. * If the function is guaranteed to be immutable (stateless) * then the function is returned, as it is thread safe, * otherwise a wrapper is returned that grabs synchronization * on {@code function} when calling {@link Function#apply(Object)}. * <BR> * If {@code function} implements {@code AutoCloseable} then * the function is assumed to be stateful and a thread-safe * version is returned. * @param <T> source tuple type * @param <R> result tuple type * @param function Function to return a thread-safe version of. * @return A thread-safe function */ public static <T,R> Function<T,R> synchronizedFunction(final Function<T,R> function) { if (isImmutable(function) && !(function instanceof AutoCloseable)) return function; // Return a function that is synchronized on the passed in function reference. return new ThreadSafeFunction<T,R>(function); }
/** * Return a thread-safe version of a {@code BiFunction} function. * If the function is guaranteed to be immutable (stateless) * then the function is returned, as it is thread safe, * otherwise a wrapper is returned that grabs synchronization * on {@code function} when calling {@link BiFunction#apply(Object, Object)}. * <BR> * If {@code function} implements {@code AutoCloseable} then * the function is assumed to be stateful and a thread-safe * version is returned. * @param <T> Type of function's first argument * @param <U> Type of function's second argument * @param <R> Type of function's third argument * @param function Function to return a thread-safe version of. * @return A thread-safe function */ public static <T,U,R> BiFunction<T,U,R> synchronizedBiFunction(final BiFunction<T,U,R> function) { if (isImmutable(function) && !(function instanceof AutoCloseable)) return function; // Return a function that is synchronized on the passed in function reference. return new ThreadSafeBiFunction<T,U,R>(function); }
if (isImmutable(field.getType())) continue;
if (isImmutable(field.getType())) continue;