-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathBreadcrumb.java
More file actions
66 lines (56 loc) · 1.61 KB
/
Breadcrumb.java
File metadata and controls
66 lines (56 loc) · 1.61 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
package graphql.util;
import graphql.PublicApi;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;
import java.util.Objects;
import java.util.StringJoiner;
/**
* A specific {@link NodeLocation} inside a node. This means {@link #getNode()} returns a Node which has a child
* at {@link #getLocation()}
* <p>
* A list of Breadcrumbs is used to identify the exact location of a specific node inside a tree.
*
* @param <T> the generic type of object
*/
@PublicApi
@NullMarked
public class Breadcrumb<T> {
private final T node;
private final NodeLocation location;
public Breadcrumb(T node, NodeLocation location) {
this.node = node;
this.location = location;
}
public T getNode() {
return node;
}
public NodeLocation getLocation() {
return location;
}
@Override
public boolean equals(@Nullable Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Breadcrumb<?> that = (Breadcrumb<?>) o;
return Objects.equals(node, that.node) &&
Objects.equals(location, that.location);
}
@Override
public int hashCode() {
int result = 1;
result = 31 * result + Objects.hashCode(node);
result = 31 * result + Objects.hashCode(location);
return result;
}
@Override
public String toString() {
return new StringJoiner(", ", "[", "]")
.add("" + location)
.add("" + node)
.toString();
}
}