1 package org.opentrafficsim.core.network;
2
3 import java.io.Serializable;
4
5 import org.djunits.value.vdouble.scalar.Length;
6 import org.opentrafficsim.core.gtu.GTUDirectionality;
7
8
9
10
11
12
13
14
15
16
17
18
19 public class LinkDirection implements Serializable
20 {
21
22 private static final long serialVersionUID = 20150000L;
23
24
25 private final Link link;
26
27
28 private final GTUDirectionality direction;
29
30
31
32
33
34 public LinkDirection(final Link link, final GTUDirectionality direction)
35 {
36 super();
37 this.link = link;
38 this.direction = direction;
39 }
40
41
42
43
44 public final Link getLink()
45 {
46 return this.link;
47 }
48
49
50
51
52
53 public String getId()
54 {
55 return this.link.getId();
56 }
57
58
59
60
61
62 public LinkType getLinkType()
63 {
64 return this.link.getLinkType();
65 }
66
67
68
69
70
71 public Length getLength()
72 {
73 return this.link.getLength();
74 }
75
76
77
78
79 public final GTUDirectionality getDirection()
80 {
81 return this.direction;
82 }
83
84
85
86
87 public final Node getNodeTo()
88 {
89 return this.direction.equals(GTUDirectionality.DIR_PLUS) ? this.link.getEndNode() : this.link.getStartNode();
90 }
91
92
93
94
95 public final Node getNodeFrom()
96 {
97 return this.direction.equals(GTUDirectionality.DIR_PLUS) ? this.link.getStartNode() : this.link.getEndNode();
98 }
99
100
101 @Override
102 public int hashCode()
103 {
104 final int prime = 31;
105 int result = 1;
106 result = prime * result + ((this.direction == null) ? 0 : this.direction.hashCode());
107 result = prime * result + ((this.link == null) ? 0 : this.link.hashCode());
108 return result;
109 }
110
111
112 @Override
113 public boolean equals(final Object obj)
114 {
115 if (this == obj)
116 {
117 return true;
118 }
119 if (obj == null)
120 {
121 return false;
122 }
123 if (getClass() != obj.getClass())
124 {
125 return false;
126 }
127 LinkDirection other = (LinkDirection) obj;
128 if (this.direction != other.direction)
129 {
130 return false;
131 }
132 if (this.link == null)
133 {
134 if (other.link != null)
135 {
136 return false;
137 }
138 }
139 else if (!this.link.equals(other.link))
140 {
141 return false;
142 }
143 return true;
144 }
145
146
147 @Override
148 public String toString()
149 {
150 return "LinkDirection [link=" + this.link + ", direction=" + this.direction + "]";
151 }
152 }