-
Notifications
You must be signed in to change notification settings - Fork 244
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding fine control over jexl expression behavior with missing values (…
…#772) * adding JexlMissingValueTreatment to control how values in a jexl expression that are missing in the evaluated context are treated * adding overloads to VariantContextUtils.match to allow control of missing value behavior * minor refactoring in JEXLMap * making enum method package private * responding to comments * updated tests * moving JexlMissingValueTreatment to top level * fixing typo
- Loading branch information
1 parent
e69aff0
commit 5a2d7a7
Showing
4 changed files
with
193 additions
and
48 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
39 changes: 39 additions & 0 deletions
39
src/main/java/htsjdk/variant/variantcontext/JexlMissingValueTreatment.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,39 @@ | ||
package htsjdk.variant.variantcontext; | ||
|
||
import java.util.function.Supplier; | ||
|
||
/** | ||
* How to treat values that appear in a jexl expression but are missing in the context it's applied to | ||
*/ | ||
public enum JexlMissingValueTreatment { | ||
/** | ||
* Treat expressions with a missing value as a mismatch and evaluate to false | ||
*/ | ||
TREAT_AS_MISMATCH(() -> false), | ||
|
||
/** | ||
* Treat expressions with a missing value as a match and evaluate to true | ||
*/ | ||
TREAT_AS_MATCH(() -> true), | ||
|
||
/** | ||
* Treat expressions with a missing value as an error and throw an {@link IllegalArgumentException} | ||
*/ | ||
THROW(() -> {throw new IllegalArgumentException("Jexl Expression couldn't be evaluated because there was a missing value.");}); | ||
|
||
private final Supplier<Boolean> resultSupplier; | ||
|
||
JexlMissingValueTreatment(final Supplier<Boolean> resultSupplier){ | ||
this.resultSupplier = resultSupplier; | ||
} | ||
|
||
/** | ||
* get the missing value that corresponds to this option or throw an exception | ||
* @return the value that should be used in case of a missing value | ||
* @throws IllegalArgumentException if this should be treated as an error | ||
*/ | ||
boolean getMissingValueOrExplode(){ | ||
return resultSupplier.get(); | ||
} | ||
|
||
} |
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