Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package myBtree;
- import java.util.function.Consumer;
- import java.util.Optional;
- import myBtree.Btree;
- import myBtree.Empty;
- final public class BtreeWrapper<T extends Comparable<T>> {
- private Btree<T> bt = null;
- static public<T extends Comparable<T>> BtreeWrapper<T> CreateEmpty() {
- return new BtreeWrapper<T>();
- }
- private BtreeWrapper() {
- this.bt = new Empty<T>();
- }
- private BtreeWrapper(Btree<T> other) {
- this.bt = other;
- }
- public BtreeWrapper<T> getBtreeWrapper() {
- return new BtreeWrapper<T>(this.bt);
- }
- public void display(Consumer<T> func) {
- this.bt.display(func);
- }
- public BtreeWrapper<T> add(T data) {
- this.bt = this.bt.add(data);
- return this;
- }
- public Optional<BtreeWrapper<T>> find(T data) {
- var ans = this.bt.find(data);
- if (ans.isEmpty()) {
- return Optional.empty();
- }else {
- return Optional.of(new BtreeWrapper<T>(ans.get()));
- }
- }
- public boolean isEmpty() {
- return this.bt.isEmpty();
- }
- public BtreeWrapper<T> remove(T data) {
- this.bt = this.bt.remove(data);
- return this;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement