Class StructureRegistry

java.lang.Object
nl.pim16aap2.animatedarchitecture.core.structures.StructureRegistry
All Implemented Interfaces:
IDebuggable, StructureDeletionManager.IDeletionListener

@Singleton public final class StructureRegistry extends Object implements IDebuggable, StructureDeletionManager.IDeletionListener
Represents a registry of structures.
See Also:
  • Field Details

    • CACHE_EXPIRY

      public static final Duration CACHE_EXPIRY
  • Method Details

    • unCached

      public static StructureRegistry unCached(DebuggableRegistry debuggableRegistry, StructureDeletionManager structureDeletionManager)
      Creates a new StructureRegistry without any caching.
      Returns:
      The new StructureRegistry.
    • onStructureDeletion

      public void onStructureDeletion(IStructureConst structure)
      Description copied from interface: StructureDeletionManager.IDeletionListener
      Called when a structure is deleted.
      Specified by:
      onStructureDeletion in interface StructureDeletionManager.IDeletionListener
      Parameters:
      structure - The structure that was deleted.
    • getRegisteredStructure

      public Optional<Structure> getRegisteredStructure(long structureUID)
      Attempts to get the Structure associated the given UID. It can only retrieve doors that still exist in the cache.
      Parameters:
      structureUID - The UID of the structure.
      Returns:
      The Structure if it has been retrieved from the database.
    • isRegistered

      public boolean isRegistered(long structureUID)
      Checks if a Structure associated with a given UID has been registered.
      Parameters:
      structureUID - The UID of the structure.
      Returns:
      True if an entry exists for the Structure with the given UID.
    • isRegistered

      public boolean isRegistered(Structure structure)
      Checks if the exact instance of the provided Structure has been registered. (i.e. it uses '==' to check if the cached entry is the same).
      Parameters:
      structure - The structure.
      Returns:
      True if an entry exists for the exact instance of the provided Structure.
    • putIfAbsent

      public Optional<Structure> putIfAbsent(Structure structure)
      Puts a new Structure in the cache if it does not exist yet.
      Parameters:
      structure - The structure to put in the cache.
      Returns:
      An empty Optional if the structure was successfully put in the cache. If a mapping already existed, the old structure will be returned instead.
    • getDebugInformation

      public String getDebugInformation()
      Description copied from interface: IDebuggable
      Gets the debug information for this object.
      Specified by:
      getDebugInformation in interface IDebuggable
      Returns:
      The debug information or null if there's nothing to log at this time.