Class ConverterValueMap


  • 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.
    • Constructor Detail

      • 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 (must not be null)
        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 Detail

      • 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 (not null, 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 (must not be null)
        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 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 (must not be null)
        Returns:
        the object associated with the specified name of the child's node (could be null)
      • getObject

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

        public 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 (must not be null)
        Returns:
        the text associated with the specified name of the child's node (could be null)
      • getString

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

        public 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 (must not be null)
        Returns:
        the boolean associated with the specified name of the child's node (could be null)
      • getBoolean

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

        public 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 (must not be null)
        Returns:
        the numeric value associated with the specified name of the child's node (could be null)
        Throws:
        com.thoughtworks.xstream.converters.ConversionException - if the value could not be converted to a numeric value
      • getInteger

        public Integer getInteger​(String nodeName,
                                  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 (must not be null)
        defaultValue - the numeric value to be returned if the node could not be found (could be null)
        Returns:
        the numeric value associated with the specified name of the child's node (could be null)
        Throws:
        com.thoughtworks.xstream.converters.ConversionException - if the value could not be converted to a numeric value