Interface Sexpr<T extends Sexpr<T>>

Type Parameters:
T - is the type of the implementing class.
All Superinterfaces:
Comparable<Sexpr<?>>
All Known Implementing Classes:
SAtom, SList

public interface Sexpr<T extends Sexpr<T>> extends Comparable<Sexpr<?>>
Symbolic Expression.

The textual representations of symbolic expressions are case-sensitive.

Symbolic expressions are naturally comparable based on their textual representations.

Two symbolic expressions (X) and (Y) are equal, iff X.toString() equals Y.toString().

All instances of this interface are immutable.

  • Method Summary

    Modifier and Type
    Method
    Description
    default SAtom
    Cast this object to SAtom.
    default SList
    Cast this object to SList.
    boolean
    bfs(Predicate<Sexpr<?>> condition)
    This method performs a breadth-first-search of the tree rooted at this node.
    default int
    compareTo(Sexpr<?> other)
    boolean
    dfs(Predicate<Sexpr<?>> condition)
    This method performs a depth-first-search of the tree rooted at this node.
    boolean
    This method determines whether this object is a SAtom.
    boolean
    This method determines whether this object is a SList.
    This method retrieves an object describing the source from which this object we obtained.
    boolean
    postorder(Predicate<Sexpr<?>> condition)
    This method performs a post-order-search of the tree rooted at this node.
    boolean
    preorder(Predicate<Sexpr<?>> condition)
    This method performs a pre-order-search of the tree rooted at this node.
    This method retrieves the textual representation of this symbolic expression.
    void
    traverse(Consumer<Sexpr<?>> before, Consumer<Sexpr<?>> after)
    This method performs a traversal of the tree rooted at this node.
    int
    This method determines the height of the tree rooted at this node.
    int
    This method counts the leaf nodes in the tree rooted at this node.
    int
    This method counts the nodes in the tree rooted at this node.
  • Method Details

    • treeLeafCount

      int treeLeafCount()
      This method counts the leaf nodes in the tree rooted at this node.

      This is a constant-time operation.

      Returns:
      the number of leaf nodes.
    • treeHeight

      int treeHeight()
      This method determines the height of the tree rooted at this node.

      This is a constant-time operation.

      Returns:
      the height of this tree.
    • treeSize

      int treeSize()
      This method counts the nodes in the tree rooted at this node.

      This is a constant-time operation.

      Returns:
      the number of nodes, including this node.
    • bfs

      boolean bfs(Predicate<Sexpr<?>> condition)
      This method performs a breadth-first-search of the tree rooted at this node.
      Parameters:
      condition - will return true, when the sought after node is found.
      Returns:
      true, if the node was found.
    • dfs

      boolean dfs(Predicate<Sexpr<?>> condition)
      This method performs a depth-first-search of the tree rooted at this node.
      Parameters:
      condition - will return true, when the sought after node is found.
      Returns:
      true, if the node was found.
    • preorder

      boolean preorder(Predicate<Sexpr<?>> condition)
      This method performs a pre-order-search of the tree rooted at this node.
      Parameters:
      condition - will return true, when the sought after node is found.
      Returns:
      true, if the node was found.
    • postorder

      boolean postorder(Predicate<Sexpr<?>> condition)
      This method performs a post-order-search of the tree rooted at this node.
      Parameters:
      condition - will return true, when the sought after node is found.
      Returns:
      true, if the node was found.
    • traverse

      void traverse(Consumer<Sexpr<?>> before, Consumer<Sexpr<?>> after)
      This method performs a traversal of the tree rooted at this node.
      Parameters:
      before - will be invoked upon entering each sub-tree.
      after - will be invoked upon exiting each sub-tree.
    • isAtom

      boolean isAtom()
      This method determines whether this object is a SAtom.
      Returns:
      true, iff this object is a SAtom.
    • isList

      boolean isList()
      This method determines whether this object is a SList.
      Returns:
      true, iff this object is a SAtom.
    • location

      SourceLocation location()
      This method retrieves an object describing the source from which this object we obtained.
      Returns:
      the source-code location of this node.
    • compareTo

      default int compareTo(Sexpr<?> other)
      Specified by:
      compareTo in interface Comparable<T extends Sexpr<T>>
    • asAtom

      default SAtom asAtom()
      Cast this object to SAtom.

      This method could be considered a bad API design choice. However, the inclusion of this method makes the use of fluent chained-methods calls clearer and easier to write; therefore, the benefits outweigh the down-sides here.

      Returns:
      this.
      Throws:
      ClassCastException - if isAtom() is false.
    • asList

      default SList asList()
      Cast this object to SList.

      This method could be considered a bad API design choice. However, the inclusion of this method makes the use of fluent chained-methods calls clearer and easier to write; therefore, the benefits outweigh the down-sides here.

      Returns:
      this.
      Throws:
      ClassCastException - if isList() is false.
    • toString

      String toString()
      This method retrieves the textual representation of this symbolic expression.
      Overrides:
      toString in class Object
      Returns:
      this object as a string.