This is an automated email from the ASF dual-hosted git repository. andy pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/jena.git
commit 22967641b072e3b37ff41ea2dc6975c7772a80ee Author: Andy Seaborne <[email protected]> AuthorDate: Sat May 10 14:25:21 2025 +0100 Deprecate for removal: MonitorGraph, MonitorModel --- .../java/org/apache/jena/util/MonitorGraph.java | 21 +++++---- .../java/org/apache/jena/util/MonitorModel.java | 4 +- .../java/org/apache/jena/util/TestMonitors.java | 54 +++++++++++----------- 3 files changed, 42 insertions(+), 37 deletions(-) diff --git a/jena-core/src/main/java/org/apache/jena/util/MonitorGraph.java b/jena-core/src/main/java/org/apache/jena/util/MonitorGraph.java index dbfb47a722..a3320f475d 100644 --- a/jena-core/src/main/java/org/apache/jena/util/MonitorGraph.java +++ b/jena-core/src/main/java/org/apache/jena/util/MonitorGraph.java @@ -25,15 +25,18 @@ import org.apache.jena.graph.impl.* ; /** * Graph wrapper which provides normal access to an underlying graph but - * also maintains a snapshot of the triples it was last known to contain. + * also maintains a snapshot of the triples it was last known to contain. * A snapshot action * causes the set of changes between this and the previous snapshot to - * be calculated and the cache updated. The snapshot process will also + * be calculated and the cache updated. The snapshot process will also * fire change notification. + * + * @deprecated Do not use - to be removed. */ +@Deprecated(forRemoval = true) public class MonitorGraph extends WrappedGraph { - + /** The last known snapshot, a set of triples */ protected Set<Triple> snapshot = new HashSet<>(); @@ -41,7 +44,7 @@ public class MonitorGraph extends WrappedGraph { public MonitorGraph(Graph g) { super(g); } - + /** * Compute the differences between the current monitored graph and the last * snapshot. The changes will also be forwarded to any listeners. @@ -53,11 +56,11 @@ public class MonitorGraph extends WrappedGraph { boolean listening = getEventManager().listening(); boolean wantAdditions = listening || additions != null; boolean wantDeletions = listening || deletions != null; - + List<Triple> additionsTemp = (additions != null) ? additions : new ArrayList<>(); List<Triple> deletionsTemp = (deletions != null) ? deletions : new ArrayList<>(); Set<Triple> deletionsTempSet = (wantDeletions) ? new HashSet<>() : null; - + if (wantAdditions || wantDeletions) { if (wantDeletions) { deletionsTempSet.addAll(snapshot); @@ -77,12 +80,12 @@ public class MonitorGraph extends WrappedGraph { // for the method signature for compatibility with listeners deletionsTemp.addAll(deletionsTempSet); } - + if (listening) { getEventManager().notifyAddList(this, additionsTemp); getEventManager().notifyDeleteList(this, deletionsTemp); } - + // Update shapshot // In somecases applying the already computed changes may be cheaper, could optmize // this based on relative sizes if it becomes an issue. @@ -92,5 +95,5 @@ public class MonitorGraph extends WrappedGraph { } } - + } diff --git a/jena-core/src/main/java/org/apache/jena/util/MonitorModel.java b/jena-core/src/main/java/org/apache/jena/util/MonitorModel.java index 2353775a95..881f518cea 100644 --- a/jena-core/src/main/java/org/apache/jena/util/MonitorModel.java +++ b/jena-core/src/main/java/org/apache/jena/util/MonitorModel.java @@ -31,8 +31,10 @@ import org.apache.jena.rdf.model.impl.ModelCom ; * causes the set of changes between this and the previous snapshot to * be calculated and the cache updated. The snapshot process will also * fire change notification. + * + * @deprecated Do not use - to be removed. */ - +@Deprecated(forRemoval = true) public class MonitorModel extends ModelCom { /** diff --git a/jena-core/src/test/java/org/apache/jena/util/TestMonitors.java b/jena-core/src/test/java/org/apache/jena/util/TestMonitors.java index 37a9f5dab0..0b3f68a9c8 100644 --- a/jena-core/src/test/java/org/apache/jena/util/TestMonitors.java +++ b/jena-core/src/test/java/org/apache/jena/util/TestMonitors.java @@ -31,25 +31,25 @@ import org.apache.jena.reasoner.test.TestUtil ; /** * Tests for MonitorGraph implementation. */ - +@SuppressWarnings("removal") public class TestMonitors extends TestCase { /** * Boilerplate for junit - */ + */ public TestMonitors( String name ) { - super( name ); + super( name ); } - + /** * Boilerplate for junit. * This is its own test suite */ public static TestSuite suite() { - return new TestSuite( TestMonitors.class ); - } + return new TestSuite( TestMonitors.class ); + } - // constants used in the tests + // constants used in the tests String NS = "http://jena.hpl.hp.com/test#"; Node a = NodeCreateUtils.create(NS + "a"); Node p = NodeCreateUtils.create(NS + "p"); @@ -59,32 +59,32 @@ public class TestMonitors extends TestCase { Triple t4 = Triple.create(a, p, NodeCreateUtils.create(NS + "v4")); Triple t5 = Triple.create(a, p, NodeCreateUtils.create(NS + "v5")); Triple t6 = Triple.create(a, p, NodeCreateUtils.create(NS + "v6")); - + /** * Basic graph level test, no monitoring */ public void testBasics() { Graph base = GraphMemFactory.createGraphMem(); MonitorGraph monitor = new MonitorGraph(base); - + // base data base.add(t1); base.add(t2); base.add(t3); - + // Test changes from empty List<Triple> additions = new ArrayList<>(); List<Triple> deletions = new ArrayList<>(); monitor.snapshot(additions, deletions); TestUtil.assertIteratorValues(this, additions.iterator(), new Object[] {t1, t2, t3}); TestUtil.assertIteratorValues(this, deletions.iterator(), new Object[] {}); - + // Make some new changes base.add(t4); base.add(t5); base.delete(t1); base.delete(t2); - + additions.clear(); deletions.clear(); monitor.snapshot(additions, deletions); @@ -92,7 +92,7 @@ public class TestMonitors extends TestCase { TestUtil.assertIteratorValues(this, deletions.iterator(), new Object[] {t1, t2}); TestUtil.assertIteratorValues(this, monitor.find(Node.ANY, Node.ANY, Node.ANY), new Object[] {t3, t4, t5}); } - + /** * Monitoring test. */ @@ -105,36 +105,36 @@ public class TestMonitors extends TestCase { base.add(t1); base.add(t2); base.add(t3); - + listener.has(new Object[]{}); - + // Test changes from empty List<Triple> additions = new ArrayList<>(); List<Triple> deletions = new ArrayList<>(); monitor.snapshot(additions, deletions); TestUtil.assertIteratorValues(this, additions.iterator(), new Object[] {t1, t2, t3}); TestUtil.assertIteratorValues(this, deletions.iterator(), new Object[] {}); - + listener.assertHas(new Object[] {"addList", monitor, additions, "deleteList", monitor, deletions}); listener.clear(); - + // Make some new changes base.add(t4); base.add(t5); base.delete(t1); base.delete(t2); - + additions.clear(); deletions.clear(); monitor.snapshot(additions, deletions); TestUtil.assertIteratorValues(this, additions.iterator(), new Object[] {t4, t5}); TestUtil.assertIteratorValues(this, deletions.iterator(), new Object[] {t1, t2}); TestUtil.assertIteratorValues(this, monitor.find(Node.ANY, Node.ANY, Node.ANY), new Object[] {t3, t4, t5}); - + listener.assertHas(new Object[] {"addList", monitor, additions, "deleteList", monitor, deletions}); listener.clear(); } - + /** * Test model level access */ @@ -148,16 +148,16 @@ public class TestMonitors extends TestCase { Statement s3 = base.createStatement(ar, pr, "3"); Statement s4 = base.createStatement(ar, pr, "4"); Statement s5 = base.createStatement(ar, pr, "5"); - + MonitorModel monitor = new MonitorModel(base); RecordingModelListener listener = new RecordingModelListener(); monitor.register(listener); - + // base data base.add(s1); base.add(s2); base.add(s3); - + // Test changes from empty List<Statement> additions = new ArrayList<>(); List<Statement> deletions = new ArrayList<>(); @@ -166,22 +166,22 @@ public class TestMonitors extends TestCase { TestUtil.assertIteratorValues(this, deletions.iterator(), new Object[] {}); listener.assertHas(new Object[] {"addList", additions, "removeList", deletions}); listener.clear(); - + // Make some new changes base.add(s4); base.add(s5); base.remove(s1); base.remove(s2); - + additions.clear(); deletions.clear(); monitor.snapshot(additions, deletions); TestUtil.assertIteratorValues(this, additions.iterator(), new Object[] {s4, s5}); TestUtil.assertIteratorValues(this, deletions.iterator(), new Object[] {s1, s2}); TestUtil.assertIteratorValues(this, monitor.listStatements(), new Object[] {s3, s4, s5}); - + listener.assertHas(new Object[] {"addList", additions, "removeList", deletions}); listener.clear(); } - + }
