Changeset 16436 in josm for trunk/src/org/openstreetmap/josm/spi
- Timestamp:
- 2020-05-17T12:08:17+02:00 (5 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/spi/preferences
- Files:
-
- 3 edited
-
AbstractPreferences.java (modified) (3 diffs)
-
ListListSetting.java (modified) (3 diffs)
-
MapListSetting.java (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/spi/preferences/AbstractPreferences.java
r14147 r16436 7 7 import java.util.Map.Entry; 8 8 import java.util.TreeMap; 9 import java.util.stream.Collectors; 9 10 10 11 import org.openstreetmap.josm.tools.Logging; … … 158 159 */ 159 160 public Map<String, String> getAllPrefix(String prefix) { 160 final Map<String, String> all = new TreeMap<>(); 161 for (final Entry<String, Setting<?>> e : getAllSettings().entrySet()) { 162 if (e.getKey().startsWith(prefix) && (e.getValue() instanceof StringSetting)) { 163 all.put(e.getKey(), ((StringSetting) e.getValue()).getValue()); 164 } 165 } 166 return all; 161 return getAllSettings().entrySet().stream() 162 .filter(e -> e.getKey().startsWith(prefix) && (e.getValue() instanceof StringSetting)) 163 .collect(Collectors.toMap(Entry::getKey, e -> ((StringSetting) e.getValue()).getValue(), (a, b) -> b, TreeMap::new)); 167 164 } 168 165 … … 173 170 */ 174 171 public List<String> getAllPrefixCollectionKeys(String prefix) { 175 final List<String> all = new LinkedList<>(); 176 for (Entry<String, Setting<?>> entry : getAllSettings().entrySet()) { 177 if (entry.getKey().startsWith(prefix) && entry.getValue() instanceof ListSetting) { 178 all.add(entry.getKey()); 179 } 180 } 181 return all; 172 return getAllSettings().entrySet().stream() 173 .filter(entry -> entry.getKey().startsWith(prefix) && entry.getValue() instanceof ListSetting) 174 .map(Entry::getKey) 175 .collect(Collectors.toCollection(LinkedList::new)); 182 176 } 183 177 } -
trunk/src/org/openstreetmap/josm/spi/preferences/ListListSetting.java
r12882 r16436 4 4 import java.util.ArrayList; 5 5 import java.util.Collection; 6 import java.util.Collections;7 6 import java.util.List; 7 import java.util.stream.Collectors; 8 9 import org.openstreetmap.josm.tools.StreamUtils; 10 import org.openstreetmap.josm.tools.Utils; 8 11 9 12 /** … … 29 32 public static ListListSetting create(Collection<Collection<String>> value) { 30 33 if (value != null) { 31 List<List<String>> valueList = new ArrayList<>(value.size()); 32 for (Collection<String> lst : value) { 33 valueList.add(new ArrayList<>(lst)); 34 } 34 List<List<String>> valueList = value.stream() 35 .map(ArrayList::new) 36 .collect(Collectors.toList()); 35 37 return new ListListSetting(valueList); 36 38 } … … 43 45 return new ListListSetting(null); 44 46 45 List<List<String>> copy = new ArrayList<>(value.size()); 46 for (Collection<String> lst : value) { 47 List<String> lstCopy = new ArrayList<>(lst); 48 copy.add(Collections.unmodifiableList(lstCopy)); 49 } 50 return new ListListSetting(Collections.unmodifiableList(copy)); 47 List<List<String>> copy = value.stream() 48 .map(Utils::toUnmodifiableList) 49 .collect(StreamUtils.toUnmodifiableList()); 50 return new ListListSetting(copy); 51 51 } 52 52 -
trunk/src/org/openstreetmap/josm/spi/preferences/MapListSetting.java
r14827 r16436 2 2 package org.openstreetmap.josm.spi.preferences; 3 3 4 import java.util.ArrayList;5 import java.util.Collections;6 4 import java.util.LinkedHashMap; 7 5 import java.util.List; 8 6 import java.util.Map; 9 7 import java.util.SortedMap; 8 9 import org.openstreetmap.josm.tools.StreamUtils; 10 import org.openstreetmap.josm.tools.Utils; 10 11 11 12 /** … … 28 29 if (value == null) 29 30 return new MapListSetting(null); 30 List<Map<String, String>> copy = new ArrayList<>(value.size()); 31 for (Map<String, String> map : value) { 32 Map<String, String> mapCopy = new LinkedHashMap<>(map); 33 copy.add(Collections.unmodifiableMap(mapCopy)); 34 } 35 return new MapListSetting(Collections.unmodifiableList(copy)); 31 List<Map<String, String>> copy = value.stream() 32 .map(LinkedHashMap::new) 33 .map(Utils::toUnmodifiableMap) 34 .collect(StreamUtils.toUnmodifiableList()); 35 return new MapListSetting(copy); 36 36 } 37 37
Note:
See TracChangeset
for help on using the changeset viewer.
