-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathTouristsInLine.java
More file actions
92 lines (83 loc) · 2.61 KB
/
TouristsInLine.java
File metadata and controls
92 lines (83 loc) · 2.61 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
package iterator;
import java.util.ArrayList;
import java.util.List;
/**
* @Title: TouristsInLine.java
*
* @Package iterator
*
* @Description: the Tourists in the line, initialized with a line of certain tourists
*
* @author Jiajie
*
* @date 2020/11/24
*/
public class TouristsInLine {
private final List<Tourist> line;
/**
*
* @Description: Constructor
*/
public TouristsInLine() {
line = new ArrayList<Tourist>() {{
add(new Tourist(TouristType.ADULTS, "Jack"));
add(new Tourist(TouristType.CHILDREN, "Peter"));
add(new Tourist(TouristType.MILITARY, "Judy"));
add(new Tourist(TouristType.ELDERLY, "Alice"));
add(new Tourist(TouristType.ADULTS, "Lindsay"));
add(new Tourist(TouristType.CHILDREN, "Victoria"));
add(new Tourist(TouristType.MILITARY, "Ella"));
add(new Tourist(TouristType.ELDERLY, "Ruby"));
add(new Tourist(TouristType.ADULTS, "Nana"));
add(new Tourist(TouristType.CHILDREN, "Delia"));
add(new Tourist(TouristType.MILITARY, "Lisa"));
add(new Tourist(TouristType.ELDERLY, "Winifred"));
add(new Tourist(TouristType.ADULTS, "Teresa"));
add(new Tourist(TouristType.CHILDREN, "Lorraine"));
add(new Tourist(TouristType.ADULTS, "Crystal"));
add(new Tourist(TouristType.ADULTS, "June"));
}};
}
/**
* @Description: get a new TouristInLineIterator instance of a certain type
*
* @param touristType: the tourist type to search
* @return: a new TouristInLineIterator instance of a certain type
*/
public TouristInLineIterator iterator(TouristType touristType) {
return new TouristInLineIterator(this, touristType);
}
/**
* @Description: get the whole line
*
* @return: the whole line of tourists in an ArrayList format
*/
public List<Tourist> getWholeLine() {
return new ArrayList<>(line);
}
/**
* @Description: Clear up the whole line
*
*/
public void clear() {
line.clear();
}
/**
* @Description: append a new tourist to the line
*
* @param touristType: the type of the newcomer
* @param name: the name of the newcomer
*/
public void append(TouristType touristType, String name) {
Tourist tourist = new Tourist(touristType, name);
line.add(tourist);
}
/**
* @Description: get the size of the current line
*
* @return: the size of the current line
*/
public int size() {
return line.size();
}
}