Skip to content
Permalink
Browse files
Use isEmpty().
  • Loading branch information
garydgregory committed Jan 17, 2021
1 parent c482839 commit 6af4086914e2961df2658e4be3104c621c7c6a79
Showing 5 changed files with 31 additions and 11 deletions.
@@ -167,6 +167,15 @@ default void close() throws Exception {
*/
Stream<BlankNodeOrIRI> getGraphNames();

/**
* Tests if this is empty.
*
* @return true if this is empty.
*/
default boolean isEmpty() {
return size() == 0;
}

/**
* Remove a concrete quad from the dataset.
*
@@ -351,4 +360,5 @@ default Iterable<Quad> iterate(final Optional<BlankNodeOrIRI> graphName, final B
final RDFTerm object) throws ConcurrentModificationException, IllegalStateException {
return ((Stream<Quad>) stream(graphName, subject, predicate, object))::iterator;
}

}
@@ -204,6 +204,15 @@ default Stream<? extends Triple> getTriples(final BlankNodeOrIRI subject, final
return stream(subject, predicate, object);
}

/**
* Tests if this is empty.
*
* @return true if this is empty.
*/
default boolean isEmpty() {
return size() == 0;
}

/**
* Gets an Iterable for iterating over all triples in the graph.
* <p>
@@ -295,4 +304,5 @@ default Iterable<Triple> iterate(final BlankNodeOrIRI subject, final IRI predica
throws ConcurrentModificationException, IllegalStateException {
return ((Stream<Triple>) stream(subject, predicate, object))::iterator;
}

}
@@ -129,7 +129,7 @@ public void size() throws Exception {

@Test
public void iterate() throws Exception {
Assume.assumeTrue(dataset.size() > 0);
Assume.assumeFalse(dataset.isEmpty());
final List<Quad> quads = new ArrayList<>();
for (final Quad t : dataset.iterate()) {
quads.add(t);
@@ -135,7 +135,7 @@ public void createGraphAndAdd() {

@Test
public void size() throws Exception {
assertTrue(graph.size() > 0);
assertFalse(graph.isEmpty());
Assume.assumeNotNull(bnode1, bnode2, aliceName, bobName, secretClubName, companyName, bobNameTriple);
// Can only reliably predict size if we could create all triples
assertEquals(8, graph.size());
@@ -144,7 +144,7 @@ public void size() throws Exception {
@Test
public void iterate() throws Exception {

Assume.assumeTrue(graph.size() > 0);
Assume.assumeFalse(graph.isEmpty());

final List<Triple> triples = new ArrayList<>();
for (final Triple t : graph.iterate()) {
@@ -89,12 +89,12 @@ public void guessRDFSyntax() throws Exception {
assertFalse(AbstractRDFParser.guessRDFSyntax(testXml).isPresent());
}

private void checkGraph(final Graph g) throws Exception {
assertTrue(g.size() > 0);
private void checkGraph(final Graph graph) throws Exception {
assertFalse(graph.isEmpty());
final IRI greeting = factory.createIRI("http://example.com/greeting");
// Should only have parsed once!
assertEquals(1, g.stream(null, greeting, null).count());
final Triple triple = g.stream(null, greeting, null).findAny().get();
assertEquals(1, graph.stream(null, greeting, null).count());
final Triple triple = graph.stream(null, greeting, null).findAny().get();
assertTrue(triple.getSubject() instanceof IRI);
final IRI parsing = (IRI) triple.getSubject();
assertTrue(parsing.getIRIString().startsWith("urn:uuid:"));
@@ -108,12 +108,12 @@ private void checkGraph(final Graph g) throws Exception {
assertEquals(Types.XSD_STRING, literal.getDatatype());

// Check uniqueness of properties that are always present
assertEquals(1, g.stream(null, factory.createIRI("http://example.com/source"), null).count());
assertEquals(1, graph.stream(null, factory.createIRI("http://example.com/source"), null).count());

// Check optional properties that are unique
assertTrue(2 > g.stream(null, factory.createIRI("http://example.com/base"), null).count());
assertTrue(2 > g.stream(null, factory.createIRI("http://example.com/contentType"), null).count());
assertTrue(2 > g.stream(null, factory.createIRI("http://example.com/contentTypeSyntax"), null).count());
assertTrue(2 > graph.stream(null, factory.createIRI("http://example.com/base"), null).count());
assertTrue(2 > graph.stream(null, factory.createIRI("http://example.com/contentType"), null).count());
assertTrue(2 > graph.stream(null, factory.createIRI("http://example.com/contentTypeSyntax"), null).count());
}

@Test

0 comments on commit 6af4086

Please sign in to comment.