Interface ProjectionCollector<E,V,A,R>

Type Parameters:
E - The type of extracted values to accumulate before being transformed.
V - The type of values to accumulate obtained by transforming extracted values (E).
A - The type of the temporary storage for accumulated values, before and after being transformed.
R - The type of the final result containing values of type V.
All Known Subinterfaces:
ProjectionAccumulator<E,V,A,R>

@Incubating public interface ProjectionCollector<E,V,A,R>
A variation on Collector suitable for projections on field values.

Compared to Collector:

  • Method Details

    • nullable

      static <V> ProjectionCollector.Provider<V,V> nullable()
      Type Parameters:
      V - The type of values to accumulate.
      Returns:
      The projection collector capable of accumulating single-valued projections in an as-is form, i.e. the value is returned without any extra transformations.
    • optional

      static <V> ProjectionCollector.Provider<V,Optional<V>> optional()
      Type Parameters:
      V - The type of values to accumulate.
      Returns:
      The projection collector capable of accumulating single-valued projections and wrapping the values in an Optional.
    • simple

      static <V, C> ProjectionCollector.Provider<V,C> simple(Function<List<V>,C> converter)
      Type Parameters:
      V - The type of values to accumulate.
      C - The type of the resulting collection.
      Parameters:
      converter - The function that defines how to convert a list of collected values to the final collection.
      Returns:
      An collector based on a list as a temporary storage.
    • list

      static <V> ProjectionCollector.Provider<V,List<V>> list()
      Type Parameters:
      V - The type of values to accumulate.
      Returns:
      The projection collector capable of accumulating multivalued projections as a List.
    • set

      static <V> ProjectionCollector.Provider<V,Set<V>> set()
      Type Parameters:
      V - The type of values to accumulate.
      Returns:
      The projection collector capable of accumulating multivalued projections as a Set.
    • sortedSet

      static <V> ProjectionCollector.Provider<V,SortedSet<V>> sortedSet()
      Type Parameters:
      V - The type of values to accumulate.
      Returns:
      The projection collector capable of accumulating multivalued projections as a SortedSet.
    • sortedSet

      static <V> ProjectionCollector.Provider<V,SortedSet<V>> sortedSet(Comparator<? super V> comparator)
      Type Parameters:
      V - The type of values to accumulate.
      Parameters:
      comparator - The comparator which should be used by the sorted set.
      Returns:
      The projection collector capable of accumulating multivalued projections as a SortedSet using a custom comparator.
    • array

      static <V> ProjectionCollector.Provider<V,V[]> array(Class<? super V> componentType)
      Type Parameters:
      V - The type of values to accumulate.
      Parameters:
      componentType - The type of the array elements.
      Returns:
      The projection collector capable of accumulating multivalued projections as an array.
    • createInitial

      A createInitial()
      Creates the initial accumulated container.

      This operation should be non-blocking.

      Returns:
      The initial accumulated container, to pass to the first call to accumulate(Object, Object).
    • accumulate

      A accumulate(A accumulated, E value)
      Folds a new value in the given accumulated container.

      This operation should be non-blocking.

      Parameters:
      accumulated - The accumulated value so far. For the first call, this is a value returned by createInitial(). For the next calls, this is the value returned by the previous call to accumulate(Object, Object).
      value - The value to accumulate.
      Returns:
      The new accumulated value.
    • accumulateAll

      default A accumulateAll(A accumulated, Collection<E> values)
      Folds a collection of new values in the given accumulated container.

      This operation should be non-blocking.

      Parameters:
      accumulated - The accumulated value so far. For the first call, this is a value returned by createInitial(). For the next calls, this is the value returned by the previous call to accumulate(Object, Object).
      values - The values to accumulate.
      Returns:
      The new accumulated value.
    • size

      int size(A accumulated)
      Parameters:
      accumulated - The accumulated value so far, returned by the last call to accumulate(Object, Object).
      Returns:
      The number of elements in the accumulated value.
    • get

      E get(A accumulated, int index)
      Retrieves the value at the given index.

      This operation should be non-blocking.

      Parameters:
      accumulated - The accumulated value so far, returned by the last call to accumulate(Object, Object).
      index - The index of the value to retrieve.
      Returns:
      The value at the given index.
    • transform

      A transform(A accumulated, int index, V transformed)
      Transforms the value at the given index, replacing it with the given transformed value.

      This operation should be non-blocking.

      Parameters:
      accumulated - The accumulated value so far, returned by the last call to accumulate(Object, Object).
      index - The index of the value being transformed.
      transformed - The transformed value.
      Returns:
      The new accumulated value.
    • transformAll

      default A transformAll(A accumulated, FromDocumentValueConverter<? super E,? extends V> converter, FromDocumentValueConvertContext context)
      Transforms all values with the given converter and the given context.

      This operation may be blocking.

      Parameters:
      accumulated - The accumulated value so far, returned by the last call to accumulate(Object, Object).
      converter - The projection converter (from F to V).
      context - The context to be passed to the projection converter.
      Returns:
      The new accumulated value.
    • finish

      R finish(A accumulated)
      Finishes the accumulation, converting the accumulated container into the final result.

      This operation may be blocking.

      Parameters:
      accumulated - The temporary storage created by createInitial(), then populated by successive calls to accumulate(Object, Object), then transformed by a single call to transformAll(Object, FromDocumentValueConverter, FromDocumentValueConvertContext) or by successive calls to transform(Object, int, Object).
      Returns:
      The final result of the accumulation.
    • empty

      default R empty()
      Returns:
      An "empty" final value, i.e. when a final transformation is applied to the initial value.