Record Class TypedKey<T>
java.lang.Object
java.lang.Record
cloud.opencode.base.rules.key.TypedKey<T>
- Type Parameters:
T- the value type | 值类型- Record Components:
name- the key name | 键名称type- the value type | 值类型
Typed Key - Type-Safe Key for Fact and Variable Access
类型化键 - 用于事实和变量访问的类型安全键
Provides compile-time type safety when accessing values from FactStore
and RuleContext, eliminating the need for manual casting.
在从 FactStore 和 RuleContext 访问值时提供编译时类型安全,
消除手动转换的需要。
Usage Examples | 使用示例:
TypedKey<String> CUSTOMER_TYPE = TypedKey.of("customerType", String.class);
TypedKey<Double> ORDER_AMOUNT = TypedKey.of("orderAmount", Double.class);
// Type-safe access
context.put(CUSTOMER_TYPE, "VIP");
String type = context.get(CUSTOMER_TYPE);
- Since:
- JDK 25, opencode-base-rules V1.0.3
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.name()Returns the value of thenamerecord component.static <T> TypedKey<T> Creates a typed key with the given name and type 使用给定名称和类型创建类型化键toString()Returns a string representation of this record class.type()Returns the value of thetyperecord component.
-
Constructor Details
-
TypedKey
Canonical constructor with validation 带验证的规范构造函数- Parameters:
name- the key name | 键名称type- the value type | 值类型- Throws:
NullPointerException- if name or type is null | 如果name或type为null则抛出
-
-
Method Details
-
of
Creates a typed key with the given name and type 使用给定名称和类型创建类型化键- Type Parameters:
T- the value type | 值类型- Parameters:
name- the key name | 键名称type- the value type | 值类型- Returns:
- the typed key | 类型化键
- Throws:
NullPointerException- if name or type is null | 如果name或type为null则抛出
-
toString
-
hashCode
-
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared withObjects::equals(Object,Object). -
name
-
type
-