Interface Map<K,​T>

  • Type Parameters:
    K - the type for the key
    T - the type for the values
    All Superinterfaces:
    Collection<Pair<K,​T>>, Foldable<Pair<K,​T>>, java.lang.Iterable<Pair<K,​T>>, java.io.Serializable, Streamable<Pair<K,​T>>, Traversable<Pair<K,​T>>, Value<Pair<K,​T>>

    public interface Map<K,​T>
    extends Collection<Pair<K,​T>>
    This class represents a map implementation that is immutable. This means all operations that would change its contents result into a new Map being returned. The current instance is not modified.
    Since:
    0.0.3
    • Method Detail

      • put

        Map<K,​T> put​(K key,
                           T value)
        Add a new entry to the Map.
        Parameters:
        key - the key for the entry
        value - the value for the entry
        Returns:
        the new Map instance with the added key, value pair
        Throws:
        java.lang.NullPointerException - in case the key is null
      • remove

        Map<K,​T> remove​(K key)
        Removes any element with the corresponding key from the map.
        Parameters:
        key - the key indicating what needs to be removed
        Returns:
        a new instance without the entry with the key
      • orElse

        Map<K,​T> orElse​(java.util.function.Supplier<? extends java.lang.Iterable<? extends Pair<K,​T>>> supplier)
        Description copied from interface: Traversable
        Returns either this if it is non empty, otherwise the provided supplier is evaluated and returned.
        Specified by:
        orElse in interface Collection<K>
        Specified by:
        orElse in interface Traversable<K>
        Parameters:
        supplier - the supplier to generate the other
        Returns:
        this (@code Traversable} if non empty, otherwise other
      • orElse

        Map<K,​T> orElse​(java.lang.Iterable<? extends Pair<K,​T>> other)
        Description copied from interface: Traversable
        Returns either this if it is non empty, otherwise will return the provided other.
        Specified by:
        orElse in interface Collection<K>
        Specified by:
        orElse in interface Traversable<K>
        Parameters:
        other - the alternative
        Returns:
        this Traversable if non empty, or other
      • containsKey

        default boolean containsKey​(K key)
        Returns true if this Map contains the key provided.
        Parameters:
        key - the key to look for
        Returns:
        true if found, otherwise false
      • containsValue

        boolean containsValue​(T value)
        Verify if the presented value is contained within the Map value set.
        Parameters:
        value - the value to look for
        Returns:
        if the value is found or not
      • get

        T get​(K key)
        Get the value from the Map with the corresponding key. If the key is not contained in this instance then null will be returned.
        Parameters:
        key - the key to obtain the value for
        Returns:
        the corresponding value, or null
      • tail

        Map<K,​T> tail()
        Description copied from interface: Collection
        Build a new collection with all elements except for the head. If there is only one element present then an empty collection will be returned. If the operation is called on an empty collection an NoSuchElementException will be thrown.
        Specified by:
        tail in interface Collection<K>
        Returns:
        a collection containing the tail
      • valueStream

        java.util.stream.Stream<T> valueStream()
        Build a stream of the values contained within this Map.
        Returns:
        the stream with all the values
      • filter

        Map<K,​T> filter​(java.util.function.Predicate<Pair<K,​T>> predicate)
        Description copied from interface: Streamable
        Filter out an element if it does not match the supplied predicate. This operation will iterate over all elements and return a new set containing only the elements where the predicate returns true for.
        Specified by:
        filter in interface Collection<K>
        Specified by:
        filter in interface Streamable<K>
        Specified by:
        filter in interface Traversable<K>
        Parameters:
        predicate - the predicate to apply to the contents of this
        Returns:
        the filtered value
      • reject

        default Map<K,​T> reject​(java.util.function.Predicate<Pair<K,​T>> predicate)
        Description copied from interface: Traversable
        Return a list that removes all elements that match the predicate provided.
        Specified by:
        reject in interface Collection<K>
        Specified by:
        reject in interface Traversable<K>
        Parameters:
        predicate - the predicate to use
        Returns:
        the elements that do not match the predicate
      • toJava

        java.util.Map<K,​T> toJava()
        Convert the map to a regular Java map type.
        Returns:
        the new java map