package org.warp.commonutils.type; import java.util.Collection; import java.util.Iterator; import java.util.Objects; import java.util.StringJoiner; import org.jetbrains.annotations.NotNull; public class FastUtilStackWrapper implements Stack, Collection { private final it.unimi.dsi.fastutil.Stack stack; private final Collection collection; public & Collection> FastUtilStackWrapper(U stack) { this.stack = stack; this.collection = stack; } @Override public void push(T o) { this.stack.push(o); } @Override public T pop() { return this.stack.pop(); } @Override public int size() { return collection.size(); } @Override public boolean isEmpty() { return this.stack.isEmpty(); } @Override public boolean contains(Object o) { return collection.contains(o); } @NotNull @Override public Iterator iterator() { return collection.iterator(); } @NotNull @Override public Object @NotNull [] toArray() { return collection.toArray(); } @NotNull @Override public T1 @NotNull [] toArray(@NotNull T1 @NotNull [] a) { //noinspection SuspiciousToArrayCall return collection.toArray(a); } @Override public boolean add(T t) { return collection.add(t); } @Override public boolean remove(Object o) { return collection.remove(o); } @Override public boolean containsAll(@NotNull Collection c) { return collection.containsAll(c); } @Override public boolean addAll(@NotNull Collection c) { return collection.addAll(c); } @Override public boolean removeAll(@NotNull Collection c) { return collection.removeAll(c); } @Override public boolean retainAll(@NotNull Collection c) { return collection.retainAll(c); } @Override public void clear() { collection.clear(); } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } FastUtilStackWrapper that = (FastUtilStackWrapper) o; return Objects.equals(stack, that.stack); } @Override public int hashCode() { return stack != null ? stack.hashCode() : 0; } @Override public String toString() { return new StringJoiner(", ", FastUtilStackWrapper.class.getSimpleName() + "[", "]") .add("stack=" + stack) .toString(); } }