Interface NamedNode

All Superinterfaces:
Comparable<NamedNode>
All Known Subinterfaces:
FolderNode, LeafNode
All Known Implementing Classes:
Hierarchy.Folder, Hierarchy.Leaf, Hierarchy.Node, Hierarchy.OrphanNode, Hierarchy.RootNode

public interface NamedNode extends Comparable<NamedNode>
A named node in a hierarchy. Paths in the hierarchy are using the '/' as separator. A hierarchy consists of Folder and Leafs. It is rooted in a root FolderNode that is the only node without a parent. The root has an empty name. I.e. not '/'

A NamedNode hashCode & equals are based on identity. They are, however, Comparable

A Named Node is either a Folder or a Leaf, there are no other types.

  • Method Details

    • name

      String name()
      The name of this node. This name is always without a '/'.
      Returns:
      the name
    • path

      String path()
      The path of this node in the hierarchy. This path never starts with a '/'. If it is a folder, the path must end with a '/'.

      This path, when used with Hierarchy.find(String) must return the this node.

      Returns:
      the name
    • parent

      Optional<? extends FolderNode> parent()
      Return the parent of this node. Only the root will return an empty Optional. Each hierarchy has a single root.
      Returns:
      the parent or an empty Optional in the case of the root node.
    • find

      Optional<NamedNode> find(String path)
      Find a path from this node down. The `..` and '.' are supported, meaning parent and this.
      Parameters:
      path - the path
      Returns:
      an optional node if found
    • isFolder

      default boolean isFolder()
      Returns:
      true if this is a FolderNode
    • isLeaf

      default boolean isLeaf()
      Returns:
      true if this is not a FolderNode
    • isRoot

      default boolean isRoot()
      Returns:
      true if this is the root node.
    • siblings

      default Optional<NamedNode[]> siblings()
      Return the siblings of this node.
      Returns:
      the siblings or empty if the root node
    • root

      FolderNode root()
      Answer the root node