/* * Copyright OpenSearch Contributors * SPDX-License-Identifier: Apache-2.0 */ package org.opensearch.dataprepper.expression; import java.util.Map; import java.util.function.BiPredicate; class GenericEqualOperator extends BinaryOperator { private final Map, Map, BiPredicate>> equalStrategy; public GenericEqualOperator( final int symbol, final int shouldEvaluateRuleIndex, final Map, Map, BiPredicate>> equalStrategy ) { super(symbol, shouldEvaluateRuleIndex); this.equalStrategy = equalStrategy; } @Override protected Boolean checkedEvaluate(final Object lhs, final Object rhs) { if (lhs == null || rhs == null) { return lhs == rhs; } else if (hasStrategyMatching(lhs, rhs)) { return equalStrategy.get(lhs.getClass()) .get(rhs.getClass()) .test(lhs, rhs); } else { return lhs.equals(rhs); } } private boolean hasStrategyMatching(final Object leftOperand, final Object rightOperand) { return equalStrategy.containsKey(leftOperand.getClass()) && equalStrategy.get(leftOperand.getClass()) .containsKey(rightOperand.getClass()); } }