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();
}
}
}
}