Skip to content

Commit 4db9c69

Browse files
committed
Source Sync
1 parent 91aabe2 commit 4db9c69

256 files changed

Lines changed: 4950 additions & 3374 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/builder/resources/speiger/assets/collections/templates/lists/ArrayList.template

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ import java.util.Iterator;
99
import java.util.Objects;
1010
#if JDK_TYPE
1111
import java.util.OPTIONAL;
12+
#if SPLIT_ITERATOR_FEATURE && STREAM_FEATURE
13+
#if TYPE_OBJECT
14+
import java.util.stream.Stream;
15+
import java.util.stream.Collector;
16+
#endif
17+
#endif
18+
1219
#endif
1320
#if TYPE_OBJECT
1421
#if IARRAY_FEATURE || TYPE_OBJECT
@@ -225,6 +232,42 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
225232
return list;
226233
}
227234

235+
#endif
236+
#if JDK_TYPE && SPLIT_ITERATOR_FEATURE && STREAM_FEATURE
237+
#if TYPE_OBJECT
238+
/**
239+
* Creates a Collector for a ArrayList
240+
* @Type(T)
241+
* @return a collector
242+
*/
243+
public static <T> Collector<T, ObjectArrayList<T>, ObjectArrayList<T>> toList() {
244+
return Collector.of(ObjectArrayList::new, ObjectArrayList::add, ObjectArrayList::merge);
245+
}
246+
247+
/**
248+
* Collects a Stream to a ArrayList
249+
* @Type(T)
250+
* @return a list with the contents of the Stream
251+
*/
252+
public static <T> ARRAY_LIST KEY_GENERIC_TYPE toList(Stream<T> stream) {
253+
return stream.collect(ObjectArrayList::new, ObjectArrayList::add, ObjectArrayList::merge);
254+
}
255+
256+
private ObjectArrayList<T> merge(ObjectArrayList<T> a) {
257+
addAll(a);
258+
return this;
259+
}
260+
261+
#else
262+
/**
263+
* Collects a Stream to a ArrayList
264+
* @return a list with the contents of the Stream
265+
*/
266+
public static ARRAY_LIST toList(JAVA_STREAM stream) {
267+
return stream.collect(ARRAY_LIST::new, ARRAY_LIST::add, ARRAY_LIST::addAll);
268+
}
269+
270+
#endif
228271
#endif
229272
/**
230273
* Appends the specified element to the end of this list.

src/builder/resources/speiger/assets/collections/templates/lists/CopyOnWriteList.template

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ import java.util.NoSuchElementException;
1010
import java.util.Objects;
1111
#if JDK_TYPE
1212
import java.util.OPTIONAL;
13+
#if SPLIT_ITERATOR_FEATURE && STREAM_FEATURE
14+
#if TYPE_OBJECT
15+
import java.util.stream.Stream;
16+
import java.util.stream.Collector;
17+
#endif
18+
#endif
1319
#endif
1420
import java.util.concurrent.locks.ReentrantLock;
1521
import java.util.function.Consumer;
@@ -172,7 +178,42 @@ public class COPY_ON_WRITE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENER
172178
}
173179

174180
#endif
181+
#if JDK_TYPE && SPLIT_ITERATOR_FEATURE && STREAM_FEATURE
182+
#if TYPE_OBJECT
183+
/**
184+
* Creates a Collector for a CopyOnWriteArrayList
185+
* @Type(T)
186+
* @return a collector
187+
*/
188+
public static <T> Collector<T, CopyOnWriteObjectArrayList<T>, CopyOnWriteObjectArrayList<T>> toList() {
189+
return Collector.of(CopyOnWriteObjectArrayList::new, CopyOnWriteObjectArrayList::add, CopyOnWriteObjectArrayList::merge);
190+
}
191+
192+
/**
193+
* Collects a Stream to a CopyOnWriteArrayList
194+
* @Type(T)
195+
* @return a list with the contents of the Stream
196+
*/
197+
public static <T> CopyOnWriteObjectArrayList KEY_GENERIC_TYPE toList(Stream<T> stream) {
198+
return stream.collect(CopyOnWriteObjectArrayList::new, CopyOnWriteObjectArrayList::add, CopyOnWriteObjectArrayList::merge);
199+
}
200+
201+
private CopyOnWriteObjectArrayList<T> merge(CopyOnWriteObjectArrayList<T> a) {
202+
addAll(a);
203+
return this;
204+
}
175205

206+
#else
207+
/**
208+
* Collects a Stream to a CopyOnWriteArrayList
209+
* @return a list with the contents of the Stream
210+
*/
211+
public static COPY_ON_WRITE_LIST toList(JAVA_STREAM stream) {
212+
return stream.collect(COPY_ON_WRITE_LIST::new, COPY_ON_WRITE_LIST::add, COPY_ON_WRITE_LIST::addAll);
213+
}
214+
215+
#endif
216+
#endif
176217
private void setArray(KEY_TYPE[] data) {
177218
this.data = data;
178219
}

src/builder/resources/speiger/assets/collections/templates/lists/ImmutableList.template

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,25 @@ package speiger.src.collections.PACKAGE.lists;
33
import java.util.Arrays;
44
#if TYPE_OBJECT
55
import java.util.Comparator;
6+
#else if !TYPE_BOOLEAN
7+
import java.util.stream.JAVA_STREAM;
8+
import java.util.stream.StreamSupport;
69
#endif
710
import java.util.Collection;
811
import java.util.NoSuchElementException;
912
import java.util.Objects;
1013
#if JDK_TYPE
1114
import java.util.OPTIONAL;
15+
#if SPLIT_ITERATOR_FEATURE && STREAM_FEATURE
16+
#if PRIMITIVES
17+
import java.util.function.Supplier;
18+
#else
19+
import java.util.stream.Stream;
20+
import java.util.stream.Collector;
21+
#endif
22+
23+
import speiger.src.collections.PACKAGE.utils.COLLECTIONS;
24+
#endif
1225
#endif
1326
#if TYPE_OBJECT
1427
import java.util.function.BiFunction;
@@ -23,6 +36,7 @@ import java.util.function.PREDICATE;
2336
#if !JDK_FUNCTION
2437
import java.util.function.JAVA_PREDICATE;
2538
#endif
39+
2640
import java.util.function.JAVA_UNARY_OPERATOR;
2741
#endif
2842

@@ -42,10 +56,6 @@ import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
4256
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
4357
import speiger.src.collections.objects.utils.ObjectArrays;
4458
import speiger.src.collections.PACKAGE.utils.ITERATORS;
45-
#if PRIMITIVES && SPLIT_ITERATOR_FEATURE && STREAM_FEATURE
46-
import java.util.stream.JAVA_STREAM;
47-
import java.util.stream.StreamSupport;
48-
#endif
4959
#if SPLIT_ITERATOR_FEATURE
5060
import speiger.src.collections.PACKAGE.collections.SPLIT_ITERATOR;
5161
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
@@ -126,6 +136,42 @@ public class IMMUTABLE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_T
126136
data = Arrays.copyOfRange(a, offset, offset+length);
127137
}
128138

139+
#if JDK_TYPE && SPLIT_ITERATOR_FEATURE && STREAM_FEATURE
140+
#if TYPE_OBJECT
141+
/**
142+
* Creates a Collector for a ImmutableList
143+
* @Type(T)
144+
* @return a collector
145+
*/
146+
public static <T> Collector<T, COLLECTION<T>, ImmutableObjectList<T>> toList() {
147+
return Collector.of(COLLECTIONS::wrapper, COLLECTION::add, ImmutableObjectList::merge, E -> new IMMUTABLE_LIST<>(E.toArray((T[])new Object[E.size()])));
148+
}
149+
150+
/**
151+
* Collects a Stream to a ImmutableList
152+
* @Type(T)
153+
* @return a list with the contents of the Stream
154+
*/
155+
public static <T> ImmutableObjectList KEY_GENERIC_TYPE toList(Stream<T> stream) {
156+
return stream.collect(toList());
157+
}
158+
159+
private static <T> COLLECTION<T> merge(COLLECTION<T> a, COLLECTION<T> b) {
160+
a.addAll(b);
161+
return a;
162+
}
163+
164+
#else
165+
/**
166+
* Collects a Stream to a ImmutableList
167+
* @return a list with the contents of the Stream
168+
*/
169+
public static IMMUTABLE_LIST toList(JAVA_STREAM stream) {
170+
return new IMMUTABLE_LIST(stream.collect((Supplier<COLLECTION>)COLLECTIONS::wrapper, COLLECTION::add, COLLECTION::addAll).TO_ARRAY());
171+
}
172+
173+
#endif
174+
#endif
129175
@Override
130176
public boolean add(KEY_TYPE e) { throw new UnsupportedOperationException(); }
131177
@Override

src/builder/resources/speiger/assets/collections/templates/lists/LinkedList.template

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ import java.util.Iterator;
1313
import java.util.Objects;
1414
#if JDK_TYPE
1515
import java.util.OPTIONAL;
16+
#if SPLIT_ITERATOR_FEATURE && STREAM_FEATURE
17+
#if TYPE_OBJECT
18+
import java.util.stream.Stream;
19+
import java.util.stream.Collector;
20+
#endif
21+
#endif
1622
#endif
1723
import java.util.NoSuchElementException;
1824
#if SPLIT_ITERATOR_FEATURE
@@ -160,6 +166,42 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
160166
for(int i = offset,m=offset+length;i<m;add(a[i++]));
161167
}
162168

169+
#if JDK_TYPE && SPLIT_ITERATOR_FEATURE && STREAM_FEATURE
170+
#if TYPE_OBJECT
171+
/**
172+
* Creates a Collector for a LinkedList
173+
* @Type(T)
174+
* @return a collector
175+
*/
176+
public static <T> Collector<T, ObjectLinkedList<T>, ObjectLinkedList<T>> toList() {
177+
return Collector.of(ObjectLinkedList::new, ObjectLinkedList::add, ObjectLinkedList::merge);
178+
}
179+
180+
/**
181+
* Collects a Stream to a LinkedList
182+
* @Type(T)
183+
* @return a list with the contents of the Stream
184+
*/
185+
public static <T> ObjectLinkedList KEY_GENERIC_TYPE toList(Stream<T> stream) {
186+
return stream.collect(ObjectLinkedList::new, ObjectLinkedList::add, ObjectLinkedList::merge);
187+
}
188+
189+
private ObjectLinkedList<T> merge(ObjectLinkedList<T> a) {
190+
addAll(a);
191+
return this;
192+
}
193+
194+
#else
195+
/**
196+
* Collects a Stream to a LinkedList
197+
* @return a list with the contents of the Stream
198+
*/
199+
public static LINKED_LIST toList(JAVA_STREAM stream) {
200+
return stream.collect(LINKED_LIST::new, LINKED_LIST::add, LINKED_LIST::addAll);
201+
}
202+
203+
#endif
204+
#endif
163205
@Override
164206
public boolean add(KEY_TYPE e) {
165207
add(size(), e);

0 commit comments

Comments
 (0)