Package one.microstream.collections.lazy
Class LazyArrayList<E>
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractList<E>
one.microstream.collections.lazy.LazyArrayList<E>
- Type Parameters:
E- the type of elements in this collection
- All Implemented Interfaces:
Iterable<E>,Collection<E>,List<E>,RandomAccess,LazyCollection<E>,LazyList<E>
public final class LazyArrayList<E> extends AbstractList<E> implements LazyList<E>, RandomAccess
LazyList implementation according to the specifications of ArrayList.
Lazy-loaded segments are used internally to achieve the partial loading.
The maximum size of these segments can be specified within the constructor.
This implementation requires an active microstream storage with specialized
type handlers. Without those handles a correct behavior is not guaranteed.
The required handlers are:
BinaryHandlerLazyArrayList
BinaryHandlerControlledLazy
This list tries to unload segments depending on the provided LazySegmentUnloader.
By default, it will use the LazySegmentUnloader.Default that keeps two segments loaded.
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classLazyArrayList.SegmentNested classes/interfaces inherited from interface one.microstream.collections.lazy.LazyCollection
LazyCollection.Static -
Field Summary
-
Constructor Summary
Constructors Constructor Description LazyArrayList()Creates a newLazyArrayListwith a maximum segment size of 1000.LazyArrayList(int maxSegmentSize)Creates a newLazyArrayListwith a defined maximum segment size.LazyArrayList(int maxSegmentSize, LazySegmentUnloader lazySegmentUnloader)Creates a newLazyArrayListwith a defined maximum segment size.LazyArrayList(LazyArrayList<E> list)Creates a new copy from the suppliedLazyArrayList. -
Method Summary
Modifier and Type Method Description voidadd(int index, E element)booleanadd(E element)booleanaddAll(int index, Collection<? extends E> elements)booleanaddAll(Collection<? extends E> elements)voidclear()booleanconsolidate()Optimizes the internal structure of this lazy collection.booleancontains(Object element)Eget(int index)intgetMaxSegmentSize()Returns the maximum segment size of thisLazyArrayList.longgetSegmentCount()Returns the current number of internal segments.intindexOf(Object element)booleanisEmpty()<P extends Consumer<Lazy<?>>>
PiterateLazyReferences(P procedure)Iterates over all internally usedLazyreferences.intlastIndexOf(Object element)Iterator<E>loadedFirstIterator()Creates a newIteratorthat will iterate all loaded entries first, it does not define any other specific ordering.Eremove(int index)booleanremove(Object element)booleanremoveAll(Collection<?> elements)booleanremoveIf(Predicate<? super E> filter)booleanretainAll(Collection<?> elements)Iterable<? extends LazyArrayList.Segment>segments()Returns an Iterable over the Segment in this list.Spliterator<E>segmentSpliterator()Creates aSpliteratorthat splits at the LazyArrayList segments borders.Eset(int index, E element)intsize()Spliterator<E>spliterator()Creates aSpliteratorthat splits at the LazyArrayList segments borders.Object[]toArray()<T> T[]toArray(T[] array)voidtryUnload(boolean unloadAll)Tries to unload as much as possible elements from the collection.Methods inherited from class java.util.AbstractList
equals, hashCode, iterator, listIterator, listIterator, removeRange, subListMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface one.microstream.collections.lazy.LazyCollection
parallelStream, streamMethods inherited from interface java.util.List
containsAll, equals, hashCode, iterator, listIterator, listIterator, replaceAll, sort, subList
-
Constructor Details
-
LazyArrayList
public LazyArrayList()Creates a newLazyArrayListwith a maximum segment size of 1000. -
LazyArrayList
public LazyArrayList(int maxSegmentSize)Creates a newLazyArrayListwith a defined maximum segment size.- Parameters:
maxSegmentSize- maximum segment size, must be positive
-
LazyArrayList
Creates a newLazyArrayListwith a defined maximum segment size.- Parameters:
maxSegmentSize- maximum segment size, must be positivelazySegmentUnloader- LazySegmentUnloader instance
-
LazyArrayList
Creates a new copy from the suppliedLazyArrayList.
The Objects of the source list will not be copied, both lists will reference the object instances.- Parameters:
list- to be copied.
-
-
Method Details
-
getSegmentCount
public long getSegmentCount()Returns the current number of internal segments.- Returns:
- the current number of internal segments.
-
segments
Returns an Iterable over the Segment in this list.- Returns:
- an Iterable over the Segment in this list
-
getMaxSegmentSize
public int getMaxSegmentSize()Returns the maximum segment size of thisLazyArrayList.- Returns:
- the maximum segment size of this
LazyArrayList
-
size
public int size()- Specified by:
sizein interfaceCollection<E>- Specified by:
sizein interfaceList<E>- Specified by:
sizein classAbstractCollection<E>
-
isEmpty
public boolean isEmpty()- Specified by:
isEmptyin interfaceCollection<E>- Specified by:
isEmptyin interfaceList<E>- Overrides:
isEmptyin classAbstractCollection<E>
-
tryUnload
public void tryUnload(boolean unloadAll)Description copied from interface:LazyCollectionTries to unload as much as possible elements from the collection. The amount of unloaded data depends on the collection's implementation details. E.g if the collection is configured to keep a minimum of data in memory that minimum will not be unloaded as long as the parameter unloadAll is not specified. If unloadAll is set it will try to to fall below that limit.- Specified by:
tryUnloadin interfaceLazyCollection<E>- Parameters:
unloadAll- if true try to unload everything, try to fall below limit if possible.
-
contains
- Specified by:
containsin interfaceCollection<E>- Specified by:
containsin interfaceList<E>- Overrides:
containsin classAbstractCollection<E>
-
indexOf
-
lastIndexOf
- Specified by:
lastIndexOfin interfaceList<E>- Overrides:
lastIndexOfin classAbstractList<E>
-
toArray
- Specified by:
toArrayin interfaceCollection<E>- Specified by:
toArrayin interfaceList<E>- Overrides:
toArrayin classAbstractCollection<E>
-
toArray
public <T> T[] toArray(T[] array)- Specified by:
toArrayin interfaceCollection<E>- Specified by:
toArrayin interfaceList<E>- Overrides:
toArrayin classAbstractCollection<E>
-
get
-
set
-
add
- Specified by:
addin interfaceCollection<E>- Specified by:
addin interfaceList<E>- Overrides:
addin classAbstractList<E>
-
addAll
- Specified by:
addAllin interfaceCollection<E>- Specified by:
addAllin interfaceList<E>- Overrides:
addAllin classAbstractCollection<E>
-
add
-
addAll
-
remove
-
remove
- Specified by:
removein interfaceCollection<E>- Specified by:
removein interfaceList<E>- Overrides:
removein classAbstractCollection<E>
-
removeAll
- Specified by:
removeAllin interfaceCollection<E>- Specified by:
removeAllin interfaceList<E>- Overrides:
removeAllin classAbstractCollection<E>
-
removeIf
- Specified by:
removeIfin interfaceCollection<E>
-
retainAll
- Specified by:
retainAllin interfaceCollection<E>- Specified by:
retainAllin interfaceList<E>- Overrides:
retainAllin classAbstractCollection<E>
-
consolidate
public boolean consolidate()Description copied from interface:LazyCollectionOptimizes the internal structure of this lazy collection. Closes possible gaps and cleans up unused storage space.- Specified by:
consolidatein interfaceLazyCollection<E>- Returns:
trueif the internal structure has changed,falseotherwise
-
iterateLazyReferences
Description copied from interface:LazyCollectionIterates over all internally usedLazyreferences.- Specified by:
iterateLazyReferencesin interfaceLazyCollection<E>- Type Parameters:
P- the procedure type- Parameters:
procedure- the lazy reference consumer- Returns:
- the given procedure
-
clear
public void clear()- Specified by:
clearin interfaceCollection<E>- Specified by:
clearin interfaceList<E>- Overrides:
clearin classAbstractList<E>
-
spliterator
Creates aSpliteratorthat splits at the LazyArrayList segments borders.- Specified by:
spliteratorin interfaceCollection<E>- Specified by:
spliteratorin interfaceIterable<E>- Specified by:
spliteratorin interfaceList<E>- Returns:
- a
Spliteratorinstance.
-
segmentSpliterator
Creates aSpliteratorthat splits at the LazyArrayList segments borders.- Returns:
- a
Spliteratorinstance.
-
loadedFirstIterator
Creates a newIteratorthat will iterate all loaded entries first, it does not define any other specific ordering.- Returns:
- a new loadedFirstIterator.
-