com.contentgrid.thunx.predicates.model.ThunkExpression Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of thunx-model Show documentation
Show all versions of thunx-model Show documentation
Set of (vendor-neutral) data structures to model authorization policy expressions
package com.contentgrid.thunx.predicates.model;
import java.util.Optional;
public interface ThunkExpression {
Class extends T> getResultType();
default ThunkExpression assertResultType(Class resultType) {
if(resultType != getResultType()) {
throw new IllegalArgumentException("Result of expression "+this+" is "+getResultType()+", which does not match the asserted type "+resultType+".");
}
return (ThunkExpression) this;
}
R accept(ThunkExpressionVisitor visitor, C context);
static Optional> maybeScalar(ThunkExpression expression) {
if(expression instanceof Scalar) {
return Optional.of((Scalar) expression);
}
return Optional.empty();
}
static Optional maybeValue(ThunkExpression expression) {
if(expression.getResultType() == Void.class) {
throw new IllegalArgumentException("Expression with result type "+Void.class+" can not be mapped with #maybeValue(), use #maybeScalar() instead.");
}
return maybeScalar(expression)
.map(Scalar::getValue);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy