ArrayListStack.java
5.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
/*
* Decompiled with CFR 0_118.
*/
package com.adobe.internal.util;
import com.adobe.internal.util.Stack;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.EmptyStackException;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
public class ArrayListStack<T>
implements Stack<T>,
List<T>,
Serializable {
private ArrayList<T> items;
private static final long serialVersionUID = 1;
public ArrayListStack() {
this.items = new ArrayList();
}
public ArrayListStack(int size) {
this.items = new ArrayList(size);
}
public ArrayListStack(ArrayList<T> list) {
this.items = list;
}
public ArrayList<T> getArrayList() {
return this.items;
}
@Override
public T push(T elem) {
this.items.add(elem);
return elem;
}
@Override
public T pop() throws EmptyStackException {
int len = this.size();
T obj = this.peek();
this.items.remove(len - 1);
return obj;
}
@Override
public T peek() throws EmptyStackException {
int len = this.size();
if (len == 0) {
throw new EmptyStackException();
}
return this.items.get(len - 1);
}
@Override
public boolean empty() {
return this.items.isEmpty();
}
@Override
public int size() {
return this.items.size();
}
@Override
public void clear() {
this.items.clear();
}
public String toString() {
StringBuilder result = new StringBuilder();
for (int i = this.size() - 1; i >= 0; --i) {
result.append(this.items.get(i)).append('\n');
}
return result.toString();
}
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof ArrayListStack)) {
return false;
}
ArrayListStack oStack = (ArrayListStack)obj;
if (this.items.size() != oStack.size()) {
return false;
}
ListIterator<T> e1 = this.items.listIterator();
ListIterator<T> e2 = oStack.getArrayList().listIterator();
while (e1.hasNext() && e2.hasNext()) {
T o1 = e1.next();
T o2 = e2.next();
if (o1 == null) {
if (o2 == null) {
continue;
}
} else if (o1.equals(o2)) continue;
return false;
}
return !e1.hasNext() && !e2.hasNext();
}
@Override
public int hashCode() {
int hashCode = 1;
for (T obj : this.items) {
hashCode = 31 * hashCode + (obj == null ? 0 : obj.hashCode());
}
return hashCode;
}
public int search(T o) {
int i = this.items.lastIndexOf(o);
if (i >= 0) {
return this.size() - i;
}
return -1;
}
@Override
public void add(int index, T element) {
this.items.add(index, element);
}
@Override
public boolean add(T element) {
return this.items.add(element);
}
@Override
public boolean addAll(Collection<? extends T> collection) {
return this.items.addAll(collection);
}
@Override
public boolean addAll(int index, Collection<? extends T> collection) {
return this.items.addAll(index, collection);
}
@Override
public boolean contains(Object o) {
return this.items.contains(o);
}
@Override
public boolean containsAll(Collection<?> collection) {
return this.items.containsAll(collection);
}
@Override
public T get(int index) {
return this.items.get(index);
}
@Override
public int indexOf(Object o) {
return this.items.indexOf(o);
}
@Override
public boolean isEmpty() {
return this.items.isEmpty();
}
@Override
public Iterator<T> iterator() {
return this.items.iterator();
}
@Override
public int lastIndexOf(Object o) {
return this.items.lastIndexOf(o);
}
@Override
public ListIterator<T> listIterator() {
return this.items.listIterator();
}
@Override
public ListIterator<T> listIterator(int index) {
return this.items.listIterator(index);
}
@Override
public T remove(int index) {
return this.items.remove(index);
}
@Override
public boolean remove(Object o) {
return this.items.remove(o);
}
@Override
public boolean removeAll(Collection<?> collection) {
return this.items.removeAll(collection);
}
@Override
public boolean retainAll(Collection<?> collection) {
return this.items.retainAll(collection);
}
@Override
public T set(int index, T element) {
return this.items.set(index, element);
}
@Override
public List<T> subList(int fromIndex, int toIndex) {
return this.items.subList(fromIndex, toIndex);
}
@Override
public Object[] toArray() {
return this.items.toArray();
}
@Override
public Object[] toArray(Object[] a) {
return this.items.toArray(a);
}
}