Search in sources :

Example 1 with BooleanLiteralImpl

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);
}
Also used : IRI(org.eclipse.rdf4j.model.IRI) Literal(org.openrdf.model.Literal) URIImpl(org.openrdf.model.impl.URIImpl) BooleanLiteralImpl(org.openrdf.model.impl.BooleanLiteralImpl)

Example 2 with BooleanLiteralImpl

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);
}
Also used : BooleanLiteralImpl(org.openrdf.model.impl.BooleanLiteralImpl) MapBindingSet(org.openrdf.query.impl.MapBindingSet) Test(org.junit.Test)

Example 3 with BooleanLiteralImpl

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);
}
Also used : BindingSet(org.openrdf.query.BindingSet) MapBindingSet(org.openrdf.query.impl.MapBindingSet) BooleanLiteralImpl(org.openrdf.model.impl.BooleanLiteralImpl) MapBindingSet(org.openrdf.query.impl.MapBindingSet) Test(org.junit.Test)

Aggregations

BooleanLiteralImpl (org.openrdf.model.impl.BooleanLiteralImpl)3 Test (org.junit.Test)2 MapBindingSet (org.openrdf.query.impl.MapBindingSet)2 IRI (org.eclipse.rdf4j.model.IRI)1 Literal (org.openrdf.model.Literal)1 URIImpl (org.openrdf.model.impl.URIImpl)1 BindingSet (org.openrdf.query.BindingSet)1