Class MapBuilder

  • Direct Known Subclasses:
    MapBuilder.Default

    public abstract class MapBuilder
    extends java.lang.Object
    Helper class that is used for constructing Maps to map JSON Object values in.

    Objects server both as "factories" for creating new builders (blueprint style), and as actual builders. For each distinct read operation, newBuilder(int) will be called at least once; this instance may be used and reused multiple times, as calling start() will reset the state so that more Lists may be built.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected boolean _checkDups  
      protected int _features  
      protected java.lang.Class<?> _mapType
      Optional Map implementation class, used when specific implementation is desired.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected MapBuilder​(int features, java.lang.Class<?> type)  
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      abstract java.util.Map<java.lang.String,​java.lang.Object> build()  
      static MapBuilder defaultImpl()
      Factory method for getting a blueprint instance of the default MapBuilder implementation.
      java.util.Map<java.lang.String,​java.lang.Object> emptyMap()
      Specialized method that is called when an empty list needs to be constructed; this may be a new list, or an immutable shared List, depending on implementation.
      boolean isEnabled​(JSON.Feature f)  
      MapBuilder newBuilder()  
      abstract MapBuilder newBuilder​(int features)  
      abstract MapBuilder newBuilder​(java.lang.Class<?> mapImpl)  
      abstract MapBuilder put​(java.lang.String key, java.lang.Object value)  
      java.util.Map<java.lang.String,​java.lang.Object> singletonMap​(java.lang.String key, java.lang.Object value)
      Specialized method that is called when an empty list needs to be constructed; this may be a new list, or an immutable shared List, depending on implementation.
      abstract MapBuilder start()  
      • Methods inherited from class java.lang.Object

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

      • _features

        protected final int _features
      • _checkDups

        protected final boolean _checkDups
      • _mapType

        protected final java.lang.Class<?> _mapType
        Optional Map implementation class, used when specific implementation is desired.
    • Constructor Detail

      • MapBuilder

        protected MapBuilder​(int features,
                             java.lang.Class<?> type)
    • Method Detail

      • defaultImpl

        public static MapBuilder defaultImpl()
        Factory method for getting a blueprint instance of the default MapBuilder implementation.
      • newBuilder

        public abstract MapBuilder newBuilder​(int features)
      • newBuilder

        public abstract MapBuilder newBuilder​(java.lang.Class<?> mapImpl)
      • isEnabled

        public final boolean isEnabled​(JSON.Feature f)
      • put

        public abstract MapBuilder put​(java.lang.String key,
                                       java.lang.Object value)
      • build

        public abstract java.util.Map<java.lang.String,​java.lang.Object> build()
      • emptyMap

        public java.util.Map<java.lang.String,​java.lang.Object> emptyMap()
                                                                        throws JSONObjectException
        Specialized method that is called when an empty list needs to be constructed; this may be a new list, or an immutable shared List, depending on implementation.

        Default implementation simply calls:

          start().build();
        
        which assumes that a builder has been constructed with newBuilder(int)
        Throws:
        JSONObjectException
      • singletonMap

        public java.util.Map<java.lang.String,​java.lang.Object> singletonMap​(java.lang.String key,
                                                                                   java.lang.Object value)
                                                                            throws JSONObjectException
        Specialized method that is called when an empty list needs to be constructed; this may be a new list, or an immutable shared List, depending on implementation.

        Default implementation simply calls:

          start().put(key, value).build();
        
        Throws:
        JSONObjectException