svoid ai_parseTree_makeTotalWeights(PTElement e, double weight) { e.totalWeight = weight*e.weight; for (PTElement child : unnull(e.children)) ai_parseTree_makeTotalWeights(child, e.totalWeight); // prefer composites if weight is the same // so we get the least casting on top sortInPlaceByCalculatedFieldDesc(e.children, ai_parseTree_sortingFunction()); }