001/**
002 * Copyright 2005-2016 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.rice.krms.framework.engine.expression;
017
018import org.kuali.rice.krms.api.engine.ExecutionEnvironment;
019
020/**
021 * Binary Operator implementation of Expression<Boolean>
022 *
023 * @author Kuali Rice Team (rice.collab@kuali.org)
024 *
025 */
026public final class BinaryOperatorExpression implements Expression<Boolean> {
027
028        private final ComparisonOperator operator;
029        private final Expression<? extends Object> lhs;
030        private final Expression<? extends Object> rhs;
031
032    /**
033     * Create a BinaryOperatorExpression with the given values
034     * @param operator {@link ComparisonOperator}
035     * @param lhs left hand side Expression
036     * @param rhs right hand side Expression
037     */
038        public BinaryOperatorExpression(ComparisonOperator operator, Expression<? extends Object> lhs, Expression<? extends Object> rhs) {
039                this.operator = operator;
040                this.lhs = lhs;
041                this.rhs = rhs;
042        }
043
044    @Override
045        public Boolean invoke(ExecutionEnvironment environment) {
046                Object lhsValue = lhs.invoke(environment);
047                Object rhsValue = rhs.invoke(environment);
048                return operator.compare(lhsValue, rhsValue);
049        }
050        
051}