示例#1
0
文件: Index.java 项目: rkfg/Hive2Hive
  /**
   * Return sif the node is shared or has any children that are shared.
   *
   * @return if the node is shared or has a shared sub-section
   */
  public boolean isSharedOrHasSharedChildren() {
    if (isShared()) {
      // this is a shared file or a shared (sub) folder
      return true;
    }

    if (this instanceof FileIndex) {
      // is not shared and is of type 'file'
      return false;
    } else {
      // is of type 'folder', check all subfolders
      List<Index> children = getIndexList(this);
      for (Index child : children) {
        if (child.isFolder()) {
          FolderIndex subfolder = (FolderIndex) child;
          if (subfolder.getSharedFlag()) {
            return true;
          }
        }
      }
    }

    // no case above matches
    return false;
  }
示例#2
0
文件: Index.java 项目: rkfg/Hive2Hive
  /**
   * Walks recursively through the file tree and returns a preorder list
   *
   * @param node The root node from which the digest is started.
   * @return The digest in preorder
   */
  public static List<Index> getIndexList(Index node) {
    List<Index> digest = new ArrayList<Index>();

    // add self
    digest.add(node);

    // add children
    if (node.isFolder()) {
      FolderIndex folder = (FolderIndex) node;
      for (Index child : folder.getChildren()) {
        digest.addAll(getIndexList(child));
      }
    }

    return digest;
  }
示例#3
0
文件: Index.java 项目: rkfg/Hive2Hive
 /**
  * Returns the full path (starting at the root) of this node
  *
  * @return
  */
 public Path getFullPath() {
   if (parent == null) {
     return Paths.get("");
   } else {
     return Paths.get(parent.getFullPath().toString(), getName());
   }
 }
示例#4
0
文件: Index.java 项目: rkfg/Hive2Hive
 /**
  * Returns the folder that is shared (can be this node or a parent / grand-parent / ... of this
  * node
  *
  * @return
  */
 public FolderIndex getSharedTopFolder() {
   if (this instanceof FileIndex) {
     // is not shared and is of type files (this has no children)
     return parent.getSharedTopFolder();
   } else {
     // is of type folder
     FolderIndex folder = (FolderIndex) this;
     if (folder.getSharedFlag()) {
       // this is the top-most shared folder because the shared flag is activated
       return folder;
     } else if (folder.isRoot()) {
       // the root folder is never shared
       return null;
     } else {
       // move one level up (recursion)
       return parent.getSharedTopFolder();
     }
   }
 }
示例#5
0
文件: Index.java 项目: rkfg/Hive2Hive
 public Index(KeyPair fileKeys, String name, FolderIndex parent) {
   this.fileKeys = fileKeys;
   this.name = name;
   this.parent = parent;
   if (parent != null) parent.addChild(this);
 }