Unable to perform tree traversal

Hi,
I’ve tried various various data structure algorithm to perform tree traversal using hierarchical data source… But i’m unable to perform the recursive tree traversal… Even though having the getParent(), hasChildren() and getChildren(). I need the getNextSibling() to perform the complete tree traversal, but it is not available in Hierarchical Datasource…

Please help me regarding this… Is there any possibility to perform the complete tree traversal without the help of getNextSibling() ?

Please help me regarding this…

Hi,

It should be simple:

public class OrgUnitBrowse extends AbstractLookup {

    private static final Logger log = LoggerFactory.getLogger(OrgUnitBrowse.class);

    @Inject
    private HierarchicalDatasource<OrgUnit, UUID> orgUnitsDs;

    public void traverse() {
        for (UUID rootId : orgUnitsDs.getRootItemIds()) {
            traverse(rootId);
        }
    }

    private void traverse(UUID itemId) {
        log.info("found: " + orgUnitsDs.getItem(itemId).getName());
        for (UUID childId : orgUnitsDs.getChildren(itemId)) {
            traverse(childId);
        }
    }
}