Package EnchantmentOrder
Class BinaryTree
java.lang.Object
kkchengaf.EnchantmentOrder.BinaryTree
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionBuild the tree based on the structure strc, value of the node are not built, Return the tree root for traversalgetCost()
get the total cost of enchantment weightsGet flatten array of the tree structuregetRoot()
get the tree root of the structuregetSort()
Get sorted flatten array of the tree structureorg.json.JSONArray
Get the JSONArray of the structureAssign and updates NodeValues to the tree nodesvoid
set the total cost of enchantment weightstoString()
boolean
traversal
(Node node, EnchantStep f) MUST invoke tree.parseTree before this function, Traverse the tree, execute the function every 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
Get flatten array of the tree structure- Returns:
- Integer ArrayList
-
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
set the total cost of enchantment weights- Parameters:
cost
- , Integer
-
getCost
get the total cost of enchantment weights- Returns:
- Integer
-
getRoot
get the tree root of the structure- Returns:
- Node
-
toString
-
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
Assign and updates NodeValues to the tree nodes- Parameters:
sortedTarget
- , ArrayList NodeValue, the mapping from sortedlist of weight to NodeValueinputsSrc
- , 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
MUST invoke tree.parseTree before this function, Traverse the tree, execute the function every non leaf node- Parameters:
node
- , the node that is processingf
- , implements the EnchantStep().parse function- Returns:
- boolean, indicate whether it is non leaf node/root
-