All Downloads are FREE. Search and download functionalities are using the official Maven repository.

htsjdk.variant.variantcontext.JexlMissingValueTreatment Maven / Gradle / Ivy

There is a newer version: 4.1.3
Show newest version
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 resultSupplier;

    JexlMissingValueTreatment(final Supplier 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();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy