-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathPath.java
More file actions
82 lines (70 loc) · 1.99 KB
/
Path.java
File metadata and controls
82 lines (70 loc) · 1.99 KB
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
package tesseract.graph;
import it.unimi.dsi.fastutil.longs.Long2ObjectLinkedOpenHashMap;
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
import it.unimi.dsi.fastutil.longs.Long2ObjectMaps;
import tesseract.api.IConnectable;
import tesseract.util.Node;
import java.util.Deque;
import java.util.Iterator;
/**
* The Path is a class that should work with paths for grids.
*/
public class Path<C extends IConnectable> {
private final Node origin;
private final Node target;
private final Long2ObjectMap<C> full = new Long2ObjectLinkedOpenHashMap<>();
private final Long2ObjectMap<C> cross = new Long2ObjectLinkedOpenHashMap<>();
/**
* Creates a path instance.
*
* @param connectors The connectors array.
* @param path The path queue.
*/
protected Path(Long2ObjectMap<Cache<C>> connectors, Deque<Node> path) {
origin = path.pollLast();
target = path.pollFirst();
Iterator<Node> it = path.descendingIterator();
while (it.hasNext()) {
Node node = it.next();
long pos = node.asLong();
Cache<C> cache = connectors.get(pos);
if (cache != null) {
C cable = cache.value();
full.put(pos, cable);
if (node.isCrossroad()) {
cross.put(pos, cable);
}
}
}
}
/**
* @return Gets the origin position.
*/
public Node origin() {
return origin;
}
/**
* @return Gets the target position.
*/
public Node target() {
return target;
}
/**
* @return Gets the full connectors path.
*/
public Long2ObjectMap<C> getFull() {
return full;
}
/**
* @return Gets the crossroad connectors path.
*/
public Long2ObjectMap<C> getCross() {
return cross;
}
/**
* @return Checks that the path is empty.
*/
public boolean isEmpty() {
return (origin == null || target == null);
}
}