You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2017/10/30 14:57:02 UTC
[02/22] commons-rdf git commit: Module names, directory names,
and artifact names should match.
http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/d59203ce/simple/pom.xml
----------------------------------------------------------------------
diff --git a/simple/pom.xml b/simple/pom.xml
deleted file mode 100644
index 1438f07..0000000
--- a/simple/pom.xml
+++ /dev/null
@@ -1,74 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
-
- <parent>
- <groupId>org.apache.commons</groupId>
- <artifactId>commons-rdf-parent</artifactId>
- <version>0.5.0-SNAPSHOT</version>
- </parent>
-
- <artifactId>commons-rdf-simple</artifactId>
- <packaging>jar</packaging>
-
- <name>Commons RDF impl: Simple</name>
- <description>Simple (if not naive) implementation of Commons RDF API</description>
-
- <distributionManagement>
- <site>
- <id>commonsrdf-api-site</id>
- <url>scm:svn:${commons.scmPubUrl}/simple/</url>
- </site>
- </distributionManagement>
-
- <dependencies>
- <dependency>
- <groupId>${project.parent.groupId}</groupId>
- <artifactId>commons-rdf-api</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>${project.parent.groupId}</groupId>
- <artifactId>commons-rdf-api</artifactId>
- <version>${project.version}</version>
- <classifier>tests</classifier>
- <scope>test</scope>
- </dependency>
- </dependencies>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-bundle-plugin</artifactId>
- <configuration>
- <instructions>
- <Bundle-SymbolicName>org.apache.commons.rdf.simple</Bundle-SymbolicName>
- <Automatic-Module-Name>org.apache.commons.rdf.simple</Automatic-Module-Name>
- <Require-Capability>osgi.extender; filter:="(osgi.extender=osgi.serviceloader.registrar)";resolution:=optional</Require-Capability>
- <Provide-Capability>osgi.serviceloader; osgi.serviceloader=org.apache.commons.rdf.api.RDF</Provide-Capability>
- </instructions>
- </configuration>
- </plugin>
- </plugins>
- </build>
-</project>
http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/d59203ce/simple/src/main/java/org/apache/commons/rdf/simple/BlankNodeImpl.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/BlankNodeImpl.java b/simple/src/main/java/org/apache/commons/rdf/simple/BlankNodeImpl.java
deleted file mode 100644
index f604f3e..0000000
--- a/simple/src/main/java/org/apache/commons/rdf/simple/BlankNodeImpl.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.rdf.simple;
-
-import java.nio.charset.StandardCharsets;
-import java.util.Objects;
-import java.util.UUID;
-import java.util.concurrent.atomic.AtomicLong;
-
-import org.apache.commons.rdf.api.BlankNode;
-import org.apache.commons.rdf.simple.SimpleRDF.SimpleRDFTerm;
-
-/**
- * A simple implementation of BlankNode.
- */
-final class BlankNodeImpl implements BlankNode, SimpleRDFTerm {
-
- private static final UUID SALT = UUID.randomUUID();
- private static final AtomicLong COUNTER = new AtomicLong();
-
- private final String uniqueReference;
-
- public BlankNodeImpl() {
- this(SALT, Long.toString(COUNTER.incrementAndGet()));
- }
-
- public BlankNodeImpl(final UUID uuidSalt, final String name) {
- if (Objects.requireNonNull(name).isEmpty()) {
- throw new IllegalArgumentException("Invalid blank node id: " + name);
- }
-
- // Build a semi-URN - to be hashed for a name-based UUID below
- // Both the scope and the id are used to create the UUID, ensuring that
- // a caller can reliably create the same bnode if necessary by sending
- // in the same scope to RDF.createBlankNode(String)
- final String uuidInput = "urn:uuid:" + uuidSalt + "#" + name;
-
- // The above is not a good value for this.id, as the id
- // needs to be further escaped for
- // ntriplesString() (there are no restrictions on
- // RDF.createBlankNode(String) ).
-
- // Rather than implement ntriples escaping here, and knowing
- // our uniqueReference() contain a UUID anyway, we simply
- // create another name-based UUID, and use it within both
- // uniqueReference() and within ntriplesString().
- //
- // A side-effect from this is that the blank node identifier
- // is not preserved or shown in ntriplesString. In a way
- // this is a feature, not a bug. as the contract for RDF
- // has no such requirement.
- this.uniqueReference = UUID.nameUUIDFromBytes(uuidInput.getBytes(StandardCharsets.UTF_8)).toString();
- }
-
- @Override
- public String uniqueReference() {
- return uniqueReference;
- }
-
- @Override
- public String ntriplesString() {
- return "_:" + uniqueReference;
- }
-
- @Override
- public String toString() {
- return ntriplesString();
- }
-
- @Override
- public int hashCode() {
- return uniqueReference.hashCode();
- }
-
- @Override
- public boolean equals(final Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- // We don't support equality with other implementations
- if (!(obj instanceof BlankNodeImpl)) {
- return false;
- }
- final BlankNodeImpl other = (BlankNodeImpl) obj;
- if (uniqueReference == null) {
- if (other.uniqueReference != null) {
- return false;
- }
- } else if (!uniqueReference.equals(other.uniqueReference)) {
- return false;
- }
- return true;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/d59203ce/simple/src/main/java/org/apache/commons/rdf/simple/DatasetGraphView.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/DatasetGraphView.java b/simple/src/main/java/org/apache/commons/rdf/simple/DatasetGraphView.java
deleted file mode 100644
index 15515f2..0000000
--- a/simple/src/main/java/org/apache/commons/rdf/simple/DatasetGraphView.java
+++ /dev/null
@@ -1,139 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.rdf.simple;
-
-import java.util.Optional;
-import java.util.stream.Stream;
-
-import org.apache.commons.rdf.api.BlankNode;
-import org.apache.commons.rdf.api.BlankNodeOrIRI;
-import org.apache.commons.rdf.api.Dataset;
-import org.apache.commons.rdf.api.Graph;
-import org.apache.commons.rdf.api.IRI;
-import org.apache.commons.rdf.api.Quad;
-import org.apache.commons.rdf.api.RDFTerm;
-import org.apache.commons.rdf.api.Triple;
-
-/**
- * A {@link Graph} view on a {@link Dataset}.
- * <p>
- * This view is backed by a {@link Dataset}, and can be constructed in two ways:
- *
- * <dl>
- * <dt>{@link #DatasetGraphView(Dataset)}</dt>
- * <dd>Expose a <em>union graph</em> view of the Dataset, where all the
- * {@link Quad}s of the Dataset is represented as a {@link Triple}. Adding
- * triples will add them to the <em>default graph</em>, while removing triples
- * will remove from all graphs.</dd>
- *
- * <dt>{@link #DatasetGraphView(Dataset, BlankNodeOrIRI)}</dt>
- * <dd>Expose a particular graph of the Dataset, either named by an {@link IRI},
- * a {@link BlankNode}, or <code>null</code> for the <em>default
- * graph</em>.</dd>
- * </dl>
- * <p>
- * Changes in the Graph are reflected directly in the Dataset and vice versa.
- * This class is thread-safe is the underlying Dataset is thread-safe.
- */
-public class DatasetGraphView implements Graph {
-
- private final boolean unionGraph;
- private final BlankNodeOrIRI namedGraph;
- private final Dataset dataset;
-
- public DatasetGraphView(final Dataset dataset) {
- this.dataset = dataset;
- this.namedGraph = null;
- this.unionGraph = true;
- }
-
- public DatasetGraphView(final Dataset dataset, final BlankNodeOrIRI namedGraph) {
- this.dataset = dataset;
- this.namedGraph = namedGraph;
- this.unionGraph = false;
- }
-
- @Override
- public void close() throws Exception {
- dataset.close();
-
- }
-
- @Override
- public void add(final Triple triple) {
- dataset.add(namedGraph, triple.getSubject(), triple.getPredicate(), triple.getObject());
- }
-
- @Override
- public void add(final BlankNodeOrIRI subject, final IRI predicate, final RDFTerm object) {
- dataset.add(namedGraph, subject, predicate, object);
- }
-
- @Override
- public boolean contains(final Triple triple) {
- return dataset.contains(unionOrNamedGraph(), triple.getSubject(), triple.getPredicate(), triple.getObject());
- }
-
- private Optional<BlankNodeOrIRI> unionOrNamedGraph() {
- if (unionGraph) {
- return null;
- }
- return Optional.ofNullable(namedGraph);
- }
-
- @Override
- public boolean contains(final BlankNodeOrIRI subject, final IRI predicate, final RDFTerm object) {
- return dataset.contains(unionOrNamedGraph(), subject, predicate, object);
- }
-
- @Override
- public void remove(final Triple triple) {
- dataset.remove(unionOrNamedGraph(), triple.getSubject(), triple.getPredicate(), triple.getObject());
- }
-
- @Override
- public void remove(final BlankNodeOrIRI subject, final IRI predicate, final RDFTerm object) {
- dataset.remove(unionOrNamedGraph(), subject, predicate, object);
- }
-
- @Override
- public void clear() {
- dataset.remove(unionOrNamedGraph(), null, null, null);
- }
-
- @Override
- public long size() {
- return stream().count();
- }
-
- @Override
- public Stream<? extends Triple> stream() {
- return stream(null, null, null);
- }
-
- @Override
- public Stream<? extends Triple> stream(final BlankNodeOrIRI subject, final IRI predicate, final RDFTerm object) {
- final Stream<Triple> stream = dataset.stream(unionOrNamedGraph(), subject, predicate, object).map(Quad::asTriple);
- if (unionGraph) {
- // remove duplicates
- return stream.distinct();
- }
- return stream;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/d59203ce/simple/src/main/java/org/apache/commons/rdf/simple/DatasetImpl.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/DatasetImpl.java b/simple/src/main/java/org/apache/commons/rdf/simple/DatasetImpl.java
deleted file mode 100644
index b1f6bdf..0000000
--- a/simple/src/main/java/org/apache/commons/rdf/simple/DatasetImpl.java
+++ /dev/null
@@ -1,214 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.rdf.simple;
-
-import java.util.HashSet;
-import java.util.Objects;
-import java.util.Optional;
-import java.util.Set;
-import java.util.function.Predicate;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
-
-import org.apache.commons.rdf.api.BlankNode;
-import org.apache.commons.rdf.api.BlankNodeOrIRI;
-import org.apache.commons.rdf.api.Dataset;
-import org.apache.commons.rdf.api.Graph;
-import org.apache.commons.rdf.api.IRI;
-import org.apache.commons.rdf.api.Literal;
-import org.apache.commons.rdf.api.Quad;
-import org.apache.commons.rdf.api.RDFTerm;
-import org.apache.commons.rdf.simple.SimpleRDF.SimpleRDFTerm;
-
-/**
- * A simple, memory-based implementation of Dataset.
- * <p>
- * {@link Quad}s in the graph are kept in a {@link Set}.
- * <p>
- * All Stream operations are performed using parallel and unordered directives.
- */
-final class DatasetImpl implements Dataset {
-
- private static final int TO_STRING_MAX = 10;
- private final Set<Quad> quads = new HashSet<>();
- private final SimpleRDF factory;
-
- DatasetImpl(final SimpleRDF simpleRDF) {
- this.factory = simpleRDF;
- }
-
- @Override
- public void add(final BlankNodeOrIRI graphName, final BlankNodeOrIRI subject, final IRI predicate, final RDFTerm object) {
- final BlankNodeOrIRI newGraphName = (BlankNodeOrIRI) internallyMap(graphName);
- final BlankNodeOrIRI newSubject = (BlankNodeOrIRI) internallyMap(subject);
- final IRI newPredicate = (IRI) internallyMap(predicate);
- final RDFTerm newObject = internallyMap(object);
- final Quad result = factory.createQuad(newGraphName, newSubject, newPredicate, newObject);
- quads.add(result);
- }
-
- @Override
- public void add(final Quad quad) {
- final BlankNodeOrIRI newGraph = (BlankNodeOrIRI) internallyMap(quad.getGraphName().orElse(null));
- final BlankNodeOrIRI newSubject = (BlankNodeOrIRI) internallyMap(quad.getSubject());
- final IRI newPredicate = (IRI) internallyMap(quad.getPredicate());
- final RDFTerm newObject = internallyMap(quad.getObject());
- // Check if any of the object references changed during the mapping, to
- // avoid creating a new Quad object if possible
- if (newGraph == quad.getGraphName().orElse(null) && newSubject == quad.getSubject()
- && newPredicate == quad.getPredicate() && newObject == quad.getObject()) {
- quads.add(quad);
- } else {
- // Make a new Quad with our mapped instances
- final Quad result = factory.createQuad(newGraph, newSubject, newPredicate, newObject);
- quads.add(result);
- }
- }
-
- private <T extends RDFTerm> RDFTerm internallyMap(final T object) {
- if (object == null || object instanceof SimpleRDFTerm) {
- return object;
- }
- if (object instanceof BlankNode && !(object instanceof BlankNodeImpl)) {
- 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());
- } else 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());
- } else {
- return factory.createLiteral(literal.getLexicalForm(), (IRI) internallyMap(literal.getDatatype()));
- }
- } else {
- throw new IllegalArgumentException("Not a BlankNode, IRI or Literal: " + object);
- }
- }
-
- @Override
- public void clear() {
- quads.clear();
- }
-
- @Override
- public boolean contains(final Optional<BlankNodeOrIRI> graphName, final BlankNodeOrIRI subject, final IRI predicate, final RDFTerm object) {
- return stream(graphName, subject, predicate, object).findAny().isPresent();
- }
-
- @Override
- public boolean contains(final Quad quad) {
- return quads.contains(Objects.requireNonNull(quad));
- }
-
- @Override
- public Stream<Quad> stream() {
- return quads.parallelStream().unordered();
- }
-
- @Override
- public Stream<Quad> stream(final Optional<BlankNodeOrIRI> graphName, final BlankNodeOrIRI subject, final IRI predicate,
- final RDFTerm object) {
- final Optional<BlankNodeOrIRI> newGraphName;
- if (graphName == null) {
- // Avoid Optional<Optional<BlankNodeOrIRI>> ...
- newGraphName = null;
- } else {
- newGraphName = graphName.map(g -> (BlankNodeOrIRI) internallyMap(g));
- }
- final BlankNodeOrIRI newSubject = (BlankNodeOrIRI) internallyMap(subject);
- final IRI newPredicate = (IRI) internallyMap(predicate);
- final RDFTerm newObject = internallyMap(object);
-
- return getQuads(t -> {
- if (newGraphName != null && !t.getGraphName().equals(newGraphName)) {
- // This would check Optional.empty() == Optional.empty()
- return false;
- }
- if (subject != null && !t.getSubject().equals(newSubject)) {
- return false;
- }
- if (predicate != null && !t.getPredicate().equals(newPredicate)) {
- return false;
- }
- if (object != null && !t.getObject().equals(newObject)) {
- return false;
- }
- return true;
- });
- }
-
- private Stream<Quad> getQuads(final Predicate<Quad> filter) {
- return stream().filter(filter);
- }
-
- @Override
- public void remove(final Optional<BlankNodeOrIRI> graphName, final BlankNodeOrIRI subject, final IRI predicate, final RDFTerm object) {
- final Stream<Quad> toRemove = stream(graphName, subject, predicate, object);
- for (final Quad t : toRemove.collect(Collectors.toList())) {
- // Avoid ConcurrentModificationException in ArrayList
- remove(t);
- }
- }
-
- @Override
- public void remove(final Quad quad) {
- quads.remove(Objects.requireNonNull(quad));
- }
-
- @Override
- public long size() {
- return quads.size();
- }
-
- @Override
- public String toString() {
- final String s = stream().limit(TO_STRING_MAX).map(Object::toString).collect(Collectors.joining("\n"));
- if (size() > TO_STRING_MAX) {
- return s + "\n# ... +" + (size() - TO_STRING_MAX) + " more";
- } else {
- return s;
- }
- }
-
- @Override
- public void close() {
- }
-
- @Override
- public Graph getGraph() {
- return getGraph(null).get();
- }
-
- @Override
- public Optional<Graph> getGraph(final BlankNodeOrIRI graphName) {
- return Optional.of(new DatasetGraphView(this, graphName));
- }
-
- @Override
- public Stream<BlankNodeOrIRI> getGraphNames() {
- // Not very efficient..
- return stream().map(Quad::getGraphName).filter(Optional::isPresent).map(Optional::get).distinct();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/d59203ce/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java b/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java
deleted file mode 100644
index 2c3bee4..0000000
--- a/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java
+++ /dev/null
@@ -1,179 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.rdf.simple;
-
-import org.apache.commons.rdf.api.*;
-import org.apache.commons.rdf.simple.SimpleRDF.SimpleRDFTerm;
-
-import java.util.HashSet;
-import java.util.Set;
-import java.util.function.Predicate;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
-
-/**
- * A simple, memory-based implementation of Graph.
- * <p>
- * {@link Triple}s in the graph are kept in a {@link Set}.
- * <p>
- * All Stream operations are performed using parallel and unordered directives.
- */
-final class GraphImpl implements Graph {
-
- private static final int TO_STRING_MAX = 10;
- private final Set<Triple> triples = new HashSet<>();
- private final SimpleRDF factory;
-
- GraphImpl(final SimpleRDF simpleRDF) {
- this.factory = simpleRDF;
- }
-
- @Override
- public void add(final BlankNodeOrIRI subject, final IRI predicate, final RDFTerm object) {
- final BlankNodeOrIRI newSubject = (BlankNodeOrIRI) internallyMap(subject);
- final IRI newPredicate = (IRI) internallyMap(predicate);
- final RDFTerm newObject = internallyMap(object);
- final Triple result = factory.createTriple(newSubject, newPredicate, newObject);
- triples.add(result);
- }
-
- @Override
- public void add(final Triple triple) {
- triples.add(internallyMap(triple));
- }
-
- 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());
- } else 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());
- } else {
- return factory.createLiteral(literal.getLexicalForm(), (IRI) internallyMap(literal.getDatatype()));
- }
- } else {
- throw new IllegalArgumentException("RDFTerm was neither a BlankNode, IRI nor Literal: " + object);
- }
- }
-
- private Triple internallyMap(final Triple triple) {
- final BlankNodeOrIRI newSubject = (BlankNodeOrIRI) internallyMap(triple.getSubject());
- final IRI newPredicate = (IRI) internallyMap(triple.getPredicate());
- final RDFTerm newObject = internallyMap(triple.getObject());
- // Check if any of the object references changed during the mapping, to
- // avoid creating a new Triple object if possible
- if (newSubject == triple.getSubject() && newPredicate == triple.getPredicate()
- && newObject == triple.getObject()) {
- return triple;
- } else {
- return factory.createTriple(newSubject, newPredicate, newObject);
- }
- }
-
- @Override
- public void clear() {
- triples.clear();
- }
-
- @Override
- public boolean contains(final BlankNodeOrIRI subject, final IRI predicate, final RDFTerm object) {
- return stream(subject, predicate, object).findFirst().isPresent();
- }
-
- @Override
- public boolean contains(final Triple triple) {
- return triples.contains(internallyMap(triple));
- }
-
- @Override
- public Stream<Triple> stream() {
- return triples.parallelStream().unordered();
- }
-
- @Override
- public Stream<Triple> stream(final BlankNodeOrIRI subject, final IRI predicate, final RDFTerm object) {
- final BlankNodeOrIRI newSubject = (BlankNodeOrIRI) internallyMap(subject);
- final IRI newPredicate = (IRI) internallyMap(predicate);
- final RDFTerm newObject = internallyMap(object);
-
- return getTriples(t -> {
- // Lacking the requirement for .equals() we have to be silly
- // and test ntriples string equivalance
- if (subject != null && !t.getSubject().equals(newSubject)) {
- return false;
- }
- if (predicate != null && !t.getPredicate().equals(newPredicate)) {
- return false;
- }
- if (object != null && !t.getObject().equals(newObject)) {
- return false;
- }
- return true;
- });
- }
-
- private Stream<Triple> getTriples(final Predicate<Triple> filter) {
- return stream().filter(filter);
- }
-
- @Override
- public void remove(final BlankNodeOrIRI subject, final IRI predicate, final RDFTerm object) {
- final Stream<Triple> toRemove = stream(subject, predicate, object);
- for (final Triple t : toRemove.collect(Collectors.toList())) {
- // Avoid ConcurrentModificationException in ArrayList
- remove(t);
- }
- }
-
- @Override
- public void remove(final Triple triple) {
- triples.remove(internallyMap(triple));
- }
-
- @Override
- public long size() {
- return triples.size();
- }
-
- @Override
- public String toString() {
- final String s = stream().limit(TO_STRING_MAX).map(Object::toString).collect(Collectors.joining("\n"));
- if (size() > TO_STRING_MAX) {
- return s + "\n# ... +" + (size() - TO_STRING_MAX) + " more";
- } else {
- return s;
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/d59203ce/simple/src/main/java/org/apache/commons/rdf/simple/IRIImpl.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/IRIImpl.java b/simple/src/main/java/org/apache/commons/rdf/simple/IRIImpl.java
deleted file mode 100644
index 114eef1..0000000
--- a/simple/src/main/java/org/apache/commons/rdf/simple/IRIImpl.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.rdf.simple;
-
-import org.apache.commons.rdf.api.IRI;
-
-import java.net.URI;
-
-/**
- * A simple implementation of IRI.
- */
-final class IRIImpl implements IRI, SimpleRDF.SimpleRDFTerm {
-
- private final String iri;
-
- public IRIImpl(final String iri) {
- // should throw IllegalArgumentException on most illegal IRIs
- URI.create(iri);
- // NOTE: We don't keep the URI as it uses outdated RFC2396 and will get
- // some IDNs wrong
- this.iri = iri;
- }
-
- @Override
- public String getIRIString() {
- return iri;
- }
-
- @Override
- public String ntriplesString() {
- return "<" + getIRIString() + ">";
- }
-
- @Override
- public String toString() {
- return ntriplesString();
- }
-
- @Override
- public boolean equals(final Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null || !(obj instanceof IRI)) {
- return false;
- }
- final IRI other = (IRI) obj;
- return getIRIString().equals(other.getIRIString());
- }
-
- @Override
- public int hashCode() {
- return iri.hashCode();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/d59203ce/simple/src/main/java/org/apache/commons/rdf/simple/LiteralImpl.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/LiteralImpl.java b/simple/src/main/java/org/apache/commons/rdf/simple/LiteralImpl.java
deleted file mode 100644
index 763a629..0000000
--- a/simple/src/main/java/org/apache/commons/rdf/simple/LiteralImpl.java
+++ /dev/null
@@ -1,136 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.rdf.simple;
-
-import java.util.IllformedLocaleException;
-import java.util.Locale;
-import java.util.Objects;
-import java.util.Optional;
-
-import org.apache.commons.rdf.api.IRI;
-import org.apache.commons.rdf.api.Literal;
-
-/**
- * A simple implementation of Literal.
- */
-final class LiteralImpl implements Literal, SimpleRDF.SimpleRDFTerm {
-
- private static final String QUOTE = "\"";
-
- private final IRI dataType;
- private final String languageTag;
- private final String lexicalForm;
-
- public LiteralImpl(final String literal) {
- this(literal, Types.XSD_STRING);
- }
-
- public LiteralImpl(final String lexicalForm, final IRI dataType) {
- this.lexicalForm = Objects.requireNonNull(lexicalForm);
- this.dataType = Types.get(Objects.requireNonNull(dataType)).orElse(dataType);
- if (Types.RDF_LANGSTRING.equals(this.dataType)) {
- throw new IllegalArgumentException(
- "Cannot create a non-language literal with type " + Types.RDF_LANGSTRING);
- }
- this.languageTag = null;
- }
-
- public LiteralImpl(final String literal, final String languageTag) {
- this.lexicalForm = Objects.requireNonNull(literal);
- this.languageTag = Objects.requireNonNull(lowerCase(languageTag));
- if (languageTag.isEmpty()) {
- // TODO: Check against
- // http://www.w3.org/TR/n-triples/#n-triples-grammar
- throw new IllegalArgumentException("Language tag can't be null");
- }
- try {
- new Locale.Builder().setLanguageTag(languageTag);
- } catch (final IllformedLocaleException ex) {
- throw new IllegalArgumentException("Invalid languageTag: " + languageTag, ex);
- }
-
- // System.out.println(aLocale);
- this.dataType = Types.RDF_LANGSTRING;
- }
-
- @Override
- public IRI getDatatype() {
- return dataType;
- }
-
- @Override
- public Optional<String> getLanguageTag() {
- return Optional.ofNullable(languageTag);
- }
-
- @Override
- public String getLexicalForm() {
- return lexicalForm;
- }
-
- @Override
- public String ntriplesString() {
- final StringBuilder sb = new StringBuilder();
- sb.append(QUOTE);
- // Escape special characters
- sb.append(getLexicalForm().replace("\\", "\\\\"). // escaped to \\
- replace("\"", "\\\""). // escaped to \"
- replace("\r", "\\r"). // escaped to \r
- replace("\n", "\\n")); // escaped to \n
- sb.append(QUOTE);
-
- // getLanguageTag().ifPresent(s -> sb.append("@" + s));
- if (getLanguageTag().isPresent()) {
- sb.append("@");
- sb.append(getLanguageTag().get());
-
- } else if (!getDatatype().equals(Types.XSD_STRING)) {
- sb.append("^^");
- sb.append(getDatatype().ntriplesString());
- }
- return sb.toString();
- }
-
- @Override
- public String toString() {
- return ntriplesString();
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(lexicalForm, dataType, languageTag);
- }
-
- private static String lowerCase(String langTag) {
- return langTag.toLowerCase(Locale.ROOT);
- }
-
- @Override
- public boolean equals(final Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null || !(obj instanceof Literal)) {
- return false;
- }
- final Literal literal = (Literal) obj;
- return getDatatype().equals(literal.getDatatype()) && getLexicalForm().equals(literal.getLexicalForm())
- && getLanguageTag().equals(literal.getLanguageTag().map(LiteralImpl::lowerCase));
- }
-
-}
http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/d59203ce/simple/src/main/java/org/apache/commons/rdf/simple/QuadImpl.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/QuadImpl.java b/simple/src/main/java/org/apache/commons/rdf/simple/QuadImpl.java
deleted file mode 100644
index 51bef69..0000000
--- a/simple/src/main/java/org/apache/commons/rdf/simple/QuadImpl.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.rdf.simple;
-
-import org.apache.commons.rdf.api.BlankNodeOrIRI;
-import org.apache.commons.rdf.api.IRI;
-import org.apache.commons.rdf.api.Quad;
-import org.apache.commons.rdf.api.RDFTerm;
-import org.apache.commons.rdf.api.Triple;
-
-import java.util.Objects;
-import java.util.Optional;
-
-/**
- * A simple implementation of Quad.
- */
-final class QuadImpl implements Quad {
-
- private final BlankNodeOrIRI graphName;
- private final BlankNodeOrIRI subject;
- private final IRI predicate;
- private final RDFTerm object;
-
- /**
- * Construct Quad from its constituent parts.
- * <p>
- * The objects are not changed. All mapping of BNode objects is done in
- * {@link SimpleRDF#createQuad(BlankNodeOrIRI, BlankNodeOrIRI, IRI, RDFTerm)}.
- *
- * @param graphName
- * graphName of triple
- * @param subject
- * subject of triple
- * @param predicate
- * predicate of triple
- * @param object
- * object of triple
- */
- public QuadImpl(final BlankNodeOrIRI graphName, final BlankNodeOrIRI subject, final IRI predicate, final RDFTerm object) {
- this.graphName = graphName; // possibly null
- this.subject = Objects.requireNonNull(subject);
- this.predicate = Objects.requireNonNull(predicate);
- this.object = Objects.requireNonNull(object);
- }
-
- @Override
- public Optional<BlankNodeOrIRI> getGraphName() {
- return Optional.ofNullable(graphName);
- }
-
- @Override
- public BlankNodeOrIRI getSubject() {
- return subject;
- }
-
- @Override
- public IRI getPredicate() {
- return predicate;
- }
-
- @Override
- public RDFTerm getObject() {
- return object;
- }
-
- @Override
- public String toString() {
- return getSubject().ntriplesString() + " " + getPredicate().ntriplesString() + " "
- + getObject().ntriplesString() + " " + getGraphName().map(g -> g.ntriplesString() + " ").orElse("")
- + ".";
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(subject, predicate, object, graphName);
- }
-
- @Override
- public boolean equals(final Object obj) {
- if (!(obj instanceof Quad)) {
- return false;
- }
- final Quad other = (Quad) obj;
- return getGraphName().equals(other.getGraphName()) && getSubject().equals(other.getSubject())
- && getPredicate().equals(other.getPredicate()) && getObject().equals(other.getObject());
- }
-
- @Override
- public Triple asTriple() {
- return new TripleImpl(getSubject(), getPredicate(), getObject());
- }
-
-}
http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/d59203ce/simple/src/main/java/org/apache/commons/rdf/simple/SimpleRDF.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/SimpleRDF.java b/simple/src/main/java/org/apache/commons/rdf/simple/SimpleRDF.java
deleted file mode 100644
index 6f6b2a5..0000000
--- a/simple/src/main/java/org/apache/commons/rdf/simple/SimpleRDF.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.rdf.simple;
-
-import java.util.UUID;
-
-import org.apache.commons.rdf.api.BlankNode;
-import org.apache.commons.rdf.api.BlankNodeOrIRI;
-import org.apache.commons.rdf.api.Dataset;
-import org.apache.commons.rdf.api.Graph;
-import org.apache.commons.rdf.api.IRI;
-import org.apache.commons.rdf.api.Literal;
-import org.apache.commons.rdf.api.Quad;
-import org.apache.commons.rdf.api.RDFTerm;
-import org.apache.commons.rdf.api.RDF;
-import org.apache.commons.rdf.api.Triple;
-
-/**
- * Simple RDF implementation.
- * <p>
- * The {@link RDFTerm}, {@link Triple}, {@link Quad}, {@link Graph} and
- * {@link Dataset} instances created by SimpleRDF are simple in-memory
- * Implementations that are not thread-safe or efficient, but which may be
- * useful for testing and prototyping purposes.
- */
-public class SimpleRDF implements RDF {
-
- /**
- * Marker interface to say that this RDFTerm is part of the Simple
- * implementation. Used by {@link GraphImpl} to avoid double remapping.
- * <p>
- * This method is package protected to avoid any third-party subclasses.
- *
- */
- static interface SimpleRDFTerm extends RDFTerm {
- }
-
- /**
- * Unique salt per instance, for {@link #createBlankNode(String)}
- */
- private final UUID SALT = UUID.randomUUID();
-
- @Override
- public BlankNode createBlankNode() {
- return new BlankNodeImpl();
- }
-
- @Override
- public BlankNode createBlankNode(final String name) {
- return new BlankNodeImpl(SALT, name);
- }
-
- @Override
- public Graph createGraph() {
- // Creates a GraphImpl object using this object as the factory for
- // delegating all object creation to
- return new GraphImpl(this);
- }
-
- @Override
- public Dataset createDataset() throws UnsupportedOperationException {
- return new DatasetImpl(this);
- }
-
- @Override
- public IRI createIRI(final String iri) {
- final IRI result = new IRIImpl(iri);
- // Reuse any IRI objects already created in Types
- return Types.get(result).orElse(result);
- }
-
- @Override
- public Literal createLiteral(final String literal) {
- return new LiteralImpl(literal);
- }
-
- @Override
- public Literal createLiteral(final String literal, final IRI dataType) {
- return new LiteralImpl(literal, dataType);
- }
-
- @Override
- public Literal createLiteral(final String literal, final String language) {
- return new LiteralImpl(literal, language);
- }
-
- @Override
- public Triple createTriple(final BlankNodeOrIRI subject, final IRI predicate, final RDFTerm object) {
- return new TripleImpl(subject, predicate, object);
- }
-
- @Override
- public Quad createQuad(final BlankNodeOrIRI graphName, final BlankNodeOrIRI subject, final IRI predicate, final RDFTerm object)
- throws IllegalArgumentException {
- return new QuadImpl(graphName, subject, predicate, object);
- }
-}
http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/d59203ce/simple/src/main/java/org/apache/commons/rdf/simple/SimpleRDFTermFactory.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/SimpleRDFTermFactory.java b/simple/src/main/java/org/apache/commons/rdf/simple/SimpleRDFTermFactory.java
deleted file mode 100644
index 676f284..0000000
--- a/simple/src/main/java/org/apache/commons/rdf/simple/SimpleRDFTermFactory.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.rdf.simple;
-
-import org.apache.commons.rdf.api.BlankNode;
-import org.apache.commons.rdf.api.BlankNodeOrIRI;
-import org.apache.commons.rdf.api.Graph;
-import org.apache.commons.rdf.api.IRI;
-import org.apache.commons.rdf.api.Literal;
-import org.apache.commons.rdf.api.RDFTerm;
-import org.apache.commons.rdf.api.RDFTermFactory;
-import org.apache.commons.rdf.api.Triple;
-
-/**
- * A Simple implementation of {@link RDFTermFactory}
- * <p>
- * This class is <strong>deprecated</strong>, use instead {@link SimpleRDF}.
- */
-@Deprecated
-public class SimpleRDFTermFactory implements RDFTermFactory {
-
- private final SimpleRDF factory = new SimpleRDF();
-
- @Override
- public BlankNode createBlankNode() {
- return factory.createBlankNode();
- }
-
- @Override
- public BlankNode createBlankNode(final String name) {
- return factory.createBlankNode(name);
- }
-
- @Override
- public Graph createGraph() {
- return factory.createGraph();
- }
-
- @Override
- public IRI createIRI(final String iri) {
- return factory.createIRI(iri);
- }
-
- @Override
- public Literal createLiteral(final String literal) {
- return factory.createLiteral(literal);
- }
-
- @Override
- public Literal createLiteral(final String literal, final IRI dataType) {
- return factory.createLiteral(literal, dataType);
- }
-
- @Override
- public Literal createLiteral(final String literal, final String language) {
- return factory.createLiteral(literal, language);
- }
-
- @Override
- public Triple createTriple(final BlankNodeOrIRI subject, final IRI predicate, final RDFTerm object) {
- return factory.createTriple(subject, predicate, object);
- }
-}
http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/d59203ce/simple/src/main/java/org/apache/commons/rdf/simple/TripleImpl.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/TripleImpl.java b/simple/src/main/java/org/apache/commons/rdf/simple/TripleImpl.java
deleted file mode 100644
index ef527ce..0000000
--- a/simple/src/main/java/org/apache/commons/rdf/simple/TripleImpl.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.rdf.simple;
-
-import org.apache.commons.rdf.api.BlankNodeOrIRI;
-import org.apache.commons.rdf.api.IRI;
-import org.apache.commons.rdf.api.RDFTerm;
-import org.apache.commons.rdf.api.Triple;
-
-import java.util.Objects;
-
-/**
- * A simple implementation of Triple.
- */
-final class TripleImpl implements Triple {
-
- private final BlankNodeOrIRI subject;
- private final IRI predicate;
- private final RDFTerm object;
-
- /**
- * Construct Triple from its constituent parts.
- * <p>
- * The objects are not changed. All mapping of BNode objects is done in
- * {@link SimpleRDF#createTriple(BlankNodeOrIRI, IRI, RDFTerm)}.
- *
- * @param subject
- * subject of triple
- * @param predicate
- * predicate of triple
- * @param object
- * object of triple
- */
- public TripleImpl(final BlankNodeOrIRI subject, final IRI predicate, final RDFTerm object) {
- this.subject = Objects.requireNonNull(subject);
- this.predicate = Objects.requireNonNull(predicate);
- this.object = Objects.requireNonNull(object);
- }
-
- @Override
- public BlankNodeOrIRI getSubject() {
- return subject;
- }
-
- @Override
- public IRI getPredicate() {
- return predicate;
- }
-
- @Override
- public RDFTerm getObject() {
- return object;
- }
-
- @Override
- public String toString() {
- return getSubject().ntriplesString() + " " + getPredicate().ntriplesString() + " "
- + getObject().ntriplesString() + " .";
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(subject, predicate, object);
- }
-
- @Override
- public boolean equals(final Object obj) {
- if (!(obj instanceof Triple)) {
- return false;
- }
- final Triple other = (Triple) obj;
- return getSubject().equals(other.getSubject()) && getPredicate().equals(other.getPredicate())
- && getObject().equals(other.getObject());
- }
-
-}
http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/d59203ce/simple/src/main/java/org/apache/commons/rdf/simple/Types.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/Types.java b/simple/src/main/java/org/apache/commons/rdf/simple/Types.java
deleted file mode 100644
index 308de71..0000000
--- a/simple/src/main/java/org/apache/commons/rdf/simple/Types.java
+++ /dev/null
@@ -1,350 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.rdf.simple;
-
-import org.apache.commons.rdf.api.IRI;
-
-import java.util.Collections;
-import java.util.LinkedHashSet;
-import java.util.Optional;
-import java.util.Set;
-
-/**
- * Types from the RDF and XML Schema vocabularies.
- */
-public final class Types implements IRI, SimpleRDF.SimpleRDFTerm {
-
- /**
- * <tt>http://www.w3.org/1999/02/22-rdf-syntax-ns#HTML</tt>
- */
- public static final Types RDF_HTML = new Types("http://www.w3.org/1999/02/22-rdf-syntax-ns#HTML");
-
- /**
- * <tt>http://www.w3.org/1999/02/22-rdf-syntax-ns#langString</tt>
- */
- public static final Types RDF_LANGSTRING = new Types("http://www.w3.org/1999/02/22-rdf-syntax-ns#langString");
-
- /**
- * <tt>http://www.w3.org/1999/02/22-rdf-syntax-ns#PlainLiteral</tt>
- *
- * @deprecated Not used in RDF-1.1
- */
- @Deprecated
- public static final Types RDF_PLAINLITERAL = new Types("http://www.w3.org/1999/02/22-rdf-syntax-ns#PlainLiteral");
-
- /**
- * <tt>http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral</tt>
- */
- public static final Types RDF_XMLLITERAL = new Types("http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral");
-
- /**
- * <tt>http://www.w3.org/2001/XMLSchema#anyURI</tt>
- */
- public static final Types XSD_ANYURI = new Types("http://www.w3.org/2001/XMLSchema#anyURI");
-
- /**
- * <tt>http://www.w3.org/2001/XMLSchema#base64Binary</tt>
- */
- public static final Types XSD_BASE64BINARY = new Types("http://www.w3.org/2001/XMLSchema#base64Binary");
-
- /**
- * <tt>http://www.w3.org/2001/XMLSchema#boolean</tt>
- */
- public static final Types XSD_BOOLEAN = new Types("http://www.w3.org/2001/XMLSchema#boolean");
-
- /**
- * <tt>http://www.w3.org/2001/XMLSchema#byte</tt>
- */
- public static final Types XSD_BYTE = new Types("http://www.w3.org/2001/XMLSchema#byte");
-
- /**
- * <tt>http://www.w3.org/2001/XMLSchema#date</tt>
- */
- public static final Types XSD_DATE = new Types("http://www.w3.org/2001/XMLSchema#date");
-
- /**
- * <tt>http://www.w3.org/2001/XMLSchema#dateTime</tt>
- */
- public static final Types XSD_DATETIME = new Types("http://www.w3.org/2001/XMLSchema#dateTime");
-
- /**
- * <tt>http://www.w3.org/2001/XMLSchema#dayTimeDuration</tt>
- */
- public static final Types XSD_DAYTIMEDURATION = new Types("http://www.w3.org/2001/XMLSchema#dayTimeDuration");
-
- /**
- * <tt>http://www.w3.org/2001/XMLSchema#decimal</tt>
- */
- public static final Types XSD_DECIMAL = new Types("http://www.w3.org/2001/XMLSchema#decimal");
-
- /**
- * <tt>http://www.w3.org/2001/XMLSchema#double</tt>
- */
- public static final Types XSD_DOUBLE = new Types("http://www.w3.org/2001/XMLSchema#double");
-
- /**
- * <tt>http://www.w3.org/2001/XMLSchema#duration</tt>
- */
- public static final Types XSD_DURATION = new Types("http://www.w3.org/2001/XMLSchema#duration");
-
- /**
- * <tt>http://www.w3.org/2001/XMLSchema#float</tt>
- */
- public static final Types XSD_FLOAT = new Types("http://www.w3.org/2001/XMLSchema#float");
-
- /**
- * <tt>http://www.w3.org/2001/XMLSchema#gDay</tt>
- */
- public static final Types XSD_GDAY = new Types("http://www.w3.org/2001/XMLSchema#gDay");
-
- /**
- * <tt>http://www.w3.org/2001/XMLSchema#gMonth</tt>
- */
- public static final Types XSD_GMONTH = new Types("http://www.w3.org/2001/XMLSchema#gMonth");
-
- /**
- * <tt>http://www.w3.org/2001/XMLSchema#gMonthDay</tt>
- */
- public static final Types XSD_GMONTHDAY = new Types("http://www.w3.org/2001/XMLSchema#gMonthDay");
-
- /**
- * <tt>http://www.w3.org/2001/XMLSchema#gYear</tt>
- */
- public static final Types XSD_GYEAR = new Types("http://www.w3.org/2001/XMLSchema#gYear");
-
- /**
- * <tt>http://www.w3.org/2001/XMLSchema#gYearMonth</tt>
- */
- public static final Types XSD_GYEARMONTH = new Types("http://www.w3.org/2001/XMLSchema#gYearMonth");
-
- /**
- * <tt>http://www.w3.org/2001/XMLSchema#hexBinary</tt>
- */
- public static final Types XSD_HEXBINARY = new Types("http://www.w3.org/2001/XMLSchema#hexBinary");
-
- /**
- * <tt>http://www.w3.org/2001/XMLSchema#int</tt>
- */
- public static final Types XSD_INT = new Types("http://www.w3.org/2001/XMLSchema#int");
-
- /**
- * <tt>http://www.w3.org/2001/XMLSchema#integer</tt>
- */
- public static final Types XSD_INTEGER = new Types("http://www.w3.org/2001/XMLSchema#integer");
-
- /**
- * <tt>http://www.w3.org/2001/XMLSchema#language</tt>
- */
- public static final Types XSD_LANGUAGE = new Types("http://www.w3.org/2001/XMLSchema#language");
-
- /**
- * <tt>http://www.w3.org/2001/XMLSchema#long</tt>
- */
- public static final Types XSD_LONG = new Types("http://www.w3.org/2001/XMLSchema#long");
-
- /**
- * <tt>http://www.w3.org/2001/XMLSchema#Name</tt>
- */
- public static final Types XSD_NAME = new Types("http://www.w3.org/2001/XMLSchema#Name");
-
- /**
- * <tt>http://www.w3.org/2001/XMLSchema#NCName</tt>
- */
- public static final Types XSD_NCNAME = new Types("http://www.w3.org/2001/XMLSchema#NCName");
-
- /**
- * <tt>http://www.w3.org/2001/XMLSchema#negativeInteger</tt>
- */
- public static final Types XSD_NEGATIVEINTEGER = new Types("http://www.w3.org/2001/XMLSchema#negativeInteger");
-
- /**
- * <tt>http://www.w3.org/2001/XMLSchema#NMTOKEN</tt>
- */
- public static final Types XSD_NMTOKEN = new Types("http://www.w3.org/2001/XMLSchema#NMTOKEN");
-
- /**
- * <tt>http://www.w3.org/2001/XMLSchema#nonNegativeInteger</tt>
- */
- public static final Types XSD_NONNEGATIVEINTEGER = new Types("http://www.w3.org/2001/XMLSchema#nonNegativeInteger");
-
- /**
- * <tt>http://www.w3.org/2001/XMLSchema#nonPositiveInteger</tt>
- */
- public static final Types XSD_NONPOSITIVEINTEGER = new Types("http://www.w3.org/2001/XMLSchema#nonPositiveInteger");
-
- /**
- * <tt>http://www.w3.org/2001/XMLSchema#normalizedString</tt>
- */
- public static final Types XSD_NORMALIZEDSTRING = new Types("http://www.w3.org/2001/XMLSchema#normalizedString");
-
- /**
- * <tt>http://www.w3.org/2001/XMLSchema#positiveInteger</tt>
- */
- public static final Types XSD_POSITIVEINTEGER = new Types("http://www.w3.org/2001/XMLSchema#positiveInteger");
-
- /**
- * <tt>http://www.w3.org/2001/XMLSchema#short</tt>
- */
- public static final Types XSD_SHORT = new Types("http://www.w3.org/2001/XMLSchema#short");
-
- /**
- * <tt>http://www.w3.org/2001/XMLSchema#string</tt>
- */
- public static final Types XSD_STRING = new Types("http://www.w3.org/2001/XMLSchema#string");
-
- /**
- * <tt>http://www.w3.org/2001/XMLSchema#time</tt>
- */
- public static final Types XSD_TIME = new Types("http://www.w3.org/2001/XMLSchema#time");
-
- /**
- * <tt>http://www.w3.org/2001/XMLSchema#token</tt>
- */
- public static final Types XSD_TOKEN = new Types("http://www.w3.org/2001/XMLSchema#token");
-
- /**
- * <tt>http://www.w3.org/2001/XMLSchema#unsignedByte</tt>
- */
- public static final Types XSD_UNSIGNEDBYTE = new Types("http://www.w3.org/2001/XMLSchema#unsignedByte");
-
- /**
- * <tt>http://www.w3.org/2001/XMLSchema#unsignedInt</tt>
- */
- public static final Types XSD_UNSIGNEDINT = new Types("http://www.w3.org/2001/XMLSchema#unsignedInt");
-
- /**
- * <tt>http://www.w3.org/2001/XMLSchema#unsignedLong</tt>
- */
- public static final Types XSD_UNSIGNEDLONG = new Types("http://www.w3.org/2001/XMLSchema#unsignedLong");
-
- /**
- * <tt>http://www.w3.org/2001/XMLSchema#unsignedShort</tt>
- */
- public static final Types XSD_UNSIGNEDSHORT = new Types("http://www.w3.org/2001/XMLSchema#unsignedShort");
-
- private static final Set<IRI> ALL_TYPES;
-
- static {
- final Set<IRI> tempTypes = new LinkedHashSet<>();
- tempTypes.add(RDF_HTML);
- tempTypes.add(RDF_LANGSTRING);
- tempTypes.add(RDF_PLAINLITERAL);
- tempTypes.add(RDF_XMLLITERAL);
- tempTypes.add(XSD_ANYURI);
- tempTypes.add(XSD_BASE64BINARY);
- tempTypes.add(XSD_BOOLEAN);
- tempTypes.add(XSD_BYTE);
- tempTypes.add(XSD_DATE);
- tempTypes.add(XSD_DATETIME);
- tempTypes.add(XSD_DAYTIMEDURATION);
- tempTypes.add(XSD_DECIMAL);
- tempTypes.add(XSD_DOUBLE);
- tempTypes.add(XSD_DURATION);
- tempTypes.add(XSD_FLOAT);
- tempTypes.add(XSD_GDAY);
- tempTypes.add(XSD_GMONTH);
- tempTypes.add(XSD_GMONTHDAY);
- tempTypes.add(XSD_GYEAR);
- tempTypes.add(XSD_GYEARMONTH);
- tempTypes.add(XSD_HEXBINARY);
- tempTypes.add(XSD_INT);
- tempTypes.add(XSD_INTEGER);
- tempTypes.add(XSD_LANGUAGE);
- tempTypes.add(XSD_LONG);
- tempTypes.add(XSD_NAME);
- tempTypes.add(XSD_NCNAME);
- tempTypes.add(XSD_NEGATIVEINTEGER);
- tempTypes.add(XSD_NMTOKEN);
- tempTypes.add(XSD_NONNEGATIVEINTEGER);
- tempTypes.add(XSD_NONPOSITIVEINTEGER);
- tempTypes.add(XSD_NORMALIZEDSTRING);
- tempTypes.add(XSD_POSITIVEINTEGER);
- tempTypes.add(XSD_SHORT);
- tempTypes.add(XSD_STRING);
- tempTypes.add(XSD_TIME);
- tempTypes.add(XSD_TOKEN);
- tempTypes.add(XSD_UNSIGNEDBYTE);
- tempTypes.add(XSD_UNSIGNEDINT);
- tempTypes.add(XSD_UNSIGNEDLONG);
- tempTypes.add(XSD_UNSIGNEDSHORT);
- ALL_TYPES = Collections.unmodifiableSet(tempTypes);
- }
-
- private final IRI field;
-
- private Types(final String field) {
- this.field = new IRIImpl(field);
- }
-
- @Override
- public String getIRIString() {
- return this.field.getIRIString();
- }
-
- @Override
- public String ntriplesString() {
- return this.field.ntriplesString();
- }
-
- @Override
- public boolean equals(final Object other) {
- return this.field.equals(other);
- }
-
- @Override
- public int hashCode() {
- return this.field.hashCode();
- }
-
- @Override
- public String toString() {
- return this.field.toString();
- }
-
- /**
- * Get an immutable set of the IRIs used by the RDF-1.1 specification to
- * define types, from the RDF and XML Schema vocabularies.
- *
- * @return A {@link Set} containing all of the IRIs in this collection.
- */
- public static Set<IRI> values() {
- return ALL_TYPES;
- }
-
- /**
- * Get the IRI from this collection if it is present, or return
- * {@link Optional#empty()} otherwise.
- *
- * @param nextIRI
- * The IRI to look for.
- * @return An {@link Optional} containing the IRI from this collection or
- * {@link Optional#empty()} if it is not present here.
- */
- public static Optional<IRI> get(final IRI nextIRI) {
- if (ALL_TYPES.contains(nextIRI)) {
- // If we know about this IRI, then look through our set to find the
- // object that matches and return it
- for (final IRI nextType : ALL_TYPES) {
- if (nextType.equals(nextIRI)) {
- return Optional.of(nextType);
- }
- }
- }
- return Optional.empty();
- }
-}
http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/d59203ce/simple/src/main/java/org/apache/commons/rdf/simple/experimental/AbstractRDFParser.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/experimental/AbstractRDFParser.java b/simple/src/main/java/org/apache/commons/rdf/simple/experimental/AbstractRDFParser.java
deleted file mode 100644
index a9af156..0000000
--- a/simple/src/main/java/org/apache/commons/rdf/simple/experimental/AbstractRDFParser.java
+++ /dev/null
@@ -1,571 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.rdf.simple.experimental;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URI;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.util.Optional;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
-import java.util.function.Consumer;
-
-import org.apache.commons.rdf.api.Dataset;
-import org.apache.commons.rdf.api.Graph;
-import org.apache.commons.rdf.api.IRI;
-import org.apache.commons.rdf.api.Quad;
-import org.apache.commons.rdf.api.RDFSyntax;
-import org.apache.commons.rdf.api.RDF;
-import org.apache.commons.rdf.experimental.RDFParser;
-import org.apache.commons.rdf.simple.SimpleRDF;
-
-/**
- * Abstract RDFParser
- * <p>
- * This abstract class keeps the properties in protected fields like
- * {@link #sourceFile} using {@link Optional}. Some basic checking like
- * {@link #checkIsAbsolute(IRI)} is performed.
- * <p>
- * This class and its subclasses are {@link Cloneable}, immutable and
- * (therefore) thread-safe - each call to option methods like
- * {@link #contentType(String)} or {@link #source(IRI)} will return a cloned,
- * mutated copy.
- * <p>
- * By default, parsing is done by the abstract method
- * {@link #parseSynchronusly()} - which is executed in a cloned snapshot - hence
- * multiple {@link #parse()} calls are thread-safe. The default {@link #parse()}
- * uses a thread pool in {@link #threadGroup} - but implementations can override
- * {@link #parse()} (e.g. because it has its own threading model or use
- * asynchronous remote execution).
- */
-public abstract class AbstractRDFParser<T extends AbstractRDFParser<T>> implements RDFParser, Cloneable {
-
- public static final ThreadGroup threadGroup = new ThreadGroup("Commons RDF parsers");
- private static final ExecutorService threadpool = Executors.newCachedThreadPool(r -> new Thread(threadGroup, r));
-
- // Basically only used for creating IRIs
- private static RDF internalRdfTermFactory = new SimpleRDF();
-
- /**
- * Get the set {@link RDF}, if any.
- *
- * @return The {@link RDF} to use, or {@link Optional#empty()} if it has not
- * been set
- */
- public Optional<RDF> getRdfTermFactory() {
- return rdfTermFactory;
- }
-
- /**
- * Get the set content-type {@link RDFSyntax}, if any.
- * <p>
- * If this is {@link Optional#isPresent()}, then {@link #getContentType()}
- * contains the value of {@link RDFSyntax#mediaType}.
- *
- * @return The {@link RDFSyntax} of the content type, or
- * {@link Optional#empty()} if it has not been set
- */
- public Optional<RDFSyntax> getContentTypeSyntax() {
- return contentTypeSyntax;
- }
-
- /**
- * Get the set content-type String, if any.
- * <p>
- * If this is {@link Optional#isPresent()} and is recognized by
- * {@link RDFSyntax#byMediaType(String)}, then the corresponding
- * {@link RDFSyntax} is set on {@link #getContentType()}, otherwise that is
- * {@link Optional#empty()}.
- *
- * @return The Content-Type IANA media type, e.g. <code>text/turtle</code>,
- * or {@link Optional#empty()} if it has not been set
- */
- public final Optional<String> getContentType() {
- return contentType;
- }
-
- /**
- * Get the target to consume parsed Quads.
- * <p>
- * From the call to {@link #parseSynchronusly()}, this will be a
- * non-<code>null</code> value (as a target is a required setting).
- *
- * @return The target consumer of {@link Quad}s, or <code>null</code> if it
- * has not yet been set.
- *
- */
- public Consumer<Quad> getTarget() {
- return target;
- }
-
- /**
- * Get the target dataset as set by {@link #target(Dataset)}.
- * <p>
- * The return value is {@link Optional#isPresent()} if and only if
- * {@link #target(Dataset)} has been set, meaning that the implementation
- * may choose to append parsed quads to the {@link Dataset} directly instead
- * of relying on the generated {@link #getTarget()} consumer.
- * <p>
- * If this value is present, then {@link #getTargetGraph()} MUST be
- * {@link Optional#empty()}.
- *
- * @return The target Dataset, or {@link Optional#empty()} if another kind
- * of target has been set.
- */
- public Optional<Dataset> getTargetDataset() {
- return targetDataset;
- }
-
- /**
- * Get the target graph as set by {@link #target(Graph)}.
- * <p>
- * The return value is {@link Optional#isPresent()} if and only if
- * {@link #target(Graph)} has been set, meaning that the implementation may
- * choose to append parsed triples to the {@link Graph} directly instead of
- * relying on the generated {@link #getTarget()} consumer.
- * <p>
- * If this value is present, then {@link #getTargetDataset()} MUST be
- * {@link Optional#empty()}.
- *
- * @return The target Graph, or {@link Optional#empty()} if another kind of
- * target has been set.
- */
- public Optional<Graph> getTargetGraph() {
- return targetGraph;
- }
-
- /**
- * Get the set base {@link IRI}, if present.
- *
- * @return The base {@link IRI}, or {@link Optional#empty()} if it has not
- * been set
- */
- public Optional<IRI> getBase() {
- return base;
- }
-
- /**
- * Get the set source {@link InputStream}.
- * <p>
- * If this is {@link Optional#isPresent()}, then {@link #getSourceFile()}
- * and {@link #getSourceIri()} are {@link Optional#empty()}.
- *
- * @return The source {@link InputStream}, or {@link Optional#empty()} if it
- * has not been set
- */
- public Optional<InputStream> getSourceInputStream() {
- return sourceInputStream;
- }
-
- /**
- * Get the set source {@link Path}.
- * <p>
- * If this is {@link Optional#isPresent()}, then
- * {@link #getSourceInputStream()} and {@link #getSourceIri()} are
- * {@link Optional#empty()}.
- *
- * @return The source {@link Path}, or {@link Optional#empty()} if it has
- * not been set
- */
- public Optional<Path> getSourceFile() {
- return sourceFile;
- }
-
- /**
- * Get the set source {@link Path}.
- * <p>
- * If this is {@link Optional#isPresent()}, then
- * {@link #getSourceInputStream()} and {@link #getSourceInputStream()} are
- * {@link Optional#empty()}.
- *
- * @return The source {@link IRI}, or {@link Optional#empty()} if it has not
- * been set
- */
- public Optional<IRI> getSourceIri() {
- return sourceIri;
- }
-
- private Optional<RDF> rdfTermFactory = Optional.empty();
- private Optional<RDFSyntax> contentTypeSyntax = Optional.empty();
- private Optional<String> contentType = Optional.empty();
- private Optional<IRI> base = Optional.empty();
- private Optional<InputStream> sourceInputStream = Optional.empty();
- private Optional<Path> sourceFile = Optional.empty();
- private Optional<IRI> sourceIri = Optional.empty();
- private Consumer<Quad> target;
- private Optional<Dataset> targetDataset;
- private Optional<Graph> targetGraph;
-
- @SuppressWarnings("unchecked")
- @Override
- public T clone() {
- try {
- return (T) super.clone();
- } catch (final CloneNotSupportedException e) {
- throw new RuntimeException(e);
- }
- }
-
- @SuppressWarnings("unchecked")
- protected T asT() {
- return (T) this;
- }
-
- @Override
- public T rdfTermFactory(final RDF rdfTermFactory) {
- final AbstractRDFParser<T> c = clone();
- c.rdfTermFactory = Optional.ofNullable(rdfTermFactory);
- return c.asT();
- }
-
- @Override
- public T contentType(final RDFSyntax rdfSyntax) throws IllegalArgumentException {
- final AbstractRDFParser<T> c = clone();
- c.contentTypeSyntax = Optional.ofNullable(rdfSyntax);
- c.contentType = c.contentTypeSyntax.map(syntax -> syntax.mediaType());
- return c.asT();
- }
-
- @Override
- public T contentType(final String contentType) throws IllegalArgumentException {
- final AbstractRDFParser<T> c = clone();
- c.contentType = Optional.ofNullable(contentType);
- c.contentTypeSyntax = c.contentType.flatMap(RDFSyntax::byMediaType);
- return c.asT();
- }
-
- @Override
- public T base(final IRI base) {
- final AbstractRDFParser<T> c = clone();
- c.base = Optional.ofNullable(base);
- c.base.ifPresent(i -> checkIsAbsolute(i));
- return c.asT();
- }
-
- @Override
- public T base(final String base) throws IllegalArgumentException {
- return base(internalRdfTermFactory.createIRI(base));
- }
-
- @Override
- public T source(final InputStream inputStream) {
- final AbstractRDFParser<T> c = clone();
- c.resetSource();
- c.sourceInputStream = Optional.ofNullable(inputStream);
- return c.asT();
- }
-
- @Override
- public T source(final Path file) {
- final AbstractRDFParser<T> c = clone();
- c.resetSource();
- c.sourceFile = Optional.ofNullable(file);
- return c.asT();
- }
-
- @Override
- public T source(final IRI iri) {
- final AbstractRDFParser<T> c = clone();
- c.resetSource();
- c.sourceIri = Optional.ofNullable(iri);
- c.sourceIri.ifPresent(i -> checkIsAbsolute(i));
- return c.asT();
- }
-
- @Override
- public T source(final String iri) throws IllegalArgumentException {
- final AbstractRDFParser<T> c = clone();
- c.resetSource();
- c.sourceIri = Optional.ofNullable(iri).map(internalRdfTermFactory::createIRI);
- c.sourceIri.ifPresent(i -> checkIsAbsolute(i));
- return source(internalRdfTermFactory.createIRI(iri));
- }
-
- /**
- * Check if an iri is absolute.
- * <p>
- * Used by {@link #source(String)} and {@link #base(String)}.
- *
- * @param iri
- * IRI to check
- * @throws IllegalArgumentException
- * If the IRI is not absolute
- */
- protected void checkIsAbsolute(final IRI iri) throws IllegalArgumentException {
- if (!URI.create(iri.getIRIString()).isAbsolute()) {
- throw new IllegalArgumentException("IRI is not absolute: " + iri);
- }
- }
-
- /**
- * Check that one and only one source is present and valid.
- * <p>
- * Used by {@link #parse()}.
- * <p>
- * Subclasses might override this method, e.g. to support other source
- * combinations, or to check if the sourceIri is resolvable.
- *
- * @throws IOException
- * If a source file can't be read
- */
- protected void checkSource() throws IOException {
- if (!sourceFile.isPresent() && !sourceInputStream.isPresent() && !sourceIri.isPresent()) {
- throw new IllegalStateException("No source has been set");
- }
- if (sourceIri.isPresent() && sourceInputStream.isPresent()) {
- throw new IllegalStateException("Both sourceIri and sourceInputStream have been set");
- }
- if (sourceIri.isPresent() && sourceFile.isPresent()) {
- throw new IllegalStateException("Both sourceIri and sourceFile have been set");
- }
- if (sourceInputStream.isPresent() && sourceFile.isPresent()) {
- throw new IllegalStateException("Both sourceInputStream and sourceFile have been set");
- }
- if (sourceFile.isPresent() && !sourceFile.filter(Files::isReadable).isPresent()) {
- throw new IOException("Can't read file: " + sourceFile);
- }
- }
-
- /**
- * Check if base is required.
- *
- * @throws IllegalStateException
- * if base is required, but not set.
- */
- protected void checkBaseRequired() throws IllegalStateException {
- if (!base.isPresent() && sourceInputStream.isPresent()
- && !contentTypeSyntax.filter(t -> t == RDFSyntax.NQUADS || t == RDFSyntax.NTRIPLES).isPresent()) {
- throw new IllegalStateException("base iri required for inputstream source");
- }
- }
-
- /**
- * Reset all source* fields to Optional.empty()
- * <p>
- * Subclasses should override this and call <code>super.resetSource()</code>
- * if they need to reset any additional source* fields.
- *
- */
- protected void resetSource() {
- sourceInputStream = Optional.empty();
- sourceIri = Optional.empty();
- sourceFile = Optional.empty();
- }
-
- /**
- * Reset all optional target* fields to {@link Optional#empty()}.
- * <p>
- * Note that the consumer set for {@link #getTarget()} is
- * <strong>note</strong> reset.
- * <p>
- * Subclasses should override this and call <code>super.resetTarget()</code>
- * if they need to reset any additional target* fields.
- *
- */
- protected void resetTarget() {
- targetDataset = Optional.empty();
- targetGraph = Optional.empty();
- }
-
- /**
- * Parse {@link #sourceInputStream}, {@link #sourceFile} or
- * {@link #sourceIri}.
- * <p>
- * One of the source fields MUST be present, as checked by
- * {@link #checkSource()}.
- * <p>
- * {@link #checkBaseRequired()} is called to verify if {@link #getBase()} is
- * required.
- *
- * @throws IOException
- * If the source could not be read
- * @throws RDFParseException
- * If the source could not be parsed (e.g. a .ttl file was not
- * valid Turtle)
- */
- protected abstract void parseSynchronusly() throws IOException, RDFParseException;
-
- /**
- * Prepare a clone of this RDFParser which have been checked and completed.
- * <p>
- * The returned clone will always have {@link #getTarget()} and
- * {@link #getRdfTermFactory()} present.
- * <p>
- * If the {@link #getSourceFile()} is present, but the {@link #getBase()} is
- * not present, the base will be set to the <code>file:///</code> IRI for
- * the Path's real path (e.g. resolving any symbolic links).
- *
- * @return A completed and checked clone of this RDFParser
- * @throws IOException
- * If the source was not accessible (e.g. a file was not found)
- * @throws IllegalStateException
- * If the parser was not in a compatible setting (e.g.
- * contentType was an invalid string)
- */
- protected T prepareForParsing() throws IOException, IllegalStateException {
- checkSource();
- checkBaseRequired();
- checkContentType();
- checkTarget();
-
- // We'll make a clone of our current state which will be passed to
- // parseSynchronously()
- final AbstractRDFParser<T> c = clone();
-
- // Use a fresh SimpleRDF for each parse
- if (!c.rdfTermFactory.isPresent()) {
- c.rdfTermFactory = Optional.of(createRDFTermFactory());
- }
- // sourceFile, but no base? Let's follow any symlinks and use
- // the file:/// URI
- if (c.sourceFile.isPresent() && !c.base.isPresent()) {
- final URI baseUri = c.sourceFile.get().toRealPath().toUri();
- c.base = Optional.of(internalRdfTermFactory.createIRI(baseUri.toString()));
- }
-
- return c.asT();
- }
-
- /**
- * Subclasses can override this method to check the target is valid.
- * <p>
- * The default implementation throws an IllegalStateException if the target
- * has not been set.
- */
- protected void checkTarget() {
- if (target == null) {
- throw new IllegalStateException("target has not been set");
- }
- if (targetGraph.isPresent() && targetDataset.isPresent()) {
- // This should not happen as each target(..) method resets the
- // optionals
- throw new IllegalStateException("targetGraph and targetDataset can't both be set");
- }
- }
-
- /**
- * Subclasses can override this method to check compatibility with the
- * contentType setting.
- *
- * @throws IllegalStateException
- * if the {@link #getContentType()} or
- * {@link #getContentTypeSyntax()} is not compatible or invalid
- */
- protected void checkContentType() throws IllegalStateException {
- }
-
- /**
- * Guess RDFSyntax from a local file's extension.
- * <p>
- * This method can be used by subclasses if {@link #getContentType()} is not
- * present and {@link #getSourceFile()} is set.
- *
- * @param path
- * Path which extension should be checked
- * @return The {@link RDFSyntax} which has a matching
- * {@link RDFSyntax#fileExtension}, otherwise
- * {@link Optional#empty()}.
- */
- protected static Optional<RDFSyntax> guessRDFSyntax(final Path path) {
- return fileExtension(path).flatMap(RDFSyntax::byFileExtension);
- }
-
- /**
- * Return the file extension of a Path - if any.
- * <p>
- * The returned file extension includes the leading <code>.</code>
- * <p>
- * Note that this only returns the last extension, e.g. the file extension
- * for <code>archive.tar.gz</code> would be <code>.gz</code>
- *
- * @param path
- * Path which filename might contain an extension
- * @return File extension (including the leading <code>.</code>, or
- * {@link Optional#empty()} if the path has no extension
- */
- private static Optional<String> fileExtension(final Path path) {
- final Path fileName = path.getFileName();
- if (fileName == null) {
- return Optional.empty();
- }
- final String filenameStr = fileName.toString();
- final int last = filenameStr.lastIndexOf(".");
- if (last > -1) {
- return Optional.of(filenameStr.substring(last));
- }
- return Optional.empty();
- }
-
- /**
- * Create a new {@link RDF} for a parse session.
- * <p>
- * This is called by {@link #parse()} to set {@link #rdfTermFactory(RDF)} if
- * it is {@link Optional#empty()}.
- * <p>
- * As parsed blank nodes might be made with
- * {@link RDF#createBlankNode(String)}, each call to this method SHOULD
- * return a new RDF instance.
- *
- * @return A new {@link RDF}
- */
- protected RDF createRDFTermFactory() {
- return new SimpleRDF();
- }
-
- @Override
- public Future<ParseResult> parse() throws IOException, IllegalStateException {
- final AbstractRDFParser<T> c = prepareForParsing();
- return threadpool.submit(() -> {
- c.parseSynchronusly();
- return null;
- });
- }
-
- @Override
- public T target(final Consumer<Quad> consumer) {
- final AbstractRDFParser<T> c = clone();
- c.resetTarget();
- c.target = consumer;
- return c.asT();
- }
-
- @Override
- public T target(final Dataset dataset) {
- @SuppressWarnings({ "rawtypes", "unchecked" })
- final
- AbstractRDFParser<T> c = (AbstractRDFParser) RDFParser.super.target(dataset);
- c.resetTarget();
- c.targetDataset = Optional.of(dataset);
- return c.asT();
- }
-
- @Override
- public T target(final Graph graph) {
- @SuppressWarnings({ "rawtypes", "unchecked" }) // super calls our
- final
- // .clone()
- AbstractRDFParser<T> c = (AbstractRDFParser) RDFParser.super.target(graph);
- c.resetTarget();
- c.targetGraph = Optional.of(graph);
- return c.asT();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/d59203ce/simple/src/main/java/org/apache/commons/rdf/simple/experimental/RDFParseException.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/experimental/RDFParseException.java b/simple/src/main/java/org/apache/commons/rdf/simple/experimental/RDFParseException.java
deleted file mode 100644
index 16bdbc9..0000000
--- a/simple/src/main/java/org/apache/commons/rdf/simple/experimental/RDFParseException.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.rdf.simple.experimental;
-
-import org.apache.commons.rdf.experimental.RDFParser;
-
-public class RDFParseException extends Exception {
- private static final long serialVersionUID = 5427752643780702976L;
- private final RDFParser builder;
-
- public RDFParseException(final RDFParser builder) {
- super();
- this.builder = builder;
- }
-
- public RDFParseException(final RDFParser builder, final String message, final Throwable cause) {
- super(message, cause);
- this.builder = builder;
- }
-
- public RDFParseException(final RDFParser builder, final String message) {
- super(message);
- this.builder = builder;
- }
-
- public RDFParseException(final RDFParser builder, final Throwable cause) {
- super(cause);
- this.builder = builder;
- }
-
- public RDFParser getRDFParserBuilder() {
- return builder;
- }
-}
\ No newline at end of file