1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.mappaint;
|
---|
3 |
|
---|
4 | import java.util.ArrayList;
|
---|
5 | import java.util.Arrays;
|
---|
6 | import java.util.Collection;
|
---|
7 | import java.util.Iterator;
|
---|
8 | import java.util.List;
|
---|
9 | import java.util.Objects;
|
---|
10 |
|
---|
11 | import org.openstreetmap.josm.gui.mappaint.styleelement.StyleElement;
|
---|
12 |
|
---|
13 | /**
|
---|
14 | * List of {@link StyleElement}s, immutable.
|
---|
15 | */
|
---|
16 | public class StyleElementList implements Iterable<StyleElement> {
|
---|
17 | private final List<StyleElement> lst;
|
---|
18 |
|
---|
19 | /**
|
---|
20 | * Constructs a new {@code StyleList}.
|
---|
21 | */
|
---|
22 | public StyleElementList() {
|
---|
23 | lst = new ArrayList<>();
|
---|
24 | }
|
---|
25 |
|
---|
26 | /**
|
---|
27 | * Create a new List of style elements
|
---|
28 | * @param init The list
|
---|
29 | */
|
---|
30 | public StyleElementList(StyleElement... init) {
|
---|
31 | lst = new ArrayList<>(Arrays.asList(init));
|
---|
32 | }
|
---|
33 |
|
---|
34 | /**
|
---|
35 | * Create a new List of style elements
|
---|
36 | * @param sl The list
|
---|
37 | */
|
---|
38 | public StyleElementList(Collection<StyleElement> sl) {
|
---|
39 | lst = new ArrayList<>(sl);
|
---|
40 | }
|
---|
41 |
|
---|
42 | /**
|
---|
43 | * Create a new List of style elements
|
---|
44 | * @param sl The list
|
---|
45 | * @param s An item to merge to the list
|
---|
46 | */
|
---|
47 | public StyleElementList(StyleElementList sl, StyleElement s) {
|
---|
48 | lst = new ArrayList<>(sl.lst);
|
---|
49 | lst.add(s);
|
---|
50 | }
|
---|
51 |
|
---|
52 | @Override
|
---|
53 | public Iterator<StyleElement> iterator() {
|
---|
54 | return lst.iterator();
|
---|
55 | }
|
---|
56 |
|
---|
57 | /**
|
---|
58 | * Check if the list is empty
|
---|
59 | * @return <code>true</code> if it is empty
|
---|
60 | */
|
---|
61 | public boolean isEmpty() {
|
---|
62 | return lst.isEmpty();
|
---|
63 | }
|
---|
64 |
|
---|
65 | /**
|
---|
66 | * Get the list size
|
---|
67 | * @return The list size
|
---|
68 | */
|
---|
69 | public int size() {
|
---|
70 | return lst.size();
|
---|
71 | }
|
---|
72 |
|
---|
73 | @Override
|
---|
74 | public String toString() {
|
---|
75 | return lst.toString();
|
---|
76 | }
|
---|
77 |
|
---|
78 | @Override
|
---|
79 | public boolean equals(Object obj) {
|
---|
80 | if (this == obj) return true;
|
---|
81 | if (obj == null || getClass() != obj.getClass()) return false;
|
---|
82 | StyleElementList that = (StyleElementList) obj;
|
---|
83 | return Objects.equals(lst, that.lst);
|
---|
84 | }
|
---|
85 |
|
---|
86 | @Override
|
---|
87 | public int hashCode() {
|
---|
88 | return Objects.hash(lst);
|
---|
89 | }
|
---|
90 | }
|
---|