-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStation.java
More file actions
99 lines (83 loc) · 2.16 KB
/
Station.java
File metadata and controls
99 lines (83 loc) · 2.16 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
98
99
import java.util.List;
import java.util.LinkedList;
import java.util.Set;
import java.util.HashSet;
public class Station implements Linkable {
private String name;
private List<Linkable> next;
private int nbPrevious;
private Set<String> components;
public Station() {
this.next = new LinkedList<>();
this.components = new HashSet<>();
}
public Station(String name) {
this();
this.name = name;
}
@Override
public String getName() {
return this.name;
}
@Override
public int getSizeNext() {
return this.next.size() + this.nbPrevious;
}
@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)) {
Station s = (Station)another;
this.next.add(s);
s.incNbPrevious();
}
}
@Override
public void linkBtw(Linkable another) {
Station s = (Station)another;
if (!this.getListNext().contains(another)) {
this.next.add(s);
}
if (!another.getListNext().contains(this)) {
s.getListNext().add(this);
}
}
@Override
public void addComponent(String line) {
this.components.add(line);
}
@Override
public List<Linkable> getListNext(){
return this.next;
}
@Override
public Set<String> getComponents() {
return this.components;
}
public void incNbPrevious() {
this.nbPrevious++;
}
@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();
}
}