use of com.hazelcast.jet.datamodel.BagsByTag in project hazelcast-jet by hazelcast.
the class AggregateOperations method toBagsByTag.
/**
* Returns an {@code AggregateOperation} that accumulates the items from
* any number of inputs into {@link BagsByTag}: items from <em>inputN</em>
* are accumulated into under <em>tagN</em>.
*
* @see #toTwoBags()
* @see #toThreeBags()
*/
@Nonnull
@SuppressWarnings("unchecked")
public static AggregateOperation<BagsByTag, BagsByTag> toBagsByTag(@Nonnull Tag<?>... tags) {
checkPositive(tags.length, "At least one tag required");
AggregateOperationBuilder.VarArity<BagsByTag> builder = AggregateOperation.withCreate(BagsByTag::new).andAccumulate(tags[0], (acc, item) -> ((Collection) acc.ensureBag(tags[0])).add(item));
for (int i = 1; i < tags.length; i++) {
Tag tag = tags[i];
builder = builder.andAccumulate(tag, (acc, item) -> acc.ensureBag(tag).add(item));
}
return builder.andCombine(BagsByTag::combineWith).andFinish(BagsByTag::finish);
}
Aggregations