Package io.deephaven.engine.table.impl
Class LiveAttributeMap<IFACE_TYPE extends AttributeMap<IFACE_TYPE>,IMPL_TYPE extends LiveAttributeMap<IFACE_TYPE,IMPL_TYPE>>
java.lang.Object
io.deephaven.util.referencecounting.ReferenceCounted
io.deephaven.engine.liveness.ReferenceCountedLivenessReferent
io.deephaven.engine.liveness.ReferenceCountedLivenessNode
io.deephaven.engine.liveness.LivenessArtifact
io.deephaven.engine.table.impl.LiveAttributeMap<IFACE_TYPE,IMPL_TYPE>
- All Implemented Interfaces:
LogOutputAppendable
,LivenessManager
,LivenessNode
,LivenessReferent
,AttributeMap<IFACE_TYPE>
,Serializable
- Direct Known Subclasses:
BaseGridAttributes
public abstract class LiveAttributeMap<IFACE_TYPE extends AttributeMap<IFACE_TYPE>,IMPL_TYPE extends LiveAttributeMap<IFACE_TYPE,IMPL_TYPE>>
extends LivenessArtifact
implements AttributeMap<IFACE_TYPE>
Re-usable
AttributeMap
implementation that is also a LivenessArtifact
.- See Also:
- ImplNote:
- Rather than rely on
final
, explicitly-immutableMap
instances for storage, this implementation does allow for mutation after construction. This allows a pattern wherein operations fill their resultAttributeMap
after construction usingsetAttribute(String, Object)
, which by convention must only be done before the result is published. No mutation is permitted after first access using any ofgetAttribute(String)
,getAttributeKeys()
,hasAttribute(String)
,getAttributes()
, orAttributeMap.getAttributes(Predicate)
.
-
Constructor Summary
ModifierConstructorDescriptionprotected
LiveAttributeMap
(@Nullable Map<String, Object> initialAttributes) -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract IMPL_TYPE
copy()
Create a copy ofthis
with initially-sharedmutableAttributes
.protected static void
copyAttributes
(@NotNull AttributeMap<?> source, @NotNull LiveAttributeMap<?, ?> destination, @NotNull Predicate<String> shouldCopy) Copy attributes between AttributeMaps, filtered by a predicate.@Nullable Object
getAttribute
(@NotNull String key) Get the value for the specified attribute key.Get an immutable set of all the attributes that have values in this AttributeMap.Get all attributes in this AttributeMap.getAttributes
(@NotNull Predicate<String> included) Get all attributes from this AttributeMap whose keys are accepted byincluded
.boolean
hasAttribute
(@NotNull String name) Check if the specified attribute exists in this AttributeMap.protected IFACE_TYPE
protected IFACE_TYPE
boolean
Test if this LiveAttributeMap has been published yet.retainingAttributes
(@NotNull Collection<String> toRetain) Get an AttributeMap that is the same asthis
, but with only the specified attributes retained.void
setAttribute
(@NotNull String key, @NotNull Object object) Set the value of an attribute.void
setAttribute
(@NotNull String key, @NotNull UnaryOperator<Object> updater) Read and update the value of an attribute.withAttributes
(@NotNull Map<String, Object> toAdd) Get an AttributeMap that is the same asthis
, but with the specified attributes added/replaced.withAttributes
(@NotNull Map<String, Object> toAdd, @NotNull Collection<String> toRemove) Get an AttributeMap that is the same asthis
, but with the specified attributes added/replaced or removed.withoutAttributes
(@NotNull Collection<String> toRemove) Get an AttributeMap that is the same asthis
, but with the specified attributes removed.Methods inherited from class io.deephaven.engine.liveness.LivenessArtifact
manageWithCurrentScope
Methods inherited from class io.deephaven.engine.liveness.ReferenceCountedLivenessNode
getWeakReference, initializeTransientFieldsForLiveness, onReferenceCountAtZero, tryManage, tryUnmanage, tryUnmanage
Methods inherited from class io.deephaven.engine.liveness.ReferenceCountedLivenessReferent
destroy, dropReference, tryRetainReference
Methods inherited from class io.deephaven.util.referencecounting.ReferenceCounted
append, decrementReferenceCount, forceReferenceCountToZero, getReferenceCountDebug, incrementReferenceCount, resetReferenceCount, toString, tryDecrementReferenceCount, tryIncrementReferenceCount
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface io.deephaven.engine.liveness.LivenessManager
manage
Methods inherited from interface io.deephaven.engine.liveness.LivenessNode
unmanage, unmanage
Methods inherited from interface io.deephaven.engine.liveness.LivenessReferent
dropReference, getReferentDescription, retainReference, tryRetainReference
-
Constructor Details
-
LiveAttributeMap
- Parameters:
initialAttributes
- The attributes map to use until mutated, or elsenull
to allocate a new one
-
-
Method Details
-
setAttribute
@InternalUseOnly public void setAttribute(@NotNull @NotNull String key, @NotNull @NotNull Object object) Set the value of an attribute. This is for internal use by operations that build result AttributeMaps, and should never be used from multiple threads or after a result has been published.- Parameters:
key
- The name of the attribute; must not benull
object
- The value to be assigned; must not benull
-
setAttribute
@InternalUseOnly public void setAttribute(@NotNull @NotNull String key, @NotNull @NotNull UnaryOperator<Object> updater) Read and update the value of an attribute. This is for internal use by operations that build result AttributeMaps, and should never be used from multiple threads or after a result has been published.- Parameters:
key
- The name of the attribute; must not benull
updater
- Function on the (possibly-null
) existing value to produce the non-null
new value
-
copyAttributes
protected static void copyAttributes(@NotNull @NotNull AttributeMap<?> source, @NotNull @NotNull LiveAttributeMap<?, ?> destination, @NotNull @NotNull Predicate<String> shouldCopy) Copy attributes between AttributeMaps, filtered by a predicate.- Parameters:
source
- The AttributeMap to copy attributes fromdestination
- The LiveAttributeMap to copy attributes toshouldCopy
- Should we copy this attribute key?
-
published
public boolean published()Test if this LiveAttributeMap has been published yet. This determines whether it's safe to callsetAttribute(String, Object)
orsetAttribute(String, UnaryOperator)
.- Returns:
- Whether this LiveAttributeMap has been published
-
prepareReturnThis
-
prepareReturnCopy
-
withAttributes
public IFACE_TYPE withAttributes(@NotNull @NotNull Map<String, Object> toAdd, @NotNull @NotNull Collection<String> toRemove) Description copied from interface:AttributeMap
Get an AttributeMap that is the same asthis
, but with the specified attributes added/replaced or removed. If the supplied attributestoAdd
andtoRemove
would not result in any changes tothis
, implementations may returnthis
.- Specified by:
withAttributes
in interfaceAttributeMap<IFACE_TYPE extends AttributeMap<IFACE_TYPE>>
- Parameters:
toAdd
- Attribute key-value pairs to add or replace (if the key already exists onthis
). Neither keys nor values may benull
.toRemove
- Attribute keys to remove- Returns:
- The result AttributeMap
-
withAttributes
Description copied from interface:AttributeMap
Get an AttributeMap that is the same asthis
, but with the specified attributes added/replaced. If the supplied attributestoAdd
would not result in any changes tothis
, implementations may returnthis
.- Specified by:
withAttributes
in interfaceAttributeMap<IFACE_TYPE extends AttributeMap<IFACE_TYPE>>
- Parameters:
toAdd
- Attribute key-value pairs to add or replace (if the key already exists onthis
)- Returns:
- The result AttributeMap
-
withoutAttributes
Description copied from interface:AttributeMap
Get an AttributeMap that is the same asthis
, but with the specified attributes removed. If the supplied attributestoRemove
would not result in any changes tothis
, implementations may returnthis
.- Specified by:
withoutAttributes
in interfaceAttributeMap<IFACE_TYPE extends AttributeMap<IFACE_TYPE>>
- Parameters:
toRemove
- Attribute keys to remove- Returns:
- The result AttributeMap
-
retainingAttributes
Description copied from interface:AttributeMap
Get an AttributeMap that is the same asthis
, but with only the specified attributes retained. If the supplied attributestoAdd
would not result in any changes tothis
, implementations may returnthis
.- Specified by:
retainingAttributes
in interfaceAttributeMap<IFACE_TYPE extends AttributeMap<IFACE_TYPE>>
- Parameters:
toRetain
- Attribute keys to retain- Returns:
- The result AttributeMap
-
copy
Create a copy ofthis
with initially-sharedmutableAttributes
. -
getAttribute
Description copied from interface:AttributeMap
Get the value for the specified attribute key.- Specified by:
getAttribute
in interfaceAttributeMap<IFACE_TYPE extends AttributeMap<IFACE_TYPE>>
- Parameters:
key
- The name of the attribute- Returns:
- The value, or
null
if there was none.
-
getAttributeKeys
Description copied from interface:AttributeMap
Get an immutable set of all the attributes that have values in this AttributeMap.- Specified by:
getAttributeKeys
in interfaceAttributeMap<IFACE_TYPE extends AttributeMap<IFACE_TYPE>>
- Returns:
- An immutable set of attribute keys (names)
-
hasAttribute
Description copied from interface:AttributeMap
Check if the specified attribute exists in this AttributeMap.- Specified by:
hasAttribute
in interfaceAttributeMap<IFACE_TYPE extends AttributeMap<IFACE_TYPE>>
- Parameters:
name
- The key (name) of the attribute- Returns:
true
if the attribute exists
-
getAttributes
Description copied from interface:AttributeMap
Get all attributes in this AttributeMap.- Specified by:
getAttributes
in interfaceAttributeMap<IFACE_TYPE extends AttributeMap<IFACE_TYPE>>
- Returns:
- An immutable map containing all attributes from this AttributeMap
-
getAttributes
@ConcurrentMethod @NotNull public @NotNull Map<String,Object> getAttributes(@NotNull @NotNull Predicate<String> included) Description copied from interface:AttributeMap
Get all attributes from this AttributeMap whose keys are accepted byincluded
.- Specified by:
getAttributes
in interfaceAttributeMap<IFACE_TYPE extends AttributeMap<IFACE_TYPE>>
- Parameters:
included
- A predicate to determine which attribute keys to include- Returns:
- An immutable map containing AttributeMap's attributes whose keys are accepted by
included
-