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/10/07 15:01:26 UTC

[23/50] incubator-commonsrdf git commit: added asRDFTermGraph(Repository, Set<>

added asRDFTermGraph(Repository, Set<>

.. and remove the array arguments as it becomes tricky with
null.


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

Branch: refs/heads/master
Commit: 69814ee5ae3f2393aa4fa14ea192ce3e06068f0d
Parents: f0bdb07
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Mon Oct 3 18:32:57 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Mon Oct 3 18:32:57 2016 +0100

----------------------------------------------------------------------
 .../commons/rdf/rdf4j/RDF4JTermFactory.java     | 25 ++++++++++----------
 1 file changed, 13 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/69814ee5/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JTermFactory.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JTermFactory.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JTermFactory.java
index a844a1a..54edaa7 100644
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JTermFactory.java
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JTermFactory.java
@@ -17,9 +17,9 @@
  */
 package org.apache.commons.rdf.rdf4j;
 
-import java.util.Arrays;
+import java.util.Objects;
+import java.util.Set;
 import java.util.UUID;
-import java.util.stream.Collectors;
 
 // To avoid confusion, avoid importing
 // classes that are in both
@@ -325,19 +325,20 @@ public class RDF4JTermFactory implements RDFTermFactory {
 	 * @param repository
 	 *            RDF4J {@link Repository} to connect to.
 	 * @param contexts
+	 *            A {@link Set} of {@link BlankNodeOrIRI} specifying the
+	 *            graph names to use as a context. The set may include the value
+	 *            <code>null</code> to indicate the default graph. The empty set
+	 *            indicates any context, e.g. the <em>union graph</em>.
 	 * 
 	 * @return A {@link Graph} backed by the RDF4J repository.
 	 */
-	public RDF4JGraph asRDFTermGraph(Repository repository, BlankNodeOrIRI... contexts) {
-		if (contexts.length == 0) {
-			throw new IllegalArgumentException("At least one context must be specified. Use asRDFTermGraphUnion for union graph.");
-		}
-		Resource[] resources = new Resource[contexts.length];
-		for (int i=0; i<contexts.length; i++) {
-			resources[i] = (Resource) asValue(contexts[i]);
-		}
-		return new RepositoryGraphImpl(repository, false, true, resources);
-	}	
+	public RDF4JGraph asRDFTermGraph(Repository repository, Set<? extends BlankNodeOrIRI> contexts) {	
+		/** NOTE: asValue() deliberately CAN handle <code>null</code> */
+		Resource[] resources = contexts.stream()
+				.map(g -> (Resource) asValue(g)).toArray(Resource[]::new);
+		return new RepositoryGraphImpl(Objects.requireNonNull(repository), 
+				false, true, resources);		
+	}
 	
 	/**
 	 * Adapt an RDF4J {@link Repository} as a Commons RDF {@link Graph}.