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/15 01:55:09 UTC

[14/17] commons-rdf git commit: Export inner classes

Export inner classes


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

Branch: refs/heads/fluent-parser
Commit: 725e8d086a0306ccdb120d117ee9c59bb7f11e3e
Parents: fb9a60b
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Thu Feb 15 00:55:04 2018 +0000
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Thu Feb 15 00:55:04 2018 +0000

----------------------------------------------------------------------
 .../rdf/api/io/AbstractParserFactory.java       | 178 ++-----------------
 .../org/apache/commons/rdf/api/io/IRIImpl.java  |  47 +++++
 .../commons/rdf/api/io/IRIParserSource.java     |  47 +++++
 .../commons/rdf/api/io/InputParserSource.java   |  44 +++++
 .../commons/rdf/api/io/ParserConfigImpl.java    |  90 ++++++++++
 .../commons/rdf/api/io/PathParserSource.java    |  49 +++++
 6 files changed, 291 insertions(+), 164 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/725e8d08/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/AbstractParserFactory.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/AbstractParserFactory.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/AbstractParserFactory.java
index 2e37b81..725a569 100644
--- a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/AbstractParserFactory.java
+++ b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/AbstractParserFactory.java
@@ -16,15 +16,9 @@
  */
 package org.apache.commons.rdf.api.io;
 
-import java.io.IOException;
 import java.io.InputStream;
 import java.io.Serializable;
-import java.net.URL;
-import java.nio.file.Files;
 import java.nio.file.Path;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Optional;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Future;
 
@@ -66,170 +60,26 @@ Async {
 		}
 	}
 
-	static final class InputParserSource implements ParserSource {
-		private final InputStream is;
-
-		private 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();
-		}
-	}
-
-	private final class PathParserSource implements ParserSource<Path> {
-		private final Path path;
-
-		private PathParserSource(Path path) {
-			this.path = path;
-		}
-
-		@Override
-		public Path src() {
-			return path;
-		}
-
-		@Override
-		public InputStream inputStream() throws IOException {
-			return Files.newInputStream(path);
-		}
+	private boolean mutable = false;
+	private ParserConfigImpl config = new ParserConfigImpl();
 
-		@Override
-		public Optional<IRI> iri() {
-			final String uri = path.toUri().toString();
-			return Optional.of(new IRIImpl(uri));
-		}
+	@Override
+	public NeedTargetOrRDF syntax(RDFSyntax syntax) {
+		return mutate(config::withSyntax, syntax);
 	}
 
-	private final class IRIParserSource implements ParserSource<IRI> {
-		private final IRI iri;
-
-		private 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);
-		}
+	@FunctionalInterface
+	private interface WithValue<V> {
+		ParserConfig withValue(V value); 
 	}
-
-	private final class IRIImpl implements IRI {
-		private final String uri;
-
-		private IRIImpl(String uri) {
-			this.uri = uri;
-		}
-
-		@Override
-		public String ntriplesString() {
-			return "<" + uri + ">";
-		}
-
-		@Override
-		public String getIRIString() {
-			return uri;
-		}
-
-		@Override
-		public boolean equals(Object obj) {
-			return (obj instanceof IRI) && ((IRI) obj).getIRIString().equals(uri);
-		}
-
-		@Override
-		public int hashCode() {
-			return uri.hashCode();
-		}
-	}
-
-	public static 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;
-		private ParserSource source = null;
-		private ParserTarget target = null;
-		final private  Map<Option, Object> options = new HashMap<>();
-
-		public ParserConfigImpl() {
-		}
-		
-		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;
+	
+	private AbstractParserFactory mutate(WithValue<V> valueFunc, V value) {
+		if (mutable) {
+			return valueFunc.withValue(value);
+		} else {
+			mutable().mutate(valueFunc, value);
 		}
 		
-		
-	}
-	private boolean mutable = false;
-	private ParserConfigImpl config = new ParserConfigImpl();
-
-	@Override
-	public NeedTargetOrRDF syntax(RDFSyntax syntax) {
-		AbstractParserFactory c = mutable();
-		c.config.syntax = syntax;
-		return c;
 	}
 
 	private AbstractParserFactory mutable(boolean mutable) {

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/725e8d08/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/IRIImpl.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/IRIImpl.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/IRIImpl.java
new file mode 100644
index 0000000..fa65e98
--- /dev/null
+++ b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/IRIImpl.java
@@ -0,0 +1,47 @@
+/*
+ * 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 org.apache.commons.rdf.api.IRI;
+
+final class IRIImpl implements IRI {
+	private final String uri;
+
+	IRIImpl(String uri) {
+		this.uri = uri;
+	}
+
+	@Override
+	public String ntriplesString() {
+		return "<" + uri + ">";
+	}
+
+	@Override
+	public String getIRIString() {
+		return uri;
+	}
+
+	@Override
+	public boolean equals(Object obj) {
+		return (obj instanceof IRI) && ((IRI) obj).getIRIString().equals(uri);
+	}
+
+	@Override
+	public int hashCode() {
+		return uri.hashCode();
+	}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/725e8d08/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
new file mode 100644
index 0000000..83a5ea4
--- /dev/null
+++ b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/IRIParserSource.java
@@ -0,0 +1,47 @@
+/*
+ * 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/725e8d08/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
new file mode 100644
index 0000000..5a99e4b
--- /dev/null
+++ b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/InputParserSource.java
@@ -0,0 +1,44 @@
+/*
+ * 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/725e8d08/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
new file mode 100644
index 0000000..a61e50e
--- /dev/null
+++ b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/ParserConfigImpl.java
@@ -0,0 +1,90 @@
+/*
+ * 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 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;
+	private ParserSource source = null;
+	private ParserTarget target = null;
+	private final  Map<Option, Object> options = new HashMap<>();
+
+	public ParserConfigImpl() {
+	}
+	
+	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;
+	}
+
+	ParserConfig withSyntax(RDFSyntax syntax) {		
+		this.syntax = syntax;
+		return this;
+	}
+	
+	
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/725e8d08/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
new file mode 100644
index 0000000..7c6e14c
--- /dev/null
+++ b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/PathParserSource.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.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