1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.spi.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 12881 (moved from package {@code org.openstreetmap.josm.data.preferences})
|
---|
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))
|
---|
41 | throw new IllegalArgumentException("Error: Null as list element in preference setting");
|
---|
42 | for (Map<String, String> map : value) {
|
---|
43 | if (map.containsKey(null))
|
---|
44 | throw new IllegalArgumentException("Error: Null as map key in preference setting");
|
---|
45 | if (map.containsValue(null))
|
---|
46 | throw new IllegalArgumentException("Error: Null as map value in preference setting");
|
---|
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 | }
|
---|