Skip to content

Commit a69244e

Browse files
committed
Return empty fragment if the entities are not found.
1 parent 21565b0 commit a69244e

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/org/linkeddatafragments/datasource/BasicLinkedDataFragmentImpl.java renamed to src/org/linkeddatafragments/datasource/BasicLinkedDataFragmentBase.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,31 @@
11
package org.linkeddatafragments.datasource;
22

33
import com.hp.hpl.jena.rdf.model.Model;
4+
import com.hp.hpl.jena.rdf.model.ModelFactory;
45

56
/**
67
* Base implementation of a Basic Linked Data Fragment.
78
* @author Ruben Verborgh
89
*/
9-
public class BasicLinkedDataFragmentImpl implements BasicLinkedDataFragment {
10+
public class BasicLinkedDataFragmentBase implements BasicLinkedDataFragment {
1011
private final Model triples;
1112
private final long totalSize;
1213

1314
/**
14-
* Create a new Basic Linked Data Fragment.
15+
* Creates an empty Basic Linked Data Fragment.
16+
*/
17+
public BasicLinkedDataFragmentBase() {
18+
this(null, 0);
19+
}
20+
21+
/**
22+
* Creates a new Basic Linked Data Fragment.
1523
* @param triples the triples (possibly partial)
1624
* @param totalSize the total size
1725
*/
18-
public BasicLinkedDataFragmentImpl(Model triples, long totalSize) {
19-
this.triples = triples;
20-
this.totalSize = totalSize;
26+
public BasicLinkedDataFragmentBase(Model triples, long totalSize) {
27+
this.triples = triples == null ? ModelFactory.createDefaultModel() : triples;
28+
this.totalSize = totalSize < 0 ? 0 : totalSize;
2129
}
2230

2331
@Override

src/org/linkeddatafragments/datasource/HdtDataSource.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ public BasicLinkedDataFragment getFragment(Resource subject, Property predicate,
4141
final int subjectId = subject == null ? 0 : dictionary.getIntID(subject.asNode(), TripleComponentRole.SUBJECT);
4242
final int predicateId = predicate == null ? 0 : dictionary.getIntID(predicate.asNode(), TripleComponentRole.PREDICATE);
4343
final int objectId = object == null ? 0 : dictionary.getIntID(object.asNode(), TripleComponentRole.OBJECT);
44+
if (subjectId < 0 || predicateId < 0 || objectId < 0)
45+
return new BasicLinkedDataFragmentBase();
4446
final IteratorTripleID result = datasource.getTriples().search(new TripleID(subjectId, predicateId, objectId));
4547

4648
// create the fragment

0 commit comments

Comments
 (0)