Advertisement
saltycracker

BtreeWrapper.java

Sep 28th, 2020 (edited)
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.13 KB | None | 0 0
  1. package myBtree;
  2.  
  3. import java.util.function.Consumer;
  4. import java.util.Optional;
  5.  
  6. import myBtree.Btree;
  7. import myBtree.Empty;
  8.  
  9. final public class BtreeWrapper<T extends Comparable<T>> {
  10.  
  11.   private Btree<T> bt = null;
  12.  
  13.   static public<T extends Comparable<T>> BtreeWrapper<T> CreateEmpty() {
  14.     return new BtreeWrapper<T>();
  15.   }
  16.  
  17.   private BtreeWrapper() {
  18.     this.bt = new Empty<T>();
  19.   }
  20.  
  21.   private BtreeWrapper(Btree<T> other) {
  22.     this.bt = other;
  23.   }
  24.  
  25.   public BtreeWrapper<T> getBtreeWrapper() {
  26.     return new BtreeWrapper<T>(this.bt);
  27.   }
  28.  
  29.   public void display(Consumer<T> func) {
  30.     this.bt.display(func);
  31.   }
  32.  
  33.   public BtreeWrapper<T> add(T data) {
  34.     this.bt = this.bt.add(data);
  35.     return this;
  36.   }
  37.  
  38.   public Optional<BtreeWrapper<T>> find(T data) {
  39.   var ans = this.bt.find(data);
  40.     if (ans.isEmpty()) {
  41.       return Optional.empty();
  42.     }else {
  43.       return Optional.of(new BtreeWrapper<T>(ans.get()));
  44.     }
  45.   }
  46.  
  47.   public boolean isEmpty() {
  48.     return this.bt.isEmpty();
  49.   }
  50.  
  51.   public BtreeWrapper<T> remove(T data) {
  52.     this.bt = this.bt.remove(data);
  53.     return this;
  54.   }
  55.  
  56. }
  57.  
  58.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement