Class AbstractNode

java.lang.Object
introspector.model.AbstractNode
All Implemented Interfaces:
Node, Serializable
Direct Known Subclasses:
ArrayNode, BuiltinTypeNode, CollectionNode, EnumNode, MapNode, ObjectNode

public abstract class AbstractNode extends Object implements Node
The abstract Node provides the default implementation of the Node interface. The node interface represents the nodes in the tree that models the structure of the program at runtime. See the derived classes to find the appropriate one to instantiate.
See Also:
  • Field Details

    • value

      private final Object value
      The object that is wrapped by the node
    • name

      private final String name
      The name of the node
    • type

      private final Class<?> type
      The type of the node
  • Constructor Details

    • AbstractNode

      protected AbstractNode(String name, Object value)
      Creates a Node that wraps a Java Object
      Parameters:
      name - The name to display the node
      value - The object that will be represented as a node
    • AbstractNode

      protected AbstractNode(String name, Object value, Class<?> type)
      Creates a Node that wraps a Java Object
      Parameters:
      name - The name to display the node
      value - The object that will be represented as a node
      type - The type of the object
  • Method Details

    • getName

      public String getName()
      Description copied from interface: Node
      Returns the name of the node
      Specified by:
      getName in interface Node
      Returns:
      The name used to display the object represented as a node
    • getType

      public Class<?> getType()
      Description copied from interface: Node
      Returns the type of the object represented as a node
      Specified by:
      getType in interface Node
      Returns:
      The type of the object represented as a node
    • getValue

      public Object getValue()
      Description copied from interface: Node
      Returns the object represented as a node
      Specified by:
      getValue in interface Node
      Returns:
      The object represented as a node
    • getChildren

      protected abstract List<Node> getChildren()
      Returns the child node of the current node. Template method to implement Node.getChild(int), Node.getChildrenCount() and Node.getIndexOfChild(Object)
      Returns:
      The children of this node (null if there are no children)
    • getChild

      public Node getChild(int index)
      Description copied from interface: Node
      Gets the index-th child of the current node.
      Specified by:
      getChild in interface Node
      Parameters:
      index - The index of the child to be found.
      Returns:
      The index-th child; null if the index is out of bounds.
      See Also:
    • getChildrenCount

      public int getChildrenCount()
      Description copied from interface: Node
      Returns the number of children of the current node.
      Specified by:
      getChildrenCount in interface Node
      Returns:
      The number of children of the current node.
      See Also:
    • getIndexOfChild

      public int getIndexOfChild(Object child)
      Description copied from interface: Node
      Searches for a child and returns its index. The child node is searched by comparing their names.
      Specified by:
      getIndexOfChild in interface Node
      Parameters:
      child - The object to be found (compared by structure with equals)
      Returns:
      The index of the child found; -1 if it no child is found.
      See Also:
    • toString

      public String toString()
      A node is represented as "name (type)".
      Overrides:
      toString in class Object
      Returns:
      The node representation as string.
    • equals

      public boolean equals(Object obj)
      Two nodes are equal when they wrap the same exact object (identity comparison)
      Overrides:
      equals in class Object
      Parameters:
      obj - To object to be compared with
      Returns:
      Whether the two objects are equal
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
      Returns:
      The hash code of the name
    • getNodeDescription

      public String getNodeDescription()
      Description copied from interface: Node
      A textual description of the node. toString must be defined for the wrapped objects.
      Specified by:
      getNodeDescription in interface Node
      Returns:
      The string representation of the node.
      See Also:
    • getClassName

      public String getClassName()
      Description copied from interface: Node
      Returns the short name of the type whose object is wrapped by the node.
      Specified by:
      getClassName in interface Node
      Returns:
      A short name of the type of the object wrapped by the node.
      See Also:
    • compareTrees

      public Set<Node> compareTrees(Node node2, boolean equalName, Set<Node> modifiedNodes, Set<SymmetricPair<Node,Node>> alreadyTraversed)
      Description copied from interface: Node
      Compare two trees and return the list of modified nodes.
      Specified by:
      compareTrees in interface Node
      Parameters:
      node2 - The node to compare with the other tree
      equalName - Whether the node names must be the same or not (important for root nodes)
      modifiedNodes - The list of modified nodes
      alreadyTraversed - The list of nodes that have been visited in this traversal
      Returns:
      The list of modified nodes
      See Also: