// removing all the links we found this time around from the set of
// old links. any links remaining after this will be stale, and need
// to be retracted
for (Link newl : new ArrayList<Link>(curlinks)) {
String key = makeKey(newl);
Link oldl = oldmap.get(key);
if (oldl == null)
continue;
if (oldl.overrides(newl))
// previous information overrides this link, so ignore
curlinks.remove(newl);
else if (sameAs(oldl, newl)) {
// there's no new information here, so just ignore this
curlinks.remove(newl);
oldmap.remove(key); // we don't want to retract the old one
} else
// the link is out of date, but will be overwritten, so remove
oldmap.remove(key);
}
// all the inferred links left in oldmap are now old links we
// didn't find on this pass. there is no longer any evidence
// supporting them, and so we can retract them.
for (Link oldl : oldmap.values())
if (oldl.getStatus() == LinkStatus.INFERRED) {
oldl.retract(); // changes to retracted, updates timestamp
curlinks.add(oldl);
}
}
// okay, now we write it all to the database