Class GuavaUtils


  • public class GuavaUtils
    extends Object
    • Constructor Detail

      • GuavaUtils

        public GuavaUtils()
    • 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 {@link 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> com.google.common.util.concurrent.Futures#allAsList(Iterable> 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