-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathExchange.java
88 lines (75 loc) · 1.74 KB
/
Exchange.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
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
import java.util.*;
public class Exchange {
int id;
Exchange parent;
ExchangeList childs = new ExchangeList();
MobilePhoneSet mobiles = new MobilePhoneSet();
Exchange(int number) {
id = number;
}
Exchange(){
id = 0;
}
public Exchange parent() {
return parent;
}
public int numChildren() {
return childs.listNumChildren();
}
public boolean isRoot() {
if (parent() == null) return true;
return false;
}
public Boolean isChild(Exchange a){
return childs.listIsMember(a);
}
public RoutingMapTree subtree(int i){
if(this.numChildren() < i)
return null;
RoutingMapTree res = new RoutingMapTree(childList().listNthChild(i));
//res.root = childList().listNthChild(i);
return res;
}
public ExchangeList childList(){
return childs;
}
public MobilePhoneSet residentSet() {
return mobiles;
}
public String printAllMobiles(int n){
return this.residentSet().printAll(n);
}
public boolean equals(Object y) {
if (y == this) return true;
if (y == null) return false;
if (y.getClass() != this.getClass()) return false;
Exchange that = (Exchange) y;
int n=this.id;
if(n==that.id)
return(true);
else
return false;
}
//makes a the child
/*public void makeChild(int a)
{
if(findExchange(a) != null )
Exchange newchild = new Exchange(a);
this.childs.listAddMember(newchild);
newchild.parent = this;
}*/
//Find exchange "a" in all its children
/*public Exchange findExchange(int a){
if(id == a) {
return this;
}
else {
for (int i = 1; i <= this.childList().listNumChildren(); i++) {
Exchange A = this.childList().listNthChild(i).findExchange(a);
if(A != null)
return A;
}
return null;
}
}*/
}