Class ChangePropertyCommand

java.lang.Object
org.openstreetmap.josm.command.Command
org.openstreetmap.josm.command.ChangePropertyCommand
All Implemented Interfaces:
PseudoCommand

public class ChangePropertyCommand extends Command
Command that manipulate the key/value structure of several objects. Manages deletion, adding and modify of values and keys.
Since:
24
  • Field Details

    • objects

      private final List<OsmPrimitive> objects
      All primitives that are affected with this command.
    • tags

      private final Map<String,String> tags
      Key and value pairs. If value is null, delete all key references with the given key. Otherwise, change the tags of all objects to the given value or create keys of those objects that do not have the key yet.
  • Constructor Details

    • ChangePropertyCommand

      public ChangePropertyCommand(DataSet ds, Collection<? extends OsmPrimitive> objects, Map<String,String> tags)
      Creates a command to change multiple tags of multiple objects
      Parameters:
      ds - The target data set. Must not be null
      objects - the objects to modify. Must not be empty
      tags - the tags to set. Caller must make sure that the tas are not changed once the command was executed.
      Since:
      12726
    • ChangePropertyCommand

      public ChangePropertyCommand(Collection<? extends OsmPrimitive> objects, Map<String,String> tags)
      Creates a command to change multiple tags of multiple objects
      Parameters:
      objects - the objects to modify. Must not be empty, and objects must belong to a data set
      tags - the tags to set. Caller must make sure that the tas are not changed once the command was executed.
      Throws:
      NullPointerException - if objects is null or contain null item
      NoSuchElementException - if objects is empty
    • ChangePropertyCommand

      public ChangePropertyCommand(Collection<? extends OsmPrimitive> objects, String key, String value)
      Creates a command to change one tag of multiple objects
      Parameters:
      objects - the objects to modify. Must not be empty, and objects must belong to a data set
      key - the key of the tag to set
      value - the value of the key to set
      Throws:
      NullPointerException - if objects is null or contain null item
      NoSuchElementException - if objects is empty
    • ChangePropertyCommand

      public ChangePropertyCommand(OsmPrimitive object, String key, String value)
      Creates a command to change one tag of one object
      Parameters:
      object - the object to modify. Must belong to a data set
      key - the key of the tag to set
      value - the value of the key to set
      Throws:
      NullPointerException - if object is null
  • Method Details

    • init

      private void init(Collection<? extends OsmPrimitive> objects)
      Initialize the instance by finding what objects will be modified
      Parameters:
      objects - the objects to (possibly) modify
    • executeCommand

      public boolean executeCommand()
      Description copied from class: Command
      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.

      Overrides:
      executeCommand in class Command
      Returns:
      true
    • fillModifiedData

      Description copied from class: Command
      Fill in the changed data this command operates on. Add to the lists, don't clear them.
      Specified by:
      fillModifiedData in class Command
      Parameters:
      modified - The modified primitives
      deleted - The deleted primitives
      added - The added primitives
    • getDescriptionText

      Description copied from interface: PseudoCommand
      Provides a description text representing this command.
      Returns:
      description text representing this command
    • getDescriptionIcon

      Description copied from interface: PseudoCommand
      Provides a descriptive icon of this command.
      Returns:
      descriptive icon of this command
    • getChildren

      Description copied from interface: PseudoCommand
      Returns the subcommands of this command. Override for subclasses that have child commands.
      Returns:
      the subcommands, null if there are no child commands
    • getObjectsNumber

      public final int getObjectsNumber()
      Returns the number of objects that will effectively be modified, before the command is executed.
      Returns:
      the number of objects that will effectively be modified (can be 0)
      Since:
      8945
      See Also:
    • getTags

      public Map<String,String> getTags()
      Returns the tags to set (key/value pairs).
      Returns:
      the tags to set (key/value pairs)
    • hashCode

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

      public boolean equals(Object obj)
      Overrides:
      equals in class Command
    • build

      public static Command build(OsmPrimitive source, Tagged target)
      Calculate the ChangePropertyCommand that is needed to change the tags in source to be equal to those in target.
      Parameters:
      source - the source primitive
      target - the target primitive
      Returns:
      null if no changes are needed, else a ChangePropertyCommand
      Since:
      17357