Class ColonyList<T extends IColony>

java.lang.Object
com.minecolonies.core.colony.ColonyList<T>
Type Parameters:
T - Type of IColony (Colony or ColonyView)
All Implemented Interfaces:
Iterable<T>

public final class ColonyList<T extends IColony> extends Object implements Iterable<T>
Data structure for storing colonies, optimized for performance.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(T colony)
    Add a new Colony to the List.
    void
    Empty the list.
    create(net.minecraft.world.level.Level world, net.minecraft.core.BlockPos position)
    Creates a new Colony, adds it to the list, and returns it.
    get(int index)
    Get the Colony with the provided colony id.
    @NotNull List<T>
    Copy all of the colonies to a List.
    int
    Return the number of Colonies in the list.
    int
    Get the top colony id.
    boolean
    Checks if there are Colonies in the list.
    Makes an iterator for the list.
    void
    remove(int id)
    Remove the colony with the provided id from the list.
    void
    remove(T colony)
    Remove the Colony from the list.
    Create a Stream of Colonies.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface java.lang.Iterable

    forEach, spliterator
  • Constructor Details

    • ColonyList

      public ColonyList()
  • Method Details

    • create

      public Colony create(net.minecraft.world.level.Level world, net.minecraft.core.BlockPos position)
      Creates a new Colony, adds it to the list, and returns it.
      Parameters:
      world - The world for the Colony.
      position - The position for the Colony center.
      Returns:
      The newly created Colony.
    • add

      public void add(T colony)
      Add a new Colony to the List.
      Parameters:
      colony - colony to add to the list.
    • get

      @Nullable public T get(int index)
      Get the Colony with the provided colony id.
      Parameters:
      index - colony id.
      Returns:
      The Colony associated with the provided id.
    • remove

      public void remove(T colony)
      Remove the Colony from the list.
      Parameters:
      colony - the Colony to remove.
    • remove

      public void remove(int id)
      Remove the colony with the provided id from the list.
      Parameters:
      id - colony id to remove.
    • clear

      public void clear()
      Empty the list.
    • getTopID

      public int getTopID()
      Get the top colony id.
      Returns:
      the top id.
    • getSize

      public int getSize()
      Return the number of Colonies in the list.
      Returns:
      number of Colonies in the list.
    • isEmpty

      public boolean isEmpty()
      Checks if there are Colonies in the list.
      Returns:
      true if there are no Colonies.
    • getCopyAsList

      @NotNull public @NotNull List<T> getCopyAsList()
      Copy all of the colonies to a List. Because this does a copy, it should only be used when really needed.
      Returns:
      List of Colonies.
    • iterator

      public Iterator<T> iterator()
      Makes an iterator for the list.
      Specified by:
      iterator in interface Iterable<T extends IColony>
      Returns:
      an iterator for the colonies.
    • stream

      public Stream<T> stream()
      Create a Stream of Colonies.
      Returns:
      a Colony Stream.