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