com.github.fge.uritemplate.vars
Class VariableMapBuilder

java.lang.Object
  extended by com.github.fge.uritemplate.vars.VariableMapBuilder
All Implemented Interfaces:
com.github.fge.Thawed<VariableMap>

@NotThreadSafe
public final class VariableMapBuilder
extends Object
implements com.github.fge.Thawed<VariableMap>

Builder class for a VariableMap

Use freeze() to build the variable map.

See Also:
VariableMap.thaw()

Method Summary
<T> VariableMapBuilder
addListValue(String varname, Iterable<T> iterable)
          Shortcut method to associate a name with a list value
 VariableMapBuilder addListValue(String varname, Object first, Object... other)
          Shortcut method to associate a name with a list value
<T> VariableMapBuilder
addMapValue(String varname, Map<String,T> map)
          Shortcut method to associate a variable name to a map value
 VariableMapBuilder addScalarValue(String varname, Object value)
          Shortcut method to associate a name with a scalar value
 VariableMapBuilder addValue(String varname, VariableValue value)
          Associate a value to a variable name
 VariableMapBuilder addVariableMap(VariableMap other)
          Add all variable definitions from another variable map
 VariableMap freeze()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

addValue

public VariableMapBuilder addValue(String varname,
                                   VariableValue value)
Associate a value to a variable name

Parameters:
varname - the variable name
value - the value, as a VariableValue
Returns:
this
Throws:
NullPointerException - either the name or the value is null

addScalarValue

public VariableMapBuilder addScalarValue(String varname,
                                         Object value)
Shortcut method to associate a name with a scalar value

The value argument can be any object, just ensure that it implements Object.toString() correctly!

Parameters:
varname - the variable name
value - the value
Returns:
this
See Also:
ScalarValue.ScalarValue(Object)

addListValue

public <T> VariableMapBuilder addListValue(String varname,
                                           Iterable<T> iterable)
Shortcut method to associate a name with a list value

Any Iterable can be used (thereby including all collections: sets, lists, etc). Note that it is your responsibility that objects in this iterable implement Object.toString() correctly!

Type Parameters:
T - type of elements in the iterable
Parameters:
varname - the variable name
iterable - the iterable
Returns:
this
See Also:
ListValue.copyOf(Iterable)

addListValue

public VariableMapBuilder addListValue(String varname,
                                       Object first,
                                       Object... other)
Shortcut method to associate a name with a list value

This method calls Object.toString() on each element to add; it is your responsibility to ensure that elements added implement Object.toString() correctly!

Parameters:
varname - the variable name
first - first element of the list value
other - other elements of the list value, if any
Returns:
this
See Also:
ListValue.of(Object, Object...)

addMapValue

public <T> VariableMapBuilder addMapValue(String varname,
                                          Map<String,T> map)
Shortcut method to associate a variable name to a map value

Values of the map can be of any type. You should ensure that they implement Object.toString() correctly!

Type Parameters:
T - type of map values
Parameters:
varname - the variable name
map - the map
Returns:
this
See Also:
MapValue.copyOf(Map)

addVariableMap

public VariableMapBuilder addVariableMap(VariableMap other)
Add all variable definitions from another variable map

Parameters:
other - the other variable map to copy definitions from
Returns:
this
Throws:
NullPointerException - other variable map is null

freeze

public VariableMap freeze()
Specified by:
freeze in interface com.github.fge.Thawed<VariableMap>