-
Notifications
You must be signed in to change notification settings - Fork 0
/
Node.java
52 lines (44 loc) · 1.35 KB
/
Node.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
47
48
49
50
51
52
/**
Represent a node that holds...
o cargo of interest to the user
o reference to the next node in the list
*/
public class Node {
private Object cargoReference;
private Node referenceToNextNode;
/**
Construct an instance
*/
public Node( Object cargoReference) {
this.cargoReference = cargoReference;
}
public Node( Object cargoReference, Node referenceToNextNode) {
this(cargoReference);
this.referenceToNextNode = referenceToNextNode;
}
/**
@return a string representation of this instance
*/
public String toString() {
String result =
cargoReference.toString() // polymorphically use appropriately toString!
+ " id " // include a usually-unique identifier for this node
+ super.toString()
;
// Show rest of chain of nodes
if( referenceToNextNode == null)
result += " [no next]";
else result += " --> " + referenceToNextNode;
return result;
}
// classic accessor and mutator
public Node getReferenceToNextNode() {
return referenceToNextNode;
}
public void setReferenceToNextNode( Node referenceToNextNode) {
this.referenceToNextNode = referenceToNextNode;
}
public Object getCargoReference() {
return cargoReference;
}
}