Class GuavaUtils

java.lang.Object
org.apache.druid.common.guava.GuavaUtils

public class GuavaUtils extends Object
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static <F extends Future<?>>
    void
    cancelAll(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>>
    T
    getEnumIfPresent(Class<T> enumClass, String value)
    Like Guava's Enums.getIfPresent, with some differences.
    static Long
    To fix semantic difference of Longs.tryParse() from Long.parseLong (Longs.tryParse() returns null for '+' started value)

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • GuavaUtils

      public GuavaUtils()
  • Method Details

    • 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 {@link <T> com.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 static ListenableFuture<List> 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 complete
      combinedFuture - The combinedFuture that associated with futures
      futures - The futures that we want to cancel