Class BambooIterables


  • public final class BambooIterables
    extends Object
    • Method Detail

      • find

        @Nullable
        public static <T,​E extends Throwable> T find​(@NotNull
                                                           @NotNull Iterable<T> iterable,
                                                           @NotNull
                                                           @NotNull ThrowingPredicate<? super T,​E> predicate,
                                                           @Nullable
                                                           T defaultValue)
                                                    throws E extends Throwable
        Returns the first element in iterable that satisfies the given predicate, or defaultValue if none found.
        Throws:
        E extends Throwable
      • find

        @Nullable
        public static <T,​E extends Throwable,​F extends Throwable> T find​(@NotNull
                                                                                     @NotNull Iterable<T> iterable,
                                                                                     @NotNull
                                                                                     @NotNull DoubleThrowingPredicate<? super T,​E,​F> predicate,
                                                                                     @Nullable
                                                                                     T defaultValue)
                                                                              throws E extends Throwable,
                                                                                     F extends Throwable
        Returns the first element in iterable that satisfies the given predicate, or defaultValue if none found.
        Throws:
        E extends Throwable
      • find

        public static <T> T find​(Iterable<T> iterable,
                                 Predicate<? super T> predicate,
                                 @Nullable
                                 @Nullable String exceptionMessage)
        Utility method to customize exception message thrown by Iterables.find(Iterable, com.google.common.base.Predicate).
      • none

        public static <T> boolean none​(@NotNull
                                       @NotNull Iterable<T> iterable,
                                       @NotNull
                                       @NotNull Predicate<? super T> predicate)
        Returns true if no elements in iterable fulfill predicate.
      • concat

        public static <T> Iterable<T> concat​(@NotNull
                                             @NotNull Iterable<? extends T> iterable,
                                             @NotNull
                                             T object)
        Combines an iterable and an element into a single iterable. The returned iterable has an iterator that traverses the elements in a, followed by b. The source iterator is not polled until necessary. The returned iterable's iterator supports remove() when the corresponding input iterator supports it.
      • concat

        public static <T> Iterable<T> concat​(@NotNull
                                             T object,
                                             @NotNull
                                             @NotNull Iterable<? extends T> iterable)
        Combines an iterable and an element into a single iterable. The returned iterable has an iterator that returns a, followed by the elements in b. The source iterator is not polled until necessary. The returned iterable's iterator supports remove() when the corresponding input iterator supports it.
      • removeFirst

        @Nullable
        public static <T> T removeFirst​(@NotNull
                                        @NotNull Iterable<T> iterable,
                                        @NotNull
                                        @NotNull Predicate<T> predicate)
        Removes first object matching the predicate.
      • hasSize

        public static boolean hasSize​(@NotNull
                                      @NotNull Iterable<?> iterable,
                                      int size)
        Checks if the supplied iterable is of size size.
      • stream

        @NotNull
        public static <T> @NotNull Stream<T> stream​(@NotNull
                                                    @NotNull Iterable<T> iterable)
        Create a Stream from the given Iterable.
      • getFirst

        @NotNull
        public static <T> T getFirst​(@NotNull
                                     @NotNull Iterable<? extends T> iterable)
        Returns the first element in iterable or throws NoSuchElementException if iterable is empty.
      • getFirstOrElse

        @NotNull
        public static <T> T getFirstOrElse​(@Nullable
                                           @Nullable Iterable<T> iterable,
                                           @NotNull
                                           @NotNull Supplier<T> supplier)
        Returns the first element in iterable or obtains a default from the given supplier.
      • iterable

        @NotNull
        public static <T> @NotNull Iterable<T> iterable​(@NotNull
                                                        @NotNull Supplier<Iterator<T>> supplier)
        Constructs an iterable for a supplier of iterators.
      • removeAll

        public static <T> boolean removeAll​(@NotNull
                                            @NotNull Iterable<T> iterable,
                                            @Nullable
                                            T o)
        Removes all occurrences of o from iterable. Returns true iff iterable was modified.
      • filter

        public static <T> Iterable<T> filter​(@NotNull
                                             @NotNull Iterable<T> iterable,
                                             @NotNull
                                             @NotNull Predicate<? super T> predicate)
        Equivalent of Iterables.filter(Iterable, com.google.common.base.Predicate) relying on Java 8 stream API.
      • transform

        public static <T,​U> Iterable<U> transform​(@NotNull
                                                        @NotNull Iterable<T> iterable,
                                                        @NotNull
                                                        @NotNull Function<? super T,​U> function)
        Equivalent of Iterables.transform(Iterable, com.google.common.base.Function) relying on Java 8 stream API.