Record Class Feature
java.lang.Object
java.lang.Record
cloud.opencode.base.feature.Feature
- Record Components:
key- the unique feature key | 唯一功能键name- the display name | 显示名称description- the description | 描述defaultEnabled- default enabled state | 默认启用状态strategy- the enable strategy | 启用策略metadata- custom metadata | 自定义元数据createdAt- creation timestamp | 创建时间戳updatedAt- update timestamp | 更新时间戳Security | 安全性:
- Thread-safe: Yes (immutable record) - 线程安全: 是(不可变记录)
- Null-safe: Partial (validates inputs) - 空值安全: 部分(验证输入)
public record Feature(String key, String name, String description, boolean defaultEnabled, EnableStrategy strategy, Map<String,Object> metadata, Instant createdAt, Instant updatedAt)
extends Record
Feature Definition
功能定义
Immutable record representing a feature toggle.
表示功能开关的不可变记录。
Features | 主要功能:
- Feature key and metadata - 功能键和元数据
- Enable strategy - 启用策略
- Default value - 默认值
- Timestamps - 时间戳
Usage Examples | 使用示例:
// Simple feature
Feature feature = Feature.builder("dark-mode")
.name("Dark Mode")
.description("Enable dark theme")
.alwaysOn()
.build();
// Percentage rollout
Feature feature = Feature.builder("new-feature")
.percentage(10)
.build();
// User whitelist
Feature feature = Feature.builder("beta-feature")
.forUsers("user1", "user2")
.build();
- Since:
- JDK 25, opencode-base-feature V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Feature.BuilderCreate a builder for feature 创建功能构建器Returns the value of thecreatedAtrecord component.booleanReturns the value of thedefaultEnabledrecord component.Returns the value of thedescriptionrecord component.final booleanIndicates whether some other object is "equal to" this one.<T> TgetMetadata(String key) Get metadata value 获取元数据值<T> TgetMetadata(String key, T defaultValue) Get metadata value with default 获取元数据值,带默认值final inthashCode()Returns a hash code value for this object.booleanCheck if this feature is enabled with empty context 使用空上下文检查此功能是否启用booleanisEnabled(FeatureContext context) Check if this feature is enabled with context 使用上下文检查此功能是否启用key()Returns the value of thekeyrecord component.metadata()Returns the value of themetadatarecord component.name()Returns the value of thenamerecord component.strategy()Returns the value of thestrategyrecord component.final StringtoString()Returns a string representation of this record class.Returns the value of theupdatedAtrecord component.withStrategy(EnableStrategy newStrategy) Create a copy with updated strategy 创建具有更新策略的副本
-
Constructor Details
-
Feature
public Feature(String key, String name, String description, boolean defaultEnabled, EnableStrategy strategy, Map<String, Object> metadata, Instant createdAt, Instant updatedAt) Creates an instance of aFeaturerecord class.- Parameters:
key- the value for thekeyrecord componentname- the value for thenamerecord componentdescription- the value for thedescriptionrecord componentdefaultEnabled- the value for thedefaultEnabledrecord componentstrategy- the value for thestrategyrecord componentmetadata- the value for themetadatarecord componentcreatedAt- the value for thecreatedAtrecord componentupdatedAt- the value for theupdatedAtrecord component
-
-
Method Details
-
builder
Create a builder for feature 创建功能构建器- Parameters:
key- the feature key | 功能键- Returns:
- new builder | 新的构建器
-
isEnabled
public boolean isEnabled()Check if this feature is enabled with empty context 使用空上下文检查此功能是否启用- Returns:
- true if enabled | 如果启用返回true
-
isEnabled
Check if this feature is enabled with context 使用上下文检查此功能是否启用- Parameters:
context- the evaluation context | 评估上下文- Returns:
- true if enabled | 如果启用返回true
-
getMetadata
Get metadata value 获取元数据值- Type Parameters:
T- the value type | 值类型- Parameters:
key- the metadata key | 元数据键- Returns:
- the metadata value or null | 元数据值或null
-
getMetadata
Get metadata value with default 获取元数据值,带默认值- Type Parameters:
T- the value type | 值类型- Parameters:
key- the metadata key | 元数据键defaultValue- the default value | 默认值- Returns:
- the metadata value or default | 元数据值或默认值
-
withStrategy
Create a copy with updated strategy 创建具有更新策略的副本- Parameters:
newStrategy- the new strategy | 新策略- Returns:
- new Feature with updated strategy | 具有更新策略的新Feature
-
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. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with thecomparemethod from their corresponding wrapper classes. -
key
-
name
-
description
Returns the value of thedescriptionrecord component.- Returns:
- the value of the
descriptionrecord component
-
defaultEnabled
public boolean defaultEnabled()Returns the value of thedefaultEnabledrecord component.- Returns:
- the value of the
defaultEnabledrecord component
-
strategy
-
metadata
-
createdAt
-
updatedAt
-