Interface TypeSafeMultiMap

  • All Superinterfaces:
    java.lang.Iterable<java.util.Collection<? extends java.lang.Object>>

    public interface TypeSafeMultiMap
    extends java.lang.Iterable<java.util.Collection<? extends java.lang.Object>>
    A map that is type safe, i.e the pairs (key, value) are type-checked, and can contain multiple values, i.e. it's associated to collections (key, collection of values). It's immutable.
    Author:
    Fabrizio Giudici
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      java.util.Map<Key<?>,​java.util.Collection<? extends java.lang.Object>> asMap()
      Returns the contents as a plain Map.
      boolean containsKey​(Key<?> key)
      Checks whether a pair has been stored.
      <T> java.util.Collection<T> get​(Key<T> key)
      Returns a value given its key.
      java.util.Set<Key<?>> getKeys()
      Returns a set of all the contained keys.
      int getSize()
      Returns the size of this map.
      static TypeSafeMultiMap newInstance()
      Creates a new empty instance.
      static TypeSafeMultiMap ofCloned​(java.util.Map<Key<?>,​java.util.Collection<?>> map)
      Creates an instance cloning the given map.
      <T> TypeSafeMultiMap 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
        <T> java.util.Collection<T> get​(@Nonnull
                                        Key<T> key)
        Returns a value given its key.
        Type Parameters:
        T - the type
        Parameters:
        key - the key
        Returns:
        the value as a Collection
      • containsKey

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

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

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

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

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

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

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