Class DataMap<K>

  • Type Parameters:
    K - Type of keys in this map.

    public final class DataMap<K>
    extends Object
    An opaque, strongly typed heterogeneous data container. Data maps can be set to accept only a certain type of key, with the type parameter. The key can itself constrain the type of values, using its own type parameter T.
    • Method Detail

      • set

        public <T> @Nullable T set​(DataMap.DataKey<? extends K,​? super T> key,
                                   T data)
        Set the mapping to the given data.
        Type Parameters:
        T - Type of the data
        Parameters:
        key - Key
        data - Data mapped to the key
        Returns:
        Previous value associated with the key (nullable)
      • get

        public <T> @Nullable T get​(DataMap.DataKey<? extends K,​? extends T> key)
        Retrieves the data currently mapped to the key.
        Type Parameters:
        T - Type of the data
        Parameters:
        key - Key
        Returns:
        Value associated with the key (nullable)
      • getOrDefault

        public <T> T getOrDefault​(DataMap.DataKey<? extends K,​? extends T> key,
                                  T defaultValue)
      • computeIfAbsent

        public <T> T computeIfAbsent​(DataMap.DataKey<? extends K,​T> key,
                                     Supplier<? extends T> supplier)
        Retrieve the value, or compute it if it is missing.
        Type Parameters:
        T - Type of the data
        Parameters:
        key - Key
        supplier - Supplier for a value
        Returns:
        Value associated with the key (as nullable as the
      • compute

        public <T> T compute​(DataMap.DataKey<? extends K,​T> key,
                             Function<? super @Nullable T,​? extends T> function)
        Create or replace a mapping with a value computed from the current value (or null if missing).
        Type Parameters:
        T - Type of the data
        Parameters:
        key - Key
        function - Supplier for a value
        Returns:
        Value returned by the parameter function
      • isSet

        public boolean isSet​(DataMap.DataKey<? extends K,​?> key)
        Returns true if the given key has a non-null value in the map.
        Parameters:
        key - Key
        Returns:
        True if some value is set
      • newDataMap

        public static <K> DataMap<K> newDataMap()