Graphen/Node.java

71 lines
1.7 KiB
Java

import java.util.ArrayList;
public class Node implements Comparable
{
private int number;
private ArrayList<Edge> edges;
public int entfernung;
public Node vorgaenger;
public boolean bearbeitet;
public int x;
public int y;
public Node(int n){
this.number = n;
this.edges = new ArrayList<Edge>();
entfernung = -1;
vorgaenger = null;
}
public Node(int n, int x, int y){
this.number = n;
this.x = x;
this.y = y;
this.edges = new ArrayList<Edge>();
entfernung = -1;
vorgaenger = null;
}
public int getNumber (){return this.number;}
public void addEdge(Edge e){
this.edges.add(e);
}
public ArrayList<Node> getTargets(){
ArrayList<Node> t= new ArrayList<Node>();
for (Edge e : this.edges){
if(e.getAnfang()== this){
t.add(e.getEnde());
}
else if (!e.istGerichtet()){
t.add(e.getAnfang());
}
}
return t;
}
public ArrayList<Edge> getEdges(){
ArrayList<Edge> t= new ArrayList<Edge>();
for (Edge e : this.edges){
if(e.getAnfang()== this){
t.add(e);
}
else if (!e.istGerichtet()){
t.add(e);
}
}
return t;
}
public int compareTo(Object o) {
Node other = (Node)o;
if(this.number < other.number)return -1;
if(this.number > other.number)return 1;
return 0;
}
public String toString(){
return "N " + this.number + " " + this.x + " " + this.y;
}
}