Class ConverterValueMap

java.lang.Object
org.openhab.core.config.core.xml.util.ConverterValueMap

@NonNullByDefault public class ConverterValueMap extends Object
The ConverterValueMap reads all children elements of a node and provides them as key-value pair map.

This class should be used for nodes whose children elements only contain simple values (without children) and whose order is unpredictable. There must be only one children with the same name.

Author:
Michael Grammling - Initial contribution, Alex Tugarev - Extended for options and filter criteria
  • Constructor Summary

    Constructors
    Constructor
    Description
    ConverterValueMap(com.thoughtworks.xstream.io.HierarchicalStreamReader reader, int numberOfValues, com.thoughtworks.xstream.converters.UnmarshallingContext context)
    Creates a new instance of this class with the specified parameters.
    ConverterValueMap(com.thoughtworks.xstream.io.HierarchicalStreamReader reader, com.thoughtworks.xstream.converters.UnmarshallingContext context)
    Creates a new instance of this class with the specified parameter.
  • Method Summary

    Modifier and Type
    Method
    Description
    @Nullable Boolean
    getBoolean(String nodeName)
    Returns the boolean associated with the specified name of the child's node.
    @Nullable Boolean
    getBoolean(String nodeName, @Nullable Boolean defaultValue)
    Returns the boolean associated with the specified name of the child's node.
    @Nullable Integer
    getInteger(String nodeName)
    Returns the numeric value associated with the specified name of the child's node.
    @Nullable Integer
    getInteger(String nodeName, @Nullable Integer defaultValue)
    Returns the numeric value associated with the specified name of the child's node.
    @Nullable Object
    getObject(String nodeName)
    Returns the object associated with the specified name of the child's node.
    @Nullable Object
    getObject(String nodeName, @Nullable Object defaultValue)
    Returns the object associated with the specified name of the child's node.
    @Nullable String
    getString(String nodeName)
    Returns the text associated with the specified name of the child's node.
    @Nullable String
    getString(String nodeName, @Nullable String defaultValue)
    Returns the text associated with the specified name of the child's node.
    Returns the key-value map containing all read-in children.
    static Map<String,Object>
    readValueMap(com.thoughtworks.xstream.io.HierarchicalStreamReader reader, int numberOfValues, com.thoughtworks.xstream.converters.UnmarshallingContext context)
    Reads-in N children in a key-value map and returns it.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ConverterValueMap

      public ConverterValueMap(com.thoughtworks.xstream.io.HierarchicalStreamReader reader, com.thoughtworks.xstream.converters.UnmarshallingContext context)
      Creates a new instance of this class with the specified parameter.
      Parameters:
      reader - the reader to be used to read-in all children
      context -
    • ConverterValueMap

      public ConverterValueMap(com.thoughtworks.xstream.io.HierarchicalStreamReader reader, int numberOfValues, com.thoughtworks.xstream.converters.UnmarshallingContext context) throws com.thoughtworks.xstream.converters.ConversionException
      Creates a new instance of this class with the specified parameters.
      Parameters:
      reader - the reader to be used to read-in all children (must not be null)
      numberOfValues - the number of children to be read-in (< 0 = until end of section)
      context -
      Throws:
      com.thoughtworks.xstream.converters.ConversionException - if not all children could be read-in
  • Method Details

    • getValueMap

      public Map<String,Object> getValueMap()
      Returns the key-value map containing all read-in children.
      Returns:
      the key-value map containing all read-in children (could be empty)
    • readValueMap

      public static Map<String,Object> readValueMap(com.thoughtworks.xstream.io.HierarchicalStreamReader reader, int numberOfValues, com.thoughtworks.xstream.converters.UnmarshallingContext context) throws com.thoughtworks.xstream.converters.ConversionException
      Reads-in N children in a key-value map and returns it.
      Parameters:
      reader - the reader to be used to read-in the children
      numberOfValues - the number of children to be read in (< 0 = until end of section)
      context -
      Returns:
      the key-value map containing the read-in children (not null, could be empty)
      Throws:
      com.thoughtworks.xstream.converters.ConversionException - if not all children could be read-in
    • getObject

      public @Nullable Object getObject(String nodeName)
      Returns the object associated with the specified name of the child's node.
      Parameters:
      nodeName - the name of the child's node
      Returns:
      the object associated with the specified name of the child's node
    • getObject

      public @Nullable Object getObject(String nodeName, @Nullable Object defaultValue)
      Returns the object associated with the specified name of the child's node.
      Parameters:
      nodeName - the name of the child's node
      defaultValue - the value to be returned if the node could not be found
      Returns:
      the object associated with the specified name of the child's node
    • getString

      public @Nullable String getString(String nodeName)
      Returns the text associated with the specified name of the child's node.
      Parameters:
      nodeName - the name of the child's node
      Returns:
      the text associated with the specified name of the child's node
    • getString

      public @Nullable String getString(String nodeName, @Nullable String defaultValue)
      Returns the text associated with the specified name of the child's node.
      Parameters:
      nodeName - the name of the child's node
      defaultValue - the text to be returned if the node could not be found
      Returns:
      the text associated with the specified name of the child's node
    • getBoolean

      public @Nullable Boolean getBoolean(String nodeName)
      Returns the boolean associated with the specified name of the child's node.
      Parameters:
      nodeName - the name of the child's node
      Returns:
      the boolean associated with the specified name of the child's node
    • getBoolean

      public @Nullable Boolean getBoolean(String nodeName, @Nullable Boolean defaultValue)
      Returns the boolean associated with the specified name of the child's node.
      Parameters:
      nodeName - the name of the child's node
      defaultValue - the boolean to be returned if the node could not be found
      Returns:
      the boolean associated with the specified name of the child's node
    • getInteger

      public @Nullable Integer getInteger(String nodeName) throws com.thoughtworks.xstream.converters.ConversionException
      Returns the numeric value associated with the specified name of the child's node.
      Parameters:
      nodeName - the name of the child's node
      Returns:
      the numeric value associated with the specified name of the child's node
      Throws:
      com.thoughtworks.xstream.converters.ConversionException - if the value could not be converted to a numeric value
    • getInteger

      public @Nullable Integer getInteger(String nodeName, @Nullable Integer defaultValue) throws com.thoughtworks.xstream.converters.ConversionException
      Returns the numeric value associated with the specified name of the child's node.
      Parameters:
      nodeName - the name of the child's node
      defaultValue - the numeric value to be returned if the node could not be found
      Returns:
      the numeric value associated with the specified name of the child's node
      Throws:
      com.thoughtworks.xstream.converters.ConversionException - if the value could not be converted to a numeric value