You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commonsrdf.apache.org by st...@apache.org on 2016/06/20 08:58:43 UTC
[49/50] incubator-commonsrdf git commit: Merge branch
'parser-writer-interface' into parser-with-quads
Merge branch 'parser-writer-interface' into parser-with-quads
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/953e9b89
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/953e9b89
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/953e9b89
Branch: refs/heads/parser-with-quads
Commit: 953e9b8915fd7d42f8beac6fac8cabc39d5351e1
Parents: 7c69d4f c0700de
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Mon Jun 20 09:52:59 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Mon Jun 20 09:52:59 2016 +0100
----------------------------------------------------------------------
api/src/main/java/org/apache/commons/rdf/api/RDFParserBuilder.java | 2 ++
1 file changed, 2 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/953e9b89/api/src/main/java/org/apache/commons/rdf/api/RDFParserBuilder.java
----------------------------------------------------------------------
diff --cc api/src/main/java/org/apache/commons/rdf/api/RDFParserBuilder.java
index 0494502,b387406..5e8ee33
--- a/api/src/main/java/org/apache/commons/rdf/api/RDFParserBuilder.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/RDFParserBuilder.java
@@@ -183,71 -166,13 +183,73 @@@ public interface RDFParserBuilder
* @return An {@link RDFParserBuilder} that will insert triples into the
* specified graph.
*/
- default RDFParserBuilder target(Graph graph) {
- return target(graph::add);
+ default RDFParserBuilder target(Graph graph) {
+ return target(q -> {
+ if (! q.getGraphName().isPresent()) {
+ graph.add(q.asTriple());
+ }
+ });
}
+ RDFParserBuilder target(Consumer<Triple> tripleConsumer);
+
/**
+ * Specify a {@link Dataset} to add parsed quads to.
+ * <p>
+ * It is undefined if any quads are added to the specified
+ * {@link Dataset} if {@link #parse()} throws any exceptions.
+ * (However implementations are free to prevent this using transaction
+ * mechanisms or similar). On the other hand, if {@link #parse()}
+ * does not indicate an exception, the
+ * implementation SHOULD have inserted all parsed quads
+ * to the specified dataset.
+ * <p>
+ * Calling this method will override any earlier targets set with
+ * {@link #target(Graph)}, {@link #target(Consumer)} or {@link #target(Dataset)}.
+ * <p>
+ * The default implementation of this method calls {@link #target(Consumer)}
+ * with a {@link Consumer} that does {@link Dataset#add(Quad)}.
+ *
+ * @param dataset
+ * The {@link Dataset} to add quads to.
+ * @return An {@link RDFParserBuilder} that will insert triples into the
+ * specified dataset.
+ */
+ default RDFParserBuilder target(Dataset dataset) {
+ return target(dataset::add);
+ }
+
+ /**
+ * Specify a consumer for parsed quads.
+ * <p>
+ * It is undefined if any quads are consumed if {@link #parse()} throws any
+ * exceptions. On the other hand, if {@link #parse()} does not indicate an
+ * exception, the implementation SHOULD have produced all parsed quads to
+ * the specified consumer.
+ * <p>
+ * Calling this method will override any earlier targets set with
+ * {@link #target(Graph)}, {@link #target(Consumer)} or
+ * {@link #target(Dataset)}.
+ * <p>
+ * The consumer is not assumed to be thread safe - only one
+ * {@link Consumer#accept(Object)} is delivered at a time for a given
+ * {@link RDFParserBuilder#parse()} call.
+ * <p>
+ * This method is typically called with a functional consumer, for example:
+ * <pre>
+ * List<Quad> quads = new ArrayList<Quad>;
+ * parserBuilder.target(quads::add).parse();
+ * </pre>
+ *
+ * @param consumer
+ * A {@link Consumer} of {@link Quad}s
+ * @return An {@link RDFParserBuilder} that will call the consumer for into
+ * the specified dataset.
+ * @return
+ */
+ RDFParserBuilder target(Consumer<Quad> consumer);
+
+ /**
* Specify a base IRI to use for parsing any relative IRI references.
* <p>
* Setting this option will override any protocol-specific base IRI (e.g.