in commons-rdf-simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java [85:113]
private <T extends RDFTerm> RDFTerm internallyMap(final T object) {
if (object == null || object instanceof SimpleRDFTerm) {
// No need to re-map our own objects.
// We support null as internallyMap() is also used by the filters,
// and the
// factory constructors later do null checks
return object;
}
if (object instanceof BlankNode) {
final BlankNode blankNode = (BlankNode) object;
// This guarantees that adding the same BlankNode multiple times to
// this graph will generate a local object that is mapped to an
// equivalent object, based on the code in the package private
// BlankNodeImpl class
return factory.createBlankNode(blankNode.uniqueReference());
}
if (object instanceof IRI) {
final IRI iri = (IRI) object;
return factory.createIRI(iri.getIRIString());
}
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()));
}