Class ResultWorkspace<R>

java.lang.Object
edu.cnu.mdi.workspace.ResultWorkspace<R>
Type Parameters:
R - retained result type

public final class ResultWorkspace<R> extends Object
Ordered, optionally bounded collection of completed application results.

The workspace centralizes the common scientific-workbench pattern of retaining completed calculations for later comparison, export, or reopening diagnostic views. It stores application result objects without knowing their scientific type or UI representation.

Retention and eviction

Entries are ordered from oldest to newest. A positive capacity evicts the oldest entry whenever a new result would exceed that capacity; zero means unbounded. Eviction produces the same removal callback as explicit removal.

Threading

State operations are synchronized and snapshots are immutable. Listeners use copy-on-write registration and are called synchronously after each state mutation. Listener failures are isolated from other listeners.

  • Constructor Details

    • ResultWorkspace

      public ResultWorkspace()
      Creates an unbounded workspace using the system UTC clock.
    • ResultWorkspace

      public ResultWorkspace(int capacity)
      Creates a workspace using the system UTC clock.
      Parameters:
      capacity - maximum entries, or zero for unbounded
      Throws:
      IllegalArgumentException - if capacity is negative
  • Method Details

    • retain

      public RetainedResult<R> retain(String name, R result)
      Retains a result without metadata.
      Parameters:
      name - user-facing name
      result - result object
      Returns:
      immutable retained entry
    • retain

      public RetainedResult<R> retain(String name, R result, Map<String,String> metadata)
      Retains a result and optional string metadata.
      Parameters:
      name - user-facing name
      result - result object
      metadata - application metadata, defensively copied
      Returns:
      immutable retained entry
    • entries

      public List<RetainedResult<R>> entries()
      Returns:
      immutable oldest-to-newest snapshot
    • find

      public Optional<RetainedResult<R>> find(UUID id)
      Finds an entry by stable ID.
      Parameters:
      id - entry ID
      Returns:
      matching entry, or empty
    • remove

      public Optional<RetainedResult<R>> remove(UUID id)
      Removes an entry by ID.
      Parameters:
      id - entry ID
      Returns:
      removed entry, or empty
    • clear

      public void clear()
      Removes all entries. A no-op workspace emits no callback.
    • capacity

      public int capacity()
      Returns:
      configured capacity, or zero when unbounded
    • size

      public int size()
      Returns:
      current number of retained entries
    • addListener

      public void addListener(ResultWorkspaceListener<R> listener)
      Parameters:
      listener - listener to add; null is ignored
    • removeListener

      public void removeListener(ResultWorkspaceListener<R> listener)
      Parameters:
      listener - listener to remove