Package com.pnfsoftware.jeb.util.collect
Class MultiList<E>
java.lang.Object
com.pnfsoftware.jeb.util.collect.MultiList<E>
- Type Parameters:
E- element type
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()Remove all buckets and values.clear(int index) Clear a bucket.findAllElements(int index, Predicate<E> check) Find all elements in a bucket matching a predicate.findFirstElement(int index, Predicate<E> check) Find the first element in a bucket matching a predicate.get(int index) Retrieve the elements stored in an indexed bucket.indexSet()Retrieve the indices of non-empty buckets.booleanisEmpty()Determine whether this multi-list has no values.intAdd an element to a bucket.voidputAll(Collection<Collection<? extends E>> colls) Add all bucketed values.voidputMulti(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()Retrieve all values.
-
Constructor Details
-
MultiList
public MultiList()Create a new multi-list.
-
-
Method Details
-
clear
public void clear()Remove all buckets and values. -
isEmpty
public boolean isEmpty()Determine whether this multi-list has no values.- Returns:
- true if no values are stored
-
size
public int size()Get the total number of elements stored in all the buckets.- Returns:
- total number of elements
-
put
Add an element to a bucket.- Parameters:
index- bucket indexelt- element to add- Returns:
- updated count of values in the bucket
-
putMulti
Add multiple elements mapped by the same key.- Parameters:
index- bucket indexvalues- values to add
-
putAll
Add all bucketed values.- Parameters:
colls- collections of values, in bucket order
-
get
Retrieve the elements stored in an indexed bucket.- Parameters:
index- bucket index- Returns:
- a list, possibly empty, never null
-
clear
Clear a bucket. The bucket stays.- Parameters:
index- bucket 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- bucket 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- bucket indexvalue- the element to be removed- Returns:
- true if the element was removed
-
removeMultipleElements
Remove elements from a bucket.- Parameters:
index- bucket indexcheck- predicate selecting elements to remove- Returns:
- the number of elements removed
-
findFirstElement
Find the first element in a bucket matching a predicate.- Parameters:
index- bucket indexcheck- predicate selecting elements- Returns:
- first matching element, or null if none was found
-
findAllElements
Find all elements in a bucket matching a predicate.- Parameters:
index- bucket indexcheck- predicate selecting elements- Returns:
- list of matching elements
-
values
Retrieve all values.- Returns:
- read-only collection of values
-
indexSet
Retrieve the indices of non-empty buckets.- Returns:
- navigable set of bucket indices
-
toString
-