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