@FunctionalInterface public interface ContextCalculator<T>
Implementations of this interface should satisfy the following requirements:
Calculators should be registered using
ContextManager.registerCalculator(ContextCalculator).
| Modifier and Type | Method and Description |
|---|---|
void |
calculate(T target,
@NonNull ContextConsumer consumer)
Submits any contexts this calculator determines to be applicable to
the
target contextual subject. |
default ContextSet |
estimatePotentialContexts()
Gets a
ContextSet, containing some/all of the contexts this
calculator could potentially submit. |
static <T> @NonNull ContextCalculator<T> |
forSingleContext(@NonNull String key,
@NonNull Function<T,String> valueFunction)
Creates a new
ContextCalculator that provides a single context. |
static <T> @NonNull ContextCalculator<T> forSingleContext(@NonNull String key, @NonNull Function<T,String> valueFunction)
ContextCalculator that provides a single context.T - the contextual typekey - the key of the context provided by the calculatorvalueFunction - the function used to compute the corresponding value
for each query. A context will not be "accumulated"
if the value returned is null.void calculate(T target, @NonNull ContextConsumer consumer)
target contextual subject.
Care should be taken to ensure implementations of this method meet the
general requirements for ContextCalculator, defined in the class
doc.
target - the target contextual subject for this operationconsumer - the ContextConsumer to submit contexts todefault ContextSet estimatePotentialContexts()
ContextSet, containing some/all of the contexts this
calculator could potentially submit.
The result of this call is primarily intended on providing suggestions to end users when defining permissions.