Class Command

java.lang.Object
org.openstreetmap.josm.command.Command
All Implemented Interfaces:
PseudoCommand
Direct Known Subclasses:
AbstractNodesCommand, AddCommand, AddPrimitivesCommand, ChangeCommand, ChangeMembersCommand, ChangePropertyCommand, ChangePropertyKeyCommand, ChangeRelationMemberRoleCommand, ConflictAddCommand, ConflictResolveCommand, DeleteCommand, MoveCommand, PurgeCommand, SelectCommand, SequenceCommand, TransformNodesCommand

public abstract class Command extends Object implements PseudoCommand
Classes implementing Command modify a dataset in a specific way. A command is one atomic action on a specific dataset, such as move or delete. The command remembers the DataSet it is operating on.
Since:
21 (creation), 10599 (signature)
  • Field Details

  • Constructor Details

    • Command

      protected Command(DataSet data)
      Creates a new command in the context of a specific data set, without data layer
      Parameters:
      data - the data set. Must not be null.
      Throws:
      IllegalArgumentException - if data is null
      Since:
      11240
  • Method Details

    • executeCommand

      public boolean executeCommand()
      Executes the command on the dataset. This implementation will remember all primitives returned by fillModifiedData for restoring them on undo.

      The layer should be invalidated after execution so that it can be re-painted.

      Returns:
      true
    • undoCommand

      public void undoCommand()
      Undoes the command. It can be assumed that all objects are in the same state they were before. It can also be assumed that executeCommand was called exactly once before. This implementation undoes all objects stored by a former call to executeCommand.
    • getOrig

      Lets other commands access the original version of the object. Usually for undoing.
      Parameters:
      osm - The requested OSM object
      Returns:
      The original version of the requested object, if any
    • getAffectedDataSet

      Gets the data set this command affects.
      Returns:
      The data set. May be null if no layer was set and no edit layer was found.
      Since:
      10467
    • fillModifiedData

      public abstract void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added)
      Fill in the changed data this command operates on. Add to the lists, don't clear them.
      Parameters:
      modified - The modified primitives
      deleted - The deleted primitives
      added - The added primitives
    • getParticipatingPrimitives

      Return the primitives that take part in this command. The collection is computed during execution.
      Specified by:
      getParticipatingPrimitives in interface PseudoCommand
      Returns:
      primitives that take part in this command
    • checkOutlyingOrIncompleteOperation

      public static int checkOutlyingOrIncompleteOperation(Collection<? extends OsmPrimitive> primitives, Collection<? extends OsmPrimitive> ignore)
      Check whether user is about to operate on data outside of the download area.
      Parameters:
      primitives - the primitives to operate on
      ignore - null or a primitive to be ignored
      Returns:
      true, if operating on outlying primitives is OK; false, otherwise
    • ensurePrimitivesAreInDataset

      protected void ensurePrimitivesAreInDataset()
      Ensures that all primitives that are participating in this command belong to the affected data set. Commands may use this in their update methods to check the consistency of the primitives they operate on.
      Throws:
      AssertionError - if no DataSet is set or if any primitive does not belong to that dataset.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object