use of org.hl7.fhir.instance.model.api.IBase in project cqf-ruler by DBCG.
the class Reflections method getFunction.
/**
* Generates a function to access a primitive property of the given
* BaseType.
*
* @param <BaseType> an IBase type
* @param <ReturnType> a return type for the Functions
* @param theBaseTypeClass the class of a the IBase type
* @param theChildName to create a function for
* @return a function for accessing the "theChildName" property of the
* BaseType
*/
@SuppressWarnings("unchecked")
public static <BaseType extends IBase, ReturnType extends List<? extends IBase>> Function<BaseType, ReturnType> getFunction(final Class<? extends BaseType> theBaseTypeClass, String theChildName) {
checkNotNull(theBaseTypeClass);
checkNotNull(theChildName);
IAccessor accessor = getAccessor(theBaseTypeClass, theChildName);
return r -> {
return (ReturnType) accessor.getValues(r);
};
}
use of org.hl7.fhir.instance.model.api.IBase in project cqf-ruler by DBCG.
the class ReflectionsTest method testAccessor.
@Test
public void testAccessor() {
Library library = new Library().setName("test");
IAccessor accessor = Reflections.getAccessor(library.getClass(), "name");
Optional<IBase> opt = accessor.getFirstValueOrNull(library);
@SuppressWarnings("unchecked") IPrimitiveType<String> value = (IPrimitiveType<String>) opt.get();
assertEquals("test", value.getValue());
}
Aggregations