private static ImmutableList<Atom> planFromTraversal(List<Atom> atoms, Conjunction<?> queryPattern, TransactionOLTP tx){
        Multimap<VarProperty, Atom> propertyMap = HashMultimap.create();
        atoms.stream()
                .filter(atom -> !(atom instanceof OntologicalAtom))
                .forEach(atom -> atom.getVarProperties().forEach(property -> propertyMap.put(property, atom)));
        Set<VarProperty> properties = propertyMap.keySet();

        GraqlTraversal graqlTraversal = TraversalPlanner.createTraversal(queryPattern, tx);
        ImmutableList<Fragment> fragments = Iterables.getOnlyElement(graqlTraversal.fragments());

        List<Atom> atomList = new ArrayList<>();

        atoms.stream()
                .filter(atom -> atom instanceof OntologicalAtom)
                .forEach(atomList::add);

        fragments.stream()
                .map(Fragment::varProperty)
                .filter(Objects::nonNull)
                .filter(properties::contains)
                .distinct()
                .flatMap(property -> propertyMap.get(property).stream())
                .distinct()
                .forEach(atomList::add);

        //add any unlinked items (disconnected and indexed for instance)
        propertyMap.values().stream()
                .filter(at -> !atomList.contains(at))
                .forEach(atomList::add);
        return ImmutableList.copyOf(atomList);
    }
private static ImmutableList < Atom > planFromTraversal ( List < Atom > atoms , Conjunction < ? > queryPattern , TransactionOLTP tx ) { Multimap < VarProperty , Atom > propertyMap = HashMultimap . create ( ) ; atoms . stream ( ) . filter ( atom -> ! ( atom instanceof OntologicalAtom ) ) . forEach ( atom -> atom . getVarProperties ( ) . forEach ( property -> propertyMap . put ( property , atom ) ) ) ; Set < VarProperty > properties = propertyMap . keySet ( ) ; GraqlTraversal graqlTraversal = TraversalPlanner . createTraversal ( queryPattern , tx ) ; ImmutableList < Fragment > fragments = Iterables . getOnlyElement ( graqlTraversal . fragments ( ) ) ; List < Atom > atomList = new ArrayList < > ( ) ; atoms . stream ( ) . filter ( atom -> atom instanceof OntologicalAtom ) . forEach ( atomList :: add ) ; fragments . stream ( ) . map ( Fragment :: varProperty ) . filter ( Objects :: nonNull ) . filter ( properties :: contains ) . distinct ( ) . flatMap ( property -> propertyMap . get ( property ) . stream ( ) ) . distinct ( ) . forEach ( atomList :: add ) ; propertyMap . values ( ) . stream ( ) . filter ( at -> ! atomList . contains ( at ) ) . forEach ( atomList :: add ) ; return ImmutableList . copyOf ( atomList ) ; }
@param atoms list of current atoms of interest
@param queryPattern corresponding pattern
@return an optimally ordered list of provided atoms