Class EnvironmentStrategy
java.lang.Object
cloud.opencode.base.feature.strategy.EnvironmentStrategy
- All Implemented Interfaces:
EnableStrategy
Environment-Based Enable Strategy
基于环境的启用策略
Strategy that enables/disables features based on the deployment environment.
根据部署环境启用/禁用功能的策略。
Environment Resolution Order | 环境解析顺序:
- Context attribute "environment" - 上下文属性 "environment"
- System property "app.environment" - 系统属性 "app.environment"
- Environment variable "APP_ENVIRONMENT" - 环境变量 "APP_ENVIRONMENT"
- Default: "default" - 默认: "default"
Usage Examples | 使用示例:
EnvironmentStrategy strategy = EnvironmentStrategy.builder()
.dev(true)
.staging(true)
.prod(false)
.defaultState(false)
.build();
Feature feature = Feature.builder("debug-mode")
.strategy(strategy)
.build();
Security | 安全性:
- Thread-safe: Yes (immutable) - 线程安全: 是(不可变)
- Null-safe: Partial (validates inputs) - 空值安全: 部分(验证输入)
- Since:
- JDK 25, opencode-base-feature V1.0.3
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder for EnvironmentStrategy EnvironmentStrategy构建器 -
Method Summary
Modifier and TypeMethodDescriptionstatic EnvironmentStrategy.Builderbuilder()Create a new builder 创建新的构建器booleanGet the default state 获取默认状态Get the environment states map 获取环境状态映射booleanisEnabled(Feature feature, FeatureContext context) Evaluate if the feature is enabled for the current environment 评估功能是否在当前环境中启用
-
Method Details
-
isEnabled
Evaluate if the feature is enabled for the current environment 评估功能是否在当前环境中启用- Specified by:
isEnabledin interfaceEnableStrategy- Parameters:
feature- the feature being evaluated | 正在评估的功能context- the evaluation context | 评估上下文- Returns:
- true if enabled for the current environment | 如果在当前环境中启用返回true
-
getEnvironmentStates
-
getDefaultState
public boolean getDefaultState()Get the default state 获取默认状态- Returns:
- default state | 默认状态
-
builder
Create a new builder 创建新的构建器- Returns:
- new builder | 新的构建器
-