- All Implemented Interfaces:
Serializable
,Cloneable
,Map<String,
Object>
- Enclosing class:
- TemplateProcessor
- An instance of a TemplateProcessor iteration class or interface
(
TemplateProcessor.KeyMapIterable
,TemplateProcessor.KeyMapList
, an array ofTemplateProcessor.KeyMap
, or [as a special case that provides a single iteration]TemplateProcessor.KeyMap
). - Any other object (but typically a string) whose toString() method will produce the desired text.
Map
does not
provide:
put(String,Object,Object,Object)
.
This method is used to define custom iterations depending on
whether a value exists or not.- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K extends Object,
V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object, V extends Object> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionGet the value associated with a key.void
print()
Print this KeyMap to System.out using the UTF-8 charset.void
print
(OutputStream os, String csn) Print this KeyMap, specifying an output stream and character set.void
print
(PrintWriter out) Print this KeyMap using PrintWriter.Set the value for a key.void
Set a key-map entry for both a key and its '+' or '-' conditional directives.void
Take the key-value pairs provided by a map and add these to this map.Methods inherited from class java.util.HashMap
clear, clone, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, forEach, getOrDefault, isEmpty, keySet, merge, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values
Methods inherited from class java.util.AbstractMap
equals, hashCode, toString
-
Constructor Details
-
KeyMap
public KeyMap()Constructor. -
KeyMap
public KeyMap(int initialCapacity) Constructor given an initial capacity.- Parameters:
initialCapacity
- the initial capacity of the map
-
KeyMap
public KeyMap(int initialCapacity, float loadFactor) Constructor given an initial capacity and load factor.- Parameters:
initialCapacity
- the initial capacity of the maploadFactor
- the load factor for the map
-
KeyMap
Constructor given an existing map.- Parameters:
map
- an existing map that will be copied
-
-
Method Details
-
get
Get the value associated with a key. -
put
Set the value for a key. The key must not start with the characters '+' or '-'. A key containing white space will not be recognized by a template processor.- Specified by:
put
in interfaceMap<String,
Object> - Overrides:
put
in classHashMap<String,
Object> - Parameters:
key
- the keyvalue
- the value corresponding to the key (either aString
or an instance of a class implementingTemplateProcessor.KeyMapIterable
, with a null value trated as an empty string)- Returns:
- the previous object; null if there was none
- Throws:
IllegalArgumentException
-
put
public void put(String key, Object value, Object hasList, Object hasntList) throws IllegalArgumentException Set a key-map entry for both a key and its '+' or '-' conditional directives.A value, if not null, must be either a
String
or an instance of a class implementingTemplateProcessor.KeyMapIterable
.- Parameters:
key
- the keyvalue
- the value for the key (if null, the key will not be entered, but KeyMap entries for the hasList and hasntList will be entered if non null)hasList
- an instance ofTemplateProcessor.KeyMap
,TemplateProcessor.KeyMapList
,TemplateProcessor.KeyMapIterable
, or an array ofTemplateProcessor.KeyMap
that provides the map or list to use for iteration given an initial '+' in the key when the key has a non-null valuehasntList
- an instance ofTemplateProcessor.KeyMap
,TemplateProcessor.KeyMapList
,TemplateProcessor.KeyMapIterable
, or an array ofTemplateProcessor.KeyMap
that provides the map or list to use for iteration given an initial '-' in the key when the key has a null value- Throws:
IllegalArgumentException
-
putAll
Take the key-value pairs provided by a map and add these to this map. -
print
public void print()Print this KeyMap to System.out using the UTF-8 charset.The output format uses indentation to indicate nesting. When a key's value is another keymap or one of the keymap iteration classes, the type of iteration used is shown in square brackets immediately after the key, followed by indented descriptions of the keys provided by each iteration. When a key was constructed using the method
put(String,Object,Object,Object)
, the iteration for the '+' and '-' variants will be flagged with the phrase "ignored" or "in use" depending on whether or not the the key has a non-null or null value respectively. -
print
Print this KeyMap, specifying an output stream and character set.The output format uses indentation to indicate nesting. When a key's value is another keymap or one of the keymap iteration classes, the type of iteration used is shown in square brackets immediately after the key, followed by indented descriptions of the keys provided by each iteration. When a key was constructed using the method
put(String,Object,Object,Object)
, the iteration for the '+' and '-' variants will be flagged with the phrase "ignored" or "in use" depending on whether or not the the key has a non-null or null value respectively.- Parameters:
os
- the output streamcsn
- the name of the character set to use
-
print
Print this KeyMap using PrintWriter.The output format uses indentation to indicate nesting. When a key's value is another keymap or one of the keymap iteration classes, the type of iteration used is shown in square brackets immediately after the key, followed by indented descriptions of the keys provided by each iteration. When a key was constructed using the method
put(String,Object,Object,Object)
, the iteration for the '+' and '-' variants will be flagged with the phrase "ignored" or "in use" depending on whether or not the the key has a non-null or null value respectively.- Parameters:
out
- a print writer
-