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 public StyleElementList(StyleElement... init) { 027 lst = new ArrayList<>(Arrays.asList(init)); 028 } 029 030 public StyleElementList(Collection<StyleElement> sl) { 031 lst = new ArrayList<>(sl); 032 } 033 034 public StyleElementList(StyleElementList sl, StyleElement s) { 035 lst = new ArrayList<>(sl.lst); 036 lst.add(s); 037 } 038 039 @Override 040 public Iterator<StyleElement> iterator() { 041 return lst.iterator(); 042 } 043 044 public boolean isEmpty() { 045 return lst.isEmpty(); 046 } 047 048 public int size() { 049 return lst.size(); 050 } 051 052 @Override 053 public String toString() { 054 return lst.toString(); 055 } 056 057 @Override 058 public boolean equals(Object obj) { 059 if (obj == null || getClass() != obj.getClass()) { 060 return false; 061 } 062 final StyleElementList other = (StyleElementList) obj; 063 return Objects.equals(lst, other.lst); 064 } 065 066 @Override 067 public int hashCode() { 068 return lst.hashCode(); 069 } 070 071}