public abstract class AbstractTokenizedActivationStrategy extends Object implements ActivationStrategy
An abstract activation strategy that is designed to support cases where a specific parameter contains comma-separated
tokens that can be negated by prefixing the value with the NOT operator (!).
AbstractTokenizedActivationStrategy makes no real assumptions on how implementations will use the tokens to
determine whether the feature is active and, instead, simply tokenizes the parameter value. It even allows for the
token values to be transformed during this process by specifying a AbstractTokenizedActivationStrategy.TokenTransformer.
Implementations are responsible for honoring the negated state of any tokens. Fortunately, this is very simple to do:
@Override
protected boolean isActive(FeatureState featureState, FeatureUser user, List<Token> tokens) {
for (Token token : tokens) {
boolean active = doSomeCheckOnTokenValue(token.getValue());
if (active != token.isNegated()) {
return true;
}
}
return false;
}
getTokenParameterName(),
getTokenParameterTransformer()| Modifier and Type | Class and Description |
|---|---|
static class |
AbstractTokenizedActivationStrategy.Token
Contains information for a specific token including the token value and whether it has been negated.
|
static interface |
AbstractTokenizedActivationStrategy.TokenTransformer
Used to transform a given
AbstractTokenizedActivationStrategy.Token value. |
| Constructor and Description |
|---|
AbstractTokenizedActivationStrategy() |
| Modifier and Type | Method and Description |
|---|---|
abstract String |
getTokenParameterName()
Returns the name of the parameter whose value is to be tokenized.
|
AbstractTokenizedActivationStrategy.TokenTransformer |
getTokenParameterTransformer()
Returns the transformer to be used to transform the value of each
AbstractTokenizedActivationStrategy.Token. |
boolean |
isActive(FeatureState featureState,
FeatureUser user)
This method is responsible to decide whether a feature is active or not.
|
protected abstract boolean |
isActive(FeatureState featureState,
FeatureUser user,
List<AbstractTokenizedActivationStrategy.Token> tokens)
This method is called by
isActive(FeatureState, FeatureUser) with the parsed tokens to make the
decision as to whether the feature is active. |
protected List<AbstractTokenizedActivationStrategy.Token> |
tokenize(FeatureState featureState,
String parameterName,
AbstractTokenizedActivationStrategy.TokenTransformer transformer)
Looks up and tokenizes the value of the parameter with the given name on the feature.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetId, getName, getParameterspublic final boolean isActive(FeatureState featureState, FeatureUser user)
ActivationStrategyisActive in interface ActivationStrategyfeatureState - The feature state which represents the current configuration of the feature. The implementation of
the method typically uses FeatureState.getParameter(String) to access custom configuration paramater
values.user - The user for which to decide whether the feature is active. May be null if the user could not be
identified by the UserProvider.true if the feature should be active, else falseprotected abstract boolean isActive(FeatureState featureState, FeatureUser user, List<AbstractTokenizedActivationStrategy.Token> tokens)
This method is called by isActive(FeatureState, FeatureUser) with the parsed tokens to make the
decision as to whether the feature is active.
featureState - the FeatureState which represents the current configuration of the featureuser - the user for which to decide whether the feature is active (may be null)tokens - the List of Tokens parsed from the parameter valueprotected List<AbstractTokenizedActivationStrategy.Token> tokenize(FeatureState featureState, String parameterName, AbstractTokenizedActivationStrategy.TokenTransformer transformer)
Looks up and tokenizes the value of the parameter with the given name on the feature.
If transformer is not null, it will be asked to transform each individual token value.
featureState - the FeatureState which represents the current configuration of the featureparameterName - the name of the parameter whose value is to be tokenizedtransformer - the AbstractTokenizedActivationStrategy.TokenTransformer to be used to transform the value of each token (may be null to use
the token values as-provided)List of Tokens extracted from the value of the parameter with the specified name.public abstract String getTokenParameterName()
Returns the name of the parameter whose value is to be tokenized.
public AbstractTokenizedActivationStrategy.TokenTransformer getTokenParameterTransformer()
Returns the transformer to be used to transform the value of each AbstractTokenizedActivationStrategy.Token.
By default, this method returns null, meaning that the token values are used as-provided.
AbstractTokenizedActivationStrategy.TokenTransformer to be used to transform token values or null to use the original
values.Copyright © 2018. All Rights Reserved.