Class StructuredItem

java.lang.Object
net.visma.autopay.http.structured.StructuredItem
All Implemented Interfaces:
StructuredField
Direct Known Subclasses:
StructuredBoolean, StructuredBytes, StructuredDecimal, StructuredInnerList, StructuredInteger, StructuredString, StructuredToken

public abstract class StructuredItem extends Object implements StructuredField
Base class for Structured Items, Inner Lists and Parameter values

Items and Inner List have common base class because they both can have parameters and can be members of Structured List and Structured Dictionary. Parameter values do not have "inner" parameters and cannot be Inner Lists.

See Also:
  • Method Details

    • serialize

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

      public static StructuredItem parse(String httpHeader) throws StructuredException
      Parses given string for Structured Item, according to the specification

      Class of returned value depends on parsed content, and it can be any of StructuredItem's subclasses, excluding StructuredInnerList.

      Parameters:
      httpHeader - String to parse, e.g. an HTTP header
      Returns:
      Parsed Structured Item: a subclass of StructuredItem
      Throws:
      StructuredException - Thrown in case of malformatted string
      See Also:
    • stringValue

      public String stringValue()
      Returns string representation this Structured Item's value

      It's not the same as the result of serialization - it's closer to Object.toString(). Mostly, it should be used for StructuredString and StructuredToken, where underlying values are strings. For remaining classes, it could be for representation only. Properties are not included.

      Returns:
      String representation of this Structured Item's value
    • parameters

      public StructuredParameters parameters()
      Returns parameters associated with this Item. If the Item does not have any parameters, an "empty" object is returned - StructuredParameters with empty underlying map.
      Returns:
      Structured Item's parameters
    • stringParam

      public Optional<String> stringParam(String key)
      Returns value of requested parameter converted to a String. Valid for all parameter types: their String representation is returned.

      Mostly, it should be used for String and Token parameters.

      Parameters:
      key - Parameter key
      Returns:
      String value of requested parameter, or empty Optional if parameter with given key does not exist.
    • boolParam

      public Optional<Boolean> boolParam(String key)
      Returns Boolean value of requested parameter. Valid for Boolean parameters only.
      Parameters:
      key - Parameter key
      Returns:
      Boolean value of requested parameter, or empty Optional if parameter with given key does not exist.
      Throws:
      UnsupportedOperationException - When requested parameter is not a Boolean
    • intParam

      public Optional<Integer> intParam(String key)
      Returns Integer value of requested parameter. Valid for Integer parameters only.

      (int) cast is used internally, which means that returned value will be incorrect for parameter values smaller than Integer.MIN_VALUE or grater than Integer.MAX_VALUE.

      Parameters:
      key - Parameter key
      Returns:
      Int value of requested parameter, or empty Optional if parameter with given key does not exist.
      Throws:
      UnsupportedOperationException - When requested parameter is not an Integer
    • longParam

      public Optional<Long> longParam(String key)
      Returns Long value of requested parameter. Valid for Integer parameters only.
      Parameters:
      key - Parameter key
      Returns:
      Long value of requested parameter, or empty Optional if parameter with given key does not exist.
      Throws:
      UnsupportedOperationException - When requested parameter is not an Integer
    • bigDecimalParam

      public Optional<BigDecimal> bigDecimalParam(String key)
      Returns BigDecimal value of requested parameter. Valid for Decimal and Integer parameters only.
      Parameters:
      key - Parameter key
      Returns:
      BigDecimal value of requested parameter, or empty Optional if parameter with given key does not exist.
      Throws:
      UnsupportedOperationException - When requested parameter is neither Decimal nor Integer
    • doubleParam

      public Optional<Double> doubleParam(String key)
      Returns Double value of requested parameter. Valid for Decimal and Integer parameters only.
      Parameters:
      key - Parameter key
      Returns:
      Double value of requested parameter, or empty Optional if parameter with given key does not exist.
      Throws:
      UnsupportedOperationException - When requested parameter is neither Decimal nor Integer
    • bytesParam

      public Optional<byte[]> bytesParam(String key)
      Returns byte[] value of requested parameter. Valid for Byte Sequence parameters only.
      Parameters:
      key - Parameter key
      Returns:
      byte[] value of requested parameter, or empty Optional if parameter with given key does not exist.
      Throws:
      UnsupportedOperationException - When requested parameter is not a Byte Sequence
    • equals

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

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

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