You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commonsrdf.apache.org by wi...@apache.org on 2015/03/27 19:15:04 UTC

[06/50] [abbrv] incubator-commonsrdf git commit: Rename source code directories to be shorter

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/88e701d3/simple/src/main/java/com/github/commonsrdf/simple/LiteralImpl.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/com/github/commonsrdf/simple/LiteralImpl.java b/simple/src/main/java/com/github/commonsrdf/simple/LiteralImpl.java
new file mode 100644
index 0000000..8d34f1e
--- /dev/null
+++ b/simple/src/main/java/com/github/commonsrdf/simple/LiteralImpl.java
@@ -0,0 +1,130 @@
+/**
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.github.commonsrdf.simple;
+
+import java.util.IllformedLocaleException;
+import java.util.Locale;
+import java.util.Objects;
+import java.util.Optional;
+
+import com.github.commonsrdf.api.IRI;
+import com.github.commonsrdf.api.Literal;
+
+/**
+ * A simple implementation of Literal.
+ *
+ */
+public class LiteralImpl implements Literal {
+
+	private static final String QUOTE = "\"";
+	private static final IRIImpl RDF_LANG_STRING = new IRIImpl(
+			"http://www.w3.org/1999/02/22-rdf-syntax-ns#langString");
+	private static final IRIImpl XSD_STRING = new IRIImpl(
+			"http://www.w3.org/2001/XMLSchema#string");
+
+	private IRI dataType;
+	private Optional<String> languageTag;
+	private String lexicalForm;
+
+	public LiteralImpl(String literal) {
+		this.lexicalForm = Objects.requireNonNull(literal);
+		this.dataType = XSD_STRING;
+		this.languageTag = Optional.empty();
+	}
+
+	public LiteralImpl(String lexicalForm, IRI dataType) {
+		this.lexicalForm = Objects.requireNonNull(lexicalForm);
+		this.dataType = Objects.requireNonNull(dataType);
+		this.languageTag = Optional.empty();
+	}
+
+	public LiteralImpl(String literal, String languageTag) {
+		this.lexicalForm = Objects.requireNonNull(literal);
+		this.languageTag = Optional.of(languageTag.toLowerCase(Locale.ENGLISH));
+		if (languageTag.isEmpty()) {
+			// TODO: Check against
+			// http://www.w3.org/TR/n-triples/#n-triples-grammar
+			throw new IllegalArgumentException("Language tag can't be null");
+		}
+		try {
+			new Locale.Builder().setLanguageTag(languageTag);
+		} catch (IllformedLocaleException ex) {
+			throw new IllegalArgumentException("Invalid languageTag: "
+					+ languageTag, ex);
+		}
+
+		// System.out.println(aLocale);
+		this.dataType = RDF_LANG_STRING;
+	}
+
+	@Override
+	public IRI getDatatype() {
+		return dataType;
+	}
+
+	@Override
+	public Optional<String> getLanguageTag() {
+		return languageTag;
+	}
+
+	@Override
+	public String getLexicalForm() {
+		return lexicalForm;
+	}
+
+	@Override
+	public String ntriplesString() {
+		StringBuilder sb = new StringBuilder();
+		sb.append(QUOTE);
+		// Escape special characters
+		sb.append(getLexicalForm().replace("\\", "\\\\"). // escaped to \\
+				replace("\"", "\\\""). // escaped to \"
+				replace("\r", "\\r"). // escaped to \r
+				replace("\n", "\\n")); // escaped to \n
+		sb.append(QUOTE);
+
+		// getLanguageTag().ifPresent(s -> sb.append("@" + s));
+		if (getLanguageTag().isPresent()) {
+			sb.append("@");
+			sb.append(getLanguageTag().get());
+
+		} else if (!getDatatype().equals(XSD_STRING)) {
+			sb.append("^^");
+			sb.append(getDatatype().ntriplesString());
+		}
+		return sb.toString();
+	}
+
+	@Override
+	public String toString() {
+		return ntriplesString();
+	}
+
+	@Override
+	public int hashCode() {
+		return Objects.hash(dataType, lexicalForm, languageTag);
+	}
+
+	@Override
+	public boolean equals(Object obj) {
+		if (!(obj instanceof Literal)) {
+			return false;
+		}
+		Literal literal = (Literal) obj;
+		return getDatatype().equals(literal.getDatatype())
+				&& getLexicalForm().equals(literal.getLexicalForm())
+				&& getLanguageTag().equals(literal.getLanguageTag());
+	}
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/88e701d3/simple/src/main/java/com/github/commonsrdf/simple/SimpleRDFTermFactory.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/com/github/commonsrdf/simple/SimpleRDFTermFactory.java b/simple/src/main/java/com/github/commonsrdf/simple/SimpleRDFTermFactory.java
new file mode 100644
index 0000000..1825c66
--- /dev/null
+++ b/simple/src/main/java/com/github/commonsrdf/simple/SimpleRDFTermFactory.java
@@ -0,0 +1,77 @@
+/**
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.github.commonsrdf.simple;
+
+import java.util.Optional;
+
+import com.github.commonsrdf.api.BlankNode;
+import com.github.commonsrdf.api.BlankNodeOrIRI;
+import com.github.commonsrdf.api.Graph;
+import com.github.commonsrdf.api.IRI;
+import com.github.commonsrdf.api.Literal;
+import com.github.commonsrdf.api.RDFTerm;
+import com.github.commonsrdf.api.RDFTermFactory;
+import com.github.commonsrdf.api.Triple;
+
+/**
+ * A simple implementation of RDFTermFactory.
+ * <p>
+ * The {@link RDFTerm} and {@link Graph} instances created by this factory are
+ * simple in-memory Implementations that are not thread-safe or efficient, but
+ * which may be useful for testing and prototyping purposes.
+ *
+ */
+public class SimpleRDFTermFactory implements RDFTermFactory {
+
+	@Override
+	public BlankNode createBlankNode() {
+		return new BlankNodeImpl();
+	}
+
+	@Override
+	public BlankNode createBlankNode(String identifier) {
+		return new BlankNodeImpl(Optional.empty(), identifier);
+	}
+
+	@Override
+	public Graph createGraph() {
+		return new GraphImpl();
+	}
+
+	@Override
+	public IRI createIRI(String iri) {
+		return new IRIImpl(iri);
+	}
+
+	@Override
+	public Literal createLiteral(String literal) {
+		return new LiteralImpl(literal);
+	}
+
+	@Override
+	public Literal createLiteral(String literal, IRI dataType) {
+		return new LiteralImpl(literal, dataType);
+	}
+
+	@Override
+	public Literal createLiteral(String literal, String language) {
+		return new LiteralImpl(literal, language);
+	}
+
+	@Override
+	public Triple createTriple(BlankNodeOrIRI subject, IRI predicate,
+			RDFTerm object) {
+		return new TripleImpl(subject, predicate, object);
+	}
+}

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/88e701d3/simple/src/main/java/com/github/commonsrdf/simple/TripleImpl.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/com/github/commonsrdf/simple/TripleImpl.java b/simple/src/main/java/com/github/commonsrdf/simple/TripleImpl.java
new file mode 100644
index 0000000..831f913
--- /dev/null
+++ b/simple/src/main/java/com/github/commonsrdf/simple/TripleImpl.java
@@ -0,0 +1,138 @@
+/**
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.github.commonsrdf.simple;
+
+import java.util.Objects;
+import java.util.Optional;
+
+import com.github.commonsrdf.api.BlankNode;
+import com.github.commonsrdf.api.BlankNodeOrIRI;
+import com.github.commonsrdf.api.Graph;
+import com.github.commonsrdf.api.IRI;
+import com.github.commonsrdf.api.Literal;
+import com.github.commonsrdf.api.RDFTerm;
+import com.github.commonsrdf.api.Triple;
+
+/**
+ * A simple implementation of Triple.
+ *
+ */
+public class TripleImpl implements Triple {
+
+	private BlankNodeOrIRI subject;
+	private IRI predicate;
+	private RDFTerm object;
+
+	/**
+	 * Construct Triple from its constituent parts.
+	 * <p>
+	 * The parts may be copied to ensure they are in scope.
+	 * 
+	 * @param subject subject of triple
+	 * @param predicate predicate of triple
+	 * @param object object of triple
+	 */
+	public TripleImpl(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+		this.subject = (BlankNodeOrIRI) inScope(Optional.empty(),
+				Objects.requireNonNull(subject));
+		this.predicate = (IRI) inScope(null, Objects.requireNonNull(predicate));
+		this.object = inScope(Optional.empty(), Objects.requireNonNull(object));
+	}
+
+	/**
+	 * Construct Triple by cloning another Triple and its constituent parts.
+	 * <p>
+	 * The parts of the triple may be copied to ensure they are in scope.
+	 * 
+	 * @param localScope
+	 *            Scope to create new triple in.
+	 * @param triple
+	 *            Triple to clone
+	 */
+	public TripleImpl(Optional<Graph> localScope, Triple triple) {
+		Objects.requireNonNull(localScope);
+		Objects.requireNonNull(triple);
+
+		this.subject = (BlankNodeOrIRI) inScope(localScope, triple.getSubject());
+		this.predicate = (IRI) inScope(localScope, triple.getPredicate());
+		this.object = inScope(localScope, triple.getObject());
+	}
+
+	private RDFTerm inScope(Optional<Graph> localScope, RDFTerm object) {
+		if (!(object instanceof BlankNode) && !(object instanceof IRI)
+				& !(object instanceof Literal)) {
+			throw new IllegalArgumentException(
+					"RDFTerm must be BlankNode, IRI or Literal");
+		}
+		if (object instanceof BlankNode) {
+			BlankNode blankNode = (BlankNode) object;
+			return new BlankNodeImpl(Objects.requireNonNull(localScope),
+					blankNode.internalIdentifier());
+		} else if (object instanceof IRI && !(object instanceof IRIImpl)) {
+			IRI iri = (IRI) object;
+			return new IRIImpl(iri.getIRIString());
+		} else if (object instanceof Literal
+				&& !(object instanceof LiteralImpl)) {
+			Literal literal = (Literal) object;
+			if (literal.getLanguageTag().isPresent()) {
+				return new LiteralImpl(literal.getLexicalForm(), literal
+						.getLanguageTag().get());
+			} else {
+				IRI dataType = (IRI) inScope(localScope, literal.getDatatype());
+				return new LiteralImpl(literal.getLexicalForm(), dataType);
+			}
+		} else {
+			return object;
+		}
+	}
+
+	@Override
+	public BlankNodeOrIRI getSubject() {
+		return subject;
+	}
+
+	@Override
+	public IRI getPredicate() {
+		return predicate;
+	}
+
+	@Override
+	public RDFTerm getObject() {
+		return object;
+	}
+
+	@Override
+	public String toString() {
+		return getSubject().ntriplesString() + " "
+				+ getPredicate().ntriplesString() + " "
+				+ getObject().ntriplesString() + " .";
+	}
+
+	@Override
+	public int hashCode() {
+		return Objects.hash(subject, predicate, object);
+	}
+
+	@Override
+	public boolean equals(Object obj) {
+		if (!(obj instanceof Triple)) {
+			return false;
+		}
+		Triple other = (Triple) obj;
+		return getSubject().equals(other.getSubject())
+				&& getPredicate().equals(other.getPredicate())
+				&& getObject().equals(other.getObject());
+	}
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/88e701d3/simple/src/main/java/com/github/commonsrdf/simple/package-info.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/com/github/commonsrdf/simple/package-info.java b/simple/src/main/java/com/github/commonsrdf/simple/package-info.java
new file mode 100644
index 0000000..2e053ae
--- /dev/null
+++ b/simple/src/main/java/com/github/commonsrdf/simple/package-info.java
@@ -0,0 +1,31 @@
+/**
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * A simple in-memory implementation of the Commons RDF API.
+ * <p>
+ * This package contains a simple (if not naive) implementation of the Commons RDF API 
+ * using in-memory POJO objects.
+ * <p>
+ * Note that although this module fully implements the commons-rdf API,
+ * it should *not*  be considered a reference implementation. 
+ * It is not thread-safe nor scalable, but may be useful for testing
+ * and simple usage (e.g. output from an independent RDF parser).
+ * <p>
+ * To use this implementation, create an instance of {@link SimpleRDFTermFactory}
+ * and use methods like {@link SimpleRDFTermFactory#createGraph} and 
+ * {@link SimpleRDFTermFactory#createIRI(String)}.
+ * 
+ */
+package com.github.commonsrdf.simple;
+

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/88e701d3/simple/src/test/java/com/github/commonsrdf/simple/DefaultGraphTest.java
----------------------------------------------------------------------
diff --git a/simple/src/test/java/com/github/commonsrdf/simple/DefaultGraphTest.java b/simple/src/test/java/com/github/commonsrdf/simple/DefaultGraphTest.java
new file mode 100644
index 0000000..1663de4
--- /dev/null
+++ b/simple/src/test/java/com/github/commonsrdf/simple/DefaultGraphTest.java
@@ -0,0 +1,48 @@
+/**
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.github.commonsrdf.simple;
+
+import com.github.commonsrdf.api.AbstractGraphTest;
+import com.github.commonsrdf.api.Graph;
+import com.github.commonsrdf.api.IRI;
+import com.github.commonsrdf.api.RDFTermFactory;
+
+/**
+ * Ensure AbstractGraphTest does not crash if the RDFTermFactory throws
+ * UnsupportedOperationException
+ *
+ */
+
+public class DefaultGraphTest extends AbstractGraphTest {
+
+	@Override
+	public RDFTermFactory createFactory() {
+		// The most minimal RDFTermFactory that would still
+		// make sense with a Graph
+		return new RDFTermFactory() {
+			@Override
+			public Graph createGraph() throws UnsupportedOperationException {
+				return new GraphImpl();
+			}
+
+			@Override
+			public IRI createIRI(String iri)
+					throws UnsupportedOperationException,
+					IllegalArgumentException {
+				return new IRIImpl(iri);
+			}
+		};
+	}
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/88e701d3/simple/src/test/java/com/github/commonsrdf/simple/DefaultRDFTermFactoryTest.java
----------------------------------------------------------------------
diff --git a/simple/src/test/java/com/github/commonsrdf/simple/DefaultRDFTermFactoryTest.java b/simple/src/test/java/com/github/commonsrdf/simple/DefaultRDFTermFactoryTest.java
new file mode 100644
index 0000000..476cbf1
--- /dev/null
+++ b/simple/src/test/java/com/github/commonsrdf/simple/DefaultRDFTermFactoryTest.java
@@ -0,0 +1,33 @@
+/**
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.github.commonsrdf.simple;
+
+import com.github.commonsrdf.api.AbstractRDFTermFactoryTest;
+import com.github.commonsrdf.api.RDFTermFactory;
+
+/**
+ * The default RDFTermFactory might be useless (every method throws
+ * UnsupportedOperationException), but this test ensures that
+ * AbstractRDFTermFactoryTest does not fall over on unsupported operations.
+ *
+ */
+public class DefaultRDFTermFactoryTest extends AbstractRDFTermFactoryTest {
+
+	@Override
+	public RDFTermFactory createFactory() {
+		return new RDFTermFactory() {
+		};
+	}
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/88e701d3/simple/src/test/java/com/github/commonsrdf/simple/SimpleGraphTest.java
----------------------------------------------------------------------
diff --git a/simple/src/test/java/com/github/commonsrdf/simple/SimpleGraphTest.java b/simple/src/test/java/com/github/commonsrdf/simple/SimpleGraphTest.java
new file mode 100644
index 0000000..d1bc435
--- /dev/null
+++ b/simple/src/test/java/com/github/commonsrdf/simple/SimpleGraphTest.java
@@ -0,0 +1,30 @@
+/**
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.github.commonsrdf.simple;
+
+import com.github.commonsrdf.api.AbstractGraphTest;
+import com.github.commonsrdf.api.RDFTermFactory;
+
+/**
+ * Test SimpleRDFTermFactory with AbstractGraphTest
+ *
+ */
+public class SimpleGraphTest extends AbstractGraphTest {
+
+	@Override
+	public RDFTermFactory createFactory() {
+		return new SimpleRDFTermFactory();
+	}
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/88e701d3/simple/src/test/java/com/github/commonsrdf/simple/SimpleNoRelativeIRIRDFTermFactoryTest.java
----------------------------------------------------------------------
diff --git a/simple/src/test/java/com/github/commonsrdf/simple/SimpleNoRelativeIRIRDFTermFactoryTest.java b/simple/src/test/java/com/github/commonsrdf/simple/SimpleNoRelativeIRIRDFTermFactoryTest.java
new file mode 100644
index 0000000..dccf72a
--- /dev/null
+++ b/simple/src/test/java/com/github/commonsrdf/simple/SimpleNoRelativeIRIRDFTermFactoryTest.java
@@ -0,0 +1,44 @@
+/**
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.github.commonsrdf.simple;
+
+import java.net.URI;
+
+import com.github.commonsrdf.api.AbstractRDFTermFactoryTest;
+import com.github.commonsrdf.api.IRI;
+import com.github.commonsrdf.api.RDFTermFactory;
+
+/**
+ * Test simple IRI without relative IRI support.
+ * <p?>
+ * Ensures that {@link AbstractRDFTermFactoryTest#createIRIRelative()} is
+ * correctly skipped (without causing an error.
+ *
+ */
+public class SimpleNoRelativeIRIRDFTermFactoryTest extends
+		AbstractRDFTermFactoryTest {
+	@Override
+	public RDFTermFactory createFactory() {
+		return new SimpleRDFTermFactory() {
+			@Override
+			public IRI createIRI(String iri) {
+				if (!URI.create(iri).isAbsolute()) {
+					throw new IllegalArgumentException("IRIs must be absolute");
+					// ..in this subclass for testing purposes only :)
+				}
+				return super.createIRI(iri);
+			}
+		};
+	}
+}

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/88e701d3/simple/src/test/java/com/github/commonsrdf/simple/SimpleRDFTermFactoryTest.java
----------------------------------------------------------------------
diff --git a/simple/src/test/java/com/github/commonsrdf/simple/SimpleRDFTermFactoryTest.java b/simple/src/test/java/com/github/commonsrdf/simple/SimpleRDFTermFactoryTest.java
new file mode 100644
index 0000000..43b9515
--- /dev/null
+++ b/simple/src/test/java/com/github/commonsrdf/simple/SimpleRDFTermFactoryTest.java
@@ -0,0 +1,26 @@
+/**
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.github.commonsrdf.simple;
+
+import com.github.commonsrdf.api.AbstractRDFTermFactoryTest;
+import com.github.commonsrdf.api.RDFTermFactory;
+
+public class SimpleRDFTermFactoryTest extends AbstractRDFTermFactoryTest {
+
+	@Override
+	public RDFTermFactory createFactory() {
+		return new SimpleRDFTermFactory();
+	}
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/88e701d3/simple/src/test/java/com/github/commonsrdf/simple/TestWritingGraph.java
----------------------------------------------------------------------
diff --git a/simple/src/test/java/com/github/commonsrdf/simple/TestWritingGraph.java b/simple/src/test/java/com/github/commonsrdf/simple/TestWritingGraph.java
new file mode 100644
index 0000000..34b8b40
--- /dev/null
+++ b/simple/src/test/java/com/github/commonsrdf/simple/TestWritingGraph.java
@@ -0,0 +1,96 @@
+/**
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.github.commonsrdf.simple;
+
+import java.nio.charset.Charset;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Optional;
+import java.util.stream.Stream;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.github.commonsrdf.api.BlankNode;
+import com.github.commonsrdf.api.IRI;
+
+public class TestWritingGraph {
+
+	/*
+	 * 200k triples should do - about 7 MB on disk. Override with
+	 * -Dtriples=20000000 to exercise your memory banks.
+	 */
+	private static final int TRIPLES = Integer.getInteger("triples", 200000);
+
+	/** Run tests with -Dkeepfiles=true to inspect /tmp files **/
+	private static boolean KEEP_FILES = Boolean.getBoolean("keepfiles");
+
+	private static GraphImpl graph;
+
+	@BeforeClass
+	public static void createGraph() throws Exception {
+		graph = new GraphImpl();
+		BlankNode subject = new BlankNodeImpl(Optional.of(graph), "subj");
+		IRI predicate = new IRIImpl("pred");
+		for (int i = 0; i < TRIPLES; i++) {
+			graph.add(subject, predicate, new LiteralImpl("Example " + i, "en"));
+		}
+	}
+
+	@Test
+	public void createGraphTiming() throws Exception {
+		createGraph();
+	}
+	
+	@Test
+	public void countQuery() {
+		BlankNode subject = new BlankNodeImpl(Optional.of(graph), "subj");
+		IRI predicate = new IRIImpl("pred");
+		long count = graph.getTriples(subject, predicate, null).unordered()
+				.parallel().count();
+		System.out.println("Counted - " + count);
+	}
+
+	@Test
+	public void writeGraphFromStream() throws Exception {
+		Path graphFile = Files.createTempFile("graph", ".nt");
+		if (KEEP_FILES) {
+			System.out.println("From stream: " + graphFile);
+		} else {
+			graphFile.toFile().deleteOnExit();
+		}
+		
+		Stream<CharSequence> stream = graph.getTriples().unordered()
+				.map(Object::toString);
+		Files.write(graphFile, stream::iterator, Charset.forName("UTF-8"));
+	}
+
+	@Test
+	public void writeGraphFromStreamFiltered() throws Exception {
+		Path graphFile = Files.createTempFile("graph", ".nt");
+		if (KEEP_FILES) {
+			System.out.println("Filtered stream: " + graphFile);
+		} else {
+			graphFile.toFile().deleteOnExit();
+		}
+
+		BlankNode subject = new BlankNodeImpl(Optional.of(graph), "subj");
+		IRI predicate = new IRIImpl("pred");
+		Stream<CharSequence> stream = graph
+				.getTriples(subject, predicate, null).map(Object::toString);
+		Files.write(graphFile, stream::iterator, Charset.forName("UTF-8"));
+
+	}
+
+}