-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathListSection.java
More file actions
54 lines (41 loc) · 1.22 KB
/
ListSection.java
File metadata and controls
54 lines (41 loc) · 1.22 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
package ru.javaops.webapp.model;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
public class ListSection extends AbstractSection {
private static final long serialVersionUID = 1L;
private List<String> strings = new ArrayList<>();
public ListSection() {
}
public ListSection(String... items) {
this(Arrays.asList(items));
}
public ListSection(List<String> strings) {
Objects.requireNonNull(strings, "items must not be null");
this.strings = strings;
}
public List<String> getStrings() {
return strings;
}
public void addString(String string) {
this.strings.add(string);
}
@Override
public String toString() {
StringBuilder str = new StringBuilder();
strings.forEach(s -> str.append(s).append("\n"));
return str.toString();
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ListSection that = (ListSection) o;
return strings.equals(that.strings);
}
@Override
public int hashCode() {
return strings.hashCode();
}
}