001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.data.preferences; 003 004import java.util.ArrayList; 005import java.util.Collection; 006import java.util.Collections; 007import java.util.List; 008 009import org.openstreetmap.josm.tools.Utils; 010 011/** 012 * Setting containing a {@link List} of {@link String} values. 013 * @since 9759 014 */ 015public class ListSetting extends AbstractSetting<List<String>> { 016 /** 017 * Constructs a new {@code ListSetting} with the given value 018 * @param value The setting value 019 */ 020 public ListSetting(List<String> value) { 021 super(value); 022 consistencyTest(); 023 } 024 025 /** 026 * Convenience factory method. 027 * @param value the value 028 * @return a corresponding ListSetting object 029 */ 030 public static ListSetting create(Collection<String> value) { 031 return new ListSetting(value == null ? null : Collections.unmodifiableList(new ArrayList<>(value))); 032 } 033 034 @Override 035 public boolean equalVal(List<String> otherVal) { 036 return Utils.equalCollection(value, otherVal); 037 } 038 039 @Override 040 public ListSetting copy() { 041 return ListSetting.create(value); 042 } 043 044 private void consistencyTest() { 045 if (value != null && value.contains(null)) 046 throw new IllegalArgumentException("Error: Null as list element in preference setting"); 047 } 048 049 @Override 050 public void visit(SettingVisitor visitor) { 051 visitor.visit(this); 052 } 053 054 @Override 055 public ListSetting getNullInstance() { 056 return new ListSetting(null); 057 } 058 059 @Override 060 public boolean equals(Object other) { 061 if (!(other instanceof ListSetting)) 062 return false; 063 return equalVal(((ListSetting) other).getValue()); 064 } 065}