org.coode.oppl.function.Expression Maven / Gradle / Ivy
package org.coode.oppl.function;
import static org.coode.oppl.utils.ArgCheck.checkNotNull;
import org.coode.oppl.ConstraintSystem;
import org.coode.oppl.PartialOWLObjectInstantiator;
import org.coode.oppl.rendering.ManchesterSyntaxRenderer;
import org.semanticweb.owlapi.model.OWLObject;
import org.semanticweb.owlapi.util.ShortFormProvider;
/** @author Luigi Iannone
* @param
* type */
public class Expression extends AbstractOPPLFunction implements
OPPLFunction {
private final O expression;
/** @param expression
* expression */
public Expression(O expression) {
this.expression = checkNotNull(expression, "expression");
}
@Override
public void accept(OPPLFunctionVisitor visitor) {
visitor.visitExpression(this);
}
@Override
public P accept(OPPLFunctionVisitorEx
visitor) {
return visitor.visitExpression(this);
}
@Override
public ValueComputation getValueComputation(
final ValueComputationParameters parameters) {
return new ValueComputation() {
@Override
@SuppressWarnings("unchecked")
public O compute(OPPLFunction extends O> opplFunction) {
PartialOWLObjectInstantiator instantiator = new PartialOWLObjectInstantiator(
parameters);
OWLObject instantiation = Expression.this.getExpression().accept(
instantiator);
// I am sure the instantiator will return an object of the same
// kind.
return (O) instantiation;
}
};
}
/** @return the expression */
public O getExpression() {
return this.expression;
}
@Override
public String render(ShortFormProvider shortFormProvider) {
ManchesterSyntaxRenderer renderer = new ManchesterSyntaxRenderer(
shortFormProvider);
this.getExpression().accept(renderer);
return renderer.toString();
}
@Override
public String render(ConstraintSystem constraintSystem) {
ManchesterSyntaxRenderer renderer = constraintSystem.getOPPLFactory()
.getManchesterSyntaxRenderer(constraintSystem);
this.getExpression().accept(renderer);
return renderer.toString();
}
}