Package javaflow.network.impl

Source Code of javaflow.network.impl.Unique

package javaflow.network.impl;

import javaflow.components.api.Component;
import javaflow.components.api.InputPort;
import javaflow.components.api.OutputPort;
import javaflow.components.api.Packet;

import java.util.HashSet;
import java.util.Set;

public class Unique implements Component {
    InputPort in;
    OutputPort out;


    @Override
    public void execute() {
        Set<Object> seen = new HashSet<>();
        Packet p;
        while(((p=in.receive())!=null)){
            if (seen.add(p.getContent())){
                out.send(p);
            } else {
                p.drop();
            }
        }
    }
}
TOP

Related Classes of javaflow.network.impl.Unique

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.