Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package tree;
- import container.Container;
- import tree.node.ITreeNode;
- import util.searchable.ISearchFilter;
- import java.util.Collection;
- public class GenericTree<TREETYPE> implements ITree<TREETYPE> { //Eldira 11815163
- private ITreeNode<TREETYPE> root;
- public GenericTree() {
- this.root = null;
- }
- public GenericTree(ITreeNode<TREETYPE> root) {
- this.root = root;
- }
- public ITreeNode<TREETYPE> getRoot() {
- return root;
- }
- public void setRoot(ITreeNode<TREETYPE> root) {
- this.root = root;
- }
- @Override
- public ITree<TREETYPE> deepCopy() {
- return new GenericTree<>(this.root.deepCopy());
- }
- @Override
- public ITreeNode<TREETYPE> findNode(ITreeNode<TREETYPE> searchNode) {
- if (this.root.equals(searchNode)) {
- return this.root;
- }
- return this.root.findNodeByNode(searchNode);
- }
- @Override
- public ITreeNode<TREETYPE> findNode(TREETYPE searchValue) {
- if (this.root.checkNodeByValue(searchValue)) {
- return this.root;
- }
- return this.root.findNodeByValue(searchValue);
- }
- @Override
- public String generateConsoleView(String spacer) {
- return this.root.generateConsoleView(spacer, "");
- }
- @Override
- public Collection<ITreeNode<TREETYPE>> searchByFilter(ISearchFilter filter, Object compareObject) {
- if (this.root == null) {
- return new Container<>();
- }
- return this.root.searchByFilter(filter, compareObject);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment