Class AbstractTokenizedActivationStrategy

  • All Implemented Interfaces:
    ActivationStrategy

    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;
     }
     
    Author:
    Alasdair Mercer
    See Also:
    getTokenParameterName(), getTokenParameterTransformer()
    • Constructor Detail

      • AbstractTokenizedActivationStrategy

        public AbstractTokenizedActivationStrategy()
    • Method Detail

      • isActive

        public final boolean isActive​(FeatureState featureState,
                                      FeatureUser user)
        Description copied from interface: ActivationStrategy
        This 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:
        isActive in interface ActivationStrategy
        Parameters:
        featureState - 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 parameter 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.
        Returns:
        true if the feature should be active, else false
      • getTokenParameterName

        public abstract String getTokenParameterName()

        Returns the name of the parameter whose value is to be tokenized.

        Returns:
        The name of the parameter containing tokens.