Class ArrayValueMap


  • public final class ArrayValueMap
    extends java.lang.Object
    Collects the array values of a key/value data object, writing the fields or map values only after all values have been collected.

    The typical application for this is when parsing JSON or XML when the value type is known to be an array. It stores the values in a collection during the parsing, and only when the parsing of an object is finished does it convert the collection into an array and stores it.

    Use put(String, Class, Object) when the destination object is a map with string keys and whose values accept an array of objects. Use put(Field, Class, Object) when setting the value of a field using reflection, assuming its type accepts an array of objects. One can potentially use both put methods for example on an instance of GenericData.

    Implementation is not thread-safe. For a thread-safe choice instead use an implementation of ConcurrentMap.

    Since:
    1.4
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      (package private) static class  ArrayValueMap.ArrayValue
      Array values on a particular field.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.Object destination
      Destination object whose fields must be set, or destination map whose values must be set.
      private java.util.Map<java.lang.reflect.Field,​ArrayValueMap.ArrayValue> fieldMap
      Map from field to its array values.
      private java.util.Map<java.lang.String,​ArrayValueMap.ArrayValue> keyMap
      Map from key name to its array values.
    • Constructor Summary

      Constructors 
      Constructor Description
      ArrayValueMap​(java.lang.Object destination)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void put​(java.lang.reflect.Field field, java.lang.Class<?> arrayComponentType, java.lang.Object value)
      Puts an additional value for the given field, accumulating values on repeated calls on the same field.
      void put​(java.lang.String keyName, java.lang.Class<?> arrayComponentType, java.lang.Object value)
      Puts an additional value for the given key name, accumulating values on repeated calls on the same key name.
      void setValues()
      Sets the fields of the given object using the values collected during parsing of the object's fields.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • keyMap

        private final java.util.Map<java.lang.String,​ArrayValueMap.ArrayValue> keyMap
        Map from key name to its array values.
      • fieldMap

        private final java.util.Map<java.lang.reflect.Field,​ArrayValueMap.ArrayValue> fieldMap
        Map from field to its array values.
      • destination

        private final java.lang.Object destination
        Destination object whose fields must be set, or destination map whose values must be set.
    • Constructor Detail

      • ArrayValueMap

        public ArrayValueMap​(java.lang.Object destination)
        Parameters:
        destination - destination object whose fields must be set, or destination map whose values must be set
    • Method Detail

      • setValues

        public void setValues()
        Sets the fields of the given object using the values collected during parsing of the object's fields.
      • put

        public void put​(java.lang.reflect.Field field,
                        java.lang.Class<?> arrayComponentType,
                        java.lang.Object value)
        Puts an additional value for the given field, accumulating values on repeated calls on the same field.
        Parameters:
        field - field
        arrayComponentType - array component type
        value - value
      • put

        public void put​(java.lang.String keyName,
                        java.lang.Class<?> arrayComponentType,
                        java.lang.Object value)
        Puts an additional value for the given key name, accumulating values on repeated calls on the same key name.
        Parameters:
        keyName - key name
        arrayComponentType - array component type
        value - value