source: josm/trunk/src/org/openstreetmap/josm/spi/preferences/MapListSetting.java@ 13499

Last change on this file since 13499 was 12882, checked in by bastiK, 7 years ago

see #15229 - fix @since

  • Property svn:eol-style set to native
File size: 1.9 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.spi.preferences;
3
4import java.util.ArrayList;
5import java.util.Collections;
6import java.util.LinkedHashMap;
7import java.util.List;
8import 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 */
14public 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}
Note: See TracBrowser for help on using the repository browser.