File size: 3,182 Bytes
7a30ee6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
import java.util.ArrayList;
public class Node implements Comparable<Node> {
private int x, y;
private Node parent;
private boolean isRoot = false;
private boolean isTreeRoot = false;
public final ArrayList<Node> children;
public ArrayList<Node> neighbours;
private int cost = Integer.MAX_VALUE;
private int color;
private Segment segment;
private boolean isEdge = false;
private ArrayList<Edge> edges;
private Centroid belongsToCentroid;
private String hash;
private boolean closed = false;
Node(int x, int y, int c) {
this.x = x;
this.y = y;
this.color = c;
this.hash = hashNode();
this.children = new ArrayList<>();
this.edges = new ArrayList<>();
}
public boolean isClosed() {
return closed;
}
public void setClosed(boolean closed) {
this.closed = closed;
}
private int concatenate() {
return Integer.parseInt((int) this.x + "" + (int) this.y);
}
@Override
public int hashCode() {
return concatenate();
}
public void setCost(int cost) {
this.cost = cost;
}
public ArrayList<Node> getChildren() {
return children;
}
public void addChild(Node child) {
synchronized(this.children) {
this.children.add(child);
}
}
public int getColor() {
return color;
}
public void setColor(int c) {
this.color = c;
}
@Override
public int compareTo(Node o) {
return Double.compare(this.getCost(), o.getCost());
}
public String hashNode() {
return "" + this.x + "" + this.y;
}
public int getX() {
return x;
}
public int getY() {
return y;
}
public double getCost() {
return cost;
}
public void setCost(double cost) {
this.cost = (int) cost;
}
public Centroid getBelongsToCentroid() {
return belongsToCentroid;
}
public void setBelongsToCentroid(Centroid belongsToCentroid) {
this.belongsToCentroid = belongsToCentroid;
}
public ArrayList<Node> getNeighbours() {
return neighbours;
}
public void setNeighbours(ArrayList<Node> neighbours) {
this.neighbours = neighbours;
}
public Node getParent() {
return parent;
}
public void setParent(Node parent) {
this.parent = parent;
}
public boolean isRoot() {
return isRoot;
}
public void setRoot(boolean root) {
isRoot = root;
}
public boolean isTreeRoot() {
return isTreeRoot;
}
public void setTreeRoot(boolean treeRoot) {
isTreeRoot = treeRoot;
}
public ArrayList<Edge> getEdges() {
return edges;
}
public void setEdges(ArrayList<Edge> edges) {
this.edges = edges;
}
public Segment getSegment() {
return segment;
}
public void setSegment(Segment segment) {
this.segment = segment;
}
public boolean isEdge() {
return isEdge;
}
public void setEdge(boolean edge) {
isEdge = edge;
}
}
|