All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.joo.libra.sql.node.ConditionalExpressionNode Maven / Gradle / Ivy

There is a newer version: 2.1.2
Show newest version
package org.joo.libra.sql.node;

import org.joo.libra.Predicate;
import org.joo.libra.PredicateContext;
import org.joo.libra.common.HasValue;
import org.joo.libra.pointer.VariablePredicate;

import lombok.Data;

@Data
public class ConditionalExpressionNode implements ExpressionNode, HasValue {

	private ExpressionNode main;

	private HasValue left;

	private HasValue right;

	private Predicate mainPredicate;

	@Override
	public Predicate buildPredicate() {
		return new VariablePredicate(this);
	}

	@Override
	public Object getValue(final PredicateContext context) {
		if (mainPredicate == null)
			mainPredicate = main.buildPredicate();
		boolean satisfied = mainPredicate.satisfiedBy(context);
		return satisfied ? left.getValue(context) : right.getValue(context);
	}
}