public class VariableBinder extends Object
VariableResolver to variables of a specific type, use bindType(String, VariableResolver).
The following example will bind all variables typed int to return the corresponding integer value.
VariableBinder binder = new VariableBinder();
b.bindType("int", new VariableResolver(){
public boolean exists(String v) {return v.matches("\\d+");}
public Integer resolve(String v) {return exists(v)? Integer.valueOf(v) : null;};
});
To assign a VariableResolver to variables of a specific name, use bindName(String, VariableResolver).
The following example will bind all variables typed int to return the corresponding integer value.
VariableBinder binder = new VariableBinder();
b.bindName("name", new VariableResolver(){
public boolean exists(String v) {return true;}
public Integer resolve(String v) {return exists(v)? Integer.valueOf(v) : null;};
});
| Constructor and Description |
|---|
VariableBinder() |
| Modifier and Type | Method and Description |
|---|---|
void |
bind(String name,
VariableResolver resolver)
Deprecated.
use #bindName() or #bindType() instead
|
void |
bindName(String name,
VariableResolver resolver)
Binds the variables with the specified name to the specified resolver.
|
void |
bindType(String type,
VariableResolver resolver)
Binds the variables with the specified name to the specified resolver.
|
VariableResolver |
getResolver(String name)
Returns the resolver used for the variable of the specified name.
|
VariableResolver |
getResolver(String name,
VariableType type)
Returns the resolver used for the variable of the specified name or type.
|
VariableResolver |
getResolver(VariableType type)
Returns the resolver used for the variable of the specified type.
|
boolean |
isNameBound(String name)
Indicates whether the given variable name is bound to a VariableResolver.
|
boolean |
isTypeBound(String type)
Indicates whether the given variable type is bound to a VariableResolver.
|
public void bind(String name, VariableResolver resolver)
name - The name of the variable.resolver - The resolver to use with these variables.public void bindName(String name, VariableResolver resolver)
name - The name of the variable.resolver - The resolver to use with these variables.public void bindType(String type, VariableResolver resolver)
type - The variable type.resolver - The resolver to use with these variables.public VariableResolver getResolver(String name, VariableType type)
By default, looks for the resolver assigned to the specified variable name; if no resolver is bound to the variable name, it will return the resolver bound to the given variable type.
This method does not return null. If the specified variable name or type is not
bound to any resolver the default resolver if returned instead.
name - The name of the variable.type - The type of the variable.public VariableResolver getResolver(String name)
This method does not return null. If the specified variable name is no bound
to any resolver the default resolver if returned instead.
name - The name of the variables.public VariableResolver getResolver(VariableType type)
This method does not return null. If the specified variable name is no bound
to any resolver the default resolver if returned instead.
type - The type of the variable.public boolean isNameBound(String name)
name - The variable name.true if a given variable resolver is bound to the specific name;
false otherwise (including if the name is null.public boolean isTypeBound(String type)
type - The variable type.true if a given variable resolver is bound to the specific type;
false otherwise (including if the type is null.Copyright © 2014. All rights reserved.