Skip to content
Permalink
Browse files
No need to nest in else.
  • Loading branch information
garydgregory committed Mar 5, 2021
1 parent 3993504 commit 58959f6fe7d5f78cc22207b36833e3f39b9f247b
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 38 deletions.
@@ -273,21 +273,21 @@ String asJsonLdString(final BlankNodeOrIRI blankNodeOrIRI) {
}
if (blankNodeOrIRI instanceof IRI) {
return ((IRI) blankNodeOrIRI).getIRIString();
} else if (blankNodeOrIRI instanceof BlankNode) {
final BlankNode blankNode = (BlankNode) blankNodeOrIRI;
final String ref = blankNode.uniqueReference();
if (ref.startsWith(bnodePrefix)) {
// One of ours (but possibly not a JsonLdBlankNode) -
// we can use the suffix directly
return ref.replace(bnodePrefix, "");
}
// Map to unique bnode identifier, e.g.
// _:0dbd92ee-ab1a-45e7-bba2-7ade54f87ec5
final UUID uuid = UUID.nameUUIDFromBytes(ref.getBytes(StandardCharsets.UTF_8));
return "_:" + uuid;
} else {
}
if (!(blankNodeOrIRI instanceof BlankNode)) {
throw new IllegalArgumentException("Expected a BlankNode or IRI, not: " + blankNodeOrIRI);
}
final BlankNode blankNode = (BlankNode) blankNodeOrIRI;
final String ref = blankNode.uniqueReference();
if (ref.startsWith(bnodePrefix)) {
// One of ours (but possibly not a JsonLdBlankNode) -
// we can use the suffix directly
return ref.replace(bnodePrefix, "");
}
// Map to unique bnode identifier, e.g.
// _:0dbd92ee-ab1a-45e7-bba2-7ade54f87ec5
final UUID uuid = UUID.nameUUIDFromBytes(ref.getBytes(StandardCharsets.UTF_8));
return "_:" + uuid;
}

JsonLdTerm asRDFTerm(final Node node, final String blankNodePrefix) {
@@ -296,17 +296,18 @@ JsonLdTerm asRDFTerm(final Node node, final String blankNodePrefix) {
}
if (node.isIRI()) {
return new JsonLdIRIImpl(node);
} else if (node.isBlankNode()) {
}
if (node.isBlankNode()) {
return new JsonLdBlankNodeImpl(node, blankNodePrefix);
} else if (node.isLiteral()) {
// TODO: Our own JsonLdLiteral
if (node.getLanguage() != null) {
return createLiteral(node.getValue(), node.getLanguage());
}
return createLiteral(node.getValue(), createIRI(node.getDatatype()));
} else {
}
if (!node.isLiteral()) {
throw new IllegalArgumentException("Node is neither IRI, BlankNode nor Literal: " + node);
}
// TODO: Our own JsonLdLiteral
if (node.getLanguage() != null) {
return createLiteral(node.getValue(), node.getLanguage());
}
return createLiteral(node.getValue(), createIRI(node.getDatatype()));
}

RDFDataset.Quad createJsonLdQuad(final BlankNodeOrIRI graphName, final BlankNodeOrIRI subject, final IRI predicate, final RDFTerm object) {
@@ -300,7 +300,8 @@ public RDF4JIRI asRDFTerm(final org.eclipse.rdf4j.model.IRI value) {
public RDF4JBlankNodeOrIRI asRDFTerm(final org.eclipse.rdf4j.model.Resource value) {
if(value instanceof IRI){
return asRDFTerm((IRI)value);
} else if (value instanceof BNode){
}
if (value instanceof BNode){
return asRDFTerm((BNode)value);
}
throw new IllegalArgumentException("Value is not a BNode or IRI: " + value.getClass());
@@ -91,18 +91,19 @@ private <T extends RDFTerm> RDFTerm internallyMap(final T object) {
// equivalent object, based on the code in the package private
// BlankNodeImpl class
return factory.createBlankNode(blankNode.uniqueReference());
} else if (object instanceof IRI && !(object instanceof IRIImpl)) {
}
if (object instanceof IRI && !(object instanceof IRIImpl)) {
final IRI iri = (IRI) object;
return factory.createIRI(iri.getIRIString());
} else if (object instanceof Literal && !(object instanceof LiteralImpl)) {
final Literal literal = (Literal) object;
if (literal.getLanguageTag().isPresent()) {
return factory.createLiteral(literal.getLexicalForm(), literal.getLanguageTag().get());
}
return factory.createLiteral(literal.getLexicalForm(), (IRI) internallyMap(literal.getDatatype()));
} else {
}
if (!(object instanceof Literal) || (object instanceof LiteralImpl)) {
throw new IllegalArgumentException("Not a BlankNode, IRI or Literal: " + object);
}
final Literal literal = (Literal) object;
if (literal.getLanguageTag().isPresent()) {
return factory.createLiteral(literal.getLexicalForm(), literal.getLanguageTag().get());
}
return factory.createLiteral(literal.getLexicalForm(), (IRI) internallyMap(literal.getDatatype()));
}

@Override
@@ -72,18 +72,19 @@ private <T extends RDFTerm> RDFTerm internallyMap(final T object) {
// equivalent object, based on the code in the package private
// BlankNodeImpl class
return factory.createBlankNode(blankNode.uniqueReference());
} else if (object instanceof IRI) {
}
if (object instanceof IRI) {
final IRI iri = (IRI) object;
return factory.createIRI(iri.getIRIString());
} else if (object instanceof Literal) {
final Literal literal = (Literal) object;
if (literal.getLanguageTag().isPresent()) {
return factory.createLiteral(literal.getLexicalForm(), literal.getLanguageTag().get());
}
return factory.createLiteral(literal.getLexicalForm(), (IRI) internallyMap(literal.getDatatype()));
} else {
}
if (!(object instanceof Literal)) {
throw new IllegalArgumentException("RDFTerm was neither a BlankNode, IRI nor Literal: " + object);
}
final Literal literal = (Literal) object;
if (literal.getLanguageTag().isPresent()) {
return factory.createLiteral(literal.getLexicalForm(), literal.getLanguageTag().get());
}
return factory.createLiteral(literal.getLexicalForm(), (IRI) internallyMap(literal.getDatatype()));
}

private Triple internallyMap(final Triple triple) {

0 comments on commit 58959f6

Please sign in to comment.