Package sources.client
Class Invoker
java.lang.Object
sources.client.Invoker
The Invoker class is responsible for executing commands and maintaining a history of executed commands.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidexecute(AbstractCommand command) Executes the specified command and adds it to the command history.<T> TexecuteAndReturn(AbstractCommandWithResult<T> command) Executes the specified command with a result and adds it to the command history.Returns the command history maintained by the invoker.
-
Constructor Details
-
Invoker
public Invoker()
-
-
Method Details
-
execute
public void execute(AbstractCommand command) throws CollectionKeyException, WrongArgumentException, CustomIOException Executes the specified command and adds it to the command history.- Parameters:
command- the command to execute- Throws:
CollectionKeyException- if there is an error with the collection keyWrongArgumentException- if there is an error with the command argumentsCustomIOException- if there is an input/output error while executing the command
-
executeAndReturn
public <T> T executeAndReturn(AbstractCommandWithResult<T> command) throws WrongArgumentException, CollectionKeyException, CustomIOException Executes the specified command with a result and adds it to the command history.- Type Parameters:
T- the type of the command result- Parameters:
command- the command to execute- Returns:
- the result of the executed command
- Throws:
WrongArgumentException- if there is an error with the command argumentsCollectionKeyException- if there is an error with the collection keyCustomIOException- if there is an input/output error while executing the command
-
getCommandHistory
Returns the command history maintained by the invoker.- Returns:
- the command history stack
-