Class GroupByMap<K,​E>


  • public class GroupByMap<K,​E>
    extends java.lang.Object
    A map which groups all elements added at the same key.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(E row)
      Adds a new row.
      static <K,​E>
      GroupByMap<K,​E>
      create​(java.lang.Iterable<? extends E> rows, IGroupKeyExtractor<K,​E> extractor)
      Creates a map for the specified rows with a given key extractor.
      java.util.Set<K> getKeys()  
      java.util.Map<K,​java.util.List<E>> getMap()  
      java.util.List<E> getOrDie​(K key)
      Returns all rows added at the specified key.
      java.util.List<E> tryGet​(K key)
      Returns all rows added at the specified key.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • GroupByMap

        public GroupByMap​(IGroupKeyExtractor<K,​E> extractor)
        Parameters:
        extractor - computes a key for the row
    • Method Detail

      • create

        public static <K,​E> GroupByMap<K,​E> create​(java.lang.Iterable<? extends E> rows,
                                                               IGroupKeyExtractor<K,​E> extractor)
        Creates a map for the specified rows with a given key extractor.
      • add

        public void add​(E row)
        Adds a new row.
      • tryGet

        public java.util.List<E> tryGet​(K key)
        Returns all rows added at the specified key.
      • getOrDie

        public java.util.List<E> getOrDie​(K key)
        Returns all rows added at the specified key.
        Throws:
        java.lang.IllegalStateException - if the key is not in the map
      • getKeys

        public java.util.Set<K> getKeys()
        Returns:
        all available keys
      • getMap

        public java.util.Map<K,​java.util.List<E>> getMap()
        Returns:
        unmodifiable map from key to a list of its values.