use of org.apache.jena.rdf.model.Statement in project jena by apache.
the class TestModelEvents method testTwoListeners.
public void testTwoListeners() {
final Statement S = ModelHelper.statement(model, "S P O");
final RecordingModelListener SL1 = new RecordingModelListener();
final RecordingModelListener SL2 = new RecordingModelListener();
model.register(SL1).register(SL2);
model.add(S);
SL2.assertHas(new Object[] { "add", S });
SL1.assertHas(new Object[] { "add", S });
}
use of org.apache.jena.rdf.model.Statement in project jena by apache.
the class TestModelSetOperations method testIntersection.
public void testIntersection() {
ModelHelper.modelAdd(model, "a P b; w R x");
ModelHelper.modelAdd(model2, "w R x; y S z");
final Model im = model.intersection(model2);
Assert.assertFalse(model.containsAll(model2));
Assert.assertFalse(model2.containsAll(model));
Assert.assertTrue(model.containsAll(im));
Assert.assertTrue(model2.containsAll(im));
for (final StmtIterator it = im.listStatements(); it.hasNext(); ) {
final Statement s = it.nextStatement();
Assert.assertTrue(model.contains(s) && model2.contains(s));
}
for (final StmtIterator it = im.listStatements(); it.hasNext(); ) {
Assert.assertTrue(model.contains(it.nextStatement()));
}
for (final StmtIterator it = im.listStatements(); it.hasNext(); ) {
Assert.assertTrue(model2.contains(it.nextStatement()));
}
Assert.assertTrue(model.containsAll(im.listStatements()));
Assert.assertTrue(model2.containsAll(im.listStatements()));
}
use of org.apache.jena.rdf.model.Statement in project jena by apache.
the class TestModelSetOperations method testDifference.
public void testDifference() {
ModelHelper.modelAdd(model, "a P b; w R x");
ModelHelper.modelAdd(model2, "w R x; y S z");
final Model dm = model.difference(model2);
for (final StmtIterator it = dm.listStatements(); it.hasNext(); ) {
final Statement s = it.nextStatement();
Assert.assertTrue(model.contains(s) && !model2.contains(s));
}
for (final StmtIterator it = model.union(model2).listStatements(); it.hasNext(); ) {
final Statement s = it.nextStatement();
Assert.assertEquals(model.contains(s) && !model2.contains(s), dm.contains(s));
}
Assert.assertTrue(dm.containsAny(model));
Assert.assertTrue(dm.containsAny(model.listStatements()));
Assert.assertFalse(dm.containsAny(model2));
Assert.assertFalse(dm.containsAny(model2.listStatements()));
Assert.assertTrue(model.containsAll(dm));
}
use of org.apache.jena.rdf.model.Statement in project jena by apache.
the class TestModelEvents method testObjectListener.
public void testObjectListener() {
final OL ll = new OL();
model.register(ll);
final Statement s = ModelHelper.statement(model, "aa BB cc"), s2 = ModelHelper.statement(model, "dd EE ff");
model.add(s);
ll.recent("add", s);
model.remove(s2);
ll.recent("rem", s2);
/* */
final List<Statement> sList = Arrays.asList(ModelHelper.statements(model, "gg HH ii; jj KK ll"));
model.add(sList);
ll.recent("add", sList);
final List<Statement> sList2 = Arrays.asList(ModelHelper.statements(model, "mm NN oo; pp QQ rr; ss TT uu"));
model.remove(sList2);
ll.recent("rem", sList2);
/* */
final Model m1 = ModelHelper.modelWithStatements(this, "vv WW xx; yy ZZ aa");
model.add(m1);
ll.recent("add", m1);
final Model m2 = ModelHelper.modelWithStatements(this, "a B g; d E z");
model.remove(m2);
ll.recent("rem", m2);
/* */
final Statement[] sa1 = ModelHelper.statements(model, "th i k; l model n");
model.add(sa1);
ll.recent("add", sa1);
final Statement[] sa2 = ModelHelper.statements(model, "x o p; r u ch");
model.remove(sa2);
ll.recent("rem", sa2);
/* */
final Statement[] si1 = ModelHelper.statements(model, "u ph ch; psi om eh");
model.add(asIterator(si1));
ll.recent("add", asIterator(si1));
final Statement[] si2 = ModelHelper.statements(model, "at last the; end of these; tests ok guv");
model.remove(asIterator(si2));
ll.recent("rem", asIterator(si2));
}
use of org.apache.jena.rdf.model.Statement in project jena by apache.
the class TestModelEvents method testRemoveSingleStatements.
public void testRemoveSingleStatements() {
final Statement S = ModelHelper.statement(model, "D E F");
model.register(SL);
model.add(S);
model.remove(S);
SL.assertHas(new Object[] { "add", S, "remove", S });
}
Aggregations