Class BatchingVisitables


  • public final class BatchingVisitables
    extends Object
    • Method Detail

      • count

        public static long count​(BatchingVisitable<?> visitable,
                                 int batchSize)
      • visitWhile

        public static <T> BatchingVisitableView<T> visitWhile​(BatchingVisitable<T> visitable,
                                                              com.google.common.base.Predicate<T> condition)
        Returns:
        Visitable containing elements from the start of the visitable for which the predicate holds true. Once boundingPredicate returns false for an element of visitable, no more elements will be included in the returned visitable.
      • getFirst

        @Nullable
        public static <T> T getFirst​(BatchingVisitable<T> visitable)
        Returns:
        the first element or null if the visitable is empty
      • getMax

        public static <T extends Comparable<? super T>> T getMax​(BatchingVisitable<T> v)
        This method will throw if there are nulls in the visitable.
        Returns:
        null if the visitable is empty, otherwise return the smallest value.
      • getMax

        public static <T> T getMax​(BatchingVisitable<T> v,
                                   com.google.common.collect.Ordering<? super T> o,
                                   @Nullable
                                   T defaultElement)
        This will return the first maximal element in the visitable. This method takes a default element and will return that if the visitable is empty. If the visitable is non-empty it will return the largest value in the visitable.

        A common way to use this would be to pass null as the defaultElement and have the ordering throw on null elements so you know the visitable doesn't have any nulls.

      • getMin

        public static <T extends Comparable<? super T>> T getMin​(BatchingVisitable<T> v)
        This method will throw if there are nulls in the visitable.
        Returns:
        null if the visitable is empty, otherwise return the smallest value.
      • getMin

        public static <T> T getMin​(BatchingVisitable<T> v,
                                   com.google.common.collect.Ordering<? super T> o,
                                   @Nullable
                                   T defaultElement)
        This will return the first maximal element in the visitable. This method takes a default element and will return that if the visitable is empty. If the visitable is non-empty it will return the largest value in the visitable.

        A common way to use this would be to pass null as the defaultElement and have the ordering throw on null elements so you know the visitable doesn't have any nulls.

      • unique

        public static <T> BatchingVisitableView<T> unique​(BatchingVisitable<T> visitable)
        This is similar to the unix uniq command.

        If there is a sequence of identical values, it will be replaced by one value. For example "AAABABBB" will become "ABAB" If the list passed in is sorted, then it will actually result in a list of unique elements

        This uses Objects#equal(Object, Object) to do comparisons.

        null is supported bug discouraged

      • take

        public static <T> List<T> take​(BatchingVisitable<T> v,
                                       int howMany,
                                       boolean includeFirst)
      • hintPageSize

        public static <T> BatchingVisitableView<T> hintPageSize​(BatchingVisitable<T> bv,
                                                                int pageSize)
        This method will wrap the passed visitable so it is called with the passed pageSize when it is called.

        This can be used to make the performance of batching visitables better. One example of where this is useful is if I just visit the results one at a time, but I know that I will visit 100 results, then I can save a lot of potential round trips by hinting a page size of 100.

      • wrap

        public static <T,​S extends T> BatchingVisitable<T> wrap​(BatchingVisitable<S> visitable)
        This will wrap the passed visitor and return a more generic type. Since Visitables just produce values, their type can be made more generic because a Visitable<Long> can safely be cast to a Visitable<Object>.
        See Also:
        for more helper methods
      • getOrderedVisitableUsingSublists

        public static <T> BatchingVisitable<T> getOrderedVisitableUsingSublists​(OrderedSublistProvider<T> sublistProvider,
                                                                                @Inclusive
                                                                                long startId,
                                                                                com.google.common.base.Function<T,​Long> idFunction)