Jena*Impl prefixes
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/6c17d5ed Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/6c17d5ed Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/6c17d5ed Branch: refs/heads/master Commit: 6c17d5ed10400c840f749ac1f2d252a4010f8cad Parents: ef6a1af Author: Stian Soiland-Reyes <st...@apache.org> Authored: Wed Sep 28 01:18:19 2016 +0100 Committer: Stian Soiland-Reyes <st...@apache.org> Committed: Wed Sep 28 01:18:19 2016 +0100 ---------------------------------------------------------------------- .../commons/rdf/jena/JenaRDFTermFactory.java | 2 +- .../rdf/jena/impl/AbstractJenaRDFTerm.java | 47 +++++ .../commons/rdf/jena/impl/AbstractRDFTerm.java | 47 ----- .../apache/commons/rdf/jena/impl/AnyImpl.java | 54 ------ .../commons/rdf/jena/impl/BlankNodeImpl.java | 61 ------ .../commons/rdf/jena/impl/DatasetImpl.java | 187 ------------------- .../rdf/jena/impl/GeneralizedQuadImpl.java | 136 -------------- .../apache/commons/rdf/jena/impl/GraphImpl.java | 154 --------------- .../apache/commons/rdf/jena/impl/IRIImpl.java | 61 ------ .../commons/rdf/jena/impl/JenaAnyImpl.java | 54 ++++++ .../rdf/jena/impl/JenaBlankNodeImpl.java | 61 ++++++ .../commons/rdf/jena/impl/JenaDatasetImpl.java | 187 +++++++++++++++++++ .../commons/rdf/jena/impl/JenaFactory.java | 52 +++--- .../rdf/jena/impl/JenaGeneralizedQuad.java | 136 ++++++++++++++ .../commons/rdf/jena/impl/JenaGraphImpl.java | 154 +++++++++++++++ .../commons/rdf/jena/impl/JenaIRIImpl.java | 61 ++++++ .../commons/rdf/jena/impl/JenaLiteralImpl.java | 73 ++++++++ .../commons/rdf/jena/impl/JenaQuadImpl.java | 66 +++++++ .../commons/rdf/jena/impl/JenaTripleImpl.java | 67 +++++++ .../commons/rdf/jena/impl/JenaVariableImpl.java | 64 +++++++ .../commons/rdf/jena/impl/LiteralImpl.java | 73 -------- .../apache/commons/rdf/jena/impl/QuadImpl.java | 66 ------- .../commons/rdf/jena/impl/TripleImpl.java | 67 ------- .../commons/rdf/jena/impl/VariableImpl.java | 64 ------- 24 files changed, 997 insertions(+), 997 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/6c17d5ed/jena/src/main/java/org/apache/commons/rdf/jena/JenaRDFTermFactory.java ---------------------------------------------------------------------- diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/JenaRDFTermFactory.java b/jena/src/main/java/org/apache/commons/rdf/jena/JenaRDFTermFactory.java index ec84c0a..7359acb 100644 --- a/jena/src/main/java/org/apache/commons/rdf/jena/JenaRDFTermFactory.java +++ b/jena/src/main/java/org/apache/commons/rdf/jena/JenaRDFTermFactory.java @@ -681,7 +681,7 @@ public final class JenaRDFTermFactory implements RDFTermFactory { return null; } if (term instanceof JenaRDFTerm) - // TODO: What if it's a BlankNodeImpl with + // TODO: What if it's a JenaBlankNodeImpl with // a different salt? Do we need to rewrite the // jena blanknode identifier? return ((JenaRDFTerm) term).asJenaNode(); http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/6c17d5ed/jena/src/main/java/org/apache/commons/rdf/jena/impl/AbstractJenaRDFTerm.java ---------------------------------------------------------------------- diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/AbstractJenaRDFTerm.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/AbstractJenaRDFTerm.java new file mode 100644 index 0000000..9c0d7ec --- /dev/null +++ b/jena/src/main/java/org/apache/commons/rdf/jena/impl/AbstractJenaRDFTerm.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.jena.impl; + +import org.apache.commons.rdf.api.RDFTerm; +import org.apache.commons.rdf.jena.JenaRDFTerm; +import org.apache.jena.graph.Node; +import org.apache.jena.riot.out.NodeFmtLib; + +class AbstractJenaRDFTerm implements JenaRDFTerm, RDFTerm { + private Node node; + // static private PrefixMapping empty = new PrefixMappingImpl() ; + + protected AbstractJenaRDFTerm(Node node) { + this.node = node; + } + + @Override + public Node asJenaNode() { + return node; + } + + public String ntriplesString() { + return NodeFmtLib.str(node); + } + + @Override + public String toString() { + return ntriplesString(); + } +} http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/6c17d5ed/jena/src/main/java/org/apache/commons/rdf/jena/impl/AbstractRDFTerm.java ---------------------------------------------------------------------- diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/AbstractRDFTerm.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/AbstractRDFTerm.java deleted file mode 100644 index 5c828ef..0000000 --- a/jena/src/main/java/org/apache/commons/rdf/jena/impl/AbstractRDFTerm.java +++ /dev/null @@ -1,47 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.commons.rdf.jena.impl; - -import org.apache.commons.rdf.api.RDFTerm; -import org.apache.commons.rdf.jena.JenaRDFTerm; -import org.apache.jena.graph.Node; -import org.apache.jena.riot.out.NodeFmtLib; - -class AbstractRDFTerm implements JenaRDFTerm, RDFTerm { - private Node node; - // static private PrefixMapping empty = new PrefixMappingImpl() ; - - protected AbstractRDFTerm(Node node) { - this.node = node; - } - - @Override - public Node asJenaNode() { - return node; - } - - public String ntriplesString() { - return NodeFmtLib.str(node); - } - - @Override - public String toString() { - return ntriplesString(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/6c17d5ed/jena/src/main/java/org/apache/commons/rdf/jena/impl/AnyImpl.java ---------------------------------------------------------------------- diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/AnyImpl.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/AnyImpl.java deleted file mode 100644 index e2d3809..0000000 --- a/jena/src/main/java/org/apache/commons/rdf/jena/impl/AnyImpl.java +++ /dev/null @@ -1,54 +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.jena.impl; - -import org.apache.commons.rdf.jena.JenaAny; -import org.apache.commons.rdf.jena.JenaRDFTerm; -import org.apache.jena.graph.Node; - -public class AnyImpl implements JenaRDFTerm, JenaAny { - - static class Singleton { - static AnyImpl instance = new AnyImpl(); - } - - /** - * Private constructor - * - * @see {@link Singleton#instance} - */ - private AnyImpl() { - } - - @Override - public String ntriplesString() { - return "[]"; - } - - @Override - public Node asJenaNode() { - return Node.ANY; - } - - @Override - public boolean equals(Object obj) { - return obj == this || obj instanceof JenaAny; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/6c17d5ed/jena/src/main/java/org/apache/commons/rdf/jena/impl/BlankNodeImpl.java ---------------------------------------------------------------------- diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/BlankNodeImpl.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/BlankNodeImpl.java deleted file mode 100644 index 2acb635..0000000 --- a/jena/src/main/java/org/apache/commons/rdf/jena/impl/BlankNodeImpl.java +++ /dev/null @@ -1,61 +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.jena.impl; - -import java.util.UUID; - -import org.apache.commons.rdf.api.BlankNode; -import org.apache.commons.rdf.jena.JenaBlankNode; -import org.apache.jena.graph.Node; - -public class BlankNodeImpl extends AbstractRDFTerm implements JenaBlankNode { - - private UUID salt; - - /* package */ BlankNodeImpl(Node node, UUID salt) { - super(node); - if (! node.isBlank()) { - throw new IllegalArgumentException("Node is not a blank node: " + node); - } - this.salt = salt; - } - - @Override - public boolean equals(Object other) { - if (other == this) - return true; - if (other == null) - return false; - if (!(other instanceof BlankNode)) - return false; - BlankNode bNode = (BlankNode) other; - return uniqueReference().equals(bNode.uniqueReference()); - } - - @Override - public int hashCode() { - return uniqueReference().hashCode(); - } - - @Override - public String uniqueReference() { - return salt + asJenaNode().getBlankNodeLabel(); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/6c17d5ed/jena/src/main/java/org/apache/commons/rdf/jena/impl/DatasetImpl.java ---------------------------------------------------------------------- diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/DatasetImpl.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/DatasetImpl.java deleted file mode 100644 index 4094efe..0000000 --- a/jena/src/main/java/org/apache/commons/rdf/jena/impl/DatasetImpl.java +++ /dev/null @@ -1,187 +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.jena.impl; - -import static org.apache.jena.graph.Node.ANY; - -import java.io.StringWriter; -import java.util.Optional; -import java.util.UUID; -import java.util.stream.Stream; - -import org.apache.commons.rdf.api.BlankNodeOrIRI; -import org.apache.commons.rdf.api.Graph; -import org.apache.commons.rdf.api.IRI; -import org.apache.commons.rdf.api.Quad; -import org.apache.commons.rdf.api.RDFTerm; -import org.apache.commons.rdf.jena.JenaDataset; -import org.apache.commons.rdf.jena.JenaRDFTermFactory; -import org.apache.jena.atlas.iterator.Iter; -import org.apache.jena.graph.Node; -import org.apache.jena.riot.Lang; -import org.apache.jena.riot.RDFDataMgr; -import org.apache.jena.sparql.core.DatasetGraph; -import org.apache.jena.sparql.core.GraphView; - -public class DatasetImpl implements JenaDataset { - - private DatasetGraph graph; - private UUID salt; - - /* package */ DatasetImpl(DatasetGraph graph, UUID salt) { - this.graph = graph; - this.salt = salt; - } - - @Override - public void add(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object) { - graph.add( - org.apache.jena.sparql.core.Quad.create( - JenaRDFTermFactory.toJena(graphName), - JenaRDFTermFactory.toJena(subject), - JenaRDFTermFactory.toJena(predicate), - JenaRDFTermFactory.toJena(object))); - } - - @Override - public void add(Quad quad) { - graph.add(JenaRDFTermFactory.toJena(quad)); - } - - @Override - public DatasetGraph asJenaDatasetGraph() { - return graph; - } - - @Override - public void clear() { - graph.clear(); - } - - @Override - public void close() { - graph.close(); - } - - - @Override - public boolean contains(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object) { - return graph.contains( - toJenaPattern(graphName), - toJenaPattern(subject), - toJenaPattern(predicate), - toJenaPattern(object)); - } - - private Node toJenaPattern(Optional<? extends RDFTerm> graphName) { - // In theory we could have done: - // JenaRDFTermFactory.toJena(graphName.orElse(JenaFactory::createAnyVariable)) - // but because of generics casting rules that doesn't work :( - - if (graphName == null) { - return ANY; - } - // null: default graph - return JenaRDFTermFactory.toJena(graphName.orElse(null)); - } - - private Node toJenaPattern(RDFTerm term) { - if (term == null) - return ANY; - return JenaRDFTermFactory.toJena(term); - } - - @Override - public boolean contains(Quad quad) { - return graph.contains(JenaRDFTermFactory.toJena(quad)); - } - - @Override - public void remove(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object) { - graph.delete(org.apache.jena.sparql.core.Quad.create( - toJenaPattern(graphName), - toJenaPattern(subject), - toJenaPattern(predicate), - toJenaPattern(object))); - } - - @Override - public void remove(Quad quad) { - graph.delete(JenaRDFTermFactory.toJena(quad)); - } - - @Override - public long size() { - return graph.size(); - } - - @Override - public Stream<? extends Quad> stream() { - JenaRDFTermFactory factory = new JenaRDFTermFactory(salt); - return Iter.asStream(graph.find(ANY, ANY, ANY, ANY), true) - .map(factory::fromJena); - } - - @Override - public Stream<? extends Quad> stream(Optional<BlankNodeOrIRI> g, BlankNodeOrIRI s, IRI p, RDFTerm o) { - JenaRDFTermFactory factory = new JenaRDFTermFactory(salt); - return Iter.asStream(graph.find(toJenaPattern(g), toJenaPattern(s), toJenaPattern(p), toJenaPattern(o)), true) - .map(factory::fromJena); - } - - @Override - public String toString() { - StringWriter sw = new StringWriter(); - RDFDataMgr.write(sw, graph, Lang.NT); - return sw.toString(); - } - - @Override - public Graph getGraph() { - GraphView gv = GraphView.createDefaultGraph(graph); - return new GraphImpl(gv, salt); - } - - @Override - public Graph getUnionGraph() { - GraphView gv = GraphView.createUnionGraph(graph); - return new GraphImpl(gv, salt); - } - - @Override - public Optional<Graph> getGraph(BlankNodeOrIRI graphName) { - GraphView gv = GraphView.createNamedGraph(graph, JenaRDFTermFactory.toJena(graphName)); - return Optional.of(new GraphImpl(gv, salt)); - } - - @Override - public Stream<BlankNodeOrIRI> getGraphNames() { - JenaRDFTermFactory factory = new JenaRDFTermFactory(salt); - return Iter.asStream(graph.listGraphNodes()).map(node -> - (BlankNodeOrIRI) factory.fromJena(node)); - } - - @Override - public Iterable<Quad> iterate() { - return Iter.asStream(graph.find(), false) - .map(q -> (Quad) JenaRDFTermFactory.fromJena(q, salt)) - ::iterator; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/6c17d5ed/jena/src/main/java/org/apache/commons/rdf/jena/impl/GeneralizedQuadImpl.java ---------------------------------------------------------------------- diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/GeneralizedQuadImpl.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/GeneralizedQuadImpl.java deleted file mode 100644 index e772bd1..0000000 --- a/jena/src/main/java/org/apache/commons/rdf/jena/impl/GeneralizedQuadImpl.java +++ /dev/null @@ -1,136 +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.jena.impl; - -import java.util.Objects; -import java.util.Optional; -import java.util.UUID; - -import org.apache.commons.rdf.api.QuadLike; -import org.apache.commons.rdf.api.RDFTerm; -import org.apache.commons.rdf.jena.JenaQuad; -import org.apache.commons.rdf.jena.JenaQuadLike; -import org.apache.commons.rdf.jena.JenaRDFTermFactory; -import org.apache.commons.rdf.jena.JenaTriple; -import org.apache.jena.graph.Triple; -import org.apache.jena.sparql.core.Quad; - -/** - * A generalized {@link QuadLike}, backed by a Jena {@link Quad} or {@link Triple}. - * <p> - * This class does not implement any particular {@link #equals(Object)} or - * {@link #hashCode()} but can otherwise be used as a base class for both - * a {@link JenaTriple} and a {@link JenaQuad}. - * - * @see TripleImpl - * @see QuadImpl - * @see JenaFactory#createGeneralizedTriple(RDFTerm, RDFTerm, RDFTerm) - * @see JenaFactory#createGeneralizedQuad(RDFTerm, RDFTerm, RDFTerm, RDFTerm) - * - */ -public class GeneralizedQuadImpl<S extends RDFTerm, P extends RDFTerm, O extends RDFTerm, G extends RDFTerm> implements JenaQuadLike<S,P,O,G> { - - final Optional<G> graphName; - final S subject; - final P predicate; - final O object; - org.apache.jena.sparql.core.Quad quad = null; - org.apache.jena.graph.Triple triple = null; - - GeneralizedQuadImpl(S subject, P predicate, O object, Optional<G> graphName) { - this.subject = Objects.requireNonNull(subject); - this.predicate = Objects.requireNonNull(predicate); - this.object = Objects.requireNonNull(object); - this.graphName = Objects.requireNonNull(graphName); - } - - GeneralizedQuadImpl(S subject, P predicate, O object) { - this(subject, predicate, object, Optional.empty()); - } - - @SuppressWarnings("unchecked") - GeneralizedQuadImpl(org.apache.jena.sparql.core.Quad quad, UUID salt) { - this.quad = Objects.requireNonNull(quad); - this.subject = (S) JenaFactory.fromJena(quad.getSubject(), salt); - this.predicate = (P) JenaFactory.fromJena(quad.getPredicate(), salt); - this.object = (O)JenaFactory.fromJena(quad.getObject(), salt); - this.graphName = Optional.of((G) JenaFactory.fromJena(quad.getGraph(), salt)); - } - - @SuppressWarnings("unchecked") - GeneralizedQuadImpl(org.apache.jena.graph.Triple triple, UUID salt) { - this.triple = Objects.requireNonNull(triple); - this.subject = (S) JenaFactory.fromJena(triple.getSubject(), salt); - this.predicate = (P) JenaFactory.fromJena(triple.getPredicate(), salt); - this.object = (O)JenaFactory.fromJena(triple.getObject(), salt); - this.graphName = Optional.empty(); - } - - @Override - public org.apache.jena.sparql.core.Quad asJenaQuad() { - if (quad == null) { - quad = org.apache.jena.sparql.core.Quad.create( - JenaRDFTermFactory.toJena(graphName.orElse(null)), - JenaRDFTermFactory.toJena(subject), - JenaRDFTermFactory.toJena(predicate), - JenaRDFTermFactory.toJena(object)); - } - return quad; - } - - @Override - public org.apache.jena.graph.Triple asJenaTriple() { - if (triple == null) { - triple = org.apache.jena.graph.Triple.create(JenaRDFTermFactory.toJena(subject), - JenaRDFTermFactory.toJena(predicate), - JenaRDFTermFactory.toJena(object)); - } - return triple; - } - - @Override - public S getSubject() { - return subject; - } - - @Override - public P getPredicate() { - return predicate; - } - - @Override - public O getObject() { - return object; - } - - @Override - public Optional<G> getGraphName() { - return graphName; - } - - @Override - public String toString() { - // kind of nquad syntax - return getSubject().ntriplesString() + " " + - getPredicate().ntriplesString() + " " - + getObject().ntriplesString() + " " + - getGraphName().map(RDFTerm::ntriplesString).orElse("") + "."; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/6c17d5ed/jena/src/main/java/org/apache/commons/rdf/jena/impl/GraphImpl.java ---------------------------------------------------------------------- diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/GraphImpl.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/GraphImpl.java deleted file mode 100644 index 3b74ee0..0000000 --- a/jena/src/main/java/org/apache/commons/rdf/jena/impl/GraphImpl.java +++ /dev/null @@ -1,154 +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.jena.impl; - -import java.io.StringWriter; -import java.util.UUID; -import java.util.stream.Stream; - -import org.apache.commons.rdf.api.BlankNodeOrIRI; -import org.apache.commons.rdf.api.IRI; -import org.apache.commons.rdf.api.RDFTerm; -import org.apache.commons.rdf.api.Triple; -import org.apache.commons.rdf.jena.JenaGraph; -import org.apache.commons.rdf.jena.JenaRDFTermFactory; -import org.apache.jena.atlas.iterator.Iter; -import org.apache.jena.graph.Node; -import org.apache.jena.rdf.model.Model; -import org.apache.jena.rdf.model.ModelFactory; -import org.apache.jena.riot.Lang; -import org.apache.jena.riot.RDFDataMgr; - -public class GraphImpl implements JenaGraph { - - private org.apache.jena.graph.Graph graph; - private UUID salt; - private Model model; - - GraphImpl(org.apache.jena.graph.Graph graph, UUID salt) { - this.graph = graph; - this.salt = salt; - } - - GraphImpl(Model model, UUID salt) { - this.model = model; - this.graph = model.getGraph(); - this.salt = salt; - } - - @Override - public void add(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) { - graph.add(org.apache.jena.graph.Triple.create( - JenaRDFTermFactory.toJena(subject), - JenaRDFTermFactory.toJena(predicate), - JenaRDFTermFactory.toJena(object))); - } - - @Override - public void add(Triple triple) { - graph.add(JenaRDFTermFactory.toJena(triple)); - } - - @Override - public org.apache.jena.graph.Graph asJenaGraph() { - return graph; - } - - @Override - public void clear() { - graph.clear(); - } - - @Override - public void close() { - graph.close(); - } - - @Override - public boolean contains(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) { - return graph.contains( - JenaRDFTermFactory.toJena(subject), - JenaRDFTermFactory.toJena(predicate), - JenaRDFTermFactory.toJena(object)); - } - - @Override - public boolean contains(Triple triple) { - return graph.contains(JenaRDFTermFactory.toJena(triple)); - } - - @Override - public void remove(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) { - graph.delete(org.apache.jena.graph.Triple.create( - JenaRDFTermFactory.toJena(subject), - JenaRDFTermFactory.toJena(predicate), - JenaRDFTermFactory.toJena(object))); - } - - @Override - public void remove(Triple triple) { - graph.delete(JenaRDFTermFactory.toJena(triple)); - } - - @Override - public long size() { - return graph.size(); - } - - @Override - public Stream<? extends Triple> stream() { - JenaRDFTermFactory factory = new JenaRDFTermFactory(salt); - return Iter.asStream(graph.find(null, null, null), true).map(factory::fromJena); - } - - @Override - public Stream<? extends Triple> stream(BlankNodeOrIRI s, IRI p, RDFTerm o) { - JenaRDFTermFactory factory = new JenaRDFTermFactory(salt); - return Iter.asStream(graph.find(toJenaAny(s), toJenaAny(p), toJenaAny(o)), true) - .map(factory::fromJena); - } - - private Node toJenaAny(RDFTerm term) { - if (term == null) - return Node.ANY; - return JenaRDFTermFactory.toJena(term); - } - - @Override - public String toString() { - StringWriter sw = new StringWriter(); - RDFDataMgr.write(sw, graph, Lang.NT); - return sw.toString(); - } - - @Override - public Model asJenaModel() { - if (model == null) { - synchronized(this) { - // As Model can be used for locks, we should make sure we don't make - // more than one model - if (model == null) { - model = ModelFactory.createModelForGraph(graph); - } - } - } - return model; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/6c17d5ed/jena/src/main/java/org/apache/commons/rdf/jena/impl/IRIImpl.java ---------------------------------------------------------------------- diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/IRIImpl.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/IRIImpl.java deleted file mode 100644 index e85c80f..0000000 --- a/jena/src/main/java/org/apache/commons/rdf/jena/impl/IRIImpl.java +++ /dev/null @@ -1,61 +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.jena.impl; - -import org.apache.commons.rdf.api.IRI; -import org.apache.commons.rdf.jena.JenaIRI; -import org.apache.jena.graph.Node; -import org.apache.jena.graph.NodeFactory; - -public class IRIImpl extends AbstractRDFTerm implements JenaIRI { - - /* package */ IRIImpl(Node node) { - super(node); - if (! node.isURI()) { - throw new IllegalArgumentException("Node is not a blank node: " + node); - } - - } - - /* package */ IRIImpl(String iriStr) { - super(NodeFactory.createURI(iriStr)); - } - - @Override - public boolean equals(Object other) { - if (other == this) - return true; - if (other == null) - return false; - if (!(other instanceof IRI)) - return false; - IRI iri = (IRI) other; - return getIRIString().equals(iri.getIRIString()); - } - - @Override - public String getIRIString() { - return asJenaNode().getURI(); - } - - @Override - public int hashCode() { - return getIRIString().hashCode(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/6c17d5ed/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaAnyImpl.java ---------------------------------------------------------------------- diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaAnyImpl.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaAnyImpl.java new file mode 100644 index 0000000..068cbd8 --- /dev/null +++ b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaAnyImpl.java @@ -0,0 +1,54 @@ +/** + * 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.jena.impl; + +import org.apache.commons.rdf.jena.JenaAny; +import org.apache.commons.rdf.jena.JenaRDFTerm; +import org.apache.jena.graph.Node; + +public class JenaAnyImpl implements JenaRDFTerm, JenaAny { + + static class Singleton { + static JenaAnyImpl instance = new JenaAnyImpl(); + } + + /** + * Private constructor + * + * @see {@link Singleton#instance} + */ + private JenaAnyImpl() { + } + + @Override + public String ntriplesString() { + return "[]"; + } + + @Override + public Node asJenaNode() { + return Node.ANY; + } + + @Override + public boolean equals(Object obj) { + return obj == this || obj instanceof JenaAny; + } + +} http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/6c17d5ed/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaBlankNodeImpl.java ---------------------------------------------------------------------- diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaBlankNodeImpl.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaBlankNodeImpl.java new file mode 100644 index 0000000..0cbd764 --- /dev/null +++ b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaBlankNodeImpl.java @@ -0,0 +1,61 @@ +/** + * 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.jena.impl; + +import java.util.UUID; + +import org.apache.commons.rdf.api.BlankNode; +import org.apache.commons.rdf.jena.JenaBlankNode; +import org.apache.jena.graph.Node; + +public class JenaBlankNodeImpl extends AbstractJenaRDFTerm implements JenaBlankNode { + + private UUID salt; + + /* package */ JenaBlankNodeImpl(Node node, UUID salt) { + super(node); + if (! node.isBlank()) { + throw new IllegalArgumentException("Node is not a blank node: " + node); + } + this.salt = salt; + } + + @Override + public boolean equals(Object other) { + if (other == this) + return true; + if (other == null) + return false; + if (!(other instanceof BlankNode)) + return false; + BlankNode bNode = (BlankNode) other; + return uniqueReference().equals(bNode.uniqueReference()); + } + + @Override + public int hashCode() { + return uniqueReference().hashCode(); + } + + @Override + public String uniqueReference() { + return salt + asJenaNode().getBlankNodeLabel(); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/6c17d5ed/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaDatasetImpl.java ---------------------------------------------------------------------- diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaDatasetImpl.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaDatasetImpl.java new file mode 100644 index 0000000..b756526 --- /dev/null +++ b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaDatasetImpl.java @@ -0,0 +1,187 @@ +/** + * 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.jena.impl; + +import static org.apache.jena.graph.Node.ANY; + +import java.io.StringWriter; +import java.util.Optional; +import java.util.UUID; +import java.util.stream.Stream; + +import org.apache.commons.rdf.api.BlankNodeOrIRI; +import org.apache.commons.rdf.api.Graph; +import org.apache.commons.rdf.api.IRI; +import org.apache.commons.rdf.api.Quad; +import org.apache.commons.rdf.api.RDFTerm; +import org.apache.commons.rdf.jena.JenaDataset; +import org.apache.commons.rdf.jena.JenaRDFTermFactory; +import org.apache.jena.atlas.iterator.Iter; +import org.apache.jena.graph.Node; +import org.apache.jena.riot.Lang; +import org.apache.jena.riot.RDFDataMgr; +import org.apache.jena.sparql.core.DatasetGraph; +import org.apache.jena.sparql.core.GraphView; + +public class JenaDatasetImpl implements JenaDataset { + + private DatasetGraph graph; + private UUID salt; + + /* package */ JenaDatasetImpl(DatasetGraph graph, UUID salt) { + this.graph = graph; + this.salt = salt; + } + + @Override + public void add(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object) { + graph.add( + org.apache.jena.sparql.core.Quad.create( + JenaRDFTermFactory.toJena(graphName), + JenaRDFTermFactory.toJena(subject), + JenaRDFTermFactory.toJena(predicate), + JenaRDFTermFactory.toJena(object))); + } + + @Override + public void add(Quad quad) { + graph.add(JenaRDFTermFactory.toJena(quad)); + } + + @Override + public DatasetGraph asJenaDatasetGraph() { + return graph; + } + + @Override + public void clear() { + graph.clear(); + } + + @Override + public void close() { + graph.close(); + } + + + @Override + public boolean contains(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object) { + return graph.contains( + toJenaPattern(graphName), + toJenaPattern(subject), + toJenaPattern(predicate), + toJenaPattern(object)); + } + + private Node toJenaPattern(Optional<? extends RDFTerm> graphName) { + // In theory we could have done: + // JenaRDFTermFactory.toJena(graphName.orElse(JenaFactory::createAnyVariable)) + // but because of generics casting rules that doesn't work :( + + if (graphName == null) { + return ANY; + } + // null: default graph + return JenaRDFTermFactory.toJena(graphName.orElse(null)); + } + + private Node toJenaPattern(RDFTerm term) { + if (term == null) + return ANY; + return JenaRDFTermFactory.toJena(term); + } + + @Override + public boolean contains(Quad quad) { + return graph.contains(JenaRDFTermFactory.toJena(quad)); + } + + @Override + public void remove(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object) { + graph.delete(org.apache.jena.sparql.core.Quad.create( + toJenaPattern(graphName), + toJenaPattern(subject), + toJenaPattern(predicate), + toJenaPattern(object))); + } + + @Override + public void remove(Quad quad) { + graph.delete(JenaRDFTermFactory.toJena(quad)); + } + + @Override + public long size() { + return graph.size(); + } + + @Override + public Stream<? extends Quad> stream() { + JenaRDFTermFactory factory = new JenaRDFTermFactory(salt); + return Iter.asStream(graph.find(ANY, ANY, ANY, ANY), true) + .map(factory::fromJena); + } + + @Override + public Stream<? extends Quad> stream(Optional<BlankNodeOrIRI> g, BlankNodeOrIRI s, IRI p, RDFTerm o) { + JenaRDFTermFactory factory = new JenaRDFTermFactory(salt); + return Iter.asStream(graph.find(toJenaPattern(g), toJenaPattern(s), toJenaPattern(p), toJenaPattern(o)), true) + .map(factory::fromJena); + } + + @Override + public String toString() { + StringWriter sw = new StringWriter(); + RDFDataMgr.write(sw, graph, Lang.NT); + return sw.toString(); + } + + @Override + public Graph getGraph() { + GraphView gv = GraphView.createDefaultGraph(graph); + return new JenaGraphImpl(gv, salt); + } + + @Override + public Graph getUnionGraph() { + GraphView gv = GraphView.createUnionGraph(graph); + return new JenaGraphImpl(gv, salt); + } + + @Override + public Optional<Graph> getGraph(BlankNodeOrIRI graphName) { + GraphView gv = GraphView.createNamedGraph(graph, JenaRDFTermFactory.toJena(graphName)); + return Optional.of(new JenaGraphImpl(gv, salt)); + } + + @Override + public Stream<BlankNodeOrIRI> getGraphNames() { + JenaRDFTermFactory factory = new JenaRDFTermFactory(salt); + return Iter.asStream(graph.listGraphNodes()).map(node -> + (BlankNodeOrIRI) factory.fromJena(node)); + } + + @Override + public Iterable<Quad> iterate() { + return Iter.asStream(graph.find(), false) + .map(q -> (Quad) JenaRDFTermFactory.fromJena(q, salt)) + ::iterator; + } + +} http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/6c17d5ed/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaFactory.java ---------------------------------------------------------------------- diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaFactory.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaFactory.java index 7a6a7ab..0551094 100644 --- a/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaFactory.java +++ b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaFactory.java @@ -62,60 +62,60 @@ import org.apache.jena.sparql.graph.GraphFactory; public class JenaFactory { public static JenaBlankNode createBlankNode(String id, UUID salt) { - return new BlankNodeImpl(NodeFactory.createBlankNode(id), salt); + return new JenaBlankNodeImpl(NodeFactory.createBlankNode(id), salt); } public static JenaBlankNode createBlankNode(UUID salt) { - return new BlankNodeImpl(NodeFactory.createBlankNode(), salt); + return new JenaBlankNodeImpl(NodeFactory.createBlankNode(), salt); } public static Dataset createDataset(UUID salt) { DatasetGraph dg = DatasetGraphFactory.createGeneral(); // Or which createMethod() -- a bit confusing with lots of choice.. - return new DatasetImpl(dg, salt); + return new JenaDatasetImpl(dg, salt); } public static JenaGraph createGraph(UUID salt) { - return new GraphImpl(GraphFactory.createDefaultGraph(), salt); + return new JenaGraphImpl(GraphFactory.createDefaultGraph(), salt); } public static JenaIRI createIRI(String iriStr) { - return new IRIImpl(iriStr); + return new JenaIRIImpl(iriStr); } public static JenaLiteral createLiteral(String lexStr) { - return new LiteralImpl(NodeFactory.createLiteral(lexStr)); + return new JenaLiteralImpl(NodeFactory.createLiteral(lexStr)); } public static JenaLiteral createLiteralDT(String lexStr, String datatypeIRI) { - return new LiteralImpl(NodeFactory.createLiteral(lexStr, NodeFactory.getType(datatypeIRI))); + return new JenaLiteralImpl(NodeFactory.createLiteral(lexStr, NodeFactory.getType(datatypeIRI))); } public static JenaLiteral createLiteralLang(String lexStr, String langTag) { - return new LiteralImpl(NodeFactory.createLiteral(lexStr, langTag)); + return new JenaLiteralImpl(NodeFactory.createLiteral(lexStr, langTag)); } public static JenaTriple createTriple(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) { - return new TripleImpl(subject, predicate, object); + return new JenaTripleImpl(subject, predicate, object); } public static JenaQuad createQuad(BlankNodeOrIRI subject, IRI predicate, RDFTerm object, BlankNodeOrIRI graphName) { - return new QuadImpl(subject, predicate, object, Optional.ofNullable(graphName)); + return new JenaQuadImpl(subject, predicate, object, Optional.ofNullable(graphName)); } public static JenaVariable createVariable(String name) { - return new VariableImpl(NodeFactory.createVariable(name)); + return new JenaVariableImpl(NodeFactory.createVariable(name)); } public static JenaAny createAnyVariable() { - return AnyImpl.Singleton.instance; + return JenaAnyImpl.Singleton.instance; } public static JenaTripleLike<RDFTerm,RDFTerm,RDFTerm> createGeneralizedTriple(RDFTerm subject, RDFTerm predicate, RDFTerm object) { - return new GeneralizedQuadImpl<RDFTerm,RDFTerm,RDFTerm,RDFTerm>(subject, predicate, object); + return new JenaGeneralizedQuad<RDFTerm,RDFTerm,RDFTerm,RDFTerm>(subject, predicate, object); } public static JenaQuadLike<RDFTerm,RDFTerm,RDFTerm,RDFTerm> createGeneralizedQuad(RDFTerm subject, RDFTerm predicate, RDFTerm object, RDFTerm graphName) { - return new GeneralizedQuadImpl<RDFTerm,RDFTerm,RDFTerm,RDFTerm>(subject, predicate, object, Optional.ofNullable(graphName)); + return new JenaGeneralizedQuad<RDFTerm,RDFTerm,RDFTerm,RDFTerm>(subject, predicate, object, Optional.ofNullable(graphName)); } public static JenaRDFTerm fromJena(Node node, UUID salt) throws ConversionException { @@ -127,49 +127,49 @@ public class JenaFactory { public static JenaRDFTerm fromJenaGeneralized(Node node, UUID salt) { if (node.isURI()) { - return new IRIImpl(node); + return new JenaIRIImpl(node); } if (node.isLiteral()) { - return new LiteralImpl(node); + return new JenaLiteralImpl(node); } if (node.isBlank()) { - return new BlankNodeImpl(node, salt); + return new JenaBlankNodeImpl(node, salt); } if (node.equals(Node.ANY)) { - return AnyImpl.Singleton.instance; + return JenaAnyImpl.Singleton.instance; } if (node.isVariable()) { - return new VariableImpl(node); + return new JenaVariableImpl(node); } throw new IllegalArgumentException("Unrecognized node type: " + node); } public static JenaGraph fromJena(org.apache.jena.graph.Graph graph, UUID salt) { - return new GraphImpl(graph, salt); + return new JenaGraphImpl(graph, salt); } public static JenaGraph fromJena(Model model, UUID salt) { - return new GraphImpl(model, salt); + return new JenaGraphImpl(model, salt); } public static JenaDataset fromJena(DatasetGraph datasetGraph, UUID salt) { - return new DatasetImpl(datasetGraph, salt); + return new JenaDatasetImpl(datasetGraph, salt); } public static JenaTriple fromJena(org.apache.jena.graph.Triple triple, UUID salt) { - return new TripleImpl(triple, salt); + return new JenaTripleImpl(triple, salt); } public static JenaTripleLike<RDFTerm, RDFTerm, RDFTerm> fromJenaGeneralized(org.apache.jena.graph.Triple triple, UUID salt) { - return new GeneralizedQuadImpl<RDFTerm,RDFTerm,RDFTerm,RDFTerm>(triple, salt); + return new JenaGeneralizedQuad<RDFTerm,RDFTerm,RDFTerm,RDFTerm>(triple, salt); } public static JenaQuadLike<RDFTerm,RDFTerm,RDFTerm,RDFTerm> fromJenaGeneralized(org.apache.jena.sparql.core.Quad quad, UUID salt) { - return new GeneralizedQuadImpl<RDFTerm,RDFTerm,RDFTerm,RDFTerm>(quad, salt); + return new JenaGeneralizedQuad<RDFTerm,RDFTerm,RDFTerm,RDFTerm>(quad, salt); } public static Quad fromJena(org.apache.jena.sparql.core.Quad quad, UUID salt) { - return new QuadImpl(quad, salt); + return new JenaQuadImpl(quad, salt); } } http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/6c17d5ed/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaGeneralizedQuad.java ---------------------------------------------------------------------- diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaGeneralizedQuad.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaGeneralizedQuad.java new file mode 100644 index 0000000..5456ec9 --- /dev/null +++ b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaGeneralizedQuad.java @@ -0,0 +1,136 @@ +/** + * 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.jena.impl; + +import java.util.Objects; +import java.util.Optional; +import java.util.UUID; + +import org.apache.commons.rdf.api.QuadLike; +import org.apache.commons.rdf.api.RDFTerm; +import org.apache.commons.rdf.jena.JenaQuad; +import org.apache.commons.rdf.jena.JenaQuadLike; +import org.apache.commons.rdf.jena.JenaRDFTermFactory; +import org.apache.commons.rdf.jena.JenaTriple; +import org.apache.jena.graph.Triple; +import org.apache.jena.sparql.core.Quad; + +/** + * A generalized {@link QuadLike}, backed by a Jena {@link Quad} or {@link Triple}. + * <p> + * This class does not implement any particular {@link #equals(Object)} or + * {@link #hashCode()} but can otherwise be used as a base class for both + * a {@link JenaTriple} and a {@link JenaQuad}. + * + * @see JenaTripleImpl + * @see JenaQuadImpl + * @see JenaFactory#createGeneralizedTriple(RDFTerm, RDFTerm, RDFTerm) + * @see JenaFactory#createGeneralizedQuad(RDFTerm, RDFTerm, RDFTerm, RDFTerm) + * + */ +public class JenaGeneralizedQuad<S extends RDFTerm, P extends RDFTerm, O extends RDFTerm, G extends RDFTerm> implements JenaQuadLike<S,P,O,G> { + + final Optional<G> graphName; + final S subject; + final P predicate; + final O object; + org.apache.jena.sparql.core.Quad quad = null; + org.apache.jena.graph.Triple triple = null; + + JenaGeneralizedQuad(S subject, P predicate, O object, Optional<G> graphName) { + this.subject = Objects.requireNonNull(subject); + this.predicate = Objects.requireNonNull(predicate); + this.object = Objects.requireNonNull(object); + this.graphName = Objects.requireNonNull(graphName); + } + + JenaGeneralizedQuad(S subject, P predicate, O object) { + this(subject, predicate, object, Optional.empty()); + } + + @SuppressWarnings("unchecked") + JenaGeneralizedQuad(org.apache.jena.sparql.core.Quad quad, UUID salt) { + this.quad = Objects.requireNonNull(quad); + this.subject = (S) JenaFactory.fromJena(quad.getSubject(), salt); + this.predicate = (P) JenaFactory.fromJena(quad.getPredicate(), salt); + this.object = (O)JenaFactory.fromJena(quad.getObject(), salt); + this.graphName = Optional.of((G) JenaFactory.fromJena(quad.getGraph(), salt)); + } + + @SuppressWarnings("unchecked") + JenaGeneralizedQuad(org.apache.jena.graph.Triple triple, UUID salt) { + this.triple = Objects.requireNonNull(triple); + this.subject = (S) JenaFactory.fromJena(triple.getSubject(), salt); + this.predicate = (P) JenaFactory.fromJena(triple.getPredicate(), salt); + this.object = (O)JenaFactory.fromJena(triple.getObject(), salt); + this.graphName = Optional.empty(); + } + + @Override + public org.apache.jena.sparql.core.Quad asJenaQuad() { + if (quad == null) { + quad = org.apache.jena.sparql.core.Quad.create( + JenaRDFTermFactory.toJena(graphName.orElse(null)), + JenaRDFTermFactory.toJena(subject), + JenaRDFTermFactory.toJena(predicate), + JenaRDFTermFactory.toJena(object)); + } + return quad; + } + + @Override + public org.apache.jena.graph.Triple asJenaTriple() { + if (triple == null) { + triple = org.apache.jena.graph.Triple.create(JenaRDFTermFactory.toJena(subject), + JenaRDFTermFactory.toJena(predicate), + JenaRDFTermFactory.toJena(object)); + } + return triple; + } + + @Override + public S getSubject() { + return subject; + } + + @Override + public P getPredicate() { + return predicate; + } + + @Override + public O getObject() { + return object; + } + + @Override + public Optional<G> getGraphName() { + return graphName; + } + + @Override + public String toString() { + // kind of nquad syntax + return getSubject().ntriplesString() + " " + + getPredicate().ntriplesString() + " " + + getObject().ntriplesString() + " " + + getGraphName().map(RDFTerm::ntriplesString).orElse("") + "."; + } + +} http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/6c17d5ed/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaGraphImpl.java ---------------------------------------------------------------------- diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaGraphImpl.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaGraphImpl.java new file mode 100644 index 0000000..49a09ae --- /dev/null +++ b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaGraphImpl.java @@ -0,0 +1,154 @@ +/** + * 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.jena.impl; + +import java.io.StringWriter; +import java.util.UUID; +import java.util.stream.Stream; + +import org.apache.commons.rdf.api.BlankNodeOrIRI; +import org.apache.commons.rdf.api.IRI; +import org.apache.commons.rdf.api.RDFTerm; +import org.apache.commons.rdf.api.Triple; +import org.apache.commons.rdf.jena.JenaGraph; +import org.apache.commons.rdf.jena.JenaRDFTermFactory; +import org.apache.jena.atlas.iterator.Iter; +import org.apache.jena.graph.Node; +import org.apache.jena.rdf.model.Model; +import org.apache.jena.rdf.model.ModelFactory; +import org.apache.jena.riot.Lang; +import org.apache.jena.riot.RDFDataMgr; + +public class JenaGraphImpl implements JenaGraph { + + private org.apache.jena.graph.Graph graph; + private UUID salt; + private Model model; + + JenaGraphImpl(org.apache.jena.graph.Graph graph, UUID salt) { + this.graph = graph; + this.salt = salt; + } + + JenaGraphImpl(Model model, UUID salt) { + this.model = model; + this.graph = model.getGraph(); + this.salt = salt; + } + + @Override + public void add(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) { + graph.add(org.apache.jena.graph.Triple.create( + JenaRDFTermFactory.toJena(subject), + JenaRDFTermFactory.toJena(predicate), + JenaRDFTermFactory.toJena(object))); + } + + @Override + public void add(Triple triple) { + graph.add(JenaRDFTermFactory.toJena(triple)); + } + + @Override + public org.apache.jena.graph.Graph asJenaGraph() { + return graph; + } + + @Override + public void clear() { + graph.clear(); + } + + @Override + public void close() { + graph.close(); + } + + @Override + public boolean contains(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) { + return graph.contains( + JenaRDFTermFactory.toJena(subject), + JenaRDFTermFactory.toJena(predicate), + JenaRDFTermFactory.toJena(object)); + } + + @Override + public boolean contains(Triple triple) { + return graph.contains(JenaRDFTermFactory.toJena(triple)); + } + + @Override + public void remove(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) { + graph.delete(org.apache.jena.graph.Triple.create( + JenaRDFTermFactory.toJena(subject), + JenaRDFTermFactory.toJena(predicate), + JenaRDFTermFactory.toJena(object))); + } + + @Override + public void remove(Triple triple) { + graph.delete(JenaRDFTermFactory.toJena(triple)); + } + + @Override + public long size() { + return graph.size(); + } + + @Override + public Stream<? extends Triple> stream() { + JenaRDFTermFactory factory = new JenaRDFTermFactory(salt); + return Iter.asStream(graph.find(null, null, null), true).map(factory::fromJena); + } + + @Override + public Stream<? extends Triple> stream(BlankNodeOrIRI s, IRI p, RDFTerm o) { + JenaRDFTermFactory factory = new JenaRDFTermFactory(salt); + return Iter.asStream(graph.find(toJenaAny(s), toJenaAny(p), toJenaAny(o)), true) + .map(factory::fromJena); + } + + private Node toJenaAny(RDFTerm term) { + if (term == null) + return Node.ANY; + return JenaRDFTermFactory.toJena(term); + } + + @Override + public String toString() { + StringWriter sw = new StringWriter(); + RDFDataMgr.write(sw, graph, Lang.NT); + return sw.toString(); + } + + @Override + public Model asJenaModel() { + if (model == null) { + synchronized(this) { + // As Model can be used for locks, we should make sure we don't make + // more than one model + if (model == null) { + model = ModelFactory.createModelForGraph(graph); + } + } + } + return model; + } + +} http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/6c17d5ed/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaIRIImpl.java ---------------------------------------------------------------------- diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaIRIImpl.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaIRIImpl.java new file mode 100644 index 0000000..2aa170f --- /dev/null +++ b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaIRIImpl.java @@ -0,0 +1,61 @@ +/** + * 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.jena.impl; + +import org.apache.commons.rdf.api.IRI; +import org.apache.commons.rdf.jena.JenaIRI; +import org.apache.jena.graph.Node; +import org.apache.jena.graph.NodeFactory; + +public class JenaIRIImpl extends AbstractJenaRDFTerm implements JenaIRI { + + /* package */ JenaIRIImpl(Node node) { + super(node); + if (! node.isURI()) { + throw new IllegalArgumentException("Node is not a blank node: " + node); + } + + } + + /* package */ JenaIRIImpl(String iriStr) { + super(NodeFactory.createURI(iriStr)); + } + + @Override + public boolean equals(Object other) { + if (other == this) + return true; + if (other == null) + return false; + if (!(other instanceof IRI)) + return false; + IRI iri = (IRI) other; + return getIRIString().equals(iri.getIRIString()); + } + + @Override + public String getIRIString() { + return asJenaNode().getURI(); + } + + @Override + public int hashCode() { + return getIRIString().hashCode(); + } +} http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/6c17d5ed/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaLiteralImpl.java ---------------------------------------------------------------------- diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaLiteralImpl.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaLiteralImpl.java new file mode 100644 index 0000000..5bbc166 --- /dev/null +++ b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaLiteralImpl.java @@ -0,0 +1,73 @@ +/** + * 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.jena.impl; + +import java.util.Objects; +import java.util.Optional; + +import org.apache.commons.rdf.api.IRI; +import org.apache.commons.rdf.api.Literal; +import org.apache.commons.rdf.jena.JenaLiteral; +import org.apache.jena.graph.Node; + +public class JenaLiteralImpl extends AbstractJenaRDFTerm implements JenaLiteral { + + /* package */ JenaLiteralImpl(Node node) { + super(node); + if (! node.isLiteral()) { + throw new IllegalArgumentException("Node is not a literal: " + node); + } + } + + @Override + public boolean equals(Object other) { + if (other == this) + return true; + if (other == null) + return false; + if (!(other instanceof Literal)) + return false; + Literal literal = (Literal) other; + return getLexicalForm().equals(literal.getLexicalForm()) && getLanguageTag().equals(literal.getLanguageTag()) + && getDatatype().equals(literal.getDatatype()); + } + + @Override + public IRI getDatatype() { + return JenaFactory.createIRI(asJenaNode().getLiteralDatatype().getURI()); + } + + @Override + public Optional<String> getLanguageTag() { + String x = asJenaNode().getLiteralLanguage(); + if (x == null || x.isEmpty()) + return Optional.empty(); + return Optional.of(x); + } + + @Override + public String getLexicalForm() { + return asJenaNode().getLiteralLexicalForm(); + } + + @Override + public int hashCode() { + return Objects.hash(getLexicalForm(), getDatatype(), getLanguageTag()); + } +} http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/6c17d5ed/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaQuadImpl.java ---------------------------------------------------------------------- diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaQuadImpl.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaQuadImpl.java new file mode 100644 index 0000000..0f3e3e3 --- /dev/null +++ b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaQuadImpl.java @@ -0,0 +1,66 @@ +/** + * 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.jena.impl; + +import java.util.Objects; +import java.util.Optional; +import java.util.UUID; + +import org.apache.commons.rdf.api.BlankNodeOrIRI; +import org.apache.commons.rdf.api.IRI; +import org.apache.commons.rdf.api.Quad; +import org.apache.commons.rdf.api.RDFTerm; +import org.apache.commons.rdf.jena.ConversionException; +import org.apache.commons.rdf.jena.JenaQuad; + +public class JenaQuadImpl extends JenaGeneralizedQuad<BlankNodeOrIRI,IRI,RDFTerm,BlankNodeOrIRI> + implements JenaQuad { + + JenaQuadImpl(BlankNodeOrIRI subject, IRI predicate, RDFTerm object, Optional<BlankNodeOrIRI> graphName) { + super(subject, predicate, object, graphName); + } + + JenaQuadImpl(org.apache.jena.sparql.core.Quad quad, UUID salt) { + super(quad, salt); + // Check the conversion + if ((graphName.isPresent() && ! (graphName.get() instanceof BlankNodeOrIRI)) || + ! (subject instanceof BlankNodeOrIRI) || + ! (predicate instanceof IRI) || + ! (object instanceof RDFTerm)) { + throw new ConversionException("Can't adapt generalized quad: " + quad); + } + } + + @Override + public boolean equals(Object other) { + if (other == this) + return true; + if (!(other instanceof Quad)) + return false; + Quad quad = (Quad) other; + return getGraphName().equals(quad.getGraphName()) && getSubject().equals(quad.getSubject()) + && getPredicate().equals(quad.getPredicate()) && getObject().equals(quad.getObject()); + } + + @Override + public int hashCode() { + return Objects.hash(getSubject(), getPredicate(), getObject(), getGraphName()); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/6c17d5ed/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaTripleImpl.java ---------------------------------------------------------------------- diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaTripleImpl.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaTripleImpl.java new file mode 100644 index 0000000..4e497f2 --- /dev/null +++ b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaTripleImpl.java @@ -0,0 +1,67 @@ +/** + * 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.jena.impl; + +import java.util.Objects; +import java.util.UUID; + +import org.apache.commons.rdf.api.BlankNodeOrIRI; +import org.apache.commons.rdf.api.IRI; +import org.apache.commons.rdf.api.RDFTerm; +import org.apache.commons.rdf.api.Triple; +import org.apache.commons.rdf.jena.ConversionException; +import org.apache.commons.rdf.jena.JenaTriple; + +public class JenaTripleImpl extends JenaGeneralizedQuad<BlankNodeOrIRI, IRI, RDFTerm, RDFTerm> + implements JenaTriple { + + JenaTripleImpl(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) { + super(subject, predicate, object); + } + + JenaTripleImpl(org.apache.jena.graph.Triple triple, UUID salt) throws ConversionException { + super(triple, salt); + // Check the conversion + if (! (subject instanceof BlankNodeOrIRI) || + ! (predicate instanceof IRI) || + ! (object instanceof RDFTerm)) { + throw new ConversionException("Can't adapt generalized triple: " + quad); + } + } + + @Override + public boolean equals(Object other) { + if (other == this) + return true; + if (other == null) + return false; + if (!(other instanceof Triple)) + return false; + Triple triple = (Triple) other; + return getSubject().equals(triple.getSubject()) && getPredicate().equals(triple.getPredicate()) + && getObject().equals(triple.getObject()); + } + + @Override + public int hashCode() { + return Objects.hash(getSubject(), getPredicate(), getObject()); + } + + +} http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/6c17d5ed/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaVariableImpl.java ---------------------------------------------------------------------- diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaVariableImpl.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaVariableImpl.java new file mode 100644 index 0000000..8027cf2 --- /dev/null +++ b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaVariableImpl.java @@ -0,0 +1,64 @@ +/** + * 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.jena.impl; + +import java.util.Objects; + +import org.apache.commons.rdf.jena.JenaRDFTerm; +import org.apache.commons.rdf.jena.JenaVariable; +import org.apache.jena.graph.Node; + +public class JenaVariableImpl implements JenaRDFTerm, JenaVariable { + + private Node node; + + JenaVariableImpl(Node node) { + if (! node.isVariable()) { + throw new IllegalArgumentException("Node is not a variable: " + node); + } + this.node = node; + } + + @Override + public String ntriplesString() { + return "?" + getVariableName(); + } + + @Override + public String getVariableName() { + return node.getName(); + } + + @Override + public Node asJenaNode() { + return node; + } + + @Override + public boolean equals(Object obj) { + if (obj == this) { + return true; + } + if (! (obj instanceof JenaVariable)) { + return false; + } + return Objects.equals(getVariableName(), ((JenaVariable)obj).getVariableName()); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/6c17d5ed/jena/src/main/java/org/apache/commons/rdf/jena/impl/LiteralImpl.java ---------------------------------------------------------------------- diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/LiteralImpl.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/LiteralImpl.java deleted file mode 100644 index 2750198..0000000 --- a/jena/src/main/java/org/apache/commons/rdf/jena/impl/LiteralImpl.java +++ /dev/null @@ -1,73 +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.jena.impl; - -import java.util.Objects; -import java.util.Optional; - -import org.apache.commons.rdf.api.IRI; -import org.apache.commons.rdf.api.Literal; -import org.apache.commons.rdf.jena.JenaLiteral; -import org.apache.jena.graph.Node; - -public class LiteralImpl extends AbstractRDFTerm implements JenaLiteral { - - /* package */ LiteralImpl(Node node) { - super(node); - if (! node.isLiteral()) { - throw new IllegalArgumentException("Node is not a literal: " + node); - } - } - - @Override - public boolean equals(Object other) { - if (other == this) - return true; - if (other == null) - return false; - if (!(other instanceof Literal)) - return false; - Literal literal = (Literal) other; - return getLexicalForm().equals(literal.getLexicalForm()) && getLanguageTag().equals(literal.getLanguageTag()) - && getDatatype().equals(literal.getDatatype()); - } - - @Override - public IRI getDatatype() { - return JenaFactory.createIRI(asJenaNode().getLiteralDatatype().getURI()); - } - - @Override - public Optional<String> getLanguageTag() { - String x = asJenaNode().getLiteralLanguage(); - if (x == null || x.isEmpty()) - return Optional.empty(); - return Optional.of(x); - } - - @Override - public String getLexicalForm() { - return asJenaNode().getLiteralLexicalForm(); - } - - @Override - public int hashCode() { - return Objects.hash(getLexicalForm(), getDatatype(), getLanguageTag()); - } -} http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/6c17d5ed/jena/src/main/java/org/apache/commons/rdf/jena/impl/QuadImpl.java ---------------------------------------------------------------------- diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/QuadImpl.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/QuadImpl.java deleted file mode 100644 index d68fcaf..0000000 --- a/jena/src/main/java/org/apache/commons/rdf/jena/impl/QuadImpl.java +++ /dev/null @@ -1,66 +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.jena.impl; - -import java.util.Objects; -import java.util.Optional; -import java.util.UUID; - -import org.apache.commons.rdf.api.BlankNodeOrIRI; -import org.apache.commons.rdf.api.IRI; -import org.apache.commons.rdf.api.Quad; -import org.apache.commons.rdf.api.RDFTerm; -import org.apache.commons.rdf.jena.ConversionException; -import org.apache.commons.rdf.jena.JenaQuad; - -public class QuadImpl extends GeneralizedQuadImpl<BlankNodeOrIRI,IRI,RDFTerm,BlankNodeOrIRI> - implements JenaQuad { - - QuadImpl(BlankNodeOrIRI subject, IRI predicate, RDFTerm object, Optional<BlankNodeOrIRI> graphName) { - super(subject, predicate, object, graphName); - } - - QuadImpl(org.apache.jena.sparql.core.Quad quad, UUID salt) { - super(quad, salt); - // Check the conversion - if ((graphName.isPresent() && ! (graphName.get() instanceof BlankNodeOrIRI)) || - ! (subject instanceof BlankNodeOrIRI) || - ! (predicate instanceof IRI) || - ! (object instanceof RDFTerm)) { - throw new ConversionException("Can't adapt generalized quad: " + quad); - } - } - - @Override - public boolean equals(Object other) { - if (other == this) - return true; - if (!(other instanceof Quad)) - return false; - Quad quad = (Quad) other; - return getGraphName().equals(quad.getGraphName()) && getSubject().equals(quad.getSubject()) - && getPredicate().equals(quad.getPredicate()) && getObject().equals(quad.getObject()); - } - - @Override - public int hashCode() { - return Objects.hash(getSubject(), getPredicate(), getObject(), getGraphName()); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/6c17d5ed/jena/src/main/java/org/apache/commons/rdf/jena/impl/TripleImpl.java ---------------------------------------------------------------------- diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/TripleImpl.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/TripleImpl.java deleted file mode 100644 index 9207b38..0000000 --- a/jena/src/main/java/org/apache/commons/rdf/jena/impl/TripleImpl.java +++ /dev/null @@ -1,67 +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.jena.impl; - -import java.util.Objects; -import java.util.UUID; - -import org.apache.commons.rdf.api.BlankNodeOrIRI; -import org.apache.commons.rdf.api.IRI; -import org.apache.commons.rdf.api.RDFTerm; -import org.apache.commons.rdf.api.Triple; -import org.apache.commons.rdf.jena.ConversionException; -import org.apache.commons.rdf.jena.JenaTriple; - -public class TripleImpl extends GeneralizedQuadImpl<BlankNodeOrIRI, IRI, RDFTerm, RDFTerm> - implements JenaTriple { - - TripleImpl(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) { - super(subject, predicate, object); - } - - TripleImpl(org.apache.jena.graph.Triple triple, UUID salt) throws ConversionException { - super(triple, salt); - // Check the conversion - if (! (subject instanceof BlankNodeOrIRI) || - ! (predicate instanceof IRI) || - ! (object instanceof RDFTerm)) { - throw new ConversionException("Can't adapt generalized triple: " + quad); - } - } - - @Override - public boolean equals(Object other) { - if (other == this) - return true; - if (other == null) - return false; - if (!(other instanceof Triple)) - return false; - Triple triple = (Triple) other; - return getSubject().equals(triple.getSubject()) && getPredicate().equals(triple.getPredicate()) - && getObject().equals(triple.getObject()); - } - - @Override - public int hashCode() { - return Objects.hash(getSubject(), getPredicate(), getObject()); - } - - -} http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/6c17d5ed/jena/src/main/java/org/apache/commons/rdf/jena/impl/VariableImpl.java ---------------------------------------------------------------------- diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/VariableImpl.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/VariableImpl.java deleted file mode 100644 index b72ecde..0000000 --- a/jena/src/main/java/org/apache/commons/rdf/jena/impl/VariableImpl.java +++ /dev/null @@ -1,64 +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.jena.impl; - -import java.util.Objects; - -import org.apache.commons.rdf.jena.JenaRDFTerm; -import org.apache.commons.rdf.jena.JenaVariable; -import org.apache.jena.graph.Node; - -public class VariableImpl implements JenaRDFTerm, JenaVariable { - - private Node node; - - VariableImpl(Node node) { - if (! node.isVariable()) { - throw new IllegalArgumentException("Node is not a variable: " + node); - } - this.node = node; - } - - @Override - public String ntriplesString() { - return "?" + getVariableName(); - } - - @Override - public String getVariableName() { - return node.getName(); - } - - @Override - public Node asJenaNode() { - return node; - } - - @Override - public boolean equals(Object obj) { - if (obj == this) { - return true; - } - if (! (obj instanceof JenaVariable)) { - return false; - } - return Objects.equals(getVariableName(), ((JenaVariable)obj).getVariableName()); - } - -}