-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPerson.java
97 lines (78 loc) · 2 KB
/
Person.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
89
90
91
92
93
94
95
96
97
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.HashSet;
public class Person implements Linkable{
private String name;
private List<Linkable> next;
private Set<String> components;
public Person() {
this.next = new LinkedList<>();
this.components = new HashSet<>();
}
public Person(String name) {
this();
this.name = name;
}
@Override
public String getName() {
return this.name;
}
@Override
public int getSizeNext() {
return this.next.size();
}
@Override
public void setName(String name) {
this.name = name;
}
@Override
public Station copy() {
Station another = new Station(this.name);
return another;
}
@Override
public void linkTo(Linkable another) {
if (!this.getListNext().contains(another)) {
Person p = (Person)another;
this.next.add(p);
}
}
@Override
public void linkBtw(Linkable another) {
Person p = (Person)another;
if (!this.getListNext().contains(another)) {
this.linkTo(p);
}
if (!another.getListNext().contains(this)) {
p.linkTo(this);
}
}
@Override
public void addComponent(String component) {
this.components.add(component);
}
@Override
public List<Linkable> getListNext(){
return this.next;
}
@Override
public Set<String> getComponents() {
return this.components;
}
@Override
public String toString() {
return this.getName();
}
@Override
public boolean equals(Object another){
if (!this.getClass().equals(another.getClass())) {
return false;
}
return this.name.equals(another.toString());
}
@Override
public int hashCode() {
return this.name.hashCode();
}
}