Interface ProjectionAccumulator<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 typeV.
public interface ProjectionAccumulator<E,V,A,R>A variation onCollectorsuitable for projections on field values.Compared to
Collector:- There is no concept of parallel execution.
- All operations are expected to be non-blocking,
except for
transformAll(Object, ProjectionConverter, FromDocumentValueConvertContext)andfinish(Object). - Values to accumulate are expected to be
transformedexactly once after accumulation, changing their type fromProjectionAccumulatortoProjectionAccumulator. Clients are responsible for ensuring values to accumulate have been transformed upon callingfinish(Object).
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interfaceProjectionAccumulator.Provider<U,R>Provides an accumulator for a given type of values to accumulate (T).
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description Aaccumulate(A accumulated, E value)Folds a new value in the given accumulated container.default AaccumulateAll(A accumulated, Collection<E> values)Folds a collection of new values in the given accumulated container.AcreateInitial()Creates the initial accumulated container.Rfinish(A accumulated)Finishes the accumulation, converting the accumulated container into the final result.Eget(A accumulated, int index)Retrieves the value at the given index.static <V> ProjectionAccumulator.Provider<V,List<V>>list()static <V> ProjectionAccumulator.Provider<V,V>single()intsize(A accumulated)Atransform(A accumulated, int index, V transformed)Transforms the value at the given index, replacing it with the given transformed value.default AtransformAll(A accumulated, ProjectionConverter<? super E,? extends V> converter, FromDocumentValueConvertContext context)Transforms all values with the given converter and the given context.
-
-
-
Method Detail
-
single
static <V> ProjectionAccumulator.Provider<V,V> single()
-
list
static <V> ProjectionAccumulator.Provider<V,List<V>> list()
-
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 bycreateInitial(). For the next calls, this is the value returned by the previous call toaccumulate(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 bycreateInitial(). For the next calls, this is the value returned by the previous call toaccumulate(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 toaccumulate(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 toaccumulate(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 toaccumulate(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, ProjectionConverter<? 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 toaccumulate(Object, Object).converter- The projection converter (fromFtoV).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 bycreateInitial(), then populated by successive calls toaccumulate(Object, Object), then transformed by a single call totransformAll(Object, ProjectionConverter, FromDocumentValueConvertContext)or by successive calls totransform(Object, int, Object).- Returns:
- The final result of the accumulation.
-
-