Class ArraySectionContainer<S extends Tracked<K>,K extends WorldKey>

java.lang.Object
net.paulem.arcana.regions.container.blocks.ArraySectionContainer<S,K>
Type Parameters:
S - the type of tracked objects, which must implement the Tracked interface
K - the type of the key associated with the tracked object
All Implemented Interfaces:
SectionContainer<S,K>

public class ArraySectionContainer<S extends Tracked<K>,K extends WorldKey> extends Object implements SectionContainer<S,K>
A fixed-size SectionContainer implementation backed by a plain array, indexed directly by position. Offers O(1) access at the cost of always allocating the full capacity upfront, regardless of how many positions are actually occupied.
  • Method Details

    • create

      public static <S extends Tracked<K>, K extends WorldKey> ArraySectionContainer<S,K> create(int size)
      Creates a new, empty ArraySectionContainer with the given fixed capacity.
      Type Parameters:
      S - the type of tracked objects
      K - the type of the key associated with the tracked object
      Parameters:
      size - the number of positions this container can hold
      Returns:
      a new ArraySectionContainer instance
    • get

      public Holder<S,K> get(int position)
      Retrieves the holder stored at the given position.
      Specified by:
      get in interface SectionContainer<S extends Tracked<K>,K extends WorldKey>
      Parameters:
      position - the index to look up
      Returns:
      the holder at the position, or null if empty
    • set

      public void set(int position, Holder<S,K> holder)
      Stores or clears the holder at the given position, updating the tracked size accordingly.
      Specified by:
      set in interface SectionContainer<S extends Tracked<K>,K extends WorldKey>
      Parameters:
      position - the index to store the holder at
      holder - the holder to store, or null to clear the position
    • getAll

      public it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap<Holder<S,K>> getAll()
      Builds a map of every occupied position to its holder.
      Specified by:
      getAll in interface SectionContainer<S extends Tracked<K>,K extends WorldKey>
      Returns:
      a map of position to holder for every non-null entry in this container
    • size

      public int size()
      Specified by:
      size in interface SectionContainer<S extends Tracked<K>,K extends WorldKey>
      Returns:
      the number of occupied positions in this container
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface SectionContainer<S extends Tracked<K>,K extends WorldKey>
      Returns:
      true if no positions are currently occupied