use of org.openrdf.model.impl.BooleanLiteralImpl in project incubator-rya by apache.
the class FunctionAdapter method adaptValue.
/**
* Convert from OpenRDF to rdf4j value used by Geo Functions.
*
* @param value
* Must be a URIImpl, Literal or a BooleanLiteralImpl, or throws error. Ignores language.
* @param rdf4jValueFactory
* @return an rdf4j Literal copied from the input
*/
public org.eclipse.rdf4j.model.Value adaptValue(Value value, org.eclipse.rdf4j.model.ValueFactory rdf4jValueFactory) {
if (value instanceof URIImpl) {
URIImpl uri = (URIImpl) value;
return rdf4jValueFactory.createIRI(uri.stringValue());
} else if (!(value instanceof Literal)) {
throw new UnsupportedOperationException("Not supported, value must be literal type, it was: " + value.getClass() + " value=" + value);
}
if (value instanceof BooleanLiteralImpl) {
BooleanLiteralImpl bl = (BooleanLiteralImpl) value;
if (bl.booleanValue())
return org.eclipse.rdf4j.model.impl.BooleanLiteral.TRUE;
else
return org.eclipse.rdf4j.model.impl.BooleanLiteral.FALSE;
}
final Literal literalValue = (Literal) value;
org.eclipse.rdf4j.model.ValueFactory vf = org.eclipse.rdf4j.model.impl.SimpleValueFactory.getInstance();
final String label = literalValue.getLabel();
final IRI datatype = vf.createIRI(literalValue.getDatatype().stringValue());
return vf.createLiteral(label, datatype);
}
use of org.openrdf.model.impl.BooleanLiteralImpl in project incubator-rya by apache.
the class BindingSetStringConverterTest method toString_Boolean.
@Test
public void toString_Boolean() throws BindingSetConversionException {
// Setup the binding set that will be converted.
final MapBindingSet originalBindingSet = new MapBindingSet();
originalBindingSet.addBinding("x", new BooleanLiteralImpl(true));
// Convert it to a String.
final VariableOrder varOrder = new VariableOrder("x");
final BindingSetConverter<String> converter = new BindingSetStringConverter();
final String bindingSetString = converter.convert(originalBindingSet, varOrder);
// Ensure it converted to the expected result.
final String expected = "true<<~>>http://www.w3.org/2001/XMLSchema#boolean";
assertEquals(expected, bindingSetString);
}
use of org.openrdf.model.impl.BooleanLiteralImpl in project incubator-rya by apache.
the class BindingSetStringConverterTest method fromString_Boolean.
@Test
public void fromString_Boolean() throws BindingSetConversionException {
// Setup the String that will be converted.
final String bindingSetString = "true<<~>>http://www.w3.org/2001/XMLSchema#boolean";
// Convert it to a BindingSet
final BindingSetConverter<String> converter = new BindingSetStringConverter();
final BindingSet bindingSet = converter.convert(bindingSetString, new VariableOrder("x"));
// Ensure it converted to the expected result.
final MapBindingSet expected = new MapBindingSet();
expected.addBinding("x", new BooleanLiteralImpl(true));
assertEquals(expected, bindingSet);
}
Aggregations