### Question:
UnionGraph extends AbstractGraph { @Override public boolean add(Triple e) { if (baseTripleCollections.length == 0) { throw new RuntimeException("no base graph for adding triples"); } return baseTripleCollections[0].add(e); } UnionGraph(Graph... baseTripleCollections); @Override int performSize(); @Override Iterator<Triple> performFilter(final BlankNodeOrIRI subject,
                                          final IRI predicate, final RDFTerm object); @Override boolean add(Triple e); @Override boolean remove(Object e); @Override boolean equals(Object obj); @Override int hashCode(); @Override ReadWriteLock getLock();  }### Answer:
@Test public void readAccess() { Graph graph = new SimpleGraph(); Graph graph2 = new SimpleGraph(); BlankNode bnode = new BlankNode() { }; graph.add(new TripleImpl(uriRef1, uriRef2, uriRef1)); graph2.add(new TripleImpl(bnode, uriRef1, uriRef3)); Graph unionGraph = new UnionGraph(graph, graph2); Iterator<Triple> unionTriples = unionGraph.iterator(); Assert.assertTrue(unionTriples.hasNext()); unionTriples.next(); Assert.assertTrue(unionTriples.hasNext()); unionTriples.next(); Assert.assertFalse(unionTriples.hasNext()); Assert.assertEquals(2, unionGraph.size()); }
@Test public void writeAccess() { Graph graph = new SimpleGraph(); Graph graph2 = new SimpleGraph(); BlankNode bnode = new BlankNode() { }; graph2.add(new TripleImpl(bnode, uriRef1, uriRef3)); Graph unionGraph = new UnionGraph(graph, graph2); Assert.assertEquals(1, unionGraph.size()); unionGraph.add(new TripleImpl(uriRef4, uriRef1, uriRef3)); Assert.assertEquals(1, graph.size()); Assert.assertEquals(2, unionGraph.size()); Assert.assertEquals(1, graph2.size()); }