Class BinaryTree

java.lang.Object
kkchengaf.EnchantmentOrder.BinaryTree

public class BinaryTree extends Object
The underlying tree structure of a search result,
it stores a reference to the result data after constructor,
buildTree(): Node, build the tree structure for later traversal,
parseTree(inputHashMap): Integer, assign the data to all the tree nodes,
traversal(node, callback): Boolean, post-order traversal and callback non leaf node
  • Constructor Details

    • BinaryTree

      public BinaryTree(org.json.JSONObject packed)
      Constructor of the tree
      Parameters:
      packed - JSONObject from data in json file
  • Method Details

    • getFlatten

      public ArrayList<Integer> getFlatten()
      Get flatten array of the tree structure
      Returns:
      Integer ArrayList
    • getSort

      public ArrayList<Integer> getSort()
      Get sorted flatten array of the tree structure
      Returns:
      Integer ArrayList
    • getStructure

      public org.json.JSONArray getStructure()
      Get the JSONArray of the structure
      Returns:
      JSONArray of Integer
    • setCost

      public void setCost(Integer cost)
      set the total cost of enchantment weights
      Parameters:
      cost - Integer
    • getCost

      public Integer getCost()
      get the total cost of enchantment weights
      Returns:
      Integer
    • getRoot

      public Node getRoot()
      get the tree root of the structure
      Returns:
      Node
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • buildTree

      public Node buildTree()
      Build the tree based on the structure strc,
      value of the node are not built,
      Return the tree root for traversal
      Returns:
      Node, the tree root of the structure
    • parseTree

      public Integer parseTree(ArrayList<Integer> sortedTarget, HashMap<Integer,Integer> inputsSrc)
      Assign and updates NodeValues to the tree nodes
      Parameters:
      sortedTarget - ArrayList NodeValue, the mapping from sortedlist of weight to NodeValue
      inputsSrc - HashMap Integer, Integer, the dict of id:lv of the books
      Returns:
      the total Enchantment cost to combine all the things (exclude anvil cost)
    • traversal

      public boolean traversal(Node node, EnchantStep f)
      MUST invoke tree.parseTree before this function,
      Traverse the tree, execute the function every non leaf node
      Parameters:
      node - the node that is processing
      f - implements the EnchantStep().parse function
      Returns:
      boolean, indicate whether it is non leaf node/root