// We split the plan at star-shaped joins!
final HashMap<Item, LinkedList<LeafNodePlan>> starJoins = new HashMap<Item, LinkedList<LeafNodePlan>>();
final HashMap<Item, LinkedList<LeafNodePlan>> helperStarJoins = new HashMap<Item, LinkedList<LeafNodePlan>>();
for (final LeafNodePlan lnp : initialPlans) {
TriplePattern tp = lnp.getTriplePatterns().iterator().next();
final Item subject = tp.getPos(0);
LinkedList<LeafNodePlan> list = starJoins.get(subject);
if (list == null){
list = new LinkedList<LeafNodePlan>();
}
list.add(lnp);
starJoins.put(subject, list);
final Item predicate = tp.getPos(1);
if (predicate instanceof Variable) {
list = helperStarJoins.get(predicate);
if (list == null)
list = new LinkedList<LeafNodePlan>();
list.add(lnp);
helperStarJoins.put(predicate, list);
}
final Item object = tp.getPos(2);
if (object instanceof Variable) {
list = helperStarJoins.get(object);
if (list == null)
list = new LinkedList<LeafNodePlan>();
list.add(lnp);