Class AbstractGenericDepot<T extends IPNDItem>

java.lang.Object
com.dna.jopt.member.unit.pnd.depot.AbstractGenericDepot<T>
Direct Known Subclasses:
AbstractNodeDepot, AbstractResourceDepot

public abstract class AbstractGenericDepot<T extends IPNDItem> extends Object
  • Constructor Details

    • AbstractGenericDepot

      public AbstractGenericDepot(String depotId)
  • Method Details

    • getDepotId

      public String getDepotId()
    • resetDerivedState

      protected void resetDerivedState()
      Called once at the very start of loadItemsDirect(java.util.List<T>), before any items are loaded and before any postAddOnCopy(T) calls.

      Override in subclasses that maintain derived boolean flags (e.g. isZeroLoad, hasFlexibleLoads, hasTimedLoads). The override must reset those flags to their "empty-depot" values so that the subsequent postAddOnCopy(T) loop can build them up correctly from scratch.

      Default is a no-op.

    • loadItemsDirect

      protected void loadItemsDirect(List<T> source)
      Bulk-loads items from a source list that is guaranteed to be duplicate-free (e.g., the output of a previous getItems() call).

      Calls resetDerivedState() first so that subclass flags are always consistent with the new contents, then populates both backing structures and calls postAddOnCopy(T) per item.

      DO NOT call from user-facing mutators. Use add(T) there — it has the duplicate-safety contract. This method is only correct when source is guaranteed unique.

      Parameters:
      source - duplicate-free list of items to load; must not be null, must not contain null elements
    • postAddOnCopy

      protected void postAddOnCopy(T item)
      Called by loadItemsDirect(java.util.List<T>) once per item. Default is a no-op.

      Override in subclasses that maintain derived state which must stay in sync even during a copy. Keep the implementation cheap — this is on the hot copy path.

      Parameters:
      item - the item just added to the backing structures
    • setItems

      public void setItems(List<T> items)
      Replaces all current items with the provided list.

      Delegates to loadItemsDirect(java.util.List<T>): the caller-supplied list is treated as a known-clean replacement set, so the full merge/dupe-check pipeline in add(T) is skipped. This is safe because setItems is itself a full replacement (not an incremental mutation), and any prior state is discarded first. resetDerivedState() is called inside loadItemsDirect before the loop.

    • getItems

      public List<T> getItems()
    • add

      public boolean add(T item)
      Adds a single item. Performs a full duplicate-id check and merge if needed. Use this for all user-facing mutations. For bulk-loading a copy, use loadItemsDirect(java.util.List<T>) instead.
    • mergeItem

      public abstract Optional<T> mergeItem(T itemOne, T itemTwo)
    • postAdd

      public abstract void postAdd(T item)
    • add

      public void add(List<T> items)
    • remove

      public boolean remove(T item)
    • replace

      public boolean replace(T orgItem, T newItem)
    • get

      public Optional<T> get(String key)