Collection Module Works now. (Least Configurable for obvious Reasons)

This commit is contained in:
2022-12-07 06:27:47 +01:00
parent 3ce52668df
commit 342b0cece9
9 changed files with 245 additions and 131 deletions
@@ -20,7 +20,7 @@ public class AsyncModule extends BaseModule
@Override
protected void loadBlockades() {
if(!isModuleEnabled()) {
addBlockedFiles("AsyncBuilder");
addBlockedFiles("AsyncBuilder", "Task");
}
}
@Override
@@ -1,5 +1,9 @@
package speiger.src.builder.modules;
import java.util.Arrays;
import java.util.Set;
import java.util.TreeSet;
import speiger.src.builder.ClassType;
@SuppressWarnings("javadoc")
@@ -12,12 +16,32 @@ public class CollectionModule extends BaseModule
@Override
protected void loadVariables() {}
@Override
protected void loadFlags() {}
@Override
public boolean areDependenciesLoaded(){ return isDependencyLoaded(JavaModule.INSTANCE); }
@Override
protected void loadBlockades()
public Set<String> getModuleKeys(ClassType keyType, ClassType valueType)
{
return new TreeSet<>(Arrays.asList("Streams", "Splititerators", "IArray", "Strategy"));
}
@Override
protected void loadFlags() {
if(isModuleEnabled()) addKeyFlag("COLLECTION_MODULE");
if(isModuleEnabled("Streams")) addKeyFlag("STREAM_FEATURE");
if(isModuleEnabled("Splititerators")) addKeyFlag("SPLIT_ITERATOR_FEATURE");
if(isModuleEnabled("IArray")) addKeyFlag("IARRAY_FEATURE");
}
@Override
protected void loadBlockades() {
if(!isModuleEnabled()) {
addBlockedFiles("Iterable", "Iterables", "Iterator", "Iterators", "BidirectionalIterator", "ListIterator");
addBlockedFiles("Arrays", "Collection", "AbstractCollection", "Collections", "Stack");
}
if(!isModuleEnabled("Splititerators")) addBlockedFiles("Splititerator", "Splititerators");
if(!isModuleEnabled("IArray")) addBlockedFiles("IArray");
if(!isModuleEnabled("Strategy")) addBlockedFiles("Strategy");
if(keyType.isObject()) {
addBlockedFiles("Stack");
addBlockedFiles("CollectionStreamTester");
@@ -5,16 +5,20 @@ import java.util.Collection;
import java.util.Objects;
import java.util.function.JAVA_PREDICATE;
import java.util.function.Predicate;
#if SPLIT_ITERATOR_FEATURE && STREAM_FEATURE
import java.util.stream.JAVA_STREAM;
import java.util.stream.StreamSupport;
#endif
#endif
#if TYPE_OBJECT
import java.util.function.Consumer;
import speiger.src.collections.ints.functions.function.Int2ObjectFunction;
#else
import speiger.src.collections.PACKAGE.functions.CONSUMER;
#endif
#if SPLIT_ITERATOR_FEATURE
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
#endif
import speiger.src.collections.PACKAGE.utils.COLLECTIONS;
import speiger.src.collections.utils.ISizeProvider;
import speiger.src.collections.utils.SanityChecks;
@@ -291,6 +295,7 @@ public interface COLLECTION KEY_GENERIC_TYPE extends Collection<CLASS_TYPE>, ITE
*/
public default COLLECTION KEY_GENERIC_TYPE unmodifiable() { return COLLECTIONS.unmodifiable(this); }
#if SPLIT_ITERATOR_FEATURE
#if PRIMITIVES
/**
* Returns a Java-Type-Specific Stream to reduce boxing/unboxing.
@@ -303,11 +308,15 @@ public interface COLLECTION KEY_GENERIC_TYPE extends Collection<CLASS_TYPE>, ITE
* @return a Stream of the closest java type
*/
default JAVA_STREAM parallelPrimitiveStream() { return StreamSupport.NEW_STREAM(SPLIT_ITERATORS.createJavaSplititerator(this, 0), true); }
#endif
#if STREAM_FEATURE
/**
* A Type Specific Type Splititerator to reduce boxing/unboxing
* @return type specific splititerator
*/
@Override
default SPLIT_ITERATOR KEY_GENERIC_TYPE spliterator() { return SPLIT_ITERATORS.createSplititerator(this, 0); }
#endif
#endif
}
@@ -49,7 +49,9 @@ import speiger.src.collections.PACKAGE.utils.ARRAYS;
#if ASYNC_MODULE
import speiger.src.collections.PACKAGE.utils.ASYNC_BUILDER;
#endif
#if SPLIT_ITERATOR_FEATURE
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
#endif
import speiger.src.collections.PACKAGE.utils.ITERABLES;
import speiger.src.collections.PACKAGE.utils.ITERATORS;
#if !LINKED_HASH_SET_FEATURE && LINKED_CUSTOM_HASH_SET_FEATURE
@@ -114,6 +116,7 @@ public interface ITERABLE KEY_GENERIC_TYPE extends Iterable<CLASS_TYPE>
iterator().forEachRemaining(input, action);
}
#if SPLIT_ITERATOR_FEATURE
/**
* A Type Specific Type Splititerator to reduce boxing/unboxing
* @return type specific splititerator
@@ -121,6 +124,7 @@ public interface ITERABLE KEY_GENERIC_TYPE extends Iterable<CLASS_TYPE>
@Override
default SPLIT_ITERATOR KEY_GENERIC_TYPE spliterator() { return SPLIT_ITERATORS.createUnknownSplititerator(iterator(), 0); }
#endif
#if ASYNC_MODULE
/**
* Creates a Async Builder for moving work of the thread.
@@ -8,7 +8,10 @@ import java.util.Collection;
import java.util.Iterator;
import java.util.Objects;
#if TYPE_OBJECT
#if IARRAY_FEATURE || TYPE_OBJECT
import java.util.function.Consumer;
#endif
import java.util.function.BiFunction;
#endif
import java.util.function.Predicate;
@@ -38,33 +41,38 @@ import speiger.src.collections.utils.Stack;
#else
import speiger.src.collections.objects.utils.ObjectArrays;
#endif
#if PRIMITIVES
#if PRIMITIVES && SPLIT_ITERATOR_FEATURE && STREAM_FEATURE
import java.util.stream.JAVA_STREAM;
import java.util.stream.StreamSupport;
#endif
#if IARRAY_FEATURE
import speiger.src.collections.PACKAGE.utils.IARRAY;
#endif
#if SPLIT_ITERATOR_FEATURE
import speiger.src.collections.PACKAGE.collections.SPLIT_ITERATOR;
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
#endif
#if !IARRAY_FEATURE
import speiger.src.collections.utils.IArray;
#endif
import speiger.src.collections.utils.SanityChecks;
#if TYPE_OBJECT
/**
* A Type-Specific Array-based implementation of list that is written to reduce (un)boxing
*
* <p>This implementation is optimized to improve how data is processed with interfaces like {@link IARRAY}, {@link Stack}
#if IARRAY_FEATURE
* <p>This implementation is optimized to improve how data is processed with interfaces like {@link IARRAY}, {@link STACK}
#else
* <p>This implementation is optimized to improve how data is processed with interfaces like {@link IArray}, {@link STACK}
#endif
* and with optimized functions that use type-specific implementations for primitives and optimized logic for bulkactions.
*
*
* @Type(T)
*/
public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE implements IARRAY<KEY_TYPE>, Stack<KEY_TYPE>
#if IARRAY_FEATURE
public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE implements IARRAY KEY_GENERIC_TYPE, STACK KEY_GENERIC_TYPE
#else
/**
* A Type-Specific Array-based implementation of list that is written to reduce (un)boxing
*
* <p>This implementation is optimized to improve how data is processed with interfaces like {@link IARRAY}, {@link STACK}
* and with optimized functions that use type-specific implementations for primitives and optimized logic for bulkactions.
*/
public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE implements IARRAY, STACK
public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE implements IArray, STACK KEY_GENERIC_TYPE
#endif
{
static final int DEFAULT_ARRAY_SIZE = 10;
@@ -587,6 +595,7 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
return data[(size() - 1) - index];
}
#if IARRAY_FEATURE
/**
* Provides the Underlying Array in the Implementation
* @return underlying Array
@@ -606,6 +615,7 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
return data.getClass() != Object[].class;
}
#endif
#endif
/**
* A Type Specific foreach function that reduces (un)boxing
@@ -1159,8 +1169,8 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + size);
}
#if PRIMITIVES
#if SPLIT_ITERATOR_FEATURE
#if PRIMITIVES && STREAM_FEATURE
/**
* Returns a Java-Type-Specific Stream to reduce boxing/unboxing.
* @return a Stream of the closest java type
@@ -1177,4 +1187,5 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
*/
@Override
public SPLIT_ITERATOR KEY_GENERIC_TYPE spliterator() { return SPLIT_ITERATORS.createArraySplititerator(data, size, 16464); }
#endif
}
@@ -41,12 +41,14 @@ import speiger.src.collections.utils.Stack;
#else
import speiger.src.collections.objects.utils.ObjectArrays;
#endif
#if PRIMITIVES
#if PRIMITIVES && STREAM_FEATURE && SPLIT_ITERATOR_FEATURE
import java.util.stream.JAVA_STREAM;
import java.util.stream.StreamSupport;
#endif
#if SPLIT_ITERATOR_FEATURE
import speiger.src.collections.PACKAGE.collections.SPLIT_ITERATOR;
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
#endif
import speiger.src.collections.utils.ITrimmable;
import speiger.src.collections.utils.SanityChecks;
@@ -1408,8 +1410,9 @@ public class COPY_ON_WRITE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENER
if (index < 0 || index > data.length)
throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + data.length);
}
#if PRIMITIVES
#if SPLIT_ITERATOR_FEATURE
#if PRIMITIVES && STREAM_FEATURE
/**
* Returns a Java-Type-Specific Stream to reduce boxing/unboxing.
* @return a Stream of the closest java type
@@ -1427,6 +1430,7 @@ public class COPY_ON_WRITE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENER
@Override
public SPLIT_ITERATOR KEY_GENERIC_TYPE spliterator() { return SPLIT_ITERATORS.createArraySplititerator(data, data.length, 16464); }
#endif
static final class COWIterator KEY_GENERIC_TYPE implements LIST_ITERATOR KEY_GENERIC_TYPE
{
KEY_TYPE[] data;
@@ -2080,9 +2084,11 @@ public class COPY_ON_WRITE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENER
}
}
#if SPLIT_ITERATOR_FEATURE
@Override
public SPLIT_ITERATOR KEY_GENERIC_TYPE spliterator() { return SPLIT_ITERATORS.createSplititerator(this, 16464); }
#endif
@Override
public LIST_ITERATOR KEY_GENERIC_TYPE listIterator(int index) {
if(index < 0 || index > size()) throw new IndexOutOfBoundsException();
@@ -29,12 +29,14 @@ import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
import speiger.src.collections.objects.utils.ObjectArrays;
import speiger.src.collections.PACKAGE.utils.ITERATORS;
#if PRIMITIVES
#if PRIMITIVES && SPLIT_ITERATOR_FEATURE && STREAM_FEATURE
import java.util.stream.JAVA_STREAM;
import java.util.stream.StreamSupport;
#endif
#if SPLIT_ITERATOR_FEATURE
import speiger.src.collections.PACKAGE.collections.SPLIT_ITERATOR;
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
#endif
import speiger.src.collections.utils.SanityChecks;
#if TYPE_OBJECT
@@ -487,7 +489,8 @@ public class IMMUTABLE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_T
throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + data.length);
}
#if PRIMITIVES
#if SPLIT_ITERATOR_FEATURE
#if PRIMITIVES && STREAM_FEATURE
/**
* Returns a Java-Type-Specific Stream to reduce boxing/unboxing.
* @return a Stream of the closest java type
@@ -505,6 +508,7 @@ public class IMMUTABLE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_T
@Override
public SPLIT_ITERATOR KEY_GENERIC_TYPE spliterator() { return SPLIT_ITERATORS.createArraySplititerator(data, data.length, 16464); }
#endif
private class LIST_ITER implements LIST_ITERATOR KEY_GENERIC_TYPE {
int index;
@@ -2,10 +2,14 @@ package speiger.src.collections.PACKAGE.utils;
import java.util.Collection;
import java.util.List;
#if IARRAY_FEATURE
import java.util.Objects;
#endif
import java.util.Random;
import java.util.RandomAccess;
#if IARRAY_FEATURE || TYPE_OBJECT
import java.util.function.Consumer;
#endif
#if PRIMITIVES
import java.nio.JAVA_BUFFER;
#endif
@@ -17,7 +21,9 @@ import speiger.src.collections.PACKAGE.functions.CONSUMER;
import speiger.src.collections.PACKAGE.lists.ABSTRACT_LIST;
import speiger.src.collections.PACKAGE.lists.LIST;
import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
#if IARRAY_FEATURE
import speiger.src.collections.PACKAGE.utils.ARRAYS;
#endif
import speiger.src.collections.utils.SanityChecks;
/**
@@ -60,7 +66,11 @@ public class LISTS
* @return a synchronized list wrapper. If the list is implementing RandomAccess or IARRAY that is also transferred. If the List already a synchronized wrapper then it just returns itself.
*/
public static GENERIC_KEY_BRACES LIST KEY_GENERIC_TYPE synchronize(LIST KEY_GENERIC_TYPE l) {
#if IARRAY_FEATURE
return l instanceof SynchronizedList ? l : (l instanceof IARRAY ? new SynchronizedArrayListBRACES(l) : (l instanceof RandomAccess ? new SynchronizedRandomAccessListBRACES(l) : new SynchronizedListBRACES(l)));
#else
return l instanceof SynchronizedList ? l : (l instanceof RandomAccess ? new SynchronizedRandomAccessListBRACES(l) : new SynchronizedListBRACES(l));
#endif
}
/**
@@ -71,7 +81,11 @@ public class LISTS
* @return a synchronized list wrapper. If the list is implementing RandomAccess or IARRAY that is also transferred. If the List already a synchronized wrapper then it just returns itself.
*/
public static GENERIC_KEY_BRACES LIST KEY_GENERIC_TYPE synchronize(LIST KEY_GENERIC_TYPE l, Object mutex) {
#if IARRAY_FEATURE
return l instanceof SynchronizedList ? l : (l instanceof IARRAY ? new SynchronizedArrayListBRACES(l, mutex) : (l instanceof RandomAccess ? new SynchronizedRandomAccessListBRACES(l, mutex) : new SynchronizedListBRACES(l, mutex)));
#else
return l instanceof SynchronizedList ? l : (l instanceof RandomAccess ? new SynchronizedRandomAccessListBRACES(l, mutex) : new SynchronizedListBRACES(l, mutex));
#endif
}
/**
@@ -92,6 +106,7 @@ public class LISTS
*/
public static GENERIC_KEY_BRACES LIST KEY_GENERIC_TYPE reverse(LIST KEY_GENERIC_TYPE list) {
int size = list.size();
#if IARRAY_FEATURE
if(list instanceof IARRAY) {
IARRAY KEY_GENERIC_TYPE array = (IARRAY KEY_GENERIC_TYPE)list;
#if TYPE_OBJECT
@@ -106,6 +121,7 @@ public class LISTS
return list;
#endif
}
#endif
if(list instanceof RandomAccess) {
for (int i = 0, mid = size >> 1, j = size - 1; i < mid; i++, j--) {
KEY_TYPE t = list.GET_KEY(i);
@@ -143,6 +159,7 @@ public class LISTS
*/
public static GENERIC_KEY_BRACES LIST KEY_GENERIC_TYPE shuffle(LIST KEY_GENERIC_TYPE list, Random random) {
int size = list.size();
#if IARRAY_FEATURE
if(list instanceof IARRAY) {
IARRAY KEY_GENERIC_TYPE array = (IARRAY KEY_GENERIC_TYPE)list;
#if TYPE_OBJECT
@@ -164,7 +181,8 @@ public class LISTS
#endif
return list;
}
for(int i = list.size(); i-- != 0;) {
#endif
for(int i = size; i-- != 0;) {
int p = random.nextInt(i + 1);
KEY_TYPE t = list.GET_KEY(i);
list.set(i, list.GET_KEY(p));
@@ -231,6 +249,7 @@ public class LISTS
public SingletonList KEY_GENERIC_TYPE copy() { return new SingletonListBRACES(element); }
}
#if IARRAY_FEATURE
private static class SynchronizedArrayList KEY_GENERIC_TYPE extends SynchronizedList KEY_GENERIC_TYPE implements IARRAY KEY_GENERIC_TYPE
{
IARRAY KEY_GENERIC_TYPE l;
@@ -271,6 +290,7 @@ public class LISTS
}
}
#endif
private static class SynchronizedRandomAccessList KEY_GENERIC_TYPE extends SynchronizedList KEY_GENERIC_TYPE implements RandomAccess
{
SynchronizedRandomAccessList(LIST KEY_GENERIC_TYPE l) {