- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPerson.java
More file actions
Latest commit
97 lines (78 loc) · 2 KB
/
Copy pathPerson.java
File metadata and controls
97 lines (78 loc) · 2 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.LinkedList;
importjava.util.List;
importjava.util.Set;
importjava.util.HashSet;
publicclassPersonimplementsLinkable{
privateStringname;
privateList<Linkable> next;
privateSet<String> components;
publicPerson() {
this.next = newLinkedList<>();
this.components = newHashSet<>();
}
publicPerson(Stringname) {
this();
this.name = name;
}
@Override
publicStringgetName() {
returnthis.name;
}
@Override
publicintgetSizeNext() {
returnthis.next.size();
}
@Override
publicvoidsetName(Stringname) {
this.name = name;
}
@Override
publicStationcopy() {
Stationanother = newStation(this.name);
returnanother;
}
@Override
publicvoidlinkTo(Linkableanother) {
if (!this.getListNext().contains(another)) {
Personp = (Person)another;
this.next.add(p);
}
}
@Override
publicvoidlinkBtw(Linkableanother) {
Personp = (Person)another;
if (!this.getListNext().contains(another)) {
this.linkTo(p);
}
if (!another.getListNext().contains(this)) {
p.linkTo(this);
}
}
@Override
publicvoidaddComponent(Stringcomponent) {
this.components.add(component);
}
@Override
publicList<Linkable> getListNext(){
returnthis.next;
}
@Override
publicSet<String> getComponents() {
returnthis.components;
}
@Override
publicStringtoString() {
returnthis.getName();
}
@Override
publicbooleanequals(Objectanother){
if (!this.getClass().equals(another.getClass())) {
returnfalse;
}
returnthis.name.equals(another.toString());
}
@Override
publicinthashCode() {
returnthis.name.hashCode();
}
}