Class NodeBase

    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected int level  
      protected java.lang.String location  
      protected java.lang.String name  
      protected Node parent  
      static char PATH_SEPARATOR
      Path separator 47.
      static java.lang.String PATH_SEPARATOR_STR
      Path separator as a string "/".
      static java.lang.String ROOT
      String representation of root "".
    • Constructor Summary

      Constructors 
      Constructor Description
      NodeBase()
      Default constructor.
      NodeBase​(java.lang.String path)
      Construct a node from its path.
      NodeBase​(java.lang.String name, java.lang.String location)
      Construct a node from its name and its location.
      NodeBase​(java.lang.String name, java.lang.String location, Node parent, int level)
      Construct a node from its name and its location.
    • Field Detail

      • PATH_SEPARATOR

        public static final char PATH_SEPARATOR
        Path separator 47.
        See Also:
        Constant Field Values
      • PATH_SEPARATOR_STR

        public static final java.lang.String PATH_SEPARATOR_STR
        Path separator as a string "/".
        See Also:
        Constant Field Values
      • ROOT

        public static final java.lang.String ROOT
        String representation of root "".
        See Also:
        Constant Field Values
      • name

        protected java.lang.String name
      • location

        protected java.lang.String location
      • level

        protected int level
      • parent

        protected Node parent
    • Constructor Detail

      • NodeBase

        public NodeBase()
        Default constructor.
      • NodeBase

        public NodeBase​(java.lang.String path)
        Construct a node from its path.
        Parameters:
        path - a concatenation of this node's location, the path seperator, and its name
      • NodeBase

        public NodeBase​(java.lang.String name,
                        java.lang.String location)
        Construct a node from its name and its location.
        Parameters:
        name - this node's name (can be null, must not contain PATH_SEPARATOR)
        location - this node's location
      • NodeBase

        public NodeBase​(java.lang.String name,
                        java.lang.String location,
                        Node parent,
                        int level)
        Construct a node from its name and its location.
        Parameters:
        name - this node's name (can be null, must not contain PATH_SEPARATOR)
        location - this node's location
        parent - this node's parent node
        level - this node's level in the tree
    • Method Detail

      • getName

        public java.lang.String getName()
        Specified by:
        getName in interface Node
        Returns:
        this node's name
      • getNetworkLocation

        public java.lang.String getNetworkLocation()
        Specified by:
        getNetworkLocation in interface Node
        Returns:
        this node's network location
      • setNetworkLocation

        public void setNetworkLocation​(java.lang.String location)
        Set this node's network location.
        Specified by:
        setNetworkLocation in interface Node
        Parameters:
        location - the location
      • getPath

        public static java.lang.String getPath​(Node node)
        Get the path of a node.
        Parameters:
        node - a non-null node
        Returns:
        the path of a node
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
        Returns:
        this node's path as its string representation
      • normalize

        public static java.lang.String normalize​(java.lang.String path)
        Normalize a path by stripping off any trailing PATH_SEPARATOR.
        Parameters:
        path - path to normalize.
        Returns:
        the normalised path If pathis null or empty ROOT is returned
        Throws:
        java.lang.IllegalArgumentException - if the first character of a non empty path is not PATH_SEPARATOR
      • getParent

        public Node getParent()
        Specified by:
        getParent in interface Node
        Returns:
        this node's parent
      • setParent

        public void setParent​(Node parent)
        Set this node's parent.
        Specified by:
        setParent in interface Node
        Parameters:
        parent - the parent
      • getLevel

        public int getLevel()
        Specified by:
        getLevel in interface Node
        Returns:
        this node's level in the tree. E.g. the root of a tree returns 0 and its children return 1
      • setLevel

        public void setLevel​(int level)
        Set this node's level in the tree.
        Specified by:
        setLevel in interface Node
        Parameters:
        level - the level
      • locationToDepth

        public static int locationToDepth​(java.lang.String location)
      • getNetworkLocation

        public java.lang.String getNetworkLocation​(int distanceFromLeaves)
        Specified by:
        getNetworkLocation in interface Node
        Returns:
        the string representation of this node's network location at the specified level in the hierarchy