Interface TypeSafeMap

  • All Superinterfaces:
    java.lang.Iterable<java.util.Map.Entry<Key<?>,​java.lang.Object>>

    @Immutable
    public interface TypeSafeMap
    extends java.lang.Iterable<java.util.Map.Entry<Key<?>,​java.lang.Object>>
    A map that is type safe, i.e. the pairs (key, value) are type-checked. It's immutable.
    Author:
    Fabrizio Giudici
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Default Methods Deprecated Methods 
      Modifier and Type Method Description
      java.util.Map<Key<?>,​java.lang.Object> asMap()
      Returns the contents as a plain Map.
      boolean containsKey​(Key<?> key)
      Checks whether a pair has been stored.
      java.util.Set<java.util.Map.Entry<Key<?>,​java.lang.Object>> entrySet()
      Returns a set of all the contained (key, value) pairs.
      void forEach​(java.util.function.BiConsumer<? super Key<?>,​? super java.lang.Object> action)
      Performs the given action on all the pairs (key, value) contained in this map.
      <T> T get​(Key<T> key)
      Deprecated.
      Use getOptional(Key) instead
      default <T> java.util.Optional<T> getOptional​(Key<? extends T> key)
      Returns an optional value given its key.
      java.util.Set<Key<?>> keySet()
      Returns a set of all the contained keys.
      static TypeSafeMap newInstance()
      Creates a new empty instance.
      static TypeSafeMap ofCloned​(java.util.Map<? extends Key<?>,​java.lang.Object> map)
      Creates an instance cloning the given map.
      int size()
      Returns the size of this map.
      java.util.Collection<java.lang.Object> values()
      Returns a set of all the contained values.
      <T> TypeSafeMap with​(Key<T> key, T value)
      Create a new instance with an additional pair (key, value=
      • Methods inherited from interface java.lang.Iterable

        forEach, iterator, spliterator
    • Method Detail

      • get

        @Nonnull
        @Deprecated
        <T> T get​(@Nonnull
                  Key<T> key)
           throws NotFoundException
        Deprecated.
        Use getOptional(Key) instead
        Returns a value given its key.
        Type Parameters:
        T - the type
        Parameters:
        key - the key
        Returns:
        the value
        Throws:
        NotFoundException - if the key is not found
      • getOptional

        @Nonnull
        default <T> java.util.Optional<T> getOptional​(@Nonnull
                                                      Key<? extends T> key)
        Returns an optional value given its key.
        Type Parameters:
        T - the type
        Parameters:
        key - the key
        Returns:
        the value
        Since:
        3.2-ALPHA-1
      • containsKey

        boolean containsKey​(@Nonnull
                            Key<?> key)
        Checks whether a pair has been stored.
        Parameters:
        key - the key
        Returns:
        true if the pair is present
      • keySet

        @Nonnull
        java.util.Set<Key<?>> keySet()
        Returns a set of all the contained keys.
        Returns:
        the keys as a mutable set
      • values

        @Nonnull
        java.util.Collection<java.lang.Object> values()
        Returns a set of all the contained values.
        Returns:
        the values as a mutable collection
        Since:
        3.2-ALPHA-6
      • entrySet

        @Nonnull
        java.util.Set<java.util.Map.Entry<Key<?>,​java.lang.Object>> entrySet()
        Returns a set of all the contained (key, value) pairs.
        Returns:
        the pairs as a mutable collection
        Since:
        3.2-ALPHA-6
      • size

        @Nonnegative
        int size()
        Returns the size of this map.
        Returns:
        the size
      • asMap

        @Nonnull
        java.util.Map<Key<?>,​java.lang.Object> asMap()
        Returns the contents as a plain Map.
        Returns:
        the contents as a mutable map
      • forEach

        void forEach​(@Nonnull
                     java.util.function.BiConsumer<? super Key<?>,​? super java.lang.Object> action)
        Performs the given action on all the pairs (key, value) contained in this map.
        Parameters:
        action - the action
        Since:
        3.2-ALPHA-10
      • with

        @Nonnull
        <T> TypeSafeMap with​(@Nonnull
                             Key<T> key,
                             @Nonnull
                             T value)
        Create a new instance with an additional pair (key, value=
        Type Parameters:
        T - the type
        Parameters:
        key - the key
        value - the value
        Returns:
        the new instance
        Since:
        3.2-ALPHA-2
      • newInstance

        @Nonnull
        static TypeSafeMap newInstance()
        Creates a new empty instance.
        Returns:
        the new instance
        Since:
        3.2-ALPHA-2
      • ofCloned

        @Nonnull
        static TypeSafeMap ofCloned​(@Nonnull
                                    java.util.Map<? extends Key<?>,​java.lang.Object> map)
        Creates an instance cloning the given map.
        Parameters:
        map - the map to clone
        Returns:
        the new instance
        Since:
        3.2-ALPHA-2