1 package org.opentrafficsim.road.network.lane.conflict;
2
3 import java.util.HashMap;
4 import java.util.HashSet;
5 import java.util.Map;
6 import java.util.Set;
7
8 import org.opentrafficsim.road.network.lane.CrossSectionLink;
9 import org.opentrafficsim.road.network.lane.Lane;
10
11
12
13
14
15
16
17
18
19
20
21
22 public class LaneCombinationList
23 {
24
25
26 private final Map<Lane, Set<Lane>> map = new HashMap<>();
27
28
29
30
31
32
33 public final void addLinkCombination(final CrossSectionLink link1, final CrossSectionLink link2)
34 {
35 for (Lane lane1 : link1.getLanes())
36 {
37 for (Lane lane2 : link2.getLanes())
38 {
39 addLaneCombination(lane1, lane2);
40 }
41 }
42 }
43
44
45
46
47
48
49 public final void addLaneCombination(final Lane lane1, final Lane lane2)
50 {
51 if (!this.map.containsKey(lane1))
52 {
53 this.map.put(lane1, new HashSet<>());
54 }
55 this.map.get(lane1).add(lane2);
56 if (!this.map.containsKey(lane2))
57 {
58 this.map.put(lane2, new HashSet<>());
59 }
60 this.map.get(lane2).add(lane1);
61 }
62
63
64
65
66
67
68
69 public final boolean contains(final Lane lane1, final Lane lane2)
70 {
71 if (!this.map.containsKey(lane1))
72 {
73 return false;
74 }
75 return this.map.get(lane1).contains(lane2);
76 }
77
78
79 @Override
80 public final String toString()
81 {
82 return "LaneCombinationList [map=" + this.map + "]";
83 }
84
85 }