// TODO: handle list containment cycles (e.g. list containing a list containing the original list) as well.
// These are actually more likely than circular lists.
Set<RDFValue> alreadyInterned = new HashSet<RDFValue>();
RippleList cur = list;
RDFValue id = cur.toRDF(this);
while (!cur.isNil()) {
if (alreadyInterned.contains(id)) {
break;
} else {
alreadyInterned.add(id);
}
RDFValue firstRdf = cur.getFirst().toRDF(this);
if (null == firstRdf) {
System.err.println("list item has no RDF identity: " + cur.getFirst());
return false;
}
if (cur.getFirst() instanceof RippleList) {
internalize((RippleList) cur.getFirst());
}
RippleList rest = cur.getRest();
RDFValue restRdf = rest.toRDF(this);
buffer.put(
valueFactory.createStatement((Resource) id.sesameValue(), RDF.TYPE, RDF.LIST));
buffer.put(
valueFactory.createStatement((Resource) id.sesameValue(), RDF.FIRST, firstRdf.sesameValue()));
buffer.put(
valueFactory.createStatement((Resource) id.sesameValue(), RDF.REST, restRdf.sesameValue()));
cur = rest;
id = restRdf;
}