Class AbstractNodeDepot

java.lang.Object
com.dna.jopt.member.unit.pnd.depot.AbstractGenericDepot<ILoad>
com.dna.jopt.member.unit.pnd.depot.node.AbstractNodeDepot
All Implemented Interfaces:
INodeDepot
Direct Known Subclasses:
SimpleNodeDepot

public abstract class AbstractNodeDepot extends AbstractGenericDepot<ILoad> implements INodeDepot
  • Constructor Details

    • AbstractNodeDepot

      protected AbstractNodeDepot(String depotId)
  • Method Details

    • resetDerivedState

      protected void resetDerivedState()
      Resets all derived boolean flags to their "empty-depot" values before a bulk-load (setItems / loadItemsDirect).

      Called automatically by AbstractGenericDepot.loadItemsDirect(List) before the item loop, so that postAddOnCopy(ILoad) can rebuild the flags from scratch. Without this reset, a previous true value of hasFlexibleLoads would survive a reload with all-simple loads, and a previous false value of isZeroLoad would survive a reload with all-zero loads.

      Overrides:
      resetDerivedState in class AbstractGenericDepot<ILoad>
    • postAddOnCopy

      public void postAddOnCopy(ILoad item)
      Called by AbstractGenericDepot.loadItemsDirect(List) once per item on the fast copy/bulk path. Updates all derived flags from the item, starting from the "empty" baseline established by resetDerivedState().

      Mirrors postAdd(ILoad) but is kept separate so that the hot copy path can skip the heavier duplicate-check and merge logic.

      Overrides:
      postAddOnCopy in class AbstractGenericDepot<ILoad>
      Parameters:
      item - the item just added to the backing structures
    • postAdd

      public void postAdd(ILoad item)
      Called by AbstractGenericDepot.add(T) after a new item is inserted or merged. Flips derived flags from false → true as needed; never flips isZeroLoad from false back to true — that direction requires a full recalculation via recalcDerivedState().
      Specified by:
      postAdd in class AbstractGenericDepot<ILoad>
    • remove

      public boolean remove(ILoad item)
      Removes item from the depot and recalculates all derived state.

      A simple one-way flag update is insufficient here: removing the last non-zero item must flip isZeroLoad back to true, and removing the last flex/timed item must flip those flags back to false. A full scan of the remaining items is the only safe approach.

      Specified by:
      remove in interface INodeDepot
      Overrides:
      remove in class AbstractGenericDepot<ILoad>
      Returns:
      true if the item was present and removed
    • replace

      public boolean replace(ILoad orgItem, ILoad newItem)
      Replaces orgItem with newItem and recalculates all derived state.

      A non-zero item may be replaced by a zero-value item (the optimizer does this via replaceWithCopy when it adjusts flex load values), so a full rescan is necessary.

      Overrides:
      replace in class AbstractGenericDepot<ILoad>
      Returns:
      true if orgItem was found and replaced
    • hasFlexLoad

      public boolean hasFlexLoad()
      Description copied from interface: INodeDepot
      Derived — true if this depot contains at least one flex load. Computed at runtime; not a user-settable property.
      Specified by:
      hasFlexLoad in interface INodeDepot
    • setHasFlexLoad

      public void setHasFlexLoad(boolean hasFlexLoad)
      Specified by:
      setHasFlexLoad in interface INodeDepot
    • hasTimedLoad

      public boolean hasTimedLoad()
      Description copied from interface: INodeDepot
      Derived — true if this depot contains at least one timed load. Computed at runtime; not a user-settable property.
      Specified by:
      hasTimedLoad in interface INodeDepot
    • setHasTimedLoads

      public void setHasTimedLoads(boolean hasTimedLoads)
      Specified by:
      setHasTimedLoads in interface INodeDepot
    • isZeroLoad

      public boolean isZeroLoad()
      Returns true when every item in the depot has a load value of zero (or the depot is empty).

      The result is cached. After a replace(ILoad, ILoad) call (used by replaceWithCopy(String)) the cache is marked dirty because FlexLoadOperator mutates the returned copy via setLoad after replace has already returned. The next call to this method rescans the live item list — at that point the mutation has already happened — caches the fresh result, and clears the dirty flag. Subsequent calls are O(1) until the next replace.

      Specified by:
      isZeroLoad in interface INodeDepot
    • mergeItem

      public Optional<ILoad> mergeItem(ILoad itemOne, ILoad itemTwo)
      Specified by:
      mergeItem in class AbstractGenericDepot<ILoad>
    • createWith

      public INodeDepot createWith(List<ILoad> loads)
      Specified by:
      createWith in interface INodeDepot
    • invokeSearchArray

      public void invokeSearchArray(String[] loadIds)
      Specified by:
      invokeSearchArray in interface INodeDepot
    • partialCopy

      public INodeDepot partialCopy()
      Creates a shallow copy: item references are shared, not deep-copied.

      setItems delegates to loadItemsDirect, which calls resetDerivedState() then postAddOnCopy(ILoad) per item. All derived flags (isZeroLoad, hasFlexibleLoads, hasTimedLoads) are therefore computed correctly from the shared item references without any manual flag assignment.

      Specified by:
      partialCopy in interface INodeDepot
    • copy

      public INodeDepot copy()
      Creates a deep copy: each item is individually copied via ILoad.copy().

      Same flag-recomputation guarantee as partialCopy().

      Specified by:
      copy in interface INodeDepot
    • replaceWithCopy

      public Optional<ILoad> replaceWithCopy(String loadId)
      Specified by:
      replaceWithCopy in interface INodeDepot