EldiraSesto

GenericTree

May 20th, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.58 KB | None | 0 0
  1. package tree;
  2.  
  3. import container.Container;
  4. import tree.node.ITreeNode;
  5. import util.searchable.ISearchFilter;
  6.  
  7. import java.util.Collection;
  8.  
  9. public class GenericTree<TREETYPE> implements ITree<TREETYPE> { //Eldira 11815163
  10.     private ITreeNode<TREETYPE> root;
  11.  
  12.     public GenericTree() {
  13.         this.root = null;
  14.     }
  15.  
  16.     public GenericTree(ITreeNode<TREETYPE> root) {
  17.         this.root = root;
  18.     }
  19.  
  20.     public ITreeNode<TREETYPE> getRoot() {
  21.         return root;
  22.     }
  23.  
  24.     public void setRoot(ITreeNode<TREETYPE> root) {
  25.         this.root = root;
  26.     }
  27.  
  28.     @Override
  29.     public ITree<TREETYPE> deepCopy() {
  30.         return new GenericTree<>(this.root.deepCopy());
  31.     }
  32.  
  33.     @Override
  34.     public ITreeNode<TREETYPE> findNode(ITreeNode<TREETYPE> searchNode) {
  35.         if (this.root.equals(searchNode)) {
  36.             return this.root;
  37.         }
  38.  
  39.         return this.root.findNodeByNode(searchNode);
  40.     }
  41.  
  42.     @Override
  43.     public ITreeNode<TREETYPE> findNode(TREETYPE searchValue) {
  44.         if (this.root.checkNodeByValue(searchValue)) {
  45.             return this.root;
  46.         }
  47.  
  48.         return this.root.findNodeByValue(searchValue);
  49.     }
  50.  
  51.     @Override
  52.     public String generateConsoleView(String spacer) {
  53.         return this.root.generateConsoleView(spacer, "");
  54.     }
  55.  
  56.     @Override
  57.     public Collection<ITreeNode<TREETYPE>> searchByFilter(ISearchFilter filter, Object compareObject) {
  58.         if (this.root == null) {
  59.             return new Container<>();
  60.         }
  61.  
  62.         return this.root.searchByFilter(filter, compareObject);
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment