This repository was archived by the owner on Feb 29, 2024. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode.java
More file actions
Latest commit
97 lines (95 loc) · 2.03 KB
/
Copy pathnode.java
File metadata and controls
97 lines (95 loc) · 2.03 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
importjava.util.*;
publicclassnode {
privateintid = -1;
privatestaticintnextId = 101;
publicvoidinit() {
this.id = nextId;
nextId++;
}
ArrayList<node> connectedNodes;
publicnode() {
init();
this.connectedNodes = newArrayList<node>(0);
}
publicnode(noden) {
init();
this.connectedNodes = newArrayList<node>(1);
this.connectedNodes.add(n);
}
publicvoidconnect(noden) {
this.connectedNodes.add(n);
}
publicArrayList<node> getChildNodes(){
returnthis.connectedNodes;
}
publicintgraphId;
publicvoidsetId(intid) {
this.graphId = id;
}
publicnodesetid(intid) {
this.graphId = id;
returnthis;
}
publicintgetId() {
returnthis.graphId;
}
publicintgetUniqueId() {
returnthis.id;
}
/* Diff mode settings
* 0 - compare by id
* 1 - compare by unique id
* 2 - Compare by connected nodes
*/
publicstaticintdiffmode = 0;
@Override
publicbooleanequals(Objectobj) {
if(objinstanceofnode) {
nodee = (node) obj;
if(diffmode == 0) {
return (this.getId() == e.getId());
}elseif(diffmode == 1) {
return (this.getUniqueId() == e.getUniqueId());
}elseif(diffmode == 2) {
return (this.connectedNodes.equals(e.connectedNodes));
}
}else {
returnfalse;
}
returnfalse;
}
publicvoidlinkNode(noden) {
this.connectedNodes.add(n);
}
publicnodeaddChild(noden) {
this.linkNode(n);
returnthis;
}
@Override
publicStringtoString() {
StringBuildersb = newStringBuilder("node(");
sb.append("id = ");
sb.append(this.graphId);
sb.append(", uniqueId = ");
sb.append(this.getUniqueId());
sb.append(", children = ");
sb.append(this.connectedNodes.toString());
sb.append(" )");
returnsb.toString();
}
privatebooleanvisited;
publicvoidreset() {
this.visited = false;
}
publicvoidvisit() {
this.visited = true;
}
publicbooleanisvisited() {
returnthis.visited;
}
publicstaticvoidmain(String[] args) {
// TODO Auto-generated method stub
node.diffmode = 0;
System.out.println((newnode()).addChild(newnode()));
}
}