use of org.hl7.fhir.dstu2016may.model.DecimalType in project org.hl7.fhir.core by hapifhir.
the class FHIRPathEngine method funcPower.
private List<Base> funcPower(ExecutionContext context, List<Base> focus, ExpressionNode expr) {
if (focus.size() != 1) {
throw makeException(expr, I18nConstants.FHIRPATH_FOCUS_PLURAL, "power", focus.size());
}
Base base = focus.get(0);
List<Base> result = new ArrayList<Base>();
if (base.hasType("integer", "decimal", "unsignedInt", "positiveInt")) {
List<Base> n1 = execute(context, focus, expr.getParameters().get(0), true);
if (n1.size() != 1) {
throw makeException(expr, I18nConstants.FHIRPATH_WRONG_PARAM_TYPE, "power", "0", "Multiple Values", "integer or decimal");
}
Double e = Double.parseDouble(n1.get(0).primitiveValue());
Double d = Double.parseDouble(base.primitiveValue());
try {
result.add(new DecimalType(Math.pow(d, e)));
} catch (Exception ex) {
// just return nothing
}
} else {
makeException(expr, I18nConstants.FHIRPATH_WRONG_PARAM_TYPE, "power", "(focus)", base.fhirType(), "integer or decimal");
}
return result;
}
use of org.hl7.fhir.dstu2016may.model.DecimalType in project org.hl7.fhir.core by hapifhir.
the class FHIRPathEngine method funcLog.
private List<Base> funcLog(ExecutionContext context, List<Base> focus, ExpressionNode expr) {
if (focus.size() != 1) {
throw makeException(expr, I18nConstants.FHIRPATH_FOCUS_PLURAL, "log", focus.size());
}
Base base = focus.get(0);
List<Base> result = new ArrayList<Base>();
if (base.hasType("integer", "decimal", "unsignedInt", "positiveInt")) {
List<Base> n1 = execute(context, focus, expr.getParameters().get(0), true);
if (n1.size() != 1) {
throw makeException(expr, I18nConstants.FHIRPATH_WRONG_PARAM_TYPE, "log", "0", "Multiple Values", "integer or decimal");
}
Double e = Double.parseDouble(n1.get(0).primitiveValue());
Double d = Double.parseDouble(base.primitiveValue());
try {
result.add(new DecimalType(customLog(e, d)));
} catch (Exception ex) {
// just return nothing
}
} else {
makeException(expr, I18nConstants.FHIRPATH_WRONG_PARAM_TYPE, "log", "(focus)", base.fhirType(), "integer or decimal");
}
return result;
}
use of org.hl7.fhir.dstu2016may.model.DecimalType in project org.hl7.fhir.core by hapifhir.
the class DecimalTypeNullTest method equalsShallow.
@Test
@DisplayName("Test null value equalsShallow()")
void equalsShallow() {
DecimalType nullDecimal = new DecimalType();
DecimalType validDecimal = new DecimalType("3.14");
Assertions.assertFalse(nullDecimal.equalsShallow(validDecimal));
}
use of org.hl7.fhir.dstu2016may.model.DecimalType in project org.hl7.fhir.core by hapifhir.
the class DecimalTypeNullTest method testToString.
@Test
@DisplayName("Test null value toString()")
void testToString() {
DecimalType nullDecimal = new DecimalType();
System.out.println("Value -> " + nullDecimal);
}
use of org.hl7.fhir.dstu2016may.model.DecimalType in project org.hl7.fhir.core by hapifhir.
the class DecimalTypeNullTest method typedCopy.
@Test
@DisplayName("Test null value typedCopy()")
void typedCopy() {
DecimalType nullDecimal = new DecimalType();
DecimalType copyDecimal = (DecimalType) nullDecimal.typedCopy();
Assertions.assertNull(copyDecimal.getValue());
}
Aggregations