You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by st...@apache.org on 2018/02/20 10:35:32 UTC
[1/9] commons-rdf git commit: Builders for ParserSource/ParserTarget
Repository: commons-rdf
Updated Branches:
refs/heads/fluent-parser 9c22589a6 -> 11a81fec6
Builders for ParserSource/ParserTarget
Project: http://git-wip-us.apache.org/repos/asf/commons-rdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-rdf/commit/b08b5bc0
Tree: http://git-wip-us.apache.org/repos/asf/commons-rdf/tree/b08b5bc0
Diff: http://git-wip-us.apache.org/repos/asf/commons-rdf/diff/b08b5bc0
Branch: refs/heads/fluent-parser
Commit: b08b5bc0290f662ac511ba6b18dc08da8ecba6a9
Parents: 9c22589
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Mon Feb 19 14:42:46 2018 +0000
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Mon Feb 19 14:42:46 2018 +0000
----------------------------------------------------------------------
.../commons/rdf/api/io/IRIParserSource.java | 47 ----------
.../commons/rdf/api/io/InputParserSource.java | 44 ---------
.../commons/rdf/api/io/ParserConfigBuilder.java | 15 ++--
.../apache/commons/rdf/api/io/ParserSource.java | 94 +++++++++++++++++++-
.../apache/commons/rdf/api/io/ParserTarget.java | 80 +++++++++++++++--
.../commons/rdf/api/io/PathParserSource.java | 49 ----------
.../rdf/api/fluentparser/TestParseConfig.java | 28 ++++++
7 files changed, 198 insertions(+), 159 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/b08b5bc0/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/IRIParserSource.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/IRIParserSource.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/IRIParserSource.java
deleted file mode 100644
index 83a5ea4..0000000
--- a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/IRIParserSource.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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 org.apache.commons.rdf.api.io;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-import java.util.Optional;
-
-import org.apache.commons.rdf.api.IRI;
-
-final class IRIParserSource implements ParserSource<IRI> {
- private final IRI iri;
-
- IRIParserSource(IRI iri) {
- this.iri = iri;
- }
-
- @Override
- public IRI src() {
- return iri;
- }
-
- @Override
- public InputStream inputStream() throws IOException {
- return new URL(iri.getIRIString()).openStream();
- }
-
- @Override
- public Optional<IRI> iri() {
- return Optional.of(iri);
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/b08b5bc0/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/InputParserSource.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/InputParserSource.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/InputParserSource.java
deleted file mode 100644
index 5a99e4b..0000000
--- a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/InputParserSource.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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 org.apache.commons.rdf.api.io;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Optional;
-
-final class InputParserSource implements ParserSource {
- private final InputStream is;
-
- InputParserSource(InputStream is) {
- this.is = is;
- }
-
- @Override
- public Object src() {
- return is;
- }
-
- @Override
- public InputStream inputStream() throws IOException {
- return is;
- }
-
- @Override
- public Optional iri() {
- return Optional.empty();
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/b08b5bc0/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/ParserConfigBuilder.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/ParserConfigBuilder.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/ParserConfigBuilder.java
index 9adc6ce..457fb6c 100644
--- a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/ParserConfigBuilder.java
+++ b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/ParserConfigBuilder.java
@@ -63,18 +63,13 @@ public final class ParserConfigBuilder implements NeedTargetOrRDF, NeedTargetOrR
@Override
public NeedSourceOrBase target(Dataset dataset) {
- return target(dataset::add);
+ return target(ParserTarget.toDataset(dataset));
}
@Override
public NeedSourceOrBase<Graph> target(Graph graph) {
- return target(q -> {
- if (q.getGraphName().isPresent()) {
- // Only add if q is in default graph
- graph.add(q.asTriple());
- }
- });
+ return target(ParserTarget.toGraph(graph));
}
@Override
@@ -94,11 +89,11 @@ public final class ParserConfigBuilder implements NeedTargetOrRDF, NeedTargetOrR
@Override
public Sync source(final IRI iri) {
- return source(new IRIParserSource(iri));
+ return source(ParserSource.fromIRI(iri));
}
public Sync source(Path path) {
- return source(new PathParserSource(path));
+ return source(ParserSource.fromPath(path));
}
@Override
@@ -123,7 +118,7 @@ public final class ParserConfigBuilder implements NeedTargetOrRDF, NeedTargetOrR
@Override
public Sync source(InputStream is) {
- return source(new InputParserSource(is));
+ return source(ParserSource.fromInputStream(is));
}
@Override
http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/b08b5bc0/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/ParserSource.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/ParserSource.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/ParserSource.java
index 259688e..63f93ac 100644
--- a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/ParserSource.java
+++ b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/ParserSource.java
@@ -19,6 +19,9 @@ package org.apache.commons.rdf.api.io;
import java.io.IOException;
import java.io.InputStream;
+import java.net.URL;
+import java.nio.file.Files;
+import java.nio.file.Path;
import java.util.Optional;
import org.apache.commons.rdf.api.IRI;
@@ -27,7 +30,92 @@ import org.apache.commons.rdf.api.IRI;
*
*/
public interface ParserSource<S> {
- S src();
- InputStream inputStream() throws IOException;
- Optional<IRI> iri();
+ S src();
+
+ InputStream inputStream() throws IOException;
+
+ Optional<IRI> iri();
+
+ static ParserSource<IRI> fromIRI(IRI iri) {
+ return new IRIParserSource(iri);
+ }
+
+ static ParserSource<Path> fromPath(Path path) {
+ return new PathParserSource(path);
+ }
+
+ static ParserSource<InputStream> fromInputStream(InputStream is) {
+ return new InputParserSource(is);
+ }
+
+}
+
+final class IRIParserSource implements ParserSource<IRI> {
+ private final IRI iri;
+
+ IRIParserSource(IRI iri) {
+ this.iri = iri;
+ }
+
+ @Override
+ public IRI src() {
+ return iri;
+ }
+
+ @Override
+ public InputStream inputStream() throws IOException {
+ return new URL(iri.getIRIString()).openStream();
+ }
+
+ @Override
+ public Optional<IRI> iri() {
+ return Optional.of(iri);
+ }
}
+
+final class PathParserSource implements ParserSource<Path> {
+ private final Path path;
+
+ PathParserSource(Path path) {
+ this.path = path;
+ }
+
+ @Override
+ public Path src() {
+ return path;
+ }
+
+ @Override
+ public InputStream inputStream() throws IOException {
+ return Files.newInputStream(path);
+ }
+
+ @Override
+ public Optional<IRI> iri() {
+ final String uri = path.toUri().toString();
+ return Optional.of(new IRIImpl(uri));
+ }
+}
+
+final class InputParserSource implements ParserSource<InputStream> {
+ private final InputStream is;
+
+ InputParserSource(InputStream is) {
+ this.is = is;
+ }
+
+ @Override
+ public InputStream src() {
+ return is;
+ }
+
+ @Override
+ public InputStream inputStream() throws IOException {
+ return is;
+ }
+
+ @Override
+ public Optional<IRI> iri() {
+ return Optional.empty();
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/b08b5bc0/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/ParserTarget.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/ParserTarget.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/ParserTarget.java
index 8898643..4c01dcf 100644
--- a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/ParserTarget.java
+++ b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/ParserTarget.java
@@ -17,16 +17,84 @@
*/
package org.apache.commons.rdf.api.io;
+import java.util.Optional;
import java.util.function.Consumer;
+import org.apache.commons.rdf.api.Dataset;
+import org.apache.commons.rdf.api.Graph;
+import org.apache.commons.rdf.api.IRI;
import org.apache.commons.rdf.api.Quad;
-/**
- *
- */
@FunctionalInterface
public interface ParserTarget<T> extends Consumer<Quad> {
- default T dest() {
- return null;// unknown
- }
+
+ default T dest() {
+ return null;// unknown
+ }
+
+ static ParserTarget<Dataset> toDataset(final Dataset ds) {
+ return new DatasetParserTarget(ds);
+ }
+
+ static ParserTarget<Graph> toGraph(final Graph graph) {
+ return new GraphParserTarget(graph, null);
+ }
+
+ static ParserTarget<Graph> toGraph(final Graph graph, IRI matchGraphName) {
+ return new GraphParserTarget(graph, matchGraphName);
+ }
+
+ static ParserTarget<Graph> toUnionGraph(final Graph graph) {
+ return q -> graph.add(q.asTriple());
+ }
+}
+
+class GraphParserTarget implements ParserTarget<Graph> {
+
+ private final boolean anyGraphName;
+ private final Graph graph;
+ private final IRI matchGraphName;
+
+ GraphParserTarget(Graph graph) {
+ this.graph = graph;
+ this.matchGraphName = null;
+ this.anyGraphName = true;
+ }
+
+ GraphParserTarget(Graph graph, IRI matchGraphName) {
+ this.graph = graph;
+ this.matchGraphName = matchGraphName;
+ this.anyGraphName = false;
+ }
+
+ @Override
+ public Graph dest() {
+ return graph;
+ }
+
+ @Override
+ public void accept(Quad q) {
+ if (anyGraphName || q.getGraphName().equals(Optional.ofNullable(matchGraphName))) {
+ graph.add(q.asTriple());
+ }
+ }
+}
+
+class DatasetParserTarget implements ParserTarget<Dataset> {
+
+ private final Dataset dataset;
+
+ public DatasetParserTarget(Dataset dataset) {
+ this.dataset = dataset;
+ }
+
+ @Override
+ public Dataset dest() {
+ return dataset;
+ }
+
+ @Override
+ public void accept(Quad q) {
+ dataset.add(q);
+ }
}
http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/b08b5bc0/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/PathParserSource.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/PathParserSource.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/PathParserSource.java
deleted file mode 100644
index 7c6e14c..0000000
--- a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/PathParserSource.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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 org.apache.commons.rdf.api.io;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.util.Optional;
-
-import org.apache.commons.rdf.api.IRI;
-
-final class PathParserSource implements ParserSource<Path> {
- private final Path path;
-
- PathParserSource(Path path) {
- this.path = path;
- }
-
- @Override
- public Path src() {
- return path;
- }
-
- @Override
- public InputStream inputStream() throws IOException {
- return Files.newInputStream(path);
- }
-
- @Override
- public Optional<IRI> iri() {
- final String uri = path.toUri().toString();
- return Optional.of(new IRIImpl(uri));
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/b08b5bc0/commons-rdf-api/src/test/java/org/apache/commons/rdf/api/fluentparser/TestParseConfig.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/test/java/org/apache/commons/rdf/api/fluentparser/TestParseConfig.java b/commons-rdf-api/src/test/java/org/apache/commons/rdf/api/fluentparser/TestParseConfig.java
new file mode 100644
index 0000000..1102633
--- /dev/null
+++ b/commons-rdf-api/src/test/java/org/apache/commons/rdf/api/fluentparser/TestParseConfig.java
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.commons.rdf.api.fluentparser;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+public class TestParseConfig {
+ @Test
+ public void immutable() throws Exception {
+
+ }
+}
[2/9] commons-rdf git commit: Use mockito to test RDF interfaces
Posted by st...@apache.org.
Use mockito to test RDF interfaces
Project: http://git-wip-us.apache.org/repos/asf/commons-rdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-rdf/commit/ae42ac33
Tree: http://git-wip-us.apache.org/repos/asf/commons-rdf/tree/ae42ac33
Diff: http://git-wip-us.apache.org/repos/asf/commons-rdf/diff/ae42ac33
Branch: refs/heads/fluent-parser
Commit: ae42ac33fecf755d337aecdf338f089884fe9652
Parents: b08b5bc
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Tue Feb 20 09:32:54 2018 +0000
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Tue Feb 20 09:32:54 2018 +0000
----------------------------------------------------------------------
pom.xml | 13 +++++++++++++
1 file changed, 13 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/ae42ac33/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 06cc58c..6bdd79c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -73,6 +73,9 @@
<!-- Test dependencies -->
<slf4j.version>1.7.25</slf4j.version>
<junit.version>4.12</junit.version>
+ <!-- temporarily downgraded mockito as 2.15.0 fails with
+ NoClassDefFound net.bytebuddy.dynamic.loading.ClassLoadingStrategy -->
+ <mockito.version>2.13.0</mockito.version>
<skipAPICompatCheck>false</skipAPICompatCheck>
</properties>
@@ -252,6 +255,11 @@
<artifactId>junit</artifactId>
<version>${junit.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <version>${mockito.version}</version>
+ </dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
@@ -276,6 +284,11 @@
<artifactId>slf4j-simple</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
[5/9] commons-rdf git commit: Unit tests for mutable/immutable
ParserConfig
Posted by st...@apache.org.
Unit tests for mutable/immutable ParserConfig
.. and their transitions
Project: http://git-wip-us.apache.org/repos/asf/commons-rdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-rdf/commit/708312c6
Tree: http://git-wip-us.apache.org/repos/asf/commons-rdf/tree/708312c6
Diff: http://git-wip-us.apache.org/repos/asf/commons-rdf/diff/708312c6
Branch: refs/heads/fluent-parser
Commit: 708312c6c089fd69dcf80471d0f8aba61b2c1e39
Parents: f845ecb
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Tue Feb 20 09:35:37 2018 +0000
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Tue Feb 20 09:35:37 2018 +0000
----------------------------------------------------------------------
.../rdf/api/fluentparser/TestParseConfig.java | 28 ---
.../rdf/api/fluentparser/TestParserConfig.java | 225 +++++++++++++++++++
.../rdf/api/fluentparser/package-info.java | 20 --
.../commons/rdf/api/fluentparser/test/Test.java | 34 ---
.../rdf/integrationtests/JSONLDParsingTest.java | 2 +-
5 files changed, 226 insertions(+), 83 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/708312c6/commons-rdf-api/src/test/java/org/apache/commons/rdf/api/fluentparser/TestParseConfig.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/test/java/org/apache/commons/rdf/api/fluentparser/TestParseConfig.java b/commons-rdf-api/src/test/java/org/apache/commons/rdf/api/fluentparser/TestParseConfig.java
deleted file mode 100644
index 1102633..0000000
--- a/commons-rdf-api/src/test/java/org/apache/commons/rdf/api/fluentparser/TestParseConfig.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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 org.apache.commons.rdf.api.fluentparser;
-
-import static org.junit.Assert.*;
-
-import org.junit.Test;
-
-public class TestParseConfig {
- @Test
- public void immutable() throws Exception {
-
- }
-}
http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/708312c6/commons-rdf-api/src/test/java/org/apache/commons/rdf/api/fluentparser/TestParserConfig.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/test/java/org/apache/commons/rdf/api/fluentparser/TestParserConfig.java b/commons-rdf-api/src/test/java/org/apache/commons/rdf/api/fluentparser/TestParserConfig.java
new file mode 100644
index 0000000..c40adf2
--- /dev/null
+++ b/commons-rdf-api/src/test/java/org/apache/commons/rdf/api/fluentparser/TestParserConfig.java
@@ -0,0 +1,225 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.commons.rdf.api.fluentparser;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Map;
+
+import org.apache.commons.rdf.api.Dataset;
+import org.apache.commons.rdf.api.IRI;
+import org.apache.commons.rdf.api.RDF;
+import org.apache.commons.rdf.api.RDFSyntax;
+import org.apache.commons.rdf.api.io.Option;
+import org.apache.commons.rdf.api.io.ParserConfig;
+import org.apache.commons.rdf.api.io.ParserConfig.ImmutableParserConfig;
+import org.apache.commons.rdf.api.io.ParserSource;
+import org.apache.commons.rdf.api.io.ParserTarget;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+public class TestParserConfig {
+
+ RDF rdf = Mockito.mock(RDF.class);
+ ParserSource<Path> source = ParserSource.fromPath(Paths.get("test"));
+ Dataset targetDataset = Mockito.mock(Dataset.class);
+ ParserTarget<Dataset> target = ParserTarget.toDataset(targetDataset);
+ IRI base = Mockito.mock(IRI.class);
+ RDFSyntax syntax = RDFSyntax.NQUADS;
+ @SuppressWarnings("unchecked")
+ Option<String> option = Mockito.mock(Option.class);
+ String optionV = "Hello";
+
+ @Test
+ public void mutable() throws Exception {
+ ParserConfig p = ParserConfig.mutable();
+ assertNotSame(p, ParserConfig.mutable());
+
+ assertFalse(p.rdf().isPresent());
+ assertFalse(p.source().isPresent());
+ assertFalse(p.target().isPresent());
+ assertFalse(p.base().isPresent());
+ assertFalse(p.syntax().isPresent());
+ assertTrue(p.options().isEmpty());
+ Map<Option, Object> options = p.options();
+ assertSame(p, p.asMutableConfig());
+
+ assertSame(p, p.withRDF(rdf));
+ assertSame(p, p.withSource(source));
+ assertSame(p, p.withTarget(target));
+ assertSame(p, p.withBase(base));
+ assertSame(p, p.withSyntax(syntax));
+ assertSame(p, p.withOption(option, optionV));
+
+ assertSame(rdf, p.rdf().get());
+ assertSame(source, p.source().get());
+ assertSame(base, p.base().get());
+ assertSame(target, p.target().get());
+ assertSame(syntax, p.syntax().get());
+ assertFalse(p.options().isEmpty());
+ assertSame(options, p.options());
+ assertEquals(optionV, p.options().get(option));
+ assertSame(p, p.asMutableConfig());
+ }
+
+ @Test
+ public void mutableAsImmutable() throws Exception {
+ ParserConfig mutable = ParserConfig.mutable();
+ ImmutableParserConfig empty = mutable.asImmutableConfig();
+
+ // Set some values in mutable
+ mutable.withRDF(rdf).withBase(base).withSource(source);
+ mutable.withTarget(target).withSyntax(syntax);
+ mutable.withOption(option, optionV);
+ // (already tested in mutable() above that these are preserved)
+
+ // Our previous immutable snapshot is untouched
+ assertFalse(empty.rdf().isPresent());
+ assertFalse(empty.source().isPresent());
+ assertFalse(empty.target().isPresent());
+ assertFalse(empty.base().isPresent());
+ assertFalse(empty.syntax().isPresent());
+ assertTrue(empty.options().isEmpty());
+ assertNotSame(empty.options(), mutable.options());
+
+ // new snapshot
+ ImmutableParserConfig everything = mutable.asImmutableConfig();
+ // reset mutable to ensure new snapshot is not touched
+ mutable.withBase(null).withRDF(null).withSource(null);
+ mutable.withSyntax(null).withTarget(null);
+ mutable.withOption(option, null);
+
+ // Now let's check our snapshot was preserved
+ assertSame(rdf, everything.rdf().get());
+ assertSame(source, everything.source().get());
+ assertSame(base, everything.base().get());
+ assertSame(target, everything.target().get());
+ assertSame(syntax, everything.syntax().get());
+ assertFalse(everything.options().isEmpty());
+ assertEquals(optionV, everything.options().get(option));
+ assertNotSame(everything.options(), mutable.options());
+ }
+
+ @Test
+ public void immutable() throws Exception {
+ ParserConfig empty = ParserConfig.immutable();
+ assertSame(empty, empty.asImmutableConfig());
+
+ ParserConfig withRDF = empty.withRDF(rdf);
+ assertSame(rdf, withRDF.rdf().get());
+ assertNotSame(empty, withRDF);
+
+ ParserConfig withSource = withRDF.withSource(source);
+ assertSame(source, withSource.source().get());
+ assertNotSame(withRDF, withSource);
+
+ ParserConfig withTarget = withSource.withTarget(target);
+ assertSame(target, withTarget.target().get());
+ assertNotSame(withSource, withTarget);
+
+ ParserConfig withBase = withTarget.withBase(base);
+ assertSame(base, withBase.base().get());
+ assertNotSame(withTarget, withBase);
+
+ ParserConfig withSyntax = withBase.withSyntax(syntax);
+ assertSame(syntax, withSyntax.syntax().get());
+ assertNotSame(withBase, withSyntax);
+
+ ParserConfig withOption = withSyntax.withOption(option, optionV);
+ assertFalse(withOption.options().isEmpty());
+ assertEquals(optionV, withOption.options().get(option));
+ assertNotSame(withSyntax, withOption);
+
+ // Our initial empty remains the same
+ assertFalse(empty.rdf().isPresent());
+ assertFalse(empty.source().isPresent());
+ assertFalse(empty.target().isPresent());
+ assertFalse(empty.base().isPresent());
+ assertFalse(empty.syntax().isPresent());
+ assertTrue(empty.options().isEmpty());
+ Map<Option, Object> options = empty.options();
+
+ // And check final withOption has propagated
+ // all options
+ assertSame(rdf, withOption.rdf().get());
+ assertSame(source, withOption.source().get());
+ assertSame(base, withOption.base().get());
+ assertSame(target, withOption.target().get());
+ assertSame(syntax, withOption.syntax().get());
+ assertNotSame(withOption, empty.options());
+ }
+ @Test
+ public void immutableAsMutable() throws Exception {
+ ParserConfig immutable = ParserConfig.immutable();
+ ParserConfig mutable = immutable.asMutableConfig();
+
+ // Set some values in immutable
+ ParserConfig everything = immutable.withRDF(rdf)
+ .withBase(base).withSource(source).withTarget(target)
+ .withSyntax(syntax).withOption(option, optionV);
+ // (already tested in mutable() above that these are preserved)
+
+ // Our previous mutable snapshot is untouched
+ assertFalse(mutable.rdf().isPresent());
+ assertFalse(mutable.source().isPresent());
+ assertFalse(mutable.target().isPresent());
+ assertFalse(mutable.base().isPresent());
+ assertFalse(mutable.syntax().isPresent());
+ assertTrue(mutable.options().isEmpty());
+ assertNotSame(mutable.options(), immutable.options());
+
+
+ // new mutable
+ ParserConfig mutable2 = everything.asMutableConfig();
+ assertSame(mutable2, mutable2.asMutableConfig());
+ assertNotSame(mutable, mutable2);
+
+ // Below should be a no-op as everything is immutable
+ everything.withRDF(null).withSyntax(null).withBase(null).withTarget(null);
+
+ // Now let's check everything was preserved
+ assertSame(rdf, mutable2.rdf().get());
+ assertSame(source, mutable2.source().get());
+ assertSame(base, mutable2.base().get());
+ assertSame(target, mutable2.target().get());
+ assertSame(syntax, mutable2.syntax().get());
+ assertFalse(mutable2.options().isEmpty());
+ assertEquals(optionV, mutable2.options().get(option));
+ assertNotSame(mutable2.options(), mutable.options());
+
+ // changing mutable2 does not modify the immutable
+ mutable2.withRDF(null).withSyntax(null).withBase(null)
+ .withTarget(null).withOption(option, null);
+
+ assertSame(rdf, everything.rdf().get());
+ assertSame(syntax, everything.syntax().get());
+ assertSame(base, everything.base().get());
+ assertSame(target, everything.target().get());
+ assertEquals(optionV, everything.options().get(option));
+ assertNotSame(mutable2.options(), mutable.options());
+
+
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/708312c6/commons-rdf-api/src/test/java/org/apache/commons/rdf/api/fluentparser/package-info.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/test/java/org/apache/commons/rdf/api/fluentparser/package-info.java b/commons-rdf-api/src/test/java/org/apache/commons/rdf/api/fluentparser/package-info.java
deleted file mode 100644
index ef84a13..0000000
--- a/commons-rdf-api/src/test/java/org/apache/commons/rdf/api/fluentparser/package-info.java
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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 org.apache.commons.rdf.api.fluentparser;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/708312c6/commons-rdf-api/src/test/java/org/apache/commons/rdf/api/fluentparser/test/Test.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/test/java/org/apache/commons/rdf/api/fluentparser/test/Test.java b/commons-rdf-api/src/test/java/org/apache/commons/rdf/api/fluentparser/test/Test.java
deleted file mode 100644
index 3f6fc7d..0000000
--- a/commons-rdf-api/src/test/java/org/apache/commons/rdf/api/fluentparser/test/Test.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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 org.apache.commons.rdf.api.fluentparser.test;
-
-import static org.junit.Assert.*;
-
-import org.apache.commons.rdf.api.Dataset;
-import org.apache.commons.rdf.api.IRI;
-import org.apache.commons.rdf.api.RDF;
-import org.apache.commons.rdf.api.RDFSyntax;
-
-public class Test {
-
- @org.junit.Test
- public void testName() throws Exception {
- RDF rdf = null;
-
- rdf.parserFactory();
- }
-}
http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/708312c6/commons-rdf-integration-tests/src/test/java/org/apache/commons/rdf/integrationtests/JSONLDParsingTest.java
----------------------------------------------------------------------
diff --git a/commons-rdf-integration-tests/src/test/java/org/apache/commons/rdf/integrationtests/JSONLDParsingTest.java b/commons-rdf-integration-tests/src/test/java/org/apache/commons/rdf/integrationtests/JSONLDParsingTest.java
index a2522ca..56828fc 100644
--- a/commons-rdf-integration-tests/src/test/java/org/apache/commons/rdf/integrationtests/JSONLDParsingTest.java
+++ b/commons-rdf-integration-tests/src/test/java/org/apache/commons/rdf/integrationtests/JSONLDParsingTest.java
@@ -80,7 +80,7 @@ public class JSONLDParsingTest {
URL aliceEmbedded = getClass().getResource("/alice-embedded.jsonld");
/**
- * Pre-test that src/test/resources files are on the classpath
+ * Pre-test that source/test/resources files are on the classpath
*
*/
@Before
[7/9] commons-rdf git commit: WithOption now builds map on the fly
Posted by st...@apache.org.
WithOption now builds map on the fly
Project: http://git-wip-us.apache.org/repos/asf/commons-rdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-rdf/commit/40d016bb
Tree: http://git-wip-us.apache.org/repos/asf/commons-rdf/tree/40d016bb
Diff: http://git-wip-us.apache.org/repos/asf/commons-rdf/diff/40d016bb
Branch: refs/heads/fluent-parser
Commit: 40d016bbb19b7962b603f5f898dc26c72a34cfd9
Parents: 9c1e638
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Tue Feb 20 10:34:23 2018 +0000
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Tue Feb 20 10:34:23 2018 +0000
----------------------------------------------------------------------
.../commons/rdf/api/io/NullParserConfig.java | 53 ++++++++++++--------
.../commons/rdf/api/io/ParserBuilder.java | 3 +-
.../commons/rdf/api/io/ParserConfigBuilder.java | 17 +++----
3 files changed, 41 insertions(+), 32 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/40d016bb/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/NullParserConfig.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/NullParserConfig.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/NullParserConfig.java
index ccbb6b4..7ad78ba 100644
--- a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/NullParserConfig.java
+++ b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/NullParserConfig.java
@@ -61,7 +61,9 @@ class NullParserConfig implements ImmutableParserConfig, Serializable {
@Override
public Map<Option, Object> options() {
- return Collections.emptyMap();
+ // Always a fresh map, so that our children can
+ // mutate it on the fly
+ return new HashMap<>();
}
@Override
@@ -93,28 +95,35 @@ class NullParserConfig implements ImmutableParserConfig, Serializable {
@Override
public <V> ParserConfig withOption(Option<V> o, V v) {
- return new WithOptional(this, o, v);
+ return new WithOption(this, o, v);
}
@SuppressWarnings("rawtypes")
- final class WithOptional extends WithParent {
+ private static final class WithOption extends WithParent {
- private final Map<Option, Object> options;
+ private Option o;
+ private Object v;
- public <V> WithOptional(final ImmutableParserConfig parent, final Option<V> o, V v) {
+ public <V> WithOption(final ImmutableParserConfig parent, final Option<V> o, V v) {
super(parent);
- this.options = new HashMap<>(parent.options());
- options.put(o, v);
+ this.o = o;
+ this.v = v;
}
@Override
public Map<Option, Object> options() {
+ // Add to parent options
+ Map options = super.options();
+ if (v == null) {
+ options.remove(o);
+ } else {
+ options.put(o, v);
+ }
return options;
}
-
}
- final class WithBase extends WithParent {
+ private static final class WithBase extends WithParent {
private final IRI base;
WithBase(final ImmutableParserConfig parent, final IRI base) {
@@ -124,11 +133,11 @@ class NullParserConfig implements ImmutableParserConfig, Serializable {
@Override
public Optional<IRI> base() {
- return Optional.of(base);
+ return Optional.ofNullable(base);
}
}
- final class WithRDF extends WithParent {
+ private static final class WithRDF extends WithParent {
private final RDF rdf;
WithRDF(final ImmutableParserConfig parent, final RDF rdf) {
@@ -138,12 +147,12 @@ class NullParserConfig implements ImmutableParserConfig, Serializable {
@Override
public Optional<RDF> rdf() {
- return Optional.of(rdf);
+ return Optional.ofNullable(rdf);
}
}
@SuppressWarnings("rawtypes")
- final class WithTarget extends WithParent {
+ private static final class WithTarget extends WithParent {
private final ParserTarget target;
WithTarget(final ImmutableParserConfig parent, final ParserTarget target) {
@@ -153,12 +162,12 @@ class NullParserConfig implements ImmutableParserConfig, Serializable {
@Override
public Optional<ParserTarget> target() {
- return Optional.of(target);
+ return Optional.ofNullable(target);
}
}
@SuppressWarnings("rawtypes")
- public class WithSource extends WithParent {
+ private static final class WithSource extends WithParent {
private final ParserSource source;
WithSource(ImmutableParserConfig parent, ParserSource source) {
@@ -168,11 +177,11 @@ class NullParserConfig implements ImmutableParserConfig, Serializable {
@Override
public Optional<ParserSource> source() {
- return Optional.of(source);
+ return Optional.ofNullable(source);
}
}
- static class WithSyntax extends WithParent {
+ private static final class WithSyntax extends WithParent {
private final RDFSyntax syntax;
WithSyntax(ImmutableParserConfig parent, RDFSyntax syntax) {
@@ -182,7 +191,7 @@ class NullParserConfig implements ImmutableParserConfig, Serializable {
@Override
public Optional<RDFSyntax> syntax() {
- return Optional.of(syntax);
+ return Optional.ofNullable(syntax);
}
}
@@ -249,7 +258,7 @@ class NullParserConfig implements ImmutableParserConfig, Serializable {
private final IRI base;
private final ParserSource source;
private final ParserTarget target;
- private final Map<Option, Object> options = new HashMap<>();
+ private final Map<Option, Object> options;
private final ExecutorService executor;
SnapshotParserConfig(ParserConfig old) {
@@ -270,7 +279,8 @@ class NullParserConfig implements ImmutableParserConfig, Serializable {
this.base = base;
this.source = source;
this.target = target;
- this.options.putAll(options);
+ // We'll make a copy
+ this.options = Collections.unmodifiableMap(new HashMap<Option, Object>(options));
this.executor = executor;
}
@@ -301,7 +311,8 @@ class NullParserConfig implements ImmutableParserConfig, Serializable {
@Override
public Map<Option, Object> options() {
- return options;
+ // return a mutable copy so our children can build on it
+ return new HashMap<Option,Object>(options);
}
}
}
http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/40d016bb/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/ParserBuilder.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/ParserBuilder.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/ParserBuilder.java
index cd3eae4..ed43444 100644
--- a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/ParserBuilder.java
+++ b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/ParserBuilder.java
@@ -1,7 +1,6 @@
package org.apache.commons.rdf.api.io;
-import org.apache.commons.rdf.api.Dataset;
import org.apache.commons.rdf.api.fluentparser.OptionalTargetOrSyntax;
-public interface ParserBuilder extends OptionalTargetOrSyntax<Dataset> {
+public interface ParserBuilder<T> extends OptionalTargetOrSyntax<T> {
}
http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/40d016bb/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/ParserConfigBuilder.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/ParserConfigBuilder.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/ParserConfigBuilder.java
index 457fb6c..406c6fe 100644
--- a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/ParserConfigBuilder.java
+++ b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/ParserConfigBuilder.java
@@ -30,13 +30,12 @@ import org.apache.commons.rdf.api.fluentparser.Async;
import org.apache.commons.rdf.api.fluentparser.NeedSourceBased;
import org.apache.commons.rdf.api.fluentparser.NeedSourceOrBase;
import org.apache.commons.rdf.api.fluentparser.NeedTargetOrRDF;
-import org.apache.commons.rdf.api.fluentparser.NeedTargetOrRDFOrSyntax;
import org.apache.commons.rdf.api.fluentparser.OptionalTarget;
import org.apache.commons.rdf.api.fluentparser.Sync;
import org.apache.commons.rdf.api.io.ParserConfig.ImmutableParserConfig;
@SuppressWarnings({ "unchecked", "rawtypes" })
-public final class ParserConfigBuilder implements NeedTargetOrRDF, NeedTargetOrRDFOrSyntax,
+public final class ParserConfigBuilder implements ParserBuilder, NeedTargetOrRDF,
NeedSourceOrBase, NeedSourceBased, OptionalTarget, Sync, Async {
public ParserConfigBuilder(ParserConfig mutated) {
@@ -52,11 +51,6 @@ public final class ParserConfigBuilder implements NeedTargetOrRDF, NeedTargetOrR
}
}
- @Override
- public NeedTargetOrRDF syntax(RDFSyntax syntax) {
- return mutate(config.withSyntax(syntax));
- }
-
public ParserConfig buildConfig() {
return config.asImmutableConfig();
}
@@ -78,12 +72,12 @@ public final class ParserConfigBuilder implements NeedTargetOrRDF, NeedTargetOrR
}
@Override
- public NeedSourceBased base(IRI iri) {
+ public ParserConfigBuilder base(IRI iri) {
return mutate(config.withBase(iri));
}
@Override
- public NeedSourceBased base(String iriStr) {
+ public ParserConfigBuilder base(String iriStr) {
return base(new IRIImpl(iriStr));
}
@@ -157,4 +151,9 @@ public final class ParserConfigBuilder implements NeedTargetOrRDF, NeedTargetOrR
return mutate(config.asImmutableConfig());
}
+ @Override
+ public NeedTargetOrRDF syntax(RDFSyntax syntax) {
+ return mutate(config.withSyntax(syntax));
+ }
+
}
[4/9] commons-rdf git commit: ParserConfig is public interface
Posted by st...@apache.org.
ParserConfig is public interface
Project: http://git-wip-us.apache.org/repos/asf/commons-rdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-rdf/commit/f845ecb8
Tree: http://git-wip-us.apache.org/repos/asf/commons-rdf/tree/f845ecb8
Diff: http://git-wip-us.apache.org/repos/asf/commons-rdf/diff/f845ecb8
Branch: refs/heads/fluent-parser
Commit: f845ecb82385cc2c33cfd372b075efdda78247bc
Parents: 898a70c
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Tue Feb 20 09:35:20 2018 +0000
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Tue Feb 20 09:35:20 2018 +0000
----------------------------------------------------------------------
.../src/main/java/org/apache/commons/rdf/api/io/ParserConfig.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/f845ecb8/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/ParserConfig.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/ParserConfig.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/ParserConfig.java
index bb7f7c5..ee7d65f 100644
--- a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/ParserConfig.java
+++ b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/ParserConfig.java
@@ -26,7 +26,7 @@ import org.apache.commons.rdf.api.RDFSyntax;
import org.apache.commons.rdf.api.io.NullParserConfig.SnapshotParserConfig;
@SuppressWarnings("rawtypes")
-interface ParserConfig {
+public interface ParserConfig {
Optional<ParserSource> source();
Optional<IRI> base();
Optional<ParserTarget> target();
[3/9] commons-rdf git commit: null-values are permitted in configs
Posted by st...@apache.org.
null-values are permitted in configs
Project: http://git-wip-us.apache.org/repos/asf/commons-rdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-rdf/commit/898a70c7
Tree: http://git-wip-us.apache.org/repos/asf/commons-rdf/tree/898a70c7
Diff: http://git-wip-us.apache.org/repos/asf/commons-rdf/diff/898a70c7
Branch: refs/heads/fluent-parser
Commit: 898a70c7be21e4bc754f9295114eb28d04c12584
Parents: ae42ac3
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Tue Feb 20 09:35:02 2018 +0000
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Tue Feb 20 09:35:02 2018 +0000
----------------------------------------------------------------------
.../apache/commons/rdf/api/io/MutableParserConfig.java | 10 +++++-----
.../org/apache/commons/rdf/api/io/NullParserConfig.java | 10 +++++-----
2 files changed, 10 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/898a70c7/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/MutableParserConfig.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/MutableParserConfig.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/MutableParserConfig.java
index 7a43f74..283732e 100644
--- a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/MutableParserConfig.java
+++ b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/MutableParserConfig.java
@@ -57,27 +57,27 @@ final class MutableParserConfig implements Cloneable, Serializable, ParserConfig
@Override
public Optional<ParserSource> source() {
- return Optional.of(source);
+ return Optional.ofNullable(source);
}
@Override
public Optional<IRI> base() {
- return Optional.of(base);
+ return Optional.ofNullable(base);
}
@Override
public Optional<ParserTarget> target() {
- return Optional.of(target);
+ return Optional.ofNullable(target);
}
@Override
public Optional<RDFSyntax> syntax() {
- return Optional.of(syntax);
+ return Optional.ofNullable(syntax);
}
@Override
public Optional<RDF> rdf() {
- return Optional.of(rdf);
+ return Optional.ofNullable(rdf);
}
@Override
http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/898a70c7/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/NullParserConfig.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/NullParserConfig.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/NullParserConfig.java
index e993949..ccbb6b4 100644
--- a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/NullParserConfig.java
+++ b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/NullParserConfig.java
@@ -276,27 +276,27 @@ class NullParserConfig implements ImmutableParserConfig, Serializable {
@Override
public Optional<ParserSource> source() {
- return Optional.of(source);
+ return Optional.ofNullable(source);
}
@Override
public Optional<IRI> base() {
- return Optional.of(base);
+ return Optional.ofNullable(base);
}
@Override
public Optional<ParserTarget> target() {
- return Optional.of(target);
+ return Optional.ofNullable(target);
}
@Override
public Optional<RDFSyntax> syntax() {
- return Optional.of(syntax);
+ return Optional.ofNullable(syntax);
}
@Override
public Optional<RDF> rdf() {
- return Optional.of(rdf);
+ return Optional.ofNullable(rdf);
}
@Override
[6/9] commons-rdf git commit: Simplified fluentparser protected
interfaces
Posted by st...@apache.org.
Simplified fluentparser protected interfaces
Removed unneccessary protected _interfaces, rest moved to be inside the
most appropriate public interface
Buildable now public (to expose common build())
Project: http://git-wip-us.apache.org/repos/asf/commons-rdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-rdf/commit/9c1e6386
Tree: http://git-wip-us.apache.org/repos/asf/commons-rdf/tree/9c1e6386
Diff: http://git-wip-us.apache.org/repos/asf/commons-rdf/diff/9c1e6386
Branch: refs/heads/fluent-parser
Commit: 9c1e63861bcc14f17b0c0ab66cde849f35c4567b
Parents: 708312c
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Tue Feb 20 10:33:26 2018 +0000
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Tue Feb 20 10:33:26 2018 +0000
----------------------------------------------------------------------
.../commons/rdf/api/fluentparser/Async.java | 2 +-
.../commons/rdf/api/fluentparser/Buildable.java | 49 ++++++++++++++++++++
.../rdf/api/fluentparser/NeedSourceBased.java | 16 ++++++-
.../rdf/api/fluentparser/NeedSourceOrBase.java | 9 +++-
.../rdf/api/fluentparser/NeedTarget.java | 26 -----------
.../rdf/api/fluentparser/NeedTargetOrRDF.java | 18 ++++++-
.../fluentparser/NeedTargetOrRDFOrSyntax.java | 22 ---------
.../rdf/api/fluentparser/OptionalTarget.java | 4 +-
.../fluentparser/OptionalTargetOrSyntax.java | 6 ++-
.../commons/rdf/api/fluentparser/Sync.java | 2 +-
.../rdf/api/fluentparser/_Buildable.java | 49 --------------------
.../api/fluentparser/_NeedIdentifiedSource.java | 33 -------------
.../rdf/api/fluentparser/_NeedSourceOrBase.java | 21 ---------
.../rdf/api/fluentparser/_NeedSyntax.java | 24 ----------
.../rdf/api/fluentparser/_NeedTarget.java | 30 ------------
.../rdf/api/fluentparser/_NeedTargetOrRDF.java | 21 ---------
.../rdf/api/fluentparser/_OptionalBase.java | 26 -----------
.../rdf/api/fluentparser/_OptionalRDF.java | 25 ----------
.../rdf/api/fluentparser/_OptionalTarget.java | 21 ---------
19 files changed, 97 insertions(+), 307 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/9c1e6386/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/Async.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/Async.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/Async.java
index 0101f6c..9341d00 100644
--- a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/Async.java
+++ b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/Async.java
@@ -22,7 +22,7 @@ import java.util.concurrent.Future;
import org.apache.commons.rdf.api.io.Option;
import org.apache.commons.rdf.api.io.Parsed;
-public interface Async<T, S> extends _Buildable {
+public interface Async<T, S> extends Buildable {
Async<T, S> build();
<V> Async<T,S> option(Option<V> option, V value);
http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/9c1e6386/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/Buildable.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/Buildable.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/Buildable.java
new file mode 100644
index 0000000..6236cc3
--- /dev/null
+++ b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/Buildable.java
@@ -0,0 +1,49 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.commons.rdf.api.fluentparser;
+
+import org.apache.commons.rdf.api.io.Option;
+import org.apache.commons.rdf.api.io.Option.RequiredOption;
+
+public interface Buildable {
+ /**
+ * Return an immutable builder at the current state. The returned builder
+ * can be re-used multiple times in a thread-safe way.
+ *
+ * @return An immutable builder
+ */
+ Buildable build();
+
+ /**
+ * Return a builder with the given option set.
+ * <p>
+ * Note that implementations of {@link Parser} may support different
+ * vendor-specific {@link Option} types, and are free to ignore the set
+ * option (unless it is a {@link RequiredOption}).
+ * <p>
+ * It is undefined if setting multiple values for the same (equal) option
+ * are accumulative or overriding.
+ *
+ * @param <V> The type of the {@link Option} value
+ * @param option Option to set
+ * @param value Value to set for option
+ * @return A builder with the given option set
+ */
+ <V> Buildable option(Option<V> option, V value);
+
+}
http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/9c1e6386/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/NeedSourceBased.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/NeedSourceBased.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/NeedSourceBased.java
index 7b9f2f7..5933fa9 100644
--- a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/NeedSourceBased.java
+++ b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/NeedSourceBased.java
@@ -18,12 +18,24 @@
package org.apache.commons.rdf.api.fluentparser;
import java.io.InputStream;
+import java.nio.file.Path;
+import org.apache.commons.rdf.api.IRI;
import org.apache.commons.rdf.api.io.Option;
+import org.apache.commons.rdf.api.io.ParserSource;
-public interface NeedSourceBased<T> extends _NeedIdentifiedSource<T>, _Buildable {
+public interface NeedSourceBased<T> extends _NeedIdentifiedSource<T>, Buildable {
NeedSourceBased<T> build();
<V> NeedSourceBased<T> option(Option<V> option, V value);
Sync<T, InputStream> source(InputStream is);
-}
\ No newline at end of file
+}
+interface _NeedIdentifiedSource<T> {
+ Sync<T, IRI> source(IRI iri);
+
+ Sync<T, Path> source(Path path);
+
+ <S> Sync<T, S> source(ParserSource<S> source);
+
+ Sync<T, IRI> source(String iri);
+}
http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/9c1e6386/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/NeedSourceOrBase.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/NeedSourceOrBase.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/NeedSourceOrBase.java
index 4da540a..c99eb99 100644
--- a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/NeedSourceOrBase.java
+++ b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/NeedSourceOrBase.java
@@ -17,9 +17,16 @@
*/
package org.apache.commons.rdf.api.fluentparser;
+import org.apache.commons.rdf.api.IRI;
import org.apache.commons.rdf.api.io.Option;
public interface NeedSourceOrBase<T> extends _NeedSourceOrBase<T> {
NeedSourceOrBase<T> build();
<V> NeedSourceOrBase<T> option(Option<V> option, V value);
-}
\ No newline at end of file
+}
+interface _NeedSourceOrBase<T> extends _NeedIdentifiedSource<T> {
+ NeedSourceBased<T> base(IRI iri);
+
+ NeedSourceBased<T> base(String iri);
+}
+
http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/9c1e6386/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/NeedTarget.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/NeedTarget.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/NeedTarget.java
deleted file mode 100644
index a2285a0..0000000
--- a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/NeedTarget.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 org.apache.commons.rdf.api.fluentparser;
-
-import org.apache.commons.rdf.api.io.Option;
-
-interface NeedTarget extends _NeedTarget,_Buildable {
- NeedTarget build();
- <V> NeedTarget option(Option<V> option, V value);
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/9c1e6386/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/NeedTargetOrRDF.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/NeedTargetOrRDF.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/NeedTargetOrRDF.java
index 674e540..df0e163 100644
--- a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/NeedTargetOrRDF.java
+++ b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/NeedTargetOrRDF.java
@@ -17,10 +17,24 @@
*/
package org.apache.commons.rdf.api.fluentparser;
+import org.apache.commons.rdf.api.Dataset;
+import org.apache.commons.rdf.api.Graph;
+import org.apache.commons.rdf.api.RDF;
import org.apache.commons.rdf.api.io.Option;
+import org.apache.commons.rdf.api.io.ParserTarget;
-public interface NeedTargetOrRDF extends _NeedTargetOrRDF,_Buildable {
+public interface NeedTargetOrRDF extends _NeedTargetOrRDF,Buildable {
NeedTargetOrRDF build();
<V> NeedTargetOrRDF option(Option<V> option, V value);
+}
+interface _NeedTargetOrRDF extends _NeedTarget {
+ OptionalTarget<Dataset> rdf(RDF rdf);
+}
-}
\ No newline at end of file
+interface _NeedTarget {
+ NeedSourceOrBase<Dataset> target(Dataset dataset);
+
+ NeedSourceOrBase<Graph> target(Graph graph);
+
+ <T> NeedSourceOrBase<T> target(ParserTarget<T> target);
+}
http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/9c1e6386/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/NeedTargetOrRDFOrSyntax.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/NeedTargetOrRDFOrSyntax.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/NeedTargetOrRDFOrSyntax.java
deleted file mode 100644
index 61a0256..0000000
--- a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/NeedTargetOrRDFOrSyntax.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 org.apache.commons.rdf.api.fluentparser;
-
-public interface NeedTargetOrRDFOrSyntax extends _NeedTargetOrRDF, _NeedSyntax {
-
-}
http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/9c1e6386/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/OptionalTarget.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/OptionalTarget.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/OptionalTarget.java
index 5693b57..bb1a8ab 100644
--- a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/OptionalTarget.java
+++ b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/OptionalTarget.java
@@ -19,8 +19,10 @@ package org.apache.commons.rdf.api.fluentparser;
import org.apache.commons.rdf.api.io.Option;
-public interface OptionalTarget<T> extends _OptionalTarget<T>,_Buildable {
+public interface OptionalTarget<T> extends _OptionalTarget<T>,Buildable {
OptionalTarget<T> build();
<V> OptionalTarget<T> option(Option<V> option, V value);
+}
+interface _OptionalTarget<T> extends _NeedTarget, _NeedSourceOrBase<T> {
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/9c1e6386/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/OptionalTargetOrSyntax.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/OptionalTargetOrSyntax.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/OptionalTargetOrSyntax.java
index e4768f8..2a7f6ca 100644
--- a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/OptionalTargetOrSyntax.java
+++ b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/OptionalTargetOrSyntax.java
@@ -16,5 +16,9 @@
* limitations under the License.
*/
package org.apache.commons.rdf.api.fluentparser;
-public interface OptionalTargetOrSyntax<T> extends _OptionalTarget<T>, _NeedSyntax {
+
+import org.apache.commons.rdf.api.RDFSyntax;
+
+public interface OptionalTargetOrSyntax<T> extends _OptionalTarget<T> {
+ NeedTargetOrRDF syntax(RDFSyntax syntax);
}
http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/9c1e6386/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/Sync.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/Sync.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/Sync.java
index c877180..3aec96f 100644
--- a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/Sync.java
+++ b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/Sync.java
@@ -20,7 +20,7 @@ package org.apache.commons.rdf.api.fluentparser;
import org.apache.commons.rdf.api.io.Option;
import org.apache.commons.rdf.api.io.Parsed;
-public interface Sync<T, S> extends _Buildable {
+public interface Sync<T, S> extends Buildable {
Sync<T, S> build();
<V> Sync<T, S> option(Option<V> option, V value);
http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/9c1e6386/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/_Buildable.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/_Buildable.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/_Buildable.java
deleted file mode 100644
index 4f1060a..0000000
--- a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/_Buildable.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 org.apache.commons.rdf.api.fluentparser;
-
-import org.apache.commons.rdf.api.io.Option;
-import org.apache.commons.rdf.api.io.Option.RequiredOption;
-
-interface _Buildable {
- /**
- * Return an immutable builder at the current state. The returned builder
- * can be re-used multiple times in a thread-safe way.
- *
- * @return An immutable builder
- */
- _Buildable build();
-
- /**
- * Return a builder with the given option set.
- * <p>
- * Note that implementations of {@link Parser} may support different
- * vendor-specific {@link Option} types, and are free to ignore the set
- * option (unless it is a {@link RequiredOption}).
- * <p>
- * It is undefined if setting multiple values for the same (equal) option
- * are accumulative or overriding.
- *
- * @param <V> The type of the {@link Option} value
- * @param option Option to set
- * @param value Value to set for option
- * @return A builder with the given option set
- */
- <V> _Buildable option(Option<V> option, V value);
-
-}
http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/9c1e6386/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/_NeedIdentifiedSource.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/_NeedIdentifiedSource.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/_NeedIdentifiedSource.java
deleted file mode 100644
index cb0a1a8..0000000
--- a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/_NeedIdentifiedSource.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 org.apache.commons.rdf.api.fluentparser;
-
-import java.nio.file.Path;
-
-import org.apache.commons.rdf.api.IRI;
-import org.apache.commons.rdf.api.io.ParserSource;
-
-interface _NeedIdentifiedSource<T> {
- Sync<T, IRI> source(IRI iri);
-
- Sync<T, Path> source(Path path);
-
- <S> Sync<T, S> source(ParserSource<S> source);
-
- Sync<T, IRI> source(String iri);
-}
http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/9c1e6386/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/_NeedSourceOrBase.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/_NeedSourceOrBase.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/_NeedSourceOrBase.java
deleted file mode 100644
index a95b4b2..0000000
--- a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/_NeedSourceOrBase.java
+++ /dev/null
@@ -1,21 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 org.apache.commons.rdf.api.fluentparser;
-
-interface _NeedSourceOrBase<T> extends _OptionalBase<T>, _NeedIdentifiedSource<T> {
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/9c1e6386/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/_NeedSyntax.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/_NeedSyntax.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/_NeedSyntax.java
deleted file mode 100644
index 6ab0142..0000000
--- a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/_NeedSyntax.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 org.apache.commons.rdf.api.fluentparser;
-
-import org.apache.commons.rdf.api.RDFSyntax;
-
-interface _NeedSyntax {
- NeedTargetOrRDF syntax(RDFSyntax syntax);
-}
http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/9c1e6386/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/_NeedTarget.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/_NeedTarget.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/_NeedTarget.java
deleted file mode 100644
index 2053f3b..0000000
--- a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/_NeedTarget.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 org.apache.commons.rdf.api.fluentparser;
-
-import org.apache.commons.rdf.api.Dataset;
-import org.apache.commons.rdf.api.Graph;
-import org.apache.commons.rdf.api.io.ParserTarget;
-
-interface _NeedTarget {
- NeedSourceOrBase<Dataset> target(Dataset dataset);
-
- NeedSourceOrBase<Graph> target(Graph graph);
-
- <T> NeedSourceOrBase<T> target(ParserTarget<T> target);
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/9c1e6386/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/_NeedTargetOrRDF.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/_NeedTargetOrRDF.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/_NeedTargetOrRDF.java
deleted file mode 100644
index 89016b4..0000000
--- a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/_NeedTargetOrRDF.java
+++ /dev/null
@@ -1,21 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 org.apache.commons.rdf.api.fluentparser;
-
-interface _NeedTargetOrRDF extends _NeedTarget, _OptionalRDF {
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/9c1e6386/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/_OptionalBase.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/_OptionalBase.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/_OptionalBase.java
deleted file mode 100644
index 3e3235c..0000000
--- a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/_OptionalBase.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 org.apache.commons.rdf.api.fluentparser;
-
-import org.apache.commons.rdf.api.IRI;
-
-interface _OptionalBase<T> {
- NeedSourceBased<T> base(IRI iri);
-
- NeedSourceBased<T> base(String iri);
-}
http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/9c1e6386/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/_OptionalRDF.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/_OptionalRDF.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/_OptionalRDF.java
deleted file mode 100644
index 80ac15b..0000000
--- a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/_OptionalRDF.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 org.apache.commons.rdf.api.fluentparser;
-
-import org.apache.commons.rdf.api.Dataset;
-import org.apache.commons.rdf.api.RDF;
-
-interface _OptionalRDF {
- OptionalTarget<Dataset> rdf(RDF rdf);
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/9c1e6386/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/_OptionalTarget.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/_OptionalTarget.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/_OptionalTarget.java
deleted file mode 100644
index 3a2143e..0000000
--- a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/_OptionalTarget.java
+++ /dev/null
@@ -1,21 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 org.apache.commons.rdf.api.fluentparser;
-
-interface _OptionalTarget<T> extends _NeedTarget, _NeedSourceOrBase<T> {
-}
\ No newline at end of file
[9/9] commons-rdf git commit: Test null overrides work
Posted by st...@apache.org.
Test null overrides work
.. even for options
Project: http://git-wip-us.apache.org/repos/asf/commons-rdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-rdf/commit/11a81fec
Tree: http://git-wip-us.apache.org/repos/asf/commons-rdf/tree/11a81fec
Diff: http://git-wip-us.apache.org/repos/asf/commons-rdf/diff/11a81fec
Branch: refs/heads/fluent-parser
Commit: 11a81fec6aafc6df9e86bd71d7dfeb75980dbe3c
Parents: 8cc07df
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Tue Feb 20 10:35:12 2018 +0000
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Tue Feb 20 10:35:12 2018 +0000
----------------------------------------------------------------------
.../rdf/api/fluentparser/TestParserConfig.java | 225 ----------------
.../commons/rdf/api/io/TestParserConfig.java | 256 +++++++++++++++++++
2 files changed, 256 insertions(+), 225 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/11a81fec/commons-rdf-api/src/test/java/org/apache/commons/rdf/api/fluentparser/TestParserConfig.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/test/java/org/apache/commons/rdf/api/fluentparser/TestParserConfig.java b/commons-rdf-api/src/test/java/org/apache/commons/rdf/api/fluentparser/TestParserConfig.java
deleted file mode 100644
index c40adf2..0000000
--- a/commons-rdf-api/src/test/java/org/apache/commons/rdf/api/fluentparser/TestParserConfig.java
+++ /dev/null
@@ -1,225 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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 org.apache.commons.rdf.api.fluentparser;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotSame;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
-
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.Map;
-
-import org.apache.commons.rdf.api.Dataset;
-import org.apache.commons.rdf.api.IRI;
-import org.apache.commons.rdf.api.RDF;
-import org.apache.commons.rdf.api.RDFSyntax;
-import org.apache.commons.rdf.api.io.Option;
-import org.apache.commons.rdf.api.io.ParserConfig;
-import org.apache.commons.rdf.api.io.ParserConfig.ImmutableParserConfig;
-import org.apache.commons.rdf.api.io.ParserSource;
-import org.apache.commons.rdf.api.io.ParserTarget;
-import org.junit.Test;
-import org.mockito.Mockito;
-
-public class TestParserConfig {
-
- RDF rdf = Mockito.mock(RDF.class);
- ParserSource<Path> source = ParserSource.fromPath(Paths.get("test"));
- Dataset targetDataset = Mockito.mock(Dataset.class);
- ParserTarget<Dataset> target = ParserTarget.toDataset(targetDataset);
- IRI base = Mockito.mock(IRI.class);
- RDFSyntax syntax = RDFSyntax.NQUADS;
- @SuppressWarnings("unchecked")
- Option<String> option = Mockito.mock(Option.class);
- String optionV = "Hello";
-
- @Test
- public void mutable() throws Exception {
- ParserConfig p = ParserConfig.mutable();
- assertNotSame(p, ParserConfig.mutable());
-
- assertFalse(p.rdf().isPresent());
- assertFalse(p.source().isPresent());
- assertFalse(p.target().isPresent());
- assertFalse(p.base().isPresent());
- assertFalse(p.syntax().isPresent());
- assertTrue(p.options().isEmpty());
- Map<Option, Object> options = p.options();
- assertSame(p, p.asMutableConfig());
-
- assertSame(p, p.withRDF(rdf));
- assertSame(p, p.withSource(source));
- assertSame(p, p.withTarget(target));
- assertSame(p, p.withBase(base));
- assertSame(p, p.withSyntax(syntax));
- assertSame(p, p.withOption(option, optionV));
-
- assertSame(rdf, p.rdf().get());
- assertSame(source, p.source().get());
- assertSame(base, p.base().get());
- assertSame(target, p.target().get());
- assertSame(syntax, p.syntax().get());
- assertFalse(p.options().isEmpty());
- assertSame(options, p.options());
- assertEquals(optionV, p.options().get(option));
- assertSame(p, p.asMutableConfig());
- }
-
- @Test
- public void mutableAsImmutable() throws Exception {
- ParserConfig mutable = ParserConfig.mutable();
- ImmutableParserConfig empty = mutable.asImmutableConfig();
-
- // Set some values in mutable
- mutable.withRDF(rdf).withBase(base).withSource(source);
- mutable.withTarget(target).withSyntax(syntax);
- mutable.withOption(option, optionV);
- // (already tested in mutable() above that these are preserved)
-
- // Our previous immutable snapshot is untouched
- assertFalse(empty.rdf().isPresent());
- assertFalse(empty.source().isPresent());
- assertFalse(empty.target().isPresent());
- assertFalse(empty.base().isPresent());
- assertFalse(empty.syntax().isPresent());
- assertTrue(empty.options().isEmpty());
- assertNotSame(empty.options(), mutable.options());
-
- // new snapshot
- ImmutableParserConfig everything = mutable.asImmutableConfig();
- // reset mutable to ensure new snapshot is not touched
- mutable.withBase(null).withRDF(null).withSource(null);
- mutable.withSyntax(null).withTarget(null);
- mutable.withOption(option, null);
-
- // Now let's check our snapshot was preserved
- assertSame(rdf, everything.rdf().get());
- assertSame(source, everything.source().get());
- assertSame(base, everything.base().get());
- assertSame(target, everything.target().get());
- assertSame(syntax, everything.syntax().get());
- assertFalse(everything.options().isEmpty());
- assertEquals(optionV, everything.options().get(option));
- assertNotSame(everything.options(), mutable.options());
- }
-
- @Test
- public void immutable() throws Exception {
- ParserConfig empty = ParserConfig.immutable();
- assertSame(empty, empty.asImmutableConfig());
-
- ParserConfig withRDF = empty.withRDF(rdf);
- assertSame(rdf, withRDF.rdf().get());
- assertNotSame(empty, withRDF);
-
- ParserConfig withSource = withRDF.withSource(source);
- assertSame(source, withSource.source().get());
- assertNotSame(withRDF, withSource);
-
- ParserConfig withTarget = withSource.withTarget(target);
- assertSame(target, withTarget.target().get());
- assertNotSame(withSource, withTarget);
-
- ParserConfig withBase = withTarget.withBase(base);
- assertSame(base, withBase.base().get());
- assertNotSame(withTarget, withBase);
-
- ParserConfig withSyntax = withBase.withSyntax(syntax);
- assertSame(syntax, withSyntax.syntax().get());
- assertNotSame(withBase, withSyntax);
-
- ParserConfig withOption = withSyntax.withOption(option, optionV);
- assertFalse(withOption.options().isEmpty());
- assertEquals(optionV, withOption.options().get(option));
- assertNotSame(withSyntax, withOption);
-
- // Our initial empty remains the same
- assertFalse(empty.rdf().isPresent());
- assertFalse(empty.source().isPresent());
- assertFalse(empty.target().isPresent());
- assertFalse(empty.base().isPresent());
- assertFalse(empty.syntax().isPresent());
- assertTrue(empty.options().isEmpty());
- Map<Option, Object> options = empty.options();
-
- // And check final withOption has propagated
- // all options
- assertSame(rdf, withOption.rdf().get());
- assertSame(source, withOption.source().get());
- assertSame(base, withOption.base().get());
- assertSame(target, withOption.target().get());
- assertSame(syntax, withOption.syntax().get());
- assertNotSame(withOption, empty.options());
- }
- @Test
- public void immutableAsMutable() throws Exception {
- ParserConfig immutable = ParserConfig.immutable();
- ParserConfig mutable = immutable.asMutableConfig();
-
- // Set some values in immutable
- ParserConfig everything = immutable.withRDF(rdf)
- .withBase(base).withSource(source).withTarget(target)
- .withSyntax(syntax).withOption(option, optionV);
- // (already tested in mutable() above that these are preserved)
-
- // Our previous mutable snapshot is untouched
- assertFalse(mutable.rdf().isPresent());
- assertFalse(mutable.source().isPresent());
- assertFalse(mutable.target().isPresent());
- assertFalse(mutable.base().isPresent());
- assertFalse(mutable.syntax().isPresent());
- assertTrue(mutable.options().isEmpty());
- assertNotSame(mutable.options(), immutable.options());
-
-
- // new mutable
- ParserConfig mutable2 = everything.asMutableConfig();
- assertSame(mutable2, mutable2.asMutableConfig());
- assertNotSame(mutable, mutable2);
-
- // Below should be a no-op as everything is immutable
- everything.withRDF(null).withSyntax(null).withBase(null).withTarget(null);
-
- // Now let's check everything was preserved
- assertSame(rdf, mutable2.rdf().get());
- assertSame(source, mutable2.source().get());
- assertSame(base, mutable2.base().get());
- assertSame(target, mutable2.target().get());
- assertSame(syntax, mutable2.syntax().get());
- assertFalse(mutable2.options().isEmpty());
- assertEquals(optionV, mutable2.options().get(option));
- assertNotSame(mutable2.options(), mutable.options());
-
- // changing mutable2 does not modify the immutable
- mutable2.withRDF(null).withSyntax(null).withBase(null)
- .withTarget(null).withOption(option, null);
-
- assertSame(rdf, everything.rdf().get());
- assertSame(syntax, everything.syntax().get());
- assertSame(base, everything.base().get());
- assertSame(target, everything.target().get());
- assertEquals(optionV, everything.options().get(option));
- assertNotSame(mutable2.options(), mutable.options());
-
-
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/11a81fec/commons-rdf-api/src/test/java/org/apache/commons/rdf/api/io/TestParserConfig.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/test/java/org/apache/commons/rdf/api/io/TestParserConfig.java b/commons-rdf-api/src/test/java/org/apache/commons/rdf/api/io/TestParserConfig.java
new file mode 100644
index 0000000..51ad4d9
--- /dev/null
+++ b/commons-rdf-api/src/test/java/org/apache/commons/rdf/api/io/TestParserConfig.java
@@ -0,0 +1,256 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.commons.rdf.api.io;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Map;
+
+import org.apache.commons.rdf.api.Dataset;
+import org.apache.commons.rdf.api.IRI;
+import org.apache.commons.rdf.api.RDF;
+import org.apache.commons.rdf.api.RDFSyntax;
+import org.apache.commons.rdf.api.io.Option;
+import org.apache.commons.rdf.api.io.ParserConfig;
+import org.apache.commons.rdf.api.io.ParserConfig.ImmutableParserConfig;
+import org.apache.commons.rdf.api.io.ParserSource;
+import org.apache.commons.rdf.api.io.ParserTarget;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+public class TestParserConfig {
+
+ RDF rdf = Mockito.mock(RDF.class);
+ ParserSource<Path> source = ParserSource.fromPath(Paths.get("test"));
+ Dataset targetDataset = Mockito.mock(Dataset.class);
+ ParserTarget<Dataset> target = ParserTarget.toDataset(targetDataset);
+ IRI base = Mockito.mock(IRI.class);
+ RDFSyntax syntax = RDFSyntax.NQUADS;
+ @SuppressWarnings("unchecked")
+ Option<String> option = Mockito.mock(Option.class);
+ String optionV = "Hello";
+
+ @Test
+ public void mutable() throws Exception {
+ ParserConfig p = ParserConfig.mutable();
+ assertNotSame(p, ParserConfig.mutable());
+
+ assertFalse(p.rdf().isPresent());
+ assertFalse(p.source().isPresent());
+ assertFalse(p.target().isPresent());
+ assertFalse(p.base().isPresent());
+ assertFalse(p.syntax().isPresent());
+ assertTrue(p.options().isEmpty());
+ Map<Option, Object> options = p.options();
+ assertSame(p, p.asMutableConfig());
+
+ assertSame(p, p.withRDF(rdf));
+ assertSame(p, p.withSource(source));
+ assertSame(p, p.withTarget(target));
+ assertSame(p, p.withBase(base));
+ assertSame(p, p.withSyntax(syntax));
+ assertSame(p, p.withOption(option, optionV));
+
+ assertSame(rdf, p.rdf().get());
+ assertSame(source, p.source().get());
+ assertSame(base, p.base().get());
+ assertSame(target, p.target().get());
+ assertSame(syntax, p.syntax().get());
+ assertFalse(p.options().isEmpty());
+ assertSame(options, p.options());
+ assertEquals(optionV, p.options().get(option));
+ assertSame(p, p.asMutableConfig());
+ }
+
+ @Test
+ public void mutableAsImmutable() throws Exception {
+ ParserConfig mutable = ParserConfig.mutable();
+ ImmutableParserConfig empty = mutable.asImmutableConfig();
+
+ // Set some values in mutable
+ mutable.withRDF(rdf).withBase(base).withSource(source);
+ mutable.withTarget(target).withSyntax(syntax);
+ mutable.withOption(option, optionV);
+ // (already tested in mutable() above that these are preserved)
+
+ // Our previous immutable snapshot is untouched
+ assertFalse(empty.rdf().isPresent());
+ assertFalse(empty.source().isPresent());
+ assertFalse(empty.target().isPresent());
+ assertFalse(empty.base().isPresent());
+ assertFalse(empty.syntax().isPresent());
+ assertTrue(empty.options().isEmpty());
+ assertNotSame(empty.options(), mutable.options());
+
+ // new snapshot
+ ImmutableParserConfig everything = mutable.asImmutableConfig();
+ // reset mutable to ensure new snapshot is not touched
+ mutable.withBase(null).withRDF(null).withSource(null);
+ mutable.withSyntax(null).withTarget(null);
+ mutable.withOption(option, null);
+
+ // Now let's check our snapshot was preserved
+ assertSame(rdf, everything.rdf().get());
+ assertSame(source, everything.source().get());
+ assertSame(base, everything.base().get());
+ assertSame(target, everything.target().get());
+ assertSame(syntax, everything.syntax().get());
+ assertFalse(everything.options().isEmpty());
+ assertEquals(optionV, everything.options().get(option));
+ assertNotSame(everything.options(), mutable.options());
+ }
+
+ @Test
+ public void immutable() throws Exception {
+ ParserConfig empty = ParserConfig.immutable();
+ assertSame(empty, empty.asImmutableConfig());
+
+ ParserConfig withRDF = empty.withRDF(rdf);
+ assertSame(rdf, withRDF.rdf().get());
+ assertNotSame(empty, withRDF);
+
+ ParserConfig withSource = withRDF.withSource(source);
+ assertSame(source, withSource.source().get());
+ assertNotSame(withRDF, withSource);
+
+ ParserConfig withTarget = withSource.withTarget(target);
+ assertSame(target, withTarget.target().get());
+ assertNotSame(withSource, withTarget);
+
+ ParserConfig withBase = withTarget.withBase(base);
+ assertSame(base, withBase.base().get());
+ assertNotSame(withTarget, withBase);
+
+ ParserConfig withSyntax = withBase.withSyntax(syntax);
+ assertSame(syntax, withSyntax.syntax().get());
+ assertNotSame(withBase, withSyntax);
+
+ ParserConfig withOption = withSyntax.withOption(option, optionV);
+ assertFalse(withOption.options().isEmpty());
+ assertEquals(optionV, withOption.options().get(option));
+ assertNotSame(withSyntax, withOption);
+
+ // Our initial empty remains the same
+ assertFalse(empty.rdf().isPresent());
+ assertFalse(empty.source().isPresent());
+ assertFalse(empty.target().isPresent());
+ assertFalse(empty.base().isPresent());
+ assertFalse(empty.syntax().isPresent());
+ assertTrue(empty.options().isEmpty());
+ Map<Option, Object> options = empty.options();
+
+ // And check final withOption has propagated
+ // all options
+ assertSame(rdf, withOption.rdf().get());
+ assertSame(source, withOption.source().get());
+ assertSame(base, withOption.base().get());
+ assertSame(target, withOption.target().get());
+ assertSame(syntax, withOption.syntax().get());
+ assertNotSame(withOption, empty.options());
+ }
+ @Test
+ public void immutableAsMutable() throws Exception {
+ ParserConfig immutable = ParserConfig.immutable();
+ ParserConfig mutable = immutable.asMutableConfig();
+
+ // Set some values in immutable
+ ParserConfig everything = immutable.withRDF(rdf)
+ .withBase(base).withSource(source).withTarget(target)
+ .withSyntax(syntax).withOption(option, optionV);
+ // (already tested in mutable() above that these are preserved)
+
+ // Our previous mutable snapshot is untouched
+ assertFalse(mutable.rdf().isPresent());
+ assertFalse(mutable.source().isPresent());
+ assertFalse(mutable.target().isPresent());
+ assertFalse(mutable.base().isPresent());
+ assertFalse(mutable.syntax().isPresent());
+ assertTrue(mutable.options().isEmpty());
+ assertNotSame(mutable.options(), immutable.options());
+
+
+ // new mutable
+ ParserConfig mutable2 = everything.asMutableConfig();
+ assertSame(mutable2, mutable2.asMutableConfig());
+ assertNotSame(mutable, mutable2);
+
+ // Below should be a no-op as everything is immutable
+ everything.withRDF(null).withSyntax(null).withBase(null).withTarget(null);
+
+ // Now let's check everything was preserved
+ assertSame(rdf, mutable2.rdf().get());
+ assertSame(source, mutable2.source().get());
+ assertSame(base, mutable2.base().get());
+ assertSame(target, mutable2.target().get());
+ assertSame(syntax, mutable2.syntax().get());
+ assertFalse(mutable2.options().isEmpty());
+ assertEquals(optionV, mutable2.options().get(option));
+ assertNotSame(mutable2.options(), mutable.options());
+
+ // changing mutable2 does not modify the immutable
+ mutable2.withRDF(null).withSyntax(null).withBase(null)
+ .withTarget(null).withOption(option, null);
+
+ assertSame(rdf, everything.rdf().get());
+ assertSame(syntax, everything.syntax().get());
+ assertSame(base, everything.base().get());
+ assertSame(target, everything.target().get());
+ assertEquals(optionV, everything.options().get(option));
+ assertNotSame(mutable2.options(), mutable.options());
+
+
+ }
+
+ @Test
+ public void immutableOverrides() throws Exception {
+ // Test that we can override
+ ParserConfig a = ParserConfig.immutable().withRDF(rdf)
+ .withBase(base).withSource(source).withSyntax(syntax)
+ .withTarget(target).withOption(option, optionV);
+ ParserConfig nulled = a.withRDF(null).withBase(null)
+ .withSource(null).withSyntax(null)
+ .withTarget(null).withOption(option, null);
+ assertFalse(nulled.rdf().isPresent());
+ assertFalse(nulled.base().isPresent());
+ assertFalse(nulled.source().isPresent());
+ assertFalse(nulled.syntax().isPresent());
+ assertFalse(nulled.target().isPresent());
+ assertNull(nulled.options().get(option));
+ assertFalse(nulled.options().containsKey(option));
+ assertTrue(nulled.options().isEmpty());
+
+ // And then we can fill it again
+ ParserConfig filled = nulled.withRDF(rdf).withBase(base)
+ .withSource(source).withSyntax(syntax)
+ .withTarget(target).withOption(option, optionV);
+ assertSame(rdf, filled.rdf().get());
+ assertSame(base, filled.base().get());
+ assertSame(source, filled.source().get());
+ assertSame(syntax, filled.syntax().get());
+ assertSame(target, filled.target().get());
+ assertEquals(optionV, filled.options().get(option));
+
+ }
+
+}
[8/9] commons-rdf git commit: Reference Buildable in javadoc
Posted by st...@apache.org.
Reference Buildable in javadoc
Project: http://git-wip-us.apache.org/repos/asf/commons-rdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-rdf/commit/8cc07df8
Tree: http://git-wip-us.apache.org/repos/asf/commons-rdf/tree/8cc07df8
Diff: http://git-wip-us.apache.org/repos/asf/commons-rdf/diff/8cc07df8
Branch: refs/heads/fluent-parser
Commit: 8cc07df8def7424c1df5f6b7ee939d995c034558
Parents: 40d016b
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Tue Feb 20 10:34:58 2018 +0000
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Tue Feb 20 10:34:58 2018 +0000
----------------------------------------------------------------------
.../src/main/java/org/apache/commons/rdf/api/RDF.java | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/8cc07df8/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/RDF.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/RDF.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/RDF.java
index 581d615..8fab94f 100644
--- a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/RDF.java
+++ b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/RDF.java
@@ -23,6 +23,7 @@ import java.util.Optional;
import java.util.concurrent.Future;
import org.apache.commons.rdf.api.fluentparser.Async;
+import org.apache.commons.rdf.api.fluentparser.Buildable;
import org.apache.commons.rdf.api.fluentparser.Sync;
import org.apache.commons.rdf.api.io.Parsed;
import org.apache.commons.rdf.api.io.Parser;
@@ -301,13 +302,13 @@ public interface RDF {
* Note that the returned {@link ParserBuilder} may be mutable and not
* thread-safe, and should only be used for parsing once. A reusable,
* immutable builder can be created at any step with
- * {@link _Builder#build()}.
+ * {@link Buildable#build()}.
*
* @return {@link ParserBuilder} supported by this RDF implementation
* @throws UnsupportedOperationException
* If this RDF implementation does not support parsing RDF
*/
- public ParserBuilder parserBuilder() throws UnsupportedOperationException;
+ public ParserBuilder<Dataset> parserBuilder() throws UnsupportedOperationException;
/**
* Return a parser for the given RDF syntax.