Class MapBuilder

  • Direct Known Subclasses:
    MapBuilder.Default

    public abstract class MapBuilder
    extends 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 Detail

      • _features

        protected final int _features
      • _checkDups

        protected final boolean _checkDups
      • _mapType

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

      • MapBuilder

        protected MapBuilder​(int features,
                             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)
      • isEnabled

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

        public Map<Object,​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 Map<Object,​Object> singletonMap​(Object key,
                                                     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