-
Notifications
You must be signed in to change notification settings - Fork 587
/
mutablePrimitiveList.stg
263 lines (219 loc) · 7.42 KB
/
mutablePrimitiveList.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
import "copyrightAndOthers.stg"
import "primitiveAPI.stg"
targetPath() ::= "org/eclipse/collections/api/list/primitive"
fileName(primitive) ::= "Mutable<primitive.name>List"
class(primitive) ::= <<
<body(primitive.type, primitive.name)>
>>
body(type, name) ::= <<
<copyrightAndOthers()>
package org.eclipse.collections.api.list.primitive;
<(auxiliaryImports.(type))(type)>
import org.eclipse.collections.api.<name>Iterable;
import org.eclipse.collections.api.block.function.primitive.<name>IntToObjectFunction;
import org.eclipse.collections.api.block.function.primitive.<name>ToObjectFunction;
import org.eclipse.collections.api.block.predicate.primitive.<name>IntPredicate;
import org.eclipse.collections.api.block.predicate.primitive.<name>Predicate;
import org.eclipse.collections.api.block.procedure.primitive.<name>Procedure;
import org.eclipse.collections.api.collection.primitive.Mutable<name>Collection;
import org.eclipse.collections.api.list.MutableList;
import org.eclipse.collections.api.tuple.primitive.<name><name>Pair;
import org.eclipse.collections.api.tuple.primitive.<name>ObjectPair;
/**
* This file was automatically generated from template file mutablePrimitiveList.stg.
*
* @since 3.0.
*/
public interface Mutable<name>List extends Mutable<name>Collection, <name>List
{
void addAtIndex(int index, <type> element);
boolean addAllAtIndex(int index, <type>... source);
boolean addAllAtIndex(int index, <name>Iterable source);
<type> removeAtIndex(int index);
<type> set(int index, <type> element);
default void swap(int index1, int index2)
{
<type> value = this.get(index1);
this.set(index1, this.get(index2));
this.set(index2, value);
}
<sharedAPI(fileName(primitive), name)>
<mutableAPI(fileName(primitive), type, name)>
/**
* @since 9.0.
*/
@Override
default Mutable<name>List tap(<name>Procedure procedure)
{
this.forEach(procedure);
return this;
}
/**
* Returns a new Mutable<name>List including all elements with corresponding indexes matching the specified predicate.
*
* @since 11.1.
*/
@Override
default Mutable<name>List selectWithIndex(<name>IntPredicate predicate)
{
int[] index = {0};
return this.select(each -> predicate.accept(each, index[0]++));
}
/**
* Returns a new Mutable<name>List excluding all elements with corresponding indexes matching the specified predicate.
*
* @since 11.1.
*/
@Override
default Mutable<name>List rejectWithIndex(<name>IntPredicate predicate)
{
int[] index = {0};
return this.reject(each -> predicate.accept(each, index[0]++));
}
\<V> MutableList\<V> collect(<name>ToObjectFunction\<? extends V> function);
/**
* Returns a new MutableList using results obtained by applying the specified function to each element
* and its corresponding index.
*
* @since 9.1.
*/
@Override
default \<V> MutableList\<V> collectWithIndex(<name>IntToObjectFunction\<? extends V> function)
{
int[] index = {0};
return this.collect(each -> function.value(each, index[0]++));
}
Mutable<name>List reverseThis();
@Override
Mutable<name>List toReversed();
/**
* @since 6.0.
*/
@Override
Mutable<name>List distinct();
<(arithmeticMethods.(type))(type)>
@Override
Mutable<name>List asUnmodifiable();
@Override
Mutable<name>List asSynchronized();
/**
* Returns an immutable copy of this list.
*/
@Override
Immutable<name>List toImmutable();
@Override
Mutable<name>List subList(int fromIndex, int toIndex);
/**
* Returns a {@code MutableList} formed from this {@code Mutable<name>List} and another {@code <name>List} by
* combining corresponding elements in pairs. If one of the two {@code <name>List}s is longer than the other, its
* remaining elements are ignored.
*
* @since 9.1.
*/
default MutableList\<<name><name>Pair> zip<name>(<name>Iterable iterable)
{
throw new UnsupportedOperationException("Default method to prevent breaking backwards compatibility");
}
/**
* Returns a {@code MutableList} formed from this {@code Mutable<name>List} and a {@code ListIterable} by
* combining corresponding elements in pairs. If one of the two Lists is longer than the other, its
* remaining elements are ignored.
*
* @since 9.1.
*/
default \<T> MutableList\<<name>ObjectPair\<T\>> zip(Iterable\<T> list)
{
throw new UnsupportedOperationException("Default method to prevent breaking backwards compatibility");
}
/**
* Creates a new empty mutable version of the same List type.
*
* @since 9.2.
*/
default Mutable<name>List newEmpty()
{
throw new UnsupportedOperationException("Implement in concrete classes.");
}
}
>>
arithmeticMethods ::= [
"byte": "allMethods",
"short": "allMethods",
"char": "allMethods",
"int": "allMethods",
"long": "allMethods",
"float": "allMethods",
"double": "allMethods",
"boolean": "noMethods"
]
allMethods(type) ::= <<
/**
* Sorts this list mutating its contents and returns the same mutable list (this).
*/
Mutable<name>List sortThis();
/**
* Sorts the internal data structure of this list and returns the list itself as a convenience.
*/
default Mutable<name>List sortThis(<name>Comparator comparator)
{
throw new UnsupportedOperationException("sortThis(<name>Comparator comparator) is not supported on " + this.getClass());
}
/**
* Sorts the internal data structure of this list based on the natural order of the key returned by {@code
* function}.
*/
default \<T> Mutable<name>List sortThisBy(<name>ToObjectFunction\<T> function)
{
return sortThisBy(function, (Comparator\<? super T>) Comparator.naturalOrder());
}
/**
* Sorts the internal data structure of this list based on the key returned by {@code
* function} using the provided {@code comparator}.
*/
default \<T> Mutable<name>List sortThisBy(<name>ToObjectFunction\<T> function, Comparator\<? super T> comparator)
{
return this.sortThis((i1, i2) -> comparator.compare(function.valueOf(i1), function.valueOf(i2)));
}
/**
* Randomly permutes this list mutating its contents and returns the same list (this).
*
* Uses {@code java.util.Random} as the source of randomness.
*/
default Mutable<name>List shuffleThis()
{
return this.shuffleThis(new Random());
}
/**
* Randomly permutes this list mutating its contents and returns the same list (this).
*
* Implements the Fisher-Yates shuffle algorithm using the provided source of randomness.
*/
default Mutable<name>List shuffleThis(Random rnd)
{
for (int j = this.size() - 1; j > 0; j--)
{
int k = rnd.nextInt(j + 1);
<type> selected = this.get(j);
this.set(j, this.get(k));
this.set(k, selected);
}
return this;
}
>>
noMethods(type) ::= ""
auxiliaryImports ::= [
"byte": "allAuxiliaryImports",
"short": "allAuxiliaryImports",
"char": "allAuxiliaryImports",
"int": "allAuxiliaryImports",
"long": "allAuxiliaryImports",
"float": "allAuxiliaryImports",
"double": "allAuxiliaryImports",
"boolean": "noAuxiliaryImports"
]
allAuxiliaryImports(type) ::= <<
import java.util.Comparator;
import java.util.Random;
import org.eclipse.collections.api.block.comparator.primitive.<name>Comparator;
>>
noAuxiliaryImports(type) ::= ""