Class CheckerTree<T>

java.lang.Object
util.AbstractChecker<Tree<T>,CheckerTree<T>>
specialized_checkers.collection.CheckerTree<T>
Type Parameters:
T - the type of elements stored in the tree
All Implemented Interfaces:
InterfaceChecker<AbstractChecker<Tree<T>,CheckerTree<T>>,Tree<T>>

public class CheckerTree<T> extends AbstractChecker<Tree<T>,CheckerTree<T>>
A specialized checker for Tree data structures, providing a fluent API to assert various properties and invariants about a tree. This class extends AbstractChecker and allows for custom or default naming of the checker instance.

CheckerTree provides static factory methods for convenient construction from a Tree instance, a root value, or a root value with a map of children. It supports checks for emptiness, binary structure, symmetry, fullness, depth, number of leaves, and diameter, among others.

Usage Example:


 Tree<Integer> tree = new Tree<>(1);
 CheckerTree<Integer> checker = CheckerTree.check(tree);
 checker.isBinaryTree().minDepth(1);
 
See Also:
  • Constructor Details

    • CheckerTree

      protected CheckerTree(Tree<T> tree, String name)
      Constructs a new CheckerTree with the specified tree and name.
      Parameters:
      tree - the underlying tree structure to be wrapped or checked
      name - the name associated with this CheckerTree
  • Method Details

    • check

      public static <T> CheckerTree<T> check(Tree<T> tree, String name)
      Creates a CheckerTree for the given tree and assigns a custom name.
      Type Parameters:
      T - the Tree's element type
      Parameters:
      tree - the tree to check
      name - the name to assign to this checker
      Returns:
      a CheckerTree instance for the given tree
    • check

      public static <T> CheckerTree<T> check(T rootValue, Map<T,List<T>> childrenMap, String name)
      Creates a CheckerTree from a root value and a map of children, and assigns a custom name.
      Type Parameters:
      T - the Tree's element type
      Parameters:
      rootValue - the value of the root node
      childrenMap - a map where each key is a node and the value is a list of its children
      name - the name to assign to this checker
      Returns:
      a CheckerTree instance for the constructed tree
    • check

      public static <T> CheckerTree<T> check(T rootValue, String name)
      Creates a CheckerTree from a root value and assigns a custom name.
      Type Parameters:
      T - the Tree's element type
      Parameters:
      rootValue - the value of the root node
      name - the name to assign to this checker
      Returns:
      a CheckerTree instance for the constructed tree
    • check

      public static <T> CheckerTree<T> check(Tree<T> tree)
      Creates a CheckerTree for the given tree with a default name.
      Type Parameters:
      T - the Tree's element type
      Parameters:
      tree - the tree to check
      Returns:
      a CheckerTree instance for the given tree
    • check

      public static <T> CheckerTree<T> check(T rootValue, Map<T,List<T>> childrenMap)
      Creates a CheckerTree from a root value and a map of children, with a default name.
      Type Parameters:
      T - the Tree's element type
      Parameters:
      rootValue - the value of the root node
      childrenMap - a map where each key is a node and the value is a list of its children
      Returns:
      a CheckerTree instance for the constructed tree
    • check

      public static <T> CheckerTree<T> check(T rootValue)
      Creates a CheckerTree from a root value with a default name.
      Type Parameters:
      T - the Tree's element type
      Parameters:
      rootValue - the value of the root node
      Returns:
      a CheckerTree instance for the constructed tree
    • self

      protected CheckerTree<T> self()
      Returns this instance (for fluent API).
      Specified by:
      self in class AbstractChecker<Tree<T>,CheckerTree<T>>
      Returns:
      this CheckerTree instance
    • isEmpty

      public CheckerTree<T> isEmpty()
      Checks if the tree is empty.
      Returns:
      this CheckerTree instance
    • isBinaryTree

      public CheckerTree<T> isBinaryTree()
      Checks if the tree is a binary tree (each node has at most two children).
      Returns:
      this CheckerTree instance
    • isSymmetric

      public CheckerTree<T> isSymmetric()
      Checks if the tree is symmetric (mirror image around its center).
      Returns:
      this CheckerTree instance
    • isFull

      public CheckerTree<T> isFull()
      Checks if the tree is full (every node has 0 or 2 children).
      Returns:
      this CheckerTree instance
    • minDepth

      public CheckerTree<T> minDepth(int min)
      Checks if the tree's depth is at least the specified minimum.
      Parameters:
      min - the minimum depth
      Returns:
      this CheckerTree instance
    • maxDepth

      public CheckerTree<T> maxDepth(int max)
      Checks if the tree's depth is at most the specified maximum.
      Parameters:
      max - the maximum depth
      Returns:
      this CheckerTree instance
    • inRangeDepth

      public CheckerTree<T> inRangeDepth(int min, int max)
      Checks if the tree's depth is within the specified range (inclusive).
      Parameters:
      min - the minimum depth
      max - the maximum depth
      Returns:
      this CheckerTree instance
    • minLeaves

      public CheckerTree<T> minLeaves(int min)
      Checks if the number of leaves in the tree is at least the specified minimum.
      Parameters:
      min - the minimum number of leaves
      Returns:
      this CheckerTree instance
    • maxLeaves

      public CheckerTree<T> maxLeaves(int max)
      Checks if the number of leaves in the tree is at most the specified maximum.
      Parameters:
      max - the maximum number of leaves
      Returns:
      this CheckerTree instance
    • inRangeLeaves

      public CheckerTree<T> inRangeLeaves(int min, int max)
      Checks if the number of leaves in the tree is within the specified range (inclusive).
      Parameters:
      min - the minimum number of leaves
      max - the maximum number of leaves
      Returns:
      this CheckerTree instance
    • minDiamenter

      public CheckerTree<T> minDiamenter(int min)
      Checks if the tree's diameter is at least the specified minimum.
      Parameters:
      min - the minimum diameter
      Returns:
      this CheckerTree instance
    • maxDiamenter

      public CheckerTree<T> maxDiamenter(int max)
      Checks if the tree's diameter is at most the specified maximum.
      Parameters:
      max - the maximum diameter
      Returns:
      this CheckerTree instance
    • inRangeDiamenter

      public CheckerTree<T> inRangeDiamenter(int min, int max)
      Checks if the tree's diameter is within the specified range (inclusive).
      Parameters:
      min - the minimum diameter
      max - the maximum diameter
      Returns:
      this CheckerTree instance