Record Class FeatureContext
java.lang.Object
java.lang.Record
cloud.opencode.base.feature.FeatureContext
- Record Components:
userId- the user ID | 用户IDtenantId- the tenant ID | 租户IDattributes- custom attributes map | 自定义属性映射Security | 安全性:
- Thread-safe: Yes (immutable record) - 线程安全: 是(不可变记录)
- Null-safe: Partial (validates inputs) - 空值安全: 部分(验证输入)
public record FeatureContext(String userId, String tenantId, Map<String,Object> attributes)
extends Record
Feature Context
功能上下文
Immutable context for feature evaluation.
用于功能评估的不可变上下文。
Features | 主要功能:
- User context - 用户上下文
- Tenant context - 租户上下文
- Custom attributes - 自定义属性
Usage Examples | 使用示例:
// Empty context
FeatureContext context = FeatureContext.empty();
// User context
FeatureContext context = FeatureContext.ofUser("user-123");
// Full context with builder
FeatureContext context = FeatureContext.builder()
.userId("user-123")
.tenantId("tenant-456")
.attribute("role", "admin")
.build();
- Since:
- JDK 25, opencode-base-feature V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder for FeatureContext FeatureContext构建器 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns the value of theattributesrecord component.static FeatureContext.Builderbuilder()Create a new builder 创建新的构建器static FeatureContextempty()Create an empty context 创建空上下文final booleanIndicates whether some other object is "equal to" this one.<T> TgetAttribute(String key) Get an attribute value 获取属性值<T> TgetAttribute(String key, T defaultValue) Get an attribute value with default 获取属性值,带默认值final inthashCode()Returns a hash code value for this object.booleanCheck if context has tenant ID 检查上下文是否有租户IDbooleanCheck if context has user ID 检查上下文是否有用户IDstatic FeatureContextCreate a context with user and tenant 使用用户和租户创建上下文static FeatureContextCreate a context with tenant ID only 仅使用租户ID创建上下文static FeatureContextCreate a context with user ID only 仅使用用户ID创建上下文tenantId()Returns the value of thetenantIdrecord component.final StringtoString()Returns a string representation of this record class.userId()Returns the value of theuserIdrecord component.
-
Constructor Details
-
FeatureContext
Creates an instance of aFeatureContextrecord class.- Parameters:
userId- the value for theuserIdrecord componenttenantId- the value for thetenantIdrecord componentattributes- the value for theattributesrecord component
-
-
Method Details
-
empty
-
ofUser
Create a context with user ID only 仅使用用户ID创建上下文- Parameters:
userId- the user ID | 用户ID- Returns:
- context with user | 带用户的上下文
-
ofTenant
Create a context with tenant ID only 仅使用租户ID创建上下文- Parameters:
tenantId- the tenant ID | 租户ID- Returns:
- context with tenant | 带租户的上下文
-
of
Create a context with user and tenant 使用用户和租户创建上下文- Parameters:
userId- the user ID | 用户IDtenantId- the tenant ID | 租户ID- Returns:
- context | 上下文
-
builder
Create a new builder 创建新的构建器- Returns:
- new builder | 新的构建器
-
getAttribute
Get an attribute value 获取属性值- Type Parameters:
T- the value type | 值类型- Parameters:
key- the attribute key | 属性键- Returns:
- the attribute value or null | 属性值或null
-
getAttribute
Get an attribute value with default 获取属性值,带默认值- Type Parameters:
T- the value type | 值类型- Parameters:
key- the attribute key | 属性键defaultValue- the default value | 默认值- Returns:
- the attribute value or default | 属性值或默认值
-
hasUserId
public boolean hasUserId()Check if context has user ID 检查上下文是否有用户ID- Returns:
- true if has user ID | 如果有用户ID返回true
-
hasTenantId
public boolean hasTenantId()Check if context has tenant ID 检查上下文是否有租户ID- Returns:
- true if has tenant ID | 如果有租户ID返回true
-
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). -
userId
-
tenantId
-
attributes
Returns the value of theattributesrecord component.- Returns:
- the value of the
attributesrecord component
-