Fixing license headers, more tests
Project: http://git-wip-us.apache.org/repos/asf/jena/repo Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/7cd63e34 Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/7cd63e34 Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/7cd63e34 Branch: refs/heads/master Commit: 7cd63e34b42d127bccb207b25c0680fae2a0e728 Parents: e280c2a Author: ajs6f <[email protected]> Authored: Fri Dec 29 10:04:36 2017 -0500 Committer: ajs6f <[email protected]> Committed: Fri Jan 5 09:26:07 2018 -0500 ---------------------------------------------------------------------- .../jena/query/util/DatasetCollector.java | 18 ++++++ .../org/apache/jena/query/util/DatasetLib.java | 18 ++++++ .../sparql/util/DifferenceDatasetGraph.java | 59 ++++++++++++++--- .../sparql/util/IntersectionDatasetGraph.java | 23 +++++++ .../jena/sparql/util/UnionDatasetGraph.java | 45 ++++++++++++- .../jena/sparql/util/ViewDatasetGraph.java | 18 ++++++ .../sparql/util/TestDifferenceDatasetGraph.java | 18 ++++++ .../util/TestIntersectionDatasetGraph.java | 18 ++++++ .../jena/sparql/util/TestUnionDatasetGraph.java | 18 ++++++ .../jena/sparql/util/TestViewDatasetGraph.java | 66 +++++++++++++++++++- 10 files changed, 286 insertions(+), 15 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/jena/blob/7cd63e34/jena-arq/src/main/java/org/apache/jena/query/util/DatasetCollector.java ---------------------------------------------------------------------- diff --git a/jena-arq/src/main/java/org/apache/jena/query/util/DatasetCollector.java b/jena-arq/src/main/java/org/apache/jena/query/util/DatasetCollector.java index 8779c4c..dfcc2c5 100644 --- a/jena-arq/src/main/java/org/apache/jena/query/util/DatasetCollector.java +++ b/jena-arq/src/main/java/org/apache/jena/query/util/DatasetCollector.java @@ -1,3 +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.jena.query.util; import static org.apache.jena.atlas.iterator.Iter.filter; http://git-wip-us.apache.org/repos/asf/jena/blob/7cd63e34/jena-arq/src/main/java/org/apache/jena/query/util/DatasetLib.java ---------------------------------------------------------------------- diff --git a/jena-arq/src/main/java/org/apache/jena/query/util/DatasetLib.java b/jena-arq/src/main/java/org/apache/jena/query/util/DatasetLib.java index 82ef4f7..5c82dbc 100644 --- a/jena-arq/src/main/java/org/apache/jena/query/util/DatasetLib.java +++ b/jena-arq/src/main/java/org/apache/jena/query/util/DatasetLib.java @@ -1,3 +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.jena.query.util; import static org.apache.jena.sparql.util.Context.emptyContext; http://git-wip-us.apache.org/repos/asf/jena/blob/7cd63e34/jena-arq/src/main/java/org/apache/jena/sparql/util/DifferenceDatasetGraph.java ---------------------------------------------------------------------- diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/util/DifferenceDatasetGraph.java b/jena-arq/src/main/java/org/apache/jena/sparql/util/DifferenceDatasetGraph.java index 8c27f81..71fc1ea 100644 --- a/jena-arq/src/main/java/org/apache/jena/sparql/util/DifferenceDatasetGraph.java +++ b/jena-arq/src/main/java/org/apache/jena/sparql/util/DifferenceDatasetGraph.java @@ -1,15 +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.jena.sparql.util; import static org.apache.jena.sparql.core.Quad.ANY; -import static org.apache.jena.sparql.core.Quad.isDefaultGraph; import java.util.Iterator; import java.util.function.Function; -import org.apache.jena.graph.Graph; -import org.apache.jena.graph.Node; +import org.apache.jena.graph.*; import org.apache.jena.graph.compose.Difference; import org.apache.jena.sparql.core.DatasetGraph; +import org.apache.jena.util.iterator.ExtendedIterator; +import org.apache.jena.util.iterator.NullIterator; public class DifferenceDatasetGraph extends ViewDatasetGraph { @@ -18,7 +36,7 @@ public class DifferenceDatasetGraph extends ViewDatasetGraph { } private Graph difference(Function<DatasetGraph, Graph> op) { - return join(Difference::new, op); + return join(DifferenceView::new, op); } @Override @@ -28,11 +46,7 @@ public class DifferenceDatasetGraph extends ViewDatasetGraph { @Override public Graph getGraph(Node graphNode) { - return isDefaultGraph(graphNode) - ? getDefaultGraph() - : getRight().containsGraph(graphNode) - ? difference(dsg -> dsg.getGraph(graphNode)) - : getLeft().getGraph(graphNode); + return difference(dsg -> dsg.getGraph(graphNode)); } @Override @@ -59,4 +73,31 @@ public class DifferenceDatasetGraph extends ViewDatasetGraph { public long size() { return getLeft().size(); } + + static class DifferenceView extends Difference { + + public DifferenceView(Graph L, Graph R) { + super(L, R); + } + + @Override + public void performAdd(Triple t) { + DifferenceDatasetGraph.throwNoMutationAllowed(); + } + + @Override + public void performDelete(Triple t) { + DifferenceDatasetGraph.throwNoMutationAllowed(); + } + + @Override + public void clear() { + DifferenceDatasetGraph.throwNoMutationAllowed(); + } + + @Override + public ExtendedIterator<Triple> _graphBaseFind(Triple s) { + return L.isEmpty() ? NullIterator.instance() : super._graphBaseFind(s); + } + } } http://git-wip-us.apache.org/repos/asf/jena/blob/7cd63e34/jena-arq/src/main/java/org/apache/jena/sparql/util/IntersectionDatasetGraph.java ---------------------------------------------------------------------- diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/util/IntersectionDatasetGraph.java b/jena-arq/src/main/java/org/apache/jena/sparql/util/IntersectionDatasetGraph.java index 20a0e3b..23c995e 100644 --- a/jena-arq/src/main/java/org/apache/jena/sparql/util/IntersectionDatasetGraph.java +++ b/jena-arq/src/main/java/org/apache/jena/sparql/util/IntersectionDatasetGraph.java @@ -1,3 +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.jena.sparql.util; import static org.apache.jena.atlas.iterator.Iter.iter; @@ -64,6 +82,11 @@ public class IntersectionDatasetGraph extends ViewDatasetGraph { public void performDelete(Triple t) { IntersectionDatasetGraph.throwNoMutationAllowed(); } + + @Override + public void clear() { + IntersectionDatasetGraph.throwNoMutationAllowed(); + } @Override protected ExtendedIterator<Triple> _graphBaseFind(Triple s) { http://git-wip-us.apache.org/repos/asf/jena/blob/7cd63e34/jena-arq/src/main/java/org/apache/jena/sparql/util/UnionDatasetGraph.java ---------------------------------------------------------------------- diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/util/UnionDatasetGraph.java b/jena-arq/src/main/java/org/apache/jena/sparql/util/UnionDatasetGraph.java index 516263b..2fca7ee 100644 --- a/jena-arq/src/main/java/org/apache/jena/sparql/util/UnionDatasetGraph.java +++ b/jena-arq/src/main/java/org/apache/jena/sparql/util/UnionDatasetGraph.java @@ -1,11 +1,28 @@ +/* + * 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.jena.sparql.util; import java.util.Iterator; import java.util.function.Function; import org.apache.jena.atlas.iterator.Iter; -import org.apache.jena.graph.Graph; -import org.apache.jena.graph.Node; +import org.apache.jena.graph.*; import org.apache.jena.graph.compose.Union; import org.apache.jena.sparql.core.DatasetGraph; import org.apache.jena.sparql.core.Quad; @@ -17,7 +34,7 @@ public class UnionDatasetGraph extends ViewDatasetGraph { } private Graph union(Function<DatasetGraph, Graph> op) { - return join(Union::new, op); + return join(UnionView::new, op); } <T> Iter<T> fromEach(Function<DatasetGraph, Iterator<T>> op) { @@ -68,4 +85,26 @@ public class UnionDatasetGraph extends ViewDatasetGraph { public boolean isEmpty() { return both(DatasetGraph::isEmpty); } + + static class UnionView extends Union { + + public UnionView(Graph L, Graph R) { + super(L, R); + } + + @Override + public void performAdd(Triple t) { + UnionDatasetGraph.throwNoMutationAllowed(); + } + + @Override + public void performDelete(Triple t) { + UnionDatasetGraph.throwNoMutationAllowed(); + } + + @Override + public void clear() { + UnionDatasetGraph.throwNoMutationAllowed(); + } + } } http://git-wip-us.apache.org/repos/asf/jena/blob/7cd63e34/jena-arq/src/main/java/org/apache/jena/sparql/util/ViewDatasetGraph.java ---------------------------------------------------------------------- diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/util/ViewDatasetGraph.java b/jena-arq/src/main/java/org/apache/jena/sparql/util/ViewDatasetGraph.java index 6d12292..5717ae4 100644 --- a/jena-arq/src/main/java/org/apache/jena/sparql/util/ViewDatasetGraph.java +++ b/jena-arq/src/main/java/org/apache/jena/sparql/util/ViewDatasetGraph.java @@ -1,3 +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.jena.sparql.util; import static java.util.Objects.requireNonNull; http://git-wip-us.apache.org/repos/asf/jena/blob/7cd63e34/jena-arq/src/test/java/org/apache/jena/sparql/util/TestDifferenceDatasetGraph.java ---------------------------------------------------------------------- diff --git a/jena-arq/src/test/java/org/apache/jena/sparql/util/TestDifferenceDatasetGraph.java b/jena-arq/src/test/java/org/apache/jena/sparql/util/TestDifferenceDatasetGraph.java index f775efd..41510d0 100644 --- a/jena-arq/src/test/java/org/apache/jena/sparql/util/TestDifferenceDatasetGraph.java +++ b/jena-arq/src/test/java/org/apache/jena/sparql/util/TestDifferenceDatasetGraph.java @@ -1,3 +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.jena.sparql.util; import static org.apache.jena.sparql.sse.SSE.parseGraph; http://git-wip-us.apache.org/repos/asf/jena/blob/7cd63e34/jena-arq/src/test/java/org/apache/jena/sparql/util/TestIntersectionDatasetGraph.java ---------------------------------------------------------------------- diff --git a/jena-arq/src/test/java/org/apache/jena/sparql/util/TestIntersectionDatasetGraph.java b/jena-arq/src/test/java/org/apache/jena/sparql/util/TestIntersectionDatasetGraph.java index d1c30e1..df52959 100644 --- a/jena-arq/src/test/java/org/apache/jena/sparql/util/TestIntersectionDatasetGraph.java +++ b/jena-arq/src/test/java/org/apache/jena/sparql/util/TestIntersectionDatasetGraph.java @@ -1,3 +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.jena.sparql.util; import static org.apache.jena.sparql.sse.SSE.parseGraph; http://git-wip-us.apache.org/repos/asf/jena/blob/7cd63e34/jena-arq/src/test/java/org/apache/jena/sparql/util/TestUnionDatasetGraph.java ---------------------------------------------------------------------- diff --git a/jena-arq/src/test/java/org/apache/jena/sparql/util/TestUnionDatasetGraph.java b/jena-arq/src/test/java/org/apache/jena/sparql/util/TestUnionDatasetGraph.java index 6ca5a02..9571bdb 100644 --- a/jena-arq/src/test/java/org/apache/jena/sparql/util/TestUnionDatasetGraph.java +++ b/jena-arq/src/test/java/org/apache/jena/sparql/util/TestUnionDatasetGraph.java @@ -1,3 +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.jena.sparql.util; import static org.apache.jena.sparql.sse.SSE.parseGraph; http://git-wip-us.apache.org/repos/asf/jena/blob/7cd63e34/jena-arq/src/test/java/org/apache/jena/sparql/util/TestViewDatasetGraph.java ---------------------------------------------------------------------- diff --git a/jena-arq/src/test/java/org/apache/jena/sparql/util/TestViewDatasetGraph.java b/jena-arq/src/test/java/org/apache/jena/sparql/util/TestViewDatasetGraph.java index 4f3390e..68a60d3 100644 --- a/jena-arq/src/test/java/org/apache/jena/sparql/util/TestViewDatasetGraph.java +++ b/jena-arq/src/test/java/org/apache/jena/sparql/util/TestViewDatasetGraph.java @@ -1,9 +1,30 @@ +/* + * 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.jena.sparql.util; +import static org.apache.jena.sparql.core.DatasetGraphFactory.createTxnMem; + import org.apache.jena.atlas.junit.BaseTest; +import org.apache.jena.graph.Node; +import org.apache.jena.graph.NodeFactory; import org.apache.jena.query.ReadWrite; -import org.apache.jena.sparql.core.DatasetGraph; -import org.apache.jena.sparql.core.DatasetGraphZero; +import org.apache.jena.sparql.core.*; import org.junit.Test; public abstract class TestViewDatasetGraph extends BaseTest { @@ -11,7 +32,7 @@ public abstract class TestViewDatasetGraph extends BaseTest { public abstract DatasetGraph testInstance(DatasetGraph left, DatasetGraph right, Context c); private DatasetGraph emptyDsg() { - return testInstance(new DatasetGraphZero(), new DatasetGraphZero(), Context.emptyContext); + return testInstance(createTxnMem(), createTxnMem(), Context.emptyContext); } @Test(expected = NullPointerException.class) @@ -63,6 +84,45 @@ public abstract class TestViewDatasetGraph extends BaseTest { public void noClearing() { emptyDsg().clear(); } + + @Test(expected = UnsupportedOperationException.class) + public void noAddingToDefaultGraph() { + emptyDsg().getDefaultGraph().add(null); + } + + @Test(expected = UnsupportedOperationException.class) + public void noDeletingFromDefaultGraph() { + emptyDsg().getDefaultGraph().delete(null); + } + + @Test(expected = UnsupportedOperationException.class) + public void noAddingToANamedGraph() { + Node graphName = NodeFactory.createBlankNode(); + emptyDsg().getGraph(graphName).add(null); + } + + @Test(expected = UnsupportedOperationException.class) + public void noDeletingFromANamedGraph() { + Node graphName = NodeFactory.createBlankNode(); + emptyDsg().getGraph(graphName).delete(null); + } + + @Test(expected = UnsupportedOperationException.class) + public void noClearingDefaultGraph() { + emptyDsg().getDefaultGraph().clear(); + } + + @Test(expected = UnsupportedOperationException.class) + public void noClearingANamedGraph() { + Node graphName = NodeFactory.createBlankNode(); + emptyDsg().getGraph(graphName).clear(); + } + + @Test(expected = UnsupportedOperationException.class) + public void noRemovingFromANamedGraph() { + Node graphName = NodeFactory.createBlankNode(); + emptyDsg().getGraph(graphName).remove(null, null, null); + } @Test(expected = UnsupportedOperationException.class) public void noWriting() {
