Refine search
/** * Find the next result triple and bind the result vars appropriately. * @param interpreter the calling interpreter whose trail should be used * @return false if there are no more matches in the iterator. */ public boolean nextMatch(LPInterpreter interpreter) { if (matchIterator.hasNext()) { lastMatch = matchIterator.next(); return true; } else { return false; } }
/** * <p>Answer the property that is the inverse of this property. If no such property is defined, * return null. If more than one inverse is defined, return an arbitrary selection.</p> * @return The property that is the inverse of this property, or null. */ @Override public OntProperty getInverse() { ExtendedIterator<OntProperty> i = listInverse(); OntProperty p = i.hasNext() ? i.next() : null; i.close(); return p; }
public void testRemove( String findRemove, String findCheck ) { Graph g = getGraphWith( "S P O" ); ExtendedIterator<Triple> it = g.find( NodeCreateUtils.createTriple( findRemove ) ); try { it.next(); it.remove(); it.close(); assertEquals( "remove with " + findRemove + ":", 0, g.size() ); assertFalse( g.contains( NodeCreateUtils.createTriple( findCheck ) ) ); } catch (UnsupportedOperationException e) { // No iterator remove. it.close(); } }
/** * Find the next result triple and bind the result vars appropriately. * @param interpreter the calling interpreter whose trail should be used * @return false if there are no more matches in the iterator. */ public boolean nextMatch(LPInterpreter interpreter) { if (matchIterator.hasNext()) { lastMatch = matchIterator.next(); return true; } else { return false; } }
public void testRemove( String findRemove, String findCheck ) { Graph g = getGraphWith( "S P O" ); ExtendedIterator<Triple> it = g.find( NodeCreateUtils.createTriple( findRemove ) ); try { it.next(); it.remove(); it.close(); assertEquals( "remove with " + findRemove + ":", 0, g.size() ); assertFalse( g.contains( NodeCreateUtils.createTriple( findCheck ) ) ); } catch (UnsupportedOperationException e) { // No iterator remove. it.close(); } }
/** * <p>Answer the property that is the inverse of this property. If no such property is defined, * return null. If more than one inverse is defined, return an arbitrary selection.</p> * @return The property that is the inverse of this property, or null. */ @Override public OntProperty getInverse() { ExtendedIterator<OntProperty> i = listInverse(); OntProperty p = i.hasNext() ? i.next() : null; i.close(); return p; }
public void testClosingConcatenationClosesRemainingIterators() { LoggingClosableIterator<String> L = new LoggingClosableIterator<>( iteratorOfStrings( "only" ) ); LoggingClosableIterator<String> M = new LoggingClosableIterator<>( iteratorOfStrings( "single" ) ); LoggingClosableIterator<String> R = new LoggingClosableIterator<>( iteratorOfStrings( "it" ) ); ExtendedIterator<String> cat = L.andThen( M ).andThen( R ); cat.next(); cat.close(); assertTrue( "middle iterator should have been closed", M.isClosed() ); assertTrue( "final iterator should have been closed", R.isClosed() ); }
/** Get exactly one triple or null for none or more than one. */ public static Triple triple1(Graph graph, Node s, Node p, Node o) { ExtendedIterator<Triple> iter = graph.find(s, p, o); try { if ( !iter.hasNext() ) return null; Triple t = iter.next(); if ( iter.hasNext() ) return null; return t; } finally { iter.close(); } }
public void testClosingConcatenationClosesRemainingIterators() { LoggingClosableIterator<String> L = new LoggingClosableIterator<>( iteratorOfStrings( "only" ) ); LoggingClosableIterator<String> M = new LoggingClosableIterator<>( iteratorOfStrings( "single" ) ); LoggingClosableIterator<String> R = new LoggingClosableIterator<>( iteratorOfStrings( "it" ) ); ExtendedIterator<String> cat = L.andThen( M ).andThen( R ); cat.next(); cat.close(); assertTrue( "middle iterator should have been closed", M.isClosed() ); assertTrue( "final iterator should have been closed", R.isClosed() ); }
private RDFNode getOrCompute(RDFNode key, Map<RDFNode,RDFNode> values, NodeExpressionContext context) { return values.computeIfAbsent(key, k -> { ExtendedIterator<RDFNode> it = comparator.eval(key, context); if(it.hasNext()) { RDFNode result = it.next(); it.close(); return result; } else { return null; } }); }
@Override public boolean contains(final RDFNode value) throws ReadDeniedException, AuthenticationRequiredException { // iterator() checks Read final ExtendedIterator<RDFNode> iter = iterator(); try { while (iter.hasNext()) { if (value.equals(iter.next())) { return true; } } return false; } finally { iter.close(); } }
/** Answer the number of triples in this graph. Default implementation counts its way through the results of a findAll. Subclasses must override if they want size() to be efficient. */ protected int graphBaseSize() { ExtendedIterator<Triple> it = GraphUtil.findAll( this ); try { int tripleCount = 0; while (it.hasNext()) { it.next(); tripleCount += 1; } return tripleCount; } finally { it.close(); } }
public static void writeReifiedGraph(Model model, Graph graph, Function<Triple, Node> tripleToSubject) { ExtendedIterator<Triple> it = graph.find(Node.ANY, Node.ANY, Node.ANY); try { while(it.hasNext()) { Triple triple = it.next(); Node s = tripleToSubject.apply(triple); writeReifiedTriple(model, s, triple); } } finally { it.close(); } }