Interface InheritanceAwareMap<C,​V>

  • Type Parameters:
    C - the base class type
    V - the value type

    public interface InheritanceAwareMap<C,​V>
    A map type that will traverse class hierarchy to find a value for a key.

    These maps are null-hostile, so both keys and values must not be null.

    There is a concept of strict mode, where map values have to be strictly non-ambiguous. When this enabled (by default it is not), a value will not be added if any subtypes or supertypes are already registered to the map.

    Inheritance aware maps are always immutable, so any mutation operations will apply any changes to a new, modified instance.

    Since:
    4.17.0
    • Method Detail

      • empty

        @NotNull
        static <K,​E> @NotNull InheritanceAwareMap<K,​E> empty()
        Get an empty inheritance aware map.
        Type Parameters:
        K - class type upper bound
        E - value type
        Returns:
        the map
        Since:
        4.17.0
      • builder

        static <K,​E> @NotNull InheritanceAwareMap.Builder<K,​E> builder()
        Create a new builder for an inheritance aware map.
        Type Parameters:
        K - class type upper bound
        E - value type
        Returns:
        a new builder
        Since:
        4.17.0
      • builder

        static <K,​E> @NotNull InheritanceAwareMap.Builder<K,​E> builder​(InheritanceAwareMap<? extends K,​? extends E> existing)
        Create a new builder for an inheritance aware map.
        Type Parameters:
        K - class type upper bound
        E - value type
        Parameters:
        existing - the existing map to populate the builder with
        Returns:
        a new builder
        Since:
        4.17.0
      • containsKey

        boolean containsKey​(@NotNull
                            @NotNull java.lang.Class<? extends C> clazz)
        Check whether this map contains a value (direct or computed) for the provided class.
        Parameters:
        clazz - the class type to check
        Returns:
        whether such a value is present
        Since:
        4.17.0
      • get

        @Nullable
        V get​(@NotNull
              @NotNull java.lang.Class<? extends C> clazz)
        Get the applicable value for the provided class.

        This can be either a direct or inherited value.

        Parameters:
        clazz - the class type
        Returns:
        the value, if any is available
        Since:
        4.17.0
      • with

        @CheckReturnValue
        @NotNull
        @NotNull InheritanceAwareMap<C,​V> with​(@NotNull
                                                     @NotNull java.lang.Class<? extends C> clazz,
                                                     @NotNull
                                                     V value)
        Get an updated inheritance aware map with the provided key changed.
        Parameters:
        clazz - the class type
        value - the value to update to
        Returns:
        the updated map
        Since:
        4.17.0
      • without

        @CheckReturnValue
        @NotNull
        @NotNull InheritanceAwareMap<C,​V> without​(@NotNull
                                                        @NotNull java.lang.Class<? extends C> clazz)
        Get an updated inheritance aware map with the provided key removed.
        Parameters:
        clazz - the class type to remove a direct value for
        Returns:
        the updated map
        Since:
        4.17.0