All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.aksw.jenax.arq.aggregation.AggCollection Maven / Gradle / Ivy

The newest version!
package org.aksw.jenax.arq.aggregation;

import java.util.function.BiConsumer;
import java.util.function.Function;
import java.util.function.Supplier;

import org.aksw.commons.collector.domain.Accumulator;
import org.aksw.commons.collector.domain.Aggregator;

public class AggCollection
    implements Aggregator
{

    protected Supplier collectionSupplier;
    protected Function bindingToItem;
    protected BiConsumer addToCollection;

    public AggCollection(
            Supplier collector,
            Function bindingToItem,
            BiConsumer addToCollection
            ) {
        super();
        this.collectionSupplier = collector;
        this.bindingToItem = bindingToItem;
        this.addToCollection = addToCollection;
    }

    @Override
    public Accumulator createAccumulator() {
        COLLECTION collection = collectionSupplier.get();
        return new AccCollection(collection);
    }

    public class AccCollection
        implements Accumulator
    {
        protected COLLECTION collection;

        public AccCollection(COLLECTION collection) {
            super();
            this.collection = collection;
        }

        @Override
        public void accumulate(T binding, E env) {
            ITEM item = bindingToItem.apply(binding);
            addToCollection.accept(collection, item);
        }

        @Override
        public COLLECTION getValue() {
            return collection;
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy