org.cqframework.cql.cql2elm.ResultWithPossibleError Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cql-to-elm Show documentation
Show all versions of cql-to-elm Show documentation
The cql-to-elm library for the Clinical Quality Language Java reference implementation
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;
}
}