Question
Create a generic class that implements the interface with the methods directions given: --------------------------------------------------------------------------------------------------------- import java.util.ArrayList; /** * This is a generic LinkedConverterTreeInterface * *
Create a generic class that implements the interface with the methods directions given:
---------------------------------------------------------------------------------------------------------
import java.util.ArrayList; /** * This is a generic LinkedConverterTreeInterface * * It is intended for creation of LinkedTrees that do conversion * using a LinkedTree * * Note: usually addNode, fetchNode and LNROutputTraversal would be private * * * */ public interface LinkedConverterTreeInterface{ /** * Returns a reference to the root * @return reference to root */ public TreeNode getRoot(); /** * sets the root of the Tree * @param newNode a TreeNode that will be the new root */ public void setRoot(TreeNode newNode); /** * Adds result to the correct position in the tree based on the code * This method will call the recursive method addNode * * @param code the code for the new node to be added * @return the linkedConverterTree with the new node added */ public LinkedConverterTreeInterface insert(T code, T result); /** * This is a recursive method that adds element to the correct position * in the tree based on the code. * * @param root the root of the tree for this particular recursive instance of addNode * @param code the code for this particular recursive instance of addNode * @param letter the data of the new TreeNode to be added */ public void addNode(TreeNode root, T code, T letter); /** * Fetch the data in the tree based on the code * This method will call the recursive method fetchNode * * @param code the code that describes the traversals within the tree * @return the result that corresponds to the code */ public T fetch(String code); /** * This is the recursive method that fetches the data of the TreeNode * that corresponds with the code * * @param root the root of the tree for this particular recursive instance of addNode * @param code the code for this particular recursive instance of fetchNode * @return the data corresponding to the code */ public T fetchNode(TreeNode root, T code); /** * This operation is not supported for a LinkedConverterTree * @param data data of node to be deleted * @return reference to the current tree * @throws UnsupportedOperationException */ public LinkedConverterTreeInterface delete(T data) throws UnsupportedOperationException; /** * This operation is not supported for a LinkedConverterTree * @return reference to the current tree * @throws UnsupportedOperationException */ public LinkedConverterTreeInterface update() throws UnsupportedOperationException; /** * This method builds the LinkedConverterTree by inserting TreeNodes * into their proper locations * */ public void buildTree(); /** * Returns an ArrayList of the items in the linked converter Tree in LNR (Inorder) Traversal order * Used for testing to make sure tree is built correctly * @return an ArrayList of the items in the linked Tree */ public ArrayList toArrayList(); /** * The recursive method to put the contents of the linked converter tree in an ArrayList * LNR (Inorder) * @param root the root of the tree for this particular recursive instance * @param list the ArrayList that will hold the contents of the tree in LNR order */ public void LNRoutputTraversal(TreeNode root, ArrayList list); }
-------------------------------------------------------------------------------------------------------------------------------
interface LinkedConverterTreeInterface
All Known Implementing Classes:
MorseCodeTree
public interface LinkedConverterTreeInterface
This is a generic LinkedConverterTreeInterface It is intended for creation of LinkedTrees that do conversion using a LinkedTree Note: usually addNode, fetchNode and LNROutputTraversal would be private
Method Summary | |
---|---|
void | addNode(TreeNode root |
void | buildTree() This method builds the LinkedConverterTree by inserting TreeNodes into their proper locations |
LinkedConverterTreeInterface | delete(T data) This operation is not supported for a LinkedConverterTree |
T | fetch(java.lang.String code) Fetch the data in the tree based on the code This method will call the recursive method fetchNode |
T | fetchNode(TreeNode |
TreeNode | getRoot() Returns a reference to the root |
LinkedConverterTreeInterface | insert(T code, T result) Adds result to the correct position in the tree based on the code This method will call the recursive method addNode |
void | LNRoutputTraversal(TreeNode |
void | setRoot(TreeNode |
java.util.ArrayList | toArrayList() Returns an ArrayList of the items in the linked converter Tree in LNR (Inorder) Traversal order Used for testing to make sure tree is built correctly |
LinkedConverterTreeInterface | update() This operation is not supported for a LinkedConverterTree |
Method Detail |
---|
getRoot
TreeNode getRoot()
Returns a reference to the root
Returns:
reference to root
setRoot
void setRoot(TreeNode newNode)
sets the root of the Tree
Parameters:
newNode - a TreeNode that will be the new root
insert
LinkedConverterTreeInterface insert(T code, T result)
Adds result to the correct position in the tree based on the code This method will call the recursive method addNode
Parameters:
code - the code for the new node to be added
Returns:
the linkedConverterTree with the new node added
addNode
void addNode(TreeNode root, T code, T letter)
This is a recursive method that adds element to the correct position in the tree based on the code.
Parameters:
root - the root of the tree for this particular recursive instance of addNode
code - the code for this particular recursive instance of addNode
letter - the data of the new TreeNode to be added
fetch
T fetch(java.lang.String code)
Fetch the data in the tree based on the code This method will call the recursive method fetchNode
Parameters:
code - the code that describes the traversals within the tree
Returns:
the result that corresponds to the code
fetchNode
T fetchNode(TreeNode root, T code)
This is the recursive method that fetches the data of the TreeNode that corresponds with the code
Parameters:
root - the root of the tree for this particular recursive instance of addNode
code - the code for this particular recursive instance of fetchNode
Returns:
the data corresponding to the code
delete
LinkedConverterTreeInterface delete(T data) throws java.lang.UnsupportedOperationException
This operation is not supported for a LinkedConverterTree
Parameters:
data - data of node to be deleted
Returns:
reference to the current tree
Throws:
java.lang.UnsupportedOperationException
update
LinkedConverterTreeInterface update() throws java.lang.UnsupportedOperationException
This operation is not supported for a LinkedConverterTree
Returns:
reference to the current tree
Throws:
java.lang.UnsupportedOperationException
buildTree
void buildTree()
This method builds the LinkedConverterTree by inserting TreeNodes into their proper locations
toArrayList
java.util.ArrayList toArrayList()
Returns an ArrayList of the items in the linked converter Tree in LNR (Inorder) Traversal order Used for testing to make sure tree is built correctly
Returns:
an ArrayList of the items in the linked Tree
LNRoutputTraversal
void LNRoutputTraversal(TreeNode root, java.util.ArrayList list)
The recursive method to put the contents of the linked converter tree in an ArrayList LNR (Inorder)
Parameters:
root - the root of the tree for this particular recursive instance
list - the ArrayList that will hold the contents of the tree in LNR order
-----------------------------------------------------------------------------------
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started