commonsrdf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ans...@apache.org
Subject [11/18] incubator-commonsrdf git commit: Remove getTriples(Predicate) as it doesn't support mapping
Date Mon, 30 Mar 2015 01:10:05 GMT
Remove getTriples(Predicate) as it doesn't support mapping

Also, map the values sent into GraphImpl.getTriples(...) and do not map
BlankNodeImpl objects, as we know they are universally unique locally ,
based on the factory they were created with, without mapping

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

Branch: refs/heads/master
Commit: a8ff114197bc706ba67d4d8e00a0a0ec347d0180
Parents: 75bca62
Author: Peter Ansell <p_ansell@yahoo.com>
Authored: Sat Mar 28 21:21:17 2015 +1100
Committer: Peter Ansell <p_ansell@yahoo.com>
Committed: Sat Mar 28 21:21:17 2015 +1100

----------------------------------------------------------------------
 .../java/org/apache/commons/rdf/api/Graph.java  | 19 --------
 .../apache/commons/rdf/simple/GraphImpl.java    | 49 +++++++++-----------
 2 files changed, 23 insertions(+), 45 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/a8ff1141/api/src/main/java/org/apache/commons/rdf/api/Graph.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/Graph.java b/api/src/main/java/org/apache/commons/rdf/api/Graph.java
index f376fe2..0ca3929 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/Graph.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/Graph.java
@@ -161,23 +161,4 @@ public interface Graph extends AutoCloseable {
 	 */
 	Stream<? extends Triple> getTriples(BlankNodeOrIRI subject, IRI predicate,
 			RDFTerm object);
-
-	/**
-	 * Get all triples contained by the graph matched with the pattern.
-	 * <p>
-	 * The iteration does not contain any duplicate triples, as determined by
-	 * the equals method for each {@link Triple}.
-	 * <p>
-	 * The behaviour of the Stream is not specified if add, remove, or clear,
-	 * are called on the Stream before it terminates.<br>
-	 * <p>
-	 * Implementations may throw ConcurrentModificationException from Stream
-	 * methods if they detect a conflict while the Stream is active.
-	 *
-	 * @param filter
-	 *            A filter to match against each triple in the graph.
-	 * @return A {@link Stream} over the matched triples.
-	 */
-	Stream<? extends Triple> getTriples(Predicate<Triple> filter);
-
 }

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/a8ff1141/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
index 24720b3..b0b3124 100644
--- a/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java
@@ -17,6 +17,7 @@
  */
 package org.apache.commons.rdf.simple;
 
+import java.util.HashSet;
 import java.util.LinkedHashSet;
 import java.util.Objects;
 import java.util.Set;
@@ -42,7 +43,7 @@ import org.apache.commons.rdf.api.Triple;
 final class GraphImpl implements Graph {
 
 	private static final int TO_STRING_MAX = 10;
-	private final Set<Triple> triples = new LinkedHashSet<Triple>();
+	private final Set<Triple> triples = new HashSet<Triple>();
 	private final SimpleRDFTermFactory factory;
 
 	GraphImpl(SimpleRDFTermFactory simpleRDFTermFactory) {
@@ -76,7 +77,7 @@ final class GraphImpl implements Graph {
 	}
 
 	private <T extends RDFTerm> RDFTerm internallyMap(T object) {
-		if (object instanceof BlankNode) {
+		if (object instanceof BlankNode && !(object instanceof BlankNodeImpl)) {
 			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
@@ -121,38 +122,34 @@ final class GraphImpl implements Graph {
 
 	@Override
 	public Stream<Triple> getTriples() {
-		return triples.parallelStream();
+		return triples.parallelStream().unordered();
 	}
 
 	@Override
 	public Stream<Triple> getTriples(final BlankNodeOrIRI subject,
 			final IRI predicate, final RDFTerm object) {
-		Predicate<Triple> match = new Predicate<Triple>() {
-			@Override
-			public boolean test(Triple t) {
-				// Lacking the requirement for .equals() we have to be silly
-				// and test ntriples string equivalance
-				if (subject != null
-						&& !t.getSubject().equals(subject)) {
-					return false;
-				}
-				if (predicate != null
-						&& !t.getPredicate().equals(predicate)) {
-					return false;
-				}
-				if (object != null
-						&& !t.getObject().equals(object)) {
-					return false;
-				}
-				return true;
+		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;
 			}
-		};
-		return getTriples(match);
+			if (predicate != null && !t.getPredicate().equals(newPredicate)) {
+				return false;
+			}
+			if (object != null && !t.getObject().equals(newObject)) {
+				return false;
+			}
+			return true;
+		});
 	}
 
-	@Override
-	public Stream<Triple> getTriples(final Predicate<Triple> filter) {
-		return getTriples().unordered().filter(filter);
+	private Stream<Triple> getTriples(final Predicate<Triple> filter) {
+		return getTriples().filter(filter);
 	}
 
 	@Override


Mime
View raw message