Ignore:
Timestamp:
2017-09-04T23:45:49+02:00 (3 years ago)
Author:
Don-vip
Message:

see #13036 - deprecate Command() default constructor, fix unit tests and java warnings

Location:
trunk/src/org/openstreetmap/josm/command
Files:
23 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/command/AddCommand.java

    r12718 r12726  
    3636     * Creates the command and specify the element to add in the context of the current edit layer, if any.
    3737     * @param osm The primitive to add
     38     * @deprecated to be removed end of 2017. Use {@link #AddCommand(DataSet, OsmPrimitive)} instead
    3839     */
     40    @Deprecated
    3941    public AddCommand(OsmPrimitive osm) {
    4042        this.osm = Objects.requireNonNull(osm, "osm");
  • trunk/src/org/openstreetmap/josm/command/AddPrimitivesCommand.java

    r12718 r12726  
    3939     * Constructs a new {@code AddPrimitivesCommand} to add data to the current edit layer.
    4040     * @param data The OSM primitives data to add. Must not be {@code null}
    41      */
     41     * @deprecated to be removed end of 2017. Use {@link #AddPrimitivesCommand(List, DataSet)} instead
     42     */
     43    @Deprecated
    4244    public AddPrimitivesCommand(List<PrimitiveData> data) {
    4345        this(data, data);
     
    4951     * @param toSelect The OSM primitives to select at the end. Can be {@code null}
    5052     * @since 5953
    51      */
     53     * @deprecated to be removed end of 2017. Use {@link #AddPrimitivesCommand(List, List, DataSet)} instead
     54     */
     55    @Deprecated
    5256    public AddPrimitivesCommand(List<PrimitiveData> data, List<PrimitiveData> toSelect) {
    5357        init(data, toSelect);
     
    7781        super(ds);
    7882        init(data, toSelect);
     83    }
     84
     85    /**
     86     * Constructs a new {@code AddPrimitivesCommand} to add data to the given data set.
     87     * @param data The OSM primitives data to add and select. Must not be {@code null}
     88     * @param ds The target data set. Must not be {@code null}
     89     * @since 12726
     90     */
     91    public AddPrimitivesCommand(List<PrimitiveData> data, DataSet ds) {
     92        this(data, data, ds);
    7993    }
    8094
  • trunk/src/org/openstreetmap/josm/command/ChangeCommand.java

    r12718 r12726  
    3030
    3131    /**
    32      * Constructs a new {@code ChangeCommand} in the context of the current edit layer, if any.
    33      * @param osm The existing primitive to modify
     32     * Constructs a new {@code ChangeCommand} in the context of {@code osm} data set.
     33     * @param osm The existing primitive to modify. It must belong to a data set
    3434     * @param newOsm The new primitive
    3535     */
    3636    public ChangeCommand(OsmPrimitive osm, OsmPrimitive newOsm) {
    37         this.osm = osm;
    38         this.newOsm = newOsm;
    39         sanityChecks();
     37        this(osm.getDataSet(), osm, newOsm);
    4038    }
    4139
  • trunk/src/org/openstreetmap/josm/command/ChangeNodesCommand.java

    r12663 r12726  
    1010import javax.swing.Icon;
    1111
     12import org.openstreetmap.josm.data.osm.DataSet;
    1213import org.openstreetmap.josm.data.osm.DefaultNameFormatter;
    1314import org.openstreetmap.josm.data.osm.Node;
     
    3637     */
    3738    public ChangeNodesCommand(Way way, List<Node> newNodes) {
     39        this(way.getDataSet(), way, newNodes);
     40    }
     41
     42    /**
     43     * Constructs a new {@code ChangeNodesCommand}.
     44     * @param ds The target data set. Must not be {@code null}
     45     * @param way The way to modify
     46     * @param newNodes The new list of nodes for the given way
     47     * @since 12726
     48     */
     49    public ChangeNodesCommand(DataSet ds, Way way, List<Node> newNodes) {
     50        super(ds);
    3851        this.way = way;
    3952        this.newNodes = newNodes;
  • trunk/src/org/openstreetmap/josm/command/ChangePropertyCommand.java

    r12663 r12726  
    1313import java.util.List;
    1414import java.util.Map;
     15import java.util.NoSuchElementException;
    1516import java.util.Objects;
    1617import java.util.stream.Collectors;
     
    7273     * Creates a command to change multiple tags of multiple objects
    7374     *
    74      * @param objects the objects to modify
     75     * @param ds The target data set. Must not be {@code null}
     76     * @param objects the objects to modify. Must not be empty
    7577     * @param tags the tags to set
    76      */
    77     public ChangePropertyCommand(Collection<? extends OsmPrimitive> objects, Map<String, String> tags) {
     78     * @since 12726
     79     */
     80    public ChangePropertyCommand(DataSet ds, Collection<? extends OsmPrimitive> objects, Map<String, String> tags) {
     81        super(ds);
    7882        this.tags = tags;
    7983        init(objects);
     
    8185
    8286    /**
     87     * Creates a command to change multiple tags of multiple objects
     88     *
     89     * @param objects the objects to modify. Must not be empty, and objects must belong to a data set
     90     * @param tags the tags to set
     91     * @throws NullPointerException if objects is null or contain null item
     92     * @throws NoSuchElementException if objects is empty
     93     */
     94    public ChangePropertyCommand(Collection<? extends OsmPrimitive> objects, Map<String, String> tags) {
     95        this(objects.iterator().next().getDataSet(), objects, tags);
     96    }
     97
     98    /**
    8399     * Creates a command to change one tag of multiple objects
    84100     *
    85      * @param objects the objects to modify
     101     * @param objects the objects to modify. Must not be empty, and objects must belong to a data set
    86102     * @param key the key of the tag to set
    87103     * @param value the value of the key to set
     104     * @throws NullPointerException if objects is null or contain null item
     105     * @throws NoSuchElementException if objects is empty
    88106     */
    89107    public ChangePropertyCommand(Collection<? extends OsmPrimitive> objects, String key, String value) {
     108        super(objects.iterator().next().getDataSet());
    90109        this.tags = new HashMap<>(1);
    91110        this.tags.put(key, value);
     
    96115     * Creates a command to change one tag of one object
    97116     *
    98      * @param object the object to modify
     117     * @param object the object to modify. Must belong to a data set
    99118     * @param key the key of the tag to set
    100119     * @param value the value of the key to set
     120     * @throws NullPointerException if object is null
    101121     */
    102122    public ChangePropertyCommand(OsmPrimitive object, String key, String value) {
     
    134154    @Override
    135155    public boolean executeCommand() {
    136         if (objects.isEmpty())
    137             return true;
    138156        final DataSet dataSet = objects.get(0).getDataSet();
    139157        if (dataSet != null) {
  • trunk/src/org/openstreetmap/josm/command/ChangePropertyKeyCommand.java

    r11608 r12726  
    1010import java.util.LinkedList;
    1111import java.util.List;
     12import java.util.NoSuchElementException;
    1213import java.util.Objects;
    1314
    1415import javax.swing.Icon;
    1516
     17import org.openstreetmap.josm.data.osm.DataSet;
    1618import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1719import org.openstreetmap.josm.data.validation.util.NameVisitor;
     
    6668     * Constructs a new {@code ChangePropertyKeyCommand}.
    6769     *
    68      * @param object the object subject to change replacement
     70     * @param object the object subject to change replacement. Must not be null, and belong to a data set
    6971     * @param key The key to replace
    7072     * @param newKey the new value of the key
     
    7880     * Constructs a new {@code ChangePropertyKeyCommand}.
    7981     *
    80      * @param objects all objects subject to change replacement
     82     * @param objects all objects subject to change replacement. Must not be null or empty, and objects must belong to a data set
    8183     * @param key The key to replace
    8284     * @param newKey the new value of the key
     85     * @throws NullPointerException if objects is null or contain null item
     86     * @throws NoSuchElementException if objects is empty
    8387     */
    8488    public ChangePropertyKeyCommand(Collection<? extends OsmPrimitive> objects, String key, String newKey) {
     89        this(objects.iterator().next().getDataSet(), objects, key, newKey);
     90    }
     91
     92    /**
     93     * Constructs a new {@code ChangePropertyKeyCommand}.
     94     *
     95     * @param ds The target data set. Must not be {@code null}
     96     * @param objects all objects subject to change replacement.
     97     * @param key The key to replace
     98     * @param newKey the new value of the key
     99     * @since 12726
     100     */
     101    public ChangePropertyKeyCommand(DataSet ds, Collection<? extends OsmPrimitive> objects, String key, String newKey) {
     102        super(ds);
    85103        this.objects = new LinkedList<>(objects);
    86104        this.key = key;
  • trunk/src/org/openstreetmap/josm/command/ChangeRelationMemberRoleCommand.java

    r12663 r12726  
    3737    /**
    3838     * Constructs a new {@code ChangeRelationMemberRoleCommand}.
    39      * @param relation The relation to be changed
     39     * @param relation The relation to be changed. Must not be null, and belong to a data set
    4040     * @param position Member position
    4141     * @param newRole New role
    4242     */
    4343    public ChangeRelationMemberRoleCommand(Relation relation, int position, String newRole) {
    44         this.relation = relation;
    45         this.position = position;
    46         this.newRole = newRole;
     44        this(relation.getDataSet(), relation, position, newRole);
    4745    }
    4846
    4947    /**
    5048     * Constructs a new {@code ChangeRelationMemberRoleCommand}.
    51      * @param dataSet The data set the role is in
     49     * @param dataSet The data set the role is in. Must not be {@code null}
    5250     * @param relation The relation to be changed
    5351     * @param position Member position
  • trunk/src/org/openstreetmap/josm/command/Command.java

    r12718 r12726  
    147147    /**
    148148     * Creates a new command in the context of the current edit layer, if any
    149      */
     149     * @deprecated to be removed end of 2017. Use {@link #Command(DataSet)} instead
     150     */
     151    @Deprecated
    150152    public Command() {
    151153        this.layer = MainApplication.getLayerManager().getEditLayer();
  • trunk/src/org/openstreetmap/josm/command/DeleteCommand.java

    r12718 r12726  
    7575        @Override
    7676        public String toString() {
    77             return "DeleteChildCommand [osm=" + osm + "]";
     77            return "DeleteChildCommand [osm=" + osm + ']';
    7878        }
    7979    }
     
    8888     * Constructor. Deletes a collection of primitives in the current edit layer.
    8989     *
    90      * @param data the primitives to delete. Must neither be null nor empty.
     90     * @param data the primitives to delete. Must neither be null nor empty, and belong to a data set
    9191     * @throws IllegalArgumentException if data is null or empty
    9292     */
    9393    public DeleteCommand(Collection<? extends OsmPrimitive> data) {
    94         CheckParameterUtil.ensureParameterNotNull(data, "data");
    95         this.toDelete = data;
    96         checkConsistency();
     94        this(data.iterator().next().getDataSet(), data);
    9795    }
    9896
  • trunk/src/org/openstreetmap/josm/command/MoveCommand.java

    r12348 r12726  
    99import java.util.LinkedList;
    1010import java.util.List;
     11import java.util.NoSuchElementException;
    1112import java.util.Objects;
    1213
     
    8485    /**
    8586     * Constructs a new {@code MoveCommand} and assign the initial object set and movement vector.
    86      * @param objects The primitives to move
     87     * @param objects The primitives to move. Must neither be null nor empty. Objects must belong to a data set
    8788     * @param x X difference movement. Coordinates are in northern/eastern
    8889     * @param y Y difference movement. Coordinates are in northern/eastern
     90     * @throws NullPointerException if objects is null or contain null item
     91     * @throws NoSuchElementException if objects is empty
    8992     */
    9093    public MoveCommand(Collection<OsmPrimitive> objects, double x, double y) {
     94        super(objects.iterator().next().getDataSet());
    9195        startEN = null;
    9296        saveCheckpoint(); // (0,0) displacement will be saved
  • trunk/src/org/openstreetmap/josm/command/RemoveNodesCommand.java

    r12663 r12726  
    3333    /**
    3434     * Constructs a new {@code RemoveNodesCommand}.
    35      * @param way The way to modify
     35     * @param way The way to modify. Must not be null, and belong to a data set
    3636     * @param rmNodes The list of nodes to remove
    3737     */
    3838    public RemoveNodesCommand(Way way, List<Node> rmNodes) {
     39        super(way.getDataSet());
    3940        this.way = way;
    4041        this.rmNodes = new HashSet<>(rmNodes);
  • trunk/src/org/openstreetmap/josm/command/SelectCommand.java

    r12350 r12726  
    2828     * Constructs a new select command.
    2929     * @param newSelection the primitives to select when executing the command.
     30     * @deprecated to be removed end of 2017. Use {@link #SelectCommand(DataSet, Collection)} instead
    3031     */
     32    @Deprecated
    3133    public SelectCommand(Collection<OsmPrimitive> newSelection) {
    3234        if (newSelection == null || newSelection.isEmpty()) {
  • trunk/src/org/openstreetmap/josm/command/SequenceCommand.java

    r12721 r12726  
    1111import javax.swing.Icon;
    1212
     13import org.openstreetmap.josm.data.osm.DataSet;
    1314import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1415import org.openstreetmap.josm.gui.layer.Layer;
     
    3334    /**
    3435     * Create the command by specifying the list of commands to execute.
     36     * @param ds The target data set. Must not be {@code null}
     37     * @param name The description text
     38     * @param sequenz The sequence that should be executed
     39     * @param continueOnError Determines if the sequence execution should continue after one of its commands fails
     40     * @since 12726
     41     */
     42    public SequenceCommand(DataSet ds, String name, Collection<Command> sequenz, boolean continueOnError) {
     43        super(ds);
     44        this.name = name;
     45        this.sequence = sequenz.toArray(new Command[sequenz.size()]);
     46        this.continueOnError = continueOnError;
     47    }
     48
     49    /**
     50     * Create the command by specifying the list of commands to execute.
    3551     * @param name The description text
    3652     * @param sequenz The sequence that should be executed. Must not be null or empty
     
    3955     */
    4056    public SequenceCommand(String name, Collection<Command> sequenz, boolean continueOnError) {
    41         super(sequenz.iterator().next().getAffectedDataSet());
    42         this.name = name;
    43         this.sequence = sequenz.toArray(new Command[sequenz.size()]);
    44         this.continueOnError = continueOnError;
     57        this(sequenz.iterator().next().getAffectedDataSet(), name, sequenz, continueOnError);
    4558    }
    4659
  • trunk/src/org/openstreetmap/josm/command/TransformNodesCommand.java

    r10663 r12726  
    66import java.util.Collection;
    77import java.util.HashMap;
    8 import java.util.LinkedList;
    98import java.util.Map;
     9import java.util.NoSuchElementException;
    1010import java.util.Objects;
    1111
     
    2828     * The nodes to transform.
    2929     */
    30     protected Collection<Node> nodes = new LinkedList<>();
     30    protected final Collection<Node> nodes;
    3131
    3232    /**
    3333     * List of all old states of the nodes.
    3434     */
    35     protected Map<Node, OldNodeState> oldStates = new HashMap<>();
     35    protected final Map<Node, OldNodeState> oldStates = new HashMap<>();
    3636
    3737    /**
     
    4747     * Creates a TransformNodesObject.
    4848     * Find out the impacted nodes and store their initial state.
    49      * @param objects objects to fetch nodes from
     49     * @param objects objects to fetch nodes from. Must neither be null nor empty. Items must belong to a data set
     50     * @throws NullPointerException if objects is null or contain null item
     51     * @throws NoSuchElementException if objects is empty
    5052     */
    5153    public TransformNodesCommand(Collection<? extends OsmPrimitive> objects) {
     54        super(objects.iterator().next().getDataSet());
    5255        this.nodes = AllNodesVisitor.getAllNodes(objects);
    5356        storeOldState();
  • trunk/src/org/openstreetmap/josm/command/conflict/ConflictAddCommand.java

    r12718 r12726  
    7979    public void undoCommand() {
    8080        DataSet ds = getAffectedDataSet();
    81         if (!Main.main.containsDataSet(ds)) {
     81        if (Main.main != null && !Main.main.containsDataSet(ds)) {
    8282            Logging.warn(tr("Layer ''{0}'' does not exist any more. Cannot remove conflict for object ''{1}''.",
    8383                    ds.getName(),
  • trunk/src/org/openstreetmap/josm/command/conflict/ConflictResolveCommand.java

    r12718 r12726  
    2828    /**
    2929     * Constructs a new {@code ConflictResolveCommand} in the context of the current edit layer, if any.
     30     * @deprecated to be removed end of 2017. Use {@link #ConflictResolveCommand(DataSet)} instead
    3031     */
     32    @Deprecated
    3133    public ConflictResolveCommand() {
    32         // Do nothing
     34        this(Main.main.getEditDataSet());
    3335    }
    3436
     
    8183
    8284        DataSet ds = getAffectedDataSet();
    83         if (!Main.main.containsDataSet(ds)) {
    84             Logging.warn(tr("Cannot undo command ''{0}'' because layer ''{1}'' is not present any more",
    85                     this.toString(),
    86                     ds.getName()
    87             ));
    88             return;
     85        if (Main.main != null) {
     86            if (!Main.main.containsDataSet(ds)) {
     87                Logging.warn(tr("Cannot undo command ''{0}'' because layer ''{1}'' is not present any more",
     88                        this.toString(),
     89                        ds.getName()
     90                ));
     91                return;
     92            }
     93
     94            Main.main.setEditDataSet(ds);
    8995        }
    90 
    91         Main.main.setEditDataSet(ds);
    9296        reconstituteConflicts();
    9397    }
  • trunk/src/org/openstreetmap/josm/command/conflict/CoordinateConflictResolveCommand.java

    r11452 r12726  
    3434     */
    3535    public CoordinateConflictResolveCommand(Conflict<? extends OsmPrimitive> conflict, MergeDecisionType decision) {
     36        super(conflict.getMy().getDataSet());
    3637        this.conflict = conflict;
    3738        this.decision = decision;
  • trunk/src/org/openstreetmap/josm/command/conflict/DeletedStateConflictResolveCommand.java

    r11452 r12726  
    3434     */
    3535    public DeletedStateConflictResolveCommand(Conflict<? extends OsmPrimitive> conflict, MergeDecisionType decision) {
     36        super(conflict.getMy().getDataSet());
    3637        this.conflict = conflict;
    3738        this.decision = decision;
  • trunk/src/org/openstreetmap/josm/command/conflict/ModifiedConflictResolveCommand.java

    r12672 r12726  
    2929     */
    3030    public ModifiedConflictResolveCommand(Conflict<? extends OsmPrimitive> conflict) {
     31        super(conflict.getMy().getDataSet());
    3132        this.conflict = conflict;
    3233    }
  • trunk/src/org/openstreetmap/josm/command/conflict/RelationMemberConflictResolverCommand.java

    r12718 r12726  
    3636    @SuppressWarnings("unchecked")
    3737    public RelationMemberConflictResolverCommand(Conflict<? extends OsmPrimitive> conflict, List<RelationMember> mergedMembers) {
     38        super(conflict.getMy().getDataSet());
    3839        this.conflict = (Conflict<Relation>) conflict;
    3940        this.mergedMembers = mergedMembers;
  • trunk/src/org/openstreetmap/josm/command/conflict/TagConflictResolveCommand.java

    r10671 r12726  
    5050     */
    5151    public TagConflictResolveCommand(Conflict<? extends OsmPrimitive> conflict, List<TagMergeItem> mergeItems) {
     52        super(conflict.getMy().getDataSet());
    5253        this.conflict = conflict;
    5354        this.mergeItems = mergeItems;
  • trunk/src/org/openstreetmap/josm/command/conflict/VersionConflictResolveCommand.java

    r12672 r12726  
    2929     */
    3030    public VersionConflictResolveCommand(Conflict<? extends OsmPrimitive> conflict) {
     31        super(conflict.getMy().getDataSet());
    3132        this.conflict = conflict;
    3233    }
  • trunk/src/org/openstreetmap/josm/command/conflict/WayNodesConflictResolverCommand.java

    r12620 r12726  
    3636    @SuppressWarnings("unchecked")
    3737    public WayNodesConflictResolverCommand(Conflict<? extends OsmPrimitive> conflict, List<Node> mergedNodeList) {
     38        super(conflict.getMy().getDataSet());
    3839        this.conflict = (Conflict<Way>) conflict;
    3940        this.mergedNodeList = mergedNodeList;
Note: See TracChangeset for help on using the changeset viewer.