Class StructuredDictionary

java.lang.Object
net.visma.autopay.http.structured.StructuredDictionary
All Implemented Interfaces:
StructuredField, StructuredMap

public final class StructuredDictionary extends Object implements StructuredField, StructuredMap
Class representing Structured Dictionaries
See Also:
  • Method Details

    • of

      public static StructuredDictionary of(Map<String,?> objectMap)
      Creates Structured Dictionary of given Map value.

      Order of Map entries is preserved. For supported value types and conversion rules see StructuredList.of(Collection).

      Parameters:
      objectMap - Map to be converted to Structured Dictionary
      Returns:
      Created Structured Dictionary
      Throws:
      IllegalArgumentException - Invalid keys or values
    • of

      public static StructuredDictionary of(Object... keysAndValues)
      Creates Structured Dictionary of provided keys and values.

      Keys and values should be provided in alternate indices of the vararg param. Order of Map entries is preserved.

      Keys are created using from "even" vararg items, using Object.toString(). Values are created from "odd" vararg items, using conversion described at StructuredList.of(Collection).

      Parameters:
      keysAndValues - Alternating keys and values: key1, value1, key2, value2, ...
      Returns:
      Created Structured Dictionary
      Throws:
      IllegalArgumentException - Invalid keys or values
    • itemMap

      public <T extends StructuredItem> Map<String,T> itemMap()
      Description copied from interface: StructuredMap
      Returns Map of Structured Items stored in this Dictionary or Parameters. Keys or returned map correspond to Dictionary or Parameters keys. Values are StructuredItem members of Dictionary or Parameters.
      Specified by:
      itemMap in interface StructuredMap
      Type Parameters:
      T - Specific Item class if needed. No type check is performed, only simple casting.
      Returns:
      Underlying map of StructuredItem objects
    • listMap

      public <T extends StructuredItem> Map<String,List<T>> listMap()
      Returns this map with Inner List values converted to List of StructuredItem objects. This map must contain StructuredInnerList values only.
      Type Parameters:
      T - Specific class of List members, if needed and the inner lists are homogenous
      Returns:
      Map with values converted to List of StructuredItem
      Throws:
      ClassCastException - Thrown if this map contains non-StructuredInnerList values
    • getList

      public <T extends StructuredItem> Optional<List<T>> getList(String key)
      Returns the value of StructuredInnerList at requested key. Valid for StructuredInnerList Items only.
      Type Parameters:
      T - Specific class of Inner List members, if needed and the list is homogenous
      Parameters:
      key - Dictionary key
      Returns:
      List of StructuredItem values stored at requested key
    • serialize

      public String serialize()
      Serializes this Structured Dictionary to a String, according to the specification.
      Specified by:
      serialize in interface StructuredField
      Returns:
      Serialized representation of this Structured Dictionary
      See Also:
    • parse

      public static StructuredDictionary parse(String httpHeader) throws StructuredException
      Parses given string for Structured Dictionary, according to the specification
      Parameters:
      httpHeader - String to parse, e.g. HTTP header
      Returns:
      Parsed Structured Dictionary
      Throws:
      StructuredException - Thrown in case of malformatted string or wrong item type
      See Also:
    • parse

      public static StructuredDictionary parse(Collection<String> httpHeaders) throws StructuredException
      Parses given HTTP header values for Structured Dictionary, according to the specification
      Parameters:
      httpHeaders - HTTP header values, for common header name, provided in order of occurrence in HTTP message
      Returns:
      Parsed Structured Dictionary
      Throws:
      StructuredException - Thrown in case of malformatted string or wrong item type
      See Also:
    • equals

      public boolean equals(Object o)
      Compares the specified object with this Structured Dictionary for equality. Returns true if the given object is of the same class as this Dictionary, has the same value and properties.
      Overrides:
      equals in class Object
      Parameters:
      o - Object to be compared with this Structured Dictionary
      Returns:
      True is specified object is equal to this Structured Dictionary
    • hashCode

      public int hashCode()
      Returns hash code for this Structured Dictionary. The hash code is a combination of hash codes of Dictionary entries.
      Overrides:
      hashCode in class Object
      Returns:
      The hash code for this Structured Dictionary
    • toString

      public String toString()
      Returns the string representation of this Structured Dictionary, which is the same as serialized representation.
      Overrides:
      toString in class Object
      Returns:
      A string representation of this Structured Dictionary
      See Also: