commonsrdf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject [3/5] incubator-commonsrdf git commit: about graphName() Optional
Date Tue, 18 Oct 2016 11:36:43 GMT
about graphName() Optional


Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/86a3b518
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/86a3b518
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/86a3b518

Branch: refs/heads/master
Commit: 86a3b518e68a4dbcecfc986410969886ad3e81a9
Parents: 7fec838
Author: Stian Soiland-Reyes <stain@apache.org>
Authored: Tue Oct 18 10:44:18 2016 +0100
Committer: Stian Soiland-Reyes <stain@apache.org>
Committed: Tue Oct 18 10:44:18 2016 +0100

----------------------------------------------------------------------
 src/site/markdown/userguide.md | 44 ++++++++++++++++++++++++++++++++-----
 1 file changed, 38 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/86a3b518/src/site/markdown/userguide.md
----------------------------------------------------------------------
diff --git a/src/site/markdown/userguide.md b/src/site/markdown/userguide.md
index 08d977b..f1da36b 100644
--- a/src/site/markdown/userguide.md
+++ b/src/site/markdown/userguide.md
@@ -48,6 +48,8 @@ Commons RDF [API](apidocs/).
     * [Iterating over triples](#Iterating_over_triples)
     * [Stream of triples](#Stream_of_triples)
     * [Removing triples](#Removing_triples)
+* [Dataset](#Dataset)
+    * [Dataset operations](#Dataset_operations)
 * [Mutability and thread safety](#Mutability_and_thread_safety)
 * [Implementations](#Implementations)
     * [Cross-compatibility](#Cross-compatibility)
@@ -711,10 +713,12 @@ Quad quad = factory.createQuad(graph, subject, predicate, object);
 The subject, predicate and object are accessible just like in a `Triple`:
 
 ```
-BlankNodeOrIRI subj = quad.getSubject();
-System.out.println(subj.ntriplesString());
+IRI pred = quad.getPredicate();
+System.out.println(pred.ntriplesString());
 ```
 
+> `<http://example.com/says>`
+
 ### Graph name
 
 In addition the _graph name_ is accessible using
@@ -722,21 +726,49 @@ In addition the _graph name_ is accessible using
 
 ```
 Optional<BlankNodeOrIRI> g = quad.getGraphName();
+```
+
+The graph name is represented as an [Optional](https://docs.oracle.com/javase/8/docs/api/java/util/Optional.html),
+where `Optional.empty()` indicates that the quad is in the [default graph](https://www.w3.org/TR/rdf11-concepts/#dfn-default-graph),
while
+if the [Optional.isPresent()](https://docs.oracle.com/javase/8/docs/api/java/util/Optional.html#isPresent--)
then the
+graph name `BlankNodeOrIRI` is accessible with `g.get()`:
+
+```
 if (g.isPresent()) {
-  System.out.println(g.get().ntriplesString());
+  BlankNodeOrIRI graphName = g.get();
+  System.out.println(graphName.ntriplesString());
 }
 ```
 
-The graph name is represented as an [Optional](https://docs.oracle.com/javase/8/docs/api/java/util/Optional.html?is-external=true),
where `Optional.empty()` indicates that the quad is in the [default graph](https://www.w3.org/TR/rdf11-concepts/#dfn-default-graph),
or
-`g.get()` retrieves the `BlankNodeOrIRI`.
+> `<http://example.com/graph>`
+
 
-To create a quad in the default graph, supply `null` as the graph name
+
+To create a quad in the _default graph_, supply `null` as the graph name
 to the factory method:
 
 ```
 Quad otherQuad = factory.createQuad(null, subject, predicate, object);
+System.out.println(otherQuad.getGraphName().isPresent());
 ```
 
+> `false`
+
+Note that a `Quad` will never return `null` on any of its getters, which is why
+the graph name is wrapped as an `Optional`. This also allows the use of
+Java 8 functional programming patterns like:
+
+```
+String str = quad.map(BlankNodeOrIRI::ntriplesString).orElse("");
+```
+
+
+Care should be taken with regards when accessing
+graph named with `BlankNode`s,
+as the graph name will be compared using
+[BlankNode's equality semantics](apidocs/org/apache/commons/rdf/api/BlankNode.html#equals-java.lang.Object-).
+
+
 ### Quad equality
 
 A `Quad` is considered


Mime
View raw message