-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathNode.java
More file actions
82 lines (68 loc) · 1.8 KB
/
Copy pathNode.java
File metadata and controls
82 lines (68 loc) · 1.8 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
import java.security.SecureRandom;
import java.util.ArrayList;
public class Node implements Comparable
{
// instance variables - replace the example below with your own
private ArrayList<Node> outgoingNodes;
public int id;
private int shift;
public static SecureRandom randGenerator;
/**
* Constructor for objects of class Node
*/
public Node(int newId, boolean isLast)
{
// initialize instance variables
id=newId;
outgoingNodes=new ArrayList<Node>();
//shift=random number 0-25
randGenerator=new SecureRandom();
shift=randGenerator.nextInt(26)+1; //length of accepted alphabet
//will add initial edge from main class after next node is created (unless isLast=false)
}
/**
* An example of a method - replace this comment with your own
*
* @param n a new Node to connect to
*/
public void addEdge(Node n)
{
// put your code here
outgoingNodes.add(n);
}
/**
* An example of a method - replace this comment with your own
*
* @return id the ID of this node
*/
public int getId(){
return id;
}
public int getShift(){
return shift;
}
public String toString() {
String s = "";
s += id+": "+shift;
return s;
}
@Override
public int compareTo(Object arg0) {
int compareId = ((Node)arg0).getId();
return this.id - compareId;
}
//traverse the list of nodes
public Node nextNode(int argID)
{
for(Node tempNode: outgoingNodes){
if(tempNode.getId() == argID)
{
return tempNode;
}
}
return new Node(0,false);
}
/*public int compareTo(Node n){
return this.id-n.id;
}*/
}