Class Maps


  • public abstract class Maps
    extends java.lang.Object
    Provides utility methods for maps.
    Since:
    8.2.0
    Version:
    $Revision$ $Date$
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static interface  Maps.IMapBuilder<K,​V>
      Map builder.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <K,​V>
      Maps.IMapBuilder<K,​V>
      builder()
      Returns a new map builder.
      static <K,​V>
      java.util.Map.Entry<K,​V>
      entryOf​(K key, V value)
      Returns a new map entry of the given key-value pair.
      static <K,​V>
      java.util.Map<K,​V>
      of​(K k1, V v1)
      Returns an immutable map with one mapping.
      static <K,​V>
      java.util.Map<K,​V>
      of​(K k1, V v1, K k2, V v2)
      Returns an immutable map with two mappings.
      static <K,​V>
      java.util.Map<K,​V>
      of​(K k1, V v1, K k2, V v2, K k3, V v3)
      Returns an immutable map with three mappings.
      static <K,​V>
      java.util.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.
      static <K,​V>
      java.util.Map<K,​V>
      singleEntry​(K key, V value)
      Returns a single-entry map, containing the given key-value pair.
      static <K,​V>
      java.lang.String
      stringify​(java.util.Map<K,​V> map, java.lang.String prefix, java.lang.String suffix, boolean includePrefixAndSuffixOnlyIfMapNotEmpty, java.lang.String separator, IStringify<java.util.Map.Entry<K,​V>> stringify)
      Creates a string representation of the given map, using its entries as values.
      static <K,​V>
      java.lang.String
      stringify​(java.util.Map<K,​V> map, java.lang.String prefix, java.lang.String suffix, java.lang.String separator, IStringify<java.util.Map.Entry<K,​V>> stringify)
      Creates a string representation of the given map, using its entries as values.
      static <K,​V>
      java.lang.String
      stringify​(java.util.Map<K,​V> map, java.lang.String separator, IStringify<java.util.Map.Entry<K,​V>> stringify)
      Creates a string representation of the given map, using its entries as values.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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> java.lang.String stringify​(java.util.Map<K,​V> map,
                                                             java.lang.String separator,
                                                             IStringify<java.util.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> java.lang.String stringify​(java.util.Map<K,​V> map,
                                                             java.lang.String prefix,
                                                             java.lang.String suffix,
                                                             java.lang.String separator,
                                                             IStringify<java.util.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> java.lang.String stringify​(java.util.Map<K,​V> map,
                                                             java.lang.String prefix,
                                                             java.lang.String suffix,
                                                             boolean includePrefixAndSuffixOnlyIfMapNotEmpty,
                                                             java.lang.String separator,
                                                             IStringify<java.util.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> java.util.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> java.util.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> java.util.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> java.util.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> java.util.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> java.util.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