CollectionQuadHolder implements QuadHolder { @Override public ExtendedIterator<Quad> getQuads() { if (values == null) { values = Collections.emptyMap(); } return WrappedIterator.create(collection.iterator()) .mapWith( triple -> new Triple( valueMap(triple.getSubject()), valueMap(triple.getPredicate()), valueMap(triple.getObject()) )) .mapWith( triple -> new Quad( defaultGraphName, triple ) ); } CollectionQuadHolder(final Node graph, Collection<Triple> triples);  CollectionQuadHolder(final Node graph, Iterator<Triple> triples);  CollectionQuadHolder(final Collection<Triple> triples);  CollectionQuadHolder(final Iterator<Triple> triples); @Override ExtendedIterator<Quad> getQuads(); @Override QuadHolder setValues(final Map<Var, Node> values);  }
@Test public void namedGraphTest_List() { Node g = NodeFactory.createURI( "g" ); List<Triple> tLst = new ArrayList<Triple>(); Node s = NodeFactory.createURI( "s" ); Node p = NodeFactory.createURI( "p" ); Node o = NodeFactory.createURI( "o" ); tLst.add( new Triple( s, p, o ) ); Node s2 = NodeFactory.createURI( "s2" ); Node p2 = NodeFactory.createURI( "p2" ); Node o2 = NodeFactory.createURI( "o2" ); tLst.add( new Triple( s2, p2, o2 ) ); holder = new CollectionQuadHolder( g, tLst ); List<Quad> lst = holder.getQuads().toList(); assertEquals( 2, lst.size() ); assertEquals( new Quad( g, tLst.get(0)), lst.get(0)); assertEquals( new Quad( g, tLst.get(1)), lst.get(1)); }
@Test public void namedGraphTest_Iterator() { Node g = NodeFactory.createURI( "g" ); List<Triple> tLst = new ArrayList<Triple>(); Node s = NodeFactory.createURI( "s" ); Node p = NodeFactory.createURI( "p" ); Node o = NodeFactory.createURI( "o" ); tLst.add( new Triple( s, p, o ) ); Node s2 = NodeFactory.createURI( "s2" ); Node p2 = NodeFactory.createURI( "p2" ); Node o2 = NodeFactory.createURI( "o2" ); tLst.add( new Triple( s2, p2, o2 ) ); holder = new CollectionQuadHolder( g, tLst.iterator() ); List<Quad> lst = holder.getQuads().toList(); assertEquals( 2, lst.size() ); assertEquals( new Quad( g, tLst.get(0)), lst.get(0)); assertEquals( new Quad( g, tLst.get(1)), lst.get(1)); }
@Test public void anonymousGraphTest_List() { List<Triple> tLst = new ArrayList<Triple>(); Node s = NodeFactory.createURI( "s" ); Node p = NodeFactory.createURI( "p" ); Node o = NodeFactory.createURI( "o" ); tLst.add( new Triple( s, p, o ) ); Node s2 = NodeFactory.createURI( "s2" ); Node p2 = NodeFactory.createURI( "p2" ); Node o2 = NodeFactory.createURI( "o2" ); tLst.add( new Triple( s2, p2, o2 ) ); holder = new CollectionQuadHolder( tLst ); List<Quad> lst = holder.getQuads().toList(); assertEquals( 2, lst.size() ); assertEquals( new Quad( Quad.defaultGraphNodeGenerated, tLst.get(0)), lst.get(0)); assertEquals( new Quad( Quad.defaultGraphNodeGenerated, tLst.get(1)), lst.get(1)); }
@Test public void anonymousGraphTest_Iterator() { List<Triple> tLst = new ArrayList<Triple>(); Node s = NodeFactory.createURI( "s" ); Node p = NodeFactory.createURI( "p" ); Node o = NodeFactory.createURI( "o" ); tLst.add( new Triple( s, p, o ) ); Node s2 = NodeFactory.createURI( "s2" ); Node p2 = NodeFactory.createURI( "p2" ); Node o2 = NodeFactory.createURI( "o2" ); tLst.add( new Triple( s2, p2, o2 ) ); holder = new CollectionQuadHolder( tLst.iterator() ); List<Quad> lst = holder.getQuads().toList(); assertEquals( 2, lst.size() ); assertEquals( new Quad( Quad.defaultGraphNodeGenerated, tLst.get(0)), lst.get(0)); assertEquals( new Quad( Quad.defaultGraphNodeGenerated, tLst.get(1)), lst.get(1)); }