类 Metadata
java.lang.Object
com.agentsflex.core.util.Metadata
- 所有已实现的接口:
Serializable
- 直接已知子类:
ChatOptions,ImageResponse,Message,Prompt,StoreOptions,StoreResult,VectorData
A thread-safe, serializable metadata container for storing key-value pairs.
Key Features:
- Thread-safe by default using
ConcurrentHashMap - Defensive copying to protect internal state
- Null-safe: returns empty map instead of null
- Type-safe generic getter with fallback default
- Immutable view exposure via
asMap()
Usage Example:
Metadata meta = new Metadata();
meta.putMetadata("model", "gpt-4");
meta.putMetadata("temperature", 0.7);
String model = meta.getMetadata("model", String.class, "default");
Map<String, Object> snapshot = meta.asMap(); // unmodifiable view
- 从以下版本开始:
- 2023
- 作者:
- Michael Yang (fuhai999@gmail.com)
- 另请参阅:
-
字段概要
字段修饰符和类型字段说明Internal storage: ConcurrentHashMap for thread-safety.private static final long -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明voidaddMetadata(String key, Object value) 已过时。voidaddMetadata(Map<String, Object> metadata) 已过时。useputMetadata(Map)for clearer semantics.asMap()Returns an unmodifiable view of the internal metadata map.voidRemoves all metadata entries.booleancontainsMetadata(String key) Checks if metadata contains the specified key.booleangetMetadata(String key) Gets the value associated with the specified key.<T> TgetMetadata(String key, Class<T> type, T defaultValue) Type-safe getter with class check and fallback default.getMetadata(String key, Object defaultValue) Gets the value associated with the specified key, or returns defaultValue if not found.Gets or creates the internal map with lazy initialization.inthashCode()booleanisEmpty()Checks if this metadata container is empty.voidputMetadata(String key, Object value) Puts a metadata entry (replaces existing value if key exists).voidputMetadata(Map<String, ?> metadata) Puts all entries from the given map (replaces existing values for duplicate keys).putMetadataIfAbsent(String key, Object value) Puts a metadata entry only if the key is not already present.removeMetadata(String key) Removes the metadata entry for the specified key.voidsetMetadataMap(Map<String, ?> metadataMap) Replaces the internal metadata map with a defensive copy of the provided map.intReturns the number of metadata entries.toString()
-
字段详细资料
-
serialVersionUID
- 另请参阅:
-
metadataMap
Internal storage: ConcurrentHashMap for thread-safety. Lazily initialized to save memory when unused.
-
-
构造器详细资料
-
Metadata
public Metadata()
-
-
方法详细资料
-
getMetadata
Gets the value associated with the specified key.- 参数:
key- the metadata key- 返回:
- the value, or
nullif not found
-
getMetadata
Gets the value associated with the specified key, or returns defaultValue if not found.- 参数:
key- the metadata keydefaultValue- the value to return if key is absent- 返回:
- the value, or defaultValue if not found
-
getMetadata
Type-safe getter with class check and fallback default.- 类型参数:
T- the expected type- 参数:
key- the metadata keytype- the expected type of the valuedefaultValue- the value to return if key is absent or type mismatch- 返回:
- the casted value, or defaultValue if not found or type mismatch
-
putMetadata
Puts a metadata entry (replaces existing value if key exists).- 参数:
key- the metadata keyvalue- the metadata value (must be Serializable if serialization is used)
-
putMetadata
Puts all entries from the given map (replaces existing values for duplicate keys).- 参数:
metadata- the map of metadata to add
-
putMetadataIfAbsent
Puts a metadata entry only if the key is not already present.- 参数:
key- the metadata keyvalue- the metadata value- 返回:
- the previous value associated with the key, or null if there was no mapping
-
removeMetadata
Removes the metadata entry for the specified key.- 参数:
key- the metadata key- 返回:
- the previous value associated with the key, or null if there was no mapping
-
containsMetadata
Checks if metadata contains the specified key.- 参数:
key- the metadata key- 返回:
- true if the key exists, false otherwise
-
isEmpty
Checks if this metadata container is empty.- 返回:
- true if no entries exist, false otherwise
-
sizeOfMetadata
Returns the number of metadata entries.- 返回:
- the entry count
-
clearMetadata
Removes all metadata entries. -
asMap
Returns an unmodifiable view of the internal metadata map.Changes to this Metadata instance will be reflected in the returned view, but attempts to modify the view directly will throw
UnsupportedOperationException.- 返回:
- an unmodifiable map view (never null)
-
setMetadataMap
Replaces the internal metadata map with a defensive copy of the provided map.This method does not merge; it replaces all existing entries.
- 参数:
metadataMap- the new metadata map (may be null to clear)
-
getOrCreateMap
Gets or creates the internal map with lazy initialization. Thread-safe via double-checked locking pattern.- 返回:
- the internal map instance
-
toString
-
equals
-
hashCode
-
addMetadata
已过时。useputMetadata(String, Object)for clearer semantics. This method is retained for backward compatibility and will be removed in a future major version. -
addMetadata
已过时。useputMetadata(Map)for clearer semantics. This method is retained for backward compatibility and will be removed in a future major version. -
getMetadataMap
-
putMetadata(String, Object)for clearer semantics.