Skip to content
Permalink
Browse files
Always use blocks.
  • Loading branch information
garydgregory committed Nov 11, 2016
1 parent e36c67a commit 5274171f4cafb2d87bb7ed244d0b52c4b0a78e7d
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 29 deletions.
@@ -262,20 +262,24 @@ public static RDFTerm asRDFTerm(RDF factory, Node node) {
// No need to convert, just wrap
return ((JenaRDF) factory).asRDFTerm(node);
}
if (node.isURI())
if (node.isURI()) {
return factory.createIRI(node.getURI());
}
if (node.isLiteral()) {
String lang = node.getLiteralLanguage();
if (lang != null && !lang.isEmpty())
if (lang != null && !lang.isEmpty()) {
return factory.createLiteral(node.getLiteralLexicalForm(), lang);
if (node.getLiteralDatatype().equals(XSDDatatype.XSDstring))
}
if (node.getLiteralDatatype().equals(XSDDatatype.XSDstring)) {
return factory.createLiteral(node.getLiteralLexicalForm());
}
IRI dt = factory.createIRI(node.getLiteralDatatype().getURI());
return factory.createLiteral(node.getLiteralLexicalForm(), dt);
}
if (node.isBlank())
if (node.isBlank()) {
// The factory
return factory.createBlankNode(node.getBlankNodeLabel());
}
throw new ConversionException("Node is not a concrete RDF Term: " + node);
}

@@ -638,8 +642,9 @@ public void quad(org.apache.jena.sparql.core.Quad quad) {
* @return Converted Jena {@link org.apache.jena.graph.Graph}
*/
public org.apache.jena.graph.Graph asJenaGraph(Graph graph) {
if (graph instanceof JenaGraph)
if (graph instanceof JenaGraph) {
return ((JenaGraph) graph).asJenaGraph();
}
org.apache.jena.graph.Graph g = GraphFactory.createGraphMem();
graph.stream().forEach(t -> g.add(asJenaTriple(t)));
return g;
@@ -658,14 +663,16 @@ public Node asJenaNode(RDFTerm term) {
if (term == null) {
return null;
}
if (term instanceof JenaRDFTerm)
if (term instanceof JenaRDFTerm) {
// TODO: What if it's a JenaBlankNodeImpl with
// a different salt? Do we need to rewrite the
// jena blanknode identifier?
return ((JenaRDFTerm) term).asJenaNode();
}

if (term instanceof IRI)
if (term instanceof IRI) {
return NodeFactory.createURI(((IRI) term).getIRIString());
}

if (term instanceof Literal) {
Literal lit = (Literal) term;
@@ -693,8 +700,9 @@ public Node asJenaNode(RDFTerm term) {
* @return Converted Jena {@link org.apache.jena.graph.Triple}
*/
public org.apache.jena.graph.Triple asJenaTriple(Triple triple) {
if (triple instanceof JenaTriple)
if (triple instanceof JenaTriple) {
return ((JenaTriple) triple).asJenaTriple();
}
return org.apache.jena.graph.Triple.create(asJenaNode(triple.getSubject()),
asJenaNode(triple.getPredicate()),
asJenaNode(triple.getObject()));
@@ -724,17 +732,21 @@ public org.apache.jena.sparql.core.Quad asJenaQuad(Quad quad) {

// Some simple validations - full IRI parsing is not cheap.
private void validateIRI(String iri) {
if (iri.contains(" "))
if (iri.contains(" ")) {
throw new IllegalArgumentException();
if (iri.contains("<"))
}
if (iri.contains("<")) {
throw new IllegalArgumentException();
if (iri.contains(">"))
}
if (iri.contains(">")) {
throw new IllegalArgumentException();
}
}

private static void validateLang(String languageTag) {
if (languageTag.contains(" "))
if (languageTag.contains(" ")) {
throw new IllegalArgumentException("Invalid language tag: " + languageTag);
}
}

/**
@@ -38,12 +38,15 @@ class JenaBlankNodeImpl extends AbstractJenaRDFTerm implements JenaBlankNode {

@Override
public boolean equals(Object other) {
if (other == this)
if (other == this) {
return true;
if (other == null)
}
if (other == null) {
return false;
if (!(other instanceof BlankNode))
}
if (!(other instanceof BlankNode)) {
return false;
}
BlankNode bNode = (BlankNode) other;
return uniqueReference().equals(bNode.uniqueReference());
}
@@ -98,8 +98,9 @@ private Node toJenaPattern(Optional<? extends RDFTerm> graphName) {
}

private Node toJenaPattern(RDFTerm term) {
if (term == null)
if (term == null) {
return ANY;
}
return factory.asJenaNode(term);
}

@@ -127,8 +127,9 @@ public Stream<? extends Triple> stream(BlankNodeOrIRI s, IRI p, RDFTerm o) {
}

private Node toJenaAny(RDFTerm term) {
if (term == null)
if (term == null) {
return Node.ANY;
}
return factory.asJenaNode(term);
}

@@ -39,12 +39,15 @@ class JenaIRIImpl extends AbstractJenaRDFTerm implements JenaIRI {

@Override
public boolean equals(Object other) {
if (other == this)
if (other == this) {
return true;
if (other == null)
}
if (other == null) {
return false;
if (!(other instanceof IRI))
}
if (!(other instanceof IRI)) {
return false;
}
IRI iri = (IRI) other;
return getIRIString().equals(iri.getIRIString());
}
@@ -40,12 +40,15 @@ class JenaLiteralImpl extends AbstractJenaRDFTerm implements JenaLiteral {

@Override
public boolean equals(Object other) {
if (other == this)
if (other == this) {
return true;
if (other == null)
}
if (other == null) {
return false;
if (!(other instanceof Literal))
}
if (!(other instanceof Literal)) {
return false;
}
Literal literal = (Literal) other;
return getLexicalForm().equals(literal.getLexicalForm()) && getLanguageTag().equals(literal.getLanguageTag())
&& getDatatype().equals(literal.getDatatype());
@@ -59,8 +62,9 @@ public IRI getDatatype() {
@Override
public Optional<String> getLanguageTag() {
String x = asJenaNode().getLiteralLanguage();
if (x == null || x.isEmpty())
if (x == null || x.isEmpty()) {
return Optional.empty();
}
return Optional.of(x);
}

@@ -47,10 +47,12 @@ class JenaQuadImpl extends AbstractQuadLike<BlankNodeOrIRI, IRI, RDFTerm, BlankN

@Override
public boolean equals(Object other) {
if (other == this)
if (other == this) {
return true;
if (!(other instanceof Quad))
}
if (!(other instanceof Quad)) {
return false;
}
Quad quad = (Quad) other;
return getGraphName().equals(quad.getGraphName()) && getSubject().equals(quad.getSubject())
&& getPredicate().equals(quad.getPredicate()) && getObject().equals(quad.getObject());
@@ -44,12 +44,15 @@ class JenaTripleImpl extends AbstractQuadLike<BlankNodeOrIRI, IRI, RDFTerm, RDFT

@Override
public boolean equals(Object other) {
if (other == this)
if (other == this) {
return true;
if (other == null)
}
if (other == null) {
return false;
if (!(other instanceof Triple))
}
if (!(other instanceof Triple)) {
return false;
}
Triple triple = (Triple) other;
return getSubject().equals(triple.getSubject()) && getPredicate().equals(triple.getPredicate())
&& getObject().equals(triple.getObject());

0 comments on commit 5274171

Please sign in to comment.