Class MultiList<E>

java.lang.Object
com.pnfsoftware.jeb.util.collect.MultiList<E>

@Ser public class MultiList<E> extends Object
A list of lists to be used as a fast-access multi-map for cases where the key is an integer index located in a compact [0, N] range. Use with caution: if the input key range is sparse, it is better to use a MultiMap.
  • Constructor Details

    • MultiList

      public MultiList()
      Create a new multi-list.
  • Method Details

    • clear

      public void clear()
    • isEmpty

      public boolean isEmpty()
    • size

      public int size()
      Get the total number of elements stored in all the buckets.
      Returns:
    • put

      public int put(int index, E elt)
      Add an element to a bucket.
      Parameters:
      index -
      elt -
      Returns:
    • putMulti

      public void putMulti(int index, Collection<? extends E> values)
      Add multiple elements mapped by the same key.
      Parameters:
      index -
      values -
    • putAll

      public void putAll(List<List<? extends E>> c)
    • get

      public List<E> get(int index)
      Retrieve the elements stored in an indexed bucket.
      Parameters:
      index -
      Returns:
      a list, possibly empty, never null
    • clear

      public List<E> clear(int index)
      Clear a bucket. The bucket stays.
      Parameters:
      index -
      Returns:
      the list of elements that were in the cleared bucket, possibly empty, never null
    • remove

      public List<E> remove(int index)
      Remove a bucket and shift subsequent bucket entries. Eg, removing the bucket at index 10 means that buckets previously at indexes 11, 12, ..., N will be at indexes 10, 11, ..., N-1. Mind the unusual semantic of this operation.
      Parameters:
      index -
      Returns:
      the list of elements that were in the removed bucket, possibly empty, never null
    • removeElement

      public boolean removeElement(int index, E value)
      Remove an element from a bucket.
      Parameters:
      index -
      value - the element to be removed
      Returns:
    • removeMultipleElements

      public int removeMultipleElements(int index, Predicate<E> check)
      Remove elements from a bucket.
      Parameters:
      index -
      check -
      Returns:
      the number of elements removed
    • findFirstElement

      public E findFirstElement(int index, Predicate<E> check)
    • findAllElements

      public List<E> findAllElements(int index, Predicate<E> check)
    • values

      public Collection<E> values()
    • indexSet

      public NavigableSet<Integer> indexSet()
    • toString

      public String toString()
      Overrides:
      toString in class Object