-
-
Notifications
You must be signed in to change notification settings - Fork 55
/
NodeUsage.java
46 lines (38 loc) · 938 Bytes
/
NodeUsage.java
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
package net.citizensnpcs.api.util.prtree;
/**
* A node used while building the leaf sets, holds the actual data and an identifier for the partition this node belongs
* to.
*
* @param <T>
* the data type of the stored item
*/
class NodeUsage<T> {
private final T data;
private int id;
public NodeUsage(T data, int id) {
this.data = data;
this.id = id;
}
public void changeOwner(int id) {
this.id = id;
}
public T getData() {
return data;
}
public int getOwner() {
return id;
}
public boolean isUsed() {
return id < 0;
}
@Override
public String toString() {
return getClass().getSimpleName() + "{data: " + data + ", id: " + id + "}";
}
public void use() {
if (id >= 0)
id = -id;
else
throw new RuntimeException("Trying to use already used node");
}
}