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/19 12:53:55 UTC

[1/3] commons-rdf git commit: Mutable/Immutable config

Repository: commons-rdf
Updated Branches:
  refs/heads/fluent-parser 8fad253a6 -> 9c22589a6


Mutable/Immutable config

Immutable using With* mini-classes for specializations

thus immutable stays immutable


Project: http://git-wip-us.apache.org/repos/asf/commons-rdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-rdf/commit/648f18b2
Tree: http://git-wip-us.apache.org/repos/asf/commons-rdf/tree/648f18b2
Diff: http://git-wip-us.apache.org/repos/asf/commons-rdf/diff/648f18b2

Branch: refs/heads/fluent-parser
Commit: 648f18b298ef4540c244ab0af8274fad15bfa532
Parents: 8fad253
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Mon Feb 19 08:57:29 2018 +0000
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Mon Feb 19 08:57:29 2018 +0000

----------------------------------------------------------------------
 .../rdf/api/io/AbstractParserBuilder.java       |  10 +-
 .../apache/commons/rdf/api/io/AsyncImpl.java    |  48 ---
 .../commons/rdf/api/io/MutableParserConfig.java | 119 +++++++
 .../commons/rdf/api/io/NullParserConfig.java    | 307 +++++++++++++++++++
 .../apache/commons/rdf/api/io/ParserConfig.java |  43 ++-
 .../commons/rdf/api/io/ParserConfigImpl.java    | 120 --------
 .../rdf/api/io/SnapshotParserConfig.java        |  29 ++
 7 files changed, 502 insertions(+), 174 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/648f18b2/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/AbstractParserBuilder.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/AbstractParserBuilder.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/AbstractParserBuilder.java
index 5bd27f1..03c6b93 100644
--- a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/AbstractParserBuilder.java
+++ b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/AbstractParserBuilder.java
@@ -48,14 +48,14 @@ public final class AbstractParserBuilder implements Cloneable, Serializable, Nee
     private static final ExecutorService DEFAULT_EXECUTOR = Executors.newCachedThreadPool(r -> new Thread(THEAD_GROUP, r));
 	
 	public AbstractParserBuilder(RDF rdf) {
-		this.config = new ParserConfigImpl(rdf);
+		this.config = ParserConfig.mutable().withRDF(rdf);
 	}
 	
 	@Override
 	public AbstractParserBuilder clone() {		
 		try {
 			AbstractParserBuilder c = (AbstractParserBuilder) super.clone();
-			c.config = (ParserConfigImpl) config.clone();
+			c.config = (MutableParserConfig) config.clone();
 			return c;
 		} catch (CloneNotSupportedException e) {
 			throw new IllegalStateException("AbstractParserBuilder was not Cloneable", e);
@@ -63,7 +63,7 @@ public final class AbstractParserBuilder implements Cloneable, Serializable, Nee
 	}
 
 	private boolean mutable = false;
-	private ParserConfigImpl config;
+	private ParserConfig config;
 	private ExecutorService executor = DEFAULT_EXECUTOR;
 
 	@Override
@@ -194,12 +194,12 @@ public final class AbstractParserBuilder implements Cloneable, Serializable, Nee
 	@Override
 	public Parsed parse() {
 		// ensure immutable copy of config
-		ParserConfigImpl c = mutable(false).config;
+		MutableParserConfig c = mutable(false).config;
 		Parser parser = getParserOrFail(c);
 		return parser.parse(c);
 	}
 
-	private Parser getParserOrFail(ParserConfigImpl c) {
+	private Parser getParserOrFail(MutableParserConfig c) {
 		if (! c.rdf().isPresent()) {
 			throw new IllegalStateException("ParserState has no RDF instance configured");
 		}

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/648f18b2/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/AsyncImpl.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/AsyncImpl.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/AsyncImpl.java
deleted file mode 100644
index 2c0c0d5..0000000
--- a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/AsyncImpl.java
+++ /dev/null
@@ -1,48 +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.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
-
-import org.apache.commons.rdf.api.fluentparser.Async;
-
-public class AsyncImpl implements Async {
-
-    public static final ThreadGroup threadGroup = new ThreadGroup("Commons RDF parsers");
-    private static final ExecutorService threadpool = Executors.newCachedThreadPool(r -> new Thread(threadGroup, r));
-	
-	@Override
-	public Async build() {
-		// TODO Auto-generated method stub
-		return null;
-	}
-
-	@Override
-	public Async option(Option option, Object value) {
-		// TODO Auto-generated method stub
-		return null;
-	}
-
-	@Override
-	public Future parseAsync() {
-		// TODO Auto-generated method stub
-		return null;
-	}
-
-}

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/648f18b2/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
new file mode 100644
index 0000000..7a43f74
--- /dev/null
+++ b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/MutableParserConfig.java
@@ -0,0 +1,119 @@
+/*
+ * 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.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;
+
+final class MutableParserConfig implements Cloneable, Serializable, ParserConfig {
+	private static final long serialVersionUID = 1L;
+	private RDF rdf = null;
+	private RDFSyntax syntax = null;
+	private IRI base = null;
+	@SuppressWarnings("rawtypes")
+	private ParserSource source = null;
+	@SuppressWarnings("rawtypes")
+	private ParserTarget target = null;
+	private final Map<Option, Object> options = new HashMap<>();
+	private ExecutorService executor;
+
+	public MutableParserConfig() {
+	}
+
+	public MutableParserConfig(ParserConfig old) {
+		rdf = old.rdf().orElse(null);
+		syntax = old.syntax().orElse(null);
+		base = old.base().orElse(null);
+		source = old.source().orElse(null);
+		target = old.target().orElse(null);
+		options.putAll(old.options());
+	}
+
+	@Override
+	protected Object clone() {
+		return new MutableParserConfig(this);
+	}
+
+	@Override
+	public Optional<ParserSource> source() {
+		return Optional.of(source);
+	}
+
+	@Override
+	public Optional<IRI> base() {
+		return Optional.of(base);
+	}
+
+	@Override
+	public Optional<ParserTarget> target() {
+		return Optional.of(target);
+	}
+
+	@Override
+	public Optional<RDFSyntax> syntax() {
+		return Optional.of(syntax);
+	}
+
+	@Override
+	public Optional<RDF> rdf() {
+		return Optional.of(rdf);
+	}
+
+	@Override
+	public Map<Option, Object> options() {
+		return options;
+	}
+
+	public ParserConfig withSyntax(RDFSyntax syntax) {
+		this.syntax = syntax;
+		return this;
+	}
+
+	@SuppressWarnings("rawtypes")
+	public ParserConfig withSource(ParserSource source) {
+		this.source = source;
+		return this;
+	}
+
+	public ParserConfig withTarget(ParserTarget target) {
+		this.target = target;
+		return this;
+	}
+
+	public ParserConfig withRDF(RDF rdf) {
+		this.rdf = rdf;
+		return this;
+	}
+
+	public ParserConfig withBase(IRI base) {
+		this.base = base;
+		return this;
+	}
+
+	public <V> ParserConfig withOption(Option<V> o, V v) {
+		this.options.put(o, v);
+		return this;
+	}
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/648f18b2/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
new file mode 100644
index 0000000..e993949
--- /dev/null
+++ b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/NullParserConfig.java
@@ -0,0 +1,307 @@
+/*
+ * 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() {
+		return Collections.emptyMap();
+	}
+
+	@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 WithOptional(this, o, v);
+	}
+
+	@SuppressWarnings("rawtypes")
+	final class WithOptional extends WithParent {
+
+		private final Map<Option, Object> options;
+
+		public <V> WithOptional(final ImmutableParserConfig parent, final Option<V> o, V v) {
+			super(parent);
+			this.options = new HashMap<>(parent.options());
+			options.put(o, v);
+		}
+
+		@Override
+		public Map<Option, Object> options() {
+			return options;
+		}
+
+	}
+
+	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.of(base);
+		}
+	}
+
+	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.of(rdf);
+		}
+	}
+
+	@SuppressWarnings("rawtypes")
+	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.of(target);
+		}
+	}
+
+	@SuppressWarnings("rawtypes")
+	public 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.of(source);
+		}
+	}
+
+	static 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.of(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 = new HashMap<>();
+		private final ExecutorService executor;
+
+		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(),
+				null);
+		}
+		
+		SnapshotParserConfig(RDF rdf, RDFSyntax syntax, IRI base, ParserSource source, ParserTarget target, Map<Option, Object> options, 
+				ExecutorService executor) {
+			this.rdf = rdf;
+			this.syntax = syntax;
+			this.base = base;
+			this.source = source;
+			this.target = target;
+			this.options.putAll(options);
+			this.executor = executor;				
+		}
+
+		@Override
+		public Optional<ParserSource> source() {
+			return Optional.of(source);
+		}
+
+		@Override
+		public Optional<IRI> base() {
+			return Optional.of(base);
+		}
+
+		@Override
+		public Optional<ParserTarget> target() {
+			return Optional.of(target);
+		}
+
+		@Override
+		public Optional<RDFSyntax> syntax() {
+			return Optional.of(syntax);
+		}
+
+		@Override
+		public Optional<RDF> rdf() {
+			return Optional.of(rdf);
+		}
+
+		@Override
+		public Map<Option, Object> options() {
+			return options;
+		}
+	}	
+}

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/648f18b2/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 d18a268..b767dcc 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
@@ -16,14 +16,17 @@
  */
 package org.apache.commons.rdf.api.io;
 
+import java.io.Serializable;
 import java.util.Map;
 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;
 
-public interface ParserConfig {
+@SuppressWarnings("rawtypes")
+interface ParserConfig {
 	Optional<ParserSource> source();
 	Optional<IRI> base();
 	Optional<ParserTarget> target();
@@ -31,4 +34,42 @@ public interface ParserConfig {
 	Optional<RDF> rdf();
 	Map<Option, Object> options();
 	
+	ParserConfig withSyntax(RDFSyntax syntax);
+
+	ParserConfig withSource(ParserSource source);
+
+	ParserConfig withTarget(ParserTarget target);
+
+	ParserConfig withRDF(RDF rdf);
+
+	ParserConfig withBase(IRI base);
+
+	<V> ParserConfig withOption(Option<V> o, V v);	
+	
+	static ParserConfig immutable() {
+		return new NullParserConfig();
+	}
+
+	static ParserConfig mutable() {
+		return new MutableParserConfig();
+	}
+	
+	default ParserConfig asMutableConfig() {
+		if (this instanceof MutableParserConfig) {
+			return this;
+		} else {
+			return new MutableParserConfig(this);
+		}
+	}
+	
+	default ParserConfig asImmutableConfig() {
+		if (this instanceof ImmutableParserConfig) {
+			return this;
+		} else {
+			return new SnapshotParserConfig(this);
+		}
+	}
+	
+	interface ImmutableParserConfig extends ParserConfig, Serializable {} 
+
 }

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/648f18b2/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/ParserConfigImpl.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/ParserConfigImpl.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/ParserConfigImpl.java
deleted file mode 100644
index 2062b6e..0000000
--- a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/ParserConfigImpl.java
+++ /dev/null
@@ -1,120 +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.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;
-
-public final class ParserConfigImpl implements Cloneable, Serializable, ParserConfig {
-	private static final long serialVersionUID = 1L;
-	private RDF rdf = null;
-	private RDFSyntax syntax = null;
-	private IRI base = null;
-	@SuppressWarnings("rawtypes")
-	private ParserSource source = null;
-	@SuppressWarnings("rawtypes")
-	private ParserTarget target = null;
-	private final Map<Option, Object> options = new HashMap<>();
-	private ExecutorService executor;
-
-	public ParserConfigImpl(RDF rdf) {
-		this.rdf = rdf;
-	}
-
-	public ParserConfigImpl(ParserConfig old) {
-		rdf = old.rdf().orElse(null);
-		syntax = old.syntax().orElse(null);
-		base = old.base().orElse(null);
-		source = old.source().orElse(null);
-		target = old.target().orElse(null);
-		options.putAll(old.options());
-	}
-
-	@Override
-	protected Object clone() {
-		return new ParserConfigImpl(this);
-	}
-
-	@Override
-	public Optional<ParserSource> source() {
-		return Optional.of(source);
-	}
-
-	@Override
-	public Optional<IRI> base() {
-		return Optional.of(base);
-	}
-
-	@Override
-	public Optional<ParserTarget> target() {
-		return Optional.of(target);
-	}
-
-	@Override
-	public Optional<RDFSyntax> syntax() {
-		return Optional.of(syntax);
-	}
-
-	@Override
-	public Optional<RDF> rdf() {
-		return Optional.of(rdf);
-	}
-
-	@Override
-	public Map<Option, Object> options() {
-		return options;
-	}
-
-	public ParserConfig withSyntax(RDFSyntax syntax) {
-		this.syntax = syntax;
-		return this;
-	}
-
-	@SuppressWarnings("rawtypes")
-	public ParserConfig withSource(ParserSource source) {
-		this.source = source;
-		return this;
-	}
-
-	public ParserConfig withTarget(ParserTarget target) {
-		this.target = target;
-		return this;
-	}
-
-	public ParserConfig withRDF(RDF rdf) {
-		this.rdf = rdf;
-		return this;
-	}
-
-	public ParserConfig withBase(IRI base) {
-		this.base = base;
-		return this;
-	}
-
-	public <V> ParserConfig withOption(Option<V> o, V v) {
-		this.options.put(o, v);
-		return this;
-	}
-
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/648f18b2/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/SnapshotParserConfig.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/SnapshotParserConfig.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/SnapshotParserConfig.java
new file mode 100644
index 0000000..47e7ce9
--- /dev/null
+++ b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/SnapshotParserConfig.java
@@ -0,0 +1,29 @@
+/*
+ * 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.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.ParserConfig.ImmutableParserConfig;
+


[2/3] commons-rdf git commit: Builder uses Immutable/Mutable config

Posted by st...@apache.org.
Builder uses Immutable/Mutable config


Project: http://git-wip-us.apache.org/repos/asf/commons-rdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-rdf/commit/2dfd4914
Tree: http://git-wip-us.apache.org/repos/asf/commons-rdf/tree/2dfd4914
Diff: http://git-wip-us.apache.org/repos/asf/commons-rdf/diff/2dfd4914

Branch: refs/heads/fluent-parser
Commit: 2dfd491432407a1dfca018b89bb353dce58b2d9d
Parents: 648f18b
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Mon Feb 19 09:08:59 2018 +0000
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Mon Feb 19 09:08:59 2018 +0000

----------------------------------------------------------------------
 .../rdf/api/io/AbstractParserBuilder.java       | 214 -------------------
 .../apache/commons/rdf/api/io/ParserConfig.java |   4 +-
 .../commons/rdf/api/io/ParserConfigBuilder.java | 150 +++++++++++++
 3 files changed, 152 insertions(+), 216 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/2dfd4914/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/AbstractParserBuilder.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/AbstractParserBuilder.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/AbstractParserBuilder.java
deleted file mode 100644
index 03c6b93..0000000
--- a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/AbstractParserBuilder.java
+++ /dev/null
@@ -1,214 +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.InputStream;
-import java.io.Serializable;
-import java.nio.file.Path;
-import java.util.Optional;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
-
-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.RDF;
-import org.apache.commons.rdf.api.RDFSyntax;
-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;
-
-@SuppressWarnings({ "unchecked", "rawtypes" })
-public final class AbstractParserBuilder implements Cloneable, Serializable, NeedTargetOrRDF, NeedTargetOrRDFOrSyntax,
-		NeedSourceOrBase, NeedSourceBased, OptionalTarget, Sync, Async {
-
-	private static final long serialVersionUID = 1L;
-
-
-    private static final ThreadGroup THEAD_GROUP = new ThreadGroup("Commons RDF parsers");
-    private static final ExecutorService DEFAULT_EXECUTOR = Executors.newCachedThreadPool(r -> new Thread(THEAD_GROUP, r));
-	
-	public AbstractParserBuilder(RDF rdf) {
-		this.config = ParserConfig.mutable().withRDF(rdf);
-	}
-	
-	@Override
-	public AbstractParserBuilder clone() {		
-		try {
-			AbstractParserBuilder c = (AbstractParserBuilder) super.clone();
-			c.config = (MutableParserConfig) config.clone();
-			return c;
-		} catch (CloneNotSupportedException e) {
-			throw new IllegalStateException("AbstractParserBuilder was not Cloneable", e);
-		}
-	}
-
-	private boolean mutable = false;
-	private ParserConfig config;
-	private ExecutorService executor = DEFAULT_EXECUTOR;
-
-	@Override
-	public NeedTargetOrRDF syntax(RDFSyntax syntax) {
-		AbstractParserBuilder c = mutable();
-		c.config.withSyntax(syntax);
-		return c;
-	}
-
-	private AbstractParserBuilder mutable(boolean mutable) {
-		if (this.mutable == mutable) {
-			return this;
-		} else {
-			AbstractParserBuilder c = clone();
-			c.mutable = mutable;
-			return c;
-		}
-	}
-
-	private AbstractParserBuilder mutable() {
-		return mutable(true);
-	}
-
-	@Override
-	public AbstractParserBuilder build() {
-		return mutable(false);
-	}
-
-	@Override
-	public NeedSourceOrBase target(Dataset dataset) {
-		return target(dataset::add);
-
-	}
-
-	@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());
-			}
-		});
-	}
-
-	@Override
-	public <T> NeedSourceOrBase<T> target(ParserTarget<T> target) {
-		AbstractParserBuilder c = mutable();
-		c.config.withTarget(target);
-		return c;
-	}
-
-	@Override
-	public NeedSourceBased base(IRI iri) {
-		AbstractParserBuilder c = mutable();
-		c.config.withBase(iri);
-		return c;
-	}
-
-	@Override
-	public NeedSourceBased base(String iri) {
-		AbstractParserBuilder c = mutable();
-		c.config.withBase(new IRIImpl(iri));
-		return c;
-	}
-
-	@Override
-	public Sync source(final IRI iri) {
-		return source(new IRIParserSource(iri));
-	}
-
-	public Sync source(Path path) {
-		return source(new PathParserSource(path));
-	}
-
-	@Override
-	public OptionalTarget<Dataset> rdf(RDF rdf) {
-		AbstractParserBuilder c = mutable();
-		c.config.withRDF(rdf);
-		return c;
-	}
-
-	@Override
-	public Sync source(ParserSource source) {
-		AbstractParserBuilder c = mutable();
-		c.config.withSource(source);
-		return c;
-	}
-
-	@Override
-	public Sync source(String iri) {
-		return source(new IRIImpl(iri));
-	}
-
-	@Override
-	public AbstractParserBuilder option(Option option, Object value) {
-		AbstractParserBuilder c = mutable();
-		c.config.withOption(option, value);
-		return c;
-	}
-
-	@Override
-	public Future<Parsed> parseAsync() {
-		// Ensure immutable
-		AbstractParserBuilder frozen = mutable(false);
-		Parser parser = getParserOrFail(frozen.config);		
-		return frozen.executor.submit(() -> parser.parse(frozen.config));
-	}
-
-	@Override
-	public Async async() {
-		AbstractParserBuilder c = mutable();
-		c.executor = DEFAULT_EXECUTOR;
-		return c;
-	}
-
-	@Override
-	public Async async(ExecutorService executor) {
-		AbstractParserBuilder c = mutable();
-		c.executor = executor;
-		return c;
-	}
-
-	@Override
-	public Sync source(InputStream is) {
-		return source(new InputParserSource(is));
-	}
-
-	@Override
-	public Parsed parse() {
-		// ensure immutable copy of config
-		MutableParserConfig c = mutable(false).config;
-		Parser parser = getParserOrFail(c);
-		return parser.parse(c);
-	}
-
-	private Parser getParserOrFail(MutableParserConfig c) {
-		if (! c.rdf().isPresent()) {
-			throw new IllegalStateException("ParserState has no RDF instance configured");
-		}
-		Optional<Parser> parser = c.rdf().get().parser(c.syntax().orElse(null));
-		if (! parser.isPresent()) { 
-			throw new IllegalStateException("Unsupported RDF syntax " 
-					+ c.syntax().map(t -> t.name() ).orElse("(guess)"));
-		}
-		return parser.get();
-	}
-
-}

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/2dfd4914/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 b767dcc..bb7f7c5 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
@@ -62,9 +62,9 @@ interface ParserConfig {
 		}
 	}
 	
-	default ParserConfig asImmutableConfig() {
+	default ImmutableParserConfig asImmutableConfig() {
 		if (this instanceof ImmutableParserConfig) {
-			return this;
+			return (ImmutableParserConfig) this;
 		} else {
 			return new SnapshotParserConfig(this);
 		}

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/2dfd4914/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
new file mode 100644
index 0000000..3409173
--- /dev/null
+++ b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/ParserConfigBuilder.java
@@ -0,0 +1,150 @@
+/*
+ * 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.InputStream;
+import java.io.Serializable;
+import java.nio.file.Path;
+import java.util.Optional;
+
+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.RDF;
+import org.apache.commons.rdf.api.RDFSyntax;
+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 Serializable, NeedTargetOrRDF, NeedTargetOrRDFOrSyntax,
+		NeedSourceOrBase, NeedSourceBased, OptionalTarget, Sync, Async {
+
+	private static final long serialVersionUID = 1L;
+
+	public ParserConfigBuilder(ParserConfig mutated) {
+		this.config = mutated;
+	}	
+	private final ParserConfig config;
+	private ParserConfigBuilder mutate(ParserConfig mutated) {
+		if (mutated == config) {
+			// We're mutable (or nothing changed)
+			return this;
+		} else {
+			return new ParserConfigBuilder(mutated);
+		}
+	}
+	
+	@Override
+	public NeedTargetOrRDF syntax(RDFSyntax syntax) {
+		return mutate(config.withSyntax(syntax));
+	}
+
+	public ParserConfig buildConfig() {
+		return config.asImmutableConfig();
+	}
+
+	@Override
+	public NeedSourceOrBase target(Dataset dataset) {
+		return target(dataset::add);
+
+	}
+
+	@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());
+			}
+		});
+	}
+
+	@Override
+	public <T> NeedSourceOrBase<T> target(ParserTarget<T> target) {
+		return mutate(config.withTarget(target));
+	}
+
+	@Override
+	public NeedSourceBased base(IRI iri) {
+		return mutate(config.withBase(iri));
+	}
+
+	@Override
+	public NeedSourceBased base(String iriStr) {
+		return base(new IRIImpl(iriStr));
+	}
+
+	@Override
+	public Sync source(final IRI iri) {
+		return source(new IRIParserSource(iri));
+	}
+
+	public Sync source(Path path) {
+		return source(new PathParserSource(path));
+	}
+
+	@Override
+	public OptionalTarget<Dataset> rdf(RDF rdf) {
+		return mutate(config.withRDF(rdf));
+	}
+
+	@Override
+	public Sync source(ParserSource source) {
+		return mutate(config.withSource(source));
+	}
+
+	@Override
+	public Sync source(String iri) {
+		return source(new IRIImpl(iri));
+	}
+
+	@Override
+	public ParserConfigBuilder option(Option option, Object value) {
+		return mutate(config.withOption(option, value));
+	}
+
+	@Override
+	public Sync source(InputStream is) {
+		return source(new InputParserSource(is));
+	}
+
+	@Override
+	public Parsed parse() {
+		ImmutableParserConfig c = config.asImmutableConfig();
+		Parser parser = getParserOrFail(c);
+		return parser.parse(c);
+	}
+
+	private static Parser getParserOrFail(ImmutableParserConfig c) {
+		if (! c.rdf().isPresent()) {
+			throw new IllegalStateException("ParserState has no RDF instance configured");
+		}
+		Optional<Parser> parser = c.rdf().get().parser(c.syntax().orElse(null));
+		if (! parser.isPresent()) { 
+			throw new IllegalStateException("Unsupported RDF syntax " 
+					+ c.syntax().map(t -> t.name() ).orElse("(guess)"));
+		}
+		return parser.get();
+	}
+
+}


[3/3] commons-rdf git commit: DefaultAsyncParser is now in Parser interface

Posted by st...@apache.org.
DefaultAsyncParser is now in Parser 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/9c22589a
Tree: http://git-wip-us.apache.org/repos/asf/commons-rdf/tree/9c22589a
Diff: http://git-wip-us.apache.org/repos/asf/commons-rdf/diff/9c22589a

Branch: refs/heads/fluent-parser
Commit: 9c22589a6b121646dbaeed19a9733328f61dec14
Parents: 2dfd491
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Mon Feb 19 09:23:53 2018 +0000
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Mon Feb 19 09:23:53 2018 +0000

----------------------------------------------------------------------
 .../commons/rdf/api/fluentparser/Sync.java      |  4 ---
 .../org/apache/commons/rdf/api/io/Parser.java   | 30 ++++++++++++++++++++
 .../commons/rdf/api/io/ParserConfigBuilder.java | 25 ++++++++++++----
 3 files changed, 50 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/9c22589a/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 14f321d..c877180 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
@@ -17,8 +17,6 @@
  */
 package org.apache.commons.rdf.api.fluentparser;
 
-import java.util.concurrent.ExecutorService;
-
 import org.apache.commons.rdf.api.io.Option;
 import org.apache.commons.rdf.api.io.Parsed;
 
@@ -26,9 +24,7 @@ public interface Sync<T, S> extends _Buildable {
 	
 	Sync<T, S> build();	
 	<V> Sync<T, S> option(Option<V> option, V value);
-
 	
     Async<T, S> async();
-    Async<T, S> async(ExecutorService executor);
     Parsed<T, S> parse();
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/9c22589a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/Parser.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/Parser.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/Parser.java
index 9e9a18a..a1040f2 100644
--- a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/Parser.java
+++ b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/Parser.java
@@ -16,9 +16,39 @@
  */
 package org.apache.commons.rdf.api.io;
 
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+
 public interface Parser {
 
 	@SuppressWarnings("rawtypes")
 	Parsed parse(ParserConfig config);
 
+	@SuppressWarnings("rawtypes")
+	default Future<Parsed> parseAsync(ParserConfig config) {
+		return new DefaultAsyncParser(this, config).submit();
+	}
+
+	class DefaultAsyncParser {
+		private static final ThreadGroup THEAD_GROUP = new ThreadGroup("Commons RDF async parser");
+		private static final ExecutorService DEFAULT_EXECUTOR = Executors
+				.newCachedThreadPool(r -> new Thread(THEAD_GROUP, r));
+		
+		private final Parser syncParser;
+		private final ParserConfig config;
+
+		DefaultAsyncParser(Parser parser, ParserConfig config) {
+			this.syncParser = parser;
+			this.config = config.asImmutableConfig();
+		}
+		
+		Parsed parse() {
+			return syncParser.parse(config);			
+		}
+
+		Future<Parsed> submit() {
+			return DEFAULT_EXECUTOR.submit(this::parse);
+		}
+	}
 }

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/9c22589a/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 3409173..9adc6ce 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
@@ -17,9 +17,9 @@
 package org.apache.commons.rdf.api.io;
 
 import java.io.InputStream;
-import java.io.Serializable;
 import java.nio.file.Path;
 import java.util.Optional;
+import java.util.concurrent.Future;
 
 import org.apache.commons.rdf.api.Dataset;
 import org.apache.commons.rdf.api.Graph;
@@ -36,11 +36,9 @@ 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 Serializable, NeedTargetOrRDF, NeedTargetOrRDFOrSyntax,
+public final class ParserConfigBuilder implements NeedTargetOrRDF, NeedTargetOrRDFOrSyntax,
 		NeedSourceOrBase, NeedSourceBased, OptionalTarget, Sync, Async {
 
-	private static final long serialVersionUID = 1L;
-
 	public ParserConfigBuilder(ParserConfig mutated) {
 		this.config = mutated;
 	}	
@@ -134,7 +132,7 @@ public final class ParserConfigBuilder implements Serializable, NeedTargetOrRDF,
 		Parser parser = getParserOrFail(c);
 		return parser.parse(c);
 	}
-
+	
 	private static Parser getParserOrFail(ImmutableParserConfig c) {
 		if (! c.rdf().isPresent()) {
 			throw new IllegalStateException("ParserState has no RDF instance configured");
@@ -147,4 +145,21 @@ public final class ParserConfigBuilder implements Serializable, NeedTargetOrRDF,
 		return parser.get();
 	}
 
+	@Override
+	public Future parseAsync() {
+		ImmutableParserConfig c = config.asImmutableConfig();
+		Parser parser = getParserOrFail(c);
+		return parser.parseAsync(c);		
+	}
+
+	@Override
+	public Async async() {
+		return this;
+	}
+
+	@Override
+	public ParserConfigBuilder build() {
+		return mutate(config.asImmutableConfig());
+	}
+
 }