001// License: GPL. For details, see LICENSE file.
002package org.openstreetmap.josm.gui.mappaint;
003
004import java.util.ArrayList;
005import java.util.Arrays;
006import java.util.Collection;
007import java.util.Iterator;
008import java.util.List;
009import java.util.Objects;
010
011import org.openstreetmap.josm.gui.mappaint.styleelement.StyleElement;
012
013/**
014 * List of {@link StyleElement}s, immutable.
015 */
016public class StyleElementList implements Iterable<StyleElement> {
017    private final List<StyleElement> lst;
018
019    /**
020     * Constructs a new {@code StyleList}.
021     */
022    public StyleElementList() {
023        lst = new ArrayList<>();
024    }
025
026    /**
027     * Create a new List of style elements
028     * @param init The list
029     */
030    public StyleElementList(StyleElement... init) {
031        lst = new ArrayList<>(Arrays.asList(init));
032    }
033
034    /**
035     * Create a new List of style elements
036     * @param sl The list
037     */
038    public StyleElementList(Collection<StyleElement> sl) {
039        lst = new ArrayList<>(sl);
040    }
041
042    /**
043     * Create a new List of style elements
044     * @param sl The list
045     * @param s An item to merge to the list
046     */
047    public StyleElementList(StyleElementList sl, StyleElement s) {
048        lst = new ArrayList<>(sl.lst);
049        lst.add(s);
050    }
051
052    @Override
053    public Iterator<StyleElement> iterator() {
054        return lst.iterator();
055    }
056
057    /**
058     * Check if the list is empty
059     * @return <code>true</code> if it is empty
060     */
061    public boolean isEmpty() {
062        return lst.isEmpty();
063    }
064
065    /**
066     * Get the list size
067     * @return The list size
068     */
069    public int size() {
070        return lst.size();
071    }
072
073    @Override
074    public String toString() {
075        return lst.toString();
076    }
077
078    @Override
079    public boolean equals(Object obj) {
080        if (this == obj) return true;
081        if (obj == null || getClass() != obj.getClass()) return false;
082        StyleElementList that = (StyleElementList) obj;
083        return Objects.equals(lst, that.lst);
084    }
085
086    @Override
087    public int hashCode() {
088        return Objects.hash(lst);
089    }
090}