public final class Variable extends Object implements NamedValueWithSource, Identifiable<VariableId>
Constructor and Description |
---|
Variable(String name,
Object value)
Creates a new variable with a mandatory name and optional value.
|
Variable(String name,
Object value,
EntityId source)
Creates a new variable with a mandatory name, optional value, and source.
|
Variable(VariableId id,
String name,
Object value,
EntityId source)
Creates a new variable with a mandatory id, name, optional value, and source.
|
Modifier and Type | Method and Description |
---|---|
static Variable |
findByName(String name,
Collection<Variable> variables)
Finds the variable with the given name among the given variables.
|
VariableId |
getId()
Returns the id of the variable.
|
String |
getName()
Returns the name of the variable.
|
EntityId |
getSource()
Returns the source of the variable.
|
Object |
getValue()
Returns the value of the variable.
|
<S> S |
getValue(Class<S> expectedType)
Convenience method for returning the value of the variable cast to the expected type.
|
<S> S |
getValue(com.google.common.reflect.TypeToken<S> expectedType)
Convenience method for returning the value of the variable cast to the expected type.
|
String |
toString() |
Variable |
withId(VariableId id)
Returns a new variable with the given id and the current name, value, and source.
|
Variable |
withSource(EntityId source)
Returns a new variable with the given source and the current id, name, and value.
|
public Variable(String name, Object value)
name
- the name of the variablevalue
- the value of the variablepublic Variable(String name, Object value, EntityId source)
name
- the name of the variablevalue
- the value of the variablesource
- the source of the variablepublic Variable(VariableId id, String name, Object value, EntityId source)
id
- the id of the variablename
- the name of the variablevalue
- the value of the variablesource
- the source of the variablepublic VariableId getId()
getId
in interface Identifiable<VariableId>
public String getName()
getName
in interface NamedValue
public Object getValue()
getValue
in interface NamedValue
public <S> S getValue(Class<S> expectedType)
IllegalArgumentException
is thrown.getValue
in interface NamedValue
S
- the type of the valueexpectedType
- the expected type of the variable valueIllegalArgumentException
- thrown if the cast is not possiblepublic <S> S getValue(com.google.common.reflect.TypeToken<S> expectedType)
IllegalArgumentException
is thrown.getValue
in interface NamedValue
S
- the type of the valueexpectedType
- the expected type of the variable valueIllegalArgumentException
- thrown if the cast is not possiblepublic EntityId getSource()
getSource
in interface NamedValueWithSource
public Variable withId(VariableId id)
id
- the new id of the variablepublic Variable withSource(EntityId source)
source
- the source of the variablepublic static Variable findByName(String name, Collection<Variable> variables)
name
- the name of the variable to findvariables
- the variables to searchNoSuchElementException
- thrown if there is no variable with the given nameCopyright © 2010 - 2018 edorasware ag. All Rights Reserved.