Package jodd.http

Class HttpMultiMap<V>

  • All Implemented Interfaces:
    java.lang.Iterable<java.util.Map.Entry<java.lang.String,​V>>
    Direct Known Subclasses:
    HeadersMultiMap

    public class HttpMultiMap<V>
    extends java.lang.Object
    implements java.lang.Iterable<java.util.Map.Entry<java.lang.String,​V>>
    General purpose HTTP multi-map. It's optimized Linked-HashMap, designed for small number of items and String non-null keys. It stores keys in case-sensitive way, but, by default, you can read them in case-insensitive way.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private static class  HttpMultiMap.MapEntry<V>  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected HttpMultiMap​(boolean caseSensitive)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void _add​(int hash, int index, java.lang.String name, V value)  
      private void _remove​(int hash, int index, java.lang.String name)  
      private HttpMultiMap<V> _set​(java.lang.Iterable<java.util.Map.Entry<java.lang.String,​V>> map)  
      HttpMultiMap<V> add​(java.lang.String name, V value)  
      HttpMultiMap<V> addAll​(java.lang.String name, java.lang.Iterable<V> values)  
      HttpMultiMap<V> addAll​(java.util.Map<java.lang.String,​V> map)  
      HttpMultiMap<V> addAll​(HttpMultiMap<V> map)  
      HttpMultiMap<V> clear()
      Clears the map.
      boolean contains​(java.lang.String name)
      Returns true if name exist.
      java.util.List<java.util.Map.Entry<java.lang.String,​V>> entries()
      Returns all the entries of this map.
      private boolean eq​(java.lang.String name1, java.lang.String name2)
      Returns true if two names are the same.
      V get​(java.lang.String name)
      Returns the first value from the map associated with the name.
      java.util.List<V> getAll​(java.lang.String name)
      Returns all values associated with the name.
      java.util.Map.Entry<java.lang.String,​V> getEntry​(java.lang.String name)
      Returns first entry for given name.
      private int hash​(java.lang.String name)
      Calculates hash value of the input string.
      private static int index​(int hash)
      Calculates bucket index from the hash.
      boolean isEmpty()
      Returns true if map is empty.
      java.util.Iterator<java.util.Map.Entry<java.lang.String,​V>> iterator()
      Returns iterator of all entries.
      java.util.Set<java.lang.String> names()  
      static <T> HttpMultiMap<T> newCaseInsensitiveMap()
      Creates new case-insensitive multimap.
      static <T> HttpMultiMap<T> newCaseSensitiveMap()
      Creates new case-insensitive map.
      HttpMultiMap<V> remove​(java.lang.String name)  
      HttpMultiMap<V> set​(java.lang.String name, V value)  
      HttpMultiMap<V> setAll​(java.lang.String name, java.lang.Iterable<V> values)  
      HttpMultiMap<V> setAll​(java.util.Map<java.lang.String,​V> map)  
      HttpMultiMap<V> setAll​(HttpMultiMap<V> multiMap)  
      int size()
      Returns the number of keys.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.lang.Iterable

        forEach, spliterator
    • Constructor Detail

      • HttpMultiMap

        protected HttpMultiMap​(boolean caseSensitive)
    • Method Detail

      • newCaseInsensitiveMap

        public static <T> HttpMultiMap<T> newCaseInsensitiveMap()
        Creates new case-insensitive multimap.
      • newCaseSensitiveMap

        public static <T> HttpMultiMap<T> newCaseSensitiveMap()
        Creates new case-insensitive map.
      • hash

        private int hash​(java.lang.String name)
        Calculates hash value of the input string.
      • index

        private static int index​(int hash)
        Calculates bucket index from the hash.
      • eq

        private boolean eq​(java.lang.String name1,
                           java.lang.String name2)
        Returns true if two names are the same.
      • size

        public int size()
        Returns the number of keys. This is not the number of all elements. Not optimized.
      • contains

        public boolean contains​(java.lang.String name)
        Returns true if name exist.
      • isEmpty

        public boolean isEmpty()
        Returns true if map is empty.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • _set

        private HttpMultiMap<V> _set​(java.lang.Iterable<java.util.Map.Entry<java.lang.String,​V>> map)
      • setAll

        public HttpMultiMap<V> setAll​(java.util.Map<java.lang.String,​V> map)
      • set

        public HttpMultiMap<V> set​(java.lang.String name,
                                   V value)
      • setAll

        public HttpMultiMap<V> setAll​(java.lang.String name,
                                      java.lang.Iterable<V> values)
      • add

        public HttpMultiMap<V> add​(java.lang.String name,
                                   V value)
      • addAll

        public HttpMultiMap<V> addAll​(java.lang.String name,
                                      java.lang.Iterable<V> values)
      • addAll

        public HttpMultiMap<V> addAll​(java.util.Map<java.lang.String,​V> map)
      • _add

        private void _add​(int hash,
                          int index,
                          java.lang.String name,
                          V value)
      • remove

        public HttpMultiMap<V> remove​(java.lang.String name)
      • _remove

        private void _remove​(int hash,
                             int index,
                             java.lang.String name)
      • get

        public V get​(java.lang.String name)
        Returns the first value from the map associated with the name. Returns null if name does not exist or if associated value is null.
      • getEntry

        public java.util.Map.Entry<java.lang.String,​V> getEntry​(java.lang.String name)
        Returns first entry for given name. Returns null if entry does not exist.
      • getAll

        public java.util.List<V> getAll​(java.lang.String name)
        Returns all values associated with the name.
      • iterator

        public java.util.Iterator<java.util.Map.Entry<java.lang.String,​V>> iterator()
        Returns iterator of all entries.
        Specified by:
        iterator in interface java.lang.Iterable<V>
      • names

        public java.util.Set<java.lang.String> names()
      • entries

        public java.util.List<java.util.Map.Entry<java.lang.String,​V>> entries()
        Returns all the entries of this map. Case sensitivity does not influence the returned list, it always contains all of the values.