Class ImmutableClassToInstanceMap.Builder<B>

  • Enclosing class:
    ImmutableClassToInstanceMap<B>

    public static final class ImmutableClassToInstanceMap.Builder<B>
    extends java.lang.Object
    A builder for creating immutable class-to-instance maps. Example:

    After invoking build() it is still possible to add more entries and build again. Thus each map generated by this builder will be a superset of any map generated before it.

    Since:
    2.0
    • Constructor Summary

      Constructors 
      Constructor Description
      Builder()
      Creates a new builder.
    • Constructor Detail

      • Builder

        public Builder()
        Creates a new builder.
    • Method Detail

      • put

        @CanIgnoreReturnValue
        public <T extends BImmutableClassToInstanceMap.Builder<Bput​(java.lang.Class<T> key,
                                                                        T value)
        Associates key with value in the built map. Duplicate keys are not allowed, and will cause build() to fail.
      • putAll

        @CanIgnoreReturnValue
        public <T extends BImmutableClassToInstanceMap.Builder<BputAll​(java.util.Map<? extends java.lang.Class<? extends T>,​? extends T> map)
        Associates all of map's keys and values in the built map. Duplicate keys are not allowed, and will cause build() to fail.
        Throws:
        java.lang.NullPointerException - if any key or value in map is null
        java.lang.ClassCastException - if any value is not an instance of the type specified by its key
      • build

        public ImmutableClassToInstanceMap<Bbuild()
        Returns a new immutable class-to-instance map containing the entries provided to this builder.
        Throws:
        java.lang.IllegalArgumentException - if duplicate keys were added