/** * 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(); } } }