java.lang.Object
net.paulem.arcana.regions.container.blocks.DynamicSectionContainer<S,K>
- Type Parameters:
S- the type of tracked objects, which must implement theTrackedinterfaceK- the type of the key associated with the tracked object
- All Implemented Interfaces:
SectionContainer<S,K>
public class DynamicSectionContainer<S extends Tracked<K>,K extends WorldKey>
extends Object
implements SectionContainer<S,K>
A container implementation that dynamically transitions between a
MapContainer and
an ArraySectionContainer based on the load factor and size constraints. This class is
designed to optimize memory usage and performance by starting with an efficient map-based
container and expanding into an array-based container when necessary.-
Method Summary
Modifier and TypeMethodDescriptionstatic <S extends Tracked<K>,K extends WorldKey>
DynamicSectionContainer<S, K> create(float loadFactor, int maxSize) Creates a newDynamicSectionContainerwith the given load factor and capacity.static <S extends Tracked<K>,K extends WorldKey>
DynamicSectionContainer<S, K> create(int maxSize) Creates a newDynamicSectionContainerwith the given capacity and the default load factor.get(int position) Retrieves the holder at the given position from the currently active underlying container.getAll()voidputAll(SectionContainer<S, K> other) Copies every entry from the given container into this one, expanding to an array-backed container first if adding them would exceed the load factor.voidStores or clears the holder at the given position in the currently active underlying container, expanding to an array-backed container first if the load factor is now exceeded.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.paulem.arcana.regions.container.blocks.SectionContainer
copyTo, isEmpty, size
-
Method Details
-
create
public static <S extends Tracked<K>,K extends WorldKey> DynamicSectionContainer<S,K> create(float loadFactor, int maxSize) Creates a newDynamicSectionContainerwith the given load factor and capacity.- Type Parameters:
S- the type of tracked objectsK- the type of the key associated with the tracked object- Parameters:
loadFactor- the fraction ofmaxSizethat, once reached, triggers expansion to an array-backed containermaxSize- the maximum number of positions this container can hold once expanded- Returns:
- a new
DynamicSectionContainerinstance
-
create
public static <S extends Tracked<K>,K extends WorldKey> DynamicSectionContainer<S,K> create(int maxSize) Creates a newDynamicSectionContainerwith the given capacity and the default load factor.- Type Parameters:
S- the type of tracked objectsK- the type of the key associated with the tracked object- Parameters:
maxSize- the maximum number of positions this container can hold once expanded- Returns:
- a new
DynamicSectionContainerinstance
-
get
Retrieves the holder at the given position from the currently active underlying container. -
set
Stores or clears the holder at the given position in the currently active underlying container, expanding to an array-backed container first if the load factor is now exceeded. -
getAll
-
putAll
Copies every entry from the given container into this one, expanding to an array-backed container first if adding them would exceed the load factor.- Parameters:
other- the container whose entries should be copied into this one
-