1 | package dk.deepthought.sidious.planner.graph; |
2 | |
3 | import dk.deepthought.sidious.supportsystem.Step; |
4 | |
5 | /** |
6 | * This class represent an edge in an A*-graph. |
7 | * |
8 | * @author Deepthought |
9 | * |
10 | */ |
11 | public final class AStarEdge implements Edge { |
12 | |
13 | /** |
14 | * The start vertex. |
15 | */ |
16 | private final Vertex startVertex; |
17 | |
18 | /** |
19 | * The end vertex. |
20 | */ |
21 | private final Vertex endVertex; |
22 | |
23 | /** |
24 | * The cost of this edge. |
25 | */ |
26 | private final double cost; |
27 | |
28 | /** |
29 | * The step of to this edge. |
30 | */ |
31 | private final Step step; |
32 | |
33 | /** |
34 | * @param startVertex |
35 | * a vertex defining the startpoint of this edge |
36 | * @param endVertex |
37 | * a vertex defining the endpoint of this edge |
38 | * @param step |
39 | * the origin of this edge |
40 | * @param cost |
41 | * the weight of this edge |
42 | */ |
43 | public AStarEdge(Vertex startVertex, Vertex endVertex, Step step, |
44 | double cost) { |
45 | this.startVertex = startVertex; |
46 | this.endVertex = endVertex; |
47 | this.step = step; |
48 | this.cost = cost; |
49 | } |
50 | |
51 | /* |
52 | * (non-Javadoc) |
53 | * |
54 | * @see dk.deepthought.sidious.planner.Edge#getCost() |
55 | */ |
56 | public double getCost() { |
57 | return cost; |
58 | } |
59 | |
60 | /* |
61 | * (non-Javadoc) |
62 | * |
63 | * @see dk.deepthought.sidious.planner.Edge#getEndVertex() |
64 | */ |
65 | public Vertex getEndVertex() { |
66 | return endVertex; |
67 | } |
68 | |
69 | /* |
70 | * (non-Javadoc) |
71 | * |
72 | * @see dk.deepthought.sidious.planner.Edge#getStartVertex() |
73 | */ |
74 | public Vertex getStartVertex() { |
75 | return startVertex; |
76 | } |
77 | |
78 | /* |
79 | * (non-Javadoc) |
80 | * |
81 | * @see dk.deepthought.sidious.planner.Edge#getStep() |
82 | */ |
83 | public Step getStep() { |
84 | return step; |
85 | } |
86 | |
87 | /* |
88 | * (non-Javadoc) |
89 | * |
90 | * @see java.lang.Object#toString() |
91 | */ |
92 | @Override |
93 | public String toString() { |
94 | return getClass().getSimpleName() + "[step=" + step + "]"; |
95 | } |
96 | |
97 | /* |
98 | * (non-Javadoc) |
99 | * |
100 | * @see java.lang.Object#hashCode() |
101 | */ |
102 | @Override |
103 | public int hashCode() { |
104 | final int PRIME = 31; |
105 | int result = 1; |
106 | long temp; |
107 | temp = Double.doubleToLongBits(cost); |
108 | result = PRIME * result + (int) (temp ^ (temp >>> 32)); |
109 | result = PRIME * result |
110 | + ((endVertex == null) ? 0 : endVertex.hashCode()); |
111 | result = PRIME * result |
112 | + ((startVertex == null) ? 0 : startVertex.hashCode()); |
113 | result = PRIME * result + ((step == null) ? 0 : step.hashCode()); |
114 | return result; |
115 | } |
116 | |
117 | /* |
118 | * (non-Javadoc) |
119 | * |
120 | * @see java.lang.Object#equals(java.lang.Object) |
121 | */ |
122 | @Override |
123 | public boolean equals(Object obj) { |
124 | if (this == obj) |
125 | return true; |
126 | if (obj == null) |
127 | return false; |
128 | if (getClass() != obj.getClass()) |
129 | return false; |
130 | final AStarEdge other = (AStarEdge) obj; |
131 | if (Double.doubleToLongBits(cost) != Double |
132 | .doubleToLongBits(other.cost)) |
133 | return false; |
134 | if (endVertex == null) { |
135 | if (other.endVertex != null) |
136 | return false; |
137 | } else if (!endVertex.equals(other.endVertex)) |
138 | return false; |
139 | if (startVertex == null) { |
140 | if (other.startVertex != null) |
141 | return false; |
142 | } else if (!startVertex.equals(other.startVertex)) |
143 | return false; |
144 | if (step == null) { |
145 | if (other.step != null) |
146 | return false; |
147 | } else if (!step.equals(other.step)) |
148 | return false; |
149 | return true; |
150 | } |
151 | } |