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

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

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

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.joo.libra.Predicate;
import org.joo.libra.logic.AndPredicate;

public class AndExpressionNode extends InfixExpressionNode {

	@Override
	public Predicate buildPredicate() {
		List predicates = compactExpressionPath();
		return new AndPredicate(predicates.toArray(new Predicate[0]));
	}

	private List compactExpressionPath() {
		List predicates = new ArrayList<>();
		Predicate leftPredicate = getLeft().buildPredicate();
		if (leftPredicate instanceof AndPredicate) {
			predicates.addAll(Arrays.asList(((AndPredicate) leftPredicate).getPredicates()));
		} else {
			predicates.add(leftPredicate);
		}
		Predicate rightPredicate = getRight().buildPredicate();
		if (rightPredicate instanceof AndPredicate) {
			predicates.addAll(Arrays.asList(((AndPredicate) rightPredicate).getPredicates()));
		} else {
			predicates.add(rightPredicate);
		}
		return predicates;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy