Package com.pnfsoftware.jeb.util.collect
Class MultiList<E>
java.lang.Object
com.pnfsoftware.jeb.util.collect.MultiList<E>
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()clear(int index) Clear a bucket.findAllElements(int index, Predicate<E> check) findFirstElement(int index, Predicate<E> check) get(int index) Retrieve the elements stored in an indexed bucket.indexSet()booleanisEmpty()intAdd an element to a bucket.voidvoidputMulti(int index, Collection<? extends E> values) Add multiple elements mapped by the same key.remove(int index) Remove a bucket and shift subsequent bucket entries.booleanremoveElement(int index, E value) Remove an element from a bucket.intremoveMultipleElements(int index, Predicate<E> check) Remove elements from a bucket.intsize()Get the total number of elements stored in all the buckets.toString()values()
-
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
Add an element to a bucket.- Parameters:
index-elt-- Returns:
-
putMulti
Add multiple elements mapped by the same key.- Parameters:
index-values-
-
putAll
-
get
Retrieve the elements stored in an indexed bucket.- Parameters:
index-- Returns:
- a list, possibly empty, never null
-
clear
Clear a bucket. The bucket stays.- Parameters:
index-- Returns:
- the list of elements that were in the cleared bucket, possibly empty, never null
-
remove
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
Remove an element from a bucket.- Parameters:
index-value- the element to be removed- Returns:
-
removeMultipleElements
Remove elements from a bucket.- Parameters:
index-check-- Returns:
- the number of elements removed
-
findFirstElement
-
findAllElements
-
values
-
indexSet
-
toString
-