source: josm/trunk/src/org/openstreetmap/josm/data/preferences/ListSetting.java@ 9798

Last change on this file since 9798 was 9759, checked in by Don-vip, 8 years ago

refactor preferences settings classes

  • Property svn:eol-style set to native
File size: 1.7 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.preferences;
3
4import java.util.ArrayList;
5import java.util.Collection;
6import java.util.Collections;
7import java.util.List;
8
9import org.openstreetmap.josm.tools.Utils;
10
11/**
12 * Setting containing a {@link List} of {@link String} values.
13 * @since 9759
14 */
15public class ListSetting extends AbstractSetting<List<String>> {
16 /**
17 * Constructs a new {@code ListSetting} with the given value
18 * @param value The setting value
19 */
20 public ListSetting(List<String> value) {
21 super(value);
22 consistencyTest();
23 }
24
25 /**
26 * Convenience factory method.
27 * @param value the value
28 * @return a corresponding ListSetting object
29 */
30 public static ListSetting create(Collection<String> value) {
31 return new ListSetting(value == null ? null : Collections.unmodifiableList(new ArrayList<>(value)));
32 }
33
34 @Override
35 public boolean equalVal(List<String> otherVal) {
36 return Utils.equalCollection(value, otherVal);
37 }
38
39 @Override
40 public ListSetting copy() {
41 return ListSetting.create(value);
42 }
43
44 private void consistencyTest() {
45 if (value != null && value.contains(null))
46 throw new RuntimeException("Error: Null as list element in preference setting");
47 }
48
49 @Override
50 public void visit(SettingVisitor visitor) {
51 visitor.visit(this);
52 }
53
54 @Override
55 public ListSetting getNullInstance() {
56 return new ListSetting(null);
57 }
58
59 @Override
60 public boolean equals(Object other) {
61 if (!(other instanceof ListSetting))
62 return false;
63 return equalVal(((ListSetting) other).getValue());
64 }
65}
Note: See TracBrowser for help on using the repository browser.