Class CompositeStrategy
java.lang.Object
cloud.opencode.base.feature.strategy.CompositeStrategy
- All Implemented Interfaces:
EnableStrategy
Composite Strategy
组合策略
Strategy that combines multiple strategies with AND/OR logic.
使用AND/OR逻辑组合多个策略的策略。
Features | 主要功能:
- AND logic (allOf) - AND逻辑(全部满足)
- OR logic (anyOf) - OR逻辑(任一满足)
- Complex conditions - 复杂条件
Usage Examples | 使用示例:
// AND: must be VIP user AND within date range
EnableStrategy strategy = CompositeStrategy.allOf(
new UserListStrategy(Set.of("vip1", "vip2")),
new DateRangeStrategy(start, end)
);
// OR: VIP user OR 50% rollout
EnableStrategy strategy = CompositeStrategy.anyOf(
new UserListStrategy(Set.of("vip1")),
new PercentageStrategy(50)
);
Security | 安全性:
- Thread-safe: Yes - 线程安全: 是
- Null-safe: Partial (validates inputs) - 空值安全: 部分(验证输入)
- Since:
- JDK 25, opencode-base-feature V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCompositeStrategy(List<EnableStrategy> strategies, boolean requireAll) Create composite strategy 创建组合策略 -
Method Summary
Modifier and TypeMethodDescriptionstatic CompositeStrategyallOf(EnableStrategy... strategies) Create AND composite (all strategies must pass) 创建AND组合(所有策略必须通过)static CompositeStrategyallOf(List<EnableStrategy> strategies) Create AND composite from list 从列表创建AND组合static CompositeStrategyanyOf(EnableStrategy... strategies) Create OR composite (any strategy must pass) 创建OR组合(任一策略通过即可)static CompositeStrategyanyOf(List<EnableStrategy> strategies) Create OR composite from list 从列表创建OR组合Get the strategies 获取策略列表booleanisEnabled(Feature feature, FeatureContext context) Evaluate all strategies with AND/OR logic 使用AND/OR逻辑评估所有策略booleanCheck if using AND logic 检查是否使用AND逻辑toString()
-
Constructor Details
-
CompositeStrategy
Create composite strategy 创建组合策略- Parameters:
strategies- the list of strategies | 策略列表requireAll- true for AND logic, false for OR | AND逻辑为true,OR为false
-
-
Method Details
-
allOf
Create AND composite (all strategies must pass) 创建AND组合(所有策略必须通过)- Parameters:
strategies- the strategies | 策略- Returns:
- composite strategy | 组合策略
-
allOf
Create AND composite from list 从列表创建AND组合- Parameters:
strategies- the strategies | 策略- Returns:
- composite strategy | 组合策略
-
anyOf
Create OR composite (any strategy must pass) 创建OR组合(任一策略通过即可)- Parameters:
strategies- the strategies | 策略- Returns:
- composite strategy | 组合策略
-
anyOf
Create OR composite from list 从列表创建OR组合- Parameters:
strategies- the strategies | 策略- Returns:
- composite strategy | 组合策略
-
isEnabled
Evaluate all strategies with AND/OR logic 使用AND/OR逻辑评估所有策略- Specified by:
isEnabledin interfaceEnableStrategy- Parameters:
feature- the feature | 功能context- the context | 上下文- Returns:
- true if conditions met | 如果条件满足返回true
-
getStrategies
-
isRequireAll
public boolean isRequireAll()Check if using AND logic 检查是否使用AND逻辑- Returns:
- true if AND | 如果是AND返回true
-
toString
-