Class BatchingVisitableView<T>

  • Type Parameters:
    T - The contained object type.
    All Implemented Interfaces:
    BatchingVisitable<T>

    public abstract class BatchingVisitableView<T>
    extends com.google.common.collect.ForwardingObject
    implements BatchingVisitable<T>
    A wrapper for BatchingVisitable which adds support for common operations.
    • Method Detail

      • delegate

        protected abstract BatchingVisitable<T> delegate()
        Specified by:
        delegate in class com.google.common.collect.ForwardingObject
      • batchAccept

        public <K extends Exception> boolean batchAccept​(int batchSize,
                                                         AbortingVisitor<? super List<T>,​K> visitor)
                                                  throws K extends Exception
        Description copied from interface: BatchingVisitable
        This method should be used to visit elements in batches until the visitor returns false or there are no batches left to visit.
        Specified by:
        batchAccept in interface BatchingVisitable<T>
        Parameters:
        batchSize - Each list passed to the visitor will be of batchSize except for the last one which could be smaller, but will not be empty;
        Returns:
        true if the visitor always returned true or was never called. false if the visitor ever returned false.
        Throws:
        K extends Exception
      • count

        public long count()
      • transform

        public <U> BatchingVisitableView<U> transform​(com.google.common.base.Function<? super T,​? extends U> fn)
      • transformBatch

        public <U> BatchingVisitableView<U> transformBatch​(com.google.common.base.Function<? super List<T>,​? extends List<U>> fn)
        This can also be used to filter or multiply the input. It is common to return a list of a smaller size than you pass in if you are filtering.

        In the filtering case, the caller may only want one value, but you may have to visit batches of size 100 to find that value. In this case you should call .transformBatch and then call .hintBatchSize(100) so your function will get 100 at a time even though the final consumer is only requesting a batch of size 1. A good example of this is in BatchingVisitablesTest#testHintPageSize()

      • forEach

        public void forEach​(int batchSize,
                            Visitor<T> visitor)
      • forEach

        public void forEach​(Visitor<T> visitor)
      • getFirst

        @Nullable
        public T getFirst()
        Gets the first element in the visitable.
        Returns:
        the first element or null if the visitable is empty
      • getFirst

        @Nullable
        public T getFirst​(@Nullable
                          T defaultElement)
        Gets the first element in the visitable. If a default value of null is wanted, then consider calling getFirst() instead.
        Returns:
        the first element or defaultElement if the visitable is empty
      • getLast

        @Nullable
        public T getLast()
        Gets the last element in the visitable.
        Returns:
        the last element or null if the visitable is empty
      • getLast

        @Nullable
        public T getLast​(@Nullable
                         T defaultElement)
        Gets the last element in the visitable. If a default value of null is wanted, then consider calling getLast() instead.
        Returns:
        the last element or defaultElement if the visitable is empty
      • getMax

        public T getMax​(com.google.common.collect.Ordering<? super T> ordering,
                        @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 T getMin​(com.google.common.collect.Ordering<? super T> ordering,
                        @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.

      • immutableCopy

        public com.google.common.collect.ImmutableList<T> immutableCopy()
        Returns an immutable copy of the elements in this visitable.
        Throws:
        NullPointerException - if any elements in the visitable are null
      • immutableSetCopy

        public com.google.common.collect.ImmutableSet<T> immutableSetCopy()
        Returns an immutable copy of the elements in this visitable.
        Throws:
        NullPointerException - if any elements in the visitable are null
      • copyInto

        public <S extends Collection<? super T>> S copyInto​(S collection)
        Copies the elements in this visitable into an existing collection. This method has equivalent behaviour to Iterables.addAll(collection, this).
        Returns:
        a reference to collection, for convenience
      • any

        public boolean any​(com.google.common.base.Predicate<? super T> predicate)
        Returns true iff one or more elements satisfy the predicate.
      • all

        public boolean all​(com.google.common.base.Predicate<? super T> predicate)
        Returns true iff every element satisfies the predicate. If empty, true is returned.
      • isEmpty

        public boolean isEmpty()
      • isEqual

        public boolean isEqual​(Iterable<T> it)
      • isEqual

        public boolean isEqual​(Iterator<T> it)
      • size

        public long size()
      • find

        public T find​(com.google.common.base.Predicate<? super T> predicate,
                      @Nullable
                      T defaultValue)