[9759] | 1 | // License: GPL. For details, see LICENSE file.
|
---|
| 2 | package org.openstreetmap.josm.data.preferences;
|
---|
| 3 |
|
---|
| 4 | import java.util.ArrayList;
|
---|
| 5 | import java.util.Collections;
|
---|
| 6 | import java.util.LinkedHashMap;
|
---|
| 7 | import java.util.List;
|
---|
| 8 | import java.util.Map;
|
---|
| 9 |
|
---|
| 10 | /**
|
---|
| 11 | * Setting containing a {@link List} of {@link Map}s of {@link String} values.
|
---|
| 12 | * @since 9759
|
---|
| 13 | */
|
---|
| 14 | public class MapListSetting extends AbstractSetting<List<Map<String, String>>> {
|
---|
| 15 |
|
---|
| 16 | /**
|
---|
| 17 | * Constructs a new {@code MapListSetting} with the given value
|
---|
| 18 | * @param value The setting value
|
---|
| 19 | */
|
---|
| 20 | public MapListSetting(List<Map<String, String>> value) {
|
---|
| 21 | super(value);
|
---|
| 22 | consistencyTest();
|
---|
| 23 | }
|
---|
| 24 |
|
---|
| 25 | @Override
|
---|
| 26 | public MapListSetting copy() {
|
---|
| 27 | if (value == null)
|
---|
| 28 | return new MapListSetting(null);
|
---|
| 29 | List<Map<String, String>> copy = new ArrayList<>(value.size());
|
---|
| 30 | for (Map<String, String> map : value) {
|
---|
| 31 | Map<String, String> mapCopy = new LinkedHashMap<>(map);
|
---|
| 32 | copy.add(Collections.unmodifiableMap(mapCopy));
|
---|
| 33 | }
|
---|
| 34 | return new MapListSetting(Collections.unmodifiableList(copy));
|
---|
| 35 | }
|
---|
| 36 |
|
---|
| 37 | private void consistencyTest() {
|
---|
| 38 | if (value == null)
|
---|
| 39 | return;
|
---|
| 40 | if (value.contains(null))
|
---|
[10235] | 41 | throw new IllegalArgumentException("Error: Null as list element in preference setting");
|
---|
[9759] | 42 | for (Map<String, String> map : value) {
|
---|
[11461] | 43 | if (map.containsKey(null))
|
---|
[10235] | 44 | throw new IllegalArgumentException("Error: Null as map key in preference setting");
|
---|
[11461] | 45 | if (map.containsValue(null))
|
---|
[10235] | 46 | throw new IllegalArgumentException("Error: Null as map value in preference setting");
|
---|
[9759] | 47 | }
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | @Override
|
---|
| 51 | public void visit(SettingVisitor visitor) {
|
---|
| 52 | visitor.visit(this);
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | @Override
|
---|
| 56 | public MapListSetting getNullInstance() {
|
---|
| 57 | return new MapListSetting(null);
|
---|
| 58 | }
|
---|
| 59 | }
|
---|