commonsrdf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ans...@apache.org
Subject [14/18] incubator-commonsrdf git commit: Return the Triple that was actually added to Graph, including any mapped components as necessary
Date Mon, 30 Mar 2015 01:10:08 GMT
Return the Triple that was actually added to Graph, including any mapped
components as necessary

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

Branch: refs/heads/master
Commit: 8d78597f93925115fcb7647a6ce207882511c31b
Parents: 32ee522
Author: Peter Ansell <p_ansell@yahoo.com>
Authored: Sat Mar 28 21:32:06 2015 +1100
Committer: Peter Ansell <p_ansell@yahoo.com>
Committed: Sat Mar 28 21:32:06 2015 +1100

----------------------------------------------------------------------
 .../main/java/org/apache/commons/rdf/api/Graph.java | 16 ++++++++++------
 .../org/apache/commons/rdf/simple/GraphImpl.java    | 15 ++++++++++-----
 2 files changed, 20 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/8d78597f/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 c4097b6..399a9bf 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
@@ -17,7 +17,6 @@
  */
 package org.apache.commons.rdf.api;
 
-import java.util.function.Predicate;
 import java.util.stream.Stream;
 
 /**
@@ -29,15 +28,19 @@ import java.util.stream.Stream;
 public interface Graph extends AutoCloseable {
 
 	/**
-	 * Add a triple to the graph.
+	 * Add a triple to the graph, possibly mapping any of the components of the
+	 * Triple to those supported by this Graph.
 	 *
 	 * @param triple
 	 *            The triple to add
+	 * @return The Triple that was added to the graph, including any mapped
+	 *         components.
 	 */
-	void add(Triple triple);
+	Triple add(Triple triple);
 
 	/**
-	 * Add a triple to the graph.
+	 * Add a triple to the graph, possibly mapping any of the components to
+	 * those supported by this Graph.
 	 *
 	 * @param subject
 	 *            The triple subject
@@ -45,8 +48,10 @@ public interface Graph extends AutoCloseable {
 	 *            The triple predicate
 	 * @param object
 	 *            The triple object
+	 * @return The Triple that was added to the graph, including any mapped
+	 *         components.
 	 */
-	void add(BlankNodeOrIRI subject, IRI predicate, RDFTerm object);
+	Triple add(BlankNodeOrIRI subject, IRI predicate, RDFTerm object);
 
 	/**
 	 * Check if graph contains triple.
@@ -109,7 +114,6 @@ public interface Graph extends AutoCloseable {
 
 	/**
 	 * Clear the graph, removing all triples.
-	 * 
 	 */
 	void clear();
 

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/8d78597f/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 b0b3124..e67d263 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
@@ -51,15 +51,17 @@ final class GraphImpl implements Graph {
 	}
 
 	@Override
-	public void add(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+	public Triple add(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
 		BlankNodeOrIRI newSubject = (BlankNodeOrIRI) internallyMap(subject);
 		IRI newPredicate = (IRI) internallyMap(predicate);
 		RDFTerm newObject = internallyMap(object);
-		triples.add(factory.createTriple(newSubject, newPredicate, newObject));
+		Triple result = factory.createTriple(newSubject, newPredicate, newObject);
+		triples.add(result);
+		return result;
 	}
 
 	@Override
-	public void add(Triple triple) {
+	public Triple add(Triple triple) {
 		BlankNodeOrIRI newSubject = (BlankNodeOrIRI) internallyMap(triple
 				.getSubject());
 		IRI newPredicate = (IRI) internallyMap(triple.getPredicate());
@@ -70,9 +72,12 @@ final class GraphImpl implements Graph {
 				&& newPredicate == triple.getPredicate()
 				&& newObject == triple.getObject()) {
 			triples.add(triple);
+			return triple;
 		} else {
-			triples.add(factory.createTriple(newSubject, newPredicate,
-					newObject));
+			Triple result = factory.createTriple(newSubject, newPredicate,
+					newObject);
+			triples.add(result);
+			return result;
 		}
 	}
 


Mime
View raw message