Class EntityRef
type (e.g. "order"),
an id (e.g. "4711"), and a few optional human-readable
attributes (e.g. label="Order #4711 — ACME").
What this class is for
EntityRef is the heart of the Ambient Activity Memory feature. When the user opens
an order, edits a customer, or searches for an invoice, we don't copy the whole record into the
activity timeline — we record a tiny reference to it. Later, when the user asks the assistant
"cancel this order" or "who is that customer?", the recent stream
of EntityRefs is what lets the assistant resolve the deixis ("this"/"that") to a concrete
order #4711 without the user ever typing the id.
Familiar analogy: a sticky note with a name and a desk number on it — "Order 4711, 3rd drawer". It is not the file in the drawer; it is just enough to find the file. We keep a little pile of these sticky notes (the activity timeline) so that when you say "pull that one", we know which drawer you mean.
Why we store refs, not blobs
The application already owns the real data (in its database, its CDI beans, its DTOs).
Duplicating it into an activity log would be wasteful, would go stale instantly, and would be a
privacy liability. A reference is cheap, always re-resolvable through the app's own services, and
carries only the labels a human (or the LLM) needs to recognise the thing. The optional
attributes() map is for exactly those recognition hints (a display label, a status), not
for mirroring the record.
Equality
Two refs are equal when their type and id match; attributes are descriptive
decoration and are deliberately excluded. This makes a ref behave like a stable identity key, so
the same entity referenced twice (perhaps with a richer label the second time) still de-duplicates
cleanly in a timeline.
Instances are immutable and therefore safe to hand to another thread, queue, or store.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionConvenience lookup for a single attribute.booleaninthashCode()id()label()The best human-readable label for this entity: the"label"attribute if present, otherwise a compacttype#idfallback.static EntityRefCreate a bare reference with no descriptive attributes.static EntityRefCreate a reference carrying a single recognition hint — typically a human-readable label.static EntityRefCreate a reference with an arbitrary set of recognition hints.toString()type()
-
Method Details
-
of
Create a bare reference with no descriptive attributes.- Parameters:
type- the kind of entity (e.g."order","customer"); requiredid- the entity's identifier as a string (e.g."4711"); required- Returns:
- a new immutable
EntityRef
-
of
Create a reference carrying a single recognition hint — typically a human-readable label.Example:
EntityRef.of("order", "4711", "label", "Order #4711 — ACME").- Parameters:
type- the kind of entity; requiredid- the entity's identifier; requiredattrKey- the attribute name (e.g."label"); requiredattrValue- the attribute value; required- Returns:
- a new immutable
EntityRef
-
of
Create a reference with an arbitrary set of recognition hints.- Parameters:
type- the kind of entity; requiredid- the entity's identifier; requiredattributes- descriptive hints (e.g.label,status); copied defensively, may benullor empty- Returns:
- a new immutable
EntityRef
-
type
- Returns:
- the kind of entity (e.g.
"order"); nevernull.
-
id
- Returns:
- the entity's identifier as a string (e.g.
"4711"); nevernull.
-
attributes
- Returns:
- an unmodifiable, insertion-ordered map of recognition hints; never
null(empty when none were supplied).
-
attribute
Convenience lookup for a single attribute.- Parameters:
key- the attribute name- Returns:
- the value, or
nullif absent
-
label
The best human-readable label for this entity: the"label"attribute if present, otherwise a compacttype#idfallback.This is what a renderer puts into the prompt so the LLM sees "Order #4711 — ACME" rather than a bare id.
- Returns:
- a never-
nulldisplay string
-
equals
-
hashCode
public int hashCode() -
toString
-