This commit is contained in:
M.Scholz 2012-11-13 18:02:02 +01:00
parent c06d2c7cf0
commit 1137aaed90
2 changed files with 17 additions and 37 deletions

View File

@ -6,19 +6,15 @@ import java.util.List;
public class Node {
<<<<<<< HEAD
// node id must be unique! id = IP of peer ?!?
// -> Should be unique if we don't consider peers behind a NAT.
private int id;
private List<Node> neighbours;
=======
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 String name;
private List<Node> neighbours = new ArrayList<Node>();
>>>>>>> some improvements
public Node(int id, String name){
this.id = id;
@ -76,7 +72,7 @@ public class Node {
return (this.neighbours.size() > 0);
}
<<<<<<< HEAD
/**
* checks if actual node has neighbour with given id
*
@ -89,7 +85,10 @@ public class Node {
if(tmp.id == id){
return true;
}
=======
}
return false;
}
public int getId(){
return this.id;
}
@ -104,18 +103,11 @@ public class Node {
System.out.print("Name: " + this.name + ", Neighbours: ");
for(int i = 0; i < this.neighbours.size(); i++){
System.out.print(this.neighbours.get(i).name + ", ");
>>>>>>> some improvements
}
System.out.println();
}
<<<<<<< HEAD
}
=======
}
>>>>>>> some improvements

View File

@ -7,23 +7,7 @@ import java.util.Random;
public class Peer {
private Node node;
<<<<<<< HEAD
/**
* Create another peer, mutually link creator and spawn.
*/
public void spawn() {
}
/**
* Circularly link all neighbours, remove itself form all neighbours and
* exit.
*/
public void leave() {
=======
public Peer(String name){
this.node = new Node(new Random().nextInt(), name);
@ -34,7 +18,9 @@ public class Peer {
}
//create another peer, mutually link creator and spawn
/**
* Create another peer, mutually link creator and spawn.
*/
public void spawn(String name){
//create a new node
Node spawnNode = new Node(new Random().nextInt(), name);
@ -46,7 +32,10 @@ public class Peer {
}
//circularly link all neighbours, remove itself form all neighbours and exit
/**
* Circularly link all neighbours, remove itself form all neighbours and
* exit.
*/
public void leave(){
List<Node> neighbours = this.node.getNeighbours();
@ -56,7 +45,6 @@ public class Peer {
//remove itself
neighbours.get(i).removeNeighbour(this.node);
}
>>>>>>> some improvements
}