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

com.annimon.stream.operator.ObjDistinctBy Maven / Gradle / Ivy

The newest version!
package com.annimon.stream.operator;

import com.annimon.stream.function.Function;
import com.annimon.stream.iterator.LsaExtIterator;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

public class ObjDistinctBy extends LsaExtIterator {

    private final Iterator iterator;
    private final Function classifier;
    private final Set set;

    public ObjDistinctBy(Iterator iterator, Function classifier) {
        this.iterator = iterator;
        this.classifier = classifier;
        set = new HashSet();
    }

    @Override
    protected void nextIteration() {
        while (hasNext = iterator.hasNext()) {
            next = iterator.next();
            final K key = classifier.apply(next);
            if (set.add(key)) {
                return;
            }
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy