forked from opensearch-project/data-prepper
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Krishna Kondaka <[email protected]>
- Loading branch information
Krishna Kondaka
committed
May 3, 2024
1 parent
32941ad
commit 88c620c
Showing
4 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
...expression/src/main/java/org/opensearch/dataprepper/expression/GenericTypeOfOperator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.dataprepper.expression; | ||
|
||
import org.antlr.v4.runtime.RuleContext; | ||
import org.opensearch.dataprepper.expression.antlr.DataPrepperExpressionParser; | ||
|
||
import java.util.Set; | ||
import java.util.function.BiPredicate; | ||
|
||
import static com.google.common.base.Preconditions.checkArgument; | ||
|
||
class GenericTypeOfOperator implements Operator<Boolean> { | ||
private final int symbol; | ||
private final String displayName; | ||
private final BiPredicate<Object, Object> operation; | ||
|
||
public GenericTypeOfOperator(final int symbol, BiPredicate<Object, Object> operation) { | ||
this.symbol = symbol; | ||
displayName = DataPrepperExpressionParser.VOCABULARY.getDisplayName(symbol); | ||
this.operation = operation; | ||
} | ||
|
||
@Override | ||
public boolean shouldEvaluate(final RuleContext ctx) { | ||
return ctx.getRuleIndex() == DataPrepperExpressionParser.RULE_typeOfOperatorExpression; | ||
} | ||
|
||
@Override | ||
public int getSymbol() { | ||
return symbol; | ||
} | ||
|
||
@Override | ||
public Boolean evaluate(final Object ... args) { | ||
checkArgument(args.length == 2, displayName + " requires operands length to be 2."); | ||
return operation.test(args[0], args[1]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters