1 package org.opentrafficsim.core.network;
2
3 import java.io.Serializable;
4 import java.rmi.RemoteException;
5 import java.util.HashSet;
6 import java.util.Set;
7
8 import javax.media.j3d.BoundingSphere;
9 import javax.media.j3d.Bounds;
10 import javax.vecmath.Point3d;
11
12 import nl.tudelft.simulation.dsol.animation.LocatableInterface;
13 import nl.tudelft.simulation.language.d3.DirectedPoint;
14
15 import org.opentrafficsim.core.unit.AnglePlaneUnit;
16 import org.opentrafficsim.core.unit.AngleSlopeUnit;
17 import org.opentrafficsim.core.value.vdouble.scalar.DoubleScalar;
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32 public abstract class AbstractNode<ID, P> implements Node<ID, P>, LocatableInterface, Serializable
33 {
34
35 private static final long serialVersionUID = 20140920L;
36
37
38 private final ID id;
39
40
41 private final P point;
42
43
44 private final DoubleScalar.Abs<AnglePlaneUnit> direction;
45
46
47 private final DoubleScalar.Abs<AngleSlopeUnit> slope;
48
49
50 private final Set<Link<?, ? extends Node<ID, P>>> linksIn = new HashSet<Link<?, ? extends Node<ID, P>>>();
51
52
53 private final Set<Link<?, ? extends Node<ID, P>>> linksOut = new HashSet<Link<?, ? extends Node<ID, P>>>();
54
55
56
57
58
59
60
61
62 public AbstractNode(final ID id, final P point, final DoubleScalar.Abs<AnglePlaneUnit> direction,
63 final DoubleScalar.Abs<AngleSlopeUnit> slope)
64 {
65 this.id = id;
66 this.point = point;
67 this.direction = direction;
68 this.slope = slope;
69 }
70
71
72
73
74
75
76 public AbstractNode(final ID id, final P point)
77 {
78 this(id, point, new DoubleScalar.Abs<AnglePlaneUnit>(0.0, AnglePlaneUnit.SI), new DoubleScalar.Abs<AngleSlopeUnit>(
79 0.0, AngleSlopeUnit.SI));
80 }
81
82
83
84
85 public final ID getId()
86 {
87 return this.id;
88 }
89
90
91
92
93 public final P getPoint()
94 {
95 return this.point;
96 }
97
98
99
100
101 public abstract double getX();
102
103
104
105
106 public abstract double getY();
107
108
109
110
111 public abstract double getZ();
112
113
114 @Override
115 public final void addLinkIn(final Link<?, ? extends Node<ID, P>> linkIn)
116 {
117 this.linksIn.add(linkIn);
118 }
119
120
121 @Override
122 public final void addLinkOut(final Link<?, ? extends Node<ID, P>> linkOut)
123 {
124 this.linksOut.add(linkOut);
125 }
126
127
128 @Override
129 public final Set<Link<?, ? extends Node<ID, P>>> getLinksIn()
130 {
131
132 return this.linksIn;
133 }
134
135
136 @Override
137 public final Set<Link<?, ? extends Node<ID, P>>> getLinksOut()
138 {
139
140 return this.linksOut;
141 }
142
143
144
145
146 public final DoubleScalar.Abs<AnglePlaneUnit> getDirection()
147 {
148 return this.direction;
149 }
150
151
152
153
154 public final DoubleScalar.Abs<AngleSlopeUnit> getSlope()
155 {
156 return this.slope;
157 }
158
159
160 @Override
161 public final DirectedPoint getLocation() throws RemoteException
162 {
163 return new DirectedPoint(new double[] {getX(), getY(), getZ()});
164 }
165
166
167 @Override
168 public final Bounds getBounds() throws RemoteException
169 {
170 return new BoundingSphere(new Point3d(0.0d, 0.0d, 0.0d), 10.0d);
171 }
172
173
174 public final String toString()
175 {
176 return "Node " + this.id;
177 }
178
179
180 @Override
181 @SuppressWarnings("checkstyle:designforextension")
182 public int hashCode()
183 {
184 final int prime = 31;
185 int result = 1;
186 result = prime * result + ((this.id == null) ? 0 : this.id.hashCode());
187 return result;
188 }
189
190
191 @Override
192 @SuppressWarnings({"checkstyle:designforextension", "checkstyle:needbraces"})
193 public boolean equals(final Object obj)
194 {
195 if (this == obj)
196 return true;
197 if (obj == null)
198 return false;
199 if (getClass() != obj.getClass())
200 return false;
201 @SuppressWarnings("unchecked")
202 AbstractNode<ID, P> other = (AbstractNode<ID, P>) obj;
203 if (this.id == null)
204 {
205 if (other.id != null)
206 return false;
207 }
208 else if (!this.id.equals(other.id))
209 return false;
210 return true;
211 }
212
213 }