Java Code Examples for org.openrdf.model.Literal#decimalValue()

The following examples show how to use org.openrdf.model.Literal#decimalValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BigDecimalMarshall.java    From anno4j with Apache License 2.0 4 votes vote down vote up
public BigDecimal deserialize(Literal literal) {
	return literal.decimalValue();
}
 
Example 2
Source File: TripleStore.java    From cumulusrdf with Apache License 2.0 3 votes vote down vote up
/**
 * Returns the decimal representation of a given literal.
 * If the literal cannot be converted in a decimal number (e.g. null or NaN) then a default value is returned.
 * 
 * @param literal the literal.
 * @param defaultValue the default value that will be returned in case of errors.
 * @return the decimal representation of a given literal.
 */
BigDecimal asDecimal(final Literal literal, final BigDecimal defaultValue) {
	try {
		return literal.decimalValue();
	} catch (final Exception exception) {
		return defaultValue;
	}
}