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:04 UTC

[09/17] commons-rdf git commit: fluent API moved into commons-rdf-api/

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/96fb0f06/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentwriter/NeedTarget.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentwriter/NeedTarget.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentwriter/NeedTarget.java
new file mode 100644
index 0000000..2148b54
--- /dev/null
+++ b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentwriter/NeedTarget.java
@@ -0,0 +1,34 @@
+/**
+ * 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.fluentwriter;
+
+import java.io.OutputStream;
+import java.nio.file.Path;
+
+import org.apache.commons.rdf.api.io.Option;
+import org.apache.commons.rdf.api.io.WriterTarget;
+
+public interface NeedTarget extends _Buildable {
+    @Override
+    NeedTarget build();
+    <V> NeedTarget option(Option<V> option, V value);
+    
+    NeedSource target(Path p);
+    NeedSource target(OutputStream out);
+    NeedSource target(WriterTarget target);
+}

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/96fb0f06/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentwriter/Sync.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentwriter/Sync.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentwriter/Sync.java
new file mode 100644
index 0000000..f6d8afc
--- /dev/null
+++ b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentwriter/Sync.java
@@ -0,0 +1,16 @@
+package org.apache.commons.rdf.api.fluentwriter;
+
+import java.util.concurrent.ExecutorService;
+
+import org.apache.commons.rdf.api.io.Option;
+import org.apache.commons.rdf.api.io.Written;
+
+public interface Sync extends _Buildable {
+    
+    Sync build();    
+    <V> Sync option(Option<V> option, V value);
+
+    Written write(); // terminal
+    Async async();
+    Async async(ExecutorService service);
+}

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/96fb0f06/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentwriter/_Buildable.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentwriter/_Buildable.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentwriter/_Buildable.java
new file mode 100644
index 0000000..fc89f60
--- /dev/null
+++ b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentwriter/_Buildable.java
@@ -0,0 +1,50 @@
+/**
+ * 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.fluentwriter;
+
+import org.apache.commons.rdf.api.io.Option;
+import org.apache.commons.rdf.api.io.Option.RequiredOption;
+import org.apache.commons.rdf.api.io.ParserFactory;
+
+interface _Buildable {
+    /**
+     * Return an immutable builder at the current state. The returned builder
+     * can be re-used multiple times in a thread-safe way.
+     * 
+     * @return An immutable builder
+     */
+    _Buildable build();
+    
+    /**
+     * Return a builder with the given option set.
+     * <p>
+     * Note that implementations of {@link ParserFactory} may support different
+     * vendor-specific {@link Option} types, and are free to ignore the set
+     * option (unless it is a {@link RequiredOption}).
+     * <p>
+     * It is undefined if setting multiple values for the same (equal) option
+     * are accumulative or overriding.
+     * 
+     * @param <V> The type of the {@link Option} value 
+     * @param option Option to set
+     * @param value Value to set for option
+     * @return A builder with the given option set
+     */
+    <V> _Buildable option(Option<V> option, V value);
+
+}

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/96fb0f06/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentwriter/package-info.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentwriter/package-info.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentwriter/package-info.java
new file mode 100644
index 0000000..85f4c8a
--- /dev/null
+++ b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentwriter/package-info.java
@@ -0,0 +1,21 @@
+/*
+ * 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.fluentwriter;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/96fb0f06/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/Option.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/Option.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/Option.java
new file mode 100644
index 0000000..7cf5c86
--- /dev/null
+++ b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/Option.java
@@ -0,0 +1,25 @@
+/**
+ * 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;
+
+public interface Option<V> {
+
+    public interface RequiredOption<V> extends Option<V> {
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/96fb0f06/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/Parsed.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/Parsed.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/Parsed.java
new file mode 100644
index 0000000..b252e44
--- /dev/null
+++ b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/Parsed.java
@@ -0,0 +1,26 @@
+/**
+ * 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;
+
+public interface Parsed<T, S> {
+    long count();
+
+    ParserSource<S> from();
+
+    ParserTarget<T> into();
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/96fb0f06/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/ParserBuilder.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/ParserBuilder.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/ParserBuilder.java
new file mode 100644
index 0000000..037271c
--- /dev/null
+++ b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/ParserBuilder.java
@@ -0,0 +1,9 @@
+package org.apache.commons.rdf.api.io;
+
+import org.apache.commons.rdf.api.Dataset;
+import org.apache.commons.rdf.api.fluentparser.OptionalTarget;
+
+public interface ParserBuilder extends OptionalTarget<Dataset> {
+    ParserBuilder build();
+    <V> ParserBuilder option(Option<V> option, V value);
+}

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/96fb0f06/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/ParserFactory.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/ParserFactory.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/ParserFactory.java
new file mode 100644
index 0000000..b25a536
--- /dev/null
+++ b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/ParserFactory.java
@@ -0,0 +1,27 @@
+/**
+ * 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.Dataset;
+import org.apache.commons.rdf.api.RDFSyntax;
+import org.apache.commons.rdf.api.fluentparser.NeedTargetOrRDF;
+import org.apache.commons.rdf.api.fluentparser.OptionalTargetOrSyntax;
+
+public interface ParserFactory extends  _SupportedSyntaxes, OptionalTargetOrSyntax<Dataset> {
+    NeedTargetOrRDF syntax(RDFSyntax syntax);
+}

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/96fb0f06/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/ParserSource.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/ParserSource.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/ParserSource.java
new file mode 100644
index 0000000..259688e
--- /dev/null
+++ b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/ParserSource.java
@@ -0,0 +1,33 @@
+/**
+ * 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;
+
+import org.apache.commons.rdf.api.IRI;
+
+/**
+ *
+ */
+public interface ParserSource<S> {
+    S src();   
+    InputStream inputStream() throws IOException;
+    Optional<IRI> iri();
+}

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/96fb0f06/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/ParserTarget.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/ParserTarget.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/ParserTarget.java
new file mode 100644
index 0000000..8898643
--- /dev/null
+++ b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/ParserTarget.java
@@ -0,0 +1,32 @@
+/**
+ * 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.function.Consumer;
+
+import org.apache.commons.rdf.api.Quad;
+
+/**
+ *
+ */
+@FunctionalInterface
+public interface ParserTarget<T> extends Consumer<Quad> {
+    default T dest() {
+        return null;// unknown
+    }
+}

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/96fb0f06/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/WriterFactory.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/WriterFactory.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/WriterFactory.java
new file mode 100644
index 0000000..59815f0
--- /dev/null
+++ b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/WriterFactory.java
@@ -0,0 +1,25 @@
+/**
+ * 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.RDFSyntax;
+import org.apache.commons.rdf.api.fluentwriter.NeedTarget;
+
+public interface WriterFactory extends _SupportedSyntaxes {
+    NeedTarget syntax(RDFSyntax syntax);
+}

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/96fb0f06/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/WriterSource.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/WriterSource.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/WriterSource.java
new file mode 100644
index 0000000..2ce9bbf
--- /dev/null
+++ b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/WriterSource.java
@@ -0,0 +1,9 @@
+package org.apache.commons.rdf.api.io;
+
+import java.util.stream.Stream;
+
+import org.apache.commons.rdf.api.TripleLike;
+
+public interface WriterSource {
+    Stream<? extends TripleLike> stream();
+}

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/96fb0f06/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/WriterTarget.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/WriterTarget.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/WriterTarget.java
new file mode 100644
index 0000000..f58f3d4
--- /dev/null
+++ b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/WriterTarget.java
@@ -0,0 +1,8 @@
+package org.apache.commons.rdf.api.io;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+public interface WriterTarget {
+    OutputStream outputStream() throws IOException;
+}

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/96fb0f06/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/Written.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/Written.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/Written.java
new file mode 100644
index 0000000..38b5360
--- /dev/null
+++ b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/Written.java
@@ -0,0 +1,9 @@
+package org.apache.commons.rdf.api.io;
+
+public interface Written<S,T> {
+
+    WriterSource source();
+
+    WriterTarget target();
+
+}

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/96fb0f06/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/_SupportedSyntaxes.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/_SupportedSyntaxes.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/_SupportedSyntaxes.java
new file mode 100644
index 0000000..aa3e115
--- /dev/null
+++ b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/_SupportedSyntaxes.java
@@ -0,0 +1,28 @@
+package org.apache.commons.rdf.api.io;
+
+import java.util.Set;
+
+import org.apache.commons.rdf.api.RDFSyntax;
+
+interface _SupportedSyntaxes {
+    /**
+     * Get set of syntaxes supported by this factory.
+     * <p>
+     * The returned syntaxes can be used with {@link #syntax(RDFSyntax)} and may
+     * be used by this factory if no syntax is given.
+     * <p>
+     * Note that the factory may support additional syntaxes not returned
+     * in this set.
+     * 
+     * @return Set of supported syntaxes
+     */
+    Set<RDFSyntax> supportedSyntaxes();
+    
+    /**
+     * Use the specified RDF syntax
+     * 
+     * @param syntax RDFSyntax
+     * @return Builder that uses specified syntax
+     */
+    Object syntax(RDFSyntax syntax);
+}

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/96fb0f06/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/package-info.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/package-info.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/package-info.java
new file mode 100644
index 0000000..859d954
--- /dev/null
+++ b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/package-info.java
@@ -0,0 +1,21 @@
+/*
+ * 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;
\ No newline at end of file