public interface JavaUtils
| 限定符和类型 | 字段和说明 |
|---|---|
static ConcurrentMap<Class<?>,String> |
CLASS_SIMPLE_NAMES |
static CompletableFuture<?>[] |
EMPTY_COMPLETABLE_FUTURE_ARRAY |
static org.slf4j.Logger |
LOG |
static Supplier<ThreadGroup> |
ROOT_THREAD_GROUP |
| 限定符和类型 | 方法和说明 |
|---|---|
static <T> CompletableFuture<Void> |
allOf(Collection<CompletableFuture<T>> futures) |
static <V> BiConsumer<V,Throwable> |
asBiConsumer(CompletableFuture<V> future) |
static <THROWABLE extends Throwable> |
attempt(CheckedRunnable<THROWABLE> runnable,
int numAttempts,
TimeDuration sleepTime,
String name,
org.slf4j.Logger log)
Attempt to run the given op multiple times.
|
static <RETURN,THROWABLE extends Throwable> |
attempt(CheckedSupplier<RETURN,THROWABLE> supplier,
int numAttempts,
TimeDuration sleepTime,
Supplier<?> name,
org.slf4j.Logger log)
Attempt to get a return value from the given supplier multiple times.
|
static <RETURN,THROWABLE extends Throwable> |
attemptRepeatedly(CheckedSupplier<RETURN,THROWABLE> supplier,
int numAttempts,
TimeDuration sleepTime,
String name,
org.slf4j.Logger log)
Attempt to get a return value from the given supplier multiple times.
|
static void |
attemptUntilTrue(BooleanSupplier condition,
int numAttempts,
TimeDuration sleepTime,
String name,
org.slf4j.Logger log)
Attempt to wait the given condition to return true multiple times.
|
static <T> T |
callAsUnchecked(Callable<T> callable)
Invoke
Callable.call() and, if there any,
wrap the checked exception by RuntimeException. |
static <OUTPUT,THROWABLE extends Throwable> |
callAsUnchecked(CheckedSupplier<OUTPUT,THROWABLE> checkedSupplier,
Function<THROWABLE,? extends RuntimeException> converter) |
static <T> T |
cast(Object obj) |
static <T> T |
cast(Object obj,
Class<T> clazz)
The same as
Class.cast(Object) except that
this method returns null (but not throw ClassCastException)
if the given object is not an instance of the given class. |
static <E> CompletableFuture<E> |
completeExceptionally(Throwable t) |
static String |
date() |
static <T> T |
doPrivileged(Supplier<T> action,
Function<SecurityException,T> exceptionHandler) |
static <T> T |
doPrivileged(Supplier<T> action,
Supplier<String> name) |
static void |
dumpAllThreads(Consumer<String> println) |
static StackTraceElement |
getCallerStackTraceElement() |
static String |
getClassSimpleName(Class<?> clazz) |
static StackTraceElement |
getCurrentStackTraceElement() |
static ThreadGroup |
getRootThreadGroup() |
static String |
getSystemProperty(String key)
Similar to
System.getProperty(String)
except that this method may invoke AccessController.doPrivileged(PrivilegedAction)
if there is a SecurityManager. |
static <T> MemoizedSupplier<T> |
memoize(Supplier<T> initializer)
Create a memoized supplier which gets a value by invoking the initializer once
and then keeps returning the same value as its supplied results.
|
static <T extends Throwable> |
runAsUnchecked(CheckedRunnable<T> runnable) |
static <THROWABLE extends Throwable> |
runAsUnchecked(CheckedRunnable<THROWABLE> runnable,
Function<THROWABLE,? extends RuntimeException> converter) |
static Timer |
runRepeatedly(Runnable runnable,
long delay,
long period,
TimeUnit unit) |
static void |
setSystemProperty(String key,
String value)
Similar to
System.setProperty(String, String)
except that this method may invoke AccessController.doPrivileged(PrivilegedAction)
if there is a SecurityManager. |
static <OUTPUT,THROWABLE extends Throwable> |
supplyAndWrapAsCompletionException(CheckedSupplier<OUTPUT,THROWABLE> supplier) |
static Throwable |
unwrapCompletionException(Throwable t) |
static final org.slf4j.Logger LOG
static final CompletableFuture<?>[] EMPTY_COMPLETABLE_FUTURE_ARRAY
static final ConcurrentMap<Class<?>,String> CLASS_SIMPLE_NAMES
static final Supplier<ThreadGroup> ROOT_THREAD_GROUP
static String date()
static <T> T cast(Object obj, Class<T> clazz)
Class.cast(Object) except that
this method returns null (but not throw ClassCastException)
if the given object is not an instance of the given class.static <T> T cast(Object obj)
static StackTraceElement getCallerStackTraceElement()
static StackTraceElement getCurrentStackTraceElement()
static <T extends Throwable> void runAsUnchecked(CheckedRunnable<T> runnable)
static <THROWABLE extends Throwable> void runAsUnchecked(CheckedRunnable<THROWABLE> runnable, Function<THROWABLE,? extends RuntimeException> converter)
static <T> T callAsUnchecked(Callable<T> callable)
Callable.call() and, if there any,
wrap the checked exception by RuntimeException.static <OUTPUT,THROWABLE extends Throwable> OUTPUT callAsUnchecked(CheckedSupplier<OUTPUT,THROWABLE> checkedSupplier, Function<THROWABLE,? extends RuntimeException> converter)
static <T> T doPrivileged(Supplier<T> action, Function<SecurityException,T> exceptionHandler)
static String getSystemProperty(String key)
System.getProperty(String)
except that this method may invoke AccessController.doPrivileged(PrivilegedAction)
if there is a SecurityManager.SecurityException;
otherwise, return system property value.static void setSystemProperty(String key, String value)
System.setProperty(String, String)
except that this method may invoke AccessController.doPrivileged(PrivilegedAction)
if there is a SecurityManager.
When there is a SecurityException, this becomes a NOOP.static <T> MemoizedSupplier<T> memoize(Supplier<T> initializer)
T - The supplier result type.initializer - to supply at most one non-null value.static ThreadGroup getRootThreadGroup()
static <RETURN,THROWABLE extends Throwable> RETURN attemptRepeatedly(CheckedSupplier<RETURN,THROWABLE> supplier, int numAttempts, TimeDuration sleepTime, String name, org.slf4j.Logger log) throws THROWABLE extends Throwable, InterruptedException
THROWABLE extends ThrowableInterruptedExceptionstatic <RETURN,THROWABLE extends Throwable> RETURN attempt(CheckedSupplier<RETURN,THROWABLE> supplier, int numAttempts, TimeDuration sleepTime, Supplier<?> name, org.slf4j.Logger log) throws THROWABLE extends Throwable, InterruptedException
THROWABLE extends ThrowableInterruptedExceptionstatic <THROWABLE extends Throwable> void attempt(CheckedRunnable<THROWABLE> runnable, int numAttempts, TimeDuration sleepTime, String name, org.slf4j.Logger log) throws THROWABLE extends Throwable, InterruptedException
THROWABLE extends ThrowableInterruptedExceptionstatic void attemptUntilTrue(BooleanSupplier condition, int numAttempts, TimeDuration sleepTime, String name, org.slf4j.Logger log) throws InterruptedException
static <E> CompletableFuture<E> completeExceptionally(Throwable t)
static <T> CompletableFuture<Void> allOf(Collection<CompletableFuture<T>> futures)
static <V> BiConsumer<V,Throwable> asBiConsumer(CompletableFuture<V> future)
static <OUTPUT,THROWABLE extends Throwable> OUTPUT supplyAndWrapAsCompletionException(CheckedSupplier<OUTPUT,THROWABLE> supplier)
Copyright © 2017–2023 The Apache Software Foundation. All rights reserved.