Class 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 Detail

      • objects

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

        private final java.util.Map<java.lang.String,​java.lang.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 Detail

      • ChangePropertyCommand

        public ChangePropertyCommand​(DataSet ds,
                                     java.util.Collection<? extends OsmPrimitive> objects,
                                     java.util.Map<java.lang.String,​java.lang.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​(java.util.Collection<? extends OsmPrimitive> objects,
                                     java.util.Map<java.lang.String,​java.lang.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:
        java.lang.NullPointerException - if objects is null or contain null item
        java.util.NoSuchElementException - if objects is empty
      • ChangePropertyCommand

        public ChangePropertyCommand​(java.util.Collection<? extends OsmPrimitive> objects,
                                     java.lang.String key,
                                     java.lang.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:
        java.lang.NullPointerException - if objects is null or contain null item
        java.util.NoSuchElementException - if objects is empty
      • ChangePropertyCommand

        public ChangePropertyCommand​(OsmPrimitive object,
                                     java.lang.String key,
                                     java.lang.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:
        java.lang.NullPointerException - if object is null
    • Method Detail

      • init

        private void init​(java.util.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

        public void fillModifiedData​(java.util.Collection<OsmPrimitive> modified,
                                     java.util.Collection<OsmPrimitive> deleted,
                                     java.util.Collection<OsmPrimitive> added)
        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

        public java.lang.String getDescriptionText()
        Description copied from interface: PseudoCommand
        Provides a description text representing this command.
        Returns:
        description text representing this command
      • getDescriptionIcon

        public javax.swing.Icon getDescriptionIcon()
        Description copied from interface: PseudoCommand
        Provides a descriptive icon of this command.
        Returns:
        descriptive icon of this command
      • getChildren

        public java.util.Collection<PseudoCommandgetChildren()
        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:
        Command.getParticipatingPrimitives()
      • getTags

        public java.util.Map<java.lang.String,​java.lang.String> getTags()
        Returns the tags to set (key/value pairs).
        Returns:
        the tags to set (key/value pairs)
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class Command