public interface Command
Interface for commands used by the pl.edu.agh.age.console.
Modifier and Type | Method and Description |
---|---|
static <T> T |
checkAndCast(java.lang.Object obj,
java.lang.Class<T> klass,
java.lang.String msg)
Checks if the object is of given klass, and if not, throws an exception
|
static <T,V extends T> |
checkAndCastDefault(@Nullable java.lang.Object obj,
java.lang.Class<T> klass,
V def,
java.lang.String msg)
Checks if the object is of given klass, and if not, throws an exception
|
static <T> java.util.Optional<T> |
checkAndCastNullable(@Nullable java.lang.Object obj,
java.lang.Class<T> klass,
java.lang.String msg)
Checks if the object is of given klass, and if not, throws an exception
|
static <T> T |
getAndCast(java.util.Map<java.lang.String,java.lang.Object> parameters,
java.lang.String name,
java.lang.Class<T> klass)
Returns the named object from the map only if the object is of given klass, and if not, throws an exception
|
static <T,V extends T> |
getAndCastDefault(java.util.Map<java.lang.String,java.lang.Object> parameters,
java.lang.String name,
java.lang.Class<T> klass,
V def)
Returns the named object from the map only if the object is of given klass, and if not, throws an exception
|
static <T> java.util.Optional<T> |
getAndCastNullable(java.util.Map<java.lang.String,java.lang.Object> parameters,
java.lang.String name,
java.lang.Class<T> klass)
Returns the named object from the map only if the object is of given klass, and if not, throws an exception
|
java.lang.String |
name()
Name of the command (for JavaScript side)
|
java.lang.String name()
Name of the command (for JavaScript side)
static <T> T checkAndCast(java.lang.Object obj, java.lang.Class<T> klass, java.lang.String msg)
Checks if the object is of given klass, and if not, throws an exception
This version requires obj
to be nonnull.
T
- expected type of the objectobj
- an object to checkklass
- expected classmsg
- message for the exceptionobj
cast to klass
, if not possible - throws an exceptionjava.lang.IllegalArgumentException
- when obj
is not instance of klass
. msg
is used as a message stringstatic <T> T getAndCast(java.util.Map<java.lang.String,java.lang.Object> parameters, java.lang.String name, java.lang.Class<T> klass)
Returns the named object from the map only if the object is of given klass, and if not, throws an exception
This version requires name
to point to a nonnull object.
T
- expected type of the objectparameters
- name -> object mappingname
- name of the parameter to getklass
- expected classname
object from parameters
map cast to klass
, if not possible - throws an exceptionjava.lang.IllegalArgumentException
- when obj
the object is not instance of klass
. msg
is used as a message stringcheckAndCast(Object, Class, String)
static <T> java.util.Optional<T> checkAndCastNullable(@Nullable java.lang.Object obj, java.lang.Class<T> klass, java.lang.String msg)
Checks if the object is of given klass, and if not, throws an exception
This version accepts null
and returns empty Optional
in such a case.
T
- expected type of the objectobj
- an object to checkklass
- expected classmsg
- message for the exceptionobj
cast to klass
, if not possible - throws an exceptionjava.lang.IllegalArgumentException
- when obj
is not instance of klass
. msg
is used as a message stringstatic <T> java.util.Optional<T> getAndCastNullable(java.util.Map<java.lang.String,java.lang.Object> parameters, java.lang.String name, java.lang.Class<T> klass)
Returns the named object from the map only if the object is of given klass, and if not, throws an exception
This version accepts name
pointing to a null object.
T
- expected type of the objectparameters
- name -> object mappingname
- name of the parameter to getklass
- expected classname
object from parameters
map cast to klass
, if not possible - throws an exceptionjava.lang.IllegalArgumentException
- when obj
the object is not instance of klass
. msg
is used as a message stringcheckAndCastNullable(Object, Class, String)
static <T,V extends T> T checkAndCastDefault(@Nullable java.lang.Object obj, java.lang.Class<T> klass, V def, java.lang.String msg)
Checks if the object is of given klass, and if not, throws an exception
This version accepts null
and returns the provided default value.
T
- expected type of the objectobj
- an object to checkklass
- expected classdef
- default value to returnmsg
- message for the exceptionobj
cast to klass
or def
, if not possible - throws an exceptionjava.lang.IllegalArgumentException
- when obj
is not instance of klass
. msg
is used as a message stringstatic <T,V extends T> T getAndCastDefault(java.util.Map<java.lang.String,java.lang.Object> parameters, java.lang.String name, java.lang.Class<T> klass, V def)
Returns the named object from the map only if the object is of given klass, and if not, throws an exception
This version accepts name
pointing to a null object.
T
- expected type of the objectparameters
- name -> object mappingname
- name of the parameter to getklass
- expected classdef
- default value to returnname
object from parameters
map cast to klass
, if not possible - throws an exceptionjava.lang.IllegalArgumentException
- when obj
the object is not instance of klass
. msg
is used as a message stringcheckAndCastDefault(Object, Class, Object, String)