class Condition
{
	public static boolean check(Row r, Column c, TreeNode tree)
	{
		boolean res=false;

		if (tree instanceof CondNode)
		{
			CondNode cond = (CondNode) tree.getNode();
			res=Select.execute(r, c, cond.getArg(), cond.getOp(), cond.getVal());
		}

		else if (tree instanceof BinaryNode)
		{
			BinaryNode bin = (BinaryNode) tree.getNode();
			
			res=check(r, c, bin.getLeftTree());

			if (bin.getOp().equals("AND"))
			{
				// only check that right subtree of the constraint tree is satisfied if the left is satisfied
				if(res==true)
				{
					res = (res && check(r, c, bin.getRightTree()) );
				}
			}
			else if (bin.getOp().equals("OR"))
			{
				// only check that right subtree of the constraint tree is satisfied if the left is NOT satisfied
				if(res==false)
				{
					res = (res || check(r, c, bin.getRightTree()) );
				}
			}
			else
			{
				System.out.println("Error in executing Constraint Tree: Unkown binary node value=" + bin.getOp());
			}
		}
		
		else
		{
			System.out.println("Unkown Node in execConstraint");
		}

		return res;	
	}
	
}
