-
Notifications
You must be signed in to change notification settings - Fork 587
/
primitiveArrayStack.stg
270 lines (233 loc) · 6.95 KB
/
primitiveArrayStack.stg
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
import "copyrightAndOthers.stg"
import "primitiveEquals.stg"
import "primitiveHashCode.stg"
import "primitiveLiteral.stg"
targetPath() ::= "org/eclipse/collections/impl/stack/mutable/primitive"
fileName(primitive) ::= "<primitive.name>ArrayStack"
class(primitive) ::= <<
<body(primitive.type, primitive.name)>
>>
body(type, name) ::= <<
<copyrightAndOthers()>
package org.eclipse.collections.impl.stack.mutable.primitive;
import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import org.eclipse.collections.api.<name>Iterable;
import org.eclipse.collections.api.block.function.primitive.<name>ToObjectFunction;
import org.eclipse.collections.api.block.predicate.primitive.<name>Predicate;
import org.eclipse.collections.api.iterator.<name>Iterator;
import org.eclipse.collections.api.list.primitive.<name>List;
import org.eclipse.collections.api.list.primitive.Mutable<name>List;
import org.eclipse.collections.api.stack.MutableStack;
import org.eclipse.collections.api.stack.primitive.<name>Stack;
import org.eclipse.collections.api.stack.primitive.Immutable<name>Stack;
import org.eclipse.collections.api.stack.primitive.Mutable<name>Stack;
import org.eclipse.collections.impl.factory.primitive.<name>Stacks;
import org.eclipse.collections.impl.list.mutable.primitive.<name>ArrayList;
import org.eclipse.collections.impl.stack.primitive.Abstract<name>Stack;
import org.eclipse.collections.impl.stack.mutable.ArrayStack;
/**
* <name>ArrayStack is similar to {@link ArrayStack}, and is memory-optimized for <type> primitives.
* This file was automatically generated from template file primitiveArrayStack.stg.
*/
public class <name>ArrayStack extends Abstract<name>Stack
implements Mutable<name>Stack, Externalizable
{
private static final long serialVersionUID = 1L;
private transient <name>ArrayList delegate;
public <name>ArrayStack()
{
this.delegate = new <name>ArrayList();
}
private <name>ArrayStack(int size)
{
this.delegate = new <name>ArrayList(size);
}
private <name>ArrayStack(<type>... items)
{
this.delegate = new <name>ArrayList(items);
}
public static <name>ArrayStack newStackFromTopToBottom(<type>... items)
{
<name>ArrayStack stack = new <name>ArrayStack(items.length);
for (int i = items.length - 1; i >= 0; i--)
{
stack.push(items[i]);
}
return stack;
}
public static <name>ArrayStack newStackWith(<type>... items)
{
return new <name>ArrayStack(items);
}
public static <name>ArrayStack newStack(<name>Iterable items)
{
<name>ArrayStack stack = new <name>ArrayStack(items.size());
stack.delegate = <name>ArrayList.newList(items);
return stack;
}
public static <name>ArrayStack newStackFromTopToBottom(<name>Iterable items)
{
<name>ArrayStack stack = new <name>ArrayStack(items.size());
stack.delegate = <name>ArrayList.newList(items).reverseThis();
return stack;
}
@Override
protected <name>ArrayList getDelegate()
{
return this.delegate;
}
@Override
public void push(<type> item)
{
this.delegate.add(item);
}
@Override
public <type> pop()
{
this.checkEmptyStack();
return this.delegate.removeAtIndex(this.delegate.size() - 1);
}
@Override
public <name>List pop(int count)
{
this.checkPositiveValueForCount(count);
this.checkSizeLessThanCount(count);
if (count == 0)
{
return new <name>ArrayList(0);
}
Mutable<name>List subList = new <name>ArrayList(count);
while (count > 0)
{
subList.add(this.pop());
count--;
}
return subList;
}
@Override
public Mutable<name>Stack select(<name>Predicate predicate)
{
return newStackFromTopToBottom(this.delegate.asReversed().select(predicate));
}
@Override
public Mutable<name>Stack reject(<name>Predicate predicate)
{
return newStackFromTopToBottom(this.delegate.asReversed().reject(predicate));
}
@Override
public \<V> MutableStack\<V> collect(<name>ToObjectFunction\<? extends V> function)
{
return ArrayStack.newStackFromTopToBottom(this.delegate.asReversed().collect(function));
}
@Override
public void clear()
{
this.delegate.clear();
}
<(sortMethods.(type))()>
@Override
public Mutable<name>Stack asUnmodifiable()
{
return new Unmodifiable<name>Stack(this);
}
@Override
public Mutable<name>Stack asSynchronized()
{
return new Synchronized<name>Stack(this);
}
@Override
public Immutable<name>Stack toImmutable()
{
return <name>Stacks.immutable.withAll(this.delegate);
}
/**
* Creates a new empty <name>ArrayStack.
*
* @since 9.2.
*/
@Override
public <name>ArrayStack newEmpty()
{
return new <name>ArrayStack();
}
@Override
public boolean equals(Object otherStack)
{
if (otherStack == this)
{
return true;
}
if (!(otherStack instanceof <name>Stack))
{
return false;
}
<name>Stack stack = (<name>Stack) otherStack;
if (this.size() != stack.size())
{
return false;
}
for (int i = 0; i \< this.size(); i++)
{
if (<(notEquals.(type))("this.peekAt(i)", "stack.peekAt(i)")>)
{
return false;
}
}
return true;
}
@Override
public int hashCode()
{
int hashCode = 1;
for (int i = this.size() - 1; i >= 0; i--)
{
<type> item = this.delegate.get(i);
hashCode = 31 * hashCode + <(hashCode.(type))("item")>;
}
return hashCode;
}
@Override
public void writeExternal(ObjectOutput out) throws IOException
{
out.writeInt(this.size());
<name>Iterator iterator = this.delegate.asReversed().<type>Iterator();
while (iterator.hasNext())
{
<type> each = iterator.next();
out.write<name>(each);
}
}
@Override
public void readExternal(ObjectInput in) throws IOException
{
int size = in.readInt();
<type>[] array = new <type>[size];
for (int i = size - 1; i >= 0; i--)
{
array[i] = in.read<name>();
}
this.delegate = <name>ArrayList.newListWith(array);
}
}
>>
sortMethods ::= [
"byte": "allMethods",
"short": "allMethods",
"char": "allMethods",
"int": "allMethods",
"long": "allMethods",
"float": "allMethods",
"double": "allMethods",
"boolean": "noMethods"
]
allMethods() ::= <<
@Override
public Mutable<name>List toSortedList()
{
return <name>ArrayList.newList(this).sortThis();
}
>>
noMethods() ::= ""