001/*
002 * Copyright 2002-2017 the original author or authors.
003 *
004 * Licensed under the Apache 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 *      https://www.apache.org/licenses/LICENSE-2.0
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 */
016
017package org.springframework.expression;
018
019/**
020 * By default the mathematical operators {@link Operation} support simple types
021 * like numbers. By providing an implementation of OperatorOverloader, a user
022 * of the expression language can support these operations on other types.
023 *
024 * @author Andy Clement
025 * @since 3.0
026 */
027public interface OperatorOverloader {
028
029        /**
030         * Return true if the operator overloader supports the specified operation
031         * between the two operands and so should be invoked to handle it.
032         * @param operation the operation to be performed
033         * @param leftOperand the left operand
034         * @param rightOperand the right operand
035         * @return true if the OperatorOverloader supports the specified operation
036         * between the two operands
037         * @throws EvaluationException if there is a problem performing the operation
038         */
039        boolean overridesOperation(Operation operation, Object leftOperand, Object rightOperand)
040                        throws EvaluationException;
041
042        /**
043         * Execute the specified operation on two operands, returning a result.
044         * See {@link Operation} for supported operations.
045         * @param operation the operation to be performed
046         * @param leftOperand the left operand
047         * @param rightOperand the right operand
048         * @return the result of performing the operation on the two operands
049         * @throws EvaluationException if there is a problem performing the operation
050         */
051        Object operate(Operation operation, Object leftOperand, Object rightOperand)
052                        throws EvaluationException;
053
054}