All Downloads are FREE. Search and download functionalities are using the official Maven repository.

brooklyn.entity.rebind.TreeUtils Maven / Gradle / Ivy

There is a newer version: 0.7.0-M1
Show newest version
package brooklyn.entity.rebind;

import java.util.ArrayDeque;
import java.util.Collection;
import java.util.Deque;
import java.util.Set;

import brooklyn.location.Location;

import com.google.common.collect.Sets;

public class TreeUtils {

    public static Collection findLocationsInHierarchy(Location root) {
        Set result = Sets.newLinkedHashSet();
        
        Deque tovisit = new ArrayDeque();
        tovisit.addFirst(root);
        
        while (tovisit.size() > 0) {
            Location current = tovisit.pop();
            result.add(current);
            for (Location child : current.getChildren()) {
                if (child != null) {
                    tovisit.push(child);
                }
            }
        }

        Location parentLocation = root.getParent();
        while (parentLocation != null) {
            result.add(parentLocation);
            parentLocation = parentLocation.getParent();
        }

        return result;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy