Permalink
Please sign in to comment.
Browse files
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...
Showing
with
193 additions
and 48 deletions.
- +76 −39 src/main/java/htsjdk/variant/variantcontext/JEXLMap.java
- +39 −0 src/main/java/htsjdk/variant/variantcontext/JexlMissingValueTreatment.java
- +33 −2 src/main/java/htsjdk/variant/variantcontext/VariantContextUtils.java
- +45 −7 src/test/java/htsjdk/variant/variantcontext/VariantJEXLContextUnitTest.java
| @@ -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(); | ||
| + } | ||
| + | ||
| +} |
0 comments on commit
5a2d7a7