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

org.cqframework.cql.cql2elm.ResultWithPossibleError Maven / Gradle / Ivy

Go to download

The cql-to-elm library for the Clinical Quality Language Java reference implementation

There is a newer version: 3.18.0
Show newest version
package org.cqframework.cql.cql2elm;

/**
 * Indicate either a populated result or the presence of an error that prevented the result from being created.
 */
public class ResultWithPossibleError {
    private final T underlyingThingOrNull;

    public static  ResultWithPossibleError withError() {
        return new ResultWithPossibleError<>(null);
    }

    public static  ResultWithPossibleError withTypeSpecifier(T underlyingThingOrNull) {
        return new ResultWithPossibleError<>(underlyingThingOrNull);
    }

    private ResultWithPossibleError(T namedTypeSpecifierOrNull) {
        this.underlyingThingOrNull = namedTypeSpecifierOrNull;
    }

    public boolean hasError() {
        return (underlyingThingOrNull == null);
    }

    public T getUnderlyingResultIfExists() {
        if (hasError()) {
            throw new IllegalArgumentException("Should have called hasError() first");
        }

        return underlyingThingOrNull;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy