Class AbstractTokenizedActivationStrategy
- All Implemented Interfaces:
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;
}
- Author:
- Alasdair Mercer
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classContains information for a specific token including the token value and whether it has been negated.static interfaceUsed to transform a givenAbstractTokenizedActivationStrategy.Tokenvalue. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract StringReturns the name of the parameter whose value is to be tokenized.Returns the transformer to be used to transform the value of eachAbstractTokenizedActivationStrategy.Token.final booleanisActive(FeatureState featureState, FeatureUser user) This method is responsible to decide whether a feature is active or not.protected abstract booleanisActive(FeatureState featureState, FeatureUser user, List<AbstractTokenizedActivationStrategy.Token> tokens) This method is called byisActive(FeatureState, FeatureUser)with the parsedtokensto 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.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.togglz.core.spi.ActivationStrategy
getId, getName, getParameters
-
Constructor Details
-
AbstractTokenizedActivationStrategy
public AbstractTokenizedActivationStrategy()
-
-
Method Details
-
isActive
Description copied from interface:ActivationStrategyThis method is responsible to decide whether a feature is active or not. The implementation can use the custom configuration parameters of the strategy stored in the feature state and information from the currently acting user to find a decision.- Specified by:
isActivein interfaceActivationStrategy- Parameters:
featureState- The feature state which represents the current configuration of the feature. The implementation of the method typically usesFeatureState.getParameter(String)to access custom configuration parameter values.user- The user for which to decide whether the feature is active. May benullif the user could not be identified by theUserProvider.- Returns:
trueif the feature should be active, elsefalse
-
isActive
protected abstract boolean isActive(FeatureState featureState, FeatureUser user, List<AbstractTokenizedActivationStrategy.Token> tokens) This method is called by
isActive(FeatureState, FeatureUser)with the parsedtokensto make the decision as to whether the feature is active.- Parameters:
featureState- theFeatureStatewhich represents the current configuration of the featureuser- theuserfor which to decide whether the feature is active (may be null)tokens- theListofTokensparsed from the parameter value- Returns:
- true if the feature should be active; otherwise false.
-
tokenize
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.
If
transformeris not null, it will be asked to transform each individual token value.- Parameters:
featureState- theFeatureStatewhich represents the current configuration of the featureparameterName- the name of the parameter whose value is to be tokenizedtransformer- theAbstractTokenizedActivationStrategy.TokenTransformerto be used to transform the value of each token (may be null to use the token values as-provided)- Returns:
- A
ListofTokensextracted from the value of the parameter with the specified name.
-
getTokenParameterName
Returns the name of the parameter whose value is to be tokenized.
- Returns:
- The name of the parameter containing tokens.
-
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.
- Returns:
- The
AbstractTokenizedActivationStrategy.TokenTransformerto be used to transform token values or null to use the original values.
-