15 Commits
Author SHA1 Message Date
Speiger 4dd3a4a6e8 0.8.0 Release 2022-12-20 09:33:26 +01:00
Speiger efd29bbe7e First draft of the 0.8.0 patch. 2022-12-19 16:03:43 +01:00
Speiger 96458bd8b6 Changes:
- Added: RandomGenerator support (Java17), though requires self
compilation
- Added: Optimizations for HashUtils next power of function.
- Added: toArray() now returns a cached empty array if the collection is
empty.
- Added: toArray function for AsyncBuilder
- Updated: SCG to version 1.2.2
2022-12-16 18:17:51 +01:00
Speiger 477f3c9f40 Implemented ForEachIndexed into all collections 2022-12-16 13:03:28 +01:00
Speiger 3f6e7fbb88 Added forEachIndexed 2022-12-15 20:08:33 +01:00
Speiger 5650c6e69b Fixed tests don't force generate 2022-12-15 18:28:00 +01:00
Speiger 61df32b7b2 Fixed unit tests and java 8 incompat. 2022-12-15 18:10:59 +01:00
Speiger 859d00da16 Fixed Java9 or newer issues. 2022-12-15 17:13:34 +01:00
Speiger 9df95c0fc3 Supplier now uses javas function name. Tests will still fail. 2022-12-15 16:26:05 +01:00
Speiger d6d2c0a396 Changed that function names are closer to javas names. 2022-12-15 16:07:44 +01:00
Speiger 127eb71968 Massive refactor.
-Changed: Classes that used Primitive Collections Functions now use Java functions if possible to increase compat.
-Changed: Started that functions go closer to javas naming sceme.
2022-12-14 18:32:04 +01:00
Speiger 6005d0fd39 Updated SCG to version 1.2.1
This fixes that all expressions are supported.
2022-12-13 13:34:11 +01:00
Speiger 290e626f07 Updated to SCG 1.2.0 2022-12-13 13:07:24 +01:00
Speiger e30d011273 Fixed Unit Test and Added putIfAbsentTest 2022-12-08 10:40:21 +01:00
Speiger 4c52636c23 Fixed Unit Tests 2022-12-07 08:22:45 +01:00
59 changed files with 1256 additions and 783 deletions
+11 -1
View File
@@ -1,14 +1,24 @@
# Changelog of versions # Changelog of versions
### Version 0.7.1 (Unreleased) ### Version 0.8.0
- Added: ISizeProvider interface (Optimization Helper) - Added: ISizeProvider interface (Optimization Helper)
- Added: ISizeProvider into most Iterable implementations (Distinct/Filter/FlatMap/ArrayFlatMap don't support it, for obvious reasons) - Added: ISizeProvider into most Iterable implementations (Distinct/Filter/FlatMap/ArrayFlatMap don't support it, for obvious reasons)
- Added: ToArray function into Iterable which uses ISizeProvider to reduce overhead of duplicating arrays. - Added: ToArray function into Iterable which uses ISizeProvider to reduce overhead of duplicating arrays.
- Added: Functions that have the same type, Int2IntFunction as example, have now a identity function.
- Added: Functions of a BooleanValue have now alwaysTrue/False function.
- Added: ForEachIndexed for all Iterable implementations
- Added: RandomGenerator support (Java17), though requires self compilation
- Added: Optimizations for HashUtils next power of function.
- Added: toArray() now returns a cached empty array if the collection is empty.
- Added: toArray function for AsyncBuilder
- Added: Modularization to the library where feature can be disabled as needed. (Requires Self-Compilation)
- Fixed: putIfAbsent now replaces defaultValues - Fixed: putIfAbsent now replaces defaultValues
- Fixed: OpenHashSet/Map and their Custom Variants no longer rely on List implementations. - Fixed: OpenHashSet/Map and their Custom Variants no longer rely on List implementations.
- Fixed: ObjectCopyOnWriteList.of did create a ObjectArrayList instead of the CopyOnWrite variant. - Fixed: ObjectCopyOnWriteList.of did create a ObjectArrayList instead of the CopyOnWrite variant.
- Removed: BooleanSet and Maps that start with a Boolean classes since they can not be used anyways. - Removed: BooleanSet and Maps that start with a Boolean classes since they can not be used anyways.
- Breaking Change: Function classes now use the "apply/applyAs/test" format from Java itself, instead of the "get" format. This cleans up a lot of things. But will break existing function class implementations - Breaking Change: Function classes now use the "apply/applyAs/test" format from Java itself, instead of the "get" format. This cleans up a lot of things. But will break existing function class implementations
- Breaking Change: Classes that used PrimitiveCollection functions now default to java functions where applicable, this is to increase compat.
- Breaking Change: Some function classes now get closer to javas terms. (Predicate/UnaryOperator etc)
### Version 0.7.0 ### Version 0.7.0
- Added: Over 11 Million Unit Tests to this library to ensure quality. - Added: Over 11 Million Unit Tests to this library to ensure quality.
+41
View File
@@ -0,0 +1,41 @@
### Extra Features
Primitive Collections comes with a few extra features that are disabled by default.
These will be enabled as soon they become relevant or never at all.
But some of these can be already unlocked when the target version changes.
If you compile the library for yourself you will automatically gain access to said features.
### Java17 Exclusive Features
Java17 has some new features that can sadly not really be back-ported but the library still supports them if it is compiled with java17
- RandomGenerator: Java17 has added [RandomGenerator.class](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/random/RandomGenerator.html).
This allows to use custom random implementations without having to re-implement them yourselves.
### ModuleSettings
Primitive Collections is a huge library.
But maybe you only use like 5-10 different classes.
Normally you would use tools like "Proguard" to get rid of classes that you don't use.
But since a lot of classes have dependencies on each other this would only do so much.
This is where the [ModuleSettings](ModuleSettings.json) come into play.
It allows you to turn of implementations as you wish and adjusts the code that everything still works.
There is 3 layers of control inside of the ModuleSettings.
- Modules directly at the top that turn off everything.
- Type Specific configurations, where you can for example turn of everything thats "Long" based.
- And then there is each type specific module settings.
Allowing for greater control without having to edit hundreds of lines of code.
On top of that:
Any Setting that isn't "Present" is counted as "Enabled".
So if you want to disable just 1 thing you can keep that 1 thing and delete the rest of the Setting.
It will still work as the same.
The default settings just come with everything so you can see what is controllable.
How to compile the Code with the ModuleSettings enabled:
```
/gradlew.bat generateLimitSource build -x test
```
+8
View File
@@ -17,6 +17,10 @@ Benchmarks can be found here: [[Charts]](https://github.com/Speiger/Primitive-Co
[Here](features.md) you find a set of features added to Primitive Collections. [Here](features.md) you find a set of features added to Primitive Collections.
These are designed to improve performance or to provide Quality of Life. These are designed to improve performance or to provide Quality of Life.
[Here](EXTRAS.md) you also find features that can be used when you compile the library for yourself.
These features are not used by default to have a wider range of compat, or require self compilation.
Such as pruning classes that are not needed in your code.
## Main Features: ## Main Features:
- ArrayLists / LinkedLists / CopyOnWriteLists - ArrayLists / LinkedLists / CopyOnWriteLists
- HashSets/Maps (Linked & HashControl) - HashSets/Maps (Linked & HashControl)
@@ -71,7 +75,11 @@ Please if you want to contribute follow the [Rule-Sheet](RuleSheet.md). It keeps
# How to Build # How to Build
The SourceCode can be generated via: The SourceCode can be generated via:
```
/gradlew.bat generateSource /gradlew.bat generateSource
```
to generate SourceCode and build the jar: to generate SourceCode and build the jar:
```
/gradlew.bat build /gradlew.bat build
```
+10 -2
View File
@@ -19,7 +19,7 @@ repositories {
} }
archivesBaseName = 'Primitive Collections' archivesBaseName = 'Primitive Collections'
version = '0.7.0'; version = '0.8.0';
sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = JavaVersion.current(); sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = JavaVersion.current();
@@ -46,7 +46,7 @@ configurations {
dependencies { dependencies {
builderImplementation 'com.google.code.gson:gson:2.10' builderImplementation 'com.google.code.gson:gson:2.10'
builderImplementation 'de.speiger:Simple-Code-Generator:1.1.4' builderImplementation 'de.speiger:Simple-Code-Generator:1.2.2'
testImplementation 'junit:junit:4.12' testImplementation 'junit:junit:4.12'
testImplementation 'com.google.guava:guava-testlib:31.0.1-jre' testImplementation 'com.google.guava:guava-testlib:31.0.1-jre'
@@ -83,6 +83,14 @@ task generateTestSource(type: JavaExec) {
args = ['tests', 'silent'] args = ['tests', 'silent']
} }
task generateLimitSource(type: JavaExec) {
group = 'internal'
description = 'Builds the Sourcecode with the ModuleSettings.json applied'
classpath = sourceSets.builder.runtimeClasspath
main = 'speiger.src.builder.PrimitiveCollectionsBuilder'
args = ['silent', 'load']
}
task javadocJar(type: Jar) { task javadocJar(type: Jar) {
from javadoc from javadoc
classifier = 'javadoc' classifier = 'javadoc'
@@ -114,7 +114,7 @@ public enum ClassType
public boolean needsCustomJDKType() public boolean needsCustomJDKType()
{ {
return this == BYTE || this == SHORT || this == CHAR || this == FLOAT; return this == BOOLEAN || this == BYTE || this == SHORT || this == CHAR || this == FLOAT;
} }
public boolean needsCast() public boolean needsCast()
@@ -1,553 +0,0 @@
package speiger.src.builder;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.function.UnaryOperator;
import speiger.src.builder.mappers.ArgumentMapper;
import speiger.src.builder.mappers.IMapper;
import speiger.src.builder.mappers.InjectMapper;
import speiger.src.builder.mappers.LineMapper;
import speiger.src.builder.mappers.SimpleMapper;
import speiger.src.builder.processor.TemplateProcess;
@SuppressWarnings("javadoc")
public class GlobalVariables
{
List<IMapper> operators = new ArrayList<>();
Set<String> flags = new LinkedHashSet<>();
ClassType type;
ClassType valueType;
public GlobalVariables(ClassType type, ClassType subType)
{
this.type = type;
valueType = subType;
}
public GlobalVariables createVariables()
{
addSimpleMapper("VALUE_PACKAGE", valueType.getPathType());
addSimpleMapper("PACKAGE", type.getPathType());
addSimpleMapper("CLASS_TYPE", type.getClassType());
addSimpleMapper("CLASS_VALUE_TYPE", valueType.getClassValueType());
addSimpleMapper("KEY_TYPE", type.getKeyType());
addSimpleMapper("KEY_OBJECT_TYPE", type.isObject() ? "Object" : type.getKeyType());
addSimpleMapper("KEY_STRING_TYPE", type.isObject() ? "String" : type.getKeyType());
addSimpleMapper("KEY_SPECIAL_TYPE", type.isObject() ? "E" : type.getKeyType());
addSimpleMapper("CLASS_OBJECT_TYPE", type.getClassType());
addSimpleMapper("CLASS_OBJECT_VALUE_TYPE", valueType.getClassValueType());
addSimpleMapper("CLASS_STRING_TYPE", type.isObject() ? "String" : type.getClassType());
addSimpleMapper("CLASS_STRING_VALUE_TYPE", valueType.isObject() ? "String" : valueType.getClassValueType());
addSimpleMapper("VALUE_TYPE", valueType.getValueType());
addSimpleMapper("VALUE_OBJECT_TYPE", valueType.isObject() ? "Object" : valueType.getValueType());
addSimpleMapper("VALUE_STRING_TYPE", valueType.isObject() ? "String" : valueType.getValueType());
addSimpleMapper("VALUE_SPECIAL_TYPE", valueType.isObject() ? "E" : valueType.getKeyType());
addSimpleMapper("KEY_JAVA_TYPE", type.getCustomJDKType().getKeyType());
addSimpleMapper("VALUE_JAVA_TYPE", type.getCustomJDKType().getKeyType());
addSimpleMapper("EMPTY_KEY_VALUE", type.getEmptyValue());
addSimpleMapper("EMPTY_VALUE", valueType.getEmptyValue());
addSimpleMapper("INVALID_KEY_VALUE", type.getInvalidValue());
addSimpleMapper("INVALID_VALUE", valueType.getInvalidValue());
addSimpleMapper(" KEY_STRING_GENERIC_TYPE", type.isObject() ? "<String>" : "");
addSimpleMapper(" VALUE_STRING_GENERIC_TYPE", valueType.isObject() ? "<String>" : "");
addSimpleMapper(" KEY_VALUE_STRING_GENERIC_TYPE", type.isObject() ? (valueType.isObject() ? "<String, String>" : "<String>") : (valueType.isObject() ? "<String>" : ""));
addSimpleMapper(" KEY_GENERIC_TYPE", type.isObject() ? "<"+type.getKeyType()+">" : "");
addSimpleMapper(" KEY_KEY_GENERIC_TYPE", type.isObject() ? "<"+type.getKeyType()+", "+type.getKeyType()+">" : "");
addSimpleMapper(" KEY_CLASS_GENERIC_TYPE", type.isObject() ? "<"+type.getClassType()+">" : "");
addSimpleMapper(" VALUE_GENERIC_TYPE", valueType.isObject() ? "<"+valueType.getValueType()+">" : "");
addSimpleMapper(" VALUE_VALUE_GENERIC_TYPE", valueType.isObject() ? "<"+valueType.getValueType()+", "+valueType.getValueType()+">" : "");
addSimpleMapper(" VALUE_CLASS_GENERIC_TYPE", valueType.isObject() ? "<"+valueType.getClassValueType()+">" : "");
addSimpleMapper(" KEY_VALUE_GENERIC_TYPE", type.isObject() ? (valueType.isObject() ? "<"+type.getKeyType()+", "+valueType.getValueType()+">" : "<"+type.getKeyType()+">") : (valueType.isObject() ? "<"+valueType.getValueType()+">" : ""));
addSimpleMapper(" KEY_VALUE_VALUE_GENERIC_TYPE", type.isObject() ? (valueType.isObject() ? "<"+type.getKeyType()+", "+valueType.getValueType()+", "+valueType.getValueType()+">" : "<"+type.getKeyType()+">") : (valueType.isObject() ? "<"+valueType.getValueType()+", "+valueType.getValueType()+">" : ""));
addInjectMapper(" KEY_VALUE_SPECIAL_GENERIC_TYPE", type.isObject() ? (valueType.isObject() ? "<"+type.getKeyType()+", "+valueType.getValueType()+", %s>" : "<"+type.getKeyType()+", %s>") : (valueType.isObject() ? "<"+valueType.getValueType()+", %s>" : "<%s>")).setBraceType("<>").removeBraces();
addSimpleMapper(" NO_GENERIC_TYPE", type.isObject() ? "<?>" : "");
addSimpleMapper(" NO_KV_GENERIC_TYPE", type.isObject() ? (valueType.isObject() ? "<?, ?>" : "<?>") : valueType.isObject() ? "<?>" : "");
addSimpleMapper(" KEY_COMPAREABLE_TYPE", type.isObject() ? "<"+type.getKeyType()+" extends Comparable<T>>" : "");
addSimpleMapper(" KEY_SUPER_GENERIC_TYPE", type.isObject() ? "<? super "+type.getKeyType()+">" : "");
addSimpleMapper(" VALUE_SUPER_GENERIC_TYPE", valueType.isObject() ? "<? super "+valueType.getValueType()+">" : "");
addSimpleMapper(" KEY_VALUE_SUPER_GENERIC_TYPE", type.isObject() ? (valueType.isObject() ? "<? super "+type.getKeyType()+", ? super "+valueType.getValueType()+">" : "<? super "+type.getKeyType()+">") : (valueType.isObject() ? "<? super "+valueType.getValueType()+">" : ""));
addSimpleMapper(" KEY_UNKNOWN_GENERIC_TYPE", type.isObject() ? "<? extends "+type.getKeyType()+">" : "");
addSimpleMapper(" VALUE_UNKNOWN_GENERIC_TYPE", valueType.isObject() ? "<? extends "+valueType.getValueType()+">" : "");
addSimpleMapper(" KEY_VALUE_UNKNOWN_GENERIC_TYPE", type.isObject() ? (valueType.isObject() ? "<? extends "+type.getKeyType()+", ? extends "+valueType.getValueType()+">" : "<? extends "+type.getKeyType()+">") : (valueType.isObject() ? "<? extends "+valueType.getValueType()+">" : ""));
addSimpleMapper(" KEY_ENUM_VALUE_GENERIC_TYPE", type.isObject() ? (valueType.isObject() ? "<"+type.getKeyType()+" extends Enum<"+type.getKeyType()+">, "+valueType.getValueType()+">" : "<"+type.getKeyType()+" extends Enum<"+type.getKeyType()+">>") : (valueType.isObject() ? "<"+valueType.getValueType()+">" : ""));
addSimpleMapper(" KEY_VALUE_ENUM_GENERIC_TYPE", type.isObject() ? (valueType.isObject() ? "<"+type.getKeyType()+", "+valueType.getValueType()+" extends Enum<"+valueType.getValueType()+">>" : "<"+type.getKeyType()+">") : (valueType.isObject() ? "<"+valueType.getValueType()+" extends Enum<"+valueType.getValueType()+">>" : ""));
addInjectMapper(" KEY_SPECIAL_GENERIC_TYPE", type.isObject() ? "<%s>" : "").removeBraces().setBraceType("<>");
addInjectMapper(" VALUE_SPECIAL_GENERIC_TYPE", valueType.isObject() ? "<%s>" : "").removeBraces().setBraceType("<>");
addInjectMapper(" KSK_GENERIC_TYPE", type.isObject() ? "<%s, "+type.getKeyType()+">" : "<%s>").removeBraces().setBraceType("<>");
addInjectMapper(" KKS_GENERIC_TYPE", type.isObject() ? "<"+type.getKeyType()+", %s>" : "<%s>").removeBraces().setBraceType("<>");
addArgumentMapper(" KSS_GENERIC_TYPE", type.isObject() ? "<%1$s, %2$s>" : "<%2$s>").removeBraces().setBraceType("<>");
addInjectMapper(" VSV_GENERIC_TYPE", valueType.isObject() ? "<%s, "+valueType.getValueType()+">" : "<%s>").removeBraces().setBraceType("<>");
addInjectMapper(" VVS_GENERIC_TYPE", valueType.isObject() ? "<"+valueType.getValueType()+", %s>" : "<%s>").removeBraces().setBraceType("<>");
addArgumentMapper(" VSS_GENERIC_TYPE", valueType.isObject() ? "<%1$s, %2$s>" : "<%2$s>").removeBraces().setBraceType("<>");
addSimpleMapper(" GENERIC_KEY_BRACES", type.isObject() ? " <"+type.getKeyType()+">" : "");
addSimpleMapper(" GENERIC_VALUE_BRACES", valueType.isObject() ? " <"+valueType.getValueType()+">" : "");
addInjectMapper(" GENERIC_SPECIAL_KEY_BRACES", type.isObject() ? " <%s>" : "").removeBraces().setBraceType("<>");
addInjectMapper(" GENERIC_SPECIAL_VALUE_BRACES", valueType.isObject() ? " <%s>" : "").removeBraces().setBraceType("<>");
addSimpleMapper(" GENERIC_KEY_ENUM_VALUE_BRACES", type.isObject() ? (valueType.isObject() ? " <"+type.getKeyType()+" extends Enum<"+type.getKeyType()+">, "+valueType.getValueType()+">" : " <"+type.getKeyType()+" extends Enum<"+type.getKeyType()+">>") : (valueType.isObject() ? " <"+valueType.getValueType()+">" : ""));
addInjectMapper(" GENERIC_KEY_SPECIAL_BRACES", type.isObject() ? " <"+type.getKeyType()+", %s>" : " <%s>").removeBraces().setBraceType("<>");
addInjectMapper(" GENERIC_VALUE_SPECIAL_BRACES", valueType.isObject() ? " <"+valueType.getKeyType()+", %s>" : " <%s>").removeBraces().setBraceType("<>");
addSimpleMapper(" GENERIC_KEY_VALUE_BRACES", type.isObject() ? (valueType.isObject() ? " <"+type.getKeyType()+", "+valueType.getValueType()+">" : " <"+type.getKeyType()+">") : (valueType.isObject() ? " <"+valueType.getValueType()+">" : ""));
addSimpleMapper(" COMPAREABLE_KEY_BRACES", type.isObject() ? " <"+type.getKeyType()+" extends Comparable<T>>" : "");
addSimpleMapper("KV_BRACES", type.isObject() || valueType.isObject() ? "<>" : "");
addSimpleMapper("VALUE_BRACES", valueType.isObject() ? "<>" : "");
addSimpleMapper("BRACES", type.isObject() ? "<>" : "");
if(type.needsCustomJDKType())
{
addSimpleMapper("JAVA_TYPE", type.getCustomJDKType().getKeyType());
addSimpleMapper("SANITY_CAST", "castTo"+type.getFileType());
}
addSimpleMapper("JAVA_CLASS", type.getCustomJDKType().getClassType());
if(valueType.needsCustomJDKType())
{
addSimpleMapper("SANITY_CAST_VALUE", "castTo"+valueType.getFileType());
}
addComment("@ArrayType", "@param <%s> the type of array that the operation should be applied");
addComment("@Type", "@param <%s> the type of elements maintained by this Collection");
addValueComment("@ValueArrayType", "@param <%s> the type of array that the operation should be applied");
addValueComment("@ValueType", "@param <%s> the type of elements maintained by this Collection");
addAnnontion("@PrimitiveOverride", "@Override");
addSimpleMapper("@PrimitiveDoc", "");
addAnnontion("@Primitive", "@Deprecated");
addValueAnnontion("@ValuePrimitiveOverride", "@Override");
addValueAnnontion("@ValuePrimitive", "@Deprecated");
return this;
}
public GlobalVariables createHelperVariables()
{
createHelperVars(type, false, "KEY");
createHelperVars(valueType, true, "VALUE");
return this;
}
private void createHelperVars(ClassType type, boolean value, String fix)
{
addArgumentMapper("EQUALS_"+fix+"_TYPE", "Objects.equals(%2$s, "+(type.isObject() ? "%1$s" : fix+"_TO_OBJ(%1$s)")+")").removeBraces();
addInjectMapper(fix+"_EQUALS_NOT_NULL", type.getComparableValue()+" != "+(type.isPrimitiveBlocking() || type.needsCast() ? type.getEmptyValue() : "0")).removeBraces();
addInjectMapper(fix+"_EQUALS_NULL", type.getComparableValue()+" == "+(type.isPrimitiveBlocking() || type.needsCast() ? type.getEmptyValue() : "0")).removeBraces();
addArgumentMapper(fix+"_EQUALS_NOT", type.getEquals(true)).removeBraces();
addArgumentMapper(fix+"_EQUALS", type.getEquals(false)).removeBraces();
addSimpleMapper("FILE_"+fix+"_TYPE", type.getFileType());
addArgumentMapper("COMPAREABLE_TO_"+fix, type.isObject() ? "((Comparable<"+type.getKeyType(value)+">)%1$s).compareTo(("+type.getKeyType(value)+")%2$s)" : type.getClassType(value)+".compare(%1$s, %2$s)").removeBraces();
addArgumentMapper("COMPARE_TO_"+fix, type.isObject() ? "%1$s.compareTo(%2$s)" : type.getClassType(value)+".compare(%1$s, %2$s)").removeBraces();
addInjectMapper(fix+"_TO_OBJ", type.isObject() ? "%s" : type.getClassType(value)+".valueOf(%s)").removeBraces();
addInjectMapper("OBJ_TO_"+fix, type.isObject() ? "%s" : "%s."+type.getKeyType(value)+"Value()").removeBraces();
addInjectMapper("CLASS_TO_"+fix, type.isObject() ? "("+type.getKeyType(value)+")%s" : "(("+type.getClassType(value)+")%s)."+type.getKeyType(value)+"Value()").removeBraces();
addInjectMapper(fix+"_TO_HASH", type.isObject() ? "Objects.hashCode(%s)" : type.getClassType(value)+".hashCode(%s)").removeBraces();
addInjectMapper(fix+"_TO_STRING", type.isObject() ? "Objects.toString(%s)" : type.getClassType(value)+".toString(%s)").removeBraces();
addSimpleMapper("CAST_"+fix+"_ARRAY ", type.isObject() ? "("+fix+"_TYPE[])" : "");
addSimpleMapper("EMPTY_"+fix+"_ARRAY", type.isObject() ? "("+fix+"_TYPE[])ARRAYS.EMPTY_ARRAY" : "ARRAYS.EMPTY_ARRAY");
addInjectMapper("NEW_"+fix+"_ARRAY", type.isObject() ? "("+fix+"_TYPE[])new Object[%s]" : "new "+fix+"_TYPE[%s]").removeBraces();
addInjectMapper("NEW_SPECIAL_"+fix+"_ARRAY", type.isObject() ? "(E[])new Object[%s]" : "new "+fix+"_TYPE[%s]").removeBraces();
if(value) addInjectMapper("NEW_CLASS_VALUE_ARRAY", type.isObject() ? "(CLASS_VALUE_TYPE[])new Object[%s]" : "new CLASS_VALUE_TYPE[%s]").removeBraces();
else addInjectMapper("NEW_CLASS_ARRAY", type.isObject() ? "(CLASS_TYPE[])new Object[%s]" : "new CLASS_TYPE[%s]").removeBraces();
}
public GlobalVariables createPreFunctions()
{
addSimpleMapper("ENTRY_SET", type.getFileType().toLowerCase()+"2"+valueType.getFileType()+"EntrySet");
return this;
}
public GlobalVariables createClassTypes()
{
addSimpleMapper("JAVA_PREDICATE", type.isPrimitiveBlocking() ? "" : type.getCustomJDKType().getFileType()+"Predicate");
addSimpleMapper("JAVA_CONSUMER", type.isPrimitiveBlocking() ? "" : "java.util.function."+type.getCustomJDKType().getFileType()+"Consumer");
addSimpleMapper("JAVA_SUPPLIER", type.isPrimitiveBlocking() ? "" : "java.util.function."+type.getCustomJDKType().getFileType()+"Supplier");
addSimpleMapper("JAVA_FUNCTION", type.getFunctionClass(valueType));
addSimpleMapper("JAVA_BINARY_OPERATOR", type == ClassType.BOOLEAN ? "" : (type.isObject() ? "java.util.function.BinaryOperator" : "java.util.function."+type.getCustomJDKType().getFileType()+"BinaryOperator"));
addSimpleMapper("JAVA_UNARY_OPERATOR", type.isObject() ? "BinaryOperator" : type == ClassType.BOOLEAN ? "" : type.getCustomJDKType().getFileType()+"UnaryOperator");
addSimpleMapper("JAVA_SPLIT_ITERATOR", type.isPrimitiveBlocking() ? "Spliterator" : "Of"+type.getCustomJDKType().getFileType());
addSimpleMapper("JAVA_STREAM", type.isPrimitiveBlocking() ? "" : type.getCustomJDKType().getFileType()+"Stream");
addSimpleMapper("JAVA_BUFFER", type.getFileType()+"Buffer");
//Final Classes
addClassMapper("ARRAY_LIST", "ArrayList");
addAbstractMapper("COPY_ON_WRITE_LIST", "CopyOnWrite%sArrayList");
addClassMapper("ASYNC_BUILDER", "AsyncBuilder");
addClassMapper("LINKED_LIST", "LinkedList");
addAbstractMapper("IMMUTABLE_LIST", "Immutable%sList");
addClassMapper("ARRAY_FIFO_QUEUE", "ArrayFIFOQueue");
addClassMapper("ARRAY_PRIORITY_QUEUE", "ArrayPriorityQueue");
addClassMapper("HEAP_PRIORITY_QUEUE", "HeapPriorityQueue");
addClassMapper("LINKED_CUSTOM_HASH_SET", "LinkedOpenCustomHashSet");
addClassMapper("LINKED_HASH_SET", "LinkedOpenHashSet");
addAbstractMapper("IMMUTABLE_HASH_SET", "Immutable%sOpenHashSet");
addClassMapper("CUSTOM_HASH_SET", "OpenCustomHashSet");
addClassMapper("HASH_SET", "OpenHashSet");
addAbstractBiMapper("IMMUTABLE_HASH_MAP", "Immutable%sOpenHashMap", "2");
addBiClassMapper("LINKED_CUSTOM_HASH_MAP", "LinkedOpenCustomHashMap", "2");
addBiClassMapper("LINKED_HASH_MAP", "LinkedOpenHashMap", "2");
addBiClassMapper("CUSTOM_HASH_MAP", "OpenCustomHashMap", "2");
addBiClassMapper("CONCURRENT_HASH_MAP", "ConcurrentOpenHashMap", "2");
addBiClassMapper("AVL_TREE_MAP", "AVLTreeMap", "2");
addBiClassMapper("RB_TREE_MAP", "RBTreeMap", "2");
addFunctionValueMappers("LINKED_ENUM_MAP", valueType.isObject() ? "LinkedEnum2ObjectMap" : "LinkedEnum2%sMap");
addFunctionValueMappers("ENUM_MAP", valueType.isObject() ? "Enum2ObjectMap" : "Enum2%sMap");
addBiClassMapper("HASH_MAP", "OpenHashMap", "2");
addBiClassMapper("ARRAY_MAP", "ArrayMap", "2");
addBiClassMapper("IMMUTABLE_PAIR", "ImmutablePair", "");
addBiClassMapper("MUTABLE_PAIR", "MutablePair", "");
addClassMapper("RB_TREE_SET", "RBTreeSet");
addClassMapper("AVL_TREE_SET", "AVLTreeSet");
addClassMapper("ARRAY_SET", "ArraySet");
addAbstractBiMapper("SIMPLE_TEST_MAP", "Test%sMap", "2");
//Final UnitTest Classes
addAbstractMapper("MINIMAL_COLLECTION", "Minimal%sCollection");
addAbstractMapper("MINIMAL_SET", "Minimal%sSet");
addAbstractMapper("ABSTRACT_CONTAINER_TESTER", "Abstract%sContainerTester");
addAbstractMapper("ABSTRACT_COLLECTION_TESTER", "Abstract%sCollectionTester");
addAbstractMapper("ABSTRACT_QUEUE_TESTER", "Abstract%sQueueTester");
addAbstractMapper("ABSTRACT_LIST_INDEX_OF_TESTER", "Abstract%sListIndexOfTester");
addAbstractMapper("ABSTRACT_LIST_TESTER", "Abstract%sListTester");
addAbstractMapper("ABSTRACT_SET_TESTER", "Abstract%sSetTester");
addAbstractMapper("ABSTRACT_ITERATOR_TESTER", "Abstract%sIteratorTester");
addAbstractBiMapper("ABSTRACT_MAP_TESTER", "Abstract%sMapTester", "2");
addClassMapper("LIST_ITERATOR_TESTER", "ListIteratorTester");
addClassMapper("BIDIRECTIONAL_ITERATOR_TESTER", "BidirectionalteratorTester");
addClassMapper("ITERATOR_TESTER", "IteratorTester");
addClassMapper("COLLECTION_TEST_BUILDER", "CollectionTestSuiteBuilder");
addClassMapper("DEQUEUE_TEST_BUILDER", "DequeueTestSuiteBuilder");
addClassMapper("QUEUE_TEST_BUILDER", "QueueTestSuiteBuilder");
addClassMapper("LIST_TEST_BUILDER", "ListTestSuiteBuilder");
addClassMapper("ORDERED_SET_TEST_BUILDER", "OrderedSetTestSuiteBuilder");
addClassMapper("SORTED_SET_TEST_BUILDER", "SortedSetTestSuiteBuilder");
addClassMapper("NAVIGABLE_SET_TEST_BUILDER", "NavigableSetTestSuiteBuilder");
addClassMapper("SET_TEST_BUILDER", "SetTestSuiteBuilder");
addAbstractBiMapper("NAVIGABLE_MAP_TEST_BUILDER", "%sNavigableMapTestSuiteBuilder", "2");
addAbstractBiMapper("SORTED_MAP_TEST_BUILDER", "%sSortedMapTestSuiteBuilder", "2");
addAbstractBiMapper("ORDERED_MAP_TEST_BUILDER", "%sOrderedMapTestSuiteBuilder", "2");
addAbstractBiMapper("MAP_TEST_BUILDER", "%sMapTestSuiteBuilder", "2");
addAbstractBiMapper("MAP_CONSTRUCTOR_TESTS", "%sMapConstructorTests", "2");
addClassMapper("COLLECTION_CONSTRUCTOR_TESTS", "CollectionConstructorTests");
addClassMapper("SUB_SORTED_SET_CLASS_GENERATOR", "SortedSetSubsetTestSetGenerator");
addClassMapper("SUB_NAVIGABLE_SET_CLASS_GENERATOR", "NavigableSetSubsetTestSetGenerator");
addClassMapper("LIST_TESTS", "ListTests");
addClassMapper("SET_TESTS", "SetTests");
addClassMapper("QUEUE_TESTS", "QueueTests");
addBiClassMapper("MAP_TESTS", "MapTests", "2");
//Abstract Classes
addAbstractMapper("ABSTRACT_COLLECTION", "Abstract%sCollection");
addAbstractMapper("ABSTRACT_PRIORITY_QUEUE", "Abstract%sPriorityQueue");
addAbstractMapper("ABSTRACT_SET", "Abstract%sSet");
addAbstractMapper("ABSTRACT_LIST", "Abstract%sList");
addAbstractBiMapper("ABSTRACT_MAP", "Abstract%sMap", "2");
addClassMapper("SUB_LIST", "SubList");
addAbstractMapper("BASE_TASK", "Base%sTask");
//Helper Classes
addClassMapper("LISTS", "Lists");
addClassMapper("SETS", "Sets");
addClassMapper("COLLECTIONS", "Collections");
addClassMapper("ARRAYS", "Arrays");
addClassMapper("PRIORITY_QUEUES", "PriorityQueues");
addClassMapper("SPLIT_ITERATORS", "Splititerators");
addClassMapper("ITERATORS", "Iterators");
addClassMapper("ITERABLES", "Iterables");
addBiClassMapper("MAPS", "Maps", "2");
addClassMapper("SAMPLE_ELEMENTS", "Samples");
//UnitTest Helper Classes
addClassMapper("HELPERS", "Helpers");
addAbstractMapper("TEST_COLLECTION_GENERATOR", "Test%sCollectionGenerator");
addAbstractMapper("TEST_QUEUE_GENERATOR", "Test%sQueueGenerator");
addAbstractMapper("TEST_LIST_GENERATOR", "Test%sListGenerator");
addAbstractMapper("TEST_NAVIGABLE_SET_GENERATOR", "Test%sNavigableSetGenerator");
addAbstractMapper("TEST_SORTED_SET_GENERATOR", "Test%sSortedSetGenerator");
addAbstractMapper("TEST_ORDERED_SET_GENERATOR", "Test%sOrderedSetGenerator");
addAbstractMapper("TEST_SET_GENERATOR", "Test%sSetGenerator");
addAbstractMapper("SIMPLE_TEST_GENERATOR", "Simple%sTestGenerator");
addAbstractMapper("SIMPLE_QUEUE_TEST_GENERATOR", "Simple%sQueueTestGenerator");
addAbstractBiMapper("SIMPLE_MAP_TEST_GENERATOR", "Simple%sMapTestGenerator", "2");
addAbstractBiMapper("DERIVED_MAP_GENERATORS", "Derived%sMapGenerators", "2");
addAbstractBiMapper("TEST_ORDERED_MAP_GENERATOR", "Test%sOrderedMapGenerator", "2");
addAbstractBiMapper("TEST_SORTED_MAP_GENERATOR", "Test%sSortedMapGenerator", "2");
addAbstractBiMapper("TEST_MAP_GENERATOR", "Test%sMapGenerator", "2");
//Interfaces
addClassMapper("LIST_ITERATOR", "ListIterator");
addClassMapper("BI_ITERATOR", "BidirectionalIterator");
addBiClassMapper("BI_CONSUMER", "Consumer", "");
addClassMapper("BI_TO_OBJECT_CONSUMER", "ObjectConsumer");
addAbstractMapper("BI_FROM_OBJECT_CONSUMER", "Object%sConsumer");
addClassMapper("SPLIT_ITERATOR", "Splititerator");
addClassMapper("ITERATOR", "Iterator");
addClassMapper("ITERABLE", "Iterable");
addClassMapper("COLLECTION", "Collection");
addClassMapper("TO_OBJECT_FUNCTION", "2ObjectFunction");
addBiClassMapper("FUNCTION", "Function", "2");
addClassMapper("LIST_ITER", "ListIter");
addClassMapper("LIST", "List");
addBiClassMapper("NAVIGABLE_MAP", "NavigableMap", "2");
addBiClassMapper("ORDERED_MAP", "OrderedMap", "2");
addBiClassMapper("SORTED_MAP", "SortedMap", "2");
addBiClassMapper("CONCURRENT_MAP", "ConcurrentMap", "2");
addBiClassMapper("MAP", "Map", "2");
addClassMapper("NAVIGABLE_SET", "NavigableSet");
addBiClassMapper("PAIR", "Pair", "");
addClassMapper("PRIORITY_QUEUE", "PriorityQueue");
addClassMapper("PRIORITY_DEQUEUE", "PriorityDequeue");
addClassMapper("PREDICATE", "2BooleanFunction");
addClassMapper("SORTED_SET", "SortedSet");
addClassMapper("ORDERED_SET", "OrderedSet");
addClassMapper("SET", "Set");
addClassMapper("STRATEGY", "Strategy");
addClassMapper("STACK", "Stack");
addClassMapper("SUPPLIER", "Supplier");
addAbstractMapper("SINGLE_UNARY_OPERATOR", "%1$s%1$sUnaryOperator");
addClassMapper("TASK", "Task");
addBiClassMapper("UNARY_OPERATOR", "UnaryOperator", "");
if(type.isObject())
{
if(!valueType.isObject()) addSimpleMapper("VALUE_CONSUMER", valueType.getFileType()+"Consumer");
else addSimpleMapper("VALUE_CONSUMER", "Consumer");
addSimpleMapper("CONSUMER", "Consumer");
addSimpleMapper("IARRAY", "IObjectArray");
}
else
{
if(valueType.isObject())
{
addSimpleMapper("VALUE_CONSUMER", "Consumer");
addSimpleMapper("CONSUMER", type.getFileType()+"Consumer");
}
else addClassMapper("CONSUMER", "Consumer");
addFunctionMappers("IARRAY", "I%sArray");
}
addSimpleMapper("VALUE_COMPARATOR", valueType.isObject() ? "Comparator" : String.format("%sComparator", valueType.getNonFileType()));
addSimpleMapper("COMPARATOR", type.isObject() ? "Comparator" : String.format("%sComparator", type.getNonFileType()));
return this;
}
public GlobalVariables createFunctions()
{
addSimpleMapper("APPLY_KEY_VALUE", type.isObject() ? "apply" : "applyAs"+type.getNonFileType());
addSimpleMapper("APPLY_VALUE", valueType.isObject() ? "apply" : "applyAs"+valueType.getNonFileType());
addSimpleMapper("APPLY_CAST", "applyAs"+type.getCustomJDKType().getNonFileType());
addSimpleMapper("APPLY", type.isObject() ? "apply" : "applyAs"+type.getNonFileType());
addFunctionValueMapper("BULK_MERGE", "mergeAll");
addFunctionValueMappers("COMPUTE_IF_ABSENT", "compute%sIfAbsent");
addFunctionValueMappers("COMPUTE_IF_PRESENT", "compute%sIfPresent");
addFunctionValueMapper("COMPUTE", "compute");
addFunctionMapper("DEQUEUE_LAST", "dequeueLast");
addFunctionMapper("DEQUEUE", "dequeue");
addFunctionMappers("POLL_FIRST_ENTRY_KEY", "pollFirst%sKey");
addFunctionMappers("POLL_LAST_ENTRY_KEY", "pollLast%sKey");
addFunctionMapper("POLL_FIRST_KEY", "pollFirst");
addFunctionMapper("POLL_LAST_KEY", "pollLast");
addFunctionMappers("FIRST_ENTRY_KEY", "first%sKey");
addFunctionValueMappers("FIRST_ENTRY_VALUE", "first%sValue");
addFunctionMapper("FIRST_KEY", "first");
addFunctionMappers("LAST_ENTRY_KEY", "last%sKey");
addFunctionValueMappers("LAST_ENTRY_VALUE", "last%sValue");
addFunctionMappers("ENTRY_KEY", "get%sKey");
addFunctionValueMappers("ENTRY_VALUE", "get%sValue");
addFunctionMappers("KEY_ENTRY", "set%sKey");
addFunctionValueMappers("VALUE_ENTRY", "set%sValue");
addFunctionMapper("GET_KEY", "get");
if(type.isObject()) addFunctionValueMapper("GET_VALUE", valueType.isObject() ? "getObject" : "get");
else addSimpleMapper("GET_VALUE", "get");
addSimpleMapper("GET_JAVA", type.isObject() ? "get" : "getAs"+type.getCustomJDKType().getNonFileType());
addFunctionMapper("LAST_KEY", "last");
addFunctionValueMapper("MERGE", "merge");
addFunctionMapper("NEXT", "next");
addFunctionMapper("PREVIOUS", "previous");
addFunctionMapper("REMOVE_SWAP", "swapRemove");
if(type.isObject()) addFunctionMapper("REMOVE_VALUE", "rem");
else addSimpleMapper("REMOVE_VALUE", "remove");
addFunctionMapper("REMOVE_KEY", "rem");
addFunctionMapper("REMOVE_LAST", "removeLast");
addFunctionMapper("REMOVE", "remove");
addFunctionValueMappers("REPLACE_VALUES", valueType.isObject() ? "replaceObjects" : "replace%ss");
addFunctionMappers("REPLACE", type.isObject() ? "replaceObjects" : "replace%ss");
addFunctionMappers("SORT", "sort%ss");
addFunctionValueMappers("SUPPLY_IF_ABSENT", "supply%sIfAbsent");
addSimpleMapper("VALUE_TEST_VALUE", valueType.isObject() ? "getBoolean" : "get");
addSimpleMapper("TEST_VALUE", type.isObject() ? "getBoolean" : "get");
addSimpleMapper("NEW_STREAM", type.isPrimitiveBlocking() ? "" : type.getCustomJDKType().getKeyType()+"Stream");
addSimpleMapper("VALUE_TO_ARRAY", "to"+valueType.getNonFileType()+"Array");
addSimpleMapper("TO_ARRAY", "to"+type.getNonFileType()+"Array");
addSimpleMapper("[SPACE]", " ");
operators.sort(Comparator.comparing(IMapper::getSearchValue, this::sort));
return this;
}
public GlobalVariables createFlags()
{
flags.add("TYPE_"+type.getCapType());
flags.add("VALUE_"+valueType.getCapType());
if(type == valueType) flags.add("SAME_TYPE");
if(type.hasFunction(valueType)) flags.add("JDK_FUNCTION");
if(!type.needsCustomJDKType()) flags.add("JDK_TYPE");
if(!type.isPrimitiveBlocking()) flags.add("PRIMITIVES");
if(!valueType.isPrimitiveBlocking()) flags.add("VALUE_PRIMITIVES");
if(valueType.needsCustomJDKType()) flags.add("JDK_VALUE");
return this;
}
public TemplateProcess create(String fileName, String splitter, boolean valueOnly)
{
TemplateProcess process = new TemplateProcess(String.format(fileName+".java", (splitter != null ? type.getFileType()+splitter+valueType.getFileType() : (valueOnly ? valueType : type).getFileType())));
process.setPathBuilder(new PathBuilder(type.getPathType()));
process.addFlags(flags);
process.addMappers(operators);
return process;
}
public void testComparason(List<String> keys, List<String> values) {
List<IMapper> copy = new ArrayList<>(operators);
Collections.shuffle(copy);
copy.sort(Comparator.comparing(IMapper::getSearchValue, this::sort));
operators.stream().map(IMapper::getSearchValue).forEach(keys::add);
copy.stream().map(IMapper::getSearchValue).forEach(values::add);
}
private int sort(String key, String value) {
if(value.contains(key)) return 1;
else if(key.contains(value)) return -1;
return 0;
}
public ClassType getType()
{
return type;
}
private void addClassMapper(String pattern, String replacement)
{
operators.add(new SimpleMapper("VALUE_"+pattern, "VALUE_"+pattern, valueType.getFileType()+replacement));
operators.add(new SimpleMapper(pattern, pattern, type.getFileType()+replacement));
}
private void addBiClassMapper(String pattern, String replacement, String splitter)
{
operators.add(new SimpleMapper("KEY_"+pattern, "KEY_"+pattern, type.getFileType()+splitter+type.getFileType()+replacement));
operators.add(new SimpleMapper("VALUE_"+pattern, "VALUE_"+pattern, valueType.getFileType()+splitter+valueType.getFileType()+replacement));
operators.add(new SimpleMapper(pattern, pattern, type.getFileType()+splitter+valueType.getFileType()+replacement));
}
private void addAbstractMapper(String pattern, String replacement)
{
operators.add(new SimpleMapper("VALUE_"+pattern, "VALUE_"+pattern, String.format(replacement, valueType.getFileType())));
operators.add(new SimpleMapper(pattern, pattern, String.format(replacement, type.getFileType())));
}
private void addAbstractBiMapper(String pattern, String replacement, String splitter)
{
operators.add(new SimpleMapper(pattern, pattern, String.format(replacement, type.getFileType()+splitter+valueType.getFileType())));
}
private void addFunctionMapper(String pattern, String replacement)
{
operators.add(new SimpleMapper("VALUE_"+pattern, "VALUE_"+pattern, replacement+valueType.getNonFileType()));
operators.add(new SimpleMapper(pattern, pattern, replacement+type.getNonFileType()));
}
private void addFunctionValueMapper(String pattern, String replacement)
{
operators.add(new SimpleMapper(pattern, pattern, replacement+valueType.getNonFileType()));
}
private void addFunctionMappers(String pattern, String replacement)
{
operators.add(new SimpleMapper("VALUE_"+pattern, "VALUE_"+pattern, String.format(replacement, valueType.getNonFileType())));
operators.add(new SimpleMapper(pattern, pattern, String.format(replacement, type.getNonFileType())));
}
private void addFunctionValueMappers(String pattern, String replacement)
{
operators.add(new SimpleMapper(pattern, pattern, String.format(replacement, valueType.getNonFileType())));
}
private void addSimpleMapper(String pattern, String replacement)
{
operators.add(new SimpleMapper(pattern, pattern, replacement));
}
private void addAnnontion(String pattern, String value)
{
if(type == ClassType.OBJECT) operators.add(new LineMapper(pattern, pattern));
else operators.add(new SimpleMapper(pattern, pattern, value));
}
private void addValueAnnontion(String pattern, String value)
{
if(valueType == ClassType.OBJECT) operators.add(new LineMapper(pattern, pattern));
else operators.add(new SimpleMapper(pattern, pattern, value));
}
private void addComment(String pattern, String value)
{
if(type == ClassType.OBJECT) operators.add(new InjectMapper(pattern, pattern, value).removeBraces());
else operators.add(new LineMapper(pattern, pattern));
}
private void addValueComment(String pattern, String value)
{
if(valueType == ClassType.OBJECT) operators.add(new InjectMapper(pattern, pattern, value).removeBraces());
else operators.add(new LineMapper(pattern, pattern));
}
private InjectMapper addInjectMapper(String pattern, String replacement)
{
InjectMapper mapper = new InjectMapper(pattern, pattern, replacement);
operators.add(mapper);
return mapper;
}
private ArgumentMapper addArgumentMapper(String pattern, String replacement)
{
return addArgumentMapper(pattern, replacement, ", ");
}
private ArgumentMapper addArgumentMapper(String pattern, String replacement, String splitter)
{
ArgumentMapper mapper = new ArgumentMapper(pattern, pattern, replacement, splitter);
operators.add(mapper);
return mapper;
}
class PathBuilder implements UnaryOperator<Path>
{
String before;
public PathBuilder(String before)
{
this.before = before;
}
@Override
public Path apply(Path t)
{
return t.subpath(0, 6).resolve(before).resolve(t.subpath(6, t.getNameCount()));
}
}
}
@@ -32,6 +32,7 @@ public class ModulePackage
List<IMapper> mappers = new ArrayList<>(); List<IMapper> mappers = new ArrayList<>();
Set<String> flags = new LinkedHashSet<>(); Set<String> flags = new LinkedHashSet<>();
Set<String> globalFlags; Set<String> globalFlags;
Map<String, Integer> flaggedValues = new HashMap<>();
BiConsumer<String, RequiredType> requirements = VOID; BiConsumer<String, RequiredType> requirements = VOID;
public ModulePackage(Set<String> globalFlags, ClassType keyType, ClassType valueType) { public ModulePackage(Set<String> globalFlags, ClassType keyType, ClassType valueType) {
@@ -74,6 +75,10 @@ public class ModulePackage
globalFlags.add(flag); globalFlags.add(flag);
} }
public void addValue(String key, int value) {
flaggedValues.put(key, value);
}
public void addRequirement(String fileName, RequiredType type) { public void addRequirement(String fileName, RequiredType type) {
requirements.accept(fileName, type); requirements.accept(fileName, type);
} }
@@ -107,6 +112,7 @@ public class ModulePackage
process.addFlags(flags); process.addFlags(flags);
process.addFlags(globalFlags); process.addFlags(globalFlags);
process.addMappers(mappers); process.addMappers(mappers);
process.addValues(flaggedValues);
result.accept(process); result.accept(process);
} }
@@ -83,6 +83,10 @@ public abstract class BaseModule
entry.addFlag(name); entry.addFlag(name);
} }
protected void addValue(String name, int value) {
entry.addValue(name, value);
}
protected void addKeyFlag(String name) { protected void addKeyFlag(String name) {
entry.addFlag(name); entry.addFlag(name);
entry.addGlobalFlag(keyType.getCapType()+"_"+name); entry.addGlobalFlag(keyType.getCapType()+"_"+name);
@@ -1,5 +1,8 @@
package speiger.src.builder.modules; package speiger.src.builder.modules;
import speiger.src.builder.ClassType;
import speiger.src.builder.RequiredType;
@SuppressWarnings("javadoc") @SuppressWarnings("javadoc")
public class FunctionModule extends BaseModule public class FunctionModule extends BaseModule
{ {
@@ -27,7 +30,23 @@ public class FunctionModule extends BaseModule
{ {
addBiRequirement("BiConsumer", ""); addBiRequirement("BiConsumer", "");
addBiRequirement("UnaryOperator", ""); addBiRequirement("UnaryOperator", "");
addBiRequirement("Function"); if(valueType == ClassType.BOOLEAN) {
addRequirement("Function", "%1$s", RequiredType.BI_CLASS);
addRemapper("Function", (keyType.isObject() ? "" : "%s")+"Predicate");
}
else if(keyType.isObject() && !valueType.isObject()) {
addRequirement("Function", "%2$s", RequiredType.BI_CLASS);
addRemapper("Function", "To%sFunction");
}
else if(keyType == valueType) {
addRequirement("Function", "%1$s", RequiredType.BI_CLASS);
addRemapper("Function", (keyType.isObject() ? "" : "%s")+"UnaryOperator");
}
else if(valueType.isObject()) {
addRequirement("Function", "%1$s", RequiredType.BI_CLASS);
addRemapper("Function", "%sFunction");
}
else addBiRequirement("Function");
addRemapper("BiConsumer", "%sConsumer"); addRemapper("BiConsumer", "%sConsumer");
} }
@@ -35,6 +54,8 @@ public class FunctionModule extends BaseModule
protected void loadFunctions() protected void loadFunctions()
{ {
addSimpleMapper("APPLY", keyType.getApply(valueType)); addSimpleMapper("APPLY", keyType.getApply(valueType));
addSimpleMapper("SUPPLY_GET", keyType.isObject() ? "get" : "getAs"+keyType.getCustomJDKType().getNonFileType());
addSimpleMapper("VALUE_SUPPLY_GET", valueType.isObject() ? "get" : "getAs"+valueType.getCustomJDKType().getNonFileType());
} }
@Override @Override
@@ -44,9 +65,22 @@ public class FunctionModule extends BaseModule
addBiClassMapper("BI_CONSUMER", "Consumer", ""); addBiClassMapper("BI_CONSUMER", "Consumer", "");
addClassMapper("BI_TO_OBJECT_CONSUMER", "ObjectConsumer"); addClassMapper("BI_TO_OBJECT_CONSUMER", "ObjectConsumer");
addAbstractMapper("BI_FROM_OBJECT_CONSUMER", "Object%sConsumer"); addAbstractMapper("BI_FROM_OBJECT_CONSUMER", "Object%sConsumer");
addClassMapper("TO_OBJECT_FUNCTION", "2ObjectFunction"); addAbstractMapper("BI_FROM_INT_CONSUMER", "Int%sConsumer");
addBiClassMapper("FUNCTION", "Function", "2"); if(keyType.isObject()) {
addClassMapper("PREDICATE", "2BooleanFunction"); addSimpleMapper("TO_OBJECT_FUNCTION", keyType.getNonFileType()+"UnaryOperator");
addSimpleMapper("VALUE_TO_OBJECT_FUNCTION", valueType.isObject() ? "UnaryOperator" : valueType.getFileType()+"Function");
}
else {
addSimpleMapper("TO_OBJECT_FUNCTION", keyType.getNonFileType()+"Function");
addSimpleMapper("VALUE_TO_OBJECT_FUNCTION", valueType.isObject() ? "UnaryOperator" : valueType.getFileType()+"Function");
}
if(valueType == ClassType.BOOLEAN) addFunctionMappers("FUNCTION", "%sPredicate");
else if(keyType.isObject() && !valueType.isObject()) addFunctionValueMappers("FUNCTION", "To%sFunction");
else if(keyType == valueType) addFunctionMappers("FUNCTION", "%sUnaryOperator");
else if(valueType.isObject()) addFunctionMappers("FUNCTION", "%sFunction");
else addBiClassMapper("FUNCTION", "Function", "2");
addFunctionMappers("PREDICATE", "%sPredicate");
addClassMapper("SUPPLIER", "Supplier"); addClassMapper("SUPPLIER", "Supplier");
addAbstractMapper("SINGLE_UNARY_OPERATOR", "%1$s%1$sUnaryOperator"); addAbstractMapper("SINGLE_UNARY_OPERATOR", "%1$s%1$sUnaryOperator");
addBiClassMapper("UNARY_OPERATOR", "UnaryOperator", ""); addBiClassMapper("UNARY_OPERATOR", "UnaryOperator", "");
@@ -22,12 +22,20 @@ public class JavaModule extends BaseModule
{ {
addFlag("TYPE_"+keyType.getCapType()); addFlag("TYPE_"+keyType.getCapType());
addFlag("VALUE_"+valueType.getCapType()); addFlag("VALUE_"+valueType.getCapType());
addValue("JAVA_VERSION", getVersion());
if(keyType == valueType) addFlag("SAME_TYPE"); if(keyType == valueType) addFlag("SAME_TYPE");
if(keyType.hasFunction(valueType)) addFlag("JDK_FUNCTION"); if(keyType.hasFunction(valueType)) addFlag("JDK_FUNCTION");
if(!keyType.needsCustomJDKType()) addFlag("JDK_TYPE"); if(!keyType.needsCustomJDKType()) addFlag("JDK_TYPE");
if(!keyType.isPrimitiveBlocking()) addFlag("PRIMITIVES"); if(!keyType.isPrimitiveBlocking()) addFlag("PRIMITIVES");
if(!valueType.isPrimitiveBlocking()) addFlag("VALUE_PRIMITIVES"); if(!valueType.isPrimitiveBlocking()) addFlag("VALUE_PRIMITIVES");
if(valueType.needsCustomJDKType()) addFlag("JDK_VALUE"); if(!valueType.needsCustomJDKType()) addFlag("JDK_VALUE");
}
private int getVersion() {
String version = System.getProperty("java.version");
if(version.startsWith("1.")) return Integer.parseInt(version.substring(2, 3));
int dot = version.indexOf(".");
return Integer.parseInt(dot != -1 ? version.substring(0, dot) : version);
} }
@Override @Override
@@ -52,6 +60,8 @@ public class JavaModule extends BaseModule
@Override @Override
protected void loadClasses() protected void loadClasses()
{ {
if(getVersion() >= 17) addSimpleMapper("RANDOM", "RandomGenerator");
else addSimpleMapper("RANDOM", "Random");
addSimpleMapper("JAVA_PREDICATE", keyType.isPrimitiveBlocking() ? "" : keyType.getCustomJDKType().getFileType()+"Predicate"); addSimpleMapper("JAVA_PREDICATE", keyType.isPrimitiveBlocking() ? "" : keyType.getCustomJDKType().getFileType()+"Predicate");
addSimpleMapper("JAVA_CONSUMER", keyType.isPrimitiveBlocking() ? "" : "java.util.function."+keyType.getCustomJDKType().getFileType()+"Consumer"); addSimpleMapper("JAVA_CONSUMER", keyType.isPrimitiveBlocking() ? "" : "java.util.function."+keyType.getCustomJDKType().getFileType()+"Consumer");
addSimpleMapper("JAVA_SUPPLIER", keyType.isPrimitiveBlocking() ? "" : "java.util.function."+keyType.getCustomJDKType().getFileType()+"Supplier"); addSimpleMapper("JAVA_SUPPLIER", keyType.isPrimitiveBlocking() ? "" : "java.util.function."+keyType.getCustomJDKType().getFileType()+"Supplier");
@@ -101,6 +111,8 @@ public class JavaModule extends BaseModule
addSimpleMapper(" VALUE_STRING_GENERIC_TYPE", valueType.isObject() ? "<String>" : ""); addSimpleMapper(" VALUE_STRING_GENERIC_TYPE", valueType.isObject() ? "<String>" : "");
addSimpleMapper(" KEY_VALUE_STRING_GENERIC_TYPE", keyType.isObject() ? (valueType.isObject() ? "<String, String>" : "<String>") : (valueType.isObject() ? "<String>" : "")); addSimpleMapper(" KEY_VALUE_STRING_GENERIC_TYPE", keyType.isObject() ? (valueType.isObject() ? "<String, String>" : "<String>") : (valueType.isObject() ? "<String>" : ""));
addSimpleMapper(" KEY_SAME_GENERIC_TYPE", keyType.isObject() ? "<T, T>" : "");
addSimpleMapper(" VALUE_SAME_GENERIC_TYPE", keyType.isObject() ? "<V, V>" : "");
addSimpleMapper(" KEY_GENERIC_TYPE", keyType.isObject() ? "<"+keyType.getKeyType()+">" : ""); addSimpleMapper(" KEY_GENERIC_TYPE", keyType.isObject() ? "<"+keyType.getKeyType()+">" : "");
addSimpleMapper(" KEY_KEY_GENERIC_TYPE", keyType.isObject() ? "<"+keyType.getKeyType()+", "+keyType.getKeyType()+">" : ""); addSimpleMapper(" KEY_KEY_GENERIC_TYPE", keyType.isObject() ? "<"+keyType.getKeyType()+", "+keyType.getKeyType()+">" : "");
@@ -135,9 +147,14 @@ public class JavaModule extends BaseModule
addInjectMapper(" KSK_GENERIC_TYPE", keyType.isObject() ? "<%s, "+keyType.getKeyType()+">" : "<%s>").removeBraces().setBraceType("<>"); addInjectMapper(" KSK_GENERIC_TYPE", keyType.isObject() ? "<%s, "+keyType.getKeyType()+">" : "<%s>").removeBraces().setBraceType("<>");
addInjectMapper(" KKS_GENERIC_TYPE", keyType.isObject() ? "<"+keyType.getKeyType()+", %s>" : "<%s>").removeBraces().setBraceType("<>"); addInjectMapper(" KKS_GENERIC_TYPE", keyType.isObject() ? "<"+keyType.getKeyType()+", %s>" : "<%s>").removeBraces().setBraceType("<>");
addArgumentMapper(" KSS_GENERIC_TYPE", keyType.isObject() ? "<%1$s, %2$s>" : "<%2$s>").removeBraces().setBraceType("<>"); addArgumentMapper(" KSS_GENERIC_TYPE", keyType.isObject() ? "<%1$s, %2$s>" : "<%2$s>").removeBraces().setBraceType("<>");
addInjectMapper(" SK_GENERIC_TYPE", keyType.isObject() ? "<%s, "+keyType.getKeyType()+">" : "").removeBraces().setBraceType("<>");
addInjectMapper(" KS_GENERIC_TYPE", keyType.isObject() ? "<"+keyType.getKeyType()+", %s>" : "").removeBraces().setBraceType("<>");
addInjectMapper(" VSV_GENERIC_TYPE", valueType.isObject() ? "<%s, "+valueType.getValueType()+">" : "<%s>").removeBraces().setBraceType("<>"); addInjectMapper(" VSV_GENERIC_TYPE", valueType.isObject() ? "<%s, "+valueType.getValueType()+">" : "<%s>").removeBraces().setBraceType("<>");
addInjectMapper(" VVS_GENERIC_TYPE", valueType.isObject() ? "<"+valueType.getValueType()+", %s>" : "<%s>").removeBraces().setBraceType("<>"); addInjectMapper(" VVS_GENERIC_TYPE", valueType.isObject() ? "<"+valueType.getValueType()+", %s>" : "<%s>").removeBraces().setBraceType("<>");
addArgumentMapper(" VSS_GENERIC_TYPE", valueType.isObject() ? "<%1$s, %2$s>" : "<%2$s>").removeBraces().setBraceType("<>"); addArgumentMapper(" VSS_GENERIC_TYPE", valueType.isObject() ? "<%1$s, %2$s>" : "<%2$s>").removeBraces().setBraceType("<>");
addInjectMapper(" SV_GENERIC_TYPE", valueType.isObject() ? "<%s, "+valueType.getValueType()+">" : "").removeBraces().setBraceType("<>");
addInjectMapper(" VS_GENERIC_TYPE", valueType.isObject() ? "<"+valueType.getValueType()+", %s>" : "").removeBraces().setBraceType("<>");
addSimpleMapper(" GENERIC_KEY_BRACES", keyType.isObject() ? " <"+keyType.getKeyType()+">" : ""); addSimpleMapper(" GENERIC_KEY_BRACES", keyType.isObject() ? " <"+keyType.getKeyType()+">" : "");
addSimpleMapper(" GENERIC_VALUE_BRACES", valueType.isObject() ? " <"+valueType.getValueType()+">" : ""); addSimpleMapper(" GENERIC_VALUE_BRACES", valueType.isObject() ? " <"+valueType.getValueType()+">" : "");
@@ -59,8 +59,8 @@ public class MapModule extends BaseModule
} }
if(implementations && isModuleEnabled("ConcurrentMap")) addFlag("CONCURRENT_MAP_FEATURE"); if(implementations && isModuleEnabled("ConcurrentMap")) addFlag("CONCURRENT_MAP_FEATURE");
if(implementations && isModuleEnabled("ImmutableMap")) addFlag("IMMUTABLE_MAP_FEATURE"); if(implementations && isModuleEnabled("ImmutableMap")) addFlag("IMMUTABLE_MAP_FEATURE");
if(hashMap) addFlag("HASH_MAP_FEATURE"); if(hashMap) addFlag("MAP_FEATURE");
if(customHashMap) addFlag("CUSTOM_HASH_MAP_FEATURE"); if(customHashMap) addFlag("CUSTOM_MAP_FEATURE");
if(enumMap) addFlag("ENUM_MAP_FEATURE"); if(enumMap) addFlag("ENUM_MAP_FEATURE");
} }
@@ -104,7 +104,7 @@ public class MapModule extends BaseModule
//Test Classes //Test Classes
addBlockedFiles("TestMap", "MapTests", "MapTestSuiteBuilder", "MapConstructorTests", "TestMapGenerator", "SimpleMapTestGenerator", "DerivedMapGenerators", "AbstractMapTester"); addBlockedFiles("TestMap", "MapTests", "MapTestSuiteBuilder", "MapConstructorTests", "TestMapGenerator", "SimpleMapTestGenerator", "DerivedMapGenerators", "AbstractMapTester");
addBlockedFiles("TestSortedMapGenerator", "NavigableMapTestSuiteBuilder", "SortedMapTestSuiteBuilder"); addBlockedFiles("TestSortedMapGenerator", "OrderedMapTestSuiteBuilder", "NavigableMapTestSuiteBuilder", "SortedMapTestSuiteBuilder");
addBlockedFiles("TestOrderedMapGenerator"); addBlockedFiles("TestOrderedMapGenerator");
addBlockedFilter(T -> T.endsWith("Tester") && (T.startsWith("Map") || T.startsWith("OrderedMap") || T.startsWith("SortedMap") || T.startsWith("NavigableMap"))); addBlockedFilter(T -> T.endsWith("Tester") && (T.startsWith("Map") || T.startsWith("OrderedMap") || T.startsWith("SortedMap") || T.startsWith("NavigableMap")));
} }
@@ -214,7 +214,6 @@ public class MapModule extends BaseModule
addFunctionValueMappers("FIRST_ENTRY_VALUE", "first%sValue"); addFunctionValueMappers("FIRST_ENTRY_VALUE", "first%sValue");
if(keyType.isObject()) addFunctionValueMapper("GET_VALUE", valueType.isObject() ? "getObject" : "get"); if(keyType.isObject()) addFunctionValueMapper("GET_VALUE", valueType.isObject() ? "getObject" : "get");
else addSimpleMapper("GET_VALUE", "get"); else addSimpleMapper("GET_VALUE", "get");
addSimpleMapper("GET_JAVA", keyType.isObject() ? "get" : "getAs"+keyType.getCustomJDKType().getNonFileType());
addFunctionMappers("LAST_ENTRY_KEY", "last%sKey"); addFunctionMappers("LAST_ENTRY_KEY", "last%sKey");
addFunctionValueMappers("LAST_ENTRY_VALUE", "last%sValue"); addFunctionValueMappers("LAST_ENTRY_VALUE", "last%sValue");
addFunctionValueMapper("MERGE", "merge"); addFunctionValueMapper("MERGE", "merge");
@@ -90,10 +90,11 @@ public class SetModule extends BaseModule
addBlockedFiles("Set", "Sets", "AbstractSet", "OpenHashSet", "OpenCustomHashSet", "ImmutableOpenHashSet"); addBlockedFiles("Set", "Sets", "AbstractSet", "OpenHashSet", "OpenCustomHashSet", "ImmutableOpenHashSet");
//Test Classes //Test Classes
addBlockedFiles("SetTests", "SetTestSuiteBuilder"); addBlockedFiles("SetTests", "SetTestSuiteBuilder", "TestSetGenerator");
addBlockedFiles("OrderedSetTestSuiteBuilder", "TestOrderedSetGenerator", "OrderedSetMoveTester", "OrderedSetNavigationTester", "OrderedSetIterationTester"); addBlockedFiles("OrderedSetTestSuiteBuilder", "TestOrderedSetGenerator", "OrderedSetMoveTester", "OrderedSetNavigationTester", "OrderedSetIterationTester");
addBlockedFiles("SortedSetTestSuiteBuilder", "TestSortedSetGenerator", "SortedSetNaviationTester", "SortedSetSubsetTestSetGenerator", "SortedSetIterationTester", "SortedSetNaviationTester"); addBlockedFiles("SortedSetTestSuiteBuilder", "TestSortedSetGenerator", "SortedSetNaviationTester", "SortedSetSubsetTestSetGenerator", "SortedSetIterationTester", "SortedSetNaviationTester");
addBlockedFiles("NavigableSetTestSuiteBuilder", "TestNavigableSetGenerator", "NavigableSetNavigationTester"); addBlockedFiles("NavigableSetTestSuiteBuilder", "TestNavigableSetGenerator", "NavigableSetNavigationTester");
addBlockedFiles("MinimalSet", "AbstractSetTester", "SetAddAllTester", "SetAddTester", "SetCreationTester", "SetEqualsTester", "SetRemoveTester");
} }
} }
@@ -11,6 +11,7 @@ import java.util.function.Consumer;
import speiger.src.collections.PACKAGE.functions.CONSUMER; import speiger.src.collections.PACKAGE.functions.CONSUMER;
import speiger.src.collections.PACKAGE.utils.ITERATORS; import speiger.src.collections.PACKAGE.utils.ITERATORS;
#endif #endif
import speiger.src.collections.PACKAGE.utils.ARRAYS;
/** /**
* Abstract Type Specific Collection that reduces boxing/unboxing * Abstract Type Specific Collection that reduces boxing/unboxing
@@ -245,6 +246,7 @@ public abstract class ABSTRACT_COLLECTION KEY_GENERIC_TYPE extends AbstractColle
*/ */
@Override @Override
public KEY_TYPE[] TO_ARRAY() { public KEY_TYPE[] TO_ARRAY() {
if(isEmpty()) return ARRAYS.EMPTY_ARRAY;
return TO_ARRAY(new KEY_TYPE[size()]); return TO_ARRAY(new KEY_TYPE[size()]);
} }
@@ -12,7 +12,7 @@ import java.util.stream.StreamSupport;
#endif #endif
#if TYPE_OBJECT #if TYPE_OBJECT
import java.util.function.Consumer; import java.util.function.Consumer;
import speiger.src.collections.ints.functions.function.Int2ObjectFunction; import java.util.function.IntFunction;
#else #else
import speiger.src.collections.PACKAGE.functions.CONSUMER; import speiger.src.collections.PACKAGE.functions.CONSUMER;
#endif #endif
@@ -182,7 +182,7 @@ public interface COLLECTION KEY_GENERIC_TYPE extends Collection<CLASS_TYPE>, ITE
* @return an array containing all of the elements in this collection * @return an array containing all of the elements in this collection
* @see Collection#toArray(Object[]) * @see Collection#toArray(Object[])
*/ */
default KEY_TYPE[] TO_ARRAY(Int2ObjectFunction<KEY_TYPE[]> action) { default <E> E[] TO_ARRAY(IntFunction<E[]> action) {
return TO_ARRAY(action.apply(size())); return TO_ARRAY(action.apply(size()));
} }
@@ -2,6 +2,10 @@ package speiger.src.collections.PACKAGE.collections;
import java.util.Objects; import java.util.Objects;
import java.util.function.Consumer; import java.util.function.Consumer;
#if JDK_FUNCTION
import java.util.function.PREDICATE;
#endif
#if !TYPE_OBJECT #if !TYPE_OBJECT
import speiger.src.collections.PACKAGE.functions.CONSUMER; import speiger.src.collections.PACKAGE.functions.CONSUMER;
@@ -9,13 +13,16 @@ import speiger.src.collections.PACKAGE.functions.COMPARATOR;
import speiger.src.collections.objects.collections.ObjectIterable; import speiger.src.collections.objects.collections.ObjectIterable;
#else #else
import java.util.function.BiFunction; import java.util.function.BiFunction;
import java.util.function.IntFunction;
import java.util.Comparator; import java.util.Comparator;
import speiger.src.collections.ints.functions.function.Int2ObjectFunction;
#endif #endif
import speiger.src.collections.PACKAGE.functions.function.TO_OBJECT_FUNCTION; import speiger.src.collections.PACKAGE.functions.function.TO_OBJECT_FUNCTION;
import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER; import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
#if !JDK_FUNCTION
import speiger.src.collections.PACKAGE.functions.function.PREDICATE; import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
#endif
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR; import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
#if ARRAY_LIST_FEATURE || LINKED_LIST_FEATURE #if ARRAY_LIST_FEATURE || LINKED_LIST_FEATURE
import speiger.src.collections.PACKAGE.lists.LIST; import speiger.src.collections.PACKAGE.lists.LIST;
@@ -104,6 +111,17 @@ public interface ITERABLE KEY_GENERIC_TYPE extends Iterable<CLASS_TYPE>
} }
#endif #endif
/**
* A Indexed forEach implementation that allows you to keep track of how many elements were already iterated over.
* @param action The action to be performed for each element
* @throws java.lang.NullPointerException if the specified action is null
*/
public default void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
Objects.requireNonNull(action);
int index = 0;
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();action.accept(index++, iter.NEXT()));
}
/** /**
* Helper function to reduce Lambda usage and allow for more method references, since these are faster/cleaner. * Helper function to reduce Lambda usage and allow for more method references, since these are faster/cleaner.
* @param input the object that should be included * @param input the object that should be included
@@ -282,12 +300,12 @@ public interface ITERABLE KEY_GENERIC_TYPE extends Iterable<CLASS_TYPE>
* @param action is the creator function of said Array to ensure type is kept. * @param action is the creator function of said Array to ensure type is kept.
* @return a new Array of all elements * @return a new Array of all elements
*/ */
default KEY_TYPE[] TO_ARRAY(Int2ObjectFunction<KEY_TYPE[]> action) { default <E> E[] TO_ARRAY(IntFunction<E[]> action) {
ISizeProvider prov = ISizeProvider.of(this); ISizeProvider prov = ISizeProvider.of(this);
if(prov != null) { if(prov != null) {
int size = prov.size(); int size = prov.size();
if(size >= 0) { if(size >= 0) {
KEY_TYPE[] array = action.apply(size); E[] array = action.apply(size);
ITERATORS.unwrap(array, iterator()); ITERATORS.unwrap(array, iterator());
return array; return array;
} }
@@ -15,12 +15,5 @@ public interface SUPPLIER KEY_GENERIC_TYPE
/** /**
* @return the supplied value * @return the supplied value
*/ */
public KEY_TYPE GET_KEY(); public KEY_TYPE SUPPLY_GET();
#if JDK_TYPE && PRIMITIVES
@Override
public default KEY_TYPE GET_JAVA() {
return GET_KEY();
}
#endif
} }
@@ -1,6 +1,6 @@
package speiger.src.collections.PACKAGE.functions.function; package speiger.src.collections.PACKAGE.functions.function;
#if JDK_FUNCTION && VALUE_BOOLEAN #if VALUE_BOOLEAN || SAME_TYPE
import java.util.Objects; import java.util.Objects;
#endif #endif
@@ -23,7 +23,65 @@ public interface FUNCTION KEY_VALUE_GENERIC_TYPE
*/ */
public VALUE_TYPE APPLY(KEY_TYPE k); public VALUE_TYPE APPLY(KEY_TYPE k);
#if JDK_FUNCTION && VALUE_BOOLEAN #if SAME_TYPE
/**
* Creates a Default function that returns the input provided.
* @Type(T)
* @return a input returning function
*/
public static GENERIC_KEY_BRACES FUNCTION KEY_SAME_GENERIC_TYPE identity() {
return T -> T;
}
/**
* Returns a composed function that first applies the {@code before}
* function to its input, and then applies this function to the result.
* If evaluation of either function throws an exception, it is relayed to
* the caller of the composed function.
*
* @Type(I)
* @param before the function that should be used first
* @return a composed function with a different starting function.
*/
public default GENERIC_SPECIAL_VALUE_BRACES<I> FUNCTION SV_GENERIC_TYPE<I> compose(FUNCTION SK_GENERIC_TYPE<I> before) {
Objects.requireNonNull(before);
return T -> APPLY(before.APPLY(T));
}
/**
* Returns a composed function that first applies this function to
* its input, and then applies the {@code after} function to the result.
* If evaluation of either function throws an exception, it is relayed to
* the caller of the composed function.
*
* @Type(I)
* @param after the function that should be used last
* @return a composed function with a different starting function.
*/
public default GENERIC_SPECIAL_VALUE_BRACES<I> FUNCTION KS_GENERIC_TYPE<I> andThen(FUNCTION VS_GENERIC_TYPE<I> after) {
Objects.requireNonNull(after);
return T -> after.APPLY(APPLY(T));
}
#endif
#if VALUE_BOOLEAN
/**
* Creates a Always true function that may be useful if you don't need to process information or just want a default.
* @Type(T)
* @return a default returning function
*/
public static GENERIC_KEY_BRACES FUNCTION KEY_GENERIC_TYPE alwaysTrue() {
return T -> true;
}
/**
* Creates a Always false function that may be useful if you don't need to process information or just want a default.
* @Type(T)
* @return a default returning function
*/
public static GENERIC_KEY_BRACES FUNCTION KEY_GENERIC_TYPE alwaysFalse() {
return T -> false;
}
/** /**
* A Type specific and-function helper function that reduces boxing/unboxing * A Type specific and-function helper function that reduces boxing/unboxing
@@ -35,6 +93,7 @@ public interface FUNCTION KEY_VALUE_GENERIC_TYPE
return T -> APPLY(T) && other.APPLY(T); return T -> APPLY(T) && other.APPLY(T);
} }
#if JDK_FUNCTION
@Override @Override
@Deprecated @Deprecated
public default FUNCTION KEY_VALUE_GENERIC_TYPE and(JAVA_FUNCTION KEY_VALUE_SUPER_GENERIC_TYPE other) { public default FUNCTION KEY_VALUE_GENERIC_TYPE and(JAVA_FUNCTION KEY_VALUE_SUPER_GENERIC_TYPE other) {
@@ -43,6 +102,12 @@ public interface FUNCTION KEY_VALUE_GENERIC_TYPE
} }
@Override @Override
#else
/**
* A type specific inverter function
* @return the same function but inverts the result
*/
#endif
public default FUNCTION KEY_VALUE_GENERIC_TYPE negate() { public default FUNCTION KEY_VALUE_GENERIC_TYPE negate() {
return T -> !APPLY(T); return T -> !APPLY(T);
} }
@@ -57,6 +122,7 @@ public interface FUNCTION KEY_VALUE_GENERIC_TYPE
return T -> APPLY(T) || other.APPLY(T); return T -> APPLY(T) || other.APPLY(T);
} }
#if JDK_FUNCTION
@Override @Override
@Deprecated @Deprecated
public default FUNCTION KEY_VALUE_GENERIC_TYPE or(JAVA_FUNCTION KEY_VALUE_SUPER_GENERIC_TYPE other) { public default FUNCTION KEY_VALUE_GENERIC_TYPE or(JAVA_FUNCTION KEY_VALUE_SUPER_GENERIC_TYPE other) {
@@ -64,4 +130,5 @@ public interface FUNCTION KEY_VALUE_GENERIC_TYPE
return T -> APPLY(T) || other.APPLY(T); return T -> APPLY(T) || other.APPLY(T);
} }
#endif #endif
#endif
} }
@@ -14,10 +14,15 @@ import java.util.function.Consumer;
import java.util.function.BiFunction; import java.util.function.BiFunction;
#endif #endif
#if !TYPE_OBJECT && JDK_FUNCTION
import java.util.function.PREDICATE;
#endif
import java.util.function.Predicate; import java.util.function.Predicate;
import java.util.function.UnaryOperator; import java.util.function.UnaryOperator;
#if PRIMITIVES #if PRIMITIVES
#if !JDK_FUNCTION
import java.util.function.JAVA_PREDICATE; import java.util.function.JAVA_PREDICATE;
#endif
import java.util.function.JAVA_UNARY_OPERATOR; import java.util.function.JAVA_UNARY_OPERATOR;
import java.nio.JAVA_BUFFER; import java.nio.JAVA_BUFFER;
#endif #endif
@@ -32,14 +37,15 @@ import speiger.src.collections.PACKAGE.functions.COMPARATOR;
import speiger.src.collections.PACKAGE.functions.CONSUMER; import speiger.src.collections.PACKAGE.functions.CONSUMER;
#endif #endif
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER; import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
#if !JDK_FUNCTION
import speiger.src.collections.PACKAGE.functions.function.PREDICATE; import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
#endif
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR; import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
import speiger.src.collections.PACKAGE.utils.ARRAYS; import speiger.src.collections.PACKAGE.utils.ARRAYS;
import speiger.src.collections.objects.utils.ObjectArrays;
import speiger.src.collections.PACKAGE.utils.ITERATORS; import speiger.src.collections.PACKAGE.utils.ITERATORS;
#if TYPE_OBJECT #if TYPE_OBJECT
import speiger.src.collections.utils.Stack; import speiger.src.collections.utils.Stack;
#else
import speiger.src.collections.objects.utils.ObjectArrays;
#endif #endif
#if PRIMITIVES && SPLIT_ITERATOR_FEATURE && STREAM_FEATURE #if PRIMITIVES && SPLIT_ITERATOR_FEATURE && STREAM_FEATURE
import java.util.stream.JAVA_STREAM; import java.util.stream.JAVA_STREAM;
@@ -1036,6 +1042,7 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
@Override @Override
@Primitive @Primitive
public Object[] toArray() { public Object[] toArray() {
if(size == 0) return ObjectArrays.EMPTY_ARRAY;
Object[] obj = new Object[size]; Object[] obj = new Object[size];
for(int i = 0;i<size;i++) for(int i = 0;i<size;i++)
obj[i] = KEY_TO_OBJ(data[i]); obj[i] = KEY_TO_OBJ(data[i]);
@@ -14,10 +14,15 @@ import java.util.function.Supplier;
#if TYPE_OBJECT #if TYPE_OBJECT
import java.util.function.BiFunction; import java.util.function.BiFunction;
#endif #endif
#if !TYPE_OBJECT && JDK_FUNCTION
import java.util.function.PREDICATE;
#endif
import java.util.function.Predicate; import java.util.function.Predicate;
import java.util.function.UnaryOperator; import java.util.function.UnaryOperator;
#if PRIMITIVES #if PRIMITIVES
#if !JDK_FUNCTION
import java.util.function.JAVA_PREDICATE; import java.util.function.JAVA_PREDICATE;
#endif
import java.util.function.JAVA_UNARY_OPERATOR; import java.util.function.JAVA_UNARY_OPERATOR;
import java.nio.JAVA_BUFFER; import java.nio.JAVA_BUFFER;
#endif #endif
@@ -32,14 +37,15 @@ import speiger.src.collections.PACKAGE.functions.COMPARATOR;
import speiger.src.collections.PACKAGE.functions.CONSUMER; import speiger.src.collections.PACKAGE.functions.CONSUMER;
#endif #endif
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER; import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
#if !JDK_FUNCTION
import speiger.src.collections.PACKAGE.functions.function.PREDICATE; import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
#endif
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR; import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
import speiger.src.collections.PACKAGE.utils.ARRAYS; import speiger.src.collections.PACKAGE.utils.ARRAYS;
import speiger.src.collections.objects.utils.ObjectArrays;
import speiger.src.collections.PACKAGE.utils.ITERATORS; import speiger.src.collections.PACKAGE.utils.ITERATORS;
#if TYPE_OBJECT #if TYPE_OBJECT
import speiger.src.collections.utils.Stack; import speiger.src.collections.utils.Stack;
#else
import speiger.src.collections.objects.utils.ObjectArrays;
#endif #endif
#if PRIMITIVES && STREAM_FEATURE && SPLIT_ITERATOR_FEATURE #if PRIMITIVES && STREAM_FEATURE && SPLIT_ITERATOR_FEATURE
import java.util.stream.JAVA_STREAM; import java.util.stream.JAVA_STREAM;
@@ -1284,6 +1290,7 @@ public class COPY_ON_WRITE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENER
public Object[] toArray() { public Object[] toArray() {
KEY_TYPE[] data = this.data; KEY_TYPE[] data = this.data;
int size = data.length; int size = data.length;
if(size == 0) return ObjectArrays.EMPTY_ARRAY;
Object[] obj = new Object[size]; Object[] obj = new Object[size];
for(int i = 0;i<size;i++) for(int i = 0;i<size;i++)
obj[i] = KEY_TO_OBJ(data[i]); obj[i] = KEY_TO_OBJ(data[i]);
@@ -13,8 +13,13 @@ import java.util.function.Consumer;
#endif #endif
import java.util.function.Predicate; import java.util.function.Predicate;
import java.util.function.UnaryOperator; import java.util.function.UnaryOperator;
#if !TYPE_OBJECT && JDK_FUNCTION
import java.util.function.PREDICATE;
#endif
#if PRIMITIVES #if PRIMITIVES
#if !JDK_FUNCTION
import java.util.function.JAVA_PREDICATE; import java.util.function.JAVA_PREDICATE;
#endif
import java.util.function.JAVA_UNARY_OPERATOR; import java.util.function.JAVA_UNARY_OPERATOR;
#endif #endif
@@ -25,7 +30,9 @@ import speiger.src.collections.PACKAGE.functions.CONSUMER;
import speiger.src.collections.PACKAGE.utils.ARRAYS; import speiger.src.collections.PACKAGE.utils.ARRAYS;
#endif #endif
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER; import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
#if !JDK_FUNCTION
import speiger.src.collections.PACKAGE.functions.function.PREDICATE; import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
#endif
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR; import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
import speiger.src.collections.objects.utils.ObjectArrays; import speiger.src.collections.objects.utils.ObjectArrays;
import speiger.src.collections.PACKAGE.utils.ITERATORS; import speiger.src.collections.PACKAGE.utils.ITERATORS;
@@ -131,7 +138,8 @@ public class IMMUTABLE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_T
@Override @Override
public KEY_TYPE[] getElements(int from, KEY_TYPE[] a, int offset, int length) { public KEY_TYPE[] getElements(int from, KEY_TYPE[] a, int offset, int length) {
SanityChecks.checkArrayCapacity(data.length, offset, length); SanityChecks.checkArrayCapacity(a.length, offset, length);
SanityChecks.checkArrayCapacity(data.length, from, length);
System.arraycopy(data, from, a, offset, length); System.arraycopy(data, from, a, offset, length);
return a; return a;
} }
@@ -438,6 +446,7 @@ public class IMMUTABLE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_T
@Override @Override
@Primitive @Primitive
public Object[] toArray() { public Object[] toArray() {
if(data.length == 0) return ObjectArrays.EMPTY_ARRAY;
Object[] obj = new Object[data.length]; Object[] obj = new Object[data.length];
for(int i = 0,m=data.length;i<m;i++) for(int i = 0,m=data.length;i<m;i++)
obj[i] = KEY_TO_OBJ(data[i]); obj[i] = KEY_TO_OBJ(data[i]);
@@ -4,6 +4,7 @@ package speiger.src.collections.PACKAGE.lists;
#if DEQUEUE_FEATURE #if DEQUEUE_FEATURE
import java.util.Comparator; import java.util.Comparator;
#endif #endif
import java.util.function.BiFunction; import java.util.function.BiFunction;
#else if PRIMITIVES #else if PRIMITIVES
import java.nio.JAVA_BUFFER; import java.nio.JAVA_BUFFER;
@@ -18,19 +19,28 @@ import java.util.Spliterator.JAVA_SPLIT_ITERATOR;
#endif #endif
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.function.Predicate; import java.util.function.Predicate;
#if TYPE_OBJECT
import java.util.function.IntFunction;
#endif
#if !TYPE_OBJECT && JDK_FUNCTION
import java.util.function.PREDICATE;
#endif
import java.util.function.UnaryOperator; import java.util.function.UnaryOperator;
#if PRIMITIVES #if PRIMITIVES
#if !JDK_FUNCTION
import java.util.function.JAVA_PREDICATE; import java.util.function.JAVA_PREDICATE;
#endif
import java.util.function.JAVA_UNARY_OPERATOR; import java.util.function.JAVA_UNARY_OPERATOR;
#endif #endif
import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER; import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
#if !JDK_FUNCTION
import speiger.src.collections.PACKAGE.functions.function.PREDICATE; import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
#endif
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR; import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
import speiger.src.collections.PACKAGE.collections.COLLECTION; import speiger.src.collections.PACKAGE.collections.COLLECTION;
#if !TYPE_OBJECT #if !TYPE_OBJECT
import speiger.src.collections.PACKAGE.collections.STACK; import speiger.src.collections.PACKAGE.collections.STACK;
#else
import speiger.src.collections.ints.functions.function.Int2ObjectFunction;
#endif #endif
import speiger.src.collections.PACKAGE.collections.ITERATOR; import speiger.src.collections.PACKAGE.collections.ITERATOR;
#if DEQUEUE_FEATURE #if DEQUEUE_FEATURE
@@ -40,13 +50,13 @@ import speiger.src.collections.PACKAGE.queues.PRIORITY_DEQUEUE;
#if DEQUEUE_FEATURE #if DEQUEUE_FEATURE
import speiger.src.collections.PACKAGE.functions.COMPARATOR; import speiger.src.collections.PACKAGE.functions.COMPARATOR;
#endif #endif
import speiger.src.collections.PACKAGE.functions.CONSUMER; import speiger.src.collections.PACKAGE.functions.CONSUMER;
#endif #endif
import speiger.src.collections.PACKAGE.utils.ARRAYS; import speiger.src.collections.PACKAGE.utils.ARRAYS;
import speiger.src.collections.objects.utils.ObjectArrays;
#if TYPE_OBJECT #if TYPE_OBJECT
import speiger.src.collections.utils.Stack; import speiger.src.collections.utils.Stack;
#else
import speiger.src.collections.objects.utils.ObjectArrays;
#endif #endif
#if PRIMITIVES #if PRIMITIVES
import java.util.stream.JAVA_STREAM; import java.util.stream.JAVA_STREAM;
@@ -410,6 +420,14 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
} }
} }
@Override
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
Objects.requireNonNull(action);
int index = 0;
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next)
action.accept(index++, entry.value);
}
@Override @Override
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) { public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action); Objects.requireNonNull(action);
@@ -948,6 +966,7 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
#endif #endif
@Override @Override
public Object[] toArray() { public Object[] toArray() {
if(size == 0) return ObjectArrays.EMPTY_ARRAY;
Object[] obj = new Object[size]; Object[] obj = new Object[size];
int i = 0; int i = 0;
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next) { for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next) {
@@ -982,7 +1001,7 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
#else #else
@Override @Override
public T[] toArray(Int2ObjectFunction<T[]> action) { public <E> E[] toArray(IntFunction<E[]> action) {
return super.toArray(action); return super.toArray(action);
} }
@@ -5,17 +5,18 @@ import java.nio.JAVA_BUFFER;
#endif #endif
import java.util.List; import java.util.List;
#if !TYPE_OBJECT && !TYPE_BOOLEAN #if !TYPE_OBJECT && !TYPE_BOOLEAN
import java.util.Objects;
import java.util.function.JAVA_UNARY_OPERATOR; import java.util.function.JAVA_UNARY_OPERATOR;
import java.util.function.UnaryOperator; #endif
#else if TYPE_OBJECT
import java.util.Objects; import java.util.Objects;
import java.util.Comparator;
#if !TYPE_BOOLEAN
import java.util.function.UnaryOperator; import java.util.function.UnaryOperator;
#endif #endif
import java.util.Comparator;
import speiger.src.collections.PACKAGE.collections.COLLECTION; import speiger.src.collections.PACKAGE.collections.COLLECTION;
import speiger.src.collections.PACKAGE.collections.SPLIT_ITERATOR; import speiger.src.collections.PACKAGE.collections.SPLIT_ITERATOR;
import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
#if !TYPE_OBJECT #if !TYPE_OBJECT
import speiger.src.collections.PACKAGE.functions.COMPARATOR; import speiger.src.collections.PACKAGE.functions.COMPARATOR;
#endif #endif
@@ -360,6 +361,16 @@ public interface LIST KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, List
} }
#endif #endif
/**
* A Indexed forEach implementation that allows you to keep track of how many elements were already iterated over.
* @param action The action to be performed for each element
* @throws java.lang.NullPointerException if the specified action is null
*/
@Override
public default void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
Objects.requireNonNull(action);
for(int i = 0,m=size();i<m;action.accept(i, GET_KEY(i++)));
}
/** /**
* A Type-Specific Iterator of listIterator * A Type-Specific Iterator of listIterator
* @see java.util.List#listIterator * @see java.util.List#listIterator
@@ -3,10 +3,15 @@ package speiger.src.collections.PACKAGE.maps.abstracts;
import java.util.AbstractMap; import java.util.AbstractMap;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
#if VALUE_BOOLEAN && JDK_FUNCTION
import java.util.function.PREDICATE;
#endif
import speiger.src.collections.PACKAGE.collections.ITERATOR; import speiger.src.collections.PACKAGE.collections.ITERATOR;
import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER; import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
#if !VALUE_BOOLEAN || !JDK_FUNCTION
import speiger.src.collections.PACKAGE.functions.function.FUNCTION; import speiger.src.collections.PACKAGE.functions.function.FUNCTION;
#endif
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR; import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
import speiger.src.collections.PACKAGE.maps.interfaces.MAP; import speiger.src.collections.PACKAGE.maps.interfaces.MAP;
import speiger.src.collections.PACKAGE.sets.ABSTRACT_SET; import speiger.src.collections.PACKAGE.sets.ABSTRACT_SET;
@@ -228,7 +233,7 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE extends AbstractMap<CL
Objects.requireNonNull(valueProvider); Objects.requireNonNull(valueProvider);
VALUE_TYPE value; VALUE_TYPE value;
if((value = GET_VALUE(key)) == getDefaultReturnValue() || !containsKey(key)) { if((value = GET_VALUE(key)) == getDefaultReturnValue() || !containsKey(key)) {
VALUE_TYPE newValue = valueProvider.VALUE_GET_KEY(); VALUE_TYPE newValue = valueProvider.VALUE_SUPPLY_GET();
if(VALUE_EQUALS_NOT(newValue, getDefaultReturnValue())) { if(VALUE_EQUALS_NOT(newValue, getDefaultReturnValue())) {
put(key, newValue); put(key, newValue);
return newValue; return newValue;
@@ -6,8 +6,14 @@ import java.util.NoSuchElementException;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.locks.StampedLock; import java.util.concurrent.locks.StampedLock;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.function.BiFunction; import java.util.function.BiFunction;
#if !TYPE_OBJECT && JDK_TYPE
import java.util.function.PREDICATE;
#endif
#if !SAME_TYPE && JDK_VALUE && !VALUE_OBJECT
import java.util.function.VALUE_PREDICATE;
#endif
#if !TYPE_OBJECT #if !TYPE_OBJECT
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR; import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
@@ -17,13 +23,22 @@ import speiger.src.collections.PACKAGE.collections.ITERATOR;
import speiger.src.collections.PACKAGE.functions.CONSUMER; import speiger.src.collections.PACKAGE.functions.CONSUMER;
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER; import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
#endif #endif
import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
#if !TYPE_OBJECT && !VALUE_OBJECT
import speiger.src.collections.ints.functions.consumer.IntObjectConsumer;
#endif
#if !SAME_TYPE
import speiger.src.collections.ints.functions.consumer.VALUE_BI_FROM_INT_CONSUMER;
#endif
import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER; import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
#if !VALUE_BOOLEAN || !JDK_TYPE
import speiger.src.collections.PACKAGE.functions.function.FUNCTION; import speiger.src.collections.PACKAGE.functions.function.FUNCTION;
#endif
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR; import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
#if !SAME_TYPE #if !SAME_TYPE
import speiger.src.collections.PACKAGE.functions.function.SINGLE_UNARY_OPERATOR; import speiger.src.collections.PACKAGE.functions.function.SINGLE_UNARY_OPERATOR;
#endif #endif
#if !TYPE_OBJECT && !VALUE_BOOLEAN #if !TYPE_OBJECT && !VALUE_BOOLEAN && !JDK_TYPE
import speiger.src.collections.PACKAGE.functions.function.PREDICATE; import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
#endif #endif
import speiger.src.collections.PACKAGE.maps.abstracts.ABSTRACT_MAP; import speiger.src.collections.PACKAGE.maps.abstracts.ABSTRACT_MAP;
@@ -43,6 +58,7 @@ import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_UNARY_OPER
#if !TYPE_OBJECT #if !TYPE_OBJECT
import speiger.src.collections.objects.functions.function.ObjectObjectUnaryOperator; import speiger.src.collections.objects.functions.function.ObjectObjectUnaryOperator;
#endif #endif
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ITERATOR; import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ITERATOR;
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_BI_ITERATOR; import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_BI_ITERATOR;
import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_CONSUMER; import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_CONSUMER;
@@ -54,18 +70,14 @@ import speiger.src.collections.objects.functions.function.ObjectObjectUnaryOpera
#if !TYPE_OBJECT && !VALUE_OBJECT || !VALUE_OBJECT #if !TYPE_OBJECT && !VALUE_OBJECT || !VALUE_OBJECT
import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer; import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer;
#endif #endif
#if !TYPE_OBJECT || !VALUE_BOOLEAN
#if !VALUE_OBJECT || SAME_TYPE
import speiger.src.collections.objects.functions.function.Object2BooleanFunction;
#endif
#endif
#if !SAME_TYPE #if !SAME_TYPE
#if !TYPE_OBJECT #if !TYPE_OBJECT
import speiger.src.collections.objects.functions.consumer.VALUE_BI_FROM_OBJECT_CONSUMER; import speiger.src.collections.objects.functions.consumer.VALUE_BI_FROM_OBJECT_CONSUMER;
#endif #endif
#if !JDK_VALUE
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE; import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE;
#endif #endif
#endif
#if VALUE_OBJECT #if VALUE_OBJECT
import speiger.src.collections.objects.collections.ObjectIterator; import speiger.src.collections.objects.collections.ObjectIterator;
#endif #endif
@@ -668,6 +680,26 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
} }
} }
@Override
public void forEachIndexed(IntObjectConsumer<MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
Objects.requireNonNull(action);
int count = 0;
for(int i = 0,m=segments.length;i<m;i++) {
Segment KEY_VALUE_GENERIC_TYPE seg = segments[i];
long stamp = seg.readLock();
try {
int index = seg.firstIndex;
while(index != -1) {
action.accept(count++, new BasicEntryKV_BRACES(seg.keys[index], seg.values[index]));
index = (int)seg.links[index];
}
}
finally {
seg.unlockRead(stamp);
}
}
}
@Override @Override
public <E> void forEach(E input, ObjectObjectConsumer<E, MAP.Entry KEY_VALUE_GENERIC_TYPE> action) { public <E> void forEach(E input, ObjectObjectConsumer<E, MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
Objects.requireNonNull(action); Objects.requireNonNull(action);
@@ -688,7 +720,7 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
} }
@Override @Override
public boolean matchesAny(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) { public boolean matchesAny(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
Objects.requireNonNull(filter); Objects.requireNonNull(filter);
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
for(int i = 0,m=segments.length;i<m;i++) { for(int i = 0,m=segments.length;i<m;i++) {
@@ -710,7 +742,7 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
} }
@Override @Override
public boolean matchesNone(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) { public boolean matchesNone(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
Objects.requireNonNull(filter); Objects.requireNonNull(filter);
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
for(int i = 0,m=segments.length;i<m;i++) { for(int i = 0,m=segments.length;i<m;i++) {
@@ -732,7 +764,7 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
} }
@Override @Override
public boolean matchesAll(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) { public boolean matchesAll(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
Objects.requireNonNull(filter); Objects.requireNonNull(filter);
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
for(int i = 0,m=segments.length;i<m;i++) { for(int i = 0,m=segments.length;i<m;i++) {
@@ -803,7 +835,7 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
} }
@Override @Override
public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) { public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
Objects.requireNonNull(filter); Objects.requireNonNull(filter);
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
for(int i = 0,m=segments.length;i<m;i++) { for(int i = 0,m=segments.length;i<m;i++) {
@@ -825,7 +857,7 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
} }
@Override @Override
public int count(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) { public int count(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
Objects.requireNonNull(filter); Objects.requireNonNull(filter);
int result = 0; int result = 0;
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
@@ -977,6 +1009,26 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
} }
} }
@Override
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
Objects.requireNonNull(action);
int count = 0;
for(int i = 0,m=segments.length;i<m;i++) {
Segment KEY_VALUE_GENERIC_TYPE seg = segments[i];
long stamp = seg.readLock();
try {
int index = seg.firstIndex;
while(index != -1){
action.accept(count++, seg.keys[index]);
index = (int)seg.links[index];
}
}
finally {
seg.unlockRead(stamp);
}
}
}
@Override @Override
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) { public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action); Objects.requireNonNull(action);
@@ -1225,6 +1277,26 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
} }
} }
@Override
public void forEachIndexed(VALUE_BI_FROM_INT_CONSUMER VALUE_GENERIC_TYPE action) {
Objects.requireNonNull(action);
int count = 0;
for(int i = 0,m=segments.length;i<m;i++) {
Segment KEY_VALUE_GENERIC_TYPE seg = segments[i];
long stamp = seg.readLock();
try {
int index = seg.firstIndex;
while(index != -1){
action.accept(count++, seg.values[index]);
index = (int)seg.links[index];
}
}
finally {
seg.unlockRead(stamp);
}
}
}
@Override @Override
public <E> void forEach(E input, VALUE_BI_FROM_OBJECT_CONSUMER VSV_GENERIC_TYPE<E> action) { public <E> void forEach(E input, VALUE_BI_FROM_OBJECT_CONSUMER VSV_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action); Objects.requireNonNull(action);
@@ -2164,14 +2236,14 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
try { try {
int index = findIndex(hash, key); int index = findIndex(hash, key);
if(index < 0) { if(index < 0) {
VALUE_TYPE newValue = valueProvider.VALUE_GET_KEY(); VALUE_TYPE newValue = valueProvider.VALUE_SUPPLY_GET();
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue; if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
insert(-index-1, key, newValue); insert(-index-1, key, newValue);
return newValue; return newValue;
} }
VALUE_TYPE newValue = values[index]; VALUE_TYPE newValue = values[index];
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) { if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
newValue = valueProvider.VALUE_GET_KEY(); newValue = valueProvider.VALUE_SUPPLY_GET();
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue; if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
values[index] = newValue; values[index] = newValue;
} }
@@ -3,16 +3,30 @@ package speiger.src.collections.PACKAGE.maps.impl.customHash;
import java.util.Arrays; import java.util.Arrays;
import java.util.Map; import java.util.Map;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.function.BiFunction; import java.util.function.BiFunction;
import java.util.Objects; import java.util.function.Predicate;
#if !TYPE_OBJECT && JDK_TYPE
import java.util.function.PREDICATE;
#endif
#if !SAME_TYPE && JDK_VALUE && !VALUE_OBJECT
import java.util.function.VALUE_PREDICATE;
#endif
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR; import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
#if !TYPE_OBJECT #if !TYPE_OBJECT
import speiger.src.collections.PACKAGE.functions.CONSUMER; import speiger.src.collections.PACKAGE.functions.CONSUMER;
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER; import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
#endif #endif
#if !TYPE_OBJECT || VALUE_BOOLEAN import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
#if !TYPE_OBJECT && !VALUE_OBJECT
import speiger.src.collections.ints.functions.consumer.IntObjectConsumer;
#endif
#if !SAME_TYPE
import speiger.src.collections.ints.functions.consumer.VALUE_BI_FROM_INT_CONSUMER;
#endif
#if !TYPE_OBJECT && !JDK_TYPE
import speiger.src.collections.PACKAGE.functions.function.PREDICATE; import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
#endif #endif
import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER; import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
@@ -36,18 +50,15 @@ import speiger.src.collections.VALUE_PACKAGE.lists.VALUE_LIST_ITERATOR;
#if !TYPE_OBJECT && !VALUE_OBJECT || !VALUE_OBJECT #if !TYPE_OBJECT && !VALUE_OBJECT || !VALUE_OBJECT
import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer; import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer;
#endif #endif
#if !TYPE_OBJECT || !VALUE_BOOLEAN
#if !VALUE_OBJECT || SAME_TYPE
import speiger.src.collections.objects.functions.function.Object2BooleanFunction;
#endif
#endif
#if !SAME_TYPE #if !SAME_TYPE
#if !TYPE_OBJECT #if !TYPE_OBJECT
import speiger.src.collections.objects.functions.consumer.VALUE_BI_FROM_OBJECT_CONSUMER; import speiger.src.collections.objects.functions.consumer.VALUE_BI_FROM_OBJECT_CONSUMER;
#endif #endif
#if !JDK_VALUE
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE; import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE;
#endif #endif
#endif
#if !TYPE_OBJECT #if !TYPE_OBJECT
#if !VALUE_OBJECT #if !VALUE_OBJECT
import speiger.src.collections.objects.functions.function.ObjectObjectUnaryOperator; import speiger.src.collections.objects.functions.function.ObjectObjectUnaryOperator;
@@ -683,6 +694,18 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
} }
} }
@Override
public void forEachIndexed(IntObjectConsumer<MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
Objects.requireNonNull(action);
if(size() <= 0) return;
int count = 0;
int index = firstIndex;
while(index != -1) {
action.accept(count++, new BasicEntryKV_BRACES(keys[index], values[index]));
index = (int)links[index];
}
}
@Override @Override
public <E> void forEach(E input, ObjectObjectConsumer<E, MAP.Entry KEY_VALUE_GENERIC_TYPE> action) { public <E> void forEach(E input, ObjectObjectConsumer<E, MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
Objects.requireNonNull(action); Objects.requireNonNull(action);
@@ -695,7 +718,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
} }
@Override @Override
public boolean matchesAny(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) { public boolean matchesAny(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
Objects.requireNonNull(filter); Objects.requireNonNull(filter);
if(size() <= 0) return false; if(size() <= 0) return false;
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
@@ -709,7 +732,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
} }
@Override @Override
public boolean matchesNone(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) { public boolean matchesNone(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
Objects.requireNonNull(filter); Objects.requireNonNull(filter);
if(size() <= 0) return true; if(size() <= 0) return true;
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
@@ -723,7 +746,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
} }
@Override @Override
public boolean matchesAll(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) { public boolean matchesAll(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
Objects.requireNonNull(filter); Objects.requireNonNull(filter);
if(size() <= 0) return true; if(size() <= 0) return true;
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
@@ -768,7 +791,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
} }
@Override @Override
public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) { public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
Objects.requireNonNull(filter); Objects.requireNonNull(filter);
if(size() <= 0) return null; if(size() <= 0) return null;
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
@@ -782,7 +805,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
} }
@Override @Override
public int count(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) { public int count(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
Objects.requireNonNull(filter); Objects.requireNonNull(filter);
if(size() <= 0) return 0; if(size() <= 0) return 0;
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
@@ -944,6 +967,18 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
} }
} }
@Override
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
Objects.requireNonNull(action);
if(size() <= 0) return;
int count = 0;
int index = firstIndex;
while(index != -1){
action.accept(count++, keys[index]);
index = (int)links[index];
}
}
@Override @Override
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) { public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action); Objects.requireNonNull(action);
@@ -1107,6 +1142,18 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
} }
} }
@Override
public void forEachIndexed(VALUE_BI_FROM_INT_CONSUMER VALUE_GENERIC_TYPE action) {
Objects.requireNonNull(action);
if(size() <= 0) return;
int count = 0;
int index = firstIndex;
while(index != -1){
action.accept(count++, values[index]);
index = (int)links[index];
}
}
@Override @Override
public <E> void forEach(E input, VALUE_BI_FROM_OBJECT_CONSUMER VSV_GENERIC_TYPE<E> action) { public <E> void forEach(E input, VALUE_BI_FROM_OBJECT_CONSUMER VSV_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action); Objects.requireNonNull(action);
@@ -7,19 +7,35 @@ import java.util.NoSuchElementException;
import java.util.Objects; import java.util.Objects;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.function.BiFunction; import java.util.function.BiFunction;
import java.util.function.Predicate;
#if !TYPE_OBJECT && JDK_TYPE
import java.util.function.PREDICATE;
#endif
#if !SAME_TYPE && JDK_VALUE && !VALUE_OBJECT
import java.util.function.VALUE_PREDICATE;
#endif
#if !TYPE_OBJECT #if !TYPE_OBJECT
import speiger.src.collections.PACKAGE.collections.ITERATOR; import speiger.src.collections.PACKAGE.collections.ITERATOR;
import speiger.src.collections.PACKAGE.functions.CONSUMER; import speiger.src.collections.PACKAGE.functions.CONSUMER;
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER; import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
#endif #endif
import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
#if !TYPE_OBJECT && !VALUE_OBJECT
import speiger.src.collections.ints.functions.consumer.IntObjectConsumer;
#endif
#if !SAME_TYPE
import speiger.src.collections.ints.functions.consumer.VALUE_BI_FROM_INT_CONSUMER;
#endif
import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER; import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
#if !VALUE_BOOLEAN || !JDK_TYPE
import speiger.src.collections.PACKAGE.functions.function.FUNCTION; import speiger.src.collections.PACKAGE.functions.function.FUNCTION;
#endif
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR; import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
#if !SAME_TYPE #if !SAME_TYPE
import speiger.src.collections.PACKAGE.functions.function.SINGLE_UNARY_OPERATOR; import speiger.src.collections.PACKAGE.functions.function.SINGLE_UNARY_OPERATOR;
#endif #endif
#if !TYPE_OBJECT && !VALUE_BOOLEAN #if !TYPE_OBJECT && !VALUE_BOOLEAN && !JDK_TYPE
import speiger.src.collections.PACKAGE.functions.function.PREDICATE; import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
#endif #endif
import speiger.src.collections.PACKAGE.maps.abstracts.ABSTRACT_MAP; import speiger.src.collections.PACKAGE.maps.abstracts.ABSTRACT_MAP;
@@ -39,6 +55,7 @@ import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_UNARY_OPER
#if !TYPE_OBJECT #if !TYPE_OBJECT
import speiger.src.collections.objects.functions.function.ObjectObjectUnaryOperator; import speiger.src.collections.objects.functions.function.ObjectObjectUnaryOperator;
#endif #endif
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ITERATOR; import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ITERATOR;
import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_CONSUMER; import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_CONSUMER;
#endif #endif
@@ -49,18 +66,15 @@ import speiger.src.collections.objects.functions.function.ObjectObjectUnaryOpera
#if !TYPE_OBJECT && !VALUE_OBJECT || !VALUE_OBJECT #if !TYPE_OBJECT && !VALUE_OBJECT || !VALUE_OBJECT
import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer; import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer;
#endif #endif
#if !TYPE_OBJECT || !VALUE_BOOLEAN
#if !VALUE_OBJECT || SAME_TYPE
import speiger.src.collections.objects.functions.function.Object2BooleanFunction;
#endif
#endif
#if !SAME_TYPE #if !SAME_TYPE
#if !TYPE_OBJECT #if !TYPE_OBJECT
import speiger.src.collections.objects.functions.consumer.VALUE_BI_FROM_OBJECT_CONSUMER; import speiger.src.collections.objects.functions.consumer.VALUE_BI_FROM_OBJECT_CONSUMER;
#endif #endif
#if !JDK_VALUE
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE; import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE;
#endif #endif
#endif
import speiger.src.collections.objects.collections.ObjectIterator; import speiger.src.collections.objects.collections.ObjectIterator;
import speiger.src.collections.objects.sets.AbstractObjectSet; import speiger.src.collections.objects.sets.AbstractObjectSet;
import speiger.src.collections.objects.sets.ObjectSet; import speiger.src.collections.objects.sets.ObjectSet;
@@ -558,14 +572,14 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
Objects.requireNonNull(valueProvider); Objects.requireNonNull(valueProvider);
int index = findIndex(key); int index = findIndex(key);
if(index < 0) { if(index < 0) {
VALUE_TYPE newValue = valueProvider.VALUE_GET_KEY(); VALUE_TYPE newValue = valueProvider.VALUE_SUPPLY_GET();
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue; if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
insert(-index-1, key, newValue); insert(-index-1, key, newValue);
return newValue; return newValue;
} }
VALUE_TYPE newValue = values[index]; VALUE_TYPE newValue = values[index];
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) { if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
newValue = valueProvider.VALUE_GET_KEY(); newValue = valueProvider.VALUE_SUPPLY_GET();
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue; if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
values[index] = newValue; values[index] = newValue;
} }
@@ -866,6 +880,16 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
} }
} }
@Override
public void forEachIndexed(IntObjectConsumer<MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
Objects.requireNonNull(action);
if(size() <= 0) return;
if(containsNull) action.accept(0, new BasicEntryKV_BRACES(keys[nullIndex], values[nullIndex]));
for(int i = nullIndex-1, index = containsNull ? 1 : 0;i>=0;i--) {
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) action.accept(index++, new BasicEntryKV_BRACES(keys[i], values[i]));
}
}
@Override @Override
public <E> void forEach(E input, ObjectObjectConsumer<E, MAP.Entry KEY_VALUE_GENERIC_TYPE> action) { public <E> void forEach(E input, ObjectObjectConsumer<E, MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
Objects.requireNonNull(action); Objects.requireNonNull(action);
@@ -877,7 +901,7 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
} }
@Override @Override
public boolean matchesAny(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) { public boolean matchesAny(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
Objects.requireNonNull(filter); Objects.requireNonNull(filter);
if(size() <= 0) return false; if(size() <= 0) return false;
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
@@ -895,7 +919,7 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
} }
@Override @Override
public boolean matchesNone(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) { public boolean matchesNone(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
Objects.requireNonNull(filter); Objects.requireNonNull(filter);
if(size() <= 0) return true; if(size() <= 0) return true;
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
@@ -913,7 +937,7 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
} }
@Override @Override
public boolean matchesAll(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) { public boolean matchesAll(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
Objects.requireNonNull(filter); Objects.requireNonNull(filter);
if(size() <= 0) return true; if(size() <= 0) return true;
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
@@ -964,7 +988,7 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
} }
@Override @Override
public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) { public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
Objects.requireNonNull(filter); Objects.requireNonNull(filter);
if(size() <= 0) return null; if(size() <= 0) return null;
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
@@ -982,7 +1006,7 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
} }
@Override @Override
public int count(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) { public int count(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
Objects.requireNonNull(filter); Objects.requireNonNull(filter);
if(size() <= 0) return 0; if(size() <= 0) return 0;
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
@@ -1103,6 +1127,16 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) action.accept(keys[i]); if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) action.accept(keys[i]);
} }
@Override
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
Objects.requireNonNull(action);
if(size() <= 0) return;
if(containsNull) action.accept(0, keys[nullIndex]);
for(int i = nullIndex-1, index = containsNull ? 1 : 0;i>=0;i--) {
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) action.accept(index++, keys[i]);
}
}
@Override @Override
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) { public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action); Objects.requireNonNull(action);
@@ -1259,6 +1293,16 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) action.accept(values[i]); if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) action.accept(values[i]);
} }
@Override
public void forEachIndexed(VALUE_BI_FROM_INT_CONSUMER VALUE_GENERIC_TYPE action) {
Objects.requireNonNull(action);
if(size() <= 0) return;
if(containsNull) action.accept(0, values[nullIndex]);
for(int i = nullIndex-1, index = containsNull ? 1 : 0;i>=0;i--) {
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) action.accept(index++, values[i]);
}
}
@Override @Override
public <E> void forEach(E input, VALUE_BI_FROM_OBJECT_CONSUMER VSV_GENERIC_TYPE<E> action) { public <E> void forEach(E input, VALUE_BI_FROM_OBJECT_CONSUMER VSV_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action); Objects.requireNonNull(action);
@@ -3,16 +3,30 @@ package speiger.src.collections.PACKAGE.maps.impl.hash;
import java.util.Arrays; import java.util.Arrays;
import java.util.Map; import java.util.Map;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.function.BiFunction; import java.util.function.BiFunction;
import java.util.Objects; import java.util.function.Predicate;
#if !TYPE_OBJECT && JDK_TYPE
import java.util.function.PREDICATE;
#endif
#if !SAME_TYPE && JDK_VALUE && !VALUE_OBJECT
import java.util.function.VALUE_PREDICATE;
#endif
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR; import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
#if !TYPE_OBJECT #if !TYPE_OBJECT
import speiger.src.collections.PACKAGE.functions.CONSUMER; import speiger.src.collections.PACKAGE.functions.CONSUMER;
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER; import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
#endif #endif
#if !TYPE_OBJECT || VALUE_BOOLEAN import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
#if !TYPE_OBJECT && !VALUE_OBJECT
import speiger.src.collections.ints.functions.consumer.IntObjectConsumer;
#endif
#if !SAME_TYPE
import speiger.src.collections.ints.functions.consumer.VALUE_BI_FROM_INT_CONSUMER;
#endif
#if !TYPE_OBJECT && !JDK_TYPE
import speiger.src.collections.PACKAGE.functions.function.PREDICATE; import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
#endif #endif
import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER; import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
@@ -35,18 +49,15 @@ import speiger.src.collections.VALUE_PACKAGE.lists.VALUE_LIST_ITERATOR;
#if !TYPE_OBJECT && !VALUE_OBJECT || !VALUE_OBJECT #if !TYPE_OBJECT && !VALUE_OBJECT || !VALUE_OBJECT
import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer; import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer;
#endif #endif
#if !TYPE_OBJECT || !VALUE_BOOLEAN
#if !VALUE_OBJECT || SAME_TYPE
import speiger.src.collections.objects.functions.function.Object2BooleanFunction;
#endif
#endif
#if !SAME_TYPE #if !SAME_TYPE
#if !TYPE_OBJECT #if !TYPE_OBJECT
import speiger.src.collections.objects.functions.consumer.VALUE_BI_FROM_OBJECT_CONSUMER; import speiger.src.collections.objects.functions.consumer.VALUE_BI_FROM_OBJECT_CONSUMER;
#endif #endif
#if !JDK_VALUE
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE; import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE;
#endif #endif
#endif
#if !TYPE_OBJECT #if !TYPE_OBJECT
#if !VALUE_OBJECT #if !VALUE_OBJECT
import speiger.src.collections.objects.functions.function.ObjectObjectUnaryOperator; import speiger.src.collections.objects.functions.function.ObjectObjectUnaryOperator;
@@ -687,6 +698,18 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
} }
} }
@Override
public void forEachIndexed(IntObjectConsumer<MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
Objects.requireNonNull(action);
if(size() <= 0) return;
int count = 0;
int index = firstIndex;
while(index != -1) {
action.accept(count++, new BasicEntryKV_BRACES(keys[index], values[index]));
index = (int)links[index];
}
}
@Override @Override
public <E> void forEach(E input, ObjectObjectConsumer<E, MAP.Entry KEY_VALUE_GENERIC_TYPE> action) { public <E> void forEach(E input, ObjectObjectConsumer<E, MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
Objects.requireNonNull(action); Objects.requireNonNull(action);
@@ -699,7 +722,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
} }
@Override @Override
public boolean matchesAny(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) { public boolean matchesAny(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
Objects.requireNonNull(filter); Objects.requireNonNull(filter);
if(size() <= 0) return false; if(size() <= 0) return false;
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
@@ -713,7 +736,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
} }
@Override @Override
public boolean matchesNone(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) { public boolean matchesNone(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
Objects.requireNonNull(filter); Objects.requireNonNull(filter);
if(size() <= 0) return true; if(size() <= 0) return true;
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
@@ -727,7 +750,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
} }
@Override @Override
public boolean matchesAll(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) { public boolean matchesAll(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
Objects.requireNonNull(filter); Objects.requireNonNull(filter);
if(size() <= 0) return true; if(size() <= 0) return true;
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
@@ -772,7 +795,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
} }
@Override @Override
public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) { public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
Objects.requireNonNull(filter); Objects.requireNonNull(filter);
if(size() <= 0) return null; if(size() <= 0) return null;
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
@@ -786,7 +809,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
} }
@Override @Override
public int count(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) { public int count(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
Objects.requireNonNull(filter); Objects.requireNonNull(filter);
if(size() <= 0) return 0; if(size() <= 0) return 0;
int result = 0; int result = 0;
@@ -943,6 +966,18 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
} }
} }
@Override
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
Objects.requireNonNull(action);
if(size() <= 0) return;
int count = 0;
int index = firstIndex;
while(index != -1){
action.accept(count++, keys[index]);
index = (int)links[index];
}
}
@Override @Override
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) { public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action); Objects.requireNonNull(action);
@@ -1107,6 +1142,18 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
} }
} }
@Override
public void forEachIndexed(VALUE_BI_FROM_INT_CONSUMER VALUE_GENERIC_TYPE action) {
Objects.requireNonNull(action);
if(size() <= 0) return;
int count = 0;
int index = firstIndex;
while(index != -1){
action.accept(count++, values[index]);
index = (int)links[index];
}
}
@Override @Override
public <E> void forEach(E input, VALUE_BI_FROM_OBJECT_CONSUMER VSV_GENERIC_TYPE<E> action) { public <E> void forEach(E input, VALUE_BI_FROM_OBJECT_CONSUMER VSV_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action); Objects.requireNonNull(action);
@@ -7,19 +7,35 @@ import java.util.NoSuchElementException;
import java.util.Objects; import java.util.Objects;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.function.BiFunction; import java.util.function.BiFunction;
import java.util.function.Predicate;
#if !TYPE_OBJECT && JDK_TYPE
import java.util.function.PREDICATE;
#endif
#if !SAME_TYPE && JDK_VALUE && !VALUE_OBJECT
import java.util.function.VALUE_PREDICATE;
#endif
#if !TYPE_OBJECT #if !TYPE_OBJECT
import speiger.src.collections.PACKAGE.collections.ITERATOR; import speiger.src.collections.PACKAGE.collections.ITERATOR;
import speiger.src.collections.PACKAGE.functions.CONSUMER; import speiger.src.collections.PACKAGE.functions.CONSUMER;
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER; import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
#endif #endif
import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
#if !TYPE_OBJECT && !VALUE_OBJECT
import speiger.src.collections.ints.functions.consumer.IntObjectConsumer;
#endif
#if !SAME_TYPE
import speiger.src.collections.ints.functions.consumer.VALUE_BI_FROM_INT_CONSUMER;
#endif
import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER; import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
#if !VALUE_BOOLEAN || !JDK_TYPE
import speiger.src.collections.PACKAGE.functions.function.FUNCTION; import speiger.src.collections.PACKAGE.functions.function.FUNCTION;
#endif
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR; import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
#if !SAME_TYPE #if !SAME_TYPE
import speiger.src.collections.PACKAGE.functions.function.SINGLE_UNARY_OPERATOR; import speiger.src.collections.PACKAGE.functions.function.SINGLE_UNARY_OPERATOR;
#endif #endif
#if !TYPE_OBJECT && !VALUE_BOOLEAN #if !TYPE_OBJECT && !VALUE_BOOLEAN && !JDK_TYPE
import speiger.src.collections.PACKAGE.functions.function.PREDICATE; import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
#endif #endif
import speiger.src.collections.PACKAGE.maps.abstracts.ABSTRACT_MAP; import speiger.src.collections.PACKAGE.maps.abstracts.ABSTRACT_MAP;
@@ -48,18 +64,15 @@ import speiger.src.collections.objects.functions.function.ObjectObjectUnaryOpera
#if !TYPE_OBJECT && !VALUE_OBJECT || !VALUE_OBJECT #if !TYPE_OBJECT && !VALUE_OBJECT || !VALUE_OBJECT
import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer; import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer;
#endif #endif
#if !TYPE_OBJECT || !VALUE_BOOLEAN
#if !VALUE_OBJECT || SAME_TYPE
import speiger.src.collections.objects.functions.function.Object2BooleanFunction;
#endif
#endif
#if !SAME_TYPE #if !SAME_TYPE
#if !TYPE_OBJECT #if !TYPE_OBJECT
import speiger.src.collections.objects.functions.consumer.VALUE_BI_FROM_OBJECT_CONSUMER; import speiger.src.collections.objects.functions.consumer.VALUE_BI_FROM_OBJECT_CONSUMER;
#endif #endif
#if !JDK_VALUE
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE; import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE;
#endif #endif
#endif
import speiger.src.collections.objects.collections.ObjectIterator; import speiger.src.collections.objects.collections.ObjectIterator;
import speiger.src.collections.objects.sets.AbstractObjectSet; import speiger.src.collections.objects.sets.AbstractObjectSet;
import speiger.src.collections.objects.sets.ObjectSet; import speiger.src.collections.objects.sets.ObjectSet;
@@ -519,14 +532,14 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
Objects.requireNonNull(valueProvider); Objects.requireNonNull(valueProvider);
int index = findIndex(key); int index = findIndex(key);
if(index < 0) { if(index < 0) {
VALUE_TYPE newValue = valueProvider.VALUE_GET_KEY(); VALUE_TYPE newValue = valueProvider.VALUE_SUPPLY_GET();
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue; if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
insert(-index-1, key, newValue); insert(-index-1, key, newValue);
return newValue; return newValue;
} }
VALUE_TYPE newValue = values[index]; VALUE_TYPE newValue = values[index];
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) { if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
newValue = valueProvider.VALUE_GET_KEY(); newValue = valueProvider.VALUE_SUPPLY_GET();
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue; if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
values[index] = newValue; values[index] = newValue;
} }
@@ -826,6 +839,16 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
} }
} }
@Override
public void forEachIndexed(IntObjectConsumer<MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
Objects.requireNonNull(action);
if(size() <= 0) return;
if(containsNull) action.accept(0, new BasicEntryKV_BRACES(keys[nullIndex], values[nullIndex]));
for(int i = nullIndex-1, index = containsNull ? 1 : 0;i>=0;i--) {
if(KEY_EQUALS_NOT_NULL(keys[i])) action.accept(index++, new BasicEntryKV_BRACES(keys[i], values[i]));
}
}
@Override @Override
public <E> void forEach(E input, ObjectObjectConsumer<E, MAP.Entry KEY_VALUE_GENERIC_TYPE> action) { public <E> void forEach(E input, ObjectObjectConsumer<E, MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
Objects.requireNonNull(action); Objects.requireNonNull(action);
@@ -837,7 +860,7 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
} }
@Override @Override
public boolean matchesAny(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) { public boolean matchesAny(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
Objects.requireNonNull(filter); Objects.requireNonNull(filter);
if(size() <= 0) return false; if(size() <= 0) return false;
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
@@ -855,7 +878,7 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
} }
@Override @Override
public boolean matchesNone(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) { public boolean matchesNone(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
Objects.requireNonNull(filter); Objects.requireNonNull(filter);
if(size() <= 0) return true; if(size() <= 0) return true;
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
@@ -873,7 +896,7 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
} }
@Override @Override
public boolean matchesAll(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) { public boolean matchesAll(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
Objects.requireNonNull(filter); Objects.requireNonNull(filter);
if(size() <= 0) return true; if(size() <= 0) return true;
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
@@ -924,7 +947,7 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
} }
@Override @Override
public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) { public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
Objects.requireNonNull(filter); Objects.requireNonNull(filter);
if(size() <= 0) return null; if(size() <= 0) return null;
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
@@ -942,7 +965,7 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
} }
@Override @Override
public int count(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) { public int count(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
Objects.requireNonNull(filter); Objects.requireNonNull(filter);
if(size() <= 0) return 0; if(size() <= 0) return 0;
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
@@ -1059,6 +1082,16 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
if(KEY_EQUALS_NOT_NULL(keys[i])) action.accept(keys[i]); if(KEY_EQUALS_NOT_NULL(keys[i])) action.accept(keys[i]);
} }
@Override
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
Objects.requireNonNull(action);
if(size() <= 0) return;
if(containsNull) action.accept(0, keys[nullIndex]);
for(int i = nullIndex-1, index = containsNull ? 1 : 0;i>=0;i--) {
if(KEY_EQUALS_NOT_NULL(keys[i])) action.accept(index++, keys[i]);
}
}
@Override @Override
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) { public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action); Objects.requireNonNull(action);
@@ -1215,6 +1248,16 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
if(KEY_EQUALS_NOT_NULL(keys[i])) action.accept(values[i]); if(KEY_EQUALS_NOT_NULL(keys[i])) action.accept(values[i]);
} }
@Override
public void forEachIndexed(VALUE_BI_FROM_INT_CONSUMER VALUE_GENERIC_TYPE action) {
Objects.requireNonNull(action);
if(size() <= 0) return;
if(containsNull) action.accept(0, values[nullIndex]);
for(int i = nullIndex-1, index = containsNull ? 1 : 0;i>=0;i--) {
if(KEY_EQUALS_NOT_NULL(keys[i])) action.accept(index++, values[i]);
}
}
@Override @Override
public <E> void forEach(E input, VALUE_BI_FROM_OBJECT_CONSUMER VSV_GENERIC_TYPE<E> action) { public <E> void forEach(E input, VALUE_BI_FROM_OBJECT_CONSUMER VSV_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action); Objects.requireNonNull(action);
@@ -6,17 +6,33 @@ import java.util.NoSuchElementException;
import java.util.Objects; import java.util.Objects;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.function.BiFunction; import java.util.function.BiFunction;
import java.util.function.Predicate;
#if !TYPE_OBJECT && JDK_TYPE
import java.util.function.PREDICATE;
#endif
#if !SAME_TYPE && JDK_VALUE && !VALUE_OBJECT
import java.util.function.VALUE_PREDICATE;
#endif
#if !TYPE_OBJECT #if !TYPE_OBJECT
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR; import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
import speiger.src.collections.PACKAGE.functions.CONSUMER; import speiger.src.collections.PACKAGE.functions.CONSUMER;
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER; import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
#endif #endif
#if !TYPE_OBJECT && !VALUE_BOOLEAN import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
#if !TYPE_OBJECT && !VALUE_OBJECT
import speiger.src.collections.ints.functions.consumer.IntObjectConsumer;
#endif
#if !SAME_TYPE
import speiger.src.collections.ints.functions.consumer.VALUE_BI_FROM_INT_CONSUMER;
#endif
#if !TYPE_OBJECT && !VALUE_BOOLEAN && !JDK_TYPE
import speiger.src.collections.PACKAGE.functions.function.PREDICATE; import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
#endif #endif
import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER; import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
#if !VALUE_BOOLEAN || !JDK_TYPE
import speiger.src.collections.PACKAGE.functions.function.FUNCTION; import speiger.src.collections.PACKAGE.functions.function.FUNCTION;
#endif
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR; import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
#if !SAME_TYPE #if !SAME_TYPE
import speiger.src.collections.PACKAGE.functions.function.SINGLE_UNARY_OPERATOR; import speiger.src.collections.PACKAGE.functions.function.SINGLE_UNARY_OPERATOR;
@@ -34,18 +50,15 @@ import speiger.src.collections.PACKAGE.utils.ARRAYS;
#if !TYPE_OBJECT && !VALUE_OBJECT || !VALUE_OBJECT #if !TYPE_OBJECT && !VALUE_OBJECT || !VALUE_OBJECT
import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer; import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer;
#endif #endif
#if !TYPE_OBJECT || !VALUE_BOOLEAN
#if !VALUE_OBJECT || SAME_TYPE
import speiger.src.collections.objects.functions.function.Object2BooleanFunction;
#endif
#endif
#if !SAME_TYPE #if !SAME_TYPE
#if !TYPE_OBJECT #if !TYPE_OBJECT
import speiger.src.collections.objects.functions.consumer.VALUE_BI_FROM_OBJECT_CONSUMER; import speiger.src.collections.objects.functions.consumer.VALUE_BI_FROM_OBJECT_CONSUMER;
#endif #endif
#if !JDK_VALUE
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE; import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE;
#endif #endif
#endif
#if !TYPE_OBJECT #if !TYPE_OBJECT
import speiger.src.collections.PACKAGE.sets.ABSTRACT_SET; import speiger.src.collections.PACKAGE.sets.ABSTRACT_SET;
#endif #endif
@@ -658,6 +671,18 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
} }
} }
@Override
public void forEachIndexed(IntObjectConsumer<MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
Objects.requireNonNull(action);
if(size() <= 0) return;
int count = 0;
int index = firstIndex;
while(index != -1) {
action.accept(count++, new BasicEntryKV_BRACES(keys[index], values[index]));
index = (int)links[index];
}
}
@Override @Override
public <E> void forEach(E input, ObjectObjectConsumer<E, MAP.Entry KEY_VALUE_GENERIC_TYPE> action) { public <E> void forEach(E input, ObjectObjectConsumer<E, MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
Objects.requireNonNull(action); Objects.requireNonNull(action);
@@ -670,7 +695,7 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
} }
@Override @Override
public boolean matchesAny(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) { public boolean matchesAny(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
Objects.requireNonNull(filter); Objects.requireNonNull(filter);
if(size() <= 0) return false; if(size() <= 0) return false;
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
@@ -684,7 +709,7 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
} }
@Override @Override
public boolean matchesNone(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) { public boolean matchesNone(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
Objects.requireNonNull(filter); Objects.requireNonNull(filter);
if(size() <= 0) return true; if(size() <= 0) return true;
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
@@ -698,7 +723,7 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
} }
@Override @Override
public boolean matchesAll(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) { public boolean matchesAll(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
Objects.requireNonNull(filter); Objects.requireNonNull(filter);
if(size() <= 0) return true; if(size() <= 0) return true;
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
@@ -743,7 +768,7 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
} }
@Override @Override
public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) { public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
Objects.requireNonNull(filter); Objects.requireNonNull(filter);
if(size() <= 0) return null; if(size() <= 0) return null;
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
@@ -757,7 +782,7 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
} }
@Override @Override
public int count(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) { public int count(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
Objects.requireNonNull(filter); Objects.requireNonNull(filter);
if(size() <= 0) return 0; if(size() <= 0) return 0;
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
@@ -886,6 +911,18 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
} }
} }
@Override
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
Objects.requireNonNull(action);
if(size() <= 0) return;
int count = 0;
int index = firstIndex;
while(index != -1){
action.accept(count++, keys[index]);
index = (int)links[index];
}
}
@Override @Override
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) { public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action); Objects.requireNonNull(action);
@@ -1047,6 +1084,18 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
} }
} }
@Override
public void forEachIndexed(VALUE_BI_FROM_INT_CONSUMER VALUE_GENERIC_TYPE action) {
Objects.requireNonNull(action);
if(size() <= 0) return;
int count = 0;
int index = firstIndex;
while(index != -1){
action.accept(count++, values[index]);
index = (int)links[index];
}
}
@Override @Override
public <E> void forEach(E input, VALUE_BI_FROM_OBJECT_CONSUMER VSV_GENERIC_TYPE<E> action) { public <E> void forEach(E input, VALUE_BI_FROM_OBJECT_CONSUMER VSV_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action); Objects.requireNonNull(action);
@@ -6,17 +6,33 @@ import java.util.NoSuchElementException;
import java.util.Objects; import java.util.Objects;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.function.BiFunction; import java.util.function.BiFunction;
import java.util.function.Predicate;
#if !TYPE_OBJECT && JDK_TYPE
import java.util.function.PREDICATE;
#endif
#if !SAME_TYPE && JDK_VALUE && !VALUE_OBJECT
import java.util.function.VALUE_PREDICATE;
#endif
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR; import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
#if !TYPE_OBJECT #if !TYPE_OBJECT
import speiger.src.collections.PACKAGE.functions.CONSUMER; import speiger.src.collections.PACKAGE.functions.CONSUMER;
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER; import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
#endif #endif
#if !TYPE_OBJECT && !VALUE_BOOLEAN import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
#if !TYPE_OBJECT && !VALUE_OBJECT
import speiger.src.collections.ints.functions.consumer.IntObjectConsumer;
#endif
#if !SAME_TYPE
import speiger.src.collections.ints.functions.consumer.VALUE_BI_FROM_INT_CONSUMER;
#endif
#if !TYPE_OBJECT && !VALUE_BOOLEAN && !JDK_TYPE
import speiger.src.collections.PACKAGE.functions.function.PREDICATE; import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
#endif #endif
import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER; import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
#if !VALUE_BOOLEAN || !JDK_TYPE
import speiger.src.collections.PACKAGE.functions.function.FUNCTION; import speiger.src.collections.PACKAGE.functions.function.FUNCTION;
#endif
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR; import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
#if !SAME_TYPE #if !SAME_TYPE
import speiger.src.collections.PACKAGE.functions.function.SINGLE_UNARY_OPERATOR; import speiger.src.collections.PACKAGE.functions.function.SINGLE_UNARY_OPERATOR;
@@ -41,18 +57,15 @@ import speiger.src.collections.VALUE_PACKAGE.lists.VALUE_LIST_ITERATOR;
#if !TYPE_OBJECT && !VALUE_OBJECT || !VALUE_OBJECT #if !TYPE_OBJECT && !VALUE_OBJECT || !VALUE_OBJECT
import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer; import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer;
#endif #endif
#if !TYPE_OBJECT || !VALUE_BOOLEAN
#if !VALUE_OBJECT || SAME_TYPE
import speiger.src.collections.objects.functions.function.Object2BooleanFunction;
#endif
#endif
#if !SAME_TYPE #if !SAME_TYPE
#if VALUE_OBJECT #if VALUE_OBJECT
import speiger.src.collections.objects.functions.consumer.VALUE_BI_FROM_OBJECT_CONSUMER; import speiger.src.collections.objects.functions.consumer.VALUE_BI_FROM_OBJECT_CONSUMER;
#endif #endif
#if !JDK_VALUE
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE; import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE;
#endif #endif
#endif
#if !VALUE_OBJECT #if !VALUE_OBJECT
import speiger.src.collections.objects.collections.ObjectIterator; import speiger.src.collections.objects.collections.ObjectIterator;
#endif #endif
@@ -517,14 +530,14 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
Objects.requireNonNull(valueProvider); Objects.requireNonNull(valueProvider);
int index = findIndex(key); int index = findIndex(key);
if(index == -1) { if(index == -1) {
VALUE_TYPE newValue = valueProvider.VALUE_GET_KEY(); VALUE_TYPE newValue = valueProvider.VALUE_SUPPLY_GET();
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue; if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
insertIndex(size++, key, newValue); insertIndex(size++, key, newValue);
return newValue; return newValue;
} }
VALUE_TYPE newValue = values[index]; VALUE_TYPE newValue = values[index];
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) { if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
newValue = valueProvider.VALUE_GET_KEY(); newValue = valueProvider.VALUE_SUPPLY_GET();
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue; if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
values[index] = newValue; values[index] = newValue;
} }
@@ -787,6 +800,14 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
} }
} }
@Override
public void forEachIndexed(IntObjectConsumer<MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
Objects.requireNonNull(action);
for(int i = 0;i<size;i++) {
action.accept(i, new BasicEntryKV_BRACES(keys[i], values[i]));
}
}
@Override @Override
public <E> void forEach(E input, ObjectObjectConsumer<E, MAP.Entry KEY_VALUE_GENERIC_TYPE> action) { public <E> void forEach(E input, ObjectObjectConsumer<E, MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
Objects.requireNonNull(action); Objects.requireNonNull(action);
@@ -796,7 +817,7 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
} }
@Override @Override
public boolean matchesAny(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) { public boolean matchesAny(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
Objects.requireNonNull(filter); Objects.requireNonNull(filter);
if(size() <= 0) return false; if(size() <= 0) return false;
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
@@ -808,7 +829,7 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
} }
@Override @Override
public boolean matchesNone(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) { public boolean matchesNone(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
Objects.requireNonNull(filter); Objects.requireNonNull(filter);
if(size() <= 0) return true; if(size() <= 0) return true;
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
@@ -820,7 +841,7 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
} }
@Override @Override
public boolean matchesAll(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) { public boolean matchesAll(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
Objects.requireNonNull(filter); Objects.requireNonNull(filter);
if(size() <= 0) return true; if(size() <= 0) return true;
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
@@ -858,7 +879,7 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
} }
@Override @Override
public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) { public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
Objects.requireNonNull(filter); Objects.requireNonNull(filter);
if(size() <= 0) return null; if(size() <= 0) return null;
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
@@ -870,7 +891,7 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
} }
@Override @Override
public int count(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) { public int count(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
Objects.requireNonNull(filter); Objects.requireNonNull(filter);
if(size() <= 0) return 0; if(size() <= 0) return 0;
int result = 0; int result = 0;
@@ -985,11 +1006,16 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
for(int i = 0;i<size;action.accept(keys[i++])); for(int i = 0;i<size;action.accept(keys[i++]));
} }
@Override
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
Objects.requireNonNull(action);
for(int i = 0;i<size;action.accept(i, keys[i++]));
}
@Override @Override
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) { public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action); Objects.requireNonNull(action);
for(int i = 0;i<size;action.accept(input, keys[i++])); for(int i = 0;i<size;action.accept(input, keys[i++]));
} }
@Override @Override
@@ -1119,6 +1145,12 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
for(int i = 0;i<size;action.accept(values[i++])); for(int i = 0;i<size;action.accept(values[i++]));
} }
@Override
public void forEachIndexed(VALUE_BI_FROM_INT_CONSUMER VALUE_GENERIC_TYPE action) {
Objects.requireNonNull(action);
for(int i = 0;i<size;action.accept(i, values[i++]));
}
@Override @Override
public boolean matchesAny(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) { public boolean matchesAny(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
Objects.requireNonNull(filter); Objects.requireNonNull(filter);
@@ -5,6 +5,10 @@ import java.util.Map;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import java.util.Objects; import java.util.Objects;
import java.util.function.Consumer; import java.util.function.Consumer;
#if VALUE_BOOLEAN
import java.util.function.Predicate;
#endif
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ABSTRACT_COLLECTION; import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ABSTRACT_COLLECTION;
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_COLLECTION; import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_COLLECTION;
@@ -18,7 +22,9 @@ import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
#if !VALUE_OBJECT #if !VALUE_OBJECT
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR; import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
#endif #endif
#if !VALUE_BOOLEAN
import speiger.src.collections.PACKAGE.functions.function.FUNCTION; import speiger.src.collections.PACKAGE.functions.function.FUNCTION;
#endif
import speiger.src.collections.objects.maps.abstracts.ABSTRACT_MAP; import speiger.src.collections.objects.maps.abstracts.ABSTRACT_MAP;
import speiger.src.collections.objects.maps.interfaces.MAP; import speiger.src.collections.objects.maps.interfaces.MAP;
import speiger.src.collections.objects.sets.AbstractObjectSet; import speiger.src.collections.objects.sets.AbstractObjectSet;
@@ -395,7 +401,7 @@ public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE
public VALUE_TYPE SUPPLY_IF_ABSENT(T key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) { public VALUE_TYPE SUPPLY_IF_ABSENT(T key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
int index = key.ordinal(); int index = key.ordinal();
if(!isSet(index)) { if(!isSet(index)) {
VALUE_TYPE newValue = valueProvider.VALUE_GET_KEY(); VALUE_TYPE newValue = valueProvider.VALUE_SUPPLY_GET();
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue; if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
set(index); set(index);
values[index] = newValue; values[index] = newValue;
@@ -403,7 +409,7 @@ public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE
} }
VALUE_TYPE newValue = values[index]; VALUE_TYPE newValue = values[index];
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) { if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
newValue = valueProvider.VALUE_GET_KEY(); newValue = valueProvider.VALUE_SUPPLY_GET();
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue; if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
values[index] = newValue; values[index] = newValue;
} }
@@ -9,6 +9,14 @@ import java.util.Objects;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.function.BiFunction; import java.util.function.BiFunction;
import java.util.function.Predicate;
#if !TYPE_OBJECT && JDK_TYPE
import java.util.function.PREDICATE;
#endif
#if !SAME_TYPE && JDK_VALUE && !VALUE_OBJECT
import java.util.function.VALUE_PREDICATE;
#endif
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR; import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
#if !TYPE_OBJECT #if !TYPE_OBJECT
@@ -16,11 +24,20 @@ import speiger.src.collections.PACKAGE.functions.COMPARATOR;
import speiger.src.collections.PACKAGE.functions.CONSUMER; import speiger.src.collections.PACKAGE.functions.CONSUMER;
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER; import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
#endif #endif
#if !TYPE_OBJECT && !VALUE_BOOLEAN import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
import speiger.src.collections.PACKAGE.functions.function.PREDICATE; #if !TYPE_OBJECT && !VALUE_OBJECT
import speiger.src.collections.ints.functions.consumer.IntObjectConsumer;
#endif
#if !SAME_TYPE
import speiger.src.collections.ints.functions.consumer.VALUE_BI_FROM_INT_CONSUMER;
#endif
#if !VALUE_BOOLEAN || !JDK_TYPE
import speiger.src.collections.PACKAGE.functions.function.FUNCTION;
#endif #endif
import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER; import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
import speiger.src.collections.PACKAGE.functions.function.FUNCTION; #if !TYPE_OBJECT && !VALUE_BOOLEAN && !JDK_TYPE
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
#endif
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR; import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
#if !SAME_TYPE #if !SAME_TYPE
import speiger.src.collections.PACKAGE.functions.function.SINGLE_UNARY_OPERATOR; import speiger.src.collections.PACKAGE.functions.function.SINGLE_UNARY_OPERATOR;
@@ -47,18 +64,15 @@ import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_CONSUMER;
#if !TYPE_OBJECT && !VALUE_OBJECT || !VALUE_OBJECT #if !TYPE_OBJECT && !VALUE_OBJECT || !VALUE_OBJECT
import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer; import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer;
#endif #endif
#if !TYPE_OBJECT || !VALUE_BOOLEAN
#if !VALUE_OBJECT || SAME_TYPE
import speiger.src.collections.objects.functions.function.Object2BooleanFunction;
#endif
#endif
#if !SAME_TYPE #if !SAME_TYPE
#if !TYPE_OBJECT #if !TYPE_OBJECT
import speiger.src.collections.objects.functions.consumer.VALUE_BI_FROM_OBJECT_CONSUMER; import speiger.src.collections.objects.functions.consumer.VALUE_BI_FROM_OBJECT_CONSUMER;
#endif #endif
#if !JDK_VALUE
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE; import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE;
#endif #endif
#endif
#if !TYPE_OBJECT && !VALUE_OBJECT #if !TYPE_OBJECT && !VALUE_OBJECT
import speiger.src.collections.objects.collections.ObjectBidirectionalIterator; import speiger.src.collections.objects.collections.ObjectBidirectionalIterator;
#endif #endif
@@ -576,13 +590,13 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
#endif #endif
Node KEY_VALUE_GENERIC_TYPE entry = findNode(key); Node KEY_VALUE_GENERIC_TYPE entry = findNode(key);
if(entry == null) { if(entry == null) {
VALUE_TYPE newValue = valueProvider.VALUE_GET_KEY(); VALUE_TYPE newValue = valueProvider.VALUE_SUPPLY_GET();
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue; if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
put(key, newValue); put(key, newValue);
return newValue; return newValue;
} }
if(VALUE_EQUALS(entry.value, getDefaultReturnValue())) { if(VALUE_EQUALS(entry.value, getDefaultReturnValue())) {
VALUE_TYPE newValue = valueProvider.VALUE_GET_KEY(); VALUE_TYPE newValue = valueProvider.VALUE_SUPPLY_GET();
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue; if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
entry.value = newValue; entry.value = newValue;
} }
@@ -1146,6 +1160,14 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
action.accept(entry.key); action.accept(entry.key);
} }
@Override
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
Objects.requireNonNull(action);
int index = 0;
for(Node KEY_VALUE_GENERIC_TYPE entry = start(), end = end();entry != null && (end == null || (end != previous(entry)));entry = next(entry))
action.accept(index++, entry.key);
}
@Override @Override
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) { public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action); Objects.requireNonNull(action);
@@ -1834,6 +1856,14 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
action.accept(new BasicEntryKV_BRACES(entry.key, entry.value)); action.accept(new BasicEntryKV_BRACES(entry.key, entry.value));
} }
@Override
public void forEachIndexed(IntObjectConsumer<MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
Objects.requireNonNull(action);
int index = 0;
for(Node KEY_VALUE_GENERIC_TYPE entry = subLowest(), last = subHighest();entry != null && (last == null || last != previous(entry));entry = next(entry))
action.accept(index++, new BasicEntryKV_BRACES(entry.key, entry.value));
}
@Override @Override
public <E> void forEach(E input, ObjectObjectConsumer<E, MAP.Entry KEY_VALUE_GENERIC_TYPE> action) { public <E> void forEach(E input, ObjectObjectConsumer<E, MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
Objects.requireNonNull(action); Objects.requireNonNull(action);
@@ -1842,7 +1872,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
} }
@Override @Override
public boolean matchesAny(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) { public boolean matchesAny(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
Objects.requireNonNull(filter); Objects.requireNonNull(filter);
if(size() <= 0) return false; if(size() <= 0) return false;
BasicEntry KEY_VALUE_GENERIC_TYPE subEntry = new BasicEntryKV_BRACES(); BasicEntry KEY_VALUE_GENERIC_TYPE subEntry = new BasicEntryKV_BRACES();
@@ -1854,7 +1884,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
} }
@Override @Override
public boolean matchesNone(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) { public boolean matchesNone(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
Objects.requireNonNull(filter); Objects.requireNonNull(filter);
if(size() <= 0) return true; if(size() <= 0) return true;
BasicEntry KEY_VALUE_GENERIC_TYPE subEntry = new BasicEntryKV_BRACES(); BasicEntry KEY_VALUE_GENERIC_TYPE subEntry = new BasicEntryKV_BRACES();
@@ -1866,7 +1896,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
} }
@Override @Override
public boolean matchesAll(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) { public boolean matchesAll(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
Objects.requireNonNull(filter); Objects.requireNonNull(filter);
if(size() <= 0) return true; if(size() <= 0) return true;
BasicEntry KEY_VALUE_GENERIC_TYPE subEntry = new BasicEntryKV_BRACES(); BasicEntry KEY_VALUE_GENERIC_TYPE subEntry = new BasicEntryKV_BRACES();
@@ -1904,7 +1934,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
} }
@Override @Override
public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) { public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
Objects.requireNonNull(filter); Objects.requireNonNull(filter);
if(size() <= 0) return null; if(size() <= 0) return null;
BasicEntry KEY_VALUE_GENERIC_TYPE subEntry = new BasicEntryKV_BRACES(); BasicEntry KEY_VALUE_GENERIC_TYPE subEntry = new BasicEntryKV_BRACES();
@@ -1916,7 +1946,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
} }
@Override @Override
public int count(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) { public int count(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
Objects.requireNonNull(filter); Objects.requireNonNull(filter);
if(size() <= 0) return 0; if(size() <= 0) return 0;
int result = 0; int result = 0;
@@ -1966,6 +1996,14 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
action.accept(entry.value); action.accept(entry.value);
} }
@Override
public void forEachIndexed(VALUE_BI_FROM_INT_CONSUMER VALUE_GENERIC_TYPE action) {
Objects.requireNonNull(action);
int index = 0;
for(Node KEY_VALUE_GENERIC_TYPE entry = subLowest(), last = subHighest();entry != null && (last == null || last != previous(entry));entry = next(entry))
action.accept(index++, entry.value);
}
@Override @Override
public <E> void forEach(E input, VALUE_BI_FROM_OBJECT_CONSUMER VSV_GENERIC_TYPE<E> action) { public <E> void forEach(E input, VALUE_BI_FROM_OBJECT_CONSUMER VSV_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action); Objects.requireNonNull(action);
@@ -2314,6 +2352,14 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
action.accept(entry.value); action.accept(entry.value);
} }
@Override
public void forEachIndexed(VALUE_BI_FROM_INT_CONSUMER VALUE_GENERIC_TYPE action) {
Objects.requireNonNull(action);
int index = 0;
for(Node KEY_VALUE_GENERIC_TYPE entry = first;entry != null;entry = entry.next())
action.accept(index++, entry.value);
}
@Override @Override
public <E> void forEach(E input, VALUE_BI_FROM_OBJECT_CONSUMER VSV_GENERIC_TYPE<E> action) { public <E> void forEach(E input, VALUE_BI_FROM_OBJECT_CONSUMER VSV_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action); Objects.requireNonNull(action);
@@ -2471,6 +2517,14 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
action.accept(new BasicEntryKV_BRACES(entry.key, entry.value)); action.accept(new BasicEntryKV_BRACES(entry.key, entry.value));
} }
@Override
public void forEachIndexed(IntObjectConsumer<MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
Objects.requireNonNull(action);
int index = 0;
for(Node KEY_VALUE_GENERIC_TYPE entry = first;entry != null;entry = entry.next())
action.accept(index++, new BasicEntryKV_BRACES(entry.key, entry.value));
}
@Override @Override
public <E> void forEach(E input, ObjectObjectConsumer<E, MAP.Entry KEY_VALUE_GENERIC_TYPE> action) { public <E> void forEach(E input, ObjectObjectConsumer<E, MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
Objects.requireNonNull(action); Objects.requireNonNull(action);
@@ -2479,7 +2533,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
} }
@Override @Override
public boolean matchesAny(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) { public boolean matchesAny(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
Objects.requireNonNull(filter); Objects.requireNonNull(filter);
if(size() <= 0) return false; if(size() <= 0) return false;
BasicEntry KEY_VALUE_GENERIC_TYPE subEntry = new BasicEntryKV_BRACES(); BasicEntry KEY_VALUE_GENERIC_TYPE subEntry = new BasicEntryKV_BRACES();
@@ -2491,7 +2545,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
} }
@Override @Override
public boolean matchesNone(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) { public boolean matchesNone(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
Objects.requireNonNull(filter); Objects.requireNonNull(filter);
if(size() <= 0) return true; if(size() <= 0) return true;
BasicEntry KEY_VALUE_GENERIC_TYPE subEntry = new BasicEntryKV_BRACES(); BasicEntry KEY_VALUE_GENERIC_TYPE subEntry = new BasicEntryKV_BRACES();
@@ -2503,7 +2557,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
} }
@Override @Override
public boolean matchesAll(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) { public boolean matchesAll(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
Objects.requireNonNull(filter); Objects.requireNonNull(filter);
if(size() <= 0) return true; if(size() <= 0) return true;
BasicEntry KEY_VALUE_GENERIC_TYPE subEntry = new BasicEntryKV_BRACES(); BasicEntry KEY_VALUE_GENERIC_TYPE subEntry = new BasicEntryKV_BRACES();
@@ -2541,7 +2595,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
} }
@Override @Override
public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) { public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
Objects.requireNonNull(filter); Objects.requireNonNull(filter);
if(size() <= 0) return null; if(size() <= 0) return null;
BasicEntry KEY_VALUE_GENERIC_TYPE subEntry = new BasicEntryKV_BRACES(); BasicEntry KEY_VALUE_GENERIC_TYPE subEntry = new BasicEntryKV_BRACES();
@@ -2553,7 +2607,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
} }
@Override @Override
public int count(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) { public int count(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
Objects.requireNonNull(filter); Objects.requireNonNull(filter);
if(size() <= 0) return 0; if(size() <= 0) return 0;
int result = 0; int result = 0;
@@ -9,6 +9,13 @@ import java.util.Objects;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.function.BiFunction; import java.util.function.BiFunction;
import java.util.function.Predicate;
#if !TYPE_OBJECT && JDK_TYPE
import java.util.function.PREDICATE;
#endif
#if !SAME_TYPE && JDK_VALUE && !VALUE_OBJECT
import java.util.function.VALUE_PREDICATE;
#endif
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR; import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
#if !TYPE_OBJECT #if !TYPE_OBJECT
@@ -16,11 +23,20 @@ import speiger.src.collections.PACKAGE.functions.COMPARATOR;
import speiger.src.collections.PACKAGE.functions.CONSUMER; import speiger.src.collections.PACKAGE.functions.CONSUMER;
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER; import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
#endif #endif
#if !TYPE_OBJECT && !VALUE_BOOLEAN import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
import speiger.src.collections.PACKAGE.functions.function.PREDICATE; #if !TYPE_OBJECT && !VALUE_OBJECT
import speiger.src.collections.ints.functions.consumer.IntObjectConsumer;
#endif
#if !SAME_TYPE
import speiger.src.collections.ints.functions.consumer.VALUE_BI_FROM_INT_CONSUMER;
#endif
#if !VALUE_BOOLEAN || !JDK_TYPE
import speiger.src.collections.PACKAGE.functions.function.FUNCTION;
#endif #endif
import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER; import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
import speiger.src.collections.PACKAGE.functions.function.FUNCTION; #if !TYPE_OBJECT && !VALUE_BOOLEAN && !JDK_TYPE
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
#endif
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR; import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
#if !SAME_TYPE #if !SAME_TYPE
import speiger.src.collections.PACKAGE.functions.function.SINGLE_UNARY_OPERATOR; import speiger.src.collections.PACKAGE.functions.function.SINGLE_UNARY_OPERATOR;
@@ -47,18 +63,15 @@ import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_CONSUMER;
#if !TYPE_OBJECT && !VALUE_OBJECT || !VALUE_OBJECT #if !TYPE_OBJECT && !VALUE_OBJECT || !VALUE_OBJECT
import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer; import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer;
#endif #endif
#if !TYPE_OBJECT || !VALUE_BOOLEAN
#if !VALUE_OBJECT || SAME_TYPE
import speiger.src.collections.objects.functions.function.Object2BooleanFunction;
#endif
#endif
#if !SAME_TYPE #if !SAME_TYPE
#if !TYPE_OBJECT #if !TYPE_OBJECT
import speiger.src.collections.objects.functions.consumer.VALUE_BI_FROM_OBJECT_CONSUMER; import speiger.src.collections.objects.functions.consumer.VALUE_BI_FROM_OBJECT_CONSUMER;
#endif #endif
#if !JDK_VALUE
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE; import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE;
#endif #endif
#endif
#if !TYPE_OBJECT && !VALUE_OBJECT #if !TYPE_OBJECT && !VALUE_OBJECT
import speiger.src.collections.objects.collections.ObjectBidirectionalIterator; import speiger.src.collections.objects.collections.ObjectBidirectionalIterator;
#endif #endif
@@ -579,13 +592,13 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
#endif #endif
Node KEY_VALUE_GENERIC_TYPE entry = findNode(key); Node KEY_VALUE_GENERIC_TYPE entry = findNode(key);
if(entry == null) { if(entry == null) {
VALUE_TYPE newValue = valueProvider.VALUE_GET_KEY(); VALUE_TYPE newValue = valueProvider.VALUE_SUPPLY_GET();
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue; if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
put(key, newValue); put(key, newValue);
return newValue; return newValue;
} }
if(VALUE_EQUALS(entry.value, getDefaultReturnValue())) { if(VALUE_EQUALS(entry.value, getDefaultReturnValue())) {
VALUE_TYPE newValue = valueProvider.VALUE_GET_KEY(); VALUE_TYPE newValue = valueProvider.VALUE_SUPPLY_GET();
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue; if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
entry.value = newValue; entry.value = newValue;
} }
@@ -1203,6 +1216,14 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
action.accept(entry.key); action.accept(entry.key);
} }
@Override
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
Objects.requireNonNull(action);
int index = 0;
for(Node KEY_VALUE_GENERIC_TYPE entry = start(), end = end();entry != null && (end == null || (end != previous(entry)));entry = next(entry))
action.accept(index++, entry.key);
}
@Override @Override
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) { public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action); Objects.requireNonNull(action);
@@ -1901,6 +1922,14 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
action.accept(new BasicEntryKV_BRACES(entry.key, entry.value)); action.accept(new BasicEntryKV_BRACES(entry.key, entry.value));
} }
@Override
public void forEachIndexed(IntObjectConsumer<MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
Objects.requireNonNull(action);
int index = 0;
for(Node KEY_VALUE_GENERIC_TYPE entry = subLowest(), last = subHighest();entry != null && (last == null || last != previous(entry));entry = next(entry))
action.accept(index++, new BasicEntryKV_BRACES(entry.key, entry.value));
}
@Override @Override
public <E> void forEach(E input, ObjectObjectConsumer<E, MAP.Entry KEY_VALUE_GENERIC_TYPE> action) { public <E> void forEach(E input, ObjectObjectConsumer<E, MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
Objects.requireNonNull(action); Objects.requireNonNull(action);
@@ -1909,7 +1938,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
} }
@Override @Override
public boolean matchesAny(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) { public boolean matchesAny(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
Objects.requireNonNull(filter); Objects.requireNonNull(filter);
if(size() <= 0) return false; if(size() <= 0) return false;
BasicEntry KEY_VALUE_GENERIC_TYPE subEntry = new BasicEntryKV_BRACES(); BasicEntry KEY_VALUE_GENERIC_TYPE subEntry = new BasicEntryKV_BRACES();
@@ -1921,7 +1950,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
} }
@Override @Override
public boolean matchesNone(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) { public boolean matchesNone(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
Objects.requireNonNull(filter); Objects.requireNonNull(filter);
if(size() <= 0) return true; if(size() <= 0) return true;
BasicEntry KEY_VALUE_GENERIC_TYPE subEntry = new BasicEntryKV_BRACES(); BasicEntry KEY_VALUE_GENERIC_TYPE subEntry = new BasicEntryKV_BRACES();
@@ -1933,7 +1962,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
} }
@Override @Override
public boolean matchesAll(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) { public boolean matchesAll(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
Objects.requireNonNull(filter); Objects.requireNonNull(filter);
if(size() <= 0) return true; if(size() <= 0) return true;
BasicEntry KEY_VALUE_GENERIC_TYPE subEntry = new BasicEntryKV_BRACES(); BasicEntry KEY_VALUE_GENERIC_TYPE subEntry = new BasicEntryKV_BRACES();
@@ -1971,7 +2000,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
} }
@Override @Override
public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) { public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
Objects.requireNonNull(filter); Objects.requireNonNull(filter);
if(size() <= 0) return null; if(size() <= 0) return null;
BasicEntry KEY_VALUE_GENERIC_TYPE subEntry = new BasicEntryKV_BRACES(); BasicEntry KEY_VALUE_GENERIC_TYPE subEntry = new BasicEntryKV_BRACES();
@@ -1983,7 +2012,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
} }
@Override @Override
public int count(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) { public int count(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
Objects.requireNonNull(filter); Objects.requireNonNull(filter);
if(size() <= 0) return 0; if(size() <= 0) return 0;
int result = 0; int result = 0;
@@ -2033,6 +2062,14 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
action.accept(entry.value); action.accept(entry.value);
} }
@Override
public void forEachIndexed(VALUE_BI_FROM_INT_CONSUMER VALUE_GENERIC_TYPE action) {
Objects.requireNonNull(action);
int index = 0;
for(Node KEY_VALUE_GENERIC_TYPE entry = subLowest(), last = subHighest();entry != null && (last == null || last != previous(entry));entry = next(entry))
action.accept(index++, entry.value);
}
@Override @Override
public <E> void forEach(E input, VALUE_BI_FROM_OBJECT_CONSUMER VSV_GENERIC_TYPE<E> action) { public <E> void forEach(E input, VALUE_BI_FROM_OBJECT_CONSUMER VSV_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action); Objects.requireNonNull(action);
@@ -2381,6 +2418,14 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
action.accept(entry.value); action.accept(entry.value);
} }
@Override
public void forEachIndexed(VALUE_BI_FROM_INT_CONSUMER VALUE_GENERIC_TYPE action) {
Objects.requireNonNull(action);
int index = 0;
for(Node KEY_VALUE_GENERIC_TYPE entry = first;entry != null;entry = entry.next())
action.accept(index++, entry.value);
}
@Override @Override
public <E> void forEach(E input, VALUE_BI_FROM_OBJECT_CONSUMER VSV_GENERIC_TYPE<E> action) { public <E> void forEach(E input, VALUE_BI_FROM_OBJECT_CONSUMER VSV_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action); Objects.requireNonNull(action);
@@ -2538,6 +2583,14 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
action.accept(new BasicEntryKV_BRACES(entry.key, entry.value)); action.accept(new BasicEntryKV_BRACES(entry.key, entry.value));
} }
@Override
public void forEachIndexed(IntObjectConsumer<MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
Objects.requireNonNull(action);
int index = 0;
for(Node KEY_VALUE_GENERIC_TYPE entry = first;entry != null;entry = entry.next())
action.accept(index++, new BasicEntryKV_BRACES(entry.key, entry.value));
}
@Override @Override
public <E> void forEach(E input, ObjectObjectConsumer<E, MAP.Entry KEY_VALUE_GENERIC_TYPE> action) { public <E> void forEach(E input, ObjectObjectConsumer<E, MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
Objects.requireNonNull(action); Objects.requireNonNull(action);
@@ -2546,7 +2599,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
} }
@Override @Override
public boolean matchesAny(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) { public boolean matchesAny(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
Objects.requireNonNull(filter); Objects.requireNonNull(filter);
if(size() <= 0) return false; if(size() <= 0) return false;
BasicEntry KEY_VALUE_GENERIC_TYPE subEntry = new BasicEntryKV_BRACES(); BasicEntry KEY_VALUE_GENERIC_TYPE subEntry = new BasicEntryKV_BRACES();
@@ -2558,7 +2611,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
} }
@Override @Override
public boolean matchesNone(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) { public boolean matchesNone(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
Objects.requireNonNull(filter); Objects.requireNonNull(filter);
if(size() <= 0) return true; if(size() <= 0) return true;
BasicEntry KEY_VALUE_GENERIC_TYPE subEntry = new BasicEntryKV_BRACES(); BasicEntry KEY_VALUE_GENERIC_TYPE subEntry = new BasicEntryKV_BRACES();
@@ -2570,7 +2623,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
} }
@Override @Override
public boolean matchesAll(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) { public boolean matchesAll(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
Objects.requireNonNull(filter); Objects.requireNonNull(filter);
if(size() <= 0) return true; if(size() <= 0) return true;
BasicEntry KEY_VALUE_GENERIC_TYPE subEntry = new BasicEntryKV_BRACES(); BasicEntry KEY_VALUE_GENERIC_TYPE subEntry = new BasicEntryKV_BRACES();
@@ -2608,7 +2661,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
} }
@Override @Override
public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) { public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
Objects.requireNonNull(filter); Objects.requireNonNull(filter);
if(size() <= 0) return null; if(size() <= 0) return null;
BasicEntry KEY_VALUE_GENERIC_TYPE subEntry = new BasicEntryKV_BRACES(); BasicEntry KEY_VALUE_GENERIC_TYPE subEntry = new BasicEntryKV_BRACES();
@@ -2620,7 +2673,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
} }
@Override @Override
public int count(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) { public int count(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
Objects.requireNonNull(filter); Objects.requireNonNull(filter);
if(size() <= 0) return 0; if(size() <= 0) return 0;
int result = 0; int result = 0;
@@ -10,6 +10,9 @@ import java.util.function.BiConsumer;
import java.util.function.BiFunction; import java.util.function.BiFunction;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.function.Function; import java.util.function.Function;
#if VALUE_BOOLEAN && JDK_FUNCTION
import java.util.function.PREDICATE;
#endif
#if TYPE_OBJECT #if TYPE_OBJECT
#if AVL_TREE_MAP_FEATURE || RB_TREE_MAP_FEATURE #if AVL_TREE_MAP_FEATURE || RB_TREE_MAP_FEATURE
@@ -19,7 +22,9 @@ import java.util.Comparator;
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_COLLECTION; import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_COLLECTION;
import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER; import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
#if !VALUE_BOOLEAN || !JDK_FUNCTION
import speiger.src.collections.PACKAGE.functions.function.FUNCTION; import speiger.src.collections.PACKAGE.functions.function.FUNCTION;
#endif
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR; import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
#if !TYPE_OBJECT && !TYPE_BOOLEAN && SORTED_MAP_FEATURE #if !TYPE_OBJECT && !TYPE_BOOLEAN && SORTED_MAP_FEATURE
#if AVL_TREE_MAP_FEATURE || RB_TREE_MAP_FEATURE #if AVL_TREE_MAP_FEATURE || RB_TREE_MAP_FEATURE
@@ -8,14 +8,20 @@ import java.util.function.BiFunction;
#endif #endif
import java.util.Objects; import java.util.Objects;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
#if JDK_FUNCTION
import java.util.function.PREDICATE;
#endif
import speiger.src.collections.PACKAGE.collections.ITERATOR; import speiger.src.collections.PACKAGE.collections.ITERATOR;
#if !TYPE_OBJECT #if !TYPE_OBJECT
import speiger.src.collections.PACKAGE.functions.COMPARATOR; import speiger.src.collections.PACKAGE.functions.COMPARATOR;
import speiger.src.collections.PACKAGE.functions.CONSUMER; import speiger.src.collections.PACKAGE.functions.CONSUMER;
#endif #endif
import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER; import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
#if !JDK_FUNCTION
import speiger.src.collections.PACKAGE.functions.function.PREDICATE; import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
#endif
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR; import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
import speiger.src.collections.utils.ITrimmable; import speiger.src.collections.utils.ITrimmable;
@@ -257,6 +263,15 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEUE K
clearAndTrim(0); clearAndTrim(0);
} }
@Override
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
Objects.requireNonNull(action);
if(first == last) return;
for(int i = 0,m=size();i<m;i++)
action.accept(i, array[(first + i) % array.length]);
clearAndTrim(0);
}
@Override @Override
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) { public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action); Objects.requireNonNull(action);
@@ -8,6 +8,9 @@ import java.util.function.Consumer;
import java.util.function.BiFunction; import java.util.function.BiFunction;
#endif #endif
import java.util.Objects; import java.util.Objects;
#if JDK_FUNCTION
import java.util.function.PREDICATE;
#endif
import speiger.src.collections.PACKAGE.collections.COLLECTION; import speiger.src.collections.PACKAGE.collections.COLLECTION;
import speiger.src.collections.PACKAGE.collections.ITERATOR; import speiger.src.collections.PACKAGE.collections.ITERATOR;
@@ -15,8 +18,11 @@ import speiger.src.collections.PACKAGE.collections.ITERATOR;
import speiger.src.collections.PACKAGE.functions.COMPARATOR; import speiger.src.collections.PACKAGE.functions.COMPARATOR;
import speiger.src.collections.PACKAGE.functions.CONSUMER; import speiger.src.collections.PACKAGE.functions.CONSUMER;
#endif #endif
import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER; import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
#if !JDK_FUNCTION
import speiger.src.collections.PACKAGE.functions.function.PREDICATE; import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
#endif
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR; import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
import speiger.src.collections.PACKAGE.utils.ARRAYS; import speiger.src.collections.PACKAGE.utils.ARRAYS;
import speiger.src.collections.utils.SanityChecks; import speiger.src.collections.utils.SanityChecks;
@@ -209,6 +215,13 @@ public class ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUE
return value; return value;
} }
@Override
public KEY_TYPE first() {
if(isEmpty()) throw new NoSuchElementException();
if(firstIndex == -1) findFirstIndex();
return array[firstIndex];
}
@Override @Override
public KEY_TYPE peek(int index) { public KEY_TYPE peek(int index) {
if(index < 0 || index >= size) throw new NoSuchElementException(); if(index < 0 || index >= size) throw new NoSuchElementException();
@@ -263,6 +276,12 @@ public class ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUE
for(int i = 0,m=size;i<m;i++) action.accept(dequeue()); for(int i = 0,m=size;i<m;i++) action.accept(dequeue());
} }
@Override
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
Objects.requireNonNull(action);
for(int i = 0,m=size;i<m;i++) action.accept(i, dequeue());
}
@Override @Override
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) { public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action); Objects.requireNonNull(action);
@@ -8,6 +8,9 @@ import java.util.function.Consumer;
import java.util.function.BiFunction; import java.util.function.BiFunction;
#endif #endif
import java.util.Objects; import java.util.Objects;
#if JDK_FUNCTION
import java.util.function.PREDICATE;
#endif
import speiger.src.collections.PACKAGE.collections.COLLECTION; import speiger.src.collections.PACKAGE.collections.COLLECTION;
import speiger.src.collections.PACKAGE.collections.ITERATOR; import speiger.src.collections.PACKAGE.collections.ITERATOR;
@@ -15,8 +18,11 @@ import speiger.src.collections.PACKAGE.collections.ITERATOR;
import speiger.src.collections.PACKAGE.functions.COMPARATOR; import speiger.src.collections.PACKAGE.functions.COMPARATOR;
import speiger.src.collections.PACKAGE.functions.CONSUMER; import speiger.src.collections.PACKAGE.functions.CONSUMER;
#endif #endif
import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER; import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
#if !JDK_FUNCTION
import speiger.src.collections.PACKAGE.functions.function.PREDICATE; import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
#endif
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR; import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
import speiger.src.collections.PACKAGE.utils.ARRAYS; import speiger.src.collections.PACKAGE.utils.ARRAYS;
import speiger.src.collections.utils.SanityChecks; import speiger.src.collections.utils.SanityChecks;
@@ -250,6 +256,12 @@ public class HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEU
for(int i = 0,m=size;i<m;i++) action.accept(dequeue()); for(int i = 0,m=size;i<m;i++) action.accept(dequeue());
} }
@Override
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
Objects.requireNonNull(action);
for(int i = 0,m=size;i<m;i++) action.accept(i, dequeue());
}
@Override @Override
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) { public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action); Objects.requireNonNull(action);
@@ -4,8 +4,7 @@ package speiger.src.collections.PACKAGE.queues;
import java.util.Comparator; import java.util.Comparator;
import java.util.Collection; import java.util.Collection;
import java.util.Iterator; import java.util.Iterator;
import java.util.function.IntFunction;
import speiger.src.collections.ints.functions.function.Int2ObjectFunction;
#else #else
import speiger.src.collections.PACKAGE.functions.COMPARATOR; import speiger.src.collections.PACKAGE.functions.COMPARATOR;
#endif #endif
@@ -189,7 +188,7 @@ public interface PRIORITY_QUEUE KEY_GENERIC_TYPE extends ITERABLE KEY_GENERIC_TY
* @return an array containing all of the elements in this collection * @return an array containing all of the elements in this collection
* @see Collection#toArray(Object[]) * @see Collection#toArray(Object[])
*/ */
default KEY_TYPE[] TO_ARRAY(Int2ObjectFunction<KEY_TYPE[]> action) { default <E> E[] TO_ARRAY(IntFunction<E[]> action) {
return TO_ARRAY(action.apply(size())); return TO_ARRAY(action.apply(size()));
} }
#endif #endif
@@ -10,13 +10,20 @@ import java.util.function.BiFunction;
import java.util.Iterator; import java.util.Iterator;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import java.util.Objects; import java.util.Objects;
#if JDK_FUNCTION
import java.util.function.PREDICATE;
#endif
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR; import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
#if !TYPE_OBJECT #if !TYPE_OBJECT
import speiger.src.collections.PACKAGE.functions.COMPARATOR; import speiger.src.collections.PACKAGE.functions.COMPARATOR;
import speiger.src.collections.PACKAGE.functions.CONSUMER; import speiger.src.collections.PACKAGE.functions.CONSUMER;
#endif #endif
import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER; import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
#if !JDK_FUNCTION
import speiger.src.collections.PACKAGE.functions.function.PREDICATE; import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
#endif
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR; import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
import speiger.src.collections.PACKAGE.collections.COLLECTION; import speiger.src.collections.PACKAGE.collections.COLLECTION;
import speiger.src.collections.PACKAGE.collections.ITERATOR; import speiger.src.collections.PACKAGE.collections.ITERATOR;
@@ -353,6 +360,15 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
} }
} }
@Override
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
Objects.requireNonNull(action);
int index = 0;
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) {
action.accept(index++, entry.key);
}
}
@Override @Override
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) { public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action); Objects.requireNonNull(action);
@@ -1192,6 +1208,15 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
} }
} }
@Override
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
Objects.requireNonNull(action);
int index = 0;
for(Entry KEY_GENERIC_TYPE entry = start();entry != null && inRange(entry.key);entry = next(entry)) {
action.accept(index++, entry.key);
}
}
@Override @Override
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) { public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action); Objects.requireNonNull(action);
@@ -9,15 +9,21 @@ import java.util.function.BiFunction;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import java.util.Objects; import java.util.Objects;
import java.util.Set; import java.util.Set;
#if PRIMITIVES #if JDK_FUNCTION
import java.util.function.PREDICATE;
#endif
#if PRIMITIVES && !JDK_FUNCTION
import java.util.function.JAVA_PREDICATE; import java.util.function.JAVA_PREDICATE;
#endif #endif
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR; import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
import speiger.src.collections.PACKAGE.collections.COLLECTION; import speiger.src.collections.PACKAGE.collections.COLLECTION;
import speiger.src.collections.PACKAGE.collections.ITERATOR; import speiger.src.collections.PACKAGE.collections.ITERATOR;
import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER; import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
#if !JDK_FUNCTION
import speiger.src.collections.PACKAGE.functions.function.PREDICATE; import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
#endif
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR; import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
#if !TYPE_OBJECT #if !TYPE_OBJECT
import speiger.src.collections.PACKAGE.functions.CONSUMER; import speiger.src.collections.PACKAGE.functions.CONSUMER;
@@ -391,6 +397,12 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
for(int i = 0;i<size;action.accept(data[i++])); for(int i = 0;i<size;action.accept(data[i++]));
} }
@Override
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
Objects.requireNonNull(action);
for(int i = 0;i<size;action.accept(i, data[i++]));
}
@Override @Override
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) { public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action); Objects.requireNonNull(action);
@@ -539,6 +551,7 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
@Override @Override
@Deprecated @Deprecated
public Object[] toArray() { public Object[] toArray() {
if(isEmpty()) return ObjectArrays.EMPTY_ARRAY;
Object[] obj = new Object[size()]; Object[] obj = new Object[size()];
for(int i = 0;i<size();i++) for(int i = 0;i<size();i++)
obj[i] = KEY_TO_OBJ(data[i]); obj[i] = KEY_TO_OBJ(data[i]);
@@ -9,6 +9,9 @@ import java.util.Collection;
import java.util.Iterator; import java.util.Iterator;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import java.util.Objects; import java.util.Objects;
#if JDK_FUNCTION
import java.util.function.PREDICATE;
#endif
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR; import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
import speiger.src.collections.PACKAGE.collections.COLLECTION; import speiger.src.collections.PACKAGE.collections.COLLECTION;
@@ -16,8 +19,11 @@ import speiger.src.collections.PACKAGE.collections.ITERATOR;
#if !TYPE_OBJECT #if !TYPE_OBJECT
import speiger.src.collections.PACKAGE.functions.CONSUMER; import speiger.src.collections.PACKAGE.functions.CONSUMER;
#endif #endif
import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER; import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
#if !JDK_FUNCTION
import speiger.src.collections.PACKAGE.functions.function.PREDICATE; import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
#endif
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR; import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR; import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
import speiger.src.collections.PACKAGE.utils.ARRAYS; import speiger.src.collections.PACKAGE.utils.ARRAYS;
@@ -323,6 +329,17 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
} }
} }
@Override
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
Objects.requireNonNull(action);
int count = 0;
int index = firstIndex;
while(index != -1) {
action.accept(count++, keys[index]);
index = (int)links[index];
}
}
@Override @Override
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) { public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action); Objects.requireNonNull(action);
@@ -9,6 +9,9 @@ import java.util.Objects;
import java.util.Collection; import java.util.Collection;
import java.util.Iterator; import java.util.Iterator;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
#if JDK_FUNCTION
import java.util.function.PREDICATE;
#endif
import speiger.src.collections.PACKAGE.collections.COLLECTION; import speiger.src.collections.PACKAGE.collections.COLLECTION;
#if !TYPE_OBJECT #if !TYPE_OBJECT
@@ -20,8 +23,11 @@ import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
import speiger.src.collections.PACKAGE.utils.ITERATORS; import speiger.src.collections.PACKAGE.utils.ITERATORS;
import speiger.src.collections.PACKAGE.functions.CONSUMER; import speiger.src.collections.PACKAGE.functions.CONSUMER;
#endif #endif
import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER; import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
#if !JDK_FUNCTION
import speiger.src.collections.PACKAGE.functions.function.PREDICATE; import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
#endif
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR; import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
import speiger.src.collections.PACKAGE.utils.STRATEGY; import speiger.src.collections.PACKAGE.utils.STRATEGY;
import speiger.src.collections.utils.HashUtil; import speiger.src.collections.utils.HashUtil;
@@ -532,6 +538,17 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
} }
} }
@Override
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
Objects.requireNonNull(action);
int count = 0;
int index = firstIndex;
while(index != -1) {
action.accept(count++, keys[index]);
index = (int)links[index];
}
}
@Override @Override
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) { public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action); Objects.requireNonNull(action);
@@ -9,6 +9,9 @@ import java.util.Objects;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.function.BiFunction; import java.util.function.BiFunction;
#endif #endif
#if JDK_FUNCTION
import java.util.function.PREDICATE;
#endif
import speiger.src.collections.PACKAGE.collections.COLLECTION; import speiger.src.collections.PACKAGE.collections.COLLECTION;
#if !TYPE_OBJECT #if !TYPE_OBJECT
@@ -18,8 +21,11 @@ import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
#if !TYPE_OBJECT #if !TYPE_OBJECT
import speiger.src.collections.PACKAGE.functions.CONSUMER; import speiger.src.collections.PACKAGE.functions.CONSUMER;
#endif #endif
import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER; import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
#if !JDK_FUNCTION
import speiger.src.collections.PACKAGE.functions.function.PREDICATE; import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
#endif
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR; import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR; import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
#if !TYPE_OBJECT #if !TYPE_OBJECT
@@ -387,6 +393,17 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
} }
} }
@Override
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
Objects.requireNonNull(action);
int count = 0;
int index = firstIndex;
while(index != -1) {
action.accept(count++, keys[index]);
index = (int)links[index];
}
}
@Override @Override
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) { public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action); Objects.requireNonNull(action);
@@ -10,6 +10,9 @@ import java.util.Objects;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.function.BiFunction; import java.util.function.BiFunction;
#endif #endif
#if JDK_FUNCTION
import java.util.function.PREDICATE;
#endif
import speiger.src.collections.PACKAGE.collections.COLLECTION; import speiger.src.collections.PACKAGE.collections.COLLECTION;
import speiger.src.collections.PACKAGE.collections.ITERATOR; import speiger.src.collections.PACKAGE.collections.ITERATOR;
@@ -17,8 +20,11 @@ import speiger.src.collections.PACKAGE.collections.ITERATOR;
import speiger.src.collections.PACKAGE.utils.ITERATORS; import speiger.src.collections.PACKAGE.utils.ITERATORS;
import speiger.src.collections.PACKAGE.functions.CONSUMER; import speiger.src.collections.PACKAGE.functions.CONSUMER;
#endif #endif
import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER; import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
#if !JDK_FUNCTION
import speiger.src.collections.PACKAGE.functions.function.PREDICATE; import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
#endif
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR; import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
import speiger.src.collections.PACKAGE.utils.STRATEGY; import speiger.src.collections.PACKAGE.utils.STRATEGY;
@@ -501,6 +507,7 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T
@Override @Override
public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) { public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) {
Objects.requireNonNull(action);
if(size() <= 0) return; if(size() <= 0) return;
if(containsNull) action.accept(keys[nullIndex]); if(containsNull) action.accept(keys[nullIndex]);
for(int i = nullIndex-1;i>=0;i--) { for(int i = nullIndex-1;i>=0;i--) {
@@ -508,6 +515,16 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T
} }
} }
@Override
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
Objects.requireNonNull(action);
if(size() <= 0) return;
if(containsNull) action.accept(0, keys[nullIndex]);
for(int i = nullIndex-1, index = containsNull ? 1 : 0;i>=0;i--) {
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) action.accept(index++, keys[i]);
}
}
@Override @Override
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) { public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action); Objects.requireNonNull(action);
@@ -10,6 +10,9 @@ import java.util.Objects;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.function.BiFunction; import java.util.function.BiFunction;
#endif #endif
#if JDK_FUNCTION
import java.util.function.PREDICATE;
#endif
import speiger.src.collections.PACKAGE.collections.COLLECTION; import speiger.src.collections.PACKAGE.collections.COLLECTION;
import speiger.src.collections.PACKAGE.collections.ITERATOR; import speiger.src.collections.PACKAGE.collections.ITERATOR;
@@ -17,8 +20,11 @@ import speiger.src.collections.PACKAGE.collections.ITERATOR;
import speiger.src.collections.PACKAGE.utils.ITERATORS; import speiger.src.collections.PACKAGE.utils.ITERATORS;
import speiger.src.collections.PACKAGE.functions.CONSUMER; import speiger.src.collections.PACKAGE.functions.CONSUMER;
#endif #endif
import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER; import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
#if !JDK_FUNCTION
import speiger.src.collections.PACKAGE.functions.function.PREDICATE; import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
#endif
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR; import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
import speiger.src.collections.utils.HashUtil; import speiger.src.collections.utils.HashUtil;
import speiger.src.collections.utils.ITrimmable; import speiger.src.collections.utils.ITrimmable;
@@ -371,6 +377,16 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
} }
} }
@Override
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
Objects.requireNonNull(action);
if(size() <= 0) return;
if(containsNull) action.accept(0, keys[nullIndex]);
for(int i = nullIndex-1, index = containsNull ? 1 : 0;i>=0;i--) {
if(KEY_EQUALS_NOT_NULL(keys[i])) action.accept(index++, keys[i]);
}
}
@Override @Override
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) { public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action); Objects.requireNonNull(action);
@@ -10,13 +10,20 @@ import java.util.function.BiFunction;
import java.util.Iterator; import java.util.Iterator;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import java.util.Objects; import java.util.Objects;
#if JDK_FUNCTION
import java.util.function.PREDICATE;
#endif
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR; import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
#if !TYPE_OBJECT #if !TYPE_OBJECT
import speiger.src.collections.PACKAGE.functions.COMPARATOR; import speiger.src.collections.PACKAGE.functions.COMPARATOR;
import speiger.src.collections.PACKAGE.functions.CONSUMER; import speiger.src.collections.PACKAGE.functions.CONSUMER;
#endif #endif
import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER; import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
#if !JDK_FUNCTION
import speiger.src.collections.PACKAGE.functions.function.PREDICATE; import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
#endif
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR; import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
import speiger.src.collections.PACKAGE.collections.COLLECTION; import speiger.src.collections.PACKAGE.collections.COLLECTION;
import speiger.src.collections.PACKAGE.collections.ITERATOR; import speiger.src.collections.PACKAGE.collections.ITERATOR;
@@ -353,6 +360,14 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
} }
} }
@Override
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
Objects.requireNonNull(action);
int index = 0;
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next())
action.accept(index++, entry.key);
}
@Override @Override
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) { public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action); Objects.requireNonNull(action);
@@ -1253,6 +1268,15 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
} }
} }
@Override
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
Objects.requireNonNull(action);
int index = 0;
for(Entry KEY_GENERIC_TYPE entry = start();entry != null && inRange(entry.key);entry = next(entry)) {
action.accept(index++, entry.key);
}
}
@Override @Override
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) { public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action); Objects.requireNonNull(action);
@@ -1,15 +1,19 @@
package speiger.src.collections.PACKAGE.utils; package speiger.src.collections.PACKAGE.utils;
import java.util.Arrays; import java.util.Arrays;
import java.util.Random; #if JAVA_VERSION>=17
import java.util.random.RANDOM;
#else
import java.util.RANDOM;
#endif
import java.util.concurrent.RecursiveAction; import java.util.concurrent.RecursiveAction;
#if !TYPE_OBJECT #if !TYPE_OBJECT
import speiger.src.collections.PACKAGE.functions.COMPARATOR; import speiger.src.collections.PACKAGE.functions.COMPARATOR;
#else #else
import java.util.Comparator; import java.util.Comparator;
import java.util.function.IntFunction;
import speiger.src.collections.ints.functions.function.Int2ObjectFunction;
#endif #endif
import speiger.src.collections.PACKAGE.collections.ITERATOR; import speiger.src.collections.PACKAGE.collections.ITERATOR;
import speiger.src.collections.PACKAGE.utils.ITERATORS; import speiger.src.collections.PACKAGE.utils.ITERATORS;
@@ -146,7 +150,7 @@ public class ARRAYS
* @param action that is creating the Array to be poured into * @param action that is creating the Array to be poured into
* @return array with all elements of the iterator * @return array with all elements of the iterator
*/ */
public static GENERIC_KEY_BRACES KEY_TYPE[] pour(ITERATOR KEY_GENERIC_TYPE iter, Int2ObjectFunction<KEY_TYPE[]> action) { public static <T, E> E[] pour(ITERATOR KEY_GENERIC_TYPE iter, IntFunction<E[]> action) {
return pour(iter, Integer.MAX_VALUE, action); return pour(iter, Integer.MAX_VALUE, action);
} }
@@ -158,7 +162,7 @@ public class ARRAYS
* @ArrayType(T) * @ArrayType(T)
* @return array with all requested elements of the iterator * @return array with all requested elements of the iterator
*/ */
public static GENERIC_KEY_BRACES KEY_TYPE[] pour(ITERATOR KEY_GENERIC_TYPE iter, int max, Int2ObjectFunction<KEY_TYPE[]> action) { public static <T, E> E[] pour(ITERATOR KEY_GENERIC_TYPE iter, int max, IntFunction<E[]> action) {
COLLECTIONS.CollectionWrapper KEY_GENERIC_TYPE list = COLLECTIONS.wrapper(); COLLECTIONS.CollectionWrapper KEY_GENERIC_TYPE list = COLLECTIONS.wrapper();
ITERATORS.pour(iter, list, max); ITERATORS.pour(iter, list, max);
return list.TO_ARRAY(action.apply(list.size())); return list.TO_ARRAY(action.apply(list.size()));
@@ -292,7 +296,7 @@ public class ARRAYS
* @ArrayType(T) * @ArrayType(T)
* @return the provided sorted array * @return the provided sorted array
*/ */
public static GENERIC_KEY_BRACES KEY_TYPE[] shuffle(KEY_TYPE[] array, Random random) { public static GENERIC_KEY_BRACES KEY_TYPE[] shuffle(KEY_TYPE[] array, RANDOM random) {
for(int i = array.length-1; i>=0;i--) { for(int i = array.length-1; i>=0;i--) {
int p = random.nextInt(i + 1); int p = random.nextInt(i + 1);
KEY_TYPE t = array[i]; KEY_TYPE t = array[i];
@@ -310,7 +314,7 @@ public class ARRAYS
* @ArrayType(T) * @ArrayType(T)
* @return the provided sorted array * @return the provided sorted array
*/ */
public static GENERIC_KEY_BRACES KEY_TYPE[] shuffle(KEY_TYPE[] array, int length, Random random) { public static GENERIC_KEY_BRACES KEY_TYPE[] shuffle(KEY_TYPE[] array, int length, RANDOM random) {
return shuffle(array, 0, length, random); return shuffle(array, 0, length, random);
} }
@@ -323,7 +327,7 @@ public class ARRAYS
* @ArrayType(T) * @ArrayType(T)
* @return the provided sorted array * @return the provided sorted array
*/ */
public static GENERIC_KEY_BRACES KEY_TYPE[] shuffle(KEY_TYPE[] array, int offset, int length, Random random) { public static GENERIC_KEY_BRACES KEY_TYPE[] shuffle(KEY_TYPE[] array, int offset, int length, RANDOM random) {
for(int i = length-1; i>=0;i--) { for(int i = length-1; i>=0;i--) {
int p = offset + random.nextInt(i + 1); int p = offset + random.nextInt(i + 1);
KEY_TYPE t = array[offset+i]; KEY_TYPE t = array[offset+i];
@@ -12,6 +12,7 @@ import java.util.function.Consumer;
import speiger.src.collections.PACKAGE.functions.CONSUMER; import speiger.src.collections.PACKAGE.functions.CONSUMER;
import speiger.src.collections.PACKAGE.functions.COMPARATOR; import speiger.src.collections.PACKAGE.functions.COMPARATOR;
#else #else
import java.util.function.IntFunction;
import java.util.function.BiFunction; import java.util.function.BiFunction;
import java.util.Comparator; import java.util.Comparator;
@@ -69,6 +70,7 @@ import speiger.src.collections.objects.utils.ObjectAsyncBuilder.BaseObjectTask;
import speiger.src.collections.ints.utils.IntAsyncBuilder; import speiger.src.collections.ints.utils.IntAsyncBuilder;
import speiger.src.collections.ints.utils.IntAsyncBuilder.BaseIntTask; import speiger.src.collections.ints.utils.IntAsyncBuilder.BaseIntTask;
#endif #endif
import speiger.src.collections.utils.ISizeProvider;
import speiger.src.collections.utils.SanityChecks; import speiger.src.collections.utils.SanityChecks;
/** /**
@@ -292,6 +294,26 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE
#endif #endif
#if OBJECT_ASYNC_MODULE #if OBJECT_ASYNC_MODULE
#if TYPE_OBJECT
/**
* Pours all elements of the Iterable down into a Array.
* @param action creates the final array that should be copied into.
* @return a new Builder with the ToArray function applied
*/
public ObjectAsyncBuilder<KEY_TYPE[]> TO_ARRAY(IntFunction<KEY_TYPE[]> action) {
return new ObjectAsyncBuilder<>(new ArrayTaskBRACES(iterable, action));
}
#else
/**
* Pours all elements of the Iterable down into a Array.
* @return a new Builder with the ToArray function applied
*/
public ObjectAsyncBuilder<KEY_TYPE[]> TO_ARRAY() {
return new ObjectAsyncBuilder<>(new ArrayTaskBRACES(iterable));
}
#endif
#if ARRAY_LIST_FEATURE || LINKED_LIST_FEATURE #if ARRAY_LIST_FEATURE || LINKED_LIST_FEATURE
/** /**
* Pours all elements into a List that can be later * Pours all elements into a List that can be later
@@ -729,6 +751,52 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE
} }
} }
private static class ArrayTask KEY_GENERIC_TYPE extends BaseObjectTask<KEY_TYPE[]>
{
ITERATOR KEY_GENERIC_TYPE iter;
COLLECTIONS.CollectionWrapper KEY_GENERIC_TYPE wrapper;
#if TYPE_OBJECT
IntFunction<KEY_TYPE[]> builder;
public ArrayTask(ITERABLE KEY_GENERIC_TYPE iterable, IntFunction<KEY_TYPE[]> builder) {
this.builder = builder;
#else
public ArrayTask(ITERABLE KEY_GENERIC_TYPE iterable) {
#endif
iter = iterable.iterator();
ISizeProvider prov = ISizeProvider.of(iterable);
int size = prov == null ? -1 : prov.size();
wrapper = size < 0 ? COLLECTIONS.wrapper() : COLLECTIONS.wrapper(size);
}
@Override
protected boolean execute() throws Exception {
while(shouldRun() && iter.hasNext()) {
wrapper.add(iter.NEXT());
}
if(!iter.hasNext()) {
#if TYPE_OBJECT
setResult(wrapper.TO_ARRAY(builder));
#else
setResult(wrapper.TO_ARRAY());
#endif
wrapper = null;
return true;
}
return false;
}
@Override
protected void onCompletion() {
super.onCompletion();
iter = null;
#if TYPE_OBJECT
builder = null;
#endif
}
}
private static class ForEachTask<T> extends BaseObjectTask<Void> private static class ForEachTask<T> extends BaseObjectTask<Void>
{ {
ITERATOR KEY_GENERIC_TYPE iter; ITERATOR KEY_GENERIC_TYPE iter;
@@ -5,6 +5,7 @@ import java.util.Collection;
#if !TYPE_BOOLEAN #if !TYPE_BOOLEAN
import java.util.ConcurrentModificationException; import java.util.ConcurrentModificationException;
#endif #endif
import java.util.Iterator;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import java.util.Objects; import java.util.Objects;
#if TYPE_OBJECT #if TYPE_OBJECT
@@ -12,7 +13,10 @@ import java.util.Comparator;
import java.util.function.BiFunction; import java.util.function.BiFunction;
#endif #endif
import java.util.function.Predicate; import java.util.function.Predicate;
#if PRIMITIVES #if JDK_FUNCTION && !TYPE_OBJECT
import java.util.function.PREDICATE;
#endif
#if PRIMITIVES && !JDK_FUNCTION
import java.util.function.JAVA_PREDICATE; import java.util.function.JAVA_PREDICATE;
#endif #endif
import java.util.function.Consumer; import java.util.function.Consumer;
@@ -28,8 +32,11 @@ import speiger.src.collections.objects.utils.ObjectArrays;
import speiger.src.collections.PACKAGE.functions.CONSUMER; import speiger.src.collections.PACKAGE.functions.CONSUMER;
import speiger.src.collections.PACKAGE.utils.ARRAYS; import speiger.src.collections.PACKAGE.utils.ARRAYS;
#endif #endif
#if !JDK_FUNCTION
import speiger.src.collections.PACKAGE.functions.function.PREDICATE; import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
#endif
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR; import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER; import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
#if !TYPE_BOOLEAN #if !TYPE_BOOLEAN
import speiger.src.collections.utils.HashUtil; import speiger.src.collections.utils.HashUtil;
@@ -635,6 +642,27 @@ public class COLLECTIONS
} }
}; };
} }
@Override
public boolean equals(Object o) {
if (o == this)
return true;
if (!(o instanceof Collection))
return false;
Collection<?> l = (Collection<?>)o;
if(l.size() != size()) return false;
Iterator<?> iter = l.iterator();
if (iter.hasNext() && !Objects.equals(element, iter.next())) {
return false;
}
return !iter.hasNext();
}
@Override
public int hashCode() {
return KEY_TO_HASH(element);
}
@Override @Override
public int size() { return 1; } public int size() { return 1; }
@@ -750,6 +778,8 @@ public class COLLECTIONS
@Override @Override
public void forEach(Consumer<? super CLASS_TYPE> action) { synchronized(mutex) { c.forEach(action); } } public void forEach(Consumer<? super CLASS_TYPE> action) { synchronized(mutex) { c.forEach(action); } }
#endif #endif
@Override
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) { synchronized(mutex) { c.forEachIndexed(action); } }
@Override @Override
public int hashCode() { synchronized(mutex) { return c.hashCode(); } } public int hashCode() { synchronized(mutex) { return c.hashCode(); } }
@Override @Override
@@ -875,6 +905,8 @@ public class COLLECTIONS
@Override @Override
public void forEach(Consumer<? super CLASS_TYPE> action) { c.forEach(action); } public void forEach(Consumer<? super CLASS_TYPE> action) { c.forEach(action); }
#endif #endif
@Override
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) { c.forEachIndexed(action); }
@Override @Override
public int hashCode() { return c.hashCode(); } public int hashCode() { return c.hashCode(); }
@Override @Override
@@ -8,6 +8,9 @@ import java.util.Comparator;
#endif #endif
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;
import java.util.function.Consumer; import java.util.function.Consumer;
#if JDK_FUNCTION
import java.util.function.PREDICATE;
#endif
import speiger.src.collections.PACKAGE.collections.ITERABLE; import speiger.src.collections.PACKAGE.collections.ITERABLE;
import speiger.src.collections.PACKAGE.collections.COLLECTION; import speiger.src.collections.PACKAGE.collections.COLLECTION;
@@ -19,7 +22,9 @@ import speiger.src.collections.PACKAGE.functions.COMPARATOR;
#endif #endif
import speiger.src.collections.PACKAGE.collections.ITERATOR; import speiger.src.collections.PACKAGE.collections.ITERATOR;
import speiger.src.collections.PACKAGE.functions.function.TO_OBJECT_FUNCTION; import speiger.src.collections.PACKAGE.functions.function.TO_OBJECT_FUNCTION;
#if !JDK_FUNCTION
import speiger.src.collections.PACKAGE.functions.function.PREDICATE; import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
#endif
import speiger.src.collections.utils.ISizeProvider; import speiger.src.collections.utils.ISizeProvider;
/** /**
@@ -6,6 +6,9 @@ import java.util.NoSuchElementException;
import java.util.Comparator; import java.util.Comparator;
import java.util.function.CONSUMER; import java.util.function.CONSUMER;
#endif #endif
#if JDK_FUNCTION
import java.util.function.PREDICATE;
#endif
import speiger.src.collections.PACKAGE.collections.ITERATOR; import speiger.src.collections.PACKAGE.collections.ITERATOR;
#if !TYPE_OBJECT #if !TYPE_OBJECT
@@ -15,7 +18,9 @@ import speiger.src.collections.PACKAGE.functions.CONSUMER;
import speiger.src.collections.PACKAGE.functions.COMPARATOR; import speiger.src.collections.PACKAGE.functions.COMPARATOR;
#endif #endif
import speiger.src.collections.PACKAGE.functions.function.TO_OBJECT_FUNCTION; import speiger.src.collections.PACKAGE.functions.function.TO_OBJECT_FUNCTION;
#if !JDK_FUNCTION
import speiger.src.collections.PACKAGE.functions.function.PREDICATE; import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
#endif
#if ARRAY_LIST_FEATURE || LINKED_LIST_FEATURE #if ARRAY_LIST_FEATURE || LINKED_LIST_FEATURE
import speiger.src.collections.PACKAGE.lists.LIST; import speiger.src.collections.PACKAGE.lists.LIST;
#if ARRAY_LIST_FEATURE #if ARRAY_LIST_FEATURE
@@ -5,7 +5,11 @@ import java.util.List;
#if IARRAY_FEATURE #if IARRAY_FEATURE
import java.util.Objects; import java.util.Objects;
#endif #endif
import java.util.Random; #if JAVA_VERSION>=17
import java.util.random.RANDOM;
#else
import java.util.RANDOM;
#endif
import java.util.RandomAccess; import java.util.RandomAccess;
#if IARRAY_FEATURE || TYPE_OBJECT #if IARRAY_FEATURE || TYPE_OBJECT
import java.util.function.Consumer; import java.util.function.Consumer;
@@ -157,7 +161,7 @@ public class LISTS
* @Type(T) * @Type(T)
* @return the input list * @return the input list
*/ */
public static GENERIC_KEY_BRACES LIST KEY_GENERIC_TYPE shuffle(LIST KEY_GENERIC_TYPE list, Random random) { public static GENERIC_KEY_BRACES LIST KEY_GENERIC_TYPE shuffle(LIST KEY_GENERIC_TYPE list, RANDOM random) {
int size = list.size(); int size = list.size();
#if IARRAY_FEATURE #if IARRAY_FEATURE
if(list instanceof IARRAY) { if(list instanceof IARRAY) {
@@ -5,6 +5,9 @@ import java.util.Collection;
import java.util.Comparator; import java.util.Comparator;
import java.util.function.Consumer; import java.util.function.Consumer;
#endif #endif
#if JDK_FUNCTION
import java.util.function.PREDICATE;
#endif
import speiger.src.collections.PACKAGE.collections.ITERATOR; import speiger.src.collections.PACKAGE.collections.ITERATOR;
import speiger.src.collections.PACKAGE.collections.COLLECTION; import speiger.src.collections.PACKAGE.collections.COLLECTION;
@@ -18,7 +21,9 @@ import speiger.src.collections.PACKAGE.queues.PRIORITY_QUEUE;
#if !TYPE_OBJECT #if !TYPE_OBJECT
import speiger.src.collections.PACKAGE.functions.CONSUMER; import speiger.src.collections.PACKAGE.functions.CONSUMER;
#endif #endif
#if !JDK_FUNCTION
import speiger.src.collections.PACKAGE.functions.function.PREDICATE; import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
#endif
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER; import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
/** /**
@@ -14,6 +14,9 @@ import java.util.function.Consumer;
#if !TYPE_OBJECT && !TYPE_BOOLEAN #if !TYPE_OBJECT && !TYPE_BOOLEAN
import java.util.function.Function; import java.util.function.Function;
#endif #endif
#if VALUE_BOOLEAN && JDK_TYPE
import java.util.function.PREDICATE;
#endif
import speiger.src.collections.objects.collections.ObjectIterable; import speiger.src.collections.objects.collections.ObjectIterable;
import speiger.src.collections.objects.collections.ObjectIterator; import speiger.src.collections.objects.collections.ObjectIterator;
@@ -28,7 +31,9 @@ import speiger.src.collections.PACKAGE.functions.COMPARATOR;
#endif #endif
#endif #endif
import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER; import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
#if !VALUE_BOOLEAN || !JDK_TYPE
import speiger.src.collections.PACKAGE.functions.function.FUNCTION; import speiger.src.collections.PACKAGE.functions.function.FUNCTION;
#endif
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR; import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
import speiger.src.collections.PACKAGE.maps.abstracts.ABSTRACT_MAP; import speiger.src.collections.PACKAGE.maps.abstracts.ABSTRACT_MAP;
import speiger.src.collections.PACKAGE.maps.interfaces.MAP; import speiger.src.collections.PACKAGE.maps.interfaces.MAP;
@@ -7,7 +7,9 @@ import com.google.common.collect.testing.features.CollectionSize;
import speiger.src.collections.PACKAGE.collections.COLLECTION; import speiger.src.collections.PACKAGE.collections.COLLECTION;
import speiger.src.collections.PACKAGE.lists.ARRAY_LIST; import speiger.src.collections.PACKAGE.lists.ARRAY_LIST;
import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_LIST_TESTER; import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_LIST_TESTER;
#if !TYPE_BOOLEAN
import speiger.src.testers.PACKAGE.utils.MINIMAL_SET; import speiger.src.testers.PACKAGE.utils.MINIMAL_SET;
#endif
@Ignore @Ignore
@SuppressWarnings("javadoc") @SuppressWarnings("javadoc")
@@ -39,7 +41,9 @@ public class FILE_KEY_TYPEListEqualsTester KEY_GENERIC_TYPE extends ABSTRACT_LIS
assertFalse("Lists of different sizes should not be equal.", getList().equals(new ARRAY_LISTBRACES(moreElements))); assertFalse("Lists of different sizes should not be equal.", getList().equals(new ARRAY_LISTBRACES(moreElements)));
} }
#if !TYPE_BOOLEAN
public void testEquals_set() { public void testEquals_set() {
assertFalse("A List should never equal a Set.", getList().equals(MINIMAL_SET.of(getList()))); assertFalse("A List should never equal a Set.", getList().equals(MINIMAL_SET.of(getList())));
} }
#endif
} }
@@ -33,6 +33,16 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapPutIfAbsentTester KEY_VALUE_GENERIC
expectUnchanged(); expectUnchanged();
} }
#ignore
@MapFeature.Require(SUPPORTS_PUT)
#endignore
public void testPutIfAbsent_replaceableDefaultValue() {
getMap().putIfAbsent(k3(), getMap().getDefaultReturnValue());
assertEquals("get(present) should return defaultValue value", getMap().getDefaultReturnValue(), get(k3()));
getMap().putIfAbsent(k3(), v3());
assertEquals("get(present) value should have been replaced", v3(), get(k3()));
}
#ignore #ignore
@MapFeature.Require(absent = SUPPORTS_PUT) @MapFeature.Require(absent = SUPPORTS_PUT)
#endignore #endignore
@@ -11,7 +11,7 @@ import java.util.function.Supplier;
import org.junit.Test; import org.junit.Test;
import junit.framework.TestCase; import junit.framework.TestCase;
import speiger.src.collections.VALUE_PACKAGE.functions.function.FILE_VALUE_TYPE2ObjectFunction; import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_TO_OBJECT_FUNCTION;
#if !SAME_TYPE #if !SAME_TYPE
import speiger.src.collections.PACKAGE.functions.function.TO_OBJECT_FUNCTION; import speiger.src.collections.PACKAGE.functions.function.TO_OBJECT_FUNCTION;
#endif #endif
@@ -24,7 +24,7 @@ public class PAIRTester KEY_VALUE_GENERIC_TYPE extends TestCase
Function<PAIR KEY_VALUE_GENERIC_TYPE, PAIR KEY_VALUE_GENERIC_TYPE> copier; Function<PAIR KEY_VALUE_GENERIC_TYPE, PAIR KEY_VALUE_GENERIC_TYPE> copier;
BiFunction<KEY_TYPE[], VALUE_TYPE[], PAIR KEY_VALUE_GENERIC_TYPE> constructor; BiFunction<KEY_TYPE[], VALUE_TYPE[], PAIR KEY_VALUE_GENERIC_TYPE> constructor;
TO_OBJECT_FUNCTION KKS_GENERIC_TYPE<PAIR KEY_VALUE_GENERIC_TYPE> keyConstructor; TO_OBJECT_FUNCTION KKS_GENERIC_TYPE<PAIR KEY_VALUE_GENERIC_TYPE> keyConstructor;
FILE_VALUE_TYPE2ObjectFunction VVS_GENERIC_TYPE<PAIR KEY_VALUE_GENERIC_TYPE> valueConstructor; VALUE_TO_OBJECT_FUNCTION VVS_GENERIC_TYPE<PAIR KEY_VALUE_GENERIC_TYPE> valueConstructor;
boolean mutable; boolean mutable;
protected PAIRTester(boolean mutable) { protected PAIRTester(boolean mutable) {
@@ -47,7 +47,7 @@ public class PAIRTester KEY_VALUE_GENERIC_TYPE extends TestCase
this.keyConstructor = keyConstructor; this.keyConstructor = keyConstructor;
} }
protected void setValueConstructor(FILE_VALUE_TYPE2ObjectFunction VVS_GENERIC_TYPE<PAIR KEY_VALUE_GENERIC_TYPE> valueConstructor) { protected void setValueConstructor(VALUE_TO_OBJECT_FUNCTION VVS_GENERIC_TYPE<PAIR KEY_VALUE_GENERIC_TYPE> valueConstructor) {
this.valueConstructor = valueConstructor; this.valueConstructor = valueConstructor;
} }
@@ -94,22 +94,14 @@ public class PAIRTester KEY_VALUE_GENERIC_TYPE extends TestCase
@Test @Test
public void testKeyMatching() { public void testKeyMatching() {
#if TYPE_OBJECT PAIR KEY_VALUE_GENERIC_TYPE pair = keyConstructor.apply(getKey());
PAIR KEY_VALUE_GENERIC_TYPE pair = keyConstructor.getObject(getKey());
#else
PAIR KEY_VALUE_GENERIC_TYPE pair = keyConstructor.GET_VALUE(getKey());
#endif
assertEquals(getKey(), pair.ENTRY_KEY()); assertEquals(getKey(), pair.ENTRY_KEY());
assertEquals(EMPTY_VALUE, pair.ENTRY_VALUE()); assertEquals(EMPTY_VALUE, pair.ENTRY_VALUE());
} }
@Test @Test
public void testValueMatching() { public void testValueMatching() {
#if VALUE_OBJECT PAIR KEY_VALUE_GENERIC_TYPE pair = valueConstructor.apply(getValue());
PAIR KEY_VALUE_GENERIC_TYPE pair = valueConstructor.getObject(getValue());
#else
PAIR KEY_VALUE_GENERIC_TYPE pair = valueConstructor.get(getValue());
#endif
assertEquals(EMPTY_KEY_VALUE, pair.ENTRY_KEY()); assertEquals(EMPTY_KEY_VALUE, pair.ENTRY_KEY());
assertEquals(getValue(), pair.ENTRY_VALUE()); assertEquals(getValue(), pair.ENTRY_VALUE());
} }
@@ -9,7 +9,7 @@ import org.junit.Ignore;
import com.google.common.collect.testing.features.CollectionSize; import com.google.common.collect.testing.features.CollectionSize;
import speiger.src.collections.PACKAGE.collections.COLLECTION; import speiger.src.collections.PACKAGE.collections.COLLECTION;
import speiger.src.collections.PACKAGE.utils.SETS; import speiger.src.collections.PACKAGE.utils.COLLECTIONS;
import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_QUEUE_TESTER; import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_QUEUE_TESTER;
@Ignore @Ignore
@@ -24,7 +24,7 @@ public class FILE_KEY_TYPEQueueFilterTester KEY_GENERIC_TYPE extends ABSTRACT_QU
@CollectionSize.Require(absent = CollectionSize.ZERO) @CollectionSize.Require(absent = CollectionSize.ZERO)
#endignore #endignore
public void testQueueFilter_filterElement() { public void testQueueFilter_filterElement() {
assertFalse(expectMissing(SETS.singleton(e0()), queue.filter(T -> KEY_EQUALS(T, e0())).pourAsList().TO_ARRAY())); assertFalse(expectMissing(COLLECTIONS.singleton(e0()), queue.filter(T -> KEY_EQUALS(T, e0())).pourAsList().TO_ARRAY()));
} }
#ignore #ignore
@@ -38,7 +38,7 @@ public class FILE_KEY_TYPEQueueFilterTester KEY_GENERIC_TYPE extends ABSTRACT_QU
@CollectionSize.Require(CollectionSize.SEVERAL) @CollectionSize.Require(CollectionSize.SEVERAL)
#endignore #endignore
public void testQueueFilter_filterSeveral() { public void testQueueFilter_filterSeveral() {
assertTrue(expectMissing(SETS.singleton(e1()), queue.filter(T -> KEY_EQUALS_NOT(T, e1())).pourAsList().TO_ARRAY())); assertTrue(expectMissing(COLLECTIONS.singleton(e1()), queue.filter(T -> KEY_EQUALS_NOT(T, e1())).pourAsList().TO_ARRAY()));
} }
protected boolean expectMissing(COLLECTION KEY_GENERIC_TYPE result, KEY_OBJECT_TYPE...elements) protected boolean expectMissing(COLLECTION KEY_GENERIC_TYPE result, KEY_OBJECT_TYPE...elements)
@@ -51,15 +51,7 @@ public class HashUtil
* @return the input number rounded up to the next power of two * @return the input number rounded up to the next power of two
*/ */
public static int nextPowerOfTwo(int x) { public static int nextPowerOfTwo(int x) {
if(x != 0) { return 1 << (32 - Integer.numberOfLeadingZeros(x - 1));
x--;
x |= x >> 1;
x |= x >> 2;
x |= x >> 4;
x |= x >> 8;
x |= x >> 16;
}
return x + 1;
} }
/** /**
@@ -69,16 +61,7 @@ public class HashUtil
* @return the input number rounded up to the next power of two * @return the input number rounded up to the next power of two
*/ */
public static long nextPowerOfTwo(long x) { public static long nextPowerOfTwo(long x) {
if(x != 0) { return 1L << (64 - Long.numberOfLeadingZeros(x - 1));
x--;
x |= x >> 1;
x |= x >> 2;
x |= x >> 4;
x |= x >> 8;
x |= x >> 16;
x |= x >> 32;
}
return x + 1L;
} }
/** /**