source: josm/trunk/src/org/openstreetmap/josm/data/osm/OsmDataManager.java@ 18801

Last change on this file since 18801 was 18801, checked in by taylor.smock, 9 months ago

Fix #22832: Code cleanup and some simplification, documentation fixes (patch by gaben)

There should not be any functional changes in this patch; it is intended to do
the following:

  • Simplify and cleanup code (example: Arrays.asList(item) -> Collections.singletonList(item))
  • Fix typos in documentation (which also corrects the documentation to match what actually happens, in some cases)
  • Property svn:eol-style set to native
File size: 2.6 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.osm;
3
4import java.util.Collection;
5import java.util.Collections;
6import java.util.Optional;
7
8import org.openstreetmap.josm.actions.mapmode.DrawAction;
9import org.openstreetmap.josm.gui.MainApplication;
10import org.openstreetmap.josm.gui.MapFrame;
11import org.openstreetmap.josm.gui.layer.OsmDataLayer;
12
13/**
14 * Global OSM dataset registry.
15 * @since 14143
16 */
17public final class OsmDataManager implements IOsmDataManager {
18
19 private OsmDataManager() {
20 // hide constructor
21 }
22
23 private static class InstanceHolder {
24 static final OsmDataManager INSTANCE = new OsmDataManager();
25 }
26
27 /**
28 * Returns the unique instance.
29 * @return the unique instance
30 */
31 public static OsmDataManager getInstance() {
32 return InstanceHolder.INSTANCE;
33 }
34
35 @Override
36 public Collection<OsmPrimitive> getInProgressSelection() {
37 MapFrame map = MainApplication.getMap();
38 if (map != null && map.mapMode instanceof DrawAction) {
39 return ((DrawAction) map.mapMode).getInProgressSelection();
40 } else {
41 DataSet ds = MainApplication.getLayerManager().getActiveDataSet();
42 if (ds == null) return Collections.emptyList();
43 return ds.getSelected();
44 }
45 }
46
47 @Override
48 public Collection<? extends IPrimitive> getInProgressISelection() {
49 MapFrame map = MainApplication.getMap();
50 if (map != null && map.mapMode instanceof DrawAction) {
51 return ((DrawAction) map.mapMode).getInProgressSelection();
52 } else {
53 OsmData<?, ?, ?, ?> ds = MainApplication.getLayerManager().getActiveData();
54 if (ds == null) return Collections.emptyList();
55 return ds.getSelected();
56 }
57 }
58
59 @Override
60 public DataSet getEditDataSet() {
61 return MainApplication.getLayerManager().getEditDataSet();
62 }
63
64 @Override
65 public DataSet getActiveDataSet() {
66 return MainApplication.getLayerManager().getActiveDataSet();
67 }
68
69 @Override
70 public void setActiveDataSet(DataSet ds) {
71 Optional<OsmDataLayer> layer = MainApplication.getLayerManager().getLayersOfType(OsmDataLayer.class).stream()
72 .filter(l -> l.data.equals(ds)).findFirst();
73 layer.ifPresent(osmDataLayer -> MainApplication.getLayerManager().setActiveLayer(osmDataLayer));
74 }
75
76 @Override
77 public boolean containsDataSet(DataSet ds) {
78 return MainApplication.getLayerManager().getLayersOfType(OsmDataLayer.class).stream().anyMatch(l -> l.data.equals(ds));
79 }
80}
Note: See TracBrowser for help on using the repository browser.