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

org.daisy.dotify.common.splitter.TrimStep Maven / Gradle / Ivy

There is a newer version: 1.0.7
Show newest version
package org.daisy.dotify.common.splitter;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

class TrimStep implements StepForward {
    private final List ret;
    private final List supplements;
    private final List discarded;
    private final Supplements map;
    private final Set ids;

    TrimStep(Supplements map) {
        this.ret = new ArrayList<>();
        this.supplements = new ArrayList<>();
        this.discarded = new ArrayList<>();
        this.map = map;
        this.ids = new HashSet<>();
    }

    @Override
    public void addUnit(T unit) {
        List idList = unit.getSupplementaryIDs();
        if (idList != null) {
            for (String id : idList) {
                if (ids.add(id)) { //id didn't already exist in the list
                    T item = map.get(id);
                    if (item != null) {
                        supplements.add(item);
                    }
                }
            }
        }
        ret.add(unit);
    }

    @Override
    public boolean overflows(T buffer) {
        return false;
    }

    List getSupplements() {
        return supplements;
    }

    List getResult() {
        return ret;
    }

    List getDiscarded() {
        return discarded;
    }

    @Override
    public void addDiscarded(T unit) {
        discarded.add(unit);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy