Class Maps


  • public abstract class Maps
    extends Object
    Provides utility methods for maps.
    Since:
    8.2.0
    Version:
    $Revision: 21231 $ $Date: 2018-04-24 19:34:27 -0300 (Tue, 24 Apr 2018) $
    • Method Detail

      • builder

        public static <K,​V> Maps.IMapBuilder<K,​V> builder()
        Returns a new map builder.
        Returns:
        a new map builder.
        Since:
        8.2.0
      • stringify

        public static <K,​V> String stringify​(Map<K,​V> map,
                                                   String separator,
                                                   IStringify<Map.Entry<K,​V>> stringify)
                                            throws PortalException
        Creates a string representation of the given map, using its entries as values. By convention, does not check whether the given stringify has returned null before concatenating to the result string.
        Parameters:
        map - the map.
        separator - the separator to use between the entries of the map.
        stringify - the stringfy to be used to convert entries in strings.
        Returns:
        the created string.
        Throws:
        PortalException
        Since:
        9.0.0
      • stringify

        public static <K,​V> String stringify​(Map<K,​V> map,
                                                   String prefix,
                                                   String suffix,
                                                   String separator,
                                                   IStringify<Map.Entry<K,​V>> stringify)
                                            throws PortalException
        Creates a string representation of the given map, using its entries as values. By convention, does not check whether the given stringify has returned null before concatenating to the result string.
        Parameters:
        map - the map.
        prefix - the prefix to be appended in final string.
        suffix - the suffix to be appended in final string.
        separator - the separator to use between the entries of the map.
        stringify - the stringfy to be used to convert entries in strings.
        Returns:
        the created string.
        Throws:
        PortalException
        Since:
        9.0.0
      • stringify

        public static <K,​V> String stringify​(Map<K,​V> map,
                                                   String prefix,
                                                   String suffix,
                                                   boolean includePrefixAndSuffixOnlyIfMapNotEmpty,
                                                   String separator,
                                                   IStringify<Map.Entry<K,​V>> stringify)
                                            throws PortalException
        Creates a string representation of the given map, using its entries as values. By convention, does not check whether the given stringify has returned null before concatenating to the result string.
        Parameters:
        map - the map.
        prefix - the prefix to be appended in final string.
        suffix - the suffix to be appended in final string.
        includePrefixAndSuffixOnlyIfMapNotEmpty - indicates whether prefix and suffix should be added only if the given collection is not empty.
        separator - the separator to use between the entries of the map.
        stringify - the stringfy to be used to convert entries in strings.
        Returns:
        the created string.
        Throws:
        PortalException
        Since:
        9.0.0
      • singleEntry

        public static <K,​V> Map<K,​V> singleEntry​(K key,
                                                             V value)
        Returns a single-entry map, containing the given key-value pair.
        Parameters:
        key - the key
        value - the value
        Returns:
        a single-entry map, containing the given key-value pair.
        Since:
        9.0.0
      • entryOf

        public static <K,​V> Map.Entry<K,​V> entryOf​(K key,
                                                               V value)
        Returns a new map entry of the given key-value pair.
        Parameters:
        key - the key.
        value - the value.
        Returns:
        a new map entry of the given key-value pair.
        Since:
        10.0.0
      • of

        public static <K,​V> Map<K,​V> of​(K k1,
                                                    V v1)
        Returns an immutable map with one mapping.
        Parameters:
        k1 - the key of mapping.
        v1 - the value of mapping.
        Returns:
        the immutable map.
        Since:
        10.4.0
      • of

        public static <K,​V> Map<K,​V> of​(K k1,
                                                    V v1,
                                                    K k2,
                                                    V v2)
        Returns an immutable map with two mappings.
        Parameters:
        k1 - the key of mapping 1.
        v1 - the value of mapping 1.
        k2 - the key of mapping 2.
        v2 - the value of mapping 2.
        Returns:
        the immutable map.
        Since:
        10.4.0
      • of

        public static <K,​V> Map<K,​V> of​(K k1,
                                                    V v1,
                                                    K k2,
                                                    V v2,
                                                    K k3,
                                                    V v3)
        Returns an immutable map with three mappings.
        Parameters:
        k1 - the key of mapping 1.
        v1 - the value of mapping 1.
        k2 - the key of mapping 2.
        v2 - the value of mapping 2.
        k3 - the key of mapping 3.
        v3 - the value of mapping 3.
        Returns:
        the immutable map.
        Since:
        10.4.0
      • of

        public static <K,​V> Map<K,​V> of​(K k1,
                                                    V v1,
                                                    K k2,
                                                    V v2,
                                                    K k3,
                                                    V v3,
                                                    K k4,
                                                    V v4)
        Returns an immutable map with four mappings.
        Parameters:
        k1 - the key of mapping 1.
        v1 - the value of mapping 1.
        k2 - the key of mapping 2.
        v2 - the value of mapping 2.
        k3 - the key of mapping 3.
        v3 - the value of mapping 3.
        k4 - the key of mapping 4.
        v4 - the value of mapping 4.
        Returns:
        the immutable map.
        Since:
        10.4.0