示例#1
0
 /**
  * Get all of the paths through which the specified node is accessible, including all paths based
  * upon the node's {@link CachedNode#getParentKey(NodeCache) parent} (which can potentially have
  * multiple paths) and upon the node's {@link CachedNode#getAdditionalParentKeys(NodeCache)
  * additional parents} (which each can potentially have multiple paths).
  *
  * @param node the node for which the paths are to be returned; may not be null
  * @return the paths for the node; never null but possibly empty
  */
 public Iterable<Path> getPaths(CachedNode node) {
   NodeKey key = node.getKey();
   List<Path> pathList = paths.get(key);
   if (pathList == null) {
     // Compute the node's path ...
     Segment nodeSegment = node.getSegment(cache);
     NodeKey parentKey = node.getParentKey(cache);
     if (parentKey == null) {
       // This is the root node ...
       pathList = Collections.singletonList(node.getPath(cache));
     } else {
       // This is not the root node, so add a path for each of the parent's valid paths ...
       CachedNode parent = cache.getNode(parentKey);
       if (parent == null && removedCache != null) {
         // This is a removed node, so check the removed cache ...
         parent = removedCache.getNode(parentKey);
       }
       pathList = new LinkedList<Path>();
       for (Path parentPath : getPaths(parent)) {
         Path path = pathFactory.create(parentPath, nodeSegment);
         pathList.add(path);
       }
       // Get the additional parents ...
       Set<NodeKey> additionalParentKeys = getAdditionalParentKeys(node, cache);
       // There is at least one additional parent ...
       for (NodeKey additionalParentKey : additionalParentKeys) {
         parent = cache.getNode(additionalParentKey);
         for (Path parentPath : getPaths(parent)) {
           Path path = pathFactory.create(parentPath, nodeSegment);
           pathList.add(path);
         }
       }
     }
     assert pathList != null;
     pathList = Collections.unmodifiableList(pathList);
     paths.put(key, pathList);
   }
   return pathList;
 }
示例#2
0
 protected Set<NodeKey> getAdditionalParentKeys(CachedNode node, NodeCache cache) {
   return node.getAdditionalParentKeys(cache);
 }