Return-Path: X-Original-To: apmail-commonsrdf-commits-archive@minotaur.apache.org Delivered-To: apmail-commonsrdf-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 09F7A10CAF for ; Mon, 30 Mar 2015 01:11:33 +0000 (UTC) Received: (qmail 85310 invoked by uid 500); 30 Mar 2015 01:11:32 -0000 Delivered-To: apmail-commonsrdf-commits-archive@commonsrdf.apache.org Received: (qmail 85244 invoked by uid 500); 30 Mar 2015 01:11:32 -0000 Mailing-List: contact commits-help@commonsrdf.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commonsrdf.incubator.apache.org Delivered-To: mailing list commits@commonsrdf.incubator.apache.org Received: (qmail 85126 invoked by uid 99); 30 Mar 2015 01:11:32 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 30 Mar 2015 01:11:32 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,T_RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO mail.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with SMTP; Mon, 30 Mar 2015 01:11:31 +0000 Received: (qmail 82086 invoked by uid 99); 30 Mar 2015 01:09:56 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 30 Mar 2015 01:09:56 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id C34BAE2F35; Mon, 30 Mar 2015 01:09:55 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: ansell@apache.org To: commits@commonsrdf.incubator.apache.org Date: Mon, 30 Mar 2015 01:10:05 -0000 Message-Id: In-Reply-To: <1cf5f6587f974f16b678c58ae5600115@git.apache.org> References: <1cf5f6587f974f16b678c58ae5600115@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [11/18] incubator-commonsrdf git commit: Remove getTriples(Predicate) as it doesn't support mapping X-Virus-Checked: Checked by ClamAV on apache.org 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 Authored: Sat Mar 28 21:21:17 2015 +1100 Committer: Peter Ansell 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 getTriples(BlankNodeOrIRI subject, IRI predicate, RDFTerm object); - - /** - * Get all triples contained by the graph matched with the pattern. - *

- * The iteration does not contain any duplicate triples, as determined by - * the equals method for each {@link Triple}. - *

- * The behaviour of the Stream is not specified if add, remove, or clear, - * are called on the Stream before it terminates.
- *

- * 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 getTriples(Predicate 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 triples = new LinkedHashSet(); + private final Set triples = new HashSet(); private final SimpleRDFTermFactory factory; GraphImpl(SimpleRDFTermFactory simpleRDFTermFactory) { @@ -76,7 +77,7 @@ final class GraphImpl implements Graph { } private 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 getTriples() { - return triples.parallelStream(); + return triples.parallelStream().unordered(); } @Override public Stream getTriples(final BlankNodeOrIRI subject, final IRI predicate, final RDFTerm object) { - Predicate match = new Predicate() { - @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 getTriples(final Predicate filter) { - return getTriples().unordered().filter(filter); + private Stream getTriples(final Predicate filter) { + return getTriples().filter(filter); } @Override