Fork of the Fernflower decompiler
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
fernflower/src/org/jetbrains/java/decompiler/util/ListStack.java

71 lines
1.3 KiB

// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.java.decompiler.util;
import java.util.ArrayList;
public class ListStack<T> extends ArrayList<T> {
protected int pointer = 0;
public ListStack() {
super();
}
public ListStack(ArrayList<? extends T> list) {
super(list);
}
@Override
@SuppressWarnings("MethodDoesntCallSuperMethod")
public ListStack<T> clone() {
ListStack<T> copy = new ListStack<>(this);
copy.pointer = this.pointer;
return copy;
}
public void push(T item) {
this.add(item);
pointer++;
}
public T pop() {
pointer--;
T o = this.get(pointer);
this.remove(pointer);
return o;
}
public T pop(int count) {
T o = null;
for (int i = count; i > 0; i--) {
o = this.pop();
}
return o;
}
public void removeMultiple(int count) {
while (count > 0) {
pointer--;
this.remove(pointer);
count--;
}
}
public int getPointer() {
return pointer;
}
public T getByOffset(int offset) {
return this.get(pointer + offset);
}
public void insertByOffset(int offset, T item) {
this.add(pointer + offset, item);
pointer++;
}
@Override
public void clear() {
super.clear();
pointer = 0;
}
}