commonsrdf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject [3/3] incubator-commonsrdf git commit: more streams..
Date Mon, 04 Apr 2016 13:53:16 GMT
more streams..


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

Branch: refs/heads/jsonld-java
Commit: db9fd76676a17479882cd8d869d44a12df486a28
Parents: da9090a
Author: Stian Soiland-Reyes <stain@apache.org>
Authored: Mon Apr 4 12:02:18 2016 +0100
Committer: Stian Soiland-Reyes <stain@apache.org>
Committed: Mon Apr 4 12:02:18 2016 +0100

----------------------------------------------------------------------
 .../commons/rdf/jsonldjava/JsonLDGraph.java     | 33 ++++++++++++++++----
 .../commons/rdf/jsonldjava/JsonLDGraphTest.java |  1 +
 2 files changed, 28 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/db9fd766/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLDGraph.java
----------------------------------------------------------------------
diff --git a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLDGraph.java
b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLDGraph.java
index 41691ba..ef117b7 100644
--- a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLDGraph.java
+++ b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLDGraph.java
@@ -19,6 +19,7 @@ package org.apache.commons.rdf.jsonldjava;
 
 import java.util.Iterator;
 import java.util.List;
+import java.util.Optional;
 import java.util.UUID;
 import java.util.function.Predicate;
 import java.util.stream.Collectors;
@@ -222,12 +223,32 @@ public class JsonLDGraph implements Graph {
 	}
 
 	@Override
-	public void remove(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
-		// rdfDataSet has no remove method - so we'll have to remove them
-		// from the inner Lists' iterator					
-		for (Iterator<? extends Triple> it = getTriples(subject, predicate, object).iterator()
;; it.hasNext()) {
-			it.remove();
-		}		
+	public void remove(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {		
+		Predicate<? super Quad> filter = quadFilter(subject, predicate, object);
+		if (! unionGraph) {
+			rdfDataSet.getQuads("@default").removeIf(filter);
+		} else {
+			rdfDataSet.graphNames().parallelStream().map(rdfDataSet::getQuads).map(t -> t.removeIf(filter));
+		}
+	}
+
+	private Predicate<? super Quad> quadFilter(BlankNodeOrIRI subject, IRI predicate,
RDFTerm object) {
+		Optional<Node> subjectNode = Optional.ofNullable(subject).map(this::asJsonLdNode);
+		Optional<Node> predicateNode = Optional.ofNullable(predicate).map(this::asJsonLdNode);
+		Optional<Node> objectNode = Optional.ofNullable(object).map(this::asJsonLdNode);
+		
+		return q -> {
+		    if (subjectNode.isPresent() && subjectNode.get().compareTo(q.getSubject())
== 0) {
+		        return false;
+		    }
+		    if (predicateNode.isPresent() && predicateNode.get().compareTo(q.getPredicate())
== 0) {	          
+		        return false;
+		    }
+		    if (objectNode.isPresent() && objectNode.get().compareTo(q.getObject()) ==
0) {
+		        return false;
+		    }
+		    return true;			
+		};
 	}
 
 	@Override

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/db9fd766/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLDGraphTest.java
----------------------------------------------------------------------
diff --git a/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLDGraphTest.java
b/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLDGraphTest.java
index 461cd24..3aa0d91 100644
--- a/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLDGraphTest.java
+++ b/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLDGraphTest.java
@@ -33,5 +33,6 @@ public class JsonLDGraphTest extends AbstractGraphTest {
 			}
 		};
 	}
+	
 
 }


Mime
View raw message