- java.lang.Object
-
- io.github.interacto.command.CommandImpl
-
- io.github.interacto.command.library.ModifyValue<T>
-
- All Implemented Interfaces:
Command
public abstract class ModifyValue<T> extends CommandImpl
The goal of this abstract command is to modify an object. This object can be for instance a property of an object. The use of this command can be made when an object has a lot of properties which modification follow the same process. Thus, a same command can be used to modify all the properties. To do so, a enumeration of the properties can be defined and used into the command to specify which property will be modified by the current command instance.- Author:
- Arnaud Blouin
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface io.github.interacto.command.Command
Command.CmdStatus, Command.RegistrationPolicy
-
-
Field Summary
Fields Modifier and Type Field Description protected TvalueThe new value of the property.-
Fields inherited from class io.github.interacto.command.CommandImpl
status
-
-
Constructor Summary
Constructors Constructor Description ModifyValue()Initialises the command.ModifyValue(T value)Initialises the command with the value to set.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract voidapplyValue(T obj)This method executes the job of methods undo, redo, and dobooleancanDo()Checks whether the command can be executed.voidflush()Flushes the command.protected abstract booleanisValueMatchesProperty()voidsetValue(T newValue)Sets the new value of the parameter to change.-
Methods inherited from class io.github.interacto.command.CommandImpl
cancel, createMemento, doCmdBody, doIt, done, getRegistrationPolicy, getStatus, hadEffect, isDone, toString, unregisteredBy
-
-
-
-
Field Detail
-
value
protected T value
The new value of the property.
-
-
Constructor Detail
-
ModifyValue
public ModifyValue()
Initialises the command.
-
ModifyValue
public ModifyValue(T value)
Initialises the command with the value to set.- Parameters:
value- The value to set.
-
-
Method Detail
-
flush
public void flush()
Description copied from interface:CommandFlushes the command. Can be useful to close streams, free objects, etc. A command should flushed manually only when it is not managed by the cmd registry of the application. When a command is gathered and managed by a command registry, it is automatically flushed when the command registry removes the cmd.- Specified by:
flushin interfaceCommand- Overrides:
flushin classCommandImpl
-
canDo
public boolean canDo()
Description copied from interface:CommandChecks whether the command can be executed.- Specified by:
canDoin interfaceCommand- Overrides:
canDoin classCommandImpl- Returns:
- True if the command can be executed.
-
setValue
public void setValue(T newValue)
Sets the new value of the parameter to change.- Parameters:
newValue- The new value.
-
applyValue
protected abstract void applyValue(T obj)
This method executes the job of methods undo, redo, and do- Parameters:
obj- The value to set. Must not be null.- Throws:
NullPointerException- If the given value is null.
-
isValueMatchesProperty
protected abstract boolean isValueMatchesProperty()
- Returns:
- True: the object to modified supports the selected property.
-
-