Class ImmutableMapTemplate<K>

    • Method Detail

      • ordered

        public static <K> @NonNull ImmutableMapTemplate<K> ordered​(Collection<K> keys)
        Create a template which produces Maps with specified keys, with iteration order matching the iteration order of keys. keySet() will return these keys in exactly the same order. The resulting map will retain insertion order through UnmodifiableMapPhase.toModifiableMap() transformations.
        Type Parameters:
        K - the type of keys maintained by resulting template
        Parameters:
        keys - Keys in requested iteration order.
        Returns:
        A template object.
        Throws:
        NullPointerException - if keys or any of its elements is null
        IllegalArgumentException - if keys is empty
      • unordered

        public static <K> @NonNull ImmutableMapTemplate<K> unordered​(Collection<K> keys)
        Create a template which produces Maps with specified keys, with unconstrained iteration order. Produced maps will have the iteration order matching the order returned by keySet(). The resulting map will NOT retain ordering through UnmodifiableMapPhase.toModifiableMap() transformations.
        Type Parameters:
        K - the type of keys maintained by resulting template
        Parameters:
        keys - Keys in any iteration order.
        Returns:
        A template object.
        Throws:
        NullPointerException - if keys or any of its elements is null
        IllegalArgumentException - if keys is empty
      • instantiateTransformed

        public abstract <T,​V> @NonNull UnmodifiableMapPhase<K,​V> instantiateTransformed​(Map<K,​T> fromMap,
                                                                                                    BiFunction<K,​T,​V> keyValueTransformer)
        Instantiate an immutable map by applying specified transformer to values of fromMap.
        Type Parameters:
        T - the type of input values
        V - the type of mapped values
        Parameters:
        fromMap - Input map
        keyValueTransformer - Transformation to apply to values
        Returns:
        An immutable map
        Throws:
        NullPointerException - if any of the arguments is null or if the transformer produces a null value
        IllegalArgumentException - if fromMap#keySet() does not match this template's keys
      • instantiateWithValues

        public abstract <V> @NonNull UnmodifiableMapPhase<K,​V> instantiateWithValues​(V... values)
        Instantiate an immutable map by filling values from provided array. The array MUST be ordered to match key order as returned by keySet().
        Type Parameters:
        V - the type of mapped values
        Parameters:
        values - Values to use
        Returns:
        An immutable map
        Throws:
        NullPointerException - if values or any of its elements is null
        IllegalArgumentException - if values.length does not match the number of keys in this template
      • keySet

        public abstract Set<K> keySet()
        Returns the set of keys expected by this template, in the iteration order Maps resulting from instantiation will have.
        Returns:
        This template's key set
        See Also:
        Map.keySet()