Class TemplateProcessor.KeyMap

java.lang.Object
java.util.AbstractMap<K,V>
java.util.HashMap<String,Object>
org.bzdev.util.TemplateProcessor.KeyMap
All Implemented Interfaces:
Serializable, Cloneable, Map<String,Object>
Enclosing class:
TemplateProcessor

public static class TemplateProcessor.KeyMap extends HashMap<String,Object>
Map from TemplateProcessor keys to their corresponding values. The keys are correspond to the first token in a TemplateProcessor directive. The corresponding value is typically a string, but may be one of the following: There is a one additional method that a 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:
  • 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 map
      loadFactor - the load factor for the map
    • KeyMap

      public KeyMap(Map<String,Object> map)
      Constructor given an existing map.
      Parameters:
      map - an existing map that will be copied
  • Method Details

    • get

      public Object get(Object key)
      Get the value associated with a key.
      Specified by:
      get in interface Map<String,Object>
      Overrides:
      get in class HashMap<String,Object>
      Parameters:
      key - the key
      Returns:
      the corresponding value
    • put

      public Object put(String key, Object value) throws IllegalArgumentException
      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 interface Map<String,Object>
      Overrides:
      put in class HashMap<String,Object>
      Parameters:
      key - the key
      value - the value corresponding to the key (either a String or an instance of a class implementing TemplateProcessor.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 implementing TemplateProcessor.KeyMapIterable.

      Parameters:
      key - the key
      value - 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 of TemplateProcessor.KeyMap, TemplateProcessor.KeyMapList, TemplateProcessor.KeyMapIterable, or an array of TemplateProcessor.KeyMap that provides the map or list to use for iteration given an initial '+' in the key when the key has a non-null value
      hasntList - an instance of TemplateProcessor.KeyMap, TemplateProcessor.KeyMapList, TemplateProcessor.KeyMapIterable, or an array of TemplateProcessor.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

      public void putAll(Map<? extends String,? extends Object> m)
      Take the key-value pairs provided by a map and add these to this map.
      Specified by:
      putAll in interface Map<String,Object>
      Overrides:
      putAll in class HashMap<String,Object>
      Parameters:
      m - a map associating keys with values
    • 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

      public void print(OutputStream os, String csn)
      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 stream
      csn - the name of the character set to use
    • print

      public void print(PrintWriter out)
      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