Package edu.cnu.mdi.workspace
Class ResultWorkspace<R>
java.lang.Object
edu.cnu.mdi.workspace.ResultWorkspace<R>
- Type Parameters:
R- retained result type
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 Summary
ConstructorsConstructorDescriptionCreates an unbounded workspace using the system UTC clock.ResultWorkspace(int capacity) Creates a workspace using the system UTC clock. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddListener(ResultWorkspaceListener<R> listener) intcapacity()voidclear()Removes all entries.entries()Finds an entry by stable ID.Removes an entry by ID.voidremoveListener(ResultWorkspaceListener<R> listener) Retains a result without metadata.Retains a result and optional string metadata.intsize()
-
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
Retains a result without metadata.- Parameters:
name- user-facing nameresult- result object- Returns:
- immutable retained entry
-
retain
Retains a result and optional string metadata.- Parameters:
name- user-facing nameresult- result objectmetadata- application metadata, defensively copied- Returns:
- immutable retained entry
-
entries
- Returns:
- immutable oldest-to-newest snapshot
-
find
Finds an entry by stable ID.- Parameters:
id- entry ID- Returns:
- matching entry, or empty
-
remove
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
- Parameters:
listener- listener to add; null is ignored
-
removeListener
- Parameters:
listener- listener to remove
-