Interface TypedMap

  • All Known Subinterfaces:
    ExecutionContext
    All Known Implementing Classes:
    DefaultExecutionContext

    public interface TypedMap
    Stores key-value attributes that can be retrieved in a type-safe manner.
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      <T> T get​(TypedKey<T> key)
      Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.
      Map<TypedKey<Object>,​Object> getAll()
      Returns all the key-value pairs as a Map.
      <T> T getOrDefault​(TypedKey<T> key, T defaultValue)
      Returns the value to which the specified key is mapped, or defaultValue if this map contains no mapping for the key.
      <T> void put​(TypedKey<T> key, T value)
      Associates the specified value with the specified key in this map.
      <T> void remove​(TypedKey<T> key)
      Removes the mapping for a key from this map if it is present (optional operation).
    • Method Detail

      • put

        <T> void put​(TypedKey<T> key,
                     T value)
        Associates the specified value with the specified key in this map. If the map previously contained a mapping for the key, the old value is replaced.
        Type Parameters:
        T - type of key and value
        Parameters:
        key - key with which the specified value is to be associated
        value - value to be associated with the specified key
        Throws:
        NullPointerException - if the specified key or value is null and this map does not permit null keys or values
      • get

        <T> T get​(TypedKey<T> key)
        Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

        More formally, if this map contains a mapping from a key k to a value v such that (key==null ? k==null : key.equals(k)), then this method returns v; otherwise it returns null. (There can be at most one such mapping.)

        A return value of null does not necessarily indicate that the map contains no mapping for the key; it's also possible that the map explicitly maps the key to null.

        Type Parameters:
        T - type of key
        Parameters:
        key - key for the value to return
        Returns:
        the value associated with key, or null if there was no mapping for key. (A null return can also indicate that the map previously associated null with key.)
        Throws:
        NullPointerException - if the specified key is null and this map does not permit null keys
      • getOrDefault

        <T> T getOrDefault​(TypedKey<T> key,
                           T defaultValue)
        Returns the value to which the specified key is mapped, or defaultValue if this map contains no mapping for the key.
        Type Parameters:
        T - type of key and value
        Parameters:
        key - key whose associated value is to be returned
        defaultValue - default mapping of the key
        Returns:
        value to which the specified key is mapped, or defaultValue if this map contains no mapping for the key
        Throws:
        NullPointerException - if the specified key is null and this map does not permit null keys
      • remove

        <T> void remove​(TypedKey<T> key)
        Removes the mapping for a key from this map if it is present (optional operation). More formally, if this map contains a mapping from key k to value v such that (key==null ? k==null : key.equals(k)), that mapping is removed. (The map can contain at most one such mapping.)

        Returns the value to which this map previously associated the key, or null if the map contained no mapping for the key.

        If this map permits null values, then a return value of null does not necessarily indicate that the map contained no mapping for the key; it's also possible that the map explicitly mapped the key to null.

        The map will not contain a mapping for the specified key once the call returns.

        Parameters:
        key - key whose mapping is to be removed from the map
        Throws:
        NullPointerException - if the specified key is null and this map does not permit null keys