Skip to content

Commit

Permalink
apacheGH-1419: fix DatasetGraphMap#clear from product and DatasetGrap…
Browse files Browse the repository at this point in the history
…hSimpleMem from test scope
  • Loading branch information
sszuev committed Jul 3, 2022
1 parent 2f9d862 commit 25c00ca
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,12 @@ public Graph getGraph(Node graphNode) {
return g;
}

@Override
public void clear() {
super.clear();
graphs.clear();
}

/** Called from getGraph when a nonexistent graph is asked for.
* Return null for "nothing created as a graph".
* Sub classes can reimplement this.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,23 @@ public abstract class AbstractDatasetGraphTests
assertFalse(dsg.containsGraph(gn)) ;
}

@Test public void clear_02() {
DatasetGraph dsg = emptyDataset();
dsg.add(SSE.parseQuad("(quad _ <a0> <b0> <b0>)"));
dsg.add(SSE.parseQuad("(quad <g1> <a1> <b1> <b1>)"));
dsg.add(SSE.parseQuad("(quad <g2> <a2> <b2> <b2>)"));

assertEquals(2, dsg.size());
assertEquals(1, dsg.getDefaultGraph().size());
assertFalse(dsg.isEmpty());

dsg.clear();

assertEquals(0, dsg.size());
assertEquals(0, dsg.getDefaultGraph().size());
assertTrue(dsg.isEmpty());
}

@Test public void graph_clear_1() {
DatasetGraph dsg = emptyDataset() ;
if ( ! dsg.supportsTransactions() )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ boolean isEmpty() {
int size() {
return store.size();
}

void clear() {
store.clear();
}
}

public DatasetGraphSimpleMem() {}
Expand Down Expand Up @@ -168,7 +172,7 @@ public void performDelete(Triple t) {
protected ExtendedIterator<Triple> graphBaseFind(Triple m) {
List<Triple> results = new ArrayList<>();
for ( Triple t : triples )
if ( t.matches(m.getMatchSubject(), m.getMatchPredicate(), m.getMatchObject()) )
if ( m.matches(t.getMatchSubject(), t.getMatchPredicate(), t.getMatchObject()) )
results.add(t);
return WrappedIterator.create(results.iterator());
}
Expand Down Expand Up @@ -214,6 +218,17 @@ public Graph getGraph(Node graphNode) {
return new GraphNamed(graphNode);
}

@Override
public void clear() {
triples.clear();
quads.clear();
}

@Override
public long size() {
return graphNodes().size();
}

@Override
public boolean containsGraph(Node graphNode) {
return graphNodes().contains(graphNode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
, TestDynamicDatasetMem.class
, TestDatasetGraphsRegular.class
, TestDatasetGraphLink.class
, TestDatasetGraphMap.class
, TestDatasetGraphCopyAdd.class
, TestDatasetGraphViewGraphs.class
, TestGraphView.class
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.apache.jena.sparql.core;

public class TestDatasetGraphMap extends AbstractDatasetGraphTests {

@Override
protected DatasetGraph emptyDataset() {
return new DatasetGraphMap();
}
}

0 comments on commit 25c00ca

Please sign in to comment.