package peer; import java.util.Iterator; import java.util.List; public class Node { private int id; // node id must be unique! id = IP of peer ?!? //-> Should be unique if we don't consider peers behind a NAT. private List neighbours; public Node(int id, List neighbours){ this.id = id; this.neighbours = neighbours; } //add one single neighbour public void addSingleNeighbour(Node neighbour){ this.neighbours.add(neighbour); } //add a list of new neighbours public void addMultiNeighbours(List neighbours){ Iterator it = neighbours.iterator(); while(it.hasNext()){ this.neighbours.add(it.next()); } } public boolean hasNeighbours(){ return (this.neighbours.size() > 0); } //checks if actual node has neighbour with given id public boolean hasNeighbour(int id){ for(int i = 0; i < neighbours.size(); i++){ Node tmp = neighbours.get(i); if(tmp.id == id){ return true; } } return false; } }