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 class
LazyArrayList.Segment
Nested classes/interfaces inherited from interface one.microstream.collections.lazy.LazyCollection
LazyCollection.Static
-
Field Summary
-
Constructor Summary
Constructors Constructor Description LazyArrayList()
Creates a newLazyArrayList
with a maximum segment size of 1000.LazyArrayList(int maxSegmentSize)
Creates a newLazyArrayList
with a defined maximum segment size.LazyArrayList(int maxSegmentSize, LazySegmentUnloader lazySegmentUnloader)
Creates a newLazyArrayList
with a defined maximum segment size.LazyArrayList(LazyArrayList<E> list)
Creates a new copy from the suppliedLazyArrayList
. -
Method Summary
Modifier and Type Method Description void
add(int index, E element)
boolean
add(E element)
boolean
addAll(int index, Collection<? extends E> elements)
boolean
addAll(Collection<? extends E> elements)
void
clear()
boolean
consolidate()
Optimizes the internal structure of this lazy collection.boolean
contains(Object element)
E
get(int index)
int
getMaxSegmentSize()
Returns the maximum segment size of thisLazyArrayList
.long
getSegmentCount()
Returns the current number of internal segments.int
indexOf(Object element)
boolean
isEmpty()
<P extends Consumer<Lazy<?>>>
PiterateLazyReferences(P procedure)
Iterates over all internally usedLazy
references.int
lastIndexOf(Object element)
Iterator<E>
loadedFirstIterator()
Creates a newIterator
that will iterate all loaded entries first, it does not define any other specific ordering.E
remove(int index)
boolean
remove(Object element)
boolean
removeAll(Collection<?> elements)
boolean
removeIf(Predicate<? super E> filter)
boolean
retainAll(Collection<?> elements)
Iterable<? extends LazyArrayList.Segment>
segments()
Returns an Iterable over the Segment in this list.Spliterator<E>
segmentSpliterator()
Creates aSpliterator
that splits at the LazyArrayList segments borders.E
set(int index, E element)
int
size()
Spliterator<E>
spliterator()
Creates aSpliterator
that splits at the LazyArrayList segments borders.Object[]
toArray()
<T> T[]
toArray(T[] array)
void
tryUnload(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, subList
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface one.microstream.collections.lazy.LazyCollection
parallelStream, stream
Methods inherited from interface java.util.List
containsAll, equals, hashCode, iterator, listIterator, listIterator, replaceAll, sort, subList
-
Constructor Details
-
LazyArrayList
public LazyArrayList()Creates a newLazyArrayList
with a maximum segment size of 1000. -
LazyArrayList
public LazyArrayList(int maxSegmentSize)Creates a newLazyArrayList
with a defined maximum segment size.- Parameters:
maxSegmentSize
- maximum segment size, must be positive
-
LazyArrayList
Creates a newLazyArrayList
with 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:
size
in interfaceCollection<E>
- Specified by:
size
in interfaceList<E>
- Specified by:
size
in classAbstractCollection<E>
-
isEmpty
public boolean isEmpty()- Specified by:
isEmpty
in interfaceCollection<E>
- Specified by:
isEmpty
in interfaceList<E>
- Overrides:
isEmpty
in classAbstractCollection<E>
-
tryUnload
public void tryUnload(boolean unloadAll)Description copied from interface:LazyCollection
Tries 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:
tryUnload
in interfaceLazyCollection<E>
- Parameters:
unloadAll
- if true try to unload everything, try to fall below limit if possible.
-
contains
- Specified by:
contains
in interfaceCollection<E>
- Specified by:
contains
in interfaceList<E>
- Overrides:
contains
in classAbstractCollection<E>
-
indexOf
-
lastIndexOf
- Specified by:
lastIndexOf
in interfaceList<E>
- Overrides:
lastIndexOf
in classAbstractList<E>
-
toArray
- Specified by:
toArray
in interfaceCollection<E>
- Specified by:
toArray
in interfaceList<E>
- Overrides:
toArray
in classAbstractCollection<E>
-
toArray
public <T> T[] toArray(T[] array)- Specified by:
toArray
in interfaceCollection<E>
- Specified by:
toArray
in interfaceList<E>
- Overrides:
toArray
in classAbstractCollection<E>
-
get
-
set
-
add
- Specified by:
add
in interfaceCollection<E>
- Specified by:
add
in interfaceList<E>
- Overrides:
add
in classAbstractList<E>
-
addAll
- Specified by:
addAll
in interfaceCollection<E>
- Specified by:
addAll
in interfaceList<E>
- Overrides:
addAll
in classAbstractCollection<E>
-
add
-
addAll
-
remove
-
remove
- Specified by:
remove
in interfaceCollection<E>
- Specified by:
remove
in interfaceList<E>
- Overrides:
remove
in classAbstractCollection<E>
-
removeAll
- Specified by:
removeAll
in interfaceCollection<E>
- Specified by:
removeAll
in interfaceList<E>
- Overrides:
removeAll
in classAbstractCollection<E>
-
removeIf
- Specified by:
removeIf
in interfaceCollection<E>
-
retainAll
- Specified by:
retainAll
in interfaceCollection<E>
- Specified by:
retainAll
in interfaceList<E>
- Overrides:
retainAll
in classAbstractCollection<E>
-
consolidate
public boolean consolidate()Description copied from interface:LazyCollection
Optimizes the internal structure of this lazy collection. Closes possible gaps and cleans up unused storage space.- Specified by:
consolidate
in interfaceLazyCollection<E>
- Returns:
true
if the internal structure has changed,false
otherwise
-
iterateLazyReferences
Description copied from interface:LazyCollection
Iterates over all internally usedLazy
references.- Specified by:
iterateLazyReferences
in interfaceLazyCollection<E>
- Type Parameters:
P
- the procedure type- Parameters:
procedure
- the lazy reference consumer- Returns:
- the given procedure
-
clear
public void clear()- Specified by:
clear
in interfaceCollection<E>
- Specified by:
clear
in interfaceList<E>
- Overrides:
clear
in classAbstractList<E>
-
spliterator
Creates aSpliterator
that splits at the LazyArrayList segments borders.- Specified by:
spliterator
in interfaceCollection<E>
- Specified by:
spliterator
in interfaceIterable<E>
- Specified by:
spliterator
in interfaceList<E>
- Returns:
- a
Spliterator
instance.
-
segmentSpliterator
Creates aSpliterator
that splits at the LazyArrayList segments borders.- Returns:
- a
Spliterator
instance.
-
loadedFirstIterator
Creates a newIterator
that will iterate all loaded entries first, it does not define any other specific ordering.- Returns:
- a new loadedFirstIterator.
-