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 11:23:31 UTC
commons-rdf git commit: ImmutableParserConfigImpl /
ImmutableWriterConfigImpl
Repository: commons-rdf
Updated Branches:
refs/heads/fluent-parser 9c7da99c0 -> f9613b90a
ImmutableParserConfigImpl / ImmutableWriterConfigImpl
Project: http://git-wip-us.apache.org/repos/asf/commons-rdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-rdf/commit/f9613b90
Tree: http://git-wip-us.apache.org/repos/asf/commons-rdf/tree/f9613b90
Diff: http://git-wip-us.apache.org/repos/asf/commons-rdf/diff/f9613b90
Branch: refs/heads/fluent-parser
Commit: f9613b90afda1049bff64f1227f9e3b3485e8171
Parents: 9c7da99
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Tue Feb 20 11:22:37 2018 +0000
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Tue Feb 20 11:23:18 2018 +0000
----------------------------------------------------------------------
.../rdf/api/io/ImmutableParserConfigImpl.java | 314 +++++++++++++++++++
.../rdf/api/io/ImmutableWriterConfigImpl.java | 252 +++++++++++++++
.../commons/rdf/api/io/NullParserConfig.java | 314 -------------------
.../commons/rdf/api/io/NullWriterConfig.java | 252 ---------------
.../apache/commons/rdf/api/io/ParserConfig.java | 6 +-
.../apache/commons/rdf/api/io/WriterConfig.java | 6 +-
6 files changed, 572 insertions(+), 572 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/f9613b90/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/ImmutableParserConfigImpl.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/ImmutableParserConfigImpl.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/ImmutableParserConfigImpl.java
new file mode 100644
index 0000000..5dea128
--- /dev/null
+++ b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/ImmutableParserConfigImpl.java
@@ -0,0 +1,314 @@
+/*
+ * 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.ObjectStreamException;
+import java.io.Serializable;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.concurrent.ExecutorService;
+
+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.ParserConfig.ImmutableParserConfig;
+
+class ImmutableParserConfigImpl implements ImmutableParserConfig, Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public Optional<ParserSource> source() {
+ return Optional.empty();
+ }
+
+ @Override
+ public Optional<IRI> base() {
+ return Optional.empty();
+ }
+
+ @Override
+ public Optional<ParserTarget> target() {
+ return Optional.empty();
+ }
+
+ @Override
+ public Optional<RDFSyntax> syntax() {
+ return Optional.empty();
+ }
+
+ @Override
+ public Optional<RDF> rdf() {
+ return Optional.empty();
+ }
+
+ @Override
+ public Map<Option, Object> options() {
+ // Always a fresh map, so that our children can
+ // mutate it on the fly
+ return new HashMap<>();
+ }
+
+ @Override
+ public ParserConfig withSyntax(RDFSyntax syntax) {
+ return new WithSyntax(this, syntax);
+ }
+
+ @SuppressWarnings("rawtypes")
+ @Override
+ public ParserConfig withSource(ParserSource source) {
+ return new WithSource(this, source);
+ }
+
+ @SuppressWarnings("rawtypes")
+ @Override
+ public ParserConfig withTarget(ParserTarget target) {
+ return new WithTarget(this, target);
+ }
+
+ @Override
+ public ParserConfig withRDF(RDF rdf) {
+ return new WithRDF(this, rdf);
+ }
+
+ @Override
+ public ParserConfig withBase(IRI base) {
+ return new WithBase(this, base);
+ }
+
+ @Override
+ public <V> ParserConfig withOption(Option<V> o, V v) {
+ return new WithOption(this, o, v);
+ }
+
+ @SuppressWarnings("rawtypes")
+ private static final class WithOption extends WithParent {
+
+ private Option o;
+ private Object v;
+
+ public <V> WithOption(final ImmutableParserConfig parent, final Option<V> o, V v) {
+ super(parent);
+ 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;
+ }
+ }
+
+ private static final class WithBase extends WithParent {
+ private final IRI base;
+
+ WithBase(final ImmutableParserConfig parent, final IRI base) {
+ super(parent);
+ this.base = base;
+ }
+
+ @Override
+ public Optional<IRI> base() {
+ return Optional.ofNullable(base);
+ }
+ }
+
+ private static final class WithRDF extends WithParent {
+ private final RDF rdf;
+
+ WithRDF(final ImmutableParserConfig parent, final RDF rdf) {
+ super(parent);
+ this.rdf = rdf;
+ }
+
+ @Override
+ public Optional<RDF> rdf() {
+ return Optional.ofNullable(rdf);
+ }
+ }
+
+ @SuppressWarnings("rawtypes")
+ private static final class WithTarget extends WithParent {
+ private final ParserTarget target;
+
+ WithTarget(final ImmutableParserConfig parent, final ParserTarget target) {
+ super(parent);
+ this.target = target;
+ }
+
+ @Override
+ public Optional<ParserTarget> target() {
+ return Optional.ofNullable(target);
+ }
+ }
+
+ @SuppressWarnings("rawtypes")
+ private static final class WithSource extends WithParent {
+ private final ParserSource source;
+
+ WithSource(ImmutableParserConfig parent, ParserSource source) {
+ super(parent);
+ this.source = source;
+ }
+
+ @Override
+ public Optional<ParserSource> source() {
+ return Optional.ofNullable(source);
+ }
+ }
+
+ private static final class WithSyntax extends WithParent {
+ private final RDFSyntax syntax;
+
+ WithSyntax(ImmutableParserConfig parent, RDFSyntax syntax) {
+ super(parent);
+ this.syntax = syntax;
+ }
+
+ @Override
+ public Optional<RDFSyntax> syntax() {
+ return Optional.ofNullable(syntax);
+ }
+ }
+
+ abstract static class WithParent extends ImmutableParserConfigImpl implements ImmutableParserConfig {
+ private final ImmutableParserConfig parent;
+
+ /**
+ * Override which object to use by Serializable, avoiding
+ * serialization of the whole WithParent tree.
+ *
+ * This method is protected so it will be invoked for all subclasses of
+ * WithParent.
+ *
+ * @return a {@link SnapshotParserConfig}
+ * @throws ObjectStreamException
+ */
+ protected Object writeReplace() throws ObjectStreamException {
+ return new SnapshotParserConfig(this);
+ }
+
+ WithParent(ImmutableParserConfig parserConfig) {
+ this.parent = Objects.requireNonNull(parserConfig);
+ }
+
+ @SuppressWarnings("rawtypes")
+ @Override
+ public Optional<ParserSource> source() {
+ return parent.source();
+ }
+
+ @Override
+ public Optional<IRI> base() {
+ return parent.base();
+ }
+
+ @SuppressWarnings("rawtypes")
+ @Override
+ public Optional<ParserTarget> target() {
+ return parent.target();
+ }
+
+ @Override
+ public Optional<RDFSyntax> syntax() {
+ return parent.syntax();
+ }
+
+ @Override
+ public Optional<RDF> rdf() {
+ return parent.rdf();
+ }
+
+ @SuppressWarnings("rawtypes")
+ @Override
+ public Map<Option, Object> options() {
+ return parent.options();
+ }
+ }
+
+ @SuppressWarnings("rawtypes")
+ final static class SnapshotParserConfig extends ImmutableParserConfigImpl {
+ private static final long serialVersionUID = 1L;
+ private final RDF rdf;
+ private final RDFSyntax syntax;
+ private final IRI base;
+ private final ParserSource source;
+ private final ParserTarget target;
+ private final Map<Option, Object> options;
+
+ SnapshotParserConfig(ParserConfig old) {
+ this(
+ old.rdf().orElse(null),
+ old.syntax().orElse(null),
+ old.base().orElse(null),
+ old.source().orElse(null),
+ old.target().orElse(null),
+ old.options());
+ }
+
+ SnapshotParserConfig(RDF rdf, RDFSyntax syntax, IRI base, ParserSource source, ParserTarget target, Map<Option, Object> options) {
+ this.rdf = rdf;
+ this.syntax = syntax;
+ this.base = base;
+ this.source = source;
+ this.target = target;
+ // We'll make a copy
+ this.options = Collections.unmodifiableMap(new HashMap<Option, Object>(options));
+ }
+
+ @Override
+ public Optional<ParserSource> source() {
+ return Optional.ofNullable(source);
+ }
+
+ @Override
+ public Optional<IRI> base() {
+ return Optional.ofNullable(base);
+ }
+
+ @Override
+ public Optional<ParserTarget> target() {
+ return Optional.ofNullable(target);
+ }
+
+ @Override
+ public Optional<RDFSyntax> syntax() {
+ return Optional.ofNullable(syntax);
+ }
+
+ @Override
+ public Optional<RDF> rdf() {
+ return Optional.ofNullable(rdf);
+ }
+
+ @Override
+ public Map<Option, Object> 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/f9613b90/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/ImmutableWriterConfigImpl.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/ImmutableWriterConfigImpl.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/ImmutableWriterConfigImpl.java
new file mode 100644
index 0000000..4c238d9
--- /dev/null
+++ b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/ImmutableWriterConfigImpl.java
@@ -0,0 +1,252 @@
+/*
+ * 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.Serializable;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+import java.util.concurrent.ExecutorService;
+
+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.WriterConfig.ImmutableWriterConfig;
+
+class ImmutableWriterConfigImpl implements ImmutableWriterConfig, Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public Optional<WriterSource> source() {
+ return Optional.empty();
+ }
+
+ @Override
+ public Optional<WriterTarget> target() {
+ return Optional.empty();
+ }
+
+ @Override
+ public Optional<RDFSyntax> syntax() {
+ return Optional.empty();
+ }
+
+ @Override
+ public Optional<RDF> rdf() {
+ return Optional.empty();
+ }
+
+ @SuppressWarnings("rawtypes")
+ @Override
+ public Map<Option, Object> options() {
+ return Collections.emptyMap();
+ }
+
+ @Override
+ public WriterConfig withSyntax(RDFSyntax syntax) {
+ return new WithSyntax(this, syntax);
+ }
+
+ @Override
+ public WriterConfig withSource(WriterSource source) {
+ return new WithSource(this, source);
+ }
+
+ @Override
+ public WriterConfig withTarget(WriterTarget target) {
+ return new WithTarget(this, target);
+ }
+
+ @Override
+ public WriterConfig withRDF(RDF rdf) {
+ return new WithRDF(this, rdf);
+ }
+
+ @Override
+ public <V> WriterConfig withOption(Option<V> o, V v) {
+ return new WithOption(this, o, v);
+ }
+
+ static class WithParent extends ImmutableWriterConfigImpl implements ImmutableWriterConfig {
+ private final ImmutableWriterConfig parent;
+
+ WithParent(ImmutableWriterConfig parent) {
+ this.parent = parent;
+ }
+
+ @Override
+ public Optional<WriterSource> source() {
+ return parent.source();
+ }
+
+ @Override
+ public Optional<WriterTarget> target() {
+ return parent.target();
+ }
+
+ @Override
+ public Optional<RDFSyntax> syntax() {
+ return parent.syntax();
+ }
+
+ @Override
+ public Optional<RDF> rdf() {
+ return parent.rdf();
+ }
+
+ @Override
+ public Map<Option, Object> options() {
+ return parent.options();
+ }
+ }
+
+ static final class WithSyntax extends WithParent implements WriterConfig {
+ private final RDFSyntax syntax;
+
+ public WithSyntax(ImmutableWriterConfig parent, RDFSyntax syntax) {
+ super(parent);
+ this.syntax = syntax;
+ }
+
+ @Override
+ public Optional<RDFSyntax> syntax() {
+ return Optional.ofNullable(syntax);
+ }
+ }
+
+ static final class WithSource extends WithParent implements WriterConfig {
+ private final WriterSource source;
+
+ public WithSource(ImmutableWriterConfig parent, WriterSource source) {
+ super(parent);
+ this.source = source;
+ }
+
+ @Override
+ public Optional<WriterSource> source() {
+ return Optional.ofNullable(source);
+ }
+ }
+
+ static class WithTarget extends WithParent implements WriterConfig {
+ private final WriterTarget target;
+
+ public WithTarget(ImmutableWriterConfig parent, WriterTarget target) {
+ super(parent);
+ this.target = target;
+ }
+
+ @Override
+ public Optional<WriterTarget> target() {
+ return Optional.ofNullable(target);
+ }
+ }
+
+ static class WithRDF extends WithParent implements WriterConfig {
+ private final RDF rdf;
+
+ public WithRDF(ImmutableWriterConfig parent, RDF rdf) {
+ super(parent);
+ this.rdf = rdf;
+ }
+ @Override
+ public Optional<RDF> rdf() {
+ return Optional.ofNullable(rdf);
+ }
+
+ }
+
+ static class WithOption extends WithParent implements WriterConfig {
+ private Option o;
+ private Object v;
+ public <V> WithOption(ImmutableWriterConfig parent, Option<V> o, V v) {
+ super(parent);
+ this.o = o;
+ this.v = v;
+ }
+ @Override
+ public Map<Option, Object> options() {
+ // Add to parent options
+ Map<Option, Object> options = super.options();
+ if (v == null) {
+ options.remove(o);
+ } else {
+ options.put(o, v);
+ }
+ return options;
+ }
+ }
+
+ @SuppressWarnings("rawtypes")
+ final static class SnapshotWriterConfig extends ImmutableWriterConfigImpl {
+ private static final long serialVersionUID = 1L;
+ private final RDF rdf;
+ private final RDFSyntax syntax;
+ private final WriterSource source;
+ private final WriterTarget target;
+ private final Map<Option, Object> options;
+
+ SnapshotWriterConfig(WriterConfig old) {
+ this(
+ old.rdf().orElse(null),
+ old.syntax().orElse(null),
+ old.source().orElse(null),
+ old.target().orElse(null),
+ old.options(),
+ null);
+ }
+
+ SnapshotWriterConfig(RDF rdf, RDFSyntax syntax, WriterSource source, WriterTarget target, Map<Option, Object> options,
+ ExecutorService executor) {
+ this.rdf = rdf;
+ this.syntax = syntax;
+ this.source = source;
+ this.target = target;
+ // We'll make a copy
+ this.options = Collections.unmodifiableMap(new HashMap<Option, Object>(options));
+ }
+
+ @Override
+ public Optional<WriterSource> source() {
+ return Optional.ofNullable(source);
+ }
+
+ @Override
+ public Optional<WriterTarget> target() {
+ return Optional.ofNullable(target);
+ }
+
+ @Override
+ public Optional<RDFSyntax> syntax() {
+ return Optional.ofNullable(syntax);
+ }
+
+ @Override
+ public Optional<RDF> rdf() {
+ return Optional.ofNullable(rdf);
+ }
+
+ @Override
+ public Map<Option, Object> options() {
+ // return a mutable copy so our children can build on it
+ return new HashMap<Option,Object>(options);
+ }
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/f9613b90/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
deleted file mode 100644
index e83a3a6..0000000
--- a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/NullParserConfig.java
+++ /dev/null
@@ -1,314 +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.ObjectStreamException;
-import java.io.Serializable;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
-import java.util.concurrent.ExecutorService;
-
-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.ParserConfig.ImmutableParserConfig;
-
-class NullParserConfig implements ImmutableParserConfig, Serializable {
-
- private static final long serialVersionUID = 1L;
-
- @Override
- public Optional<ParserSource> source() {
- return Optional.empty();
- }
-
- @Override
- public Optional<IRI> base() {
- return Optional.empty();
- }
-
- @Override
- public Optional<ParserTarget> target() {
- return Optional.empty();
- }
-
- @Override
- public Optional<RDFSyntax> syntax() {
- return Optional.empty();
- }
-
- @Override
- public Optional<RDF> rdf() {
- return Optional.empty();
- }
-
- @Override
- public Map<Option, Object> options() {
- // Always a fresh map, so that our children can
- // mutate it on the fly
- return new HashMap<>();
- }
-
- @Override
- public ParserConfig withSyntax(RDFSyntax syntax) {
- return new WithSyntax(this, syntax);
- }
-
- @SuppressWarnings("rawtypes")
- @Override
- public ParserConfig withSource(ParserSource source) {
- return new WithSource(this, source);
- }
-
- @SuppressWarnings("rawtypes")
- @Override
- public ParserConfig withTarget(ParserTarget target) {
- return new WithTarget(this, target);
- }
-
- @Override
- public ParserConfig withRDF(RDF rdf) {
- return new WithRDF(this, rdf);
- }
-
- @Override
- public ParserConfig withBase(IRI base) {
- return new WithBase(this, base);
- }
-
- @Override
- public <V> ParserConfig withOption(Option<V> o, V v) {
- return new WithOption(this, o, v);
- }
-
- @SuppressWarnings("rawtypes")
- private static final class WithOption extends WithParent {
-
- private Option o;
- private Object v;
-
- public <V> WithOption(final ImmutableParserConfig parent, final Option<V> o, V v) {
- super(parent);
- 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;
- }
- }
-
- private static final class WithBase extends WithParent {
- private final IRI base;
-
- WithBase(final ImmutableParserConfig parent, final IRI base) {
- super(parent);
- this.base = base;
- }
-
- @Override
- public Optional<IRI> base() {
- return Optional.ofNullable(base);
- }
- }
-
- private static final class WithRDF extends WithParent {
- private final RDF rdf;
-
- WithRDF(final ImmutableParserConfig parent, final RDF rdf) {
- super(parent);
- this.rdf = rdf;
- }
-
- @Override
- public Optional<RDF> rdf() {
- return Optional.ofNullable(rdf);
- }
- }
-
- @SuppressWarnings("rawtypes")
- private static final class WithTarget extends WithParent {
- private final ParserTarget target;
-
- WithTarget(final ImmutableParserConfig parent, final ParserTarget target) {
- super(parent);
- this.target = target;
- }
-
- @Override
- public Optional<ParserTarget> target() {
- return Optional.ofNullable(target);
- }
- }
-
- @SuppressWarnings("rawtypes")
- private static final class WithSource extends WithParent {
- private final ParserSource source;
-
- WithSource(ImmutableParserConfig parent, ParserSource source) {
- super(parent);
- this.source = source;
- }
-
- @Override
- public Optional<ParserSource> source() {
- return Optional.ofNullable(source);
- }
- }
-
- private static final class WithSyntax extends WithParent {
- private final RDFSyntax syntax;
-
- WithSyntax(ImmutableParserConfig parent, RDFSyntax syntax) {
- super(parent);
- this.syntax = syntax;
- }
-
- @Override
- public Optional<RDFSyntax> syntax() {
- return Optional.ofNullable(syntax);
- }
- }
-
- abstract static class WithParent extends NullParserConfig implements ImmutableParserConfig {
- private final ImmutableParserConfig parent;
-
- /**
- * Override which object to use by Serializable, avoiding
- * serialization of the whole WithParent tree.
- *
- * This method is protected so it will be invoked for all subclasses of
- * WithParent.
- *
- * @return a {@link SnapshotParserConfig}
- * @throws ObjectStreamException
- */
- protected Object writeReplace() throws ObjectStreamException {
- return new SnapshotParserConfig(this);
- }
-
- WithParent(ImmutableParserConfig parserConfig) {
- this.parent = Objects.requireNonNull(parserConfig);
- }
-
- @SuppressWarnings("rawtypes")
- @Override
- public Optional<ParserSource> source() {
- return parent.source();
- }
-
- @Override
- public Optional<IRI> base() {
- return parent.base();
- }
-
- @SuppressWarnings("rawtypes")
- @Override
- public Optional<ParserTarget> target() {
- return parent.target();
- }
-
- @Override
- public Optional<RDFSyntax> syntax() {
- return parent.syntax();
- }
-
- @Override
- public Optional<RDF> rdf() {
- return parent.rdf();
- }
-
- @SuppressWarnings("rawtypes")
- @Override
- public Map<Option, Object> options() {
- return parent.options();
- }
- }
-
- @SuppressWarnings("rawtypes")
- final static class SnapshotParserConfig extends NullParserConfig {
- private static final long serialVersionUID = 1L;
- private final RDF rdf;
- private final RDFSyntax syntax;
- private final IRI base;
- private final ParserSource source;
- private final ParserTarget target;
- private final Map<Option, Object> options;
-
- SnapshotParserConfig(ParserConfig old) {
- this(
- old.rdf().orElse(null),
- old.syntax().orElse(null),
- old.base().orElse(null),
- old.source().orElse(null),
- old.target().orElse(null),
- old.options());
- }
-
- SnapshotParserConfig(RDF rdf, RDFSyntax syntax, IRI base, ParserSource source, ParserTarget target, Map<Option, Object> options) {
- this.rdf = rdf;
- this.syntax = syntax;
- this.base = base;
- this.source = source;
- this.target = target;
- // We'll make a copy
- this.options = Collections.unmodifiableMap(new HashMap<Option, Object>(options));
- }
-
- @Override
- public Optional<ParserSource> source() {
- return Optional.ofNullable(source);
- }
-
- @Override
- public Optional<IRI> base() {
- return Optional.ofNullable(base);
- }
-
- @Override
- public Optional<ParserTarget> target() {
- return Optional.ofNullable(target);
- }
-
- @Override
- public Optional<RDFSyntax> syntax() {
- return Optional.ofNullable(syntax);
- }
-
- @Override
- public Optional<RDF> rdf() {
- return Optional.ofNullable(rdf);
- }
-
- @Override
- public Map<Option, Object> 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/f9613b90/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/NullWriterConfig.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/NullWriterConfig.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/NullWriterConfig.java
deleted file mode 100644
index e26cfaf..0000000
--- a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/NullWriterConfig.java
+++ /dev/null
@@ -1,252 +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.Serializable;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Optional;
-import java.util.concurrent.ExecutorService;
-
-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.WriterConfig.ImmutableWriterConfig;
-
-class NullWriterConfig implements ImmutableWriterConfig, Serializable {
-
- private static final long serialVersionUID = 1L;
-
- @Override
- public Optional<WriterSource> source() {
- return Optional.empty();
- }
-
- @Override
- public Optional<WriterTarget> target() {
- return Optional.empty();
- }
-
- @Override
- public Optional<RDFSyntax> syntax() {
- return Optional.empty();
- }
-
- @Override
- public Optional<RDF> rdf() {
- return Optional.empty();
- }
-
- @SuppressWarnings("rawtypes")
- @Override
- public Map<Option, Object> options() {
- return Collections.emptyMap();
- }
-
- @Override
- public WriterConfig withSyntax(RDFSyntax syntax) {
- return new WithSyntax(this, syntax);
- }
-
- @Override
- public WriterConfig withSource(WriterSource source) {
- return new WithSource(this, source);
- }
-
- @Override
- public WriterConfig withTarget(WriterTarget target) {
- return new WithTarget(this, target);
- }
-
- @Override
- public WriterConfig withRDF(RDF rdf) {
- return new WithRDF(this, rdf);
- }
-
- @Override
- public <V> WriterConfig withOption(Option<V> o, V v) {
- return new WithOption(this, o, v);
- }
-
- static class WithParent extends NullWriterConfig implements ImmutableWriterConfig {
- private final ImmutableWriterConfig parent;
-
- WithParent(ImmutableWriterConfig parent) {
- this.parent = parent;
- }
-
- @Override
- public Optional<WriterSource> source() {
- return parent.source();
- }
-
- @Override
- public Optional<WriterTarget> target() {
- return parent.target();
- }
-
- @Override
- public Optional<RDFSyntax> syntax() {
- return parent.syntax();
- }
-
- @Override
- public Optional<RDF> rdf() {
- return parent.rdf();
- }
-
- @Override
- public Map<Option, Object> options() {
- return parent.options();
- }
- }
-
- static final class WithSyntax extends WithParent implements WriterConfig {
- private final RDFSyntax syntax;
-
- public WithSyntax(ImmutableWriterConfig parent, RDFSyntax syntax) {
- super(parent);
- this.syntax = syntax;
- }
-
- @Override
- public Optional<RDFSyntax> syntax() {
- return Optional.ofNullable(syntax);
- }
- }
-
- static final class WithSource extends WithParent implements WriterConfig {
- private final WriterSource source;
-
- public WithSource(ImmutableWriterConfig parent, WriterSource source) {
- super(parent);
- this.source = source;
- }
-
- @Override
- public Optional<WriterSource> source() {
- return Optional.ofNullable(source);
- }
- }
-
- static class WithTarget extends WithParent implements WriterConfig {
- private final WriterTarget target;
-
- public WithTarget(ImmutableWriterConfig parent, WriterTarget target) {
- super(parent);
- this.target = target;
- }
-
- @Override
- public Optional<WriterTarget> target() {
- return Optional.ofNullable(target);
- }
- }
-
- static class WithRDF extends WithParent implements WriterConfig {
- private final RDF rdf;
-
- public WithRDF(ImmutableWriterConfig parent, RDF rdf) {
- super(parent);
- this.rdf = rdf;
- }
- @Override
- public Optional<RDF> rdf() {
- return Optional.ofNullable(rdf);
- }
-
- }
-
- static class WithOption extends WithParent implements WriterConfig {
- private Option o;
- private Object v;
- public <V> WithOption(ImmutableWriterConfig parent, Option<V> o, V v) {
- super(parent);
- this.o = o;
- this.v = v;
- }
- @Override
- public Map<Option, Object> options() {
- // Add to parent options
- Map<Option, Object> options = super.options();
- if (v == null) {
- options.remove(o);
- } else {
- options.put(o, v);
- }
- return options;
- }
- }
-
- @SuppressWarnings("rawtypes")
- final static class SnapshotWriterConfig extends NullWriterConfig {
- private static final long serialVersionUID = 1L;
- private final RDF rdf;
- private final RDFSyntax syntax;
- private final WriterSource source;
- private final WriterTarget target;
- private final Map<Option, Object> options;
-
- SnapshotWriterConfig(WriterConfig old) {
- this(
- old.rdf().orElse(null),
- old.syntax().orElse(null),
- old.source().orElse(null),
- old.target().orElse(null),
- old.options(),
- null);
- }
-
- SnapshotWriterConfig(RDF rdf, RDFSyntax syntax, WriterSource source, WriterTarget target, Map<Option, Object> options,
- ExecutorService executor) {
- this.rdf = rdf;
- this.syntax = syntax;
- this.source = source;
- this.target = target;
- // We'll make a copy
- this.options = Collections.unmodifiableMap(new HashMap<Option, Object>(options));
- }
-
- @Override
- public Optional<WriterSource> source() {
- return Optional.ofNullable(source);
- }
-
- @Override
- public Optional<WriterTarget> target() {
- return Optional.ofNullable(target);
- }
-
- @Override
- public Optional<RDFSyntax> syntax() {
- return Optional.ofNullable(syntax);
- }
-
- @Override
- public Optional<RDF> rdf() {
- return Optional.ofNullable(rdf);
- }
-
- @Override
- public Map<Option, Object> options() {
- // return a mutable copy so our children can build on it
- return new HashMap<Option,Object>(options);
- }
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/f9613b90/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 ee7d65f..50aa0ae 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
@@ -23,7 +23,7 @@ import java.util.Optional;
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.NullParserConfig.SnapshotParserConfig;
+import org.apache.commons.rdf.api.io.ImmutableParserConfigImpl.SnapshotParserConfig;
@SuppressWarnings("rawtypes")
public interface ParserConfig {
@@ -46,8 +46,8 @@ public interface ParserConfig {
<V> ParserConfig withOption(Option<V> o, V v);
- static ParserConfig immutable() {
- return new NullParserConfig();
+ static ImmutableParserConfig immutable() {
+ return new ImmutableParserConfigImpl();
}
static ParserConfig mutable() {
http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/f9613b90/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/WriterConfig.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/WriterConfig.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/WriterConfig.java
index bbe781f..8385b4a 100644
--- a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/WriterConfig.java
+++ b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/WriterConfig.java
@@ -22,7 +22,7 @@ import java.util.Optional;
import org.apache.commons.rdf.api.RDF;
import org.apache.commons.rdf.api.RDFSyntax;
-import org.apache.commons.rdf.api.io.NullWriterConfig.SnapshotWriterConfig;
+import org.apache.commons.rdf.api.io.ImmutableWriterConfigImpl.SnapshotWriterConfig;
@SuppressWarnings("rawtypes")
public interface WriterConfig {
@@ -39,8 +39,8 @@ public interface WriterConfig {
<V> WriterConfig withOption(Option<V> o, V v);
- static WriterConfig immutable() {
- return new NullWriterConfig();
+ static ImmutableWriterConfig immutable() {
+ return new ImmutableWriterConfigImpl();
}
static WriterConfig mutable() {