124 lines
2.3 KiB
Java
124 lines
2.3 KiB
Java
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<T> implements Stack<T>, Collection<T> {
|
|
|
|
private final it.unimi.dsi.fastutil.Stack<T> stack;
|
|
private final Collection<T> collection;
|
|
|
|
public <U extends it.unimi.dsi.fastutil.Stack<T> & Collection<T>> 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<T> iterator() {
|
|
return collection.iterator();
|
|
}
|
|
|
|
@NotNull
|
|
@Override
|
|
public Object @NotNull [] toArray() {
|
|
return collection.toArray();
|
|
}
|
|
|
|
@NotNull
|
|
@Override
|
|
public <T1> 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<? extends T> 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();
|
|
}
|
|
}
|