Package org.openstreetmap.josm.command
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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
ChangePropertyCommand.OsmPseudoCommand
-
Nested classes/interfaces inherited from class org.openstreetmap.josm.command.Command
Command.OldNodeState
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<OsmPrimitive>
objects
All primitives that are affected with this command.private java.util.Map<java.lang.String,java.lang.String>
tags
Key and value pairs.-
Fields inherited from class org.openstreetmap.josm.command.Command
IS_INCOMPLETE, IS_OK, IS_OUTSIDE
-
-
Constructor Summary
Constructors Constructor Description ChangePropertyCommand(java.util.Collection<? extends OsmPrimitive> objects, java.lang.String key, java.lang.String value)
Creates a command to change one tag of multiple objectsChangePropertyCommand(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 objectsChangePropertyCommand(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 objectsChangePropertyCommand(OsmPrimitive object, java.lang.String key, java.lang.String value)
Creates a command to change one tag of one object
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Command
build(OsmPrimitive source, Tagged target)
Calculate theChangePropertyCommand
that is needed to change the tags in source to be equal to those in target.boolean
equals(java.lang.Object obj)
boolean
executeCommand()
Executes the command on the dataset.void
fillModifiedData(java.util.Collection<OsmPrimitive> modified, java.util.Collection<OsmPrimitive> deleted, java.util.Collection<OsmPrimitive> added)
Fill in the changed data this command operates on.java.util.Collection<PseudoCommand>
getChildren()
Returns the subcommands of this command.javax.swing.Icon
getDescriptionIcon()
Provides a descriptive icon of this command.java.lang.String
getDescriptionText()
Provides a description text representing this command.int
getObjectsNumber()
Returns the number of objects that will effectively be modified, before the command is executed.java.util.Map<java.lang.String,java.lang.String>
getTags()
Returns the tags to set (key/value pairs).int
hashCode()
private void
init(java.util.Collection<? extends OsmPrimitive> objects)
Initialize the instance by finding what objects will be modified-
Methods inherited from class org.openstreetmap.josm.command.Command
checkOutlyingOrIncompleteOperation, ensurePrimitivesAreInDataset, getAffectedDataSet, getOrig, getParticipatingPrimitives, undoCommand
-
-
-
-
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 isnull
, 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 benull
objects
- the objects to modify. Must not be emptytags
- 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 settags
- 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 itemjava.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 setkey
- the key of the tag to setvalue
- the value of the key to set- Throws:
java.lang.NullPointerException
- if objects is null or contain null itemjava.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 setkey
- the key of the tag to setvalue
- 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 classCommand
- 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 classCommand
- Parameters:
modified
- The modified primitivesdeleted
- The deleted primitivesadded
- 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<PseudoCommand> 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:
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)
-
build
public static Command build(OsmPrimitive source, Tagged target)
Calculate theChangePropertyCommand
that is needed to change the tags in source to be equal to those in target.- Parameters:
source
- the source primitivetarget
- the target primitive- Returns:
- null if no changes are needed, else a
ChangePropertyCommand
- Since:
- 17357
-
-