source: josm/trunk/src/org/openstreetmap/josm/actions/relation/AbstractRelationAction.java@ 9971

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

sonar - use diamond operator when possible (some cases cause compilation failures with Java 9)

  • Property svn:eol-style set to native
File size: 1.5 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.actions.relation;
3
4import java.util.Collection;
5import java.util.Collections;
6
7import javax.swing.AbstractAction;
8
9import org.openstreetmap.josm.actions.OsmPrimitiveAction;
10import org.openstreetmap.josm.data.osm.OsmPrimitive;
11import org.openstreetmap.josm.data.osm.Relation;
12import org.openstreetmap.josm.tools.SubclassFilteredCollection;
13
14/**
15 * Ancestor for all actions that want to work with relation collection and
16 * to be disabled if the collection is empty
17 * @since 5793
18 */
19public abstract class AbstractRelationAction extends AbstractAction implements OsmPrimitiveAction {
20 protected transient Collection<Relation> relations = Collections.<Relation>emptySet();
21
22 @SuppressWarnings("unused")
23 protected static final Collection<Relation> getRelations(Collection<? extends OsmPrimitive> primitives) {
24 if (primitives == null || primitives.isEmpty()) {
25 return Collections.<Relation>emptySet();
26 } else {
27 // Diamond operator does not work with Java 9 here
28 return new SubclassFilteredCollection<OsmPrimitive, Relation>(
29 primitives, OsmPrimitive.relationPredicate);
30 }
31 }
32
33 @Override
34 public void setPrimitives(Collection<? extends OsmPrimitive> primitives) {
35 this.relations = getRelations(primitives);
36 updateEnabledState();
37 }
38
39 protected void updateEnabledState() {
40 setEnabled(!relations.isEmpty());
41 }
42}
Note: See TracBrowser for help on using the repository browser.