Package org.apache.druid.common.guava
Class GuavaUtils
- java.lang.Object
-
- org.apache.druid.common.guava.GuavaUtils
-
public class GuavaUtils extends Object
-
-
Constructor Summary
Constructors Constructor Description GuavaUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <F extends Future<?>>
voidcancelAll(boolean mayInterruptIfRunning, Future<?> combinedFuture, List<F> futures)
Cancel futures manually, because sometime we can't cancel all futures in {code com.google.common.util.concurrent.Futures.CombinedFuture} automatically.static <T> T
firstNonNull(T lhs, T rhs)
If first argument is not null, return it, else return the other argument.static <T extends Enum<T>>
TgetEnumIfPresent(Class<T> enumClass, String value)
Like Guava's Enums.getIfPresent, with some differences.static Long
tryParseLong(String string)
To fix semantic difference of Longs.tryParse() from Long.parseLong (Longs.tryParse() returns null for '+' started value)
-
-
-
Method Detail
-
tryParseLong
@Nullable public static Long tryParseLong(@Nullable String string)
To fix semantic difference of Longs.tryParse() from Long.parseLong (Longs.tryParse() returns null for '+' started value)
-
getEnumIfPresent
@Nullable public static <T extends Enum<T>> T getEnumIfPresent(Class<T> enumClass, String value)
Like Guava's Enums.getIfPresent, with some differences.- Returns nullable rather than Optional
- Does not require Guava 12
-
firstNonNull
@Nullable public static <T> T firstNonNull(@Nullable T lhs, @Nullable T rhs)
If first argument is not null, return it, else return the other argument. Sort of like {@linkcom.google.common.base.Objects#firstNonNull(T, T)} except will not explode if both arguments are null.
-
cancelAll
public static <F extends Future<?>> void cancelAll(boolean mayInterruptIfRunning, @Nullable Future<?> combinedFuture, List<F> futures)
Cancel futures manually, because sometime we can't cancel all futures in {code com.google.common.util.concurrent.Futures.CombinedFuture} automatically. Especially when we call {@link staticListenableFuture - > com.google.common.util.concurrent.Futures#allAsList(Iterable extends ListenableFuture extends V>> futures)}
to create a batch of future.
- Parameters:
mayInterruptIfRunning
-true
if the thread executing this task should be interrupted; otherwise, in-progress tasks are allowed to completecombinedFuture
- The combinedFuture that associated with futuresfutures
- The futures that we want to cancel
-
-