Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3f6ffea14e | ||
|
|
9c09f2ee70 | ||
|
|
3fc6bed79a |
+1
-1
@@ -38,7 +38,7 @@
|
||||
<attribute name="gradle_used_by_scope" value="builder"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8/"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
|
||||
<classpathentry kind="output" path="bin/default"/>
|
||||
</classpath>
|
||||
|
||||
+10
-2
@@ -11,15 +11,23 @@ gradle-app.setting
|
||||
|
||||
# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
|
||||
# gradle/wrapper/gradle-wrapper.properties
|
||||
|
||||
.classpath
|
||||
.project
|
||||
|
||||
---> Custom
|
||||
# IntelliJ
|
||||
|
||||
.idea/
|
||||
out/
|
||||
*.iws
|
||||
*.ipr
|
||||
*.iml
|
||||
|
||||
# ---> Custom
|
||||
!/libs/
|
||||
/.settings/
|
||||
/bin/
|
||||
/storage/
|
||||
|
||||
#Generated Code
|
||||
/src/main/java/speiger/src/collections/booleans/*
|
||||
/src/main/java/speiger/src/collections/bytes/*
|
||||
|
||||
@@ -1,70 +1,5 @@
|
||||
# Changelog of versions
|
||||
|
||||
### Version 0.5.0
|
||||
- Added: 2 Helper functions to find out how many bits are required to store a Number.
|
||||
- Added: pour function directly into Iterable which allows to collect all elements in the Iterable directly.
|
||||
- Added: The new ToArray method from Java9 and newer into the library. Using a functional interface. (Just a backport)
|
||||
- Changed: Reworked how the Map Builder functions are created. They are now in a SubClass that moves them out of the way. Less Clutter. (This might break things if that was used before)
|
||||
- Added: Map Builder that allows now to Build Maps like Guava ImmutableMaps can be build. Note: This has a slight performance overhead.
|
||||
- Added: Unmodifiable and Synchronize wrapper functions direclty into Collection Interfaces. This is mostly a quality of life thing.
|
||||
- Added: Unmodifiable and Synchronized Wrapper Collections can now be cloned. They clone the underlying map which doesn't break functionality. (Had a usecase for it)
|
||||
- Added: A boxed putAll array variant.
|
||||
- Fixed: EnumMaps didn't keep track of their size and now got proper care and implementations as needed. There might be more work required but at least the core functionality is now up to date.
|
||||
- Added: Tests for the new Stream replace functions to ensure no bugs are left.
|
||||
- Fixed: Custom HashSet reduce function with a default value was checking incorrectly for present keys.
|
||||
- Added: Guava TestSuit
|
||||
- Fixed: HashCode and toString method would crash if the Object Key/Value was null
|
||||
- Added: AbstractTypeCollection now delegates the contains check to type-specific Collections if it detects it.
|
||||
- Fixed: Map.Entry toString wasn't writing values not like it should do.
|
||||
- Fixed: Set.hashCode now is the sum of the elements instead of a Unique HashCode based on the elements.
|
||||
- Fixed: Added missing NonNull Checks.
|
||||
- Fixed: Custom/OpenHashMap.containsValue implementation was wrong.
|
||||
- Fixed: Custom/OpenHashMap.compute/present/absent now works how it is specified in the Java Documentation
|
||||
- Fixed: Custom/OpenHashMap.merge/BulkMerge now works how it is specified in the Java Documentation
|
||||
- Fixed: Custom/Linked/OpenHashMap.keySet.remove was causing a infinite loop.
|
||||
- Fixed: Custom/Linked/OpenHashMap.entrySet.contains was not correctly comparing the entry.
|
||||
- Fixed: Custom/OpenHashMap.mapIterator now no longer crashes in certain cases.
|
||||
- Added: Custom/LinkedOpenHashMap now takes use of the improved Iterator it has for containsValue
|
||||
- Fixed: CustomOpenHashMap.keySet.forEach was basically putting out keys even if they were present
|
||||
- Fixed: ImmutableMaps issues thanks to the tests. Roughly the same as the rest of the maps
|
||||
- Fixed: RB/AVLTreeMaps issues. Roughly the same as the rest of the maps
|
||||
- Fixed: SubLists are now properly implemented.
|
||||
- Fixed: HashSet Iterator bugs now fixed... That was Painful.
|
||||
- Added: Tests for Lists and Sets
|
||||
|
||||
### Version 0.4.5
|
||||
- Added: removeAll/retainAll(Collection c, Consumer r) which receives all the elements that got deleted from the collection
|
||||
- Fixed: Supplier get function wasn't referencing original function.
|
||||
- Added: addIfPresent/Absent to lists
|
||||
- Added: distinct, limit and peek iterators
|
||||
- Added: Iterable's can now reduce its contents
|
||||
- Added: Better ForEach support for IterableWrappers so a Iterator chain is not created
|
||||
- Added: SwapRemove to Lists which moves the last element into the desired space to be deleted
|
||||
- Added: More Test cases
|
||||
|
||||
### Version 0.4.4
|
||||
- Fixed: ObjectArrayList.of was causing crashes because of a Poor implementation.
|
||||
- Added: Unsorted HashMaps/Sets now throw Concurrent exceptions if they were modified during a rehash.
|
||||
- Added: Array/Collection version of enqueue and enqueueFirst to PriorityQueues.
|
||||
- Added: fillBuffer function into PrimitiveLists which allow to optimize JavaNio buffers if needed.
|
||||
|
||||
### Version 0.4.3
|
||||
- Added: Wrapper now support the Optimized Lambda replacer functions to improve performance.
|
||||
- Added: FIFO Queue has now a minimum capacity and that is now checked more consistently.
|
||||
|
||||
### Version 0.4.2
|
||||
- Added: Lists/Sets/Maps/PriorityQueues are now copy-able. with the new copy() function.
|
||||
Note: subLists/subMaps/subSets or synchronize/unmodifyable wrappers do not support that function.
|
||||
- Fixed: PriorityQueues didn't implement: hashCode/equals/toString
|
||||
|
||||
### Version 0.4.1
|
||||
- Changed: ForEach with input now provides input, value instead of value, input, this improves the usage of method references greatly
|
||||
- Added: addAll with Array-types in collections.
|
||||
- Added: Java Iterator/Iterable support for Stream replacing methods
|
||||
- Added: Suppliers.
|
||||
- Added: SupplyIfAbsent. It is ComputeIfAbsent but using suppliers
|
||||
- Added: Count feature into Iterable
|
||||
- Fixed: A couple bugs with the new StreamReplacing functions in LinkedCollections Iterating to Infinity
|
||||
|
||||
### Version 0.4.0
|
||||
- Changed: Iterable specific helper functions were moved out of Iterators and moved into Iterables
|
||||
|
||||
@@ -11,53 +11,27 @@ But its focus is a different one.
|
||||
- EnumMap
|
||||
- Immutable Maps/Lists/Sets
|
||||
- Priority Queue
|
||||
- Streams & Functional Queries
|
||||
- Streams
|
||||
- SplitIterators
|
||||
- Iterators
|
||||
- Pairs
|
||||
- Unary/Functions
|
||||
- Suppliers
|
||||
- Bi/Consumers
|
||||
|
||||
|
||||
## Current Level of Stability
|
||||
Since this is a relatively new Library, stability was not perfect and some areas are not perfect yet.
|
||||
Thanks to [ben-manes](https://github.com/ben-manes) we now have Roughly 16000 test covering Maps/Sets/Lists.
|
||||
These tests cover Javas Collection API completely and ensuring a Stable implementation.
|
||||
These freshly added tests allowed me to squash thousands of issues according to Googles Test Library (Guava-Tests).
|
||||
These will be expanded on as time goes on.
|
||||
|
||||
One know aspect of Instability is SubSets and SubMaps. They require full rewrites to be fully stable.
|
||||
So it is not advised to use them until these issues are addressed.
|
||||
PriorityQueues are tested separately and ensure basic functionality though GuavaTests are planned.
|
||||
They just require a custom test implementation.
|
||||
|
||||
As a summary: Stability is good/excellent, unless you need SubSets/SubMaps
|
||||
|
||||
## Specialized Functions
|
||||
New Specialized functions that were added to increase performance or reduce allocations or Quality Of life.
|
||||
To highlight things that may be wanted.
|
||||
- Iterable:
|
||||
- map/flatMap/arrayFlatMap: A Light weight version of Stream.map().
|
||||
- map/flatMap/arrayFlatMap: A Light weight version of Stream.map()
|
||||
- findFirst: Allows to find the first element of a Predicated Iterable.
|
||||
- filter: Allows to filter unwanted elements for wrapped Iterable
|
||||
- matchAny/matchNone/matchAll: Allows to find elements in a collection.
|
||||
- count: counts all valid elements in a collection.
|
||||
- forEach: Allows to input a second element into a forEach move allowing for more flexibility for Method References
|
||||
- reduce/limit/peek/distinct: Light Versions of the Stream variant, to reduce Stream usage.
|
||||
- pour: a function that allows to collect all elements within the Collection
|
||||
- Collection:
|
||||
- containsAny: Allows to test if another collection contains an of the elements of the tested collection.
|
||||
- primitiveStream: Provides access to the closest Java Stream Type.
|
||||
- copy: shallowCopies the collection, used instead of clone because this is better to use.
|
||||
(subCollections not supported for obvious reasons)
|
||||
- toArray: the ToArray function from Java9 and newer that uses a Functional interface and can use a method reference
|
||||
- List:
|
||||
- add/get/removeElements (From FastUtil): Allows to add/get/remove an Array into/from a list. Just with less overhead
|
||||
- extractElements: Allows to remove a Range of elements from the List and get what was removed.
|
||||
- Unstable Sort(From FastUtil): Uses a faster but not stable sort (Quick-Sort as example) to sort the list.
|
||||
- addIfAbsent/Present: adds a element only if absent/present in the list
|
||||
- swapRemove: deletes a desired element and inserts the last element in its place instead of leftshifting elements.
|
||||
- SortedSet:
|
||||
- addAndMoveToFirst/Last (From FastUtil but moved to Interface): Allows to add a element to the first/last position of a sorted set.
|
||||
- moveToFirst/Last: Moves the desired element at the first/last position of the SortedSet.
|
||||
@@ -69,7 +43,6 @@ To highlight things that may be wanted.
|
||||
- addToAll: Same as addTo but bulkVersion.
|
||||
- removeOrDefault: removes a Element and if not present returns the default value instead of the present value.
|
||||
- mergeAll: BulkVersion of Merge function.
|
||||
- supplyIfAbsent: A Supplier based computeIfAbsent
|
||||
- Sorted Map:
|
||||
- addAndMoveToFirst/Last (From FastUtil but moved to Interface): Allows to add a element to the first/last position of a sorted Map.
|
||||
- moveToFirst/Last: Moves the desired element at the first/last position of the Map.
|
||||
@@ -83,9 +56,6 @@ Any 0.x.0 version (Minor) can be reason for massive changes including API.
|
||||
To ensure that problems can be dealt with even if it is breaking the current API.
|
||||
Any breaking changes will be Documented (once 1.0 is released)
|
||||
|
||||
Also to save space every 0.0.x (Patch) that is 2 Minor Versions behind will be removed.
|
||||
So if 0.5.0 is released every 0.3.x patch will be deleted, except for the last patch for that minor version.
|
||||
|
||||
# How to install
|
||||
Using Gradle:
|
||||
```gradle
|
||||
@@ -95,21 +65,18 @@ repositories {
|
||||
}
|
||||
}
|
||||
dependencies {
|
||||
compile 'de.speiger:Primitive-Collections:0.5.0'
|
||||
compile 'de.speiger:Primitive-Collections:0.4.0'
|
||||
}
|
||||
```
|
||||
Direct:
|
||||
|
||||
| Version | Jar | Sources | Java Doc |
|
||||
|--------- |------------------------------------------------------------------------------------------------------------------------------ |-------------------------------------------------------------------------------------------------------------------------------------- |-------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| 0.5.0 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.5.0/Primitive-Collections-0.5.0.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.5.0/Primitive-Collections-0.5.0-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.5.0/Primitive-Collections-0.5.0-javadoc.jar) |
|
||||
| 0.4.5 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.5/Primitive-Collections-0.4.5.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.5/Primitive-Collections-0.4.5-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.5/Primitive-Collections-0.4.5-javadoc.jar) |
|
||||
| 0.4.4 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.4/Primitive-Collections-0.4.4.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.4/Primitive-Collections-0.4.4-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.4/Primitive-Collections-0.4.4-javadoc.jar) |
|
||||
| 0.4.3 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.3/Primitive-Collections-0.4.3.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.3/Primitive-Collections-0.4.3-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.3/Primitive-Collections-0.4.3-javadoc.jar) |
|
||||
| 0.4.2 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.2/Primitive-Collections-0.4.2.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.2/Primitive-Collections-0.4.2-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.2/Primitive-Collections-0.4.2-javadoc.jar) |
|
||||
| 0.4.1 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.1/Primitive-Collections-0.4.1.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.1/Primitive-Collections-0.4.1-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.1/Primitive-Collections-0.4.1-javadoc.jar) |
|
||||
| 0.4.0 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.0/Primitive-Collections-0.4.0.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.0/Primitive-Collections-0.4.0-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.0/Primitive-Collections-0.4.0-javadoc.jar) |
|
||||
| 0.3.6 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.3.6/Primitive-Collections-0.3.6.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.3.6/Primitive-Collections-0.3.6-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.3.6/Primitive-Collections-0.3.6-javadoc.jar) |
|
||||
| 0.3.5 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.3.5/Primitive-Collections-0.3.5.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.3.5/Primitive-Collections-0.3.5-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.3.5/Primitive-Collections-0.3.5-javadoc.jar) |
|
||||
| 0.3.4 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.3.4/Primitive-Collections-0.3.4.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.3.4/Primitive-Collections-0.3.4-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.3.4/Primitive-Collections-0.3.4-javadoc.jar) |
|
||||
| 0.3.3 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.3.3/Primitive-Collections-0.3.3.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.3.3/Primitive-Collections-0.3.3-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.3.3/Primitive-Collections-0.3.3-javadoc.jar) |
|
||||
|
||||
# Contributing
|
||||
If you want to contribute.
|
||||
@@ -134,5 +101,5 @@ to build the jar:
|
||||
do not combine the commands because they can not be executed at the same time.
|
||||
|
||||
## Current Down Sides (Random order)
|
||||
- SubMaps/Set implementation isn't perfect right now. This will be addressed slowly due to rewrites required.
|
||||
- Testing for Sub Maps/Sets/Lists are only in a very basic way tested
|
||||
- Documentation is only present at the lowest level for most cases and needs a typo fixing.
|
||||
+40
-20
@@ -1,9 +1,7 @@
|
||||
plugins {
|
||||
id 'java-library'
|
||||
}
|
||||
|
||||
tasks.withType(JavaCompile) {
|
||||
options.encoding = 'UTF-8'
|
||||
buildscript {
|
||||
def config = new Properties()
|
||||
file('build.properties').withInputStream(config.&load)
|
||||
project.ext.config = config
|
||||
}
|
||||
|
||||
apply plugin: 'java'
|
||||
@@ -12,25 +10,50 @@ apply plugin: 'maven'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
google()
|
||||
|
||||
maven {
|
||||
url = "https://maven.speiger.com/repository/main"
|
||||
}
|
||||
}
|
||||
|
||||
archivesBaseName = 'Primitive Collections'
|
||||
version = '0.5.0';
|
||||
|
||||
sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8'
|
||||
archivesBaseName = config.project_name
|
||||
version = config.project_version
|
||||
group = config.project_group
|
||||
sourceCompatibility = config.java_source_version
|
||||
targetCompatibility = config.java_target_version
|
||||
|
||||
javadoc {
|
||||
options.tags = [ "implSpec", "note" ]
|
||||
failOnError = false
|
||||
options.memberLevel = JavadocMemberLevel.PUBLIC
|
||||
options.quiet()
|
||||
}
|
||||
|
||||
eclipse {
|
||||
classpath {
|
||||
downloadJavadoc = true
|
||||
downloadSources = true
|
||||
|
||||
file {
|
||||
whenMerged {
|
||||
//Enforce a custom container and allowing access to the sun.misc package which is nessesary for EnumMaps
|
||||
entries.find{ it.kind == 'con' && it.path.startsWith('org.eclipse.jdt')}.path = 'org.eclipse.jdt.launching.JRE_CONTAINER';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tasks.withType(JavaCompile) {
|
||||
sourceCompatibility = config.java_source_version
|
||||
targetCompatibility = config.java_target_version
|
||||
options.encoding = 'UTF-8'
|
||||
}
|
||||
|
||||
compileJava {
|
||||
options.compilerArgs << '-XDignore.symbol.file'
|
||||
options.fork = true
|
||||
options.forkOptions.executable = 'javac' // may not needed on 1.8
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
@@ -42,11 +65,12 @@ configurations {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
builderCompile 'de.speiger:Simple-Code-Generator:1.0.5'
|
||||
runtimeOnly 'de.speiger:Simple-Code-Generator:1.0.5'
|
||||
testImplementation 'junit:junit:4.12'
|
||||
testImplementation 'com.google.guava:guava-testlib:31.0.1-jre'
|
||||
implementation group: 'org.jetbrains', name: 'annotations', version: config.annotations_version
|
||||
|
||||
builderCompile group: 'de.speiger', name: 'Simple-Code-Generator', version: config.scg_version
|
||||
runtimeOnly group: 'de.speiger', name: 'Simple-Code-Generator', version: config.scg_version
|
||||
|
||||
testImplementation 'junit:junit:4.12'
|
||||
}
|
||||
|
||||
task generateSource(type: JavaExec) {
|
||||
@@ -74,10 +98,6 @@ task srcJar(type: Jar) {
|
||||
classifier = 'sources'
|
||||
}
|
||||
|
||||
javadoc.failOnError = false
|
||||
javadoc.options.memberLevel = JavadocMemberLevel.PUBLIC
|
||||
javadoc.options.quiet()
|
||||
|
||||
artifacts {
|
||||
archives javadocJar
|
||||
archives srcJar
|
||||
@@ -97,8 +117,8 @@ uploadArchives {
|
||||
}
|
||||
pom {
|
||||
version = project.version
|
||||
artifactId = project.archivesBaseName.replace(" ", "-")
|
||||
groupId = 'de.speiger'
|
||||
artifactId = config.artifact_id
|
||||
groupId = config.artifact_group
|
||||
project {
|
||||
licenses {
|
||||
license {
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
project_name=PrimitiveCollections
|
||||
project_id=primitivecollections
|
||||
project_group=speiger.src.collections
|
||||
project_version=0.4.0
|
||||
|
||||
artifact_group=de.speiger
|
||||
artifact_id=Primitive-Collections
|
||||
|
||||
java_source_version=11
|
||||
java_target_version=8
|
||||
annotations_version=22.0.0
|
||||
|
||||
scg_version=1.0.4
|
||||
@@ -75,7 +75,6 @@ public class GlobalVariables
|
||||
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("<>");
|
||||
@@ -128,8 +127,8 @@ public class GlobalVariables
|
||||
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();
|
||||
addInjectMapper(fix+"_TO_HASH", type.isObject() ? "%s.hashCode()" : type.getClassType(value)+".hashCode(%s)").removeBraces();
|
||||
addInjectMapper(fix+"_TO_STRING", type.isObject() ? "%s.toString()" : 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");
|
||||
@@ -148,13 +147,11 @@ public class GlobalVariables
|
||||
{
|
||||
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");
|
||||
@@ -186,7 +183,6 @@ public class GlobalVariables
|
||||
|
||||
//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");
|
||||
@@ -207,8 +203,7 @@ public class GlobalVariables
|
||||
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("BI_OBJECT_CONSUMER", "ObjectConsumer");
|
||||
addClassMapper("SPLIT_ITERATOR", "Splititerator");
|
||||
addClassMapper("ITERATOR", "Iterator");
|
||||
addClassMapper("ITERABLE", "Iterable");
|
||||
@@ -229,8 +224,6 @@ public class GlobalVariables
|
||||
addClassMapper("SET", "Set");
|
||||
addClassMapper("STRATEGY", "Strategy");
|
||||
addClassMapper("STACK", "Stack");
|
||||
addClassMapper("SUPPLIER", "Supplier");
|
||||
addAbstractMapper("SINGLE_UNARY_OPERATOR", "%1$s%1$sUnaryOperator");
|
||||
addBiClassMapper("UNARY_OPERATOR", "UnaryOperator", "");
|
||||
if(type.isObject())
|
||||
{
|
||||
@@ -256,7 +249,6 @@ public class GlobalVariables
|
||||
|
||||
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());
|
||||
@@ -282,12 +274,10 @@ public class GlobalVariables
|
||||
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");
|
||||
@@ -296,7 +286,6 @@ public class GlobalVariables
|
||||
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");
|
||||
|
||||
@@ -78,7 +78,6 @@ public class PrimitiveCollectionsBuilder extends TemplateProcessor
|
||||
nameRemapper.put("IArray", "I%sArray");
|
||||
nameRemapper.put("AbstractMap", "Abstract%sMap");
|
||||
nameRemapper.put("AbstractCollection", "Abstract%sCollection");
|
||||
nameRemapper.put("AbstractPriorityQueue", "Abstract%sPriorityQueue");
|
||||
nameRemapper.put("AbstractSet", "Abstract%sSet");
|
||||
nameRemapper.put("AbstractList", "Abstract%sList");
|
||||
nameRemapper.put("EnumMap", "Enum2%sMap");
|
||||
|
||||
-55
@@ -3,13 +3,9 @@ package speiger.src.collections.PACKAGE.collections;
|
||||
import java.util.Collection;
|
||||
import java.util.Objects;
|
||||
import java.util.AbstractCollection;
|
||||
#if TYPE_OBJECT
|
||||
import java.util.function.Consumer;
|
||||
#endif
|
||||
|
||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
import speiger.src.collections.PACKAGE.utils.ITERATORS;
|
||||
#endif
|
||||
|
||||
@@ -39,9 +35,6 @@ public abstract class ABSTRACT_COLLECTION KEY_GENERIC_TYPE extends AbstractColle
|
||||
return modified;
|
||||
}
|
||||
|
||||
@Override
|
||||
public COLLECTION KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
/** {@inheritDoc}
|
||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||
@@ -83,19 +76,12 @@ public abstract class ABSTRACT_COLLECTION KEY_GENERIC_TYPE extends AbstractColle
|
||||
@Override
|
||||
public boolean containsAll(COLLECTION KEY_GENERIC_TYPE c) {
|
||||
Objects.requireNonNull(c);
|
||||
if(c.isEmpty()) return true;
|
||||
for(ITERATOR KEY_GENERIC_TYPE iter = c.iterator();iter.hasNext();)
|
||||
if(!contains(iter.NEXT()))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsAll(Collection<?> c) {
|
||||
Objects.requireNonNull(c);
|
||||
return c instanceof COLLECTION ? containsAll((COLLECTION KEY_GENERIC_TYPE)c) : super.containsAll(c);
|
||||
}
|
||||
|
||||
/**
|
||||
* This implementation iterates over the elements of the collection and checks if they are stored in this collection
|
||||
* @param c the elements that should be checked for
|
||||
@@ -107,7 +93,6 @@ public abstract class ABSTRACT_COLLECTION KEY_GENERIC_TYPE extends AbstractColle
|
||||
@Primitive
|
||||
public boolean containsAny(Collection<?> c) {
|
||||
Objects.requireNonNull(c);
|
||||
if(c.isEmpty()) return false;
|
||||
for(Object e : c)
|
||||
if(contains(e))
|
||||
return true;
|
||||
@@ -123,7 +108,6 @@ public abstract class ABSTRACT_COLLECTION KEY_GENERIC_TYPE extends AbstractColle
|
||||
@Override
|
||||
public boolean containsAny(COLLECTION KEY_GENERIC_TYPE c) {
|
||||
Objects.requireNonNull(c);
|
||||
if(c.isEmpty()) return false;
|
||||
for(ITERATOR KEY_GENERIC_TYPE iter = c.iterator();iter.hasNext();)
|
||||
if(contains(iter.NEXT()))
|
||||
return true;
|
||||
@@ -166,7 +150,6 @@ public abstract class ABSTRACT_COLLECTION KEY_GENERIC_TYPE extends AbstractColle
|
||||
@Override
|
||||
public boolean removeAll(COLLECTION KEY_GENERIC_TYPE c) {
|
||||
Objects.requireNonNull(c);
|
||||
if(c.isEmpty()) return false;
|
||||
boolean modified = false;
|
||||
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
||||
if(c.contains(iter.NEXT())) {
|
||||
@@ -177,23 +160,6 @@ public abstract class ABSTRACT_COLLECTION KEY_GENERIC_TYPE extends AbstractColle
|
||||
return modified;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeAll(COLLECTION KEY_GENERIC_TYPE c, CONSUMER KEY_GENERIC_TYPE r) {
|
||||
Objects.requireNonNull(c);
|
||||
if(c.isEmpty()) return false;
|
||||
Objects.requireNonNull(r);
|
||||
boolean modified = false;
|
||||
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
||||
KEY_TYPE e = iter.NEXT();
|
||||
if(c.contains(e)) {
|
||||
r.accept(e);
|
||||
iter.remove();
|
||||
modified = true;
|
||||
}
|
||||
}
|
||||
return modified;
|
||||
}
|
||||
|
||||
/**
|
||||
* A Type-Specific implementation of retainAll. This Implementation iterates over all elements and removes them as they were not found in the other collection.
|
||||
* @param c the elements that should be kept
|
||||
@@ -218,27 +184,6 @@ public abstract class ABSTRACT_COLLECTION KEY_GENERIC_TYPE extends AbstractColle
|
||||
return modified;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c, CONSUMER KEY_GENERIC_TYPE r) {
|
||||
Objects.requireNonNull(c);
|
||||
Objects.requireNonNull(r);
|
||||
if(c.isEmpty()) {
|
||||
boolean modified = !isEmpty();
|
||||
forEach(r);
|
||||
clear();
|
||||
return modified;
|
||||
}
|
||||
boolean modified = false;
|
||||
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
||||
KEY_TYPE e = iter.NEXT();
|
||||
if(!c.contains(e)) {
|
||||
iter.remove();
|
||||
modified = true;
|
||||
}
|
||||
}
|
||||
return modified;
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
/**
|
||||
* A Type-Specific implementation of toArray that links to {@link #TO_ARRAY(KEY_TYPE[])} with a newly created array.
|
||||
|
||||
+4
-113
@@ -8,16 +8,12 @@ import java.util.function.Predicate;
|
||||
import java.util.stream.JAVA_STREAM;
|
||||
import java.util.stream.StreamSupport;
|
||||
#endif
|
||||
#if TYPE_OBJECT
|
||||
import java.util.function.Consumer;
|
||||
import speiger.src.collections.ints.functions.function.Int2ObjectFunction;
|
||||
#else
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
||||
import speiger.src.collections.PACKAGE.utils.COLLECTIONS;
|
||||
|
||||
#if TYPE_BYTE || TYPE_SHORT || TYPE_CHAR || TYPE_FLOAT
|
||||
import speiger.src.collections.utils.SanityChecks;
|
||||
|
||||
#endif
|
||||
/**
|
||||
* A Type-Specific {@link Collection} that reduces (un)boxing
|
||||
* @Type(T)
|
||||
@@ -40,38 +36,6 @@ public interface COLLECTION KEY_GENERIC_TYPE extends Collection<CLASS_TYPE>, ITE
|
||||
*/
|
||||
public boolean addAll(COLLECTION KEY_GENERIC_TYPE c);
|
||||
|
||||
/**
|
||||
* A Type-Specific Array based addAll method to reduce the amount of Wrapping
|
||||
* @param e the elements that should be added
|
||||
* @return if the collection was modified
|
||||
*/
|
||||
public default boolean addAll(KEY_TYPE... e) { return addAll(e, 0, e.length); }
|
||||
|
||||
/**
|
||||
* A Type-Specific Array based addAll method to reduce the amount of Wrapping
|
||||
* @param e the elements that should be added
|
||||
* @param length how many elements of the array should be added
|
||||
* @return if the collection was modified
|
||||
*/
|
||||
public default boolean addAll(KEY_TYPE[] e, int length) { return addAll(e, 0, length); }
|
||||
|
||||
/**
|
||||
* A Type-Specific Array based addAll method to reduce the amount of Wrapping
|
||||
* @param e the elements that should be added
|
||||
* @param offset where to start within the array
|
||||
* @param length how many elements of the array should be added
|
||||
* @return if the collection was modified
|
||||
*/
|
||||
public default boolean addAll(KEY_TYPE[] e, int offset, int length) {
|
||||
if(length <= 0) return false;
|
||||
SanityChecks.checkArrayCapacity(e.length, offset, length);
|
||||
boolean added = false;
|
||||
for(int i = 0;i<length;i++) {
|
||||
if(add(e[offset+i])) added = true;
|
||||
}
|
||||
return added;
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
/**
|
||||
* A Type-Specific contains function to reduce (un)boxing
|
||||
@@ -122,16 +86,6 @@ public interface COLLECTION KEY_GENERIC_TYPE extends Collection<CLASS_TYPE>, ITE
|
||||
*/
|
||||
public boolean removeAll(COLLECTION KEY_GENERIC_TYPE c);
|
||||
|
||||
/**
|
||||
* A Type-Specific removeAll function that reduces (un)boxing.
|
||||
* It also notifies the remover of which exact element is going to be removed.
|
||||
* @param c the collection of elements that should be removed
|
||||
* @param r elements that got removed
|
||||
* @return true if any element was removed
|
||||
* @see Collection#removeAll(Collection)
|
||||
*/
|
||||
public boolean removeAll(COLLECTION KEY_GENERIC_TYPE c, CONSUMER KEY_GENERIC_TYPE r);
|
||||
|
||||
/**
|
||||
* A Type-Specific retainAll function that reduces (un)boxing.
|
||||
* @param c the collection of elements that should be kept
|
||||
@@ -140,48 +94,7 @@ public interface COLLECTION KEY_GENERIC_TYPE extends Collection<CLASS_TYPE>, ITE
|
||||
*/
|
||||
public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c);
|
||||
|
||||
/**
|
||||
* A Type-Specific retainAll function that reduces (un)boxing.
|
||||
* It also notifies the remover of which exact element is going to be removed.
|
||||
* @param c the collection of elements that should be kept
|
||||
* @param r elements that got removed
|
||||
* @return true if any element was removed
|
||||
* @see Collection#retainAll(Collection)
|
||||
*/
|
||||
public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c, CONSUMER KEY_GENERIC_TYPE r);
|
||||
|
||||
/**
|
||||
* A Helper function to reduce the usage of Streams and allows to collect all elements
|
||||
* @param collection that the elements should be inserted to
|
||||
* @param <E> the collection type
|
||||
* @return the input with the desired elements
|
||||
*/
|
||||
default <E extends COLLECTION KEY_GENERIC_TYPE> E pour(E collection) {
|
||||
collection.addAll(this);
|
||||
return collection;
|
||||
}
|
||||
|
||||
/**
|
||||
* A Function that does a shallow clone of the Collection itself.
|
||||
* This function is more optimized then a copy constructor since the Collection does not have to be unsorted/resorted.
|
||||
* It can be compared to Cloneable but with less exception risk
|
||||
* @return a Shallow Copy of the collection
|
||||
* @note Wrappers and view collections will not support this feature
|
||||
*/
|
||||
public COLLECTION KEY_GENERIC_TYPE copy();
|
||||
|
||||
#if TYPE_OBJECT
|
||||
/**
|
||||
* A Helper function that simplifies the process of creating a new Array.
|
||||
* @param action the array creation function
|
||||
* @return an array containing all of the elements in this collection
|
||||
* @see Collection#toArray(Object[])
|
||||
*/
|
||||
default KEY_TYPE[] TO_ARRAY(Int2ObjectFunction<KEY_TYPE[]> action) {
|
||||
return TO_ARRAY(action.get(size()));
|
||||
}
|
||||
|
||||
#else
|
||||
#if !TYPE_OBJECT
|
||||
/**
|
||||
* A Type-Specific toArray function that delegates to {@link #TO_ARRAY(KEY_TYPE[])} with a newly created array.
|
||||
* @return an array containing all of the elements in this collection
|
||||
@@ -268,28 +181,6 @@ public interface COLLECTION KEY_GENERIC_TYPE extends Collection<CLASS_TYPE>, ITE
|
||||
@Override
|
||||
public ITERATOR KEY_GENERIC_TYPE iterator();
|
||||
|
||||
/**
|
||||
* Creates a Wrapped Collection that is Synchronized
|
||||
* @return a new Collection that is synchronized
|
||||
* @see COLLECTIONS#synchronize
|
||||
*/
|
||||
public default COLLECTION KEY_GENERIC_TYPE synchronize() { return COLLECTIONS.synchronize(this); }
|
||||
|
||||
/**
|
||||
* Creates a Wrapped Collection that is Synchronized
|
||||
* @param mutex is the controller of the synchronization block
|
||||
* @return a new Collection Wrapper that is synchronized
|
||||
* @see COLLECTIONS#synchronize
|
||||
*/
|
||||
public default COLLECTION KEY_GENERIC_TYPE synchronize(Object mutex) { return COLLECTIONS.synchronize(this, mutex); }
|
||||
|
||||
/**
|
||||
* Creates a Wrapped Collection that is unmodifiable
|
||||
* @return a new Collection Wrapper that is unmodifiable
|
||||
* @see COLLECTIONS#unmodifiable
|
||||
*/
|
||||
public default COLLECTION KEY_GENERIC_TYPE unmodifiable() { return COLLECTIONS.unmodifiable(this); }
|
||||
|
||||
#if PRIMITIVES
|
||||
/**
|
||||
* Returns a Java-Type-Specific Stream to reduce boxing/unboxing.
|
||||
|
||||
+3
-116
@@ -1,23 +1,18 @@
|
||||
package speiger.src.collections.PACKAGE.collections;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.function.Consumer;
|
||||
#if !TYPE_OBJECT
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
import speiger.src.collections.objects.collections.ObjectIterable;
|
||||
#else
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.functions.function.TO_OBJECT_FUNCTION;
|
||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||
import speiger.src.collections.PACKAGE.functions.consumer.BI_OBJECT_CONSUMER;
|
||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||
import speiger.src.collections.PACKAGE.collections.SPLIT_ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
||||
import speiger.src.collections.PACKAGE.utils.ITERABLES;
|
||||
import speiger.src.collections.PACKAGE.utils.ITERATORS;
|
||||
|
||||
/**
|
||||
* A Type-Specific {@link Iterable} that reduces (un)boxing
|
||||
@@ -71,7 +66,7 @@ public interface ITERABLE KEY_GENERIC_TYPE extends Iterable<CLASS_TYPE>
|
||||
* @param <E> the generic type of the Object
|
||||
* @throws java.lang.NullPointerException if the specified action is null
|
||||
*/
|
||||
default <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
||||
default <E> void forEach(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE<E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
iterator().forEachRemaining(input, action);
|
||||
}
|
||||
@@ -123,43 +118,6 @@ public interface ITERABLE KEY_GENERIC_TYPE extends Iterable<CLASS_TYPE>
|
||||
return ITERABLES.filter(this, filter);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function to reduce the usage of Streams and allows to filter out duplicated elements
|
||||
* @return a Iterable that filtered out all duplicated elements
|
||||
*/
|
||||
default ITERABLE KEY_GENERIC_TYPE distinct() {
|
||||
return ITERABLES.distinct(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function to reduce the usage of Streams and allows to limit the amount of elements
|
||||
* @param limit the amount of elements it should be limited to
|
||||
* @return a Iterable that is limited in length
|
||||
*/
|
||||
default ITERABLE KEY_GENERIC_TYPE limit(long limit) {
|
||||
return ITERABLES.limit(this, limit);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function to reduce the usage of Streams and allows to preview elements before they are iterated through
|
||||
* @param action the action that should be applied
|
||||
* @return a Peeked Iterable
|
||||
*/
|
||||
default ITERABLE KEY_GENERIC_TYPE peek(CONSUMER KEY_GENERIC_TYPE action) {
|
||||
return ITERABLES.peek(this, action);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function to reduce the usage of Streams and allows to collect all elements
|
||||
* @param collection that the elements should be inserted to
|
||||
* @param <E> the collection type
|
||||
* @return the input with the desired elements
|
||||
*/
|
||||
default <E extends COLLECTION KEY_GENERIC_TYPE> E pour(E collection) {
|
||||
ITERATORS.pour(iterator(), collection);
|
||||
return collection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to reduce stream usage that allows to filter for any matches.
|
||||
* @param filter that should be applied
|
||||
@@ -212,75 +170,4 @@ public interface ITERABLE KEY_GENERIC_TYPE extends Iterable<CLASS_TYPE>
|
||||
}
|
||||
return EMPTY_VALUE;
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
/**
|
||||
* Performs a <a href="package-summary.html#Reduction">reduction</a> on the
|
||||
* elements of this Iterable
|
||||
* @param operator the operation that should be applied
|
||||
* @param identity the start value
|
||||
* @return the reduction result, returns identity if nothing was found
|
||||
*/
|
||||
default KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = identity;
|
||||
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
||||
state = operator.APPLY_VALUE(state, iter.NEXT());
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
#else
|
||||
/**
|
||||
* Performs a <a href="package-summary.html#Reduction">reduction</a> on the
|
||||
* elements of this Iterable
|
||||
* @param operator the operation that should be applied
|
||||
* @param identity the start value
|
||||
* @Type(E)
|
||||
* @return the reduction result, returns identity if nothing was found
|
||||
*/
|
||||
default <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_SPECIAL_TYPE state = identity;
|
||||
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
||||
state = operator.APPLY_VALUE(state, iter.NEXT());
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
#endif
|
||||
/**
|
||||
* Performs a <a href="package-summary.html#Reduction">reduction</a> on the
|
||||
* elements of this Iterable
|
||||
* @param operator the operation that should be applied
|
||||
* @return the reduction result, returns null value if nothing was found
|
||||
*/
|
||||
default KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = EMPTY_VALUE;
|
||||
boolean empty = true;
|
||||
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
||||
if(empty) {
|
||||
empty = false;
|
||||
state = iter.NEXT();
|
||||
continue;
|
||||
}
|
||||
state = operator.APPLY_VALUE(state, iter.NEXT());
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to reduce stream usage that allows to count the valid elements.
|
||||
* @param filter that should be applied
|
||||
* @return the amount of Valid Elements
|
||||
*/
|
||||
default int count(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
int result = 0;
|
||||
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
||||
if(filter.TEST_VALUE(iter.NEXT())) result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -8,7 +8,7 @@ import java.util.function.Consumer;
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
|
||||
#endif
|
||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||
import speiger.src.collections.PACKAGE.functions.consumer.BI_OBJECT_CONSUMER;
|
||||
|
||||
/**
|
||||
* A Type-Specific {@link Iterator} that reduces (un)boxing
|
||||
@@ -74,9 +74,9 @@ public interface ITERATOR KEY_GENERIC_TYPE extends Iterator<CLASS_TYPE>
|
||||
* @param <E> the generic type of the Object
|
||||
* @throws java.lang.NullPointerException if the specified action is null
|
||||
*/
|
||||
default <E> void forEachRemaining(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
||||
default <E> void forEachRemaining(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE<E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
while(hasNext()) { action.accept(input, NEXT()); }
|
||||
while(hasNext()) { action.accept(NEXT(), input); }
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
-26
@@ -1,26 +0,0 @@
|
||||
package speiger.src.collections.PACKAGE.functions;
|
||||
|
||||
/**
|
||||
* Type-Specific Supplier interface that reduces (un)boxing and allows to merge other consumer types into this interface
|
||||
* @Type(T)
|
||||
*/
|
||||
#if TYPE_OBJECT
|
||||
public interface SUPPLIER KEY_GENERIC_TYPE extends java.util.function.Supplier<KEY_TYPE>
|
||||
#else if JDK_TYPE && !TYPE_BOOLEAN
|
||||
public interface SUPPLIER KEY_GENERIC_TYPE extends JAVA_SUPPLIER
|
||||
#else
|
||||
public interface SUPPLIER KEY_GENERIC_TYPE
|
||||
#endif
|
||||
{
|
||||
/**
|
||||
* @return the supplied value
|
||||
*/
|
||||
public KEY_TYPE GET_KEY();
|
||||
#if JDK_TYPE && PRIMITIVES
|
||||
|
||||
@Override
|
||||
public default KEY_TYPE GET_JAVA() {
|
||||
return GET_KEY();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
+69
-191
@@ -3,15 +3,11 @@ package speiger.src.collections.PACKAGE.lists;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Objects;
|
||||
|
||||
import speiger.src.collections.PACKAGE.collections.ABSTRACT_COLLECTION;
|
||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.collections.SPLIT_ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
||||
import speiger.src.collections.utils.SanityChecks;
|
||||
|
||||
/**
|
||||
* Abstract implementation of the {@link LIST} interface.
|
||||
@@ -19,8 +15,9 @@ import speiger.src.collections.utils.SanityChecks;
|
||||
*/
|
||||
public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION KEY_GENERIC_TYPE implements LIST KEY_GENERIC_TYPE
|
||||
{
|
||||
#if !TYPE_OBJECT
|
||||
/**
|
||||
* A Type-Specific implementation of add function that delegates to {@link List#add(int, Object)}
|
||||
* A Type-Specific implementation of add function that delegates to {@link #add(int, KEY_TYPE)}
|
||||
*/
|
||||
@Override
|
||||
public boolean add(KEY_TYPE e) {
|
||||
@@ -28,7 +25,6 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
||||
return true;
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
/** {@inheritDoc}
|
||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||
* @deprecated Please use the corresponding type-specific function instead.
|
||||
@@ -159,14 +155,6 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public boolean REMOVE_SWAP(KEY_TYPE e) {
|
||||
int index = indexOf(e);
|
||||
if(index == -1) return false;
|
||||
swapRemove(index);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares if the list are the same.
|
||||
*/
|
||||
@@ -217,8 +205,7 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
||||
|
||||
@Override
|
||||
public LIST KEY_GENERIC_TYPE subList(int fromIndex, int toIndex) {
|
||||
SanityChecks.checkArrayCapacity(size(), fromIndex, toIndex-fromIndex);
|
||||
return new SubList(this, 0, fromIndex, toIndex);
|
||||
return new SUB_LIST(this, fromIndex, toIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -233,7 +220,6 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
||||
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE listIterator(int index) {
|
||||
if(index < 0 || index > size()) throw new IndexOutOfBoundsException();
|
||||
return new LIST_ITER(index);
|
||||
}
|
||||
|
||||
@@ -243,130 +229,116 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
||||
while(size < size()) REMOVE(size() - 1);
|
||||
}
|
||||
|
||||
public ABSTRACT_LIST KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
||||
|
||||
private class SubList extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
{
|
||||
final ABSTRACT_LIST KEY_GENERIC_TYPE list;
|
||||
final int parentOffset;
|
||||
final int offset;
|
||||
private class SUB_LIST extends ABSTRACT_LIST KEY_GENERIC_TYPE {
|
||||
ABSTRACT_LIST KEY_GENERIC_TYPE l;
|
||||
int offset;
|
||||
int size;
|
||||
|
||||
public SubList(ABSTRACT_LIST KEY_GENERIC_TYPE list, int offset, int from, int to) {
|
||||
this.list = list;
|
||||
this.parentOffset = from;
|
||||
this.offset = offset + from;
|
||||
this.size = to - from;
|
||||
SUB_LIST(ABSTRACT_LIST KEY_GENERIC_TYPE l, int from, int to) {
|
||||
if (from < 0) throw new IndexOutOfBoundsException("fromIndex = " + from);
|
||||
else if (to > l.size()) throw new IndexOutOfBoundsException("toIndex = " + to);
|
||||
else if (from > to) throw new IllegalArgumentException("fromIndex(" + from + ") > toIndex(" + to + ")");
|
||||
this.l = l;
|
||||
offset = from;
|
||||
size = to - from;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(int index, KEY_TYPE element) {
|
||||
checkAddSubRange(index);
|
||||
list.add(parentOffset+index, element);
|
||||
public void add(int index, KEY_TYPE e) {
|
||||
checkAddRange(index);
|
||||
l.add(index+offset, e);
|
||||
size++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAll(int index, Collection<? extends CLASS_TYPE> c) {
|
||||
checkAddSubRange(index);
|
||||
int add = c.size();
|
||||
if(add <= 0) return false;
|
||||
list.addAll(parentOffset+index, c);
|
||||
this.size += add;
|
||||
checkAddRange(index);
|
||||
int size = c.size();
|
||||
if(size == 0) return false;
|
||||
l.addAll(index + offset, l);
|
||||
offset += size;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAll(int index, COLLECTION KEY_GENERIC_TYPE c) {
|
||||
checkAddSubRange(index);
|
||||
int add = c.size();
|
||||
if(add <= 0) return false;
|
||||
list.addAll(parentOffset+index, c);
|
||||
this.size += add;
|
||||
checkAddRange(index);
|
||||
int size = c.size();
|
||||
if(size == 0) return false;
|
||||
l.addAll(index + offset, l);
|
||||
offset += size;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAll(int index, LIST KEY_GENERIC_TYPE c) {
|
||||
checkAddSubRange(index);
|
||||
int add = c.size();
|
||||
if(add <= 0) return false;
|
||||
list.addAll(parentOffset+index, c);
|
||||
this.size += add;
|
||||
checkAddRange(index);
|
||||
int size = c.size();
|
||||
if(size == 0) return false;
|
||||
l.addAll(index + offset, l);
|
||||
offset += size;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addElements(int from, KEY_TYPE[] a, int offset, int length) {
|
||||
checkAddSubRange(from);
|
||||
if(length <= 0) return;
|
||||
list.addElements(parentOffset+from, a, offset, length);
|
||||
this.size += length;
|
||||
checkRange(from);
|
||||
l.addElements(from + this.offset, a, offset, length);
|
||||
size += length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE[] getElements(int from, KEY_TYPE[] a, int offset, int length) {
|
||||
SanityChecks.checkArrayCapacity(size, from, length);
|
||||
SanityChecks.checkArrayCapacity(a.length, offset, length);
|
||||
return list.getElements(from+this.offset, a, offset, length);
|
||||
checkRange(from);
|
||||
return l.getElements(from + this.offset, a, offset, length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeElements(int from, int to) {
|
||||
if(to-from <= 0) return;
|
||||
checkSubRange(from);
|
||||
checkSubRange(to);
|
||||
list.removeElements(from+parentOffset, to+parentOffset);
|
||||
checkRange(from);
|
||||
checkRange(to);
|
||||
l.removeElements(from + offset, to + offset);
|
||||
size -= to - from;
|
||||
}
|
||||
|
||||
#if TYPE_OBJECT
|
||||
@Override
|
||||
public <K> K[] extractElements(int from, int to, Class<K> type) {
|
||||
checkSubRange(from);
|
||||
checkSubRange(to);
|
||||
K[] result = list.extractElements(from+parentOffset, to+parentOffset, type);
|
||||
public <K> K[] extractElements(int from, int to, Class<K> clz) {
|
||||
checkRange(from);
|
||||
checkRange(to);
|
||||
K[] a = l.extractElements(from + offset, to + offset, clz);
|
||||
size -= to - from;
|
||||
return result;
|
||||
return a;
|
||||
}
|
||||
|
||||
#else
|
||||
@Override
|
||||
public KEY_TYPE[] extractElements(int from, int to) {
|
||||
checkSubRange(from);
|
||||
checkSubRange(to);
|
||||
KEY_TYPE[] result = list.extractElements(from+parentOffset, to+parentOffset);
|
||||
checkRange(from);
|
||||
checkRange(to);
|
||||
KEY_TYPE[] a = l.extractElements(from + offset, to + offset);
|
||||
size -= to - from;
|
||||
return result;
|
||||
return a;
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public KEY_TYPE GET_KEY(int index) {
|
||||
checkSubRange(index);
|
||||
return list.GET_KEY(offset+index);
|
||||
checkRange(index);
|
||||
return l.GET_KEY(index + offset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE set(int index, KEY_TYPE element) {
|
||||
checkSubRange(index);
|
||||
return list.set(offset+index, element);
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE swapRemove(int index) {
|
||||
checkSubRange(index);
|
||||
KEY_TYPE result = list.swapRemove(index+parentOffset);
|
||||
size--;
|
||||
return result;
|
||||
public KEY_TYPE set(int index, KEY_TYPE e) {
|
||||
checkRange(index);
|
||||
return l.set(index + offset, e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE REMOVE(int index) {
|
||||
checkSubRange(index);
|
||||
KEY_TYPE result = list.REMOVE(index+parentOffset);
|
||||
checkRange(index);
|
||||
size--;
|
||||
return result;
|
||||
return l.REMOVE(index + offset);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -374,112 +346,15 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
||||
return size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SPLIT_ITERATOR KEY_GENERIC_TYPE spliterator() { return SPLIT_ITERATORS.createSplititerator(this, 16464); }
|
||||
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE listIterator(int index) {
|
||||
if(index < 0 || index > size()) throw new IndexOutOfBoundsException();
|
||||
return new SubListIterator(this, index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LIST KEY_GENERIC_TYPE subList(int fromIndex, int toIndex) {
|
||||
SanityChecks.checkArrayCapacity(size, fromIndex, toIndex-fromIndex);
|
||||
return new SubList(list, offset, fromIndex, toIndex);
|
||||
}
|
||||
|
||||
protected void checkSubRange(int index) {
|
||||
private void checkRange(int index) {
|
||||
if (index < 0 || index >= size)
|
||||
throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + size);
|
||||
}
|
||||
|
||||
protected void checkAddSubRange(int index) {
|
||||
private void checkAddRange(int index) {
|
||||
if (index < 0 || index > size)
|
||||
throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + size);
|
||||
}
|
||||
|
||||
private class SubListIterator implements LIST_ITERATOR KEY_GENERIC_TYPE
|
||||
{
|
||||
ABSTRACT_LIST KEY_GENERIC_TYPE list;
|
||||
int index;
|
||||
int lastReturned = -1;
|
||||
|
||||
SubListIterator(ABSTRACT_LIST KEY_GENERIC_TYPE list, int index) {
|
||||
this.list = list;
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return index < list.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE NEXT() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
int i = index++;
|
||||
return list.GET_KEY((lastReturned = i));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPrevious() {
|
||||
return index > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE PREVIOUS() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
index--;
|
||||
return list.GET_KEY((lastReturned = index));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int nextIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int previousIndex() {
|
||||
return index-1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
if(lastReturned == -1) throw new IllegalStateException();
|
||||
list.REMOVE(lastReturned);
|
||||
index = lastReturned;
|
||||
lastReturned = -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(KEY_TYPE e) {
|
||||
if(lastReturned == -1) throw new IllegalStateException();
|
||||
list.set(lastReturned, e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(KEY_TYPE e) {
|
||||
list.add(index++, e);
|
||||
lastReturned = -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int skip(int amount) {
|
||||
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
||||
int steps = Math.min(amount, (list.size() - 1) - index);
|
||||
index += steps;
|
||||
return steps;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int back(int amount) {
|
||||
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
||||
int steps = Math.min(amount, index);
|
||||
index -= steps;
|
||||
return steps;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class LIST_ITER implements LIST_ITERATOR KEY_GENERIC_TYPE {
|
||||
@@ -497,9 +372,8 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
||||
|
||||
@Override
|
||||
public KEY_TYPE NEXT() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
int i = index++;
|
||||
return GET_KEY((lastReturned = i));
|
||||
lastReturned = index;
|
||||
return GET_KEY(index++);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -509,9 +383,8 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
||||
|
||||
@Override
|
||||
public KEY_TYPE PREVIOUS() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
index--;
|
||||
return GET_KEY((lastReturned = index));
|
||||
lastReturned = index;
|
||||
return GET_KEY(index--);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -526,20 +399,25 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
if(lastReturned == -1) throw new IllegalStateException();
|
||||
if(lastReturned == -1)
|
||||
throw new IllegalStateException();
|
||||
ABSTRACT_LIST.this.REMOVE(lastReturned);
|
||||
index = lastReturned;
|
||||
if(lastReturned < index)
|
||||
index--;
|
||||
lastReturned = -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(KEY_TYPE e) {
|
||||
if(lastReturned == -1) throw new IllegalStateException();
|
||||
if(lastReturned == -1)
|
||||
throw new IllegalStateException();
|
||||
ABSTRACT_LIST.this.set(lastReturned, e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(KEY_TYPE e) {
|
||||
if(lastReturned == -1)
|
||||
throw new IllegalStateException();
|
||||
ABSTRACT_LIST.this.add(index++, e);
|
||||
lastReturned = -1;
|
||||
}
|
||||
|
||||
+4
-135
@@ -9,14 +9,12 @@ import java.util.Iterator;
|
||||
import java.util.Objects;
|
||||
#if TYPE_OBJECT
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.BiFunction;
|
||||
#endif
|
||||
import java.util.function.Predicate;
|
||||
import java.util.function.UnaryOperator;
|
||||
#if PRIMITIVES
|
||||
import java.util.function.JAVA_PREDICATE;
|
||||
import java.util.function.JAVA_UNARY_OPERATOR;
|
||||
import java.nio.JAVA_BUFFER;
|
||||
#endif
|
||||
|
||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||
@@ -28,9 +26,8 @@ import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
#endif
|
||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||
import speiger.src.collections.PACKAGE.functions.consumer.BI_OBJECT_CONSUMER;
|
||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||
import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
||||
import speiger.src.collections.PACKAGE.utils.ITERATORS;
|
||||
#if TYPE_OBJECT
|
||||
@@ -184,7 +181,7 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES ARRAY_LIST KEY_GENERIC_TYPE of(Class<KEY_TYPE> c) {
|
||||
ARRAY_LIST KEY_GENERIC_TYPE list = new ARRAY_LISTBRACES();
|
||||
list.data = (KEY_TYPE[])ObjectArrays.newArray(c, 0);
|
||||
list.data = (KEY_TYPE[])ObjectArrays.newArray(c.getClass().getComponentType(), 0);
|
||||
return list;
|
||||
}
|
||||
|
||||
@@ -285,16 +282,6 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAll(KEY_TYPE[] e, int offset, int length) {
|
||||
if(length <= 0) return false;
|
||||
SanityChecks.checkArrayCapacity(e.length, offset, length);
|
||||
grow(size + length);
|
||||
System.arraycopy(e, offset, data, size, length);
|
||||
size+=length;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the specified array elements to the index of the list.
|
||||
* @param from the index where to append the elements to
|
||||
@@ -393,13 +380,7 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
}
|
||||
|
||||
#endif
|
||||
#if PRIMITIVES
|
||||
@Override
|
||||
public void fillBuffer(JAVA_BUFFER buffer) {
|
||||
buffer.put(data, 0, size);
|
||||
}
|
||||
|
||||
#endif
|
||||
/**
|
||||
* A function to find if the Element is present in this list.
|
||||
* @param o the element that is searched for
|
||||
@@ -610,10 +591,10 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
||||
public <E> void forEach(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE<E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
for(int i = 0;i<size;i++)
|
||||
action.accept(input, data[i]);
|
||||
action.accept(data[i], input);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -652,55 +633,6 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
return EMPTY_VALUE;
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = identity;
|
||||
for(int i = 0;i<size;i++) {
|
||||
state = operator.APPLY_VALUE(state, data[i]);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
#else
|
||||
@Override
|
||||
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_SPECIAL_TYPE state = identity;
|
||||
for(int i = 0;i<size;i++) {
|
||||
state = operator.APPLY_VALUE(state, data[i]);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = EMPTY_VALUE;
|
||||
boolean empty = true;
|
||||
for(int i = 0;i<size;i++) {
|
||||
if(empty) {
|
||||
empty = false;
|
||||
state = data[i];
|
||||
continue;
|
||||
}
|
||||
state = operator.APPLY_VALUE(state, data[i]);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
int result = 0;
|
||||
for(int i = 0;i<size;i++) {
|
||||
if(filter.TEST_VALUE(data[i])) result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* A Type-Specific set function to reduce (un)boxing
|
||||
* @param index the index of the element to set
|
||||
@@ -774,17 +706,6 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
return old;
|
||||
}
|
||||
|
||||
public KEY_TYPE swapRemove(int index) {
|
||||
checkRange(index);
|
||||
KEY_TYPE old = data[index];
|
||||
size--;
|
||||
data[index] = data[size];
|
||||
#if TYPE_OBJECT
|
||||
data[size] = null;
|
||||
#endif
|
||||
return old;
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
/**
|
||||
* A Type-Specific implementation of remove. This implementation iterates over the elements until it finds the element that is searched for or it runs out of elements.
|
||||
@@ -916,22 +837,6 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
return modified;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeAll(COLLECTION KEY_GENERIC_TYPE c, CONSUMER KEY_GENERIC_TYPE r) {
|
||||
if(c.isEmpty()) return false;
|
||||
int j = 0;
|
||||
for(int i = 0;i<size;i++) {
|
||||
if(!c.contains(data[i])) data[j++] = data[i];
|
||||
else r.accept(data[i]);
|
||||
}
|
||||
boolean modified = j != size;
|
||||
#if TYPE_OBJECT
|
||||
Arrays.fill(data, j, size, null);
|
||||
#endif
|
||||
size = j;
|
||||
return modified;
|
||||
}
|
||||
|
||||
/**
|
||||
* A function to retain all elements that were provided in the other collection
|
||||
* This function might delegate to a more appropriate function if necessary
|
||||
@@ -959,27 +864,6 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
return modified;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c, CONSUMER KEY_GENERIC_TYPE r) {
|
||||
if(c.isEmpty()) {
|
||||
boolean modifed = size > 0;
|
||||
forEach(r);
|
||||
clear();
|
||||
return modifed;
|
||||
}
|
||||
int j = 0;
|
||||
for(int i = 0;i<size;i++) {
|
||||
if(c.contains(data[i])) data[j++] = data[i];
|
||||
else r.accept(data[i]);
|
||||
}
|
||||
boolean modified = j != size;
|
||||
#if TYPE_OBJECT
|
||||
Arrays.fill(data, j, size, null);
|
||||
#endif
|
||||
size = j;
|
||||
return modified;
|
||||
}
|
||||
|
||||
#if PRIMITIVES
|
||||
/**
|
||||
* A optimized List#removeIf(Predicate) that more quickly removes elements from the list then the ArrayList implementation
|
||||
@@ -1023,13 +907,8 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
public <E> E[] toArray(E[] a) {
|
||||
if(a == null) a = (E[])new Object[size];
|
||||
else if(a.length < size) a = (E[])ObjectArrays.newArray(a.getClass().getComponentType(), size);
|
||||
#if TYPE_OBJECT
|
||||
System.arraycopy(data, 0, a, 0, size);
|
||||
#else
|
||||
for(int i = 0;i<size;i++)
|
||||
a[i] = (E)KEY_TO_OBJ(data[i]);
|
||||
#endif
|
||||
if (a.length > size) a[size] = null;
|
||||
return a;
|
||||
}
|
||||
|
||||
@@ -1038,7 +917,6 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
public KEY_TYPE[] TO_ARRAY(KEY_TYPE[] a) {
|
||||
if(a.length < size) a = new KEY_TYPE[size];
|
||||
System.arraycopy(data, 0, a, 0, size);
|
||||
if (a.length > size) a[size] = EMPTY_KEY_VALUE;
|
||||
return a;
|
||||
}
|
||||
|
||||
@@ -1117,14 +995,6 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
grow(size);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ARRAY_LIST KEY_GENERIC_TYPE copy() {
|
||||
ARRAY_LIST KEY_GENERIC_TYPE list = new ARRAY_LISTBRACES();
|
||||
list.data = Arrays.copyOf(data, data.length);
|
||||
list.size = size;
|
||||
return list;
|
||||
}
|
||||
|
||||
protected void grow(int capacity) {
|
||||
if(capacity < data.length) return;
|
||||
data = Arrays.copyOf(data, data == ARRAYS.EMPTY_ARRAY ? Math.max(DEFAULT_ARRAY_SIZE, capacity) : (int)Math.max(Math.min((long)data.length + (data.length >> 1), SanityChecks.MAX_ARRAY_SIZE), capacity));
|
||||
@@ -1140,7 +1010,6 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + size);
|
||||
}
|
||||
|
||||
|
||||
#if PRIMITIVES
|
||||
/**
|
||||
* Returns a Java-Type-Specific Stream to reduce boxing/unboxing.
|
||||
|
||||
+4
-141
@@ -5,10 +5,8 @@ import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
#endif
|
||||
import java.util.Collection;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Objects;
|
||||
#if TYPE_OBJECT
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Consumer;
|
||||
#endif
|
||||
import java.util.function.Predicate;
|
||||
@@ -24,9 +22,8 @@ import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
||||
#endif
|
||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||
import speiger.src.collections.PACKAGE.functions.consumer.BI_OBJECT_CONSUMER;
|
||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||
import speiger.src.collections.objects.utils.ObjectArrays;
|
||||
import speiger.src.collections.PACKAGE.utils.ITERATORS;
|
||||
#if PRIMITIVES
|
||||
@@ -123,8 +120,6 @@ public class IMMUTABLE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_T
|
||||
@Override
|
||||
public boolean addAll(int index, LIST KEY_GENERIC_TYPE c) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean addAll(KEY_TYPE[] e, int offset, int length) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void addElements(int from, KEY_TYPE[] a, int offset, int length) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
@@ -264,11 +259,6 @@ public class IMMUTABLE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_T
|
||||
return data[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMMUTABLE_LIST KEY_GENERIC_TYPE copy() {
|
||||
return new IMMUTABLE_LISTBRACES(Arrays.copyOf(data, data.length));
|
||||
}
|
||||
|
||||
/**
|
||||
* A Type Specific foreach function that reduces (un)boxing
|
||||
*
|
||||
@@ -291,10 +281,10 @@ public class IMMUTABLE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_T
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
||||
public <E> void forEach(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE<E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
for(int i = 0,m=data.length;i<m;i++)
|
||||
action.accept(input, data[i]);
|
||||
action.accept(data[i], input);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -333,61 +323,6 @@ public class IMMUTABLE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_T
|
||||
return EMPTY_VALUE;
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = identity;
|
||||
for(int i = 0,m=data.length;i<m;i++) {
|
||||
state = operator.APPLY_VALUE(state, data[i]);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
#else
|
||||
@Override
|
||||
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_SPECIAL_TYPE state = identity;
|
||||
for(int i = 0,m=data.length;i<m;i++) {
|
||||
state = operator.APPLY_VALUE(state, data[i]);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = EMPTY_VALUE;
|
||||
boolean empty = true;
|
||||
for(int i = 0,m=data.length;i<m;i++) {
|
||||
if(empty) {
|
||||
empty = false;
|
||||
state = data[i];
|
||||
continue;
|
||||
}
|
||||
state = operator.APPLY_VALUE(state, data[i]);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
int result = 0;
|
||||
for(int i = 0,m=data.length;i<m;i++) {
|
||||
if(filter.TEST_VALUE(data[i])) result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE listIterator(int index) {
|
||||
if(index < 0 || index > size()) throw new IndexOutOfBoundsException();
|
||||
return new LIST_ITER(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE set(int index, KEY_TYPE e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
@@ -399,8 +334,7 @@ public class IMMUTABLE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_T
|
||||
#endif
|
||||
@Override
|
||||
public KEY_TYPE REMOVE(int index) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public KEY_TYPE swapRemove(int index) { throw new UnsupportedOperationException(); }
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public boolean REMOVE_KEY(KEY_TYPE type) { throw new UnsupportedOperationException(); }
|
||||
@@ -419,10 +353,6 @@ public class IMMUTABLE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_T
|
||||
public boolean removeAll(COLLECTION KEY_GENERIC_TYPE c) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean removeAll(COLLECTION KEY_GENERIC_TYPE c, CONSUMER KEY_GENERIC_TYPE r) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c, CONSUMER KEY_GENERIC_TYPE r) { throw new UnsupportedOperationException(); }
|
||||
|
||||
#if PRIMITIVES
|
||||
@Override
|
||||
@@ -454,7 +384,6 @@ public class IMMUTABLE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_T
|
||||
else if(a.length < data.length) a = (E[])ObjectArrays.newArray(a.getClass().getComponentType(), data.length);
|
||||
for(int i = 0,m=data.length;i<m;i++)
|
||||
a[i] = (E)KEY_TO_OBJ(data[i]);
|
||||
if (a.length > data.length) a[data.length] = null;
|
||||
return a;
|
||||
}
|
||||
|
||||
@@ -463,7 +392,6 @@ public class IMMUTABLE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_T
|
||||
public KEY_TYPE[] TO_ARRAY(KEY_TYPE[] a) {
|
||||
if(a.length < data.length) a = new KEY_TYPE[data.length];
|
||||
System.arraycopy(data, 0, a, 0, data.length);
|
||||
if (a.length > data.length) a[data.length] = EMPTY_KEY_VALUE;
|
||||
return a;
|
||||
}
|
||||
|
||||
@@ -504,69 +432,4 @@ public class IMMUTABLE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_T
|
||||
*/
|
||||
@Override
|
||||
public SPLIT_ITERATOR KEY_GENERIC_TYPE spliterator() { return SPLIT_ITERATORS.createArraySplititerator(data, data.length, 16464); }
|
||||
|
||||
private class LIST_ITER implements LIST_ITERATOR KEY_GENERIC_TYPE {
|
||||
int index;
|
||||
|
||||
LIST_ITER(int index) {
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return index < size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE NEXT() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
return GET_KEY(index++);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPrevious() {
|
||||
return index > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE PREVIOUS() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
return GET_KEY(--index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int nextIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int previousIndex() {
|
||||
return index-1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public void set(KEY_TYPE e) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public void add(KEY_TYPE e) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public int skip(int amount) {
|
||||
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
||||
int steps = Math.min(amount, (size() - 1) - index);
|
||||
index += steps;
|
||||
return steps;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int back(int amount) {
|
||||
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
||||
int steps = Math.min(amount, index);
|
||||
index -= steps;
|
||||
return steps;
|
||||
}
|
||||
}
|
||||
}
|
||||
+38
-234
@@ -2,14 +2,10 @@ package speiger.src.collections.PACKAGE.lists;
|
||||
|
||||
#if TYPE_OBJECT
|
||||
import java.util.Comparator;
|
||||
import java.util.function.BiFunction;
|
||||
#else if PRIMITIVES
|
||||
import java.nio.JAVA_BUFFER;
|
||||
#endif
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.Objects;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Spliterator;
|
||||
#if PRIMITIVES
|
||||
import java.util.Spliterator.JAVA_SPLIT_ITERATOR;
|
||||
@@ -21,14 +17,11 @@ import java.util.function.UnaryOperator;
|
||||
import java.util.function.JAVA_PREDICATE;
|
||||
import java.util.function.JAVA_UNARY_OPERATOR;
|
||||
#endif
|
||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||
import speiger.src.collections.PACKAGE.functions.consumer.BI_OBJECT_CONSUMER;
|
||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.collections.STACK;
|
||||
#else
|
||||
import speiger.src.collections.ints.functions.function.Int2ObjectFunction;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.queues.PRIORITY_DEQUEUE;
|
||||
@@ -248,14 +241,6 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
add(e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAll(KEY_TYPE[] e, int offset, int length) {
|
||||
if(length <= 0) return false;
|
||||
SanityChecks.checkArrayCapacity(e.length, offset, length);
|
||||
for(int i = 0;i<length;i++) linkLast(e[offset+i]);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addElements(int from, KEY_TYPE[] a, int offset, int length) {
|
||||
SanityChecks.checkArrayCapacity(a.length, offset, length);
|
||||
@@ -327,8 +312,9 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
@Override
|
||||
@Primitive
|
||||
public int indexOf(Object o) {
|
||||
if(o == null) return -1;
|
||||
Entry KEY_GENERIC_TYPE entry = first;
|
||||
for(int i = 0;entry != null;entry = entry.next,i++) {
|
||||
for(int i = 0;entry != null;entry = entry.next) {
|
||||
if(Objects.equals(KEY_TO_OBJ(entry.value), o)) return i;
|
||||
}
|
||||
return -1;
|
||||
@@ -337,8 +323,9 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
@Override
|
||||
@Primitive
|
||||
public int lastIndexOf(Object o) {
|
||||
if(o == null) return -1;
|
||||
Entry KEY_GENERIC_TYPE entry = last;
|
||||
for(int i = size-1;entry != null;entry = entry.prev,i--) {
|
||||
for(int i = size-1;entry != null;entry = entry.prev) {
|
||||
if(Objects.equals(KEY_TO_OBJ(entry.value), o)) return i;
|
||||
}
|
||||
return -1;
|
||||
@@ -353,7 +340,7 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
@Override
|
||||
public int indexOf(KEY_TYPE e) {
|
||||
Entry entry = first;
|
||||
for(int i = 0;entry != null;entry = entry.next,i++) {
|
||||
for(int i = 0;entry != null;entry = entry.next) {
|
||||
if(KEY_EQUALS(entry.value, e)) return i;
|
||||
}
|
||||
return -1;
|
||||
@@ -362,17 +349,26 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
@Override
|
||||
public int lastIndexOf(KEY_TYPE e) {
|
||||
Entry entry = last;
|
||||
for(int i = size-1;entry != null;entry = entry.prev,i--) {
|
||||
for(int i = size-1;entry != null;entry = entry.prev) {
|
||||
if(KEY_EQUALS(entry.value, e)) return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public ITERATOR KEY_GENERIC_TYPE iterator() {
|
||||
return new ListIter(first, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE listIterator() {
|
||||
return new ListIter(first, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE listIterator(int index) {
|
||||
if(index < 0 || index > size()) throw new IndexOutOfBoundsException();
|
||||
if(index == size) return new ListIter(null, index);
|
||||
if(index == size-1) return new ListIter(last, index);
|
||||
if(index == 0) return new ListIter(first, index);
|
||||
return new ListIter(getNode(index), index);
|
||||
}
|
||||
@@ -406,10 +402,10 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
||||
public <E> void forEach(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE<E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next)
|
||||
action.accept(input, entry.value);
|
||||
action.accept(entry.value, input);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -448,55 +444,6 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
return EMPTY_VALUE;
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = identity;
|
||||
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next) {
|
||||
state = operator.APPLY_VALUE(state, entry.value);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
#else
|
||||
@Override
|
||||
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_SPECIAL_TYPE state = identity;
|
||||
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next) {
|
||||
state = operator.APPLY_VALUE(state, entry.value);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = EMPTY_VALUE;
|
||||
boolean empty = true;
|
||||
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next) {
|
||||
if(empty) {
|
||||
empty = false;
|
||||
state = entry.value;
|
||||
continue;
|
||||
}
|
||||
state = operator.APPLY_VALUE(state, entry.value);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
int result = 0;
|
||||
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next) {
|
||||
if(filter.TEST_VALUE(entry.value)) result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE set(int index, KEY_TYPE e) {
|
||||
checkRange(index);
|
||||
@@ -554,7 +501,7 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
@Override
|
||||
public boolean removeFirst(KEY_TYPE e) {
|
||||
if(size == 0) return false;
|
||||
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next) {
|
||||
for(Entry KEY_GENERIC_TYPE entry = first;entry.next != null;entry = entry.next) {
|
||||
if(KEY_EQUALS(entry.value, e)) {
|
||||
unlink(entry);
|
||||
return true;
|
||||
@@ -566,7 +513,7 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
@Override
|
||||
public boolean removeLast(KEY_TYPE e) {
|
||||
if(size == 0) return false;
|
||||
for(Entry KEY_GENERIC_TYPE entry = last;entry != null;entry = entry.prev) {
|
||||
for(Entry KEY_GENERIC_TYPE entry = last;entry.prev != null;entry = entry.prev) {
|
||||
if(KEY_EQUALS(entry.value, e)) {
|
||||
unlink(entry);
|
||||
return true;
|
||||
@@ -575,71 +522,11 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE swapRemove(int index) {
|
||||
checkRange(index);
|
||||
Entry KEY_GENERIC_TYPE entry = getNode(index);
|
||||
if(entry == null) return EMPTY_KEY_VALUE;
|
||||
if(entry.next == null) return unlinkLast(entry);
|
||||
Entry KEY_GENERIC_TYPE before = entry.prev;
|
||||
KEY_TYPE result = unlink(entry);
|
||||
if(before == null) {
|
||||
Entry KEY_GENERIC_TYPE temp = last;
|
||||
last = temp.prev;
|
||||
last.next = null;
|
||||
temp.next = first;
|
||||
temp.prev = null;
|
||||
first.prev = temp;
|
||||
first = temp;
|
||||
return result;
|
||||
}
|
||||
Entry KEY_GENERIC_TYPE temp = last;
|
||||
last = temp.prev;
|
||||
last.next = null;
|
||||
temp.next = before.next;
|
||||
temp.prev = before;
|
||||
before.next = temp;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean REMOVE_SWAP(KEY_TYPE e) {
|
||||
if(size == 0) return false;
|
||||
for(Entry KEY_GENERIC_TYPE entry = last;entry != null;entry = entry.prev) {
|
||||
if(KEY_EQUALS(entry.value, e)) {
|
||||
if(entry.next == null) {
|
||||
unlinkLast(entry);
|
||||
return true;
|
||||
}
|
||||
Entry KEY_GENERIC_TYPE before = entry.prev;
|
||||
unlink(entry);
|
||||
if(before == null) {
|
||||
Entry KEY_GENERIC_TYPE temp = last;
|
||||
last = temp.prev;
|
||||
last.next = null;
|
||||
temp.next = first;
|
||||
temp.prev = null;
|
||||
first.prev = temp;
|
||||
first = temp;
|
||||
return true;
|
||||
}
|
||||
Entry KEY_GENERIC_TYPE temp = last;
|
||||
last = temp.prev;
|
||||
last.next = null;
|
||||
temp.next = before.next;
|
||||
temp.prev = before;
|
||||
before.next = temp;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
#if TYPE_OBJECT
|
||||
@Override
|
||||
public boolean remove(Object e) {
|
||||
if(size <= 0) return false;
|
||||
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next) {
|
||||
for(Entry KEY_GENERIC_TYPE entry = first;entry.next != null;entry = entry.next) {
|
||||
if(KEY_EQUALS(entry.value, e)) {
|
||||
unlink(entry);
|
||||
return true;
|
||||
@@ -658,8 +545,7 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
@Override
|
||||
public KEY_TYPE REMOVE(int index) {
|
||||
checkRange(index);
|
||||
Entry KEY_GENERIC_TYPE entry = getNode(index);
|
||||
return entry == null ? EMPTY_KEY_VALUE : unlink(entry);
|
||||
return unlink(getNode(index));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -733,14 +619,6 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
return d;
|
||||
}
|
||||
|
||||
#endif
|
||||
#if PRIMITIVES
|
||||
@Override
|
||||
public void fillBuffer(JAVA_BUFFER buffer) {
|
||||
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next)
|
||||
buffer.put(entry.value);
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
@Primitive
|
||||
@@ -808,27 +686,6 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
return modified;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeAll(COLLECTION KEY_GENERIC_TYPE c, CONSUMER KEY_GENERIC_TYPE r) {
|
||||
if(c.isEmpty()) return false;
|
||||
boolean modified = false;
|
||||
int j = 0;
|
||||
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;) {
|
||||
if(c.contains(entry.value)) {
|
||||
r.accept(entry.value);
|
||||
Entry KEY_GENERIC_TYPE next = entry.next;
|
||||
unlink(entry);
|
||||
entry = next;
|
||||
modified = true;
|
||||
continue;
|
||||
}
|
||||
else j++;
|
||||
entry = entry.next;
|
||||
}
|
||||
size = j;
|
||||
return modified;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c) {
|
||||
if(c.isEmpty()) {
|
||||
@@ -853,32 +710,6 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
return modified;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c, CONSUMER KEY_GENERIC_TYPE r) {
|
||||
if(c.isEmpty()) {
|
||||
boolean changed = size > 0;
|
||||
forEach(r);
|
||||
clear();
|
||||
return changed;
|
||||
}
|
||||
boolean modified = false;
|
||||
int j = 0;
|
||||
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;) {
|
||||
if(!c.contains(entry.value)) {
|
||||
r.accept(entry.value);
|
||||
Entry KEY_GENERIC_TYPE next = entry.next;
|
||||
unlink(entry);
|
||||
entry = next;
|
||||
modified = true;
|
||||
continue;
|
||||
}
|
||||
else j++;
|
||||
entry = entry.next;
|
||||
}
|
||||
size = j;
|
||||
return modified;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Primitive
|
||||
public boolean removeIf(Predicate<? super CLASS_TYPE> filter) {
|
||||
@@ -939,7 +770,6 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next) {
|
||||
a[i++] = (E)KEY_TO_OBJ(entry.value);
|
||||
}
|
||||
if (a.length > size) a[size] = null;
|
||||
return a;
|
||||
}
|
||||
|
||||
@@ -949,18 +779,11 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
if(a.length < size) a = new KEY_TYPE[size];
|
||||
int i = 0;
|
||||
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next) {
|
||||
a[i++] = entry.value;
|
||||
a[i++] = KEY_TO_OBJ(entry.value);
|
||||
}
|
||||
if (a.length > size) a[size] = EMPTY_KEY_VALUE;
|
||||
return a;
|
||||
}
|
||||
|
||||
#else
|
||||
@Override
|
||||
public T[] toArray(Int2ObjectFunction<T[]> action) {
|
||||
return super.toArray(action);
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public int size() {
|
||||
@@ -979,23 +802,6 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
size = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LINKED_LIST KEY_GENERIC_TYPE copy() {
|
||||
LINKED_LIST KEY_GENERIC_TYPE list = new LINKED_LISTBRACES();
|
||||
list.size = size;
|
||||
if(first != null) {
|
||||
list.first = new EntryBRACES(first.value, null, null);
|
||||
Entry KEY_GENERIC_TYPE lastReturned = list.first;
|
||||
for(Entry KEY_GENERIC_TYPE entry = first.next;entry != null;entry = entry.next) {
|
||||
Entry KEY_GENERIC_TYPE next = new EntryBRACES(entry.value, lastReturned, null);
|
||||
lastReturned.next = next;
|
||||
lastReturned = next;
|
||||
}
|
||||
list.last = lastReturned;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
protected Entry KEY_GENERIC_TYPE getNode(int index) {
|
||||
if(index < size >> 2) {
|
||||
Entry KEY_GENERIC_TYPE x = first;
|
||||
@@ -1110,23 +916,23 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
|
||||
private class ListIter implements LIST_ITERATOR KEY_GENERIC_TYPE
|
||||
{
|
||||
Entry KEY_GENERIC_TYPE next;
|
||||
Entry KEY_GENERIC_TYPE node;
|
||||
Entry KEY_GENERIC_TYPE lastReturned;
|
||||
int index;
|
||||
|
||||
ListIter(Entry KEY_GENERIC_TYPE next, int index) {
|
||||
this.next = next;
|
||||
ListIter(Entry KEY_GENERIC_TYPE node, int index) {
|
||||
this.node = node;
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return index < size;
|
||||
return node != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPrevious() {
|
||||
return index > 0;
|
||||
return node != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1142,26 +948,23 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
@Override
|
||||
public void remove() {
|
||||
if(lastReturned == null) throw new IllegalStateException();
|
||||
Entry KEY_GENERIC_TYPE lastNext = lastReturned.next;
|
||||
if(lastReturned.next == node) index--;
|
||||
unlink(lastReturned);
|
||||
if (next == lastReturned) next = lastNext;
|
||||
else index--;
|
||||
lastReturned = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE PREVIOUS() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
lastReturned = next = (next == null) ? last : next.prev;
|
||||
lastReturned = node;
|
||||
node = node.prev;
|
||||
index--;
|
||||
return lastReturned.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE NEXT() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
lastReturned = next;
|
||||
next = next.next;
|
||||
lastReturned = node;
|
||||
node = node.next;
|
||||
index++;
|
||||
return lastReturned.value;
|
||||
}
|
||||
@@ -1174,9 +977,10 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
|
||||
@Override
|
||||
public void add(KEY_TYPE e) {
|
||||
if(lastReturned == null) throw new IllegalStateException();
|
||||
if(node.next == null) linkLast(e);
|
||||
else linkBefore(e, node);
|
||||
lastReturned = null;
|
||||
if (next == null) linkLast(e);
|
||||
else linkBefore(e, next);
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
package speiger.src.collections.PACKAGE.lists;
|
||||
|
||||
#if PRIMITIVES
|
||||
import java.nio.JAVA_BUFFER;
|
||||
#endif
|
||||
import java.util.List;
|
||||
#if !TYPE_OBJECT && !TYPE_BOOLEAN
|
||||
import java.util.Objects;
|
||||
@@ -20,7 +17,6 @@ import speiger.src.collections.PACKAGE.collections.SPLIT_ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
||||
import speiger.src.collections.PACKAGE.utils.LISTS;
|
||||
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
||||
#if TYPE_BYTE || TYPE_SHORT || TYPE_CHAR || TYPE_FLOAT
|
||||
import speiger.src.collections.utils.SanityChecks;
|
||||
@@ -51,26 +47,6 @@ public interface LIST KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, List
|
||||
public void add(int index, KEY_TYPE e);
|
||||
|
||||
#endif
|
||||
/**
|
||||
* A Helper function that will only add elements if it is not present.
|
||||
* @param e the element to add
|
||||
* @return true if the list was modified
|
||||
*/
|
||||
public default boolean addIfAbsent(KEY_TYPE e) {
|
||||
if(indexOf(e) == -1) return add(e);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that will only add elements if it is present.
|
||||
* @param e the element to add
|
||||
* @return true if the list was modified
|
||||
*/
|
||||
public default boolean addIfPresent(KEY_TYPE e) {
|
||||
if(indexOf(e) != -1) return add(e);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* A Type-Specific addAll Function to reduce (un)boxing
|
||||
* @param c the elements that need to be added
|
||||
@@ -193,6 +169,7 @@ public interface LIST KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, List
|
||||
* @param offset the start index of the array should be read from
|
||||
* @param length how many elements should be read from
|
||||
* @throws IndexOutOfBoundsException if from is outside of the lists range
|
||||
* @throws IllegalStateException if offset or length are smaller then 0 or exceed the array length
|
||||
*/
|
||||
public void addElements(int from, KEY_TYPE[] a, int offset, int length);
|
||||
|
||||
@@ -227,22 +204,6 @@ public interface LIST KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, List
|
||||
*/
|
||||
public void removeElements(int from, int to);
|
||||
|
||||
/**
|
||||
* A Highly Optimized remove function that removes the desired element.
|
||||
* But instead of shifting the elements to the left it moves the last element to the removed space.
|
||||
* @param index the index of the element to be removed
|
||||
* @return the element previously at the specified position
|
||||
*/
|
||||
public KEY_TYPE swapRemove(int index);
|
||||
|
||||
/**
|
||||
* A Highly Optimized remove function that removes the desired element.
|
||||
* But instead of shifting the elements to the left it moves the last element to the removed space.
|
||||
* @param e the element that should be removed
|
||||
* @return true if the element was removed
|
||||
*/
|
||||
public boolean REMOVE_SWAP(KEY_TYPE e);
|
||||
|
||||
#if TYPE_OBJECT
|
||||
/**
|
||||
* A function to fast extract elements out of the list, this removes the elements that were fetched.
|
||||
@@ -295,14 +256,6 @@ public interface LIST KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, List
|
||||
*/
|
||||
public KEY_TYPE[] extractElements(int from, int to);
|
||||
|
||||
#if PRIMITIVES
|
||||
/**
|
||||
* Helper function that allows to fastFill a buffer reducing the duplication requirement
|
||||
* @param buffer where the data should be stored in.
|
||||
*/
|
||||
public default void fillBuffer(JAVA_BUFFER buffer) { buffer.put(TO_ARRAY()); }
|
||||
|
||||
#endif
|
||||
/** {@inheritDoc}
|
||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||
* @deprecated Please use the corresponding type-specific function instead.
|
||||
@@ -379,28 +332,6 @@ public interface LIST KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, List
|
||||
@Override
|
||||
public LIST KEY_GENERIC_TYPE subList(int from, int to);
|
||||
|
||||
/**
|
||||
* Creates a Wrapped List that is Synchronized
|
||||
* @return a new List that is synchronized
|
||||
* @see LISTS#synchronize
|
||||
*/
|
||||
public default LIST KEY_GENERIC_TYPE synchronize() { return LISTS.synchronize(this); }
|
||||
|
||||
/**
|
||||
* Creates a Wrapped List that is Synchronized
|
||||
* @param mutex is the controller of the synchronization block
|
||||
* @return a new List Wrapper that is synchronized
|
||||
* @see LISTS#synchronize
|
||||
*/
|
||||
public default LIST KEY_GENERIC_TYPE synchronize(Object mutex) { return LISTS.synchronize(this, mutex); }
|
||||
|
||||
/**
|
||||
* Creates a Wrapped List that is unmodifiable
|
||||
* @return a new List Wrapper that is unmodifiable
|
||||
* @see LISTS#unmodifiable
|
||||
*/
|
||||
public default LIST KEY_GENERIC_TYPE unmodifiable() { return LISTS.unmodifiable(this); }
|
||||
|
||||
/**
|
||||
* A function to ensure the elements are within the requested size.
|
||||
* If smaller then the stored elements they get removed as needed.
|
||||
@@ -409,8 +340,6 @@ public interface LIST KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, List
|
||||
*/
|
||||
public void size(int size);
|
||||
|
||||
@Override
|
||||
public LIST KEY_GENERIC_TYPE copy();
|
||||
#if !TYPE_OBJECT
|
||||
|
||||
/** {@inheritDoc}
|
||||
|
||||
+1
-30
@@ -18,7 +18,6 @@ import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_COLLECTION;
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ITERATOR;
|
||||
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_UNARY_OPERATOR;
|
||||
#endif
|
||||
import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_SUPPLIER;
|
||||
#if !TYPE_OBJECT && !VALUE_OBJECT
|
||||
import speiger.src.collections.objects.collections.ObjectIterator;
|
||||
#endif
|
||||
@@ -47,11 +46,6 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE extends AbstractMap<CL
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP KEY_VALUE_GENERIC_TYPE copy() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT || !VALUE_OBJECT
|
||||
@Override
|
||||
@Deprecated
|
||||
@@ -90,15 +84,6 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE extends AbstractMap<CL
|
||||
for(int i = 0;i<size;i++) put(keys[i], values[i]);
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT || !VALUE_OBJECT
|
||||
@Override
|
||||
public void putAll(CLASS_TYPE[] keys, CLASS_VALUE_TYPE[] values, int offset, int size) {
|
||||
SanityChecks.checkArrayCapacity(keys.length, offset, size);
|
||||
SanityChecks.checkArrayCapacity(values.length, offset, size);
|
||||
for(int i = 0;i<size;i++) put(keys[i], values[i]);
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public void putAllIfAbsent(MAP KEY_VALUE_GENERIC_TYPE m) {
|
||||
for(MAP.Entry KEY_VALUE_GENERIC_TYPE entry : MAPS.fastIterable(m))
|
||||
@@ -204,20 +189,6 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE extends AbstractMap<CL
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENT(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
|
||||
Objects.requireNonNull(valueProvider);
|
||||
VALUE_TYPE value;
|
||||
if((value = GET_VALUE(key)) == getDefaultReturnValue() || !containsKey(key)) {
|
||||
VALUE_TYPE newValue = valueProvider.VALUE_GET_KEY();
|
||||
if(VALUE_EQUALS_NOT(newValue, getDefaultReturnValue())) {
|
||||
put(key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
@@ -504,7 +475,7 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE extends AbstractMap<CL
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return KEY_TO_STRING(key) + "=" + VALUE_TO_STRING(value);
|
||||
return KEY_TO_STRING(key) + "->" + VALUE_TO_STRING(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
+14
-223
@@ -1,24 +1,23 @@
|
||||
package speiger.src.collections.PACKAGE.maps.impl.customHash;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.Objects;
|
||||
|
||||
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||
#endif
|
||||
#if !TYPE_OBJECT && !VALUE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.functions.consumer.BI_OBJECT_CONSUMER;
|
||||
#endif
|
||||
#if !TYPE_OBJECT || VALUE_BOOLEAN
|
||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
|
||||
import speiger.src.collections.PACKAGE.functions.function.SINGLE_UNARY_OPERATOR;
|
||||
import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.maps.interfaces.MAP;
|
||||
import speiger.src.collections.PACKAGE.maps.interfaces.SORTED_MAP;
|
||||
@@ -29,9 +28,6 @@ import speiger.src.collections.PACKAGE.utils.STRATEGY;
|
||||
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_ITERATOR;
|
||||
#if !SAME_TYPE
|
||||
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_UNARY_OPERATOR;
|
||||
#endif
|
||||
#if !VALUE_OBJECT && !SAME_TYPE
|
||||
import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_CONSUMER;
|
||||
import speiger.src.collections.VALUE_PACKAGE.lists.VALUE_LIST_ITERATOR;
|
||||
@@ -45,17 +41,10 @@ import speiger.src.collections.objects.functions.function.Object2BooleanFunction
|
||||
#endif
|
||||
#endif
|
||||
#if !SAME_TYPE
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.objects.functions.consumer.VALUE_BI_FROM_OBJECT_CONSUMER;
|
||||
|
||||
#endif
|
||||
import speiger.src.collections.VALUE_PACKAGE.functions.consumer.VALUE_BI_OBJECT_CONSUMER;
|
||||
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE;
|
||||
#endif
|
||||
#if !TYPE_OBJECT
|
||||
#if !VALUE_OBJECT
|
||||
import speiger.src.collections.objects.functions.function.ObjectObjectUnaryOperator;
|
||||
|
||||
#endif
|
||||
import speiger.src.collections.objects.collections.ObjectBidirectionalIterator;
|
||||
import speiger.src.collections.objects.lists.ObjectListIterator;
|
||||
import speiger.src.collections.objects.sets.AbstractObjectSet;
|
||||
@@ -346,23 +335,6 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
return values[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE copy() {
|
||||
LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE map = new LINKED_CUSTOM_HASH_MAPKV_BRACES(0, loadFactor, strategy);
|
||||
map.minCapacity = minCapacity;
|
||||
map.mask = mask;
|
||||
map.maxFill = maxFill;
|
||||
map.nullIndex = nullIndex;
|
||||
map.containsNull = containsNull;
|
||||
map.size = size;
|
||||
map.keys = Arrays.copyOf(keys, keys.length);
|
||||
map.values = Arrays.copyOf(values, values.length);
|
||||
map.links = Arrays.copyOf(links, links.length);
|
||||
map.firstIndex = firstIndex;
|
||||
map.lastIndex = lastIndex;
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public COMPARATOR KEY_GENERIC_TYPE comparator() {
|
||||
return null;
|
||||
@@ -680,9 +652,6 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
return new FastEntryIterator(fromElement);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MapEntrySet copy() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public void forEach(Consumer<? super MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
|
||||
int index = firstIndex;
|
||||
@@ -704,12 +673,12 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, ObjectObjectConsumer<E, MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
|
||||
public <E> void forEach(E input, ObjectObjectConsumer<MAP.Entry KEY_VALUE_GENERIC_TYPE, E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
if(size() <= 0) return;
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
action.accept(input, new BasicEntryKV_BRACES(keys[index], values[index]));
|
||||
action.accept(new BasicEntryKV_BRACES(keys[index], values[index]), input);
|
||||
index = (int)links[index];
|
||||
}
|
||||
}
|
||||
@@ -756,37 +725,6 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> E reduce(E identity, BiFunction<E, MAP.Entry KEY_VALUE_GENERIC_TYPE, E> operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
E state = identity;
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
state = operator.apply(state, new BasicEntryKV_BRACES(keys[index], values[index]));
|
||||
index = (int)links[index];
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE reduce(ObjectObjectUnaryOperator<MAP.Entry KEY_VALUE_GENERIC_TYPE, MAP.Entry KEY_VALUE_GENERIC_TYPE> operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
MAP.Entry KEY_VALUE_GENERIC_TYPE state = null;
|
||||
boolean empty = true;
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
if(empty) {
|
||||
empty = false;
|
||||
state = new BasicEntryKV_BRACES(keys[index], values[index]);
|
||||
index = (int)links[index];
|
||||
continue;
|
||||
}
|
||||
state = operator.apply(state, new BasicEntryKV_BRACES(keys[index], values[index]));
|
||||
index = (int)links[index];
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
@@ -801,38 +739,12 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return 0;
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
|
||||
int result = 0;
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
entry.set(keys[index], values[index]);
|
||||
if(filter.getBoolean(entry)) result++;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean contains(Object o) {
|
||||
if(o instanceof Map.Entry) {
|
||||
if(o instanceof MAP.Entry) {
|
||||
MAP.Entry KEY_VALUE_GENERIC_TYPE entry = (MAP.Entry KEY_VALUE_GENERIC_TYPE)o;
|
||||
int index = LINKED_CUSTOM_HASH_MAP.this.findIndex(entry.ENTRY_KEY());
|
||||
if(index >= 0) return VALUE_EQUALS(entry.ENTRY_VALUE(), LINKED_CUSTOM_HASH_MAP.this.values[index]);
|
||||
}
|
||||
else {
|
||||
Map.Entry<?, ?> entry = (Map.Entry<?, ?>)o;
|
||||
#if !TYPE_OBJECT
|
||||
if(!(entry.getKey() instanceof CLASS_TYPE)) return false;
|
||||
#endif
|
||||
int index = LINKED_CUSTOM_HASH_MAP.this.findIndex((CLASS_TYPE)entry.getKey());
|
||||
if(index >= 0) return Objects.equals(entry.getValue(), VALUE_TO_OBJ(LINKED_CUSTOM_HASH_MAP.this.values[index]));
|
||||
}
|
||||
if(o instanceof MAP.Entry) return LINKED_CUSTOM_HASH_MAP.this.containsKey(((MAP.Entry KEY_VALUE_GENERIC_TYPE)o).ENTRY_KEY());
|
||||
return LINKED_CUSTOM_HASH_MAP.this.containsKey(((Map.Entry<?, ?>)o).getKey());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -884,7 +796,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
@Override
|
||||
public boolean remove(Object o) {
|
||||
int oldSize = size;
|
||||
LINKED_CUSTOM_HASH_MAP.this.remove(o);
|
||||
remove(o);
|
||||
return size != oldSize;
|
||||
}
|
||||
|
||||
@@ -897,7 +809,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
@Override
|
||||
public boolean remove(KEY_TYPE o) {
|
||||
int oldSize = size;
|
||||
LINKED_CUSTOM_HASH_MAP.this.remove(o);
|
||||
remove(o);
|
||||
return size != oldSize;
|
||||
}
|
||||
|
||||
@@ -933,9 +845,6 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
return new KeyIterator(fromElement);
|
||||
}
|
||||
|
||||
@Override
|
||||
public KeySet copy() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return LINKED_CUSTOM_HASH_MAP.this.size();
|
||||
@@ -976,12 +885,12 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
||||
public <E> void forEach(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE<E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
if(size() <= 0) return;
|
||||
int index = firstIndex;
|
||||
while(index != -1){
|
||||
action.accept(input, keys[index]);
|
||||
action.accept(keys[index], input);
|
||||
index = (int)links[index];
|
||||
}
|
||||
}
|
||||
@@ -1022,52 +931,6 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
return true;
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public KEY_TYPE reduce(KEY_TYPE identity, SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = identity;
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
state = operator.APPLY_KEY_VALUE(state, keys[index]);
|
||||
index = (int)links[index];
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
#else
|
||||
@Override
|
||||
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_SPECIAL_TYPE state = identity;
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
state = operator.apply(state, keys[index]);
|
||||
index = (int)links[index];
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public KEY_TYPE reduce(SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = EMPTY_KEY_VALUE;
|
||||
boolean empty = true;
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
if(empty) {
|
||||
empty = false;
|
||||
state = keys[index];
|
||||
index = (int)links[index];
|
||||
continue;
|
||||
}
|
||||
state = operator.APPLY_KEY_VALUE(state, keys[index]);
|
||||
index = (int)links[index];
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
@@ -1080,19 +943,6 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
return EMPTY_KEY_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return 0;
|
||||
int result = 0;
|
||||
int index = firstIndex;
|
||||
while(index != -1){
|
||||
if(filter.TEST_VALUE(keys[index])) result++;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public COMPARATOR KEY_GENERIC_TYPE comparator() { return null; }
|
||||
|
||||
@@ -1151,12 +1001,12 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
}
|
||||
|
||||
@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_OBJECT_CONSUMER VVS_GENERIC_TYPE<E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
if(size() <= 0) return;
|
||||
int index = firstIndex;
|
||||
while(index != -1){
|
||||
action.accept(input, values[index]);
|
||||
action.accept(values[index], input);
|
||||
index = (int)links[index];
|
||||
}
|
||||
}
|
||||
@@ -1197,52 +1047,6 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
return true;
|
||||
}
|
||||
|
||||
#if !VALUE_OBJECT
|
||||
@Override
|
||||
public VALUE_TYPE reduce(VALUE_TYPE identity, VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
VALUE_TYPE state = identity;
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
state = operator.APPLY_VALUE(state, values[index]);
|
||||
index = (int)links[index];
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
#else
|
||||
@Override
|
||||
public <VALUE_SPECIAL_TYPE> VALUE_SPECIAL_TYPE reduce(VALUE_SPECIAL_TYPE identity, BiFunction<VALUE_SPECIAL_TYPE, VALUE_TYPE, VALUE_SPECIAL_TYPE> operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
VALUE_SPECIAL_TYPE state = identity;
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
state = operator.apply(state, values[index]);
|
||||
index = (int)links[index];
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public VALUE_TYPE reduce(VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
VALUE_TYPE state = EMPTY_VALUE;
|
||||
boolean empty = true;
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
if(empty) {
|
||||
empty = false;
|
||||
state = values[index];
|
||||
index = (int)links[index];
|
||||
continue;
|
||||
}
|
||||
state = operator.APPLY_VALUE(state, values[index]);
|
||||
index = (int)links[index];
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
@@ -1254,19 +1058,6 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
}
|
||||
return EMPTY_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return 0;
|
||||
int result = 0;
|
||||
int index = firstIndex;
|
||||
while(index != -1){
|
||||
if(filter.VALUE_TEST_VALUE(values[index])) result++;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
private class FastEntryIterator extends MapIterator implements ObjectListIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> {
|
||||
|
||||
+30
-284
@@ -1,23 +1,20 @@
|
||||
package speiger.src.collections.PACKAGE.maps.impl.customHash;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.ConcurrentModificationException;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
|
||||
import speiger.src.collections.PACKAGE.functions.function.FUNCTION;
|
||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||
#if !SAME_TYPE
|
||||
import speiger.src.collections.PACKAGE.functions.function.SINGLE_UNARY_OPERATOR;
|
||||
#if !TYPE_OBJECT && !VALUE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.functions.consumer.BI_OBJECT_CONSUMER;
|
||||
#endif
|
||||
#if !TYPE_OBJECT && !VALUE_BOOLEAN
|
||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||
@@ -34,20 +31,12 @@ import speiger.src.collections.PACKAGE.sets.SET;
|
||||
import speiger.src.collections.PACKAGE.utils.STRATEGY;
|
||||
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.functions.VALUE_SUPPLIER;
|
||||
#if !SAME_TYPE
|
||||
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_UNARY_OPERATOR;
|
||||
|
||||
#if !VALUE_OBJECT
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.objects.functions.function.ObjectObjectUnaryOperator;
|
||||
#endif
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ITERATOR;
|
||||
import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_CONSUMER;
|
||||
#endif
|
||||
#else if !VALUE_OBJECT
|
||||
import speiger.src.collections.objects.functions.function.ObjectObjectUnaryOperator;
|
||||
|
||||
#endif
|
||||
#if !TYPE_OBJECT && !VALUE_OBJECT || !VALUE_OBJECT
|
||||
import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer;
|
||||
@@ -58,10 +47,7 @@ import speiger.src.collections.objects.functions.function.Object2BooleanFunction
|
||||
#endif
|
||||
#endif
|
||||
#if !SAME_TYPE
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.objects.functions.consumer.VALUE_BI_FROM_OBJECT_CONSUMER;
|
||||
|
||||
#endif
|
||||
import speiger.src.collections.VALUE_PACKAGE.functions.consumer.VALUE_BI_OBJECT_CONSUMER;
|
||||
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE;
|
||||
#endif
|
||||
import speiger.src.collections.objects.collections.ObjectIterator;
|
||||
@@ -307,7 +293,8 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
#if !VALUE_OBJECT
|
||||
@Override
|
||||
public boolean containsValue(VALUE_TYPE value) {
|
||||
for(int i = nullIndex;i >= 0;i--)
|
||||
if(VALUE_EQUALS(value, values[nullIndex])) return true;
|
||||
for(int i = nullIndex-1;i >= 0;i--)
|
||||
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE) && VALUE_EQUALS(values[i], value)) return true;
|
||||
return false;
|
||||
}
|
||||
@@ -316,12 +303,9 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
@Override
|
||||
@ValuePrimitive
|
||||
public boolean containsValue(Object value) {
|
||||
for(int i = nullIndex;i >= 0;i--)
|
||||
#if VALUE_OBJECT
|
||||
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE) && EQUALS_VALUE_TYPE(values[i], value)) return true;
|
||||
#else
|
||||
if((value == null && VALUE_EQUALS(values[nullIndex], getDefaultReturnValue())) || EQUALS_VALUE_TYPE(values[nullIndex], value)) return true;
|
||||
for(int i = nullIndex-1;i >= 0;i--)
|
||||
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE) && ((value == null && values[i] == getDefaultReturnValue()) || EQUALS_VALUE_TYPE(values[i], value))) return true;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -340,6 +324,7 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public CLASS_VALUE_TYPE remove(Object key) {
|
||||
#if !TYPE_OBJECT
|
||||
if(!(key instanceof CLASS_TYPE)) return getDefaultReturnValue();
|
||||
@@ -436,20 +421,6 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE copy() {
|
||||
CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE map = new CUSTOM_HASH_MAPKV_BRACES(0, loadFactor, strategy);
|
||||
map.minCapacity = minCapacity;
|
||||
map.mask = mask;
|
||||
map.maxFill = maxFill;
|
||||
map.nullIndex = nullIndex;
|
||||
map.containsNull = containsNull;
|
||||
map.size = size;
|
||||
map.keys = Arrays.copyOf(keys, keys.length);
|
||||
map.values = Arrays.copyOf(values, values.length);
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> ENTRY_SET() {
|
||||
if(entrySet == null) entrySet = new MapEntrySet();
|
||||
@@ -496,7 +467,6 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
int index = findIndex(key);
|
||||
if(index < 0) {
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, getDefaultReturnValue());
|
||||
@@ -515,7 +485,6 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_ABSENT(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
int index = findIndex(key);
|
||||
if(index < 0) {
|
||||
VALUE_TYPE newValue = mappingFunction.GET_VALUE(key);
|
||||
@@ -523,39 +492,13 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
insert(-index-1, key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
VALUE_TYPE newValue = values[index];
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
newValue = mappingFunction.GET_VALUE(key);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
values[index] = newValue;
|
||||
}
|
||||
return newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENT(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
|
||||
Objects.requireNonNull(valueProvider);
|
||||
int index = findIndex(key);
|
||||
if(index < 0) {
|
||||
VALUE_TYPE newValue = valueProvider.VALUE_GET_KEY();
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
insert(-index-1, key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
VALUE_TYPE newValue = values[index];
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
newValue = valueProvider.VALUE_GET_KEY();
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
values[index] = newValue;
|
||||
}
|
||||
return newValue;
|
||||
return values[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
int index = findIndex(key);
|
||||
if(index < 0 || VALUE_EQUALS(values[index], getDefaultReturnValue())) return getDefaultReturnValue();
|
||||
if(index < 0) return getDefaultReturnValue();
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
removeIndex(index);
|
||||
@@ -567,12 +510,8 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE MERGE(KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
#if VALUE_OBJECT
|
||||
Objects.requireNonNull(value);
|
||||
#endif
|
||||
int index = findIndex(key);
|
||||
VALUE_TYPE newValue = index < 0 || VALUE_EQUALS(values[index], getDefaultReturnValue()) ? value : mappingFunction.APPLY_VALUE(values[index], value);
|
||||
VALUE_TYPE newValue = index < 0 ? value : mappingFunction.APPLY_VALUE(values[index], value);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
if(index >= 0)
|
||||
removeIndex(index);
|
||||
@@ -588,7 +527,7 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
for(MAP.Entry KEY_VALUE_GENERIC_TYPE entry : MAPS.fastIterable(m)) {
|
||||
KEY_TYPE key = entry.ENTRY_KEY();
|
||||
int index = findIndex(key);
|
||||
VALUE_TYPE newValue = index < 0 || VALUE_EQUALS(values[index], getDefaultReturnValue()) ? entry.ENTRY_VALUE() : mappingFunction.APPLY_VALUE(values[index], entry.ENTRY_VALUE());
|
||||
VALUE_TYPE newValue = index < 0 ? entry.ENTRY_VALUE() : mappingFunction.APPLY_VALUE(values[index], entry.ENTRY_VALUE());
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
if(index >= 0)
|
||||
removeIndex(index);
|
||||
@@ -700,10 +639,7 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
KEY_TYPE[] newKeys = NEW_KEY_ARRAY(newSize + 1);
|
||||
VALUE_TYPE[] newValues = NEW_VALUE_ARRAY(newSize + 1);
|
||||
for(int i = nullIndex, pos = 0, j = (size - (containsNull ? 1 : 0));j-- != 0;) {
|
||||
while(true) {
|
||||
if(--i < 0) throw new ConcurrentModificationException("Map was modified during rehash");
|
||||
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) break;
|
||||
}
|
||||
while(strategy.equals(keys[--i], EMPTY_KEY_VALUE));
|
||||
if(!strategy.equals(newKeys[pos = HashUtil.mix(strategy.hashCode(keys[i])) & newMask], EMPTY_KEY_VALUE))
|
||||
while(!strategy.equals(newKeys[pos = (++pos & newMask)], EMPTY_KEY_VALUE));
|
||||
newKeys[pos] = keys[i];
|
||||
@@ -805,7 +741,7 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return KEY_TO_STRING(keys[index]) + "=" + VALUE_TO_STRING(values[index]);
|
||||
return KEY_TO_STRING(keys[index]) + "->" + VALUE_TO_STRING(values[index]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -843,12 +779,12 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, ObjectObjectConsumer<E, MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
|
||||
public <E> void forEach(E input, ObjectObjectConsumer<MAP.Entry KEY_VALUE_GENERIC_TYPE, E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
if(size() <= 0) return;
|
||||
if(containsNull) action.accept(input, new BasicEntryKV_BRACES(keys[nullIndex], values[nullIndex]));
|
||||
if(containsNull) action.accept(new BasicEntryKV_BRACES(keys[nullIndex], values[nullIndex]), input);
|
||||
for(int i = nullIndex-1;i>=0;i--) {
|
||||
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) action.accept(input, new BasicEntryKV_BRACES(keys[i], values[i]));
|
||||
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) action.accept(new BasicEntryKV_BRACES(keys[i], values[i]), input);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -906,39 +842,6 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> E reduce(E identity, BiFunction<E, MAP.Entry KEY_VALUE_GENERIC_TYPE, E> operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
E state = identity;
|
||||
if(containsNull) state = operator.apply(state, new BasicEntryKV_BRACES(keys[nullIndex], values[nullIndex]));
|
||||
for(int i = nullIndex-1;i>=0;i--) {
|
||||
if(strategy.equals(keys[i], EMPTY_KEY_VALUE)) continue;
|
||||
state = operator.apply(state, new BasicEntryKV_BRACES(keys[i], values[i]));
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE reduce(ObjectObjectUnaryOperator<MAP.Entry KEY_VALUE_GENERIC_TYPE, MAP.Entry KEY_VALUE_GENERIC_TYPE> operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
MAP.Entry KEY_VALUE_GENERIC_TYPE state = null;
|
||||
boolean empty = true;
|
||||
if(containsNull) {
|
||||
state = new BasicEntryKV_BRACES(keys[nullIndex], values[nullIndex]);
|
||||
empty = false;
|
||||
}
|
||||
for(int i = 0;i<size;i++) {
|
||||
if(strategy.equals(keys[i], EMPTY_KEY_VALUE)) continue;
|
||||
if(empty) {
|
||||
empty = false;
|
||||
state = new BasicEntryKV_BRACES(keys[i], values[i]);
|
||||
continue;
|
||||
}
|
||||
state = operator.apply(state, new BasicEntryKV_BRACES(keys[i], values[i]));
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
@@ -957,25 +860,6 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return 0;
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
|
||||
int result = 0;
|
||||
if(containsNull) {
|
||||
entry.set(keys[nullIndex], values[nullIndex]);
|
||||
if(filter.getBoolean(entry)) result++;
|
||||
}
|
||||
for(int i = nullIndex-1;i>=0;i--) {
|
||||
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) {
|
||||
entry.set(keys[i], values[i]);
|
||||
if(filter.getBoolean(entry)) result++;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return CUSTOM_HASH_MAP.this.size();
|
||||
@@ -989,19 +873,8 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
@Override
|
||||
public boolean contains(Object o) {
|
||||
if(o instanceof Map.Entry) {
|
||||
if(o instanceof MAP.Entry) {
|
||||
MAP.Entry KEY_VALUE_GENERIC_TYPE entry = (MAP.Entry KEY_VALUE_GENERIC_TYPE)o;
|
||||
int index = CUSTOM_HASH_MAP.this.findIndex(entry.ENTRY_KEY());
|
||||
if(index >= 0) return VALUE_EQUALS(entry.ENTRY_VALUE(), CUSTOM_HASH_MAP.this.values[index]);
|
||||
}
|
||||
else {
|
||||
Map.Entry<?, ?> entry = (Map.Entry<?, ?>)o;
|
||||
#if !TYPE_OBJECT
|
||||
if(!(entry.getKey() instanceof CLASS_TYPE)) return false;
|
||||
#endif
|
||||
int index = CUSTOM_HASH_MAP.this.findIndex((CLASS_TYPE)entry.getKey());
|
||||
if(index >= 0) return Objects.equals(entry.getValue(), VALUE_TO_OBJ(CUSTOM_HASH_MAP.this.values[index]));
|
||||
}
|
||||
if(o instanceof MAP.Entry) return CUSTOM_HASH_MAP.this.containsKey(((MAP.Entry KEY_VALUE_GENERIC_TYPE)o).ENTRY_KEY());
|
||||
return CUSTOM_HASH_MAP.this.containsKey(((Map.Entry<?, ?>)o).getKey());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -1030,7 +903,7 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
@Override
|
||||
public boolean remove(Object o) {
|
||||
int oldSize = size;
|
||||
CUSTOM_HASH_MAP.this.remove(o);
|
||||
remove(o);
|
||||
return size != oldSize;
|
||||
}
|
||||
|
||||
@@ -1043,7 +916,7 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
@Override
|
||||
public boolean remove(KEY_TYPE o) {
|
||||
int oldSize = size;
|
||||
CUSTOM_HASH_MAP.this.remove(o);
|
||||
remove(o);
|
||||
return size != oldSize;
|
||||
}
|
||||
|
||||
@@ -1058,9 +931,6 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
return new KeyIterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public KeySet copy() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return CUSTOM_HASH_MAP.this.size();
|
||||
@@ -1073,19 +943,18 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
|
||||
@Override
|
||||
public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) {
|
||||
Objects.requireNonNull(action);
|
||||
if(containsNull) action.accept(keys[nullIndex]);
|
||||
for(int i = nullIndex-1;i>=0;i--)
|
||||
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 <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
||||
public <E> void forEach(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE<E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
if(size() <= 0) return;
|
||||
if(containsNull) action.accept(input, keys[nullIndex]);
|
||||
if(containsNull) action.accept(keys[nullIndex], input);
|
||||
for(int i = nullIndex-1;i>=0;i--) {
|
||||
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) action.accept(input, keys[i]);
|
||||
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) action.accept(keys[i], input);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1122,54 +991,6 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
return true;
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public KEY_TYPE reduce(KEY_TYPE identity, SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = identity;
|
||||
if(containsNull) state = operator.APPLY_KEY_VALUE(state, keys[nullIndex]);
|
||||
for(int i = nullIndex-1;i>=0;i--) {
|
||||
if(strategy.equals(keys[i], EMPTY_KEY_VALUE)) continue;
|
||||
state = operator.APPLY_KEY_VALUE(state, keys[i]);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
#else
|
||||
@Override
|
||||
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_SPECIAL_TYPE state = identity;
|
||||
if(containsNull) state = operator.apply(state, keys[nullIndex]);
|
||||
for(int i = nullIndex-1;i>=0;i--) {
|
||||
if(strategy.equals(keys[i], EMPTY_KEY_VALUE)) continue;
|
||||
state = operator.apply(state, keys[i]);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public KEY_TYPE reduce(SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = EMPTY_KEY_VALUE;
|
||||
boolean empty = true;
|
||||
if(containsNull) {
|
||||
state = keys[nullIndex];
|
||||
empty = false;
|
||||
}
|
||||
for(int i = 0;i<size;i++) {
|
||||
if(strategy.equals(keys[i], EMPTY_KEY_VALUE)) continue;
|
||||
if(empty) {
|
||||
empty = false;
|
||||
state = keys[i];
|
||||
continue;
|
||||
}
|
||||
state = operator.APPLY_KEY_VALUE(state, keys[i]);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
@@ -1180,18 +1001,6 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
}
|
||||
return EMPTY_KEY_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return 0;
|
||||
int result = 0;
|
||||
if(containsNull && filter.TEST_VALUE(keys[nullIndex])) result++;
|
||||
for(int i = nullIndex-1;i>=0;i--) {
|
||||
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE) && filter.TEST_VALUE(keys[i])) result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
private class Values extends VALUE_ABSTRACT_COLLECTION VALUE_GENERIC_TYPE {
|
||||
@@ -1236,12 +1045,12 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
}
|
||||
|
||||
@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_OBJECT_CONSUMER VVS_GENERIC_TYPE<E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
if(size() <= 0) return;
|
||||
if(containsNull) action.accept(input, values[nullIndex]);
|
||||
if(containsNull) action.accept(values[nullIndex], input);
|
||||
for(int i = nullIndex-1;i>=0;i--) {
|
||||
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) action.accept(input, values[i]);
|
||||
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) action.accept(values[i], input);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1278,54 +1087,6 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
return true;
|
||||
}
|
||||
|
||||
#if !VALUE_OBJECT
|
||||
@Override
|
||||
public VALUE_TYPE reduce(VALUE_TYPE identity, VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
VALUE_TYPE state = identity;
|
||||
if(containsNull) state = operator.APPLY_VALUE(state, values[nullIndex]);
|
||||
for(int i = nullIndex-1;i>=0;i--) {
|
||||
if(strategy.equals(keys[i], EMPTY_KEY_VALUE)) continue;
|
||||
state = operator.APPLY_VALUE(state, values[i]);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
#else
|
||||
@Override
|
||||
public <VALUE_SPECIAL_TYPE> VALUE_SPECIAL_TYPE reduce(VALUE_SPECIAL_TYPE identity, BiFunction<VALUE_SPECIAL_TYPE, VALUE_TYPE, VALUE_SPECIAL_TYPE> operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
VALUE_SPECIAL_TYPE state = identity;
|
||||
if(containsNull) state = operator.APPLY_VALUE(state, values[nullIndex]);
|
||||
for(int i = nullIndex-1;i>=0;i--) {
|
||||
if(strategy.equals(keys[i], EMPTY_KEY_VALUE)) continue;
|
||||
state = operator.APPLY_VALUE(state, values[i]);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public VALUE_TYPE reduce(VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
VALUE_TYPE state = EMPTY_VALUE;
|
||||
boolean empty = true;
|
||||
if(containsNull) {
|
||||
state = values[nullIndex];
|
||||
empty = false;
|
||||
}
|
||||
for(int i = 0;i<size;i++) {
|
||||
if(strategy.equals(keys[i], EMPTY_KEY_VALUE)) continue;
|
||||
if(empty) {
|
||||
empty = false;
|
||||
state = values[i];
|
||||
continue;
|
||||
}
|
||||
state = operator.APPLY_VALUE(state, values[i]);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
@@ -1336,18 +1097,6 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
}
|
||||
return EMPTY_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return 0;
|
||||
int result = 0;
|
||||
if(containsNull && filter.VALUE_TEST_VALUE(values[nullIndex])) result++;
|
||||
for(int i = nullIndex-1;i>=0;i--) {
|
||||
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE) && filter.VALUE_TEST_VALUE(values[i])) result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
private class FastEntryIterator extends MapIterator implements ObjectIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> {
|
||||
@@ -1389,7 +1138,6 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
|
||||
private class MapIterator {
|
||||
int pos = nullIndex;
|
||||
int returnedPos = -1;
|
||||
int lastReturned = -1;
|
||||
int nextIndex = Integer.MIN_VALUE;
|
||||
boolean returnNull = containsNull;
|
||||
@@ -1421,7 +1169,6 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
|
||||
public int nextEntry() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
returnedPos = pos;
|
||||
if(nextIndex < 0){
|
||||
lastReturned = Integer.MAX_VALUE;
|
||||
int value = findIndex(wrapped.GET_KEY(nextIndex));
|
||||
@@ -1441,10 +1188,9 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
keys[nullIndex] = EMPTY_KEY_VALUE;
|
||||
values[nullIndex] = EMPTY_VALUE;
|
||||
}
|
||||
else if(returnedPos >= 0) shiftKeys(returnedPos);
|
||||
else if(pos >= 0) shiftKeys(pos);
|
||||
else {
|
||||
CUSTOM_HASH_MAP.this.remove(wrapped.GET_KEY(-returnedPos - 1));
|
||||
lastReturned = -1;
|
||||
CUSTOM_HASH_MAP.this.remove(wrapped.GET_KEY(-pos - 1));
|
||||
return;
|
||||
}
|
||||
size--;
|
||||
|
||||
+17
-250
@@ -1,24 +1,23 @@
|
||||
package speiger.src.collections.PACKAGE.maps.impl.hash;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.Objects;
|
||||
|
||||
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||
#endif
|
||||
#if !TYPE_OBJECT && !VALUE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.functions.consumer.BI_OBJECT_CONSUMER;
|
||||
#endif
|
||||
#if !TYPE_OBJECT || VALUE_BOOLEAN
|
||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
|
||||
import speiger.src.collections.PACKAGE.functions.function.SINGLE_UNARY_OPERATOR;
|
||||
import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.maps.interfaces.MAP;
|
||||
import speiger.src.collections.PACKAGE.maps.interfaces.SORTED_MAP;
|
||||
@@ -28,9 +27,6 @@ import speiger.src.collections.PACKAGE.sets.SET;
|
||||
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_ITERATOR;
|
||||
#if !SAME_TYPE
|
||||
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_UNARY_OPERATOR;
|
||||
#endif
|
||||
#if !VALUE_OBJECT && !SAME_TYPE
|
||||
import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_CONSUMER;
|
||||
import speiger.src.collections.VALUE_PACKAGE.lists.VALUE_LIST_ITERATOR;
|
||||
@@ -44,17 +40,10 @@ import speiger.src.collections.objects.functions.function.Object2BooleanFunction
|
||||
#endif
|
||||
#endif
|
||||
#if !SAME_TYPE
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.objects.functions.consumer.VALUE_BI_FROM_OBJECT_CONSUMER;
|
||||
|
||||
#endif
|
||||
import speiger.src.collections.VALUE_PACKAGE.functions.consumer.VALUE_BI_OBJECT_CONSUMER;
|
||||
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE;
|
||||
#endif
|
||||
#if !TYPE_OBJECT
|
||||
#if !VALUE_OBJECT
|
||||
import speiger.src.collections.objects.functions.function.ObjectObjectUnaryOperator;
|
||||
|
||||
#endif
|
||||
import speiger.src.collections.objects.collections.ObjectBidirectionalIterator;
|
||||
import speiger.src.collections.objects.lists.ObjectListIterator;
|
||||
import speiger.src.collections.objects.sets.AbstractObjectSet;
|
||||
@@ -323,50 +312,6 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
return values[index];
|
||||
}
|
||||
|
||||
#if !VALUE_OBJECT
|
||||
@Override
|
||||
public boolean containsValue(VALUE_TYPE value) {
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
if(VALUE_EQUALS(values[index], value)) return true;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
@ValuePrimitive
|
||||
public boolean containsValue(Object value) {
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
#if VALUE_OBJECT
|
||||
if(VALUE_EQUALS(values[index], value)) return true;
|
||||
#else
|
||||
if((value == null && values[index] == getDefaultReturnValue()) || EQUALS_VALUE_TYPE(values[index], value)) return true;
|
||||
#endif
|
||||
index = (int)links[index];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE copy() {
|
||||
LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE map = new LINKED_HASH_MAPKV_BRACES(0, loadFactor);
|
||||
map.minCapacity = minCapacity;
|
||||
map.mask = mask;
|
||||
map.maxFill = maxFill;
|
||||
map.nullIndex = nullIndex;
|
||||
map.containsNull = containsNull;
|
||||
map.size = size;
|
||||
map.keys = Arrays.copyOf(keys, keys.length);
|
||||
map.values = Arrays.copyOf(values, values.length);
|
||||
map.links = Arrays.copyOf(links, links.length);
|
||||
map.firstIndex = firstIndex;
|
||||
map.lastIndex = lastIndex;
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public COMPARATOR KEY_GENERIC_TYPE comparator() {
|
||||
return null;
|
||||
@@ -684,9 +629,6 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
return new FastEntryIterator(fromElement);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MapEntrySet copy() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public void forEach(Consumer<? super MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
|
||||
int index = firstIndex;
|
||||
@@ -708,12 +650,12 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, ObjectObjectConsumer<E, MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
|
||||
public <E> void forEach(E input, ObjectObjectConsumer<MAP.Entry KEY_VALUE_GENERIC_TYPE, E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
if(size() <= 0) return;
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
action.accept(input, new BasicEntryKV_BRACES(keys[index], values[index]));
|
||||
action.accept(new BasicEntryKV_BRACES(keys[index], values[index]), input);
|
||||
index = (int)links[index];
|
||||
}
|
||||
}
|
||||
@@ -760,37 +702,6 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> E reduce(E identity, BiFunction<E, MAP.Entry KEY_VALUE_GENERIC_TYPE, E> operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
E state = identity;
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
state = operator.apply(state, new BasicEntryKV_BRACES(keys[index], values[index]));
|
||||
index = (int)links[index];
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE reduce(ObjectObjectUnaryOperator<MAP.Entry KEY_VALUE_GENERIC_TYPE, MAP.Entry KEY_VALUE_GENERIC_TYPE> operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
MAP.Entry KEY_VALUE_GENERIC_TYPE state = null;
|
||||
boolean empty = true;
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
if(empty) {
|
||||
empty = false;
|
||||
state = new BasicEntryKV_BRACES(keys[index], values[index]);
|
||||
index = (int)links[index];
|
||||
continue;
|
||||
}
|
||||
state = operator.apply(state, new BasicEntryKV_BRACES(keys[index], values[index]));
|
||||
index = (int)links[index];
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
@@ -805,35 +716,12 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return 0;
|
||||
int result = 0;
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
entry.set(keys[index], values[index]);
|
||||
if(filter.getBoolean(entry)) result++;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean contains(Object o) {
|
||||
if(o instanceof Map.Entry) {
|
||||
if(o instanceof MAP.Entry) {
|
||||
MAP.Entry KEY_VALUE_GENERIC_TYPE entry = (MAP.Entry KEY_VALUE_GENERIC_TYPE)o;
|
||||
int index = LINKED_HASH_MAP.this.findIndex(entry.ENTRY_KEY());
|
||||
if(index >= 0) return VALUE_EQUALS(entry.ENTRY_VALUE(), LINKED_HASH_MAP.this.values[index]);
|
||||
}
|
||||
else {
|
||||
Map.Entry<?, ?> entry = (Map.Entry<?, ?>)o;
|
||||
int index = LINKED_HASH_MAP.this.findIndex(entry.getKey());
|
||||
if(index >= 0) return Objects.equals(entry.getValue(), VALUE_TO_OBJ(LINKED_HASH_MAP.this.values[index]));
|
||||
}
|
||||
if(o instanceof MAP.Entry) return LINKED_HASH_MAP.this.containsKey(((MAP.Entry KEY_VALUE_GENERIC_TYPE)o).ENTRY_KEY());
|
||||
return LINKED_HASH_MAP.this.containsKey(((Map.Entry<?, ?>)o).getKey());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -885,7 +773,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
@Override
|
||||
public boolean remove(Object o) {
|
||||
int oldSize = size;
|
||||
LINKED_HASH_MAP.this.remove(o);
|
||||
remove(o);
|
||||
return size != oldSize;
|
||||
}
|
||||
|
||||
@@ -898,7 +786,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
@Override
|
||||
public boolean remove(KEY_TYPE o) {
|
||||
int oldSize = size;
|
||||
LINKED_HASH_MAP.this.remove(o);
|
||||
remove(o);
|
||||
return size != oldSize;
|
||||
}
|
||||
|
||||
@@ -934,9 +822,6 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
return new KeyIterator(fromElement);
|
||||
}
|
||||
|
||||
@Override
|
||||
public KeySet copy() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return LINKED_HASH_MAP.this.size();
|
||||
@@ -977,12 +862,12 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
||||
public <E> void forEach(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE<E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
if(size() <= 0) return;
|
||||
int index = firstIndex;
|
||||
while(index != -1){
|
||||
action.accept(input, keys[index]);
|
||||
action.accept(keys[index], input);
|
||||
index = (int)links[index];
|
||||
}
|
||||
}
|
||||
@@ -1016,59 +901,13 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return true;
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
while(index != -1){
|
||||
if(!filter.TEST_VALUE(keys[index])) return false;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public KEY_TYPE reduce(KEY_TYPE identity, SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = identity;
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
state = operator.APPLY_KEY_VALUE(state, keys[index]);
|
||||
index = (int)links[index];
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
#else
|
||||
@Override
|
||||
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_SPECIAL_TYPE state = identity;
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
state = operator.apply(state, keys[index]);
|
||||
index = (int)links[index];
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public KEY_TYPE reduce(SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = EMPTY_KEY_VALUE;
|
||||
boolean empty = true;
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
if(empty) {
|
||||
empty = false;
|
||||
state = keys[index];
|
||||
index = (int)links[index];
|
||||
continue;
|
||||
}
|
||||
state = operator.APPLY_KEY_VALUE(state, keys[index]);
|
||||
index = (int)links[index];
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
@@ -1081,19 +920,6 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
return EMPTY_KEY_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return 0;
|
||||
int result = 0;
|
||||
int index = firstIndex;
|
||||
while(index != -1){
|
||||
if(filter.TEST_VALUE(keys[index])) return result++;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public COMPARATOR KEY_GENERIC_TYPE comparator() { return null; }
|
||||
|
||||
@@ -1153,12 +979,12 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
}
|
||||
|
||||
@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_OBJECT_CONSUMER VVS_GENERIC_TYPE<E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
if(size() <= 0) return;
|
||||
int index = firstIndex;
|
||||
while(index != -1){
|
||||
action.accept(input, values[index]);
|
||||
action.accept(values[index], input);
|
||||
index = (int)links[index];
|
||||
}
|
||||
}
|
||||
@@ -1180,7 +1006,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return true;
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
while(index != -1){
|
||||
if(filter.VALUE_TEST_VALUE(values[index])) return false;
|
||||
index = (int)links[index];
|
||||
}
|
||||
@@ -1192,59 +1018,13 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return true;
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
while(index != -1){
|
||||
if(!filter.VALUE_TEST_VALUE(values[index])) return false;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
#if !VALUE_OBJECT
|
||||
@Override
|
||||
public VALUE_TYPE reduce(VALUE_TYPE identity, VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
VALUE_TYPE state = identity;
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
state = operator.APPLY_VALUE(state, values[index]);
|
||||
index = (int)links[index];
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
#else
|
||||
@Override
|
||||
public <VALUE_SPECIAL_TYPE> VALUE_SPECIAL_TYPE reduce(VALUE_SPECIAL_TYPE identity, BiFunction<VALUE_SPECIAL_TYPE, VALUE_TYPE, VALUE_SPECIAL_TYPE> operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
VALUE_SPECIAL_TYPE state = identity;
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
state = operator.apply(state, values[index]);
|
||||
index = (int)links[index];
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public VALUE_TYPE reduce(VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
VALUE_TYPE state = EMPTY_VALUE;
|
||||
boolean empty = true;
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
if(empty) {
|
||||
empty = false;
|
||||
state = values[index];
|
||||
index = (int)links[index];
|
||||
continue;
|
||||
}
|
||||
state = operator.APPLY_VALUE(state, values[index]);
|
||||
index = (int)links[index];
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
@@ -1256,19 +1036,6 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
}
|
||||
return EMPTY_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return 0;
|
||||
int result = 0;
|
||||
int index = firstIndex;
|
||||
while(index != -1){
|
||||
if(filter.VALUE_TEST_VALUE(values[index])) result++;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
private class FastEntryIterator extends MapIterator implements ObjectListIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> {
|
||||
|
||||
+29
-279
@@ -1,23 +1,20 @@
|
||||
package speiger.src.collections.PACKAGE.maps.impl.hash;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.ConcurrentModificationException;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
|
||||
import speiger.src.collections.PACKAGE.functions.function.FUNCTION;
|
||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||
#if !SAME_TYPE
|
||||
import speiger.src.collections.PACKAGE.functions.function.SINGLE_UNARY_OPERATOR;
|
||||
#if !TYPE_OBJECT && !VALUE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.functions.consumer.BI_OBJECT_CONSUMER;
|
||||
#endif
|
||||
#if !TYPE_OBJECT && !VALUE_BOOLEAN
|
||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||
@@ -33,20 +30,12 @@ import speiger.src.collections.PACKAGE.sets.SET;
|
||||
#endif
|
||||
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.functions.VALUE_SUPPLIER;
|
||||
#if !SAME_TYPE
|
||||
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_UNARY_OPERATOR;
|
||||
|
||||
#if !VALUE_OBJECT
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.objects.functions.function.ObjectObjectUnaryOperator;
|
||||
#endif
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ITERATOR;
|
||||
import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_CONSUMER;
|
||||
#endif
|
||||
#else if !VALUE_OBJECT
|
||||
import speiger.src.collections.objects.functions.function.ObjectObjectUnaryOperator;
|
||||
|
||||
#endif
|
||||
#if !TYPE_OBJECT && !VALUE_OBJECT || !VALUE_OBJECT
|
||||
import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer;
|
||||
@@ -57,10 +46,7 @@ import speiger.src.collections.objects.functions.function.Object2BooleanFunction
|
||||
#endif
|
||||
#endif
|
||||
#if !SAME_TYPE
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.objects.functions.consumer.VALUE_BI_FROM_OBJECT_CONSUMER;
|
||||
#endif
|
||||
|
||||
import speiger.src.collections.VALUE_PACKAGE.functions.consumer.VALUE_BI_OBJECT_CONSUMER;
|
||||
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE;
|
||||
#endif
|
||||
import speiger.src.collections.objects.collections.ObjectIterator;
|
||||
@@ -278,7 +264,8 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
#if !VALUE_OBJECT
|
||||
@Override
|
||||
public boolean containsValue(VALUE_TYPE value) {
|
||||
for(int i = nullIndex;i >= 0;i--)
|
||||
if(VALUE_EQUALS(value, values[nullIndex])) return true;
|
||||
for(int i = nullIndex-1;i >= 0;i--)
|
||||
if(KEY_EQUALS_NOT_NULL(keys[i]) && VALUE_EQUALS(values[i], value)) return true;
|
||||
return false;
|
||||
}
|
||||
@@ -287,12 +274,9 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
@Override
|
||||
@ValuePrimitive
|
||||
public boolean containsValue(Object value) {
|
||||
for(int i = nullIndex;i >= 0;i--)
|
||||
#if VALUE_OBJECT
|
||||
if(KEY_EQUALS_NOT_NULL(keys[i]) && EQUALS_VALUE_TYPE(values[i], value)) return true;
|
||||
#else
|
||||
if((value == null && VALUE_EQUALS(values[nullIndex], getDefaultReturnValue())) || EQUALS_VALUE_TYPE(values[nullIndex], value)) return true;
|
||||
for(int i = nullIndex-1;i >= 0;i--)
|
||||
if(KEY_EQUALS_NOT_NULL(keys[i]) && ((value == null && values[i] == getDefaultReturnValue()) || EQUALS_VALUE_TYPE(values[i], value))) return true;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -311,6 +295,7 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public CLASS_VALUE_TYPE remove(Object key) {
|
||||
int slot = findIndex(key);
|
||||
if(slot < 0) return VALUE_TO_OBJ(getDefaultReturnValue());
|
||||
@@ -397,20 +382,6 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public HASH_MAP KEY_VALUE_GENERIC_TYPE copy() {
|
||||
HASH_MAP KEY_VALUE_GENERIC_TYPE map = new HASH_MAPKV_BRACES(0, loadFactor);
|
||||
map.minCapacity = minCapacity;
|
||||
map.mask = mask;
|
||||
map.maxFill = maxFill;
|
||||
map.nullIndex = nullIndex;
|
||||
map.containsNull = containsNull;
|
||||
map.size = size;
|
||||
map.keys = Arrays.copyOf(keys, keys.length);
|
||||
map.values = Arrays.copyOf(values, values.length);
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> ENTRY_SET() {
|
||||
if(entrySet == null) entrySet = new MapEntrySet();
|
||||
@@ -457,7 +428,6 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
int index = findIndex(key);
|
||||
if(index < 0) {
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, getDefaultReturnValue());
|
||||
@@ -476,7 +446,6 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_ABSENT(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
int index = findIndex(key);
|
||||
if(index < 0) {
|
||||
VALUE_TYPE newValue = mappingFunction.GET_VALUE(key);
|
||||
@@ -484,39 +453,13 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
insert(-index-1, key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
VALUE_TYPE newValue = values[index];
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
newValue = mappingFunction.GET_VALUE(key);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
values[index] = newValue;
|
||||
}
|
||||
return newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENT(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
|
||||
Objects.requireNonNull(valueProvider);
|
||||
int index = findIndex(key);
|
||||
if(index < 0) {
|
||||
VALUE_TYPE newValue = valueProvider.VALUE_GET_KEY();
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
insert(-index-1, key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
VALUE_TYPE newValue = values[index];
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
newValue = valueProvider.VALUE_GET_KEY();
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
values[index] = newValue;
|
||||
}
|
||||
return newValue;
|
||||
return values[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
int index = findIndex(key);
|
||||
if(index < 0 || VALUE_EQUALS(values[index], getDefaultReturnValue())) return getDefaultReturnValue();
|
||||
if(index < 0) return getDefaultReturnValue();
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
removeIndex(index);
|
||||
@@ -528,12 +471,8 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE MERGE(KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
#if VALUE_OBJECT
|
||||
Objects.requireNonNull(value);
|
||||
#endif
|
||||
int index = findIndex(key);
|
||||
VALUE_TYPE newValue = index < 0 || VALUE_EQUALS(values[index], getDefaultReturnValue()) ? value : mappingFunction.APPLY_VALUE(values[index], value);
|
||||
VALUE_TYPE newValue = index < 0 ? value : mappingFunction.APPLY_VALUE(values[index], value);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
if(index >= 0)
|
||||
removeIndex(index);
|
||||
@@ -549,7 +488,7 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
for(MAP.Entry KEY_VALUE_GENERIC_TYPE entry : MAPS.fastIterable(m)) {
|
||||
KEY_TYPE key = entry.ENTRY_KEY();
|
||||
int index = findIndex(key);
|
||||
VALUE_TYPE newValue = index < 0 || VALUE_EQUALS(values[index], getDefaultReturnValue()) ? entry.ENTRY_VALUE() : mappingFunction.APPLY_VALUE(values[index], entry.ENTRY_VALUE());
|
||||
VALUE_TYPE newValue = index < 0 ? entry.ENTRY_VALUE() : mappingFunction.APPLY_VALUE(values[index], entry.ENTRY_VALUE());
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
if(index >= 0)
|
||||
removeIndex(index);
|
||||
@@ -660,10 +599,7 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
KEY_TYPE[] newKeys = NEW_KEY_ARRAY(newSize + 1);
|
||||
VALUE_TYPE[] newValues = NEW_VALUE_ARRAY(newSize + 1);
|
||||
for(int i = nullIndex, pos = 0, j = (size - (containsNull ? 1 : 0));j-- != 0;) {
|
||||
while(true) {
|
||||
if(--i < 0) throw new ConcurrentModificationException("Map was modified during rehash");
|
||||
if(KEY_EQUALS_NOT_NULL(keys[i])) break;
|
||||
}
|
||||
while(KEY_EQUALS_NULL(keys[--i]));
|
||||
if(KEY_EQUALS_NOT_NULL(newKeys[pos = HashUtil.mix(KEY_TO_HASH(keys[i])) & newMask]))
|
||||
while(KEY_EQUALS_NOT_NULL(newKeys[pos = (++pos & newMask)]));
|
||||
newKeys[pos] = keys[i];
|
||||
@@ -765,7 +701,7 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return KEY_TO_STRING(keys[index]) + "=" + VALUE_TO_STRING(values[index]);
|
||||
return KEY_TO_STRING(keys[index]) + "->" + VALUE_TO_STRING(values[index]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -803,12 +739,12 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, ObjectObjectConsumer<E, MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
|
||||
public <E> void forEach(E input, ObjectObjectConsumer<MAP.Entry KEY_VALUE_GENERIC_TYPE, E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
if(size() <= 0) return;
|
||||
if(containsNull) action.accept(input, new BasicEntryKV_BRACES(keys[nullIndex], values[nullIndex]));
|
||||
if(containsNull) action.accept(new BasicEntryKV_BRACES(keys[nullIndex], values[nullIndex]), input);
|
||||
for(int i = nullIndex-1;i>=0;i--) {
|
||||
if(KEY_EQUALS_NOT_NULL(keys[i])) action.accept(input, new BasicEntryKV_BRACES(keys[i], values[i]));
|
||||
if(KEY_EQUALS_NOT_NULL(keys[i])) action.accept(new BasicEntryKV_BRACES(keys[i], values[i]), input);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -866,39 +802,6 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> E reduce(E identity, BiFunction<E, MAP.Entry KEY_VALUE_GENERIC_TYPE, E> operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
E state = identity;
|
||||
if(containsNull) state = operator.apply(state, new BasicEntryKV_BRACES(keys[nullIndex], values[nullIndex]));
|
||||
for(int i = nullIndex-1;i>=0;i--) {
|
||||
if(KEY_EQUALS_NULL(keys[i])) continue;
|
||||
state = operator.apply(state, new BasicEntryKV_BRACES(keys[i], values[i]));
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE reduce(ObjectObjectUnaryOperator<MAP.Entry KEY_VALUE_GENERIC_TYPE, MAP.Entry KEY_VALUE_GENERIC_TYPE> operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
MAP.Entry KEY_VALUE_GENERIC_TYPE state = null;
|
||||
boolean empty = true;
|
||||
if(containsNull) {
|
||||
state = new BasicEntryKV_BRACES(keys[nullIndex], values[nullIndex]);
|
||||
empty = false;
|
||||
}
|
||||
for(int i = 0;i<size;i++) {
|
||||
if(KEY_EQUALS_NULL(keys[i])) continue;
|
||||
if(empty) {
|
||||
empty = false;
|
||||
state = new BasicEntryKV_BRACES(keys[i], values[i]);
|
||||
continue;
|
||||
}
|
||||
state = operator.apply(state, new BasicEntryKV_BRACES(keys[i], values[i]));
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
@@ -917,25 +820,6 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return 0;
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
|
||||
int result = 0;
|
||||
if(containsNull) {
|
||||
entry.set(keys[nullIndex], values[nullIndex]);
|
||||
if(filter.getBoolean(entry)) result++;
|
||||
}
|
||||
for(int i = nullIndex-1;i>=0;i--) {
|
||||
if(KEY_EQUALS_NOT_NULL(keys[i])) {
|
||||
entry.set(keys[i], values[i]);
|
||||
if(filter.getBoolean(entry)) result++;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return HASH_MAP.this.size();
|
||||
@@ -949,16 +833,8 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
@Override
|
||||
public boolean contains(Object o) {
|
||||
if(o instanceof Map.Entry) {
|
||||
if(o instanceof MAP.Entry) {
|
||||
MAP.Entry KEY_VALUE_GENERIC_TYPE entry = (MAP.Entry KEY_VALUE_GENERIC_TYPE)o;
|
||||
int index = HASH_MAP.this.findIndex(entry.ENTRY_KEY());
|
||||
if(index >= 0) return VALUE_EQUALS(entry.ENTRY_VALUE(), HASH_MAP.this.values[index]);
|
||||
}
|
||||
else {
|
||||
Map.Entry<?, ?> entry = (Map.Entry<?, ?>)o;
|
||||
int index = HASH_MAP.this.findIndex(entry.getKey());
|
||||
if(index >= 0) return Objects.equals(entry.getValue(), VALUE_TO_OBJ(HASH_MAP.this.values[index]));
|
||||
}
|
||||
if(o instanceof MAP.Entry) return HASH_MAP.this.containsKey(((MAP.Entry KEY_VALUE_GENERIC_TYPE)o).ENTRY_KEY());
|
||||
return HASH_MAP.this.containsKey(((Map.Entry<?, ?>)o).getKey());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -987,7 +863,7 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
@Override
|
||||
public boolean remove(Object o) {
|
||||
int oldSize = size;
|
||||
HASH_MAP.this.remove(o);
|
||||
remove(o);
|
||||
return size != oldSize;
|
||||
}
|
||||
|
||||
@@ -1000,7 +876,7 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
@Override
|
||||
public boolean remove(KEY_TYPE o) {
|
||||
int oldSize = size;
|
||||
HASH_MAP.this.remove(o);
|
||||
remove(o);
|
||||
return size != oldSize;
|
||||
}
|
||||
|
||||
@@ -1025,9 +901,6 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
HASH_MAP.this.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public KeySet copy() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) {
|
||||
if(containsNull) action.accept(keys[nullIndex]);
|
||||
@@ -1036,12 +909,12 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
||||
public <E> void forEach(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE<E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
if(size() <= 0) return;
|
||||
if(containsNull) action.accept(input, keys[nullIndex]);
|
||||
if(containsNull) action.accept(keys[nullIndex], input);
|
||||
for(int i = nullIndex-1;i>=0;i--) {
|
||||
if(KEY_EQUALS_NOT_NULL(keys[i])) action.accept(input, keys[i]);
|
||||
if(KEY_EQUALS_NOT_NULL(keys[i])) action.accept(keys[i], input);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1078,54 +951,6 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
return true;
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public KEY_TYPE reduce(KEY_TYPE identity, SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = identity;
|
||||
if(containsNull) state = operator.APPLY_KEY_VALUE(state, keys[nullIndex]);
|
||||
for(int i = nullIndex-1;i>=0;i--) {
|
||||
if(KEY_EQUALS_NULL(keys[i])) continue;
|
||||
state = operator.APPLY_KEY_VALUE(state, keys[i]);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
#else
|
||||
@Override
|
||||
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_SPECIAL_TYPE state = identity;
|
||||
if(containsNull) state = operator.apply(state, keys[nullIndex]);
|
||||
for(int i = nullIndex-1;i>=0;i--) {
|
||||
if(KEY_EQUALS_NULL(keys[i])) continue;
|
||||
state = operator.apply(state, keys[i]);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public KEY_TYPE reduce(SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = EMPTY_KEY_VALUE;
|
||||
boolean empty = true;
|
||||
if(containsNull) {
|
||||
state = keys[nullIndex];
|
||||
empty = false;
|
||||
}
|
||||
for(int i = 0;i<size;i++) {
|
||||
if(KEY_EQUALS_NULL(keys[i])) continue;
|
||||
if(empty) {
|
||||
empty = false;
|
||||
state = keys[i];
|
||||
continue;
|
||||
}
|
||||
state = operator.APPLY_KEY_VALUE(state, keys[i]);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
@@ -1136,18 +961,6 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
}
|
||||
return EMPTY_KEY_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return 0;
|
||||
int result = 0;
|
||||
if(containsNull && filter.TEST_VALUE(keys[nullIndex])) result++;
|
||||
for(int i = nullIndex-1;i>=0;i--) {
|
||||
if(KEY_EQUALS_NOT_NULL(keys[i]) && filter.TEST_VALUE(keys[i])) result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
private class Values extends VALUE_ABSTRACT_COLLECTION VALUE_GENERIC_TYPE {
|
||||
@@ -1192,12 +1005,12 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
}
|
||||
|
||||
@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_OBJECT_CONSUMER VVS_GENERIC_TYPE<E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
if(size() <= 0) return;
|
||||
if(containsNull) action.accept(input, values[nullIndex]);
|
||||
if(containsNull) action.accept(values[nullIndex], input);
|
||||
for(int i = nullIndex-1;i>=0;i--) {
|
||||
if(KEY_EQUALS_NOT_NULL(keys[i])) action.accept(input, values[i]);
|
||||
if(KEY_EQUALS_NOT_NULL(keys[i])) action.accept(values[i], input);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1234,54 +1047,6 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
return true;
|
||||
}
|
||||
|
||||
#if !VALUE_OBJECT
|
||||
@Override
|
||||
public VALUE_TYPE reduce(VALUE_TYPE identity, VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
VALUE_TYPE state = identity;
|
||||
if(containsNull) state = operator.APPLY_VALUE(state, values[nullIndex]);
|
||||
for(int i = nullIndex-1;i>=0;i--) {
|
||||
if(KEY_EQUALS_NULL(keys[i])) continue;
|
||||
state = operator.APPLY_VALUE(state, values[i]);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
#else
|
||||
@Override
|
||||
public <VALUE_SPECIAL_TYPE> VALUE_SPECIAL_TYPE reduce(VALUE_SPECIAL_TYPE identity, BiFunction<VALUE_SPECIAL_TYPE, VALUE_TYPE, VALUE_SPECIAL_TYPE> operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
VALUE_SPECIAL_TYPE state = identity;
|
||||
if(containsNull) state = operator.APPLY_VALUE(state, values[nullIndex]);
|
||||
for(int i = nullIndex-1;i>=0;i--) {
|
||||
if(KEY_EQUALS_NULL(keys[i])) continue;
|
||||
state = operator.APPLY_VALUE(state, values[i]);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public VALUE_TYPE reduce(VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
VALUE_TYPE state = EMPTY_VALUE;
|
||||
boolean empty = true;
|
||||
if(containsNull) {
|
||||
state = values[nullIndex];
|
||||
empty = false;
|
||||
}
|
||||
for(int i = 0;i<size;i++) {
|
||||
if(KEY_EQUALS_NULL(keys[i])) continue;
|
||||
if(empty) {
|
||||
empty = false;
|
||||
state = values[i];
|
||||
continue;
|
||||
}
|
||||
state = operator.APPLY_VALUE(state, values[i]);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
@@ -1292,18 +1057,6 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
}
|
||||
return EMPTY_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return 0;
|
||||
int result = 0;
|
||||
if(containsNull && filter.VALUE_TEST_VALUE(values[nullIndex])) result++;
|
||||
for(int i = nullIndex-1;i>=0;i--) {
|
||||
if(KEY_EQUALS_NOT_NULL(keys[i]) && filter.VALUE_TEST_VALUE(values[i])) result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
private class FastEntryIterator extends MapIterator implements ObjectIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> {
|
||||
@@ -1345,7 +1098,6 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
|
||||
private class MapIterator {
|
||||
int pos = nullIndex;
|
||||
int returnedPos = -1;
|
||||
int lastReturned = -1;
|
||||
int nextIndex = Integer.MIN_VALUE;
|
||||
boolean returnNull = containsNull;
|
||||
@@ -1377,7 +1129,6 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
|
||||
public int nextEntry() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
returnedPos = pos;
|
||||
if(nextIndex < 0){
|
||||
lastReturned = Integer.MAX_VALUE;
|
||||
int value = findIndex(wrapped.GET_KEY(nextIndex));
|
||||
@@ -1397,10 +1148,9 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
keys[nullIndex] = EMPTY_KEY_VALUE;
|
||||
values[nullIndex] = EMPTY_VALUE;
|
||||
}
|
||||
else if(returnedPos >= 0) shiftKeys(returnedPos);
|
||||
else if(pos >= 0) shiftKeys(pos);
|
||||
else {
|
||||
HASH_MAP.this.remove(wrapped.GET_KEY(-returnedPos - 1));
|
||||
lastReturned = -1;
|
||||
HASH_MAP.this.remove(wrapped.GET_KEY(-pos - 1));
|
||||
return;
|
||||
}
|
||||
size--;
|
||||
|
||||
+25
-267
@@ -1,18 +1,18 @@
|
||||
package speiger.src.collections.PACKAGE.maps.impl.immutable;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.Map;
|
||||
import java.util.Comparator;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||
#endif
|
||||
#if !TYPE_OBJECT && !VALUE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.functions.consumer.BI_OBJECT_CONSUMER;
|
||||
#endif
|
||||
#if !TYPE_OBJECT && !VALUE_BOOLEAN
|
||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||
@@ -20,9 +20,6 @@ import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||
import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
|
||||
import speiger.src.collections.PACKAGE.functions.function.FUNCTION;
|
||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||
#if !SAME_TYPE
|
||||
import speiger.src.collections.PACKAGE.functions.function.SINGLE_UNARY_OPERATOR;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.maps.interfaces.SORTED_MAP;
|
||||
import speiger.src.collections.PACKAGE.maps.abstracts.ABSTRACT_MAP;
|
||||
@@ -41,10 +38,7 @@ import speiger.src.collections.objects.functions.function.Object2BooleanFunction
|
||||
#endif
|
||||
#endif
|
||||
#if !SAME_TYPE
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.objects.functions.consumer.VALUE_BI_FROM_OBJECT_CONSUMER;
|
||||
|
||||
#endif
|
||||
import speiger.src.collections.VALUE_PACKAGE.functions.consumer.VALUE_BI_OBJECT_CONSUMER;
|
||||
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE;
|
||||
#endif
|
||||
#if !TYPE_OBJECT
|
||||
@@ -54,7 +48,6 @@ import speiger.src.collections.PACKAGE.sets.SET;
|
||||
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_ITERATOR;
|
||||
import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_SUPPLIER;
|
||||
#if !SAME_TYPE
|
||||
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_UNARY_OPERATOR;
|
||||
#if !VALUE_OBJECT
|
||||
@@ -65,10 +58,6 @@ import speiger.src.collections.VALUE_PACKAGE.utils.VALUE_ARRAYS;
|
||||
#endif
|
||||
import speiger.src.collections.objects.collections.ObjectBidirectionalIterator;
|
||||
#if !TYPE_OBJECT
|
||||
#if !VALUE_OBJECT
|
||||
import speiger.src.collections.objects.functions.function.ObjectObjectUnaryOperator;
|
||||
|
||||
#endif
|
||||
import speiger.src.collections.objects.lists.ObjectListIterator;
|
||||
import speiger.src.collections.objects.sets.ObjectSortedSet;
|
||||
#endif
|
||||
@@ -112,10 +101,6 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
/** Amount of Elements stored in the HashMap */
|
||||
protected int size;
|
||||
|
||||
/**
|
||||
* Helper constructor for copying the Map
|
||||
*/
|
||||
protected IMMUTABLE_HASH_MAP() {}
|
||||
|
||||
#if !TYPE_OBJECT || !VALUE_OBJECT
|
||||
/**
|
||||
@@ -237,34 +222,18 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
{
|
||||
KEY_TYPE o = a[i];
|
||||
if(KEY_EQUALS_NULL(o)) {
|
||||
if(!containsNull) {
|
||||
size++;
|
||||
if(prev != -1) {
|
||||
newLinks[prev] ^= ((newLinks[prev] ^ (newSize & 0xFFFFFFFFL)) & 0xFFFFFFFFL);
|
||||
newLinks[newSize] ^= ((newLinks[newSize] ^ ((prev & 0xFFFFFFFFL) << 32)) & 0xFFFFFFFF00000000L);
|
||||
prev = newSize;
|
||||
}
|
||||
else {
|
||||
prev = firstIndex = newSize;
|
||||
newLinks[newSize] = -1L;
|
||||
}
|
||||
}
|
||||
if(!containsNull) size++;
|
||||
containsNull = true;
|
||||
newValues[newSize] = b[i];
|
||||
continue;
|
||||
}
|
||||
boolean found = true;
|
||||
int pos = HashUtil.mix(KEY_TO_HASH(o)) & newMask;
|
||||
KEY_TYPE current = newKeys[pos];
|
||||
if(KEY_EQUALS_NOT_NULL(current)) {
|
||||
if(KEY_EQUALS(current, o)) {
|
||||
newValues[pos] = b[i];
|
||||
continue;
|
||||
}
|
||||
while(KEY_EQUALS_NOT_NULL((current = newKeys[pos = (++pos & newMask)]))) {
|
||||
if(KEY_EQUALS(current, o)) continue;
|
||||
while(KEY_EQUALS_NOT_NULL((current = newKeys[pos = (++pos & mask)]))) {
|
||||
if(KEY_EQUALS(current, o)) {
|
||||
found = false;
|
||||
newValues[pos] = b[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -272,7 +241,7 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
if(found) {
|
||||
size++;
|
||||
newKeys[pos] = o;
|
||||
newValues[pos] = b[i];
|
||||
values[pos] = b[i];
|
||||
if(prev != -1) {
|
||||
newLinks[prev] ^= ((newLinks[prev] ^ (pos & 0xFFFFFFFFL)) & 0xFFFFFFFFL);
|
||||
newLinks[pos] ^= ((newLinks[pos] ^ ((prev & 0xFFFFFFFFL) << 32)) & 0xFFFFFFFF00000000L);
|
||||
@@ -284,7 +253,7 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
}
|
||||
}
|
||||
}
|
||||
nullIndex = newSize;
|
||||
nullIndex = size;
|
||||
mask = newMask;
|
||||
keys = newKeys;
|
||||
values = newValues;
|
||||
@@ -332,11 +301,9 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
#if !VALUE_OBJECT
|
||||
@Override
|
||||
public boolean containsValue(VALUE_TYPE value) {
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
if(VALUE_EQUALS(values[index], value)) return true;
|
||||
index = (int)links[index];
|
||||
}
|
||||
if(VALUE_EQUALS(value, values[nullIndex])) return true;
|
||||
for(int i = nullIndex-1;i >= 0;i--)
|
||||
if(KEY_EQUALS_NOT_NULL(keys[i]) && VALUE_EQUALS(values[i], value)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -344,15 +311,9 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
@Override
|
||||
@ValuePrimitive
|
||||
public boolean containsValue(Object value) {
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
#if VALUE_OBJECT
|
||||
if(VALUE_EQUALS(values[index], value)) return true;
|
||||
#else
|
||||
if((value == null && values[index] == getDefaultReturnValue()) || EQUALS_VALUE_TYPE(values[index], value)) return true;
|
||||
#endif
|
||||
index = (int)links[index];
|
||||
}
|
||||
if((value == null && VALUE_EQUALS(values[nullIndex], getDefaultReturnValue())) || EQUALS_VALUE_TYPE(values[nullIndex], value)) return true;
|
||||
for(int i = nullIndex-1;i >= 0;i--)
|
||||
if(KEY_EQUALS_NOT_NULL(keys[i]) && ((value == null && values[i] == getDefaultReturnValue()) || EQUALS_VALUE_TYPE(values[i], value))) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -449,21 +410,6 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
return valuesC;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE copy() {
|
||||
IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE map = new IMMUTABLE_HASH_MAPKV_BRACES();
|
||||
map.mask = mask;
|
||||
map.nullIndex = nullIndex;
|
||||
map.containsNull = containsNull;
|
||||
map.size = size;
|
||||
map.keys = Arrays.copyOf(keys, keys.length);
|
||||
map.values = Arrays.copyOf(values, values.length);
|
||||
map.links = Arrays.copyOf(links, links.length);
|
||||
map.firstIndex = firstIndex;
|
||||
map.lastIndex = lastIndex;
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public COMPARATOR KEY_GENERIC_TYPE comparator() { return null; }
|
||||
@Override
|
||||
@@ -494,9 +440,6 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_ABSENT(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENT(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@@ -568,9 +511,6 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
}
|
||||
Map.Entry<?, ?> entry = (Map.Entry<?, ?>)obj;
|
||||
Object key = entry.getKey();
|
||||
#if !TYPE_OBJECT
|
||||
if(!(key instanceof CLASS_TYPE)) return false;
|
||||
#endif
|
||||
Object value = entry.getValue();
|
||||
#if TYPE_OBJECT && VALUE_OBJECT
|
||||
return KEY_EQUALS(keys[index], key) && VALUE_EQUALS(values[index], value);
|
||||
@@ -592,7 +532,7 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return KEY_TO_STRING(keys[index]) + "=" + VALUE_TO_STRING(values[index]);
|
||||
return KEY_TO_STRING(keys[index]) + "->" + VALUE_TO_STRING(values[index]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -644,9 +584,6 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
return new FastEntryIterator(fromElement);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MapEntrySet copy() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public void forEach(Consumer<? super MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
|
||||
int index = firstIndex;
|
||||
@@ -668,12 +605,12 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, ObjectObjectConsumer<E, MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
|
||||
public <E> void forEach(E input, ObjectObjectConsumer<MAP.Entry KEY_VALUE_GENERIC_TYPE, E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
if(size() <= 0) return;
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
action.accept(input, new BasicEntryKV_BRACES(keys[index], values[index]));
|
||||
action.accept(new BasicEntryKV_BRACES(keys[index], values[index]), input);
|
||||
index = (int)links[index];
|
||||
}
|
||||
}
|
||||
@@ -687,7 +624,6 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
while(index != -1) {
|
||||
entry.set(keys[index], values[index]);
|
||||
if(filter.getBoolean(entry)) return true;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -701,7 +637,6 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
while(index != -1) {
|
||||
entry.set(keys[index], values[index]);
|
||||
if(filter.getBoolean(entry)) return false;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -715,42 +650,10 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
while(index != -1) {
|
||||
entry.set(keys[index], values[index]);
|
||||
if(!filter.getBoolean(entry)) return false;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> E reduce(E identity, BiFunction<E, MAP.Entry KEY_VALUE_GENERIC_TYPE, E> operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
E state = identity;
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
state = operator.apply(state, new BasicEntryKV_BRACES(keys[index], values[index]));
|
||||
index = (int)links[index];
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE reduce(ObjectObjectUnaryOperator<MAP.Entry KEY_VALUE_GENERIC_TYPE, MAP.Entry KEY_VALUE_GENERIC_TYPE> operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
MAP.Entry KEY_VALUE_GENERIC_TYPE state = null;
|
||||
boolean empty = true;
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
if(empty) {
|
||||
empty = false;
|
||||
state = new BasicEntryKV_BRACES(keys[index], values[index]);
|
||||
index = (int)links[index];
|
||||
continue;
|
||||
}
|
||||
state = operator.apply(state, new BasicEntryKV_BRACES(keys[index], values[index]));
|
||||
index = (int)links[index];
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
@@ -760,40 +663,16 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
while(index != -1) {
|
||||
entry.set(keys[index], values[index]);
|
||||
if(filter.getBoolean(entry)) return entry;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return 0;
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
|
||||
int result = 0;
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
entry.set(keys[index], values[index]);
|
||||
if(filter.getBoolean(entry)) result++;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean contains(Object o) {
|
||||
if(o instanceof Map.Entry) {
|
||||
if(o instanceof MAP.Entry) {
|
||||
MAP.Entry KEY_VALUE_GENERIC_TYPE entry = (MAP.Entry KEY_VALUE_GENERIC_TYPE)o;
|
||||
int index = IMMUTABLE_HASH_MAP.this.findIndex(entry.ENTRY_KEY());
|
||||
if(index >= 0) return VALUE_EQUALS(entry.ENTRY_VALUE(), IMMUTABLE_HASH_MAP.this.values[index]);
|
||||
}
|
||||
else {
|
||||
Map.Entry<?, ?> entry = (Map.Entry<?, ?>)o;
|
||||
int index = IMMUTABLE_HASH_MAP.this.findIndex(entry.getKey());
|
||||
if(index >= 0) return Objects.equals(entry.getValue(), VALUE_TO_OBJ(IMMUTABLE_HASH_MAP.this.values[index]));
|
||||
}
|
||||
if(o instanceof MAP.Entry) return IMMUTABLE_HASH_MAP.this.containsKey(((MAP.Entry KEY_VALUE_GENERIC_TYPE)o).ENTRY_KEY());
|
||||
return IMMUTABLE_HASH_MAP.this.containsKey(((Map.Entry<?, ?>)o).getKey());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -870,9 +749,6 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
return new KeyIterator(fromElement);
|
||||
}
|
||||
|
||||
@Override
|
||||
public KeySet copy() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return IMMUTABLE_HASH_MAP.this.size();
|
||||
@@ -907,12 +783,12 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
||||
public <E> void forEach(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE<E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
if(size() <= 0) return;
|
||||
int index = firstIndex;
|
||||
while(index != -1){
|
||||
action.accept(input, keys[index]);
|
||||
action.accept(keys[index], input);
|
||||
index = (int)links[index];
|
||||
}
|
||||
}
|
||||
@@ -953,52 +829,6 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
return true;
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public KEY_TYPE reduce(KEY_TYPE identity, SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = identity;
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
state = operator.APPLY_KEY_VALUE(state, keys[index]);
|
||||
index = (int)links[index];
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
#else
|
||||
@Override
|
||||
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_SPECIAL_TYPE state = identity;
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
state = operator.apply(state, keys[index]);
|
||||
index = (int)links[index];
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public KEY_TYPE reduce(SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = EMPTY_KEY_VALUE;
|
||||
boolean empty = true;
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
if(empty) {
|
||||
empty = false;
|
||||
state = keys[index];
|
||||
index = (int)links[index];
|
||||
continue;
|
||||
}
|
||||
state = operator.APPLY_KEY_VALUE(state, keys[index]);
|
||||
index = (int)links[index];
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
@@ -1011,19 +841,6 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
return EMPTY_KEY_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return 0;
|
||||
int index = firstIndex;
|
||||
int result = 0;
|
||||
while(index != -1){
|
||||
if(filter.TEST_VALUE(keys[index])) result++;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public COMPARATOR KEY_GENERIC_TYPE comparator() { return null; }
|
||||
|
||||
@@ -1080,12 +897,12 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
}
|
||||
|
||||
@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_OBJECT_CONSUMER VVS_GENERIC_TYPE<E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
if(size() <= 0) return;
|
||||
int index = firstIndex;
|
||||
while(index != -1){
|
||||
action.accept(input, values[index]);
|
||||
action.accept(values[index], input);
|
||||
index = (int)links[index];
|
||||
}
|
||||
}
|
||||
@@ -1126,52 +943,6 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
return true;
|
||||
}
|
||||
|
||||
#if !VALUE_OBJECT
|
||||
@Override
|
||||
public VALUE_TYPE reduce(VALUE_TYPE identity, VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
VALUE_TYPE state = identity;
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
state = operator.APPLY_VALUE(state, values[index]);
|
||||
index = (int)links[index];
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
#else
|
||||
@Override
|
||||
public <VALUE_SPECIAL_TYPE> VALUE_SPECIAL_TYPE reduce(VALUE_SPECIAL_TYPE identity, BiFunction<VALUE_SPECIAL_TYPE, VALUE_TYPE, VALUE_SPECIAL_TYPE> operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
VALUE_SPECIAL_TYPE state = identity;
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
state = operator.apply(state, values[index]);
|
||||
index = (int)links[index];
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public VALUE_TYPE reduce(VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
VALUE_TYPE state = EMPTY_VALUE;
|
||||
boolean empty = true;
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
if(empty) {
|
||||
empty = false;
|
||||
state = values[index];
|
||||
index = (int)links[index];
|
||||
continue;
|
||||
}
|
||||
state = operator.APPLY_VALUE(state, values[index]);
|
||||
index = (int)links[index];
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
@@ -1183,19 +954,6 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
}
|
||||
return EMPTY_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return 0;
|
||||
int result = 0;
|
||||
int index = firstIndex;
|
||||
while(index != -1){
|
||||
if(filter.VALUE_TEST_VALUE(values[index])) result++;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
private class FastEntryIterator extends MapIterator implements ObjectListIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> {
|
||||
|
||||
+42
-394
@@ -6,13 +6,14 @@ import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||
#endif
|
||||
#if !TYPE_OBJECT && !VALUE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.functions.consumer.BI_OBJECT_CONSUMER;
|
||||
#endif
|
||||
#if !TYPE_OBJECT && !VALUE_BOOLEAN
|
||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||
@@ -20,9 +21,6 @@ import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||
import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
|
||||
import speiger.src.collections.PACKAGE.functions.function.FUNCTION;
|
||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||
#if !SAME_TYPE
|
||||
import speiger.src.collections.PACKAGE.functions.function.SINGLE_UNARY_OPERATOR;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.maps.abstracts.ABSTRACT_MAP;
|
||||
import speiger.src.collections.PACKAGE.maps.interfaces.MAP;
|
||||
@@ -34,7 +32,6 @@ import speiger.src.collections.PACKAGE.utils.maps.MAPS;
|
||||
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_ITERATOR;
|
||||
import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_SUPPLIER;
|
||||
#if !SAME_TYPE
|
||||
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_UNARY_OPERATOR;
|
||||
#if !VALUE_OBJECT
|
||||
@@ -51,20 +48,13 @@ import speiger.src.collections.objects.functions.function.Object2BooleanFunction
|
||||
#endif
|
||||
#endif
|
||||
#if !SAME_TYPE
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.objects.functions.consumer.VALUE_BI_FROM_OBJECT_CONSUMER;
|
||||
|
||||
#endif
|
||||
import speiger.src.collections.VALUE_PACKAGE.functions.consumer.VALUE_BI_OBJECT_CONSUMER;
|
||||
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE;
|
||||
#endif
|
||||
#if !VALUE_OBJECT
|
||||
import speiger.src.collections.objects.collections.ObjectIterator;
|
||||
#endif
|
||||
#if !TYPE_OBJECT
|
||||
#if !VALUE_OBJECT
|
||||
import speiger.src.collections.objects.functions.function.ObjectObjectUnaryOperator;
|
||||
|
||||
#endif
|
||||
import speiger.src.collections.objects.collections.ObjectBidirectionalIterator;
|
||||
import speiger.src.collections.objects.lists.ObjectListIterator;
|
||||
import speiger.src.collections.objects.sets.AbstractObjectSet;
|
||||
@@ -138,7 +128,11 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
public ARRAY_MAP(CLASS_TYPE[] keys, CLASS_VALUE_TYPE[] values, int length) {
|
||||
this(length);
|
||||
if(keys.length != values.length) throw new IllegalStateException("Input Arrays are not equal size");
|
||||
putAll(keys, values, 0, length);
|
||||
size = length;
|
||||
for(int i = 0,m=length;i<m;i++) {
|
||||
this.keys[i] = OBJ_TO_KEY(keys[i]);
|
||||
this.values[i] = OBJ_TO_VALUE(values[i]);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -160,9 +154,10 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
* @throws IllegalStateException if the keys and values do not match in lenght
|
||||
*/
|
||||
public ARRAY_MAP(KEY_TYPE[] keys, VALUE_TYPE[] values, int length) {
|
||||
this(length);
|
||||
if(keys.length != values.length) throw new IllegalStateException("Input Arrays are not equal size");
|
||||
putAll(keys, values, 0, length);
|
||||
this.keys = Arrays.copyOf(keys, length);
|
||||
this.values = Arrays.copyOf(values, length);
|
||||
this.size = length;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -202,12 +197,9 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
@Override
|
||||
public VALUE_TYPE putIfAbsent(KEY_TYPE key, VALUE_TYPE value) {
|
||||
int index = findIndex(key);
|
||||
if(index < 0) {
|
||||
insertIndex(size++, key, value);
|
||||
if(index >= 0) insertIndex(size++, key, value);
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
return values[index];
|
||||
}
|
||||
|
||||
#if VALUE_PRIMITIVES
|
||||
@Override
|
||||
@@ -466,7 +458,6 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
int index = findIndex(key);
|
||||
if(index == -1) {
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, getDefaultReturnValue());
|
||||
@@ -485,7 +476,6 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_ABSENT(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
int index = findIndex(key);
|
||||
if(index == -1) {
|
||||
VALUE_TYPE newValue = mappingFunction.GET_VALUE(key);
|
||||
@@ -493,39 +483,13 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
insertIndex(size++, key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
VALUE_TYPE newValue = values[index];
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
newValue = mappingFunction.GET_VALUE(key);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
values[index] = newValue;
|
||||
}
|
||||
return newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENT(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
|
||||
Objects.requireNonNull(valueProvider);
|
||||
int index = findIndex(key);
|
||||
if(index == -1) {
|
||||
VALUE_TYPE newValue = valueProvider.VALUE_GET_KEY();
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
insertIndex(size++, key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
VALUE_TYPE newValue = values[index];
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
newValue = valueProvider.VALUE_GET_KEY();
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
values[index] = newValue;
|
||||
}
|
||||
return newValue;
|
||||
return values[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
int index = findIndex(key);
|
||||
if(index == -1 || VALUE_EQUALS(values[index], getDefaultReturnValue())) return getDefaultReturnValue();
|
||||
if(index == -1) return getDefaultReturnValue();
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
removeIndex(index);
|
||||
@@ -537,12 +501,8 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE MERGE(KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
#if VALUE_OBJECT
|
||||
Objects.requireNonNull(value);
|
||||
#endif
|
||||
int index = findIndex(key);
|
||||
VALUE_TYPE newValue = index == -1 || VALUE_EQUALS(values[index], getDefaultReturnValue()) ? value : mappingFunction.APPLY_VALUE(values[index], value);
|
||||
VALUE_TYPE newValue = index == -1 ? value : mappingFunction.APPLY_VALUE(values[index], value);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
if(index >= 0)
|
||||
removeIndex(index);
|
||||
@@ -558,7 +518,7 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
for(MAP.Entry KEY_VALUE_GENERIC_TYPE entry : MAPS.fastIterable(m)) {
|
||||
KEY_TYPE key = entry.ENTRY_KEY();
|
||||
int index = findIndex(key);
|
||||
VALUE_TYPE newValue = index == -1 || VALUE_EQUALS(values[index], getDefaultReturnValue()) ? entry.ENTRY_VALUE() : mappingFunction.APPLY_VALUE(values[index], entry.ENTRY_VALUE());
|
||||
VALUE_TYPE newValue = index == -1 ? entry.ENTRY_VALUE() : mappingFunction.APPLY_VALUE(values[index], entry.ENTRY_VALUE());
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
if(index >= 0)
|
||||
removeIndex(index);
|
||||
@@ -580,14 +540,6 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
size = 0;
|
||||
}
|
||||
|
||||
public ARRAY_MAP KEY_VALUE_GENERIC_TYPE copy() {
|
||||
ARRAY_MAP KEY_VALUE_GENERIC_TYPE map = new ARRAY_MAPKV_BRACES();
|
||||
map.size = size;
|
||||
map.keys = Arrays.copyOf(keys, keys.length);
|
||||
map.values = Arrays.copyOf(values, keys.length);
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public COMPARATOR KEY_GENERIC_TYPE comparator() {
|
||||
return null;
|
||||
@@ -706,18 +658,21 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
|
||||
#endif
|
||||
protected int findIndex(Object key, Object value) {
|
||||
if(key == null || value == null) return -1;
|
||||
for(int i = size-1;i>=0;i--)
|
||||
if(EQUALS_KEY_TYPE(keys[i], key) && EQUALS_VALUE_TYPE(values[i], value)) return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
protected int findIndex(Object key) {
|
||||
if(key == null) return -1;
|
||||
for(int i = size-1;i>=0;i--)
|
||||
if(EQUALS_KEY_TYPE(keys[i], key)) return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
protected int findValue(Object value) {
|
||||
if(value == null) return -1;
|
||||
for(int i = size-1;i>=0;i--)
|
||||
if(EQUALS_VALUE_TYPE(values[i], value)) return i;
|
||||
return -1;
|
||||
@@ -1012,11 +967,6 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
return entrySet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SubMap copy() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public COMPARATOR KEY_GENERIC_TYPE comparator() {
|
||||
return null;
|
||||
@@ -1089,18 +1039,21 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
|
||||
#endif
|
||||
protected int findIndex(Object key, Object value) {
|
||||
if(key == null || value == null) return -1;
|
||||
for(int i = length-1;i>=0;i--)
|
||||
if(EQUALS_KEY_TYPE(keys[offset+i], key) && EQUALS_VALUE_TYPE(values[offset+i], value)) return i+offset;
|
||||
return -1;
|
||||
}
|
||||
|
||||
protected int findIndex(Object key) {
|
||||
if(key == null) return -1;
|
||||
for(int i = length-1;i>=0;i--)
|
||||
if(EQUALS_KEY_TYPE(keys[offset+i], key)) return i+offset;
|
||||
return -1;
|
||||
}
|
||||
|
||||
protected int findValue(Object value) {
|
||||
if(value == null) return -1;
|
||||
for(int i = length-1;i>=0;i--)
|
||||
if(EQUALS_VALUE_TYPE(values[offset+i], value)) return i+offset;
|
||||
return -1;
|
||||
@@ -1166,9 +1119,6 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
return new SubFastEntryIterator(fromElement);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SubMapEntrySet copy() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public void forEach(Consumer<? super MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
|
||||
Objects.requireNonNull(action);
|
||||
@@ -1188,10 +1138,10 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, ObjectObjectConsumer<E, MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
|
||||
public <E> void forEach(E input, ObjectObjectConsumer<MAP.Entry KEY_VALUE_GENERIC_TYPE, E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
for(int i = 0;i<length;i++)
|
||||
action.accept(input, new BasicEntryKV_BRACES(keys[offset+i], values[offset+i]));
|
||||
action.accept(new BasicEntryKV_BRACES(keys[offset+i], values[offset+i]), input);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1230,32 +1180,6 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> E reduce(E identity, BiFunction<E, MAP.Entry KEY_VALUE_GENERIC_TYPE, E> operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
E state = identity;
|
||||
for(int i = 0;i<length;i++) {
|
||||
state = operator.apply(state, new BasicEntryKV_BRACES(keys[offset+i], values[offset+i]));
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE reduce(ObjectObjectUnaryOperator<MAP.Entry KEY_VALUE_GENERIC_TYPE, MAP.Entry KEY_VALUE_GENERIC_TYPE> operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
MAP.Entry KEY_VALUE_GENERIC_TYPE state = null;
|
||||
boolean empty = true;
|
||||
for(int i = 0;i<length;i++) {
|
||||
if(empty) {
|
||||
empty = false;
|
||||
state = new BasicEntryKV_BRACES(keys[offset+i], values[offset+i]);
|
||||
continue;
|
||||
}
|
||||
state = operator.apply(state, new BasicEntryKV_BRACES(keys[offset+i], values[offset+i]));
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
@@ -1268,31 +1192,12 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return 0;
|
||||
int result = 0;
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
|
||||
for(int i = 0;i<length;i++) {
|
||||
entry.set(keys[offset+i], values[offset+i]);
|
||||
if(filter.getBoolean(entry)) result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean contains(Object o) {
|
||||
if(o instanceof Map.Entry) {
|
||||
if(o instanceof MAP.Entry) {
|
||||
MAP.Entry KEY_VALUE_GENERIC_TYPE entry = (MAP.Entry KEY_VALUE_GENERIC_TYPE)o;
|
||||
return SubMap.this.findIndex(entry.ENTRY_KEY(), entry.ENTRY_VALUE()) >= 0;
|
||||
}
|
||||
else {
|
||||
Map.Entry<?, ?> entry = (Map.Entry<?, ?>)o;
|
||||
return ARRAY_MAP.this.findIndex(entry.getKey(), entry.getValue()) >= 0;
|
||||
}
|
||||
if(o instanceof MAP.Entry) return SubMap.this.containsKey(((MAP.Entry KEY_VALUE_GENERIC_TYPE)o).ENTRY_KEY());
|
||||
return SubMap.this.containsKey(((Map.Entry<?, ?>)o).getKey());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -1341,7 +1246,7 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
@Override
|
||||
public boolean remove(Object o) {
|
||||
int oldSize = length;
|
||||
SubMap.this.remove(o);
|
||||
remove(o);
|
||||
return length != oldSize;
|
||||
}
|
||||
|
||||
@@ -1352,7 +1257,7 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
@Override
|
||||
public boolean remove(KEY_TYPE o) {
|
||||
int oldSize = length;
|
||||
SubMap.this.remove(o);
|
||||
remove(o);
|
||||
return length != oldSize;
|
||||
}
|
||||
|
||||
@@ -1384,9 +1289,6 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
@Override
|
||||
public KEY_TYPE POLL_LAST_KEY() { return POLL_LAST_ENTRY_KEY(); }
|
||||
|
||||
@Override
|
||||
public SubKeySet copy() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) {
|
||||
Objects.requireNonNull(action);
|
||||
@@ -1394,10 +1296,10 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
||||
public <E> void forEach(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE<E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
if(size() <= 0) return;
|
||||
for(int i = 0;i<length;action.accept(input, keys[offset+i]));
|
||||
for(int i = 0;i<length;action.accept(keys[offset+i], input));
|
||||
|
||||
}
|
||||
|
||||
@@ -1431,45 +1333,6 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
return true;
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public KEY_TYPE reduce(KEY_TYPE identity, SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = identity;
|
||||
for(int i = 0;i<length;i++) {
|
||||
state = operator.APPLY_KEY_VALUE(state, keys[i+offset]);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
#else
|
||||
@Override
|
||||
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_SPECIAL_TYPE state = identity;
|
||||
for(int i = 0;i<length;i++) {
|
||||
state = operator.apply(state, keys[i+offset]);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public KEY_TYPE reduce(SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = EMPTY_KEY_VALUE;
|
||||
boolean empty = true;
|
||||
for(int i = 0;i<length;i++) {
|
||||
if(empty) {
|
||||
empty = false;
|
||||
state = keys[i+offset];
|
||||
continue;
|
||||
}
|
||||
state = operator.APPLY_KEY_VALUE(state, keys[i+offset]);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
@@ -1480,17 +1343,6 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
return EMPTY_KEY_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return 0;
|
||||
int result = 0;
|
||||
for(int i = 0;i<length;i++) {
|
||||
if(filter.TEST_VALUE(keys[i+offset])) result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public COMPARATOR KEY_GENERIC_TYPE comparator() { return null; }
|
||||
@Override
|
||||
@@ -1542,9 +1394,9 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
}
|
||||
|
||||
@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_OBJECT_CONSUMER VVS_GENERIC_TYPE<E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
for(int i = 0;i<length;action.accept(input, values[offset+i]));
|
||||
for(int i = 0;i<length;action.accept(values[offset+i], input));
|
||||
|
||||
}
|
||||
|
||||
@@ -1575,45 +1427,6 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
return true;
|
||||
}
|
||||
|
||||
#if !VALUE_OBJECT
|
||||
@Override
|
||||
public VALUE_TYPE reduce(VALUE_TYPE identity, VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
VALUE_TYPE state = identity;
|
||||
for(int i = 0;i<length;i++) {
|
||||
state = operator.APPLY_VALUE(state, values[offset+i]);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
#else
|
||||
@Override
|
||||
public <VALUE_SPECIAL_TYPE> VALUE_SPECIAL_TYPE reduce(VALUE_SPECIAL_TYPE identity, BiFunction<VALUE_SPECIAL_TYPE, VALUE_TYPE, VALUE_SPECIAL_TYPE> operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
VALUE_SPECIAL_TYPE state = identity;
|
||||
for(int i = 0;i<length;i++) {
|
||||
state = operator.apply(state, values[offset+i]);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public VALUE_TYPE reduce(VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
VALUE_TYPE state = EMPTY_VALUE;
|
||||
boolean empty = true;
|
||||
for(int i = 0;i<length;i++) {
|
||||
if(empty) {
|
||||
empty = false;
|
||||
state = values[offset+i];
|
||||
continue;
|
||||
}
|
||||
state = operator.APPLY_VALUE(state, values[offset+i]);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
@@ -1622,16 +1435,6 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
}
|
||||
return EMPTY_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
int result = 0;
|
||||
for(int i = 0;i<length;i++) {
|
||||
if(filter.VALUE_TEST_VALUE(values[offset+i])) result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
private class SubFastEntryIterator extends SubMapIterator implements ObjectListIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> {
|
||||
@@ -1760,14 +1563,12 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
}
|
||||
|
||||
public int previousEntry() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
int returnIndex = offset+index;
|
||||
lastReturned = index--;
|
||||
return returnIndex;
|
||||
}
|
||||
|
||||
public int nextEntry() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
int returnIndex = offset+index;
|
||||
lastReturned = index++;
|
||||
return returnIndex;
|
||||
@@ -1849,9 +1650,6 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
return new FastEntryIterator(fromElement);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MapEntrySet copy() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public void forEach(Consumer<? super MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
|
||||
Objects.requireNonNull(action);
|
||||
@@ -1871,10 +1669,10 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, ObjectObjectConsumer<E, MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
|
||||
public <E> void forEach(E input, ObjectObjectConsumer<MAP.Entry KEY_VALUE_GENERIC_TYPE, E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
for(int i = 0;i<size;i++) {
|
||||
action.accept(input, new BasicEntryKV_BRACES(keys[i], values[i]));
|
||||
action.accept(new BasicEntryKV_BRACES(keys[i], values[i]), input);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1914,32 +1712,6 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> E reduce(E identity, BiFunction<E, MAP.Entry KEY_VALUE_GENERIC_TYPE, E> operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
E state = identity;
|
||||
for(int i = 0;i<size;i++) {
|
||||
state = operator.apply(state, new BasicEntryKV_BRACES(keys[i], values[i]));
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE reduce(ObjectObjectUnaryOperator<MAP.Entry KEY_VALUE_GENERIC_TYPE, MAP.Entry KEY_VALUE_GENERIC_TYPE> operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
MAP.Entry KEY_VALUE_GENERIC_TYPE state = null;
|
||||
boolean empty = true;
|
||||
for(int i = 0;i<size;i++) {
|
||||
if(empty) {
|
||||
empty = false;
|
||||
state = new BasicEntryKV_BRACES(keys[i], values[i]);
|
||||
continue;
|
||||
}
|
||||
state = operator.apply(state, new BasicEntryKV_BRACES(keys[i], values[i]));
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
@@ -1952,33 +1724,12 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return 0;
|
||||
int result = 0;
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
|
||||
for(int i = 0;i<size;i++) {
|
||||
entry.set(keys[i], values[i]);
|
||||
if(filter.getBoolean(entry)) result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean contains(Object o) {
|
||||
if(o instanceof Map.Entry) {
|
||||
if(o instanceof MAP.Entry) {
|
||||
MAP.Entry KEY_VALUE_GENERIC_TYPE entry = (MAP.Entry KEY_VALUE_GENERIC_TYPE)o;
|
||||
int index = ARRAY_MAP.this.findIndex(entry.ENTRY_KEY());
|
||||
if(index >= 0) return VALUE_EQUALS(entry.ENTRY_VALUE(), ARRAY_MAP.this.values[index]);
|
||||
}
|
||||
else {
|
||||
Map.Entry<?, ?> entry = (Map.Entry<?, ?>)o;
|
||||
int index = ARRAY_MAP.this.findIndex(entry.getKey());
|
||||
if(index >= 0) return Objects.equals(entry.getValue(), VALUE_TO_OBJ(ARRAY_MAP.this.values[index]));
|
||||
}
|
||||
if(o instanceof MAP.Entry) return ARRAY_MAP.this.containsKey(((MAP.Entry KEY_VALUE_GENERIC_TYPE)o).ENTRY_KEY());
|
||||
return ARRAY_MAP.this.containsKey(((Map.Entry<?, ?>)o).getKey());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -2027,7 +1778,7 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
@Override
|
||||
public boolean remove(Object o) {
|
||||
int oldSize = size;
|
||||
ARRAY_MAP.this.remove(o);
|
||||
remove(o);
|
||||
return size != oldSize;
|
||||
}
|
||||
|
||||
@@ -2038,7 +1789,7 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
@Override
|
||||
public boolean remove(KEY_TYPE o) {
|
||||
int oldSize = size;
|
||||
ARRAY_MAP.this.remove(o);
|
||||
remove(o);
|
||||
return size != oldSize;
|
||||
}
|
||||
|
||||
@@ -2070,9 +1821,6 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
@Override
|
||||
public KEY_TYPE POLL_LAST_KEY() { return POLL_LAST_ENTRY_KEY(); }
|
||||
|
||||
@Override
|
||||
public KeySet copy() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) {
|
||||
Objects.requireNonNull(action);
|
||||
@@ -2080,9 +1828,9 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
||||
public <E> void forEach(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE<E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
for(int i = 0;i<size;action.accept(input, keys[i++]));
|
||||
for(int i = 0;i<size;action.accept(keys[i++], input));
|
||||
|
||||
}
|
||||
|
||||
@@ -2114,45 +1862,6 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
return true;
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public KEY_TYPE reduce(KEY_TYPE identity, SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = identity;
|
||||
for(int i = 0;i<size;i++) {
|
||||
state = operator.APPLY_KEY_VALUE(state, keys[i]);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
#else
|
||||
@Override
|
||||
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_SPECIAL_TYPE state = identity;
|
||||
for(int i = 0;i<size;i++) {
|
||||
state = operator.apply(state, keys[i]);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public KEY_TYPE reduce(SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = EMPTY_KEY_VALUE;
|
||||
boolean empty = true;
|
||||
for(int i = 0;i<size;i++) {
|
||||
if(empty) {
|
||||
empty = false;
|
||||
state = keys[i];
|
||||
continue;
|
||||
}
|
||||
state = operator.APPLY_KEY_VALUE(state, keys[i]);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
@@ -2162,16 +1871,6 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
return EMPTY_KEY_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
int result = 0;
|
||||
for(int i = 0;i<size;i++) {
|
||||
if(filter.TEST_VALUE(keys[i])) result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public COMPARATOR KEY_GENERIC_TYPE comparator() { return null; }
|
||||
@Override
|
||||
@@ -2249,45 +1948,6 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
return true;
|
||||
}
|
||||
|
||||
#if !VALUE_OBJECT
|
||||
@Override
|
||||
public VALUE_TYPE reduce(VALUE_TYPE identity, VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
VALUE_TYPE state = identity;
|
||||
for(int i = 0;i<size;i++) {
|
||||
state = operator.APPLY_VALUE(state, values[i]);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
#else
|
||||
@Override
|
||||
public <VALUE_SPECIAL_TYPE> VALUE_SPECIAL_TYPE reduce(VALUE_SPECIAL_TYPE identity, BiFunction<VALUE_SPECIAL_TYPE, VALUE_TYPE, VALUE_SPECIAL_TYPE> operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
VALUE_SPECIAL_TYPE state = identity;
|
||||
for(int i = 0;i<size;i++) {
|
||||
state = operator.apply(state, values[i]);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public VALUE_TYPE reduce(VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
VALUE_TYPE state = EMPTY_VALUE;
|
||||
boolean empty = true;
|
||||
for(int i = 0;i<size;i++) {
|
||||
if(empty) {
|
||||
empty = false;
|
||||
state = values[i];
|
||||
continue;
|
||||
}
|
||||
state = operator.APPLY_VALUE(state, values[i]);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
@@ -2296,16 +1956,6 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
}
|
||||
return EMPTY_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
int result = 0;
|
||||
for(int i = 0;i<size;i++) {
|
||||
if(filter.VALUE_TEST_VALUE(values[i])) result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
private class FastEntryIterator extends MapIterator implements ObjectListIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> {
|
||||
@@ -2434,13 +2084,11 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
}
|
||||
|
||||
public int previousEntry() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
lastReturned = index;
|
||||
return index--;
|
||||
}
|
||||
|
||||
public int nextEntry() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
lastReturned = index;
|
||||
return index++;
|
||||
}
|
||||
@@ -2515,7 +2163,7 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return KEY_TO_STRING(keys[index]) + "=" + VALUE_TO_STRING(values[index]);
|
||||
return KEY_TO_STRING(keys[index]) + "->" + VALUE_TO_STRING(values[index]);
|
||||
}
|
||||
}
|
||||
}
|
||||
+14
-347
@@ -3,7 +3,9 @@ package speiger.src.collections.PACKAGE.maps.impl.misc;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
#if VALUE_OBJECT
|
||||
import java.util.Objects;
|
||||
#endif
|
||||
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ABSTRACT_COLLECTION;
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_COLLECTION;
|
||||
@@ -11,14 +13,6 @@ import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ITERATOR;
|
||||
#if !VALUE_OBJECT
|
||||
import speiger.src.collections.objects.collections.ObjectIterator;
|
||||
#endif
|
||||
import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_SUPPLIER;
|
||||
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_UNARY_OPERATOR;
|
||||
import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
|
||||
#if !VALUE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.functions.function.FUNCTION;
|
||||
import speiger.src.collections.PACKAGE.utils.maps.MAPS;
|
||||
import speiger.src.collections.objects.maps.abstracts.ABSTRACT_MAP;
|
||||
import speiger.src.collections.objects.maps.interfaces.MAP;
|
||||
import speiger.src.collections.objects.sets.AbstractObjectSet;
|
||||
@@ -34,13 +28,13 @@ import speiger.src.collections.objects.sets.ObjectSet;
|
||||
public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE
|
||||
{
|
||||
/** Enum Type that is being used */
|
||||
protected Class<T> keyType;
|
||||
protected final Class<T> keyType;
|
||||
/** The Backing keys array. */
|
||||
protected transient T[] keys;
|
||||
protected transient final T[] keys;
|
||||
/** The Backing values array */
|
||||
protected transient VALUE_TYPE[] values;
|
||||
protected transient final VALUE_TYPE[] values;
|
||||
/** The Backing array that indicates which index is present or not */
|
||||
protected transient long[] present;
|
||||
protected transient final long[] present;
|
||||
/** Amount of Elements stored in the ArrayMap */
|
||||
protected int size = 0;
|
||||
/** EntrySet cache */
|
||||
@@ -50,9 +44,6 @@ public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE
|
||||
/** Values cache */
|
||||
protected transient VALUE_COLLECTION VALUE_GENERIC_TYPE valuesC;
|
||||
|
||||
protected ENUM_MAP() {
|
||||
|
||||
}
|
||||
/**
|
||||
* Default Constructor
|
||||
* @param keyType the type of Enum that should be used
|
||||
@@ -64,86 +55,6 @@ public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE
|
||||
present = new long[((keys.length - 1) >> 6) + 1];
|
||||
}
|
||||
|
||||
#if !VALUE_OBJECT
|
||||
/**
|
||||
* Helper constructor that allow to create a EnumMap from boxed values (it will unbox them)
|
||||
* @param keys the keys that should be put into the EnumMap
|
||||
* @param values the values that should be put into the EnumMap.
|
||||
* @throws IllegalStateException if the keys and values do not match in lenght
|
||||
*/
|
||||
public ENUM_MAP(T[] keys, CLASS_VALUE_TYPE[] values) {
|
||||
if(keys.length <= 0) throw new IllegalArgumentException("Empty Array are not allowed");
|
||||
if(keys.length != values.length) throw new IllegalArgumentException("Keys and Values have to be the same size");
|
||||
keyType = keys[0].getDeclaringClass();
|
||||
this.keys = getKeyUniverse(keyType);
|
||||
this.values = NEW_VALUE_ARRAY(keys.length);
|
||||
present = new long[((keys.length - 1) >> 6) + 1];
|
||||
putAll(keys, values);
|
||||
}
|
||||
|
||||
#endif
|
||||
/**
|
||||
* Helper constructor that allow to create a EnumMap from unboxed values
|
||||
* @param keys the keys that should be put into the map
|
||||
* @param values the values that should be put into the map.
|
||||
* @throws IllegalStateException if the keys and values do not match in lenght
|
||||
*/
|
||||
public ENUM_MAP(T[] keys, VALUE_TYPE[] values) {
|
||||
if(keys.length <= 0) throw new IllegalArgumentException("Empty Array are not allowed");
|
||||
if(keys.length != values.length) throw new IllegalArgumentException("Keys and Values have to be the same size");
|
||||
keyType = keys[0].getDeclaringClass();
|
||||
this.keys = getKeyUniverse(keyType);
|
||||
this.values = NEW_VALUE_ARRAY(keys.length);
|
||||
present = new long[((keys.length - 1) >> 6) + 1];
|
||||
putAll(keys, values);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper constructor that allows to create a EnumMap with exactly the same values as the provided map.
|
||||
* @param map the values that should be present in the map
|
||||
*/
|
||||
public ENUM_MAP(Map<? extends CLASS_TYPE, ? extends CLASS_VALUE_TYPE> map) {
|
||||
if(map instanceof ENUM_MAP) {
|
||||
ENUM_MAP KEY_VALUE_GENERIC_TYPE enumMap = (ENUM_MAP KEY_VALUE_GENERIC_TYPE)map;
|
||||
keyType = enumMap.keyType;
|
||||
keys = enumMap.keys;
|
||||
values = enumMap.values.clone();
|
||||
present = enumMap.present.clone();
|
||||
size = enumMap.size;
|
||||
}
|
||||
else if(map.isEmpty()) throw new IllegalArgumentException("Empty Maps are not allowed");
|
||||
else {
|
||||
keyType = map.keySet().iterator().next().getDeclaringClass();
|
||||
this.keys = getKeyUniverse(keyType);
|
||||
this.values = NEW_VALUE_ARRAY(keys.length);
|
||||
present = new long[((keys.length - 1) >> 6) + 1];
|
||||
putAll(map);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A Type Specific Helper function that allows to create a new EnumMap with exactly the same values as the provided map.
|
||||
* @param map the values that should be present in the map
|
||||
*/
|
||||
public ENUM_MAP(MAP KEY_VALUE_GENERIC_TYPE map) {
|
||||
if(map instanceof ENUM_MAP) {
|
||||
ENUM_MAP KEY_VALUE_GENERIC_TYPE enumMap = (ENUM_MAP KEY_VALUE_GENERIC_TYPE)map;
|
||||
keyType = enumMap.keyType;
|
||||
keys = enumMap.keys;
|
||||
values = enumMap.values.clone();
|
||||
present = enumMap.present.clone();
|
||||
size = enumMap.size;
|
||||
}
|
||||
else if(map.isEmpty()) throw new IllegalArgumentException("Empty Maps are not allowed");
|
||||
else {
|
||||
keyType = map.keySet().iterator().next().getDeclaringClass();
|
||||
this.keys = getKeyUniverse(keyType);
|
||||
this.values = NEW_VALUE_ARRAY(keys.length);
|
||||
present = new long[((keys.length - 1) >> 6) + 1];
|
||||
putAll(map);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE put(T key, VALUE_TYPE value) {
|
||||
int index = key.ordinal();
|
||||
@@ -183,7 +94,6 @@ public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE
|
||||
#endif
|
||||
@Override
|
||||
public boolean containsKey(Object key) {
|
||||
if(!keyType.isInstance(key)) return false;
|
||||
return isSet(((T)key).ordinal());
|
||||
}
|
||||
|
||||
@@ -191,7 +101,7 @@ public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE
|
||||
@Override
|
||||
public boolean containsValue(Object value) {
|
||||
for(int i = 0;i<values.length;i++)
|
||||
if(isSet(i) && VALUE_EQUALS(value, values[i])) return true;
|
||||
if(VALUE_EQUALS(value, values[i])) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -199,25 +109,13 @@ public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE
|
||||
@Override
|
||||
public boolean containsValue(VALUE_TYPE value) {
|
||||
for(int i = 0;i<values.length;i++)
|
||||
if(isSet(i) && VALUE_EQUALS(value, values[i])) return true;
|
||||
if(VALUE_EQUALS(value, values[i])) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public CLASS_VALUE_TYPE remove(Object key) {
|
||||
if(!keyType.isInstance(key)) return getDefaultReturnValue();
|
||||
int index = ((T)key).ordinal();
|
||||
if(!isSet(index)) return getDefaultReturnValue();
|
||||
clear(index);
|
||||
VALUE_TYPE result = values[index];
|
||||
values[index] = EMPTY_VALUE;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE rem(T key) {
|
||||
if(!keyType.isInstance(key)) return getDefaultReturnValue();
|
||||
int index = key.ordinal();
|
||||
if(!isSet(index)) return getDefaultReturnValue();
|
||||
clear(index);
|
||||
@@ -259,7 +157,6 @@ public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE
|
||||
#endif
|
||||
@Override
|
||||
public VALUE_TYPE GET_VALUE(T key) {
|
||||
if(!keyType.isInstance(key)) return getDefaultReturnValue();
|
||||
int index = key.ordinal();
|
||||
return isSet(index) ? values[index] : getDefaultReturnValue();
|
||||
}
|
||||
@@ -267,7 +164,6 @@ public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE
|
||||
#if VALUE_OBJECT
|
||||
@Override
|
||||
public VALUE_TYPE getOrDefault(Object key, VALUE_TYPE defaultValue) {
|
||||
if(!keyType.isInstance(key)) return defaultValue;
|
||||
int index = ((T)key).ordinal();
|
||||
return isSet(index) ? values[index] : defaultValue;
|
||||
}
|
||||
@@ -275,21 +171,11 @@ public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE
|
||||
#else
|
||||
@Override
|
||||
public VALUE_TYPE getOrDefault(T key, VALUE_TYPE defaultValue) {
|
||||
if(!keyType.isInstance(key)) return defaultValue;
|
||||
int index = key.ordinal();
|
||||
return isSet(index) ? values[index] : defaultValue;
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public ENUM_MAP KEY_VALUE_GENERIC_TYPE copy() {
|
||||
ENUM_MAP KEY_VALUE_GENERIC_TYPE map = new ENUM_MAPKV_BRACES(keyType);
|
||||
map.size = size;
|
||||
System.arraycopy(present, 0, map.present, 0, Math.min(present.length, map.present.length));
|
||||
System.arraycopy(values, 0, map.values, 0, Math.min(values.length, map.values.length));
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> ENTRY_SET() {
|
||||
if(entrySet == null) entrySet = new EntrySet();
|
||||
@@ -308,145 +194,6 @@ public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE
|
||||
return valuesC;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEach(BI_CONSUMER KEY_VALUE_GENERIC_TYPE action) {
|
||||
if(size() <= 0) return;
|
||||
for(int i = 0,m=keys.length;i<m;i++) {
|
||||
if(isSet(i)) action.accept(keys[i], values[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean replace(T key, VALUE_TYPE oldValue, VALUE_TYPE newValue) {
|
||||
int index = key.ordinal();
|
||||
if(!isSet(index) || values[index] != oldValue) return false;
|
||||
values[index] = newValue;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE replace(T key, VALUE_TYPE value) {
|
||||
int index = key.ordinal();
|
||||
if(!isSet(index)) return getDefaultReturnValue();
|
||||
VALUE_TYPE oldValue = values[index];
|
||||
values[index] = value;
|
||||
return oldValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE(T key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
int index = key.ordinal();
|
||||
if(!isSet(index)) {
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, getDefaultReturnValue());
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
set(index);
|
||||
values[index] = newValue;
|
||||
return newValue;
|
||||
}
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
clear(index);
|
||||
values[index] = EMPTY_VALUE;
|
||||
return newValue;
|
||||
}
|
||||
values[index] = newValue;
|
||||
return newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_ABSENT(T key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
int index = key.ordinal();
|
||||
if(!isSet(index)) {
|
||||
VALUE_TYPE newValue = mappingFunction.GET_VALUE(key);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
set(index);
|
||||
values[index] = newValue;
|
||||
return newValue;
|
||||
}
|
||||
VALUE_TYPE newValue = values[index];
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
newValue = mappingFunction.GET_VALUE(key);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
values[index] = newValue;
|
||||
}
|
||||
return newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENT(T key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
|
||||
int index = key.ordinal();
|
||||
if(!isSet(index)) {
|
||||
VALUE_TYPE newValue = valueProvider.VALUE_GET_KEY();
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
set(index);
|
||||
values[index] = newValue;
|
||||
return newValue;
|
||||
}
|
||||
VALUE_TYPE newValue = values[index];
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
newValue = valueProvider.VALUE_GET_KEY();
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
values[index] = newValue;
|
||||
}
|
||||
return newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENT(T key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
int index = key.ordinal();
|
||||
if(!isSet(index) || VALUE_EQUALS(values[index], getDefaultReturnValue())) return getDefaultReturnValue();
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
clear(index);
|
||||
values[index] = EMPTY_VALUE;
|
||||
return newValue;
|
||||
}
|
||||
values[index] = newValue;
|
||||
return newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE MERGE(T key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
int index = key.ordinal();
|
||||
#if VALUE_OBJECT
|
||||
Objects.requireNonNull(value);
|
||||
#endif
|
||||
VALUE_TYPE newValue = !isSet(index) || VALUE_EQUALS(values[index], getDefaultReturnValue()) ? value : mappingFunction.APPLY_VALUE(values[index], value);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
if(isSet(index)) {
|
||||
clear(index);
|
||||
values[index] = EMPTY_VALUE;
|
||||
}
|
||||
}
|
||||
else if(!isSet(index)) {
|
||||
set(index);
|
||||
values[index] = newValue;
|
||||
}
|
||||
else values[index] = newValue;
|
||||
return newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void BULK_MERGE(MAP KEY_VALUE_GENERIC_TYPE m, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
for(MAP.Entry KEY_VALUE_GENERIC_TYPE entry : MAPS.fastIterable(m)) {
|
||||
T key = entry.ENTRY_KEY();
|
||||
int index = key.ordinal();
|
||||
VALUE_TYPE newValue = !isSet(index) || VALUE_EQUALS(values[index], getDefaultReturnValue()) ? entry.ENTRY_VALUE() : mappingFunction.APPLY_VALUE(values[index], entry.ENTRY_VALUE());
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
if(isSet(index)) {
|
||||
clear(index);
|
||||
values[index] = EMPTY_VALUE;
|
||||
}
|
||||
}
|
||||
else if(!isSet(index)) {
|
||||
set(index);
|
||||
values[index] = newValue;
|
||||
}
|
||||
else values[index] = newValue;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
if(size == 0) return;
|
||||
@@ -455,11 +202,6 @@ public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE
|
||||
Arrays.fill(values, EMPTY_VALUE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return size;
|
||||
}
|
||||
|
||||
protected void onNodeAdded(int index) {
|
||||
|
||||
}
|
||||
@@ -469,18 +211,16 @@ public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE
|
||||
}
|
||||
|
||||
protected void set(int index) {
|
||||
onNodeAdded(index);
|
||||
present[index >> 6] |= (1L << index);
|
||||
size++;
|
||||
onNodeAdded(index);
|
||||
}
|
||||
protected void clear(int index) {
|
||||
size--;
|
||||
present[index >> 6] &= ~(1L << index);
|
||||
onNodeRemoved(index);
|
||||
}
|
||||
protected boolean isSet(int index) { return (present[index >> 6] & (1L << index)) != 0; }
|
||||
|
||||
protected static <K extends Enum<K>> K[] getKeyUniverse(Class<K> keyType) {
|
||||
private static <K extends Enum<K>> K[] getKeyUniverse(Class<K> keyType) {
|
||||
return keyType.getEnumConstants();
|
||||
}
|
||||
|
||||
@@ -488,20 +228,7 @@ public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE
|
||||
|
||||
@Override
|
||||
public boolean contains(Object o) {
|
||||
if(o instanceof Map.Entry) {
|
||||
if(o instanceof MAP.Entry) {
|
||||
MAP.Entry KEY_VALUE_GENERIC_TYPE entry = (MAP.Entry KEY_VALUE_GENERIC_TYPE)o;
|
||||
if(!keyType.isInstance(entry.ENTRY_KEY())) return false;
|
||||
int index = ((T)entry.ENTRY_KEY()).ordinal();
|
||||
if(index >= 0 && ENUM_MAP.this.isSet(index)) return VALUE_EQUALS(entry.ENTRY_VALUE(), ENUM_MAP.this.values[index]);
|
||||
}
|
||||
else {
|
||||
Map.Entry<?, ?> entry = (Map.Entry<?, ?>)o;
|
||||
if(!keyType.isInstance(entry.getKey())) return false;
|
||||
int index = ((T)entry.getKey()).ordinal();
|
||||
if(index >= 0 && ENUM_MAP.this.isSet(index)) return Objects.equals(entry.getValue(), VALUE_TO_OBJ(ENUM_MAP.this.values[index]));
|
||||
}
|
||||
}
|
||||
if(o instanceof Map.Entry) return containsKey(((Map.Entry<?, ?>)o).getKey());
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -597,7 +324,8 @@ public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE
|
||||
class EntryIterator extends MapIterator implements ObjectIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> {
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE next() {
|
||||
return new MapEntry(nextEntry());
|
||||
int index = nextEntry();
|
||||
return new BasicEntry<>(keys[index], values[index]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -632,74 +360,13 @@ public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE
|
||||
public int nextEntry() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
lastReturnValue = nextIndex;
|
||||
nextIndex = -1;
|
||||
return lastReturnValue;
|
||||
return nextIndex;
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
if(lastReturnValue == -1) throw new IllegalStateException();
|
||||
clear(lastReturnValue);
|
||||
values[lastReturnValue] = EMPTY_VALUE;
|
||||
lastReturnValue = -1;
|
||||
}
|
||||
}
|
||||
|
||||
protected class MapEntry implements MAP.Entry KEY_VALUE_GENERIC_TYPE, Map.Entry<CLASS_TYPE, CLASS_VALUE_TYPE> {
|
||||
public int index = -1;
|
||||
|
||||
public MapEntry() {}
|
||||
public MapEntry(int index) {
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE ENTRY_KEY() {
|
||||
return keys[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE ENTRY_VALUE() {
|
||||
return values[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE setValue(VALUE_TYPE value) {
|
||||
VALUE_TYPE oldValue = values[index];
|
||||
values[index] = value;
|
||||
return oldValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(obj instanceof Map.Entry) {
|
||||
if(obj instanceof MAP.Entry) {
|
||||
MAP.Entry KEY_VALUE_GENERIC_TYPE entry = (MAP.Entry KEY_VALUE_GENERIC_TYPE)obj;
|
||||
return KEY_EQUALS(keys[index], entry.ENTRY_KEY()) && VALUE_EQUALS(values[index], entry.ENTRY_VALUE());
|
||||
}
|
||||
Map.Entry<?, ?> entry = (Map.Entry<?, ?>)obj;
|
||||
Object key = entry.getKey();
|
||||
Object value = entry.getValue();
|
||||
#if TYPE_OBJECT && VALUE_OBJECT
|
||||
return KEY_EQUALS(keys[index], key) && VALUE_EQUALS(values[index], value);
|
||||
#else if TYPE_OBJECT
|
||||
return value instanceof CLASS_VALUE_TYPE && KEY_EQUALS(keys[index], key) && VALUE_EQUALS(values[index], CLASS_TO_VALUE(value));
|
||||
#else if VALUE_OBJECT
|
||||
return key instanceof CLASS_TYPE && KEY_EQUALS(keys[index], CLASS_TO_KEY(key)) && VALUE_EQUALS(values[index], value);
|
||||
#else
|
||||
return key instanceof CLASS_TYPE && value instanceof CLASS_VALUE_TYPE && KEY_EQUALS(keys[index], CLASS_TO_KEY(key)) && VALUE_EQUALS(values[index], CLASS_TO_VALUE(value));
|
||||
#endif
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return KEY_TO_HASH(keys[index]) ^ VALUE_TO_HASH(values[index]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return KEY_TO_STRING(keys[index]) + "=" + VALUE_TO_STRING(values[index]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+5
-164
@@ -59,136 +59,6 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
links = new long[keys.length];
|
||||
}
|
||||
|
||||
#if !VALUE_OBJECT
|
||||
/**
|
||||
* Helper constructor that allow to create a EnumMap from boxed values (it will unbox them)
|
||||
* @param keys the keys that should be put into the EnumMap
|
||||
* @param values the values that should be put into the EnumMap.
|
||||
* @throws IllegalStateException if the keys and values do not match in lenght
|
||||
*/
|
||||
public LINKED_ENUM_MAP(T[] keys, CLASS_VALUE_TYPE[] values) {
|
||||
if(keys.length <= 0) throw new IllegalArgumentException("Empty Array are not allowed");
|
||||
if(keys.length != values.length) throw new IllegalArgumentException("Keys and Values have to be the same size");
|
||||
keyType = keys[0].getDeclaringClass();
|
||||
this.keys = getKeyUniverse(keyType);
|
||||
this.values = NEW_VALUE_ARRAY(keys.length);
|
||||
present = new long[((keys.length - 1) >> 6) + 1];
|
||||
links = new long[keys.length];
|
||||
putAll(keys, values);
|
||||
}
|
||||
|
||||
#endif
|
||||
/**
|
||||
* Helper constructor that allow to create a EnumMap from unboxed values
|
||||
* @param keys the keys that should be put into the map
|
||||
* @param values the values that should be put into the map.
|
||||
* @throws IllegalStateException if the keys and values do not match in lenght
|
||||
*/
|
||||
public LINKED_ENUM_MAP(T[] keys, VALUE_TYPE[] values) {
|
||||
if(keys.length <= 0) throw new IllegalArgumentException("Empty Array are not allowed");
|
||||
if(keys.length != values.length) throw new IllegalArgumentException("Keys and Values have to be the same size");
|
||||
keyType = keys[0].getDeclaringClass();
|
||||
this.keys = getKeyUniverse(keyType);
|
||||
this.values = NEW_VALUE_ARRAY(keys.length);
|
||||
present = new long[((keys.length - 1) >> 6) + 1];
|
||||
links = new long[keys.length];
|
||||
putAll(keys, values);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper constructor that allows to create a EnumMap with exactly the same values as the provided map.
|
||||
* @param map the values that should be present in the map
|
||||
*/
|
||||
public LINKED_ENUM_MAP(Map<? extends CLASS_TYPE, ? extends CLASS_VALUE_TYPE> map) {
|
||||
if(map instanceof LINKED_ENUM_MAP) {
|
||||
LINKED_ENUM_MAP KEY_VALUE_GENERIC_TYPE enumMap = (LINKED_ENUM_MAP KEY_VALUE_GENERIC_TYPE)map;
|
||||
keyType = enumMap.keyType;
|
||||
keys = enumMap.keys;
|
||||
values = enumMap.values.clone();
|
||||
present = enumMap.present.clone();
|
||||
links = enumMap.links.clone();
|
||||
size = enumMap.size;
|
||||
}
|
||||
else if(map instanceof ENUM_MAP) {
|
||||
ENUM_MAP KEY_VALUE_GENERIC_TYPE enumMap = (ENUM_MAP KEY_VALUE_GENERIC_TYPE)map;
|
||||
keyType = enumMap.keyType;
|
||||
keys = enumMap.keys;
|
||||
values = enumMap.values.clone();
|
||||
present = enumMap.present.clone();
|
||||
links = new long[keys.length];
|
||||
for(int i = 0,m=keys.length;i<m;i++) {
|
||||
if(isSet(i)) {
|
||||
if(size == 0) {
|
||||
firstIndex = lastIndex = i;
|
||||
links[i] = -1L;
|
||||
}
|
||||
else {
|
||||
links[lastIndex] ^= ((links[lastIndex] ^ (i & 0xFFFFFFFFL)) & 0xFFFFFFFFL);
|
||||
links[i] = ((lastIndex & 0xFFFFFFFFL) << 32) | 0xFFFFFFFFL;
|
||||
lastIndex = i;
|
||||
}
|
||||
size++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(map.isEmpty()) throw new IllegalArgumentException("Empty Maps are not allowed");
|
||||
else {
|
||||
keyType = map.keySet().iterator().next().getDeclaringClass();
|
||||
this.keys = getKeyUniverse(keyType);
|
||||
this.values = NEW_VALUE_ARRAY(keys.length);
|
||||
present = new long[((keys.length - 1) >> 6) + 1];
|
||||
links = new long[keys.length];
|
||||
putAll(map);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A Type Specific Helper function that allows to create a new EnumMap with exactly the same values as the provided map.
|
||||
* @param map the values that should be present in the map
|
||||
*/
|
||||
public LINKED_ENUM_MAP(MAP KEY_VALUE_GENERIC_TYPE map) {
|
||||
if(map instanceof LINKED_ENUM_MAP) {
|
||||
LINKED_ENUM_MAP KEY_VALUE_GENERIC_TYPE enumMap = (LINKED_ENUM_MAP KEY_VALUE_GENERIC_TYPE)map;
|
||||
keyType = enumMap.keyType;
|
||||
keys = enumMap.keys;
|
||||
values = enumMap.values.clone();
|
||||
present = enumMap.present.clone();
|
||||
links = enumMap.links.clone();
|
||||
size = enumMap.size;
|
||||
}
|
||||
else if(map instanceof ENUM_MAP) {
|
||||
ENUM_MAP KEY_VALUE_GENERIC_TYPE enumMap = (ENUM_MAP KEY_VALUE_GENERIC_TYPE)map;
|
||||
keyType = enumMap.keyType;
|
||||
keys = enumMap.keys;
|
||||
values = enumMap.values.clone();
|
||||
present = enumMap.present.clone();
|
||||
links = new long[keys.length];
|
||||
for(int i = 0,m=keys.length;i<m;i++) {
|
||||
if(isSet(i)) {
|
||||
if(size == 0) {
|
||||
firstIndex = lastIndex = i;
|
||||
links[i] = -1L;
|
||||
}
|
||||
else {
|
||||
links[lastIndex] ^= ((links[lastIndex] ^ (i & 0xFFFFFFFFL)) & 0xFFFFFFFFL);
|
||||
links[i] = ((lastIndex & 0xFFFFFFFFL) << 32) | 0xFFFFFFFFL;
|
||||
lastIndex = i;
|
||||
}
|
||||
size++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(map.isEmpty()) throw new IllegalArgumentException("Empty Maps are not allowed");
|
||||
else {
|
||||
keyType = map.keySet().iterator().next().getDeclaringClass();
|
||||
this.keys = getKeyUniverse(keyType);
|
||||
this.values = NEW_VALUE_ARRAY(keys.length);
|
||||
present = new long[((keys.length - 1) >> 6) + 1];
|
||||
links = new long[keys.length];
|
||||
putAll(map);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE putAndMoveToFirst(T key, VALUE_TYPE value) {
|
||||
int index = key.ordinal();
|
||||
@@ -257,18 +127,6 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
return values[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public LINKED_ENUM_MAP KEY_VALUE_GENERIC_TYPE copy() {
|
||||
LINKED_ENUM_MAP KEY_VALUE_GENERIC_TYPE map = new LINKED_ENUM_MAPKV_BRACES(keyType);
|
||||
map.size = size;
|
||||
System.arraycopy(present, 0, map.present, 0, Math.min(present.length, map.present.length));
|
||||
System.arraycopy(values, 0, map.values, 0, Math.min(values.length, map.values.length));
|
||||
System.arraycopy(links, 0, map.links, 0, Math.min(links.length, map.links.length));
|
||||
map.firstIndex = firstIndex;
|
||||
map.lastIndex = lastIndex;
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public COMPARATOR KEY_GENERIC_TYPE comparator() {
|
||||
return null;
|
||||
@@ -493,8 +351,6 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
return new FastEntryIterator(fromElement);
|
||||
}
|
||||
|
||||
public MapEntrySet copy() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public void forEach(Consumer<? super MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
|
||||
int index = firstIndex;
|
||||
@@ -519,18 +375,8 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
@Deprecated
|
||||
public boolean contains(Object o) {
|
||||
if(o instanceof Map.Entry) {
|
||||
if(o instanceof MAP.Entry) {
|
||||
MAP.Entry KEY_VALUE_GENERIC_TYPE entry = (MAP.Entry KEY_VALUE_GENERIC_TYPE)o;
|
||||
if(!keyType.isInstance(entry.ENTRY_KEY())) return false;
|
||||
int index = ((T)entry.ENTRY_KEY()).ordinal();
|
||||
if(index >= 0 && LINKED_ENUM_MAP.this.isSet(index)) return VALUE_EQUALS(entry.ENTRY_VALUE(), LINKED_ENUM_MAP.this.values[index]);
|
||||
}
|
||||
else {
|
||||
Map.Entry<?, ?> entry = (Map.Entry<?, ?>)o;
|
||||
if(!keyType.isInstance(entry.getKey())) return false;
|
||||
int index = ((T)entry.getKey()).ordinal();
|
||||
if(index >= 0 && LINKED_ENUM_MAP.this.isSet(index)) return Objects.equals(entry.getValue(), VALUE_TO_OBJ(LINKED_ENUM_MAP.this.values[index]));
|
||||
}
|
||||
if(o instanceof MAP.Entry) return LINKED_ENUM_MAP.this.containsKey(((MAP.Entry KEY_VALUE_GENERIC_TYPE)o).ENTRY_KEY());
|
||||
return LINKED_ENUM_MAP.this.containsKey(((Map.Entry<?, ?>)o).getKey());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -582,7 +428,7 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
@Override
|
||||
public boolean remove(Object o) {
|
||||
int oldSize = size;
|
||||
LINKED_ENUM_MAP.this.remove(o);
|
||||
remove(o);
|
||||
return size != oldSize;
|
||||
}
|
||||
|
||||
@@ -595,7 +441,7 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
@Override
|
||||
public boolean remove(T o) {
|
||||
int oldSize = size;
|
||||
LINKED_ENUM_MAP.this.remove(o);
|
||||
remove(o);
|
||||
return size != oldSize;
|
||||
}
|
||||
|
||||
@@ -631,8 +477,6 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
return new KeyIterator(fromElement);
|
||||
}
|
||||
|
||||
public KeySet copy() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return LINKED_ENUM_MAP.this.size();
|
||||
@@ -897,7 +741,6 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
previous = (int)(links[current] >>> 32);
|
||||
}
|
||||
else next = (int)links[current];
|
||||
|
||||
size--;
|
||||
if(previous == -1) firstIndex = next;
|
||||
else links[previous] ^= ((links[previous] ^ (next & 0xFFFFFFFFL)) & 0xFFFFFFFFL);
|
||||
@@ -905,8 +748,6 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
if (next == -1) lastIndex = previous;
|
||||
else links[next] ^= ((links[next] ^ ((previous & 0xFFFFFFFFL) << 32)) & 0xFFFFFFFF00000000L);
|
||||
values[current] = EMPTY_VALUE;
|
||||
present[current >> 6] &= ~(1L << current);
|
||||
current = -1;
|
||||
}
|
||||
|
||||
public int previousEntry() {
|
||||
@@ -998,7 +839,7 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return KEY_TO_STRING(keys[index]) + "=" + VALUE_TO_STRING(values[index]);
|
||||
return KEY_TO_STRING(keys[index]) + "->" + VALUE_TO_STRING(values[index]);
|
||||
}
|
||||
}
|
||||
}
|
||||
+22
-385
@@ -5,7 +5,6 @@ import java.util.Map;
|
||||
import java.util.Comparator;
|
||||
#endif
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.Objects;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
@@ -13,7 +12,9 @@ import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||
#endif
|
||||
#if !TYPE_OBJECT && !VALUE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.functions.consumer.BI_OBJECT_CONSUMER;
|
||||
#endif
|
||||
#if !TYPE_OBJECT && !VALUE_BOOLEAN
|
||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||
@@ -21,9 +22,6 @@ import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||
import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
|
||||
import speiger.src.collections.PACKAGE.functions.function.FUNCTION;
|
||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||
#if !SAME_TYPE
|
||||
import speiger.src.collections.PACKAGE.functions.function.SINGLE_UNARY_OPERATOR;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.maps.abstracts.ABSTRACT_MAP;
|
||||
import speiger.src.collections.PACKAGE.maps.interfaces.MAP;
|
||||
@@ -37,7 +35,6 @@ import speiger.src.collections.PACKAGE.utils.maps.MAPS;
|
||||
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_ITERATOR;
|
||||
import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_SUPPLIER;
|
||||
#if !SAME_TYPE
|
||||
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_UNARY_OPERATOR;
|
||||
import speiger.src.collections.VALUE_PACKAGE.lists.VALUE_LIST_ITERATOR;
|
||||
@@ -55,10 +52,7 @@ import speiger.src.collections.objects.functions.function.Object2BooleanFunction
|
||||
#endif
|
||||
#endif
|
||||
#if !SAME_TYPE
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.objects.functions.consumer.VALUE_BI_FROM_OBJECT_CONSUMER;
|
||||
|
||||
#endif
|
||||
import speiger.src.collections.VALUE_PACKAGE.functions.consumer.VALUE_BI_OBJECT_CONSUMER;
|
||||
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE;
|
||||
#endif
|
||||
#if !TYPE_OBJECT && !VALUE_OBJECT
|
||||
@@ -69,10 +63,6 @@ import speiger.src.collections.objects.utils.ObjectIterators;
|
||||
import speiger.src.collections.objects.collections.ObjectIterator;
|
||||
#endif
|
||||
#if !TYPE_OBJECT
|
||||
#if !VALUE_OBJECT
|
||||
import speiger.src.collections.objects.functions.function.ObjectObjectUnaryOperator;
|
||||
|
||||
#endif
|
||||
import speiger.src.collections.objects.sets.AbstractObjectSet;
|
||||
import speiger.src.collections.objects.sets.ObjectSet;
|
||||
#endif
|
||||
@@ -233,9 +223,6 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
#endif
|
||||
@Override
|
||||
public VALUE_TYPE put(KEY_TYPE key, VALUE_TYPE value) {
|
||||
#if TYPE_OBJECT
|
||||
validate(key);
|
||||
#endif
|
||||
if(tree == null) {
|
||||
tree = first = last = new EntryKV_BRACES(key, value, null);
|
||||
size++;
|
||||
@@ -270,9 +257,6 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE putIfAbsent(KEY_TYPE key, VALUE_TYPE value) {
|
||||
#if TYPE_OBJECT
|
||||
validate(key);
|
||||
#endif
|
||||
if(tree == null) {
|
||||
tree = first = last = new EntryKV_BRACES(key, value, null);
|
||||
size++;
|
||||
@@ -308,9 +292,6 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
#if VALUE_PRIMITIVES
|
||||
@Override
|
||||
public VALUE_TYPE addTo(KEY_TYPE key, VALUE_TYPE value) {
|
||||
#if TYPE_OBJECT
|
||||
validate(key);
|
||||
#endif
|
||||
if(tree == null) {
|
||||
tree = first = last = new EntryKV_BRACES(key, value, null);
|
||||
size++;
|
||||
@@ -519,10 +500,6 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
#if TYPE_OBJECT
|
||||
validate(key);
|
||||
#endif
|
||||
Entry KEY_VALUE_GENERIC_TYPE entry = findNode(key);
|
||||
if(entry == null) {
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, getDefaultReturnValue());
|
||||
@@ -541,10 +518,6 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_ABSENT(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
#if TYPE_OBJECT
|
||||
validate(key);
|
||||
#endif
|
||||
Entry KEY_VALUE_GENERIC_TYPE entry = findNode(key);
|
||||
if(entry == null) {
|
||||
VALUE_TYPE newValue = mappingFunction.GET_VALUE(key);
|
||||
@@ -552,43 +525,13 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
put(key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
if(VALUE_EQUALS(entry.value, getDefaultReturnValue())) {
|
||||
VALUE_TYPE newValue = mappingFunction.GET_VALUE(key);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
entry.value = newValue;
|
||||
}
|
||||
return entry.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENT(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
|
||||
Objects.requireNonNull(valueProvider);
|
||||
#if TYPE_OBJECT
|
||||
validate(key);
|
||||
#endif
|
||||
Entry KEY_VALUE_GENERIC_TYPE entry = findNode(key);
|
||||
if(entry == null) {
|
||||
VALUE_TYPE newValue = valueProvider.VALUE_GET_KEY();
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
put(key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
if(VALUE_EQUALS(entry.value, getDefaultReturnValue())) {
|
||||
VALUE_TYPE newValue = valueProvider.VALUE_GET_KEY();
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
entry.value = newValue;
|
||||
}
|
||||
return entry.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
#if TYPE_OBJECT
|
||||
validate(key);
|
||||
#endif
|
||||
Entry KEY_VALUE_GENERIC_TYPE entry = findNode(key);
|
||||
if(entry == null || VALUE_EQUALS(entry.value, getDefaultReturnValue())) return getDefaultReturnValue();
|
||||
if(entry == null) return getDefaultReturnValue();
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, entry.value);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
removeNode(entry);
|
||||
@@ -600,12 +543,8 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE MERGE(KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
#if TYPE_OBJECT
|
||||
validate(key);
|
||||
#endif
|
||||
Entry KEY_VALUE_GENERIC_TYPE entry = findNode(key);
|
||||
VALUE_TYPE newValue = entry == null || VALUE_EQUALS(entry.value, getDefaultReturnValue()) ? value : mappingFunction.APPLY_VALUE(entry.value, value);
|
||||
VALUE_TYPE newValue = entry == null ? value : mappingFunction.APPLY_VALUE(entry.value, value);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
if(entry != null)
|
||||
removeNode(entry);
|
||||
@@ -621,7 +560,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
for(MAP.Entry KEY_VALUE_GENERIC_TYPE entry : MAPS.fastIterable(m)) {
|
||||
KEY_TYPE key = entry.ENTRY_KEY();
|
||||
Entry KEY_VALUE_GENERIC_TYPE subEntry = findNode(key);
|
||||
VALUE_TYPE newValue = subEntry == null || VALUE_EQUALS(subEntry.value, getDefaultReturnValue()) ? entry.ENTRY_VALUE() : mappingFunction.APPLY_VALUE(subEntry.value, entry.ENTRY_VALUE());
|
||||
VALUE_TYPE newValue = subEntry == null ? entry.ENTRY_VALUE() : mappingFunction.APPLY_VALUE(subEntry.value, entry.ENTRY_VALUE());
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
if(subEntry != null)
|
||||
removeNode(subEntry);
|
||||
@@ -657,21 +596,6 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
return new KeyIterator(findNode(key));
|
||||
}
|
||||
|
||||
public AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE copy() {
|
||||
AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE set = new AVL_TREE_MAPKV_BRACES();
|
||||
set.size = size;
|
||||
if(tree != null) {
|
||||
set.tree = tree.copy();
|
||||
Entry KEY_VALUE_GENERIC_TYPE lastFound = null;
|
||||
for(Entry KEY_VALUE_GENERIC_TYPE entry = tree;entry != null;entry = entry.left) lastFound = entry;
|
||||
set.first = lastFound;
|
||||
lastFound = null;
|
||||
for(Entry KEY_VALUE_GENERIC_TYPE entry = tree;entry != null;entry = entry.right) lastFound = entry;
|
||||
set.last = lastFound;
|
||||
}
|
||||
return set;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SORTED_SET KEY_GENERIC_TYPE keySet() {
|
||||
return navigableKeySet();
|
||||
@@ -899,7 +823,6 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
}
|
||||
}
|
||||
|
||||
protected void validate(KEY_TYPE k) { compare(k, k); }
|
||||
protected int compare(KEY_TYPE k, KEY_TYPE v) { return comparator != null ? comparator.compare(k, v) : COMPAREABLE_TO_KEY(k, v);}
|
||||
|
||||
/** From CLR */
|
||||
@@ -1196,8 +1119,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
abstract AVL_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE next(AVL_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry);
|
||||
abstract AVL_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE previous(AVL_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry);
|
||||
|
||||
@Override
|
||||
public NavigableSubMap KEY_VALUE_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public abstract NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE descendingMap();
|
||||
@Override
|
||||
@@ -1531,21 +1453,8 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
@Deprecated
|
||||
public boolean contains(Object o) {
|
||||
if(o instanceof Map.Entry) {
|
||||
if(o instanceof MAP.Entry) {
|
||||
MAP.Entry KEY_VALUE_GENERIC_TYPE entry = (MAP.Entry KEY_VALUE_GENERIC_TYPE)o;
|
||||
if(entry.getKey() == null && comparator() == null) return false;
|
||||
AVL_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE subEntry = m.findNode(entry.ENTRY_KEY());
|
||||
if(subEntry != null) return VALUE_EQUALS(entry.ENTRY_VALUE(), subEntry.value);
|
||||
}
|
||||
else {
|
||||
Map.Entry<?, ?> entry = (Map.Entry<?, ?>)o;
|
||||
if(entry.getKey() == null && comparator() == null) return false;
|
||||
#if !TYPE_OBJECT
|
||||
if(!(entry.getKey() instanceof CLASS_TYPE)) return false;
|
||||
#endif
|
||||
AVL_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE subEntry = m.findNode((CLASS_TYPE)entry.getKey());
|
||||
if(subEntry != null) return Objects.equals(entry.getValue(), VALUE_TO_OBJ(subEntry.value));
|
||||
}
|
||||
if(o instanceof MAP.Entry) return NavigableSubMap.this.containsKey(((MAP.Entry KEY_VALUE_GENERIC_TYPE)o).ENTRY_KEY());
|
||||
return NavigableSubMap.this.containsKey(((Map.Entry<?, ?>)o).getKey());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -1578,10 +1487,10 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, ObjectObjectConsumer<E, MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
|
||||
public <E> void forEach(E input, ObjectObjectConsumer<MAP.Entry KEY_VALUE_GENERIC_TYPE, E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
for(AVL_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = findLowest(), last = findHighest();entry != null && (last == null || last != previous(entry));entry = next(entry))
|
||||
action.accept(input, new BasicEntryKV_BRACES(entry.key, entry.value));
|
||||
action.accept(new BasicEntryKV_BRACES(entry.key, entry.value), input);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1620,32 +1529,6 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> E reduce(E identity, BiFunction<E, MAP.Entry KEY_VALUE_GENERIC_TYPE, E> operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
E state = identity;
|
||||
for(AVL_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = findLowest(), last = findHighest();entry != null && (last == null || last != previous(entry));entry = next(entry)) {
|
||||
state = operator.apply(state, new BasicEntryKV_BRACES(entry.key, entry.value));
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE reduce(ObjectObjectUnaryOperator<MAP.Entry KEY_VALUE_GENERIC_TYPE, MAP.Entry KEY_VALUE_GENERIC_TYPE> operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
MAP.Entry KEY_VALUE_GENERIC_TYPE state = null;
|
||||
boolean empty = true;
|
||||
for(AVL_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = findLowest(), last = findHighest();entry != null && (last == null || last != previous(entry));entry = next(entry)) {
|
||||
if(empty) {
|
||||
empty = false;
|
||||
state = new BasicEntryKV_BRACES(entry.key, entry.value);
|
||||
continue;
|
||||
}
|
||||
state = operator.apply(state, new BasicEntryKV_BRACES(entry.key, entry.value));
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
@@ -1657,19 +1540,6 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return 0;
|
||||
int result = 0;
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE subEntry = new BasicEntryKV_BRACES();
|
||||
for(AVL_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = findLowest(), last = findHighest();entry != null && (last == null || last != previous(entry));entry = next(entry)) {
|
||||
subEntry.set(entry.key, entry.value);
|
||||
if(filter.getBoolean(subEntry)) result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
final class SubMapValues extends VALUE_ABSTRACT_COLLECTION VALUE_GENERIC_TYPE {
|
||||
@@ -1710,10 +1580,10 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
}
|
||||
|
||||
@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_OBJECT_CONSUMER VVS_GENERIC_TYPE<E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
for(AVL_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = findLowest(), last = findHighest();entry != null && (last == null || last != previous(entry));entry = next(entry))
|
||||
action.accept(input, entry.value);
|
||||
action.accept(entry.value, input);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1740,43 +1610,6 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
return true;
|
||||
}
|
||||
|
||||
#if !VALUE_OBJECT
|
||||
@Override
|
||||
public VALUE_TYPE reduce(VALUE_TYPE identity, VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
VALUE_TYPE state = identity;
|
||||
for(AVL_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = findLowest(), last = findHighest();entry != null && (last == null || last != previous(entry));entry = next(entry))
|
||||
state = operator.APPLY_VALUE(state, entry.value);
|
||||
return state;
|
||||
}
|
||||
|
||||
#else
|
||||
@Override
|
||||
public <VALUE_SPECIAL_TYPE> VALUE_SPECIAL_TYPE reduce(VALUE_SPECIAL_TYPE identity, BiFunction<VALUE_SPECIAL_TYPE, VALUE_TYPE, VALUE_SPECIAL_TYPE> operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
VALUE_SPECIAL_TYPE state = identity;
|
||||
for(AVL_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = findLowest(), last = findHighest();entry != null && (last == null || last != previous(entry));entry = next(entry))
|
||||
state = operator.apply(state, entry.value);
|
||||
return state;
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public VALUE_TYPE reduce(VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
VALUE_TYPE state = EMPTY_VALUE;
|
||||
boolean empty = true;
|
||||
for(AVL_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = findLowest(), last = findHighest();entry != null && (last == null || last != previous(entry));entry = next(entry)) {
|
||||
if(empty) {
|
||||
empty = false;
|
||||
state = entry.value;
|
||||
continue;
|
||||
}
|
||||
state = operator.APPLY_VALUE(state, entry.value);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
@@ -1784,15 +1617,6 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
if(filter.VALUE_TEST_VALUE(entry.value)) return entry.value;
|
||||
return EMPTY_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
int result = 0;
|
||||
for(AVL_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = findLowest(), last = findHighest();entry != null && (last == null || last != previous(entry));entry = next(entry))
|
||||
if(filter.VALUE_TEST_VALUE(entry.value)) result++;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
final class SubMapEntrySetIterator extends SubMapEntryIterator implements ObjectListIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> {
|
||||
@@ -1937,21 +1761,8 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
@Deprecated
|
||||
public boolean contains(Object o) {
|
||||
if(o instanceof Map.Entry) {
|
||||
if(o instanceof MAP.Entry) {
|
||||
MAP.Entry KEY_VALUE_GENERIC_TYPE entry = (MAP.Entry KEY_VALUE_GENERIC_TYPE)o;
|
||||
if(entry.getKey() == null && comparator() == null) return false;
|
||||
AVL_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE subEntry = AVL_TREE_MAP.this.findNode(entry.ENTRY_KEY());
|
||||
if(subEntry != null) return VALUE_EQUALS(entry.ENTRY_VALUE(), subEntry.value);
|
||||
}
|
||||
else {
|
||||
Map.Entry<?, ?> entry = (Map.Entry<?, ?>)o;
|
||||
if(entry.getKey() == null && comparator() == null) return false;
|
||||
#if !TYPE_OBJECT
|
||||
if(!(entry.getKey() instanceof CLASS_TYPE)) return false;
|
||||
#endif
|
||||
AVL_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE subEntry = AVL_TREE_MAP.this.findNode((CLASS_TYPE)entry.getKey());
|
||||
if(subEntry != null) return Objects.equals(entry.getValue(), VALUE_TO_OBJ(subEntry.value));
|
||||
}
|
||||
if(o instanceof MAP.Entry) return AVL_TREE_MAP.this.containsKey(((MAP.Entry KEY_VALUE_GENERIC_TYPE)o).ENTRY_KEY());
|
||||
return AVL_TREE_MAP.this.containsKey(((Map.Entry<?, ?>)o).getKey());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -1988,10 +1799,10 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, ObjectObjectConsumer<E, MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
|
||||
public <E> void forEach(E input, ObjectObjectConsumer<MAP.Entry KEY_VALUE_GENERIC_TYPE, E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
for(AVL_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = first;entry != null;entry = entry.next())
|
||||
action.accept(input, new BasicEntryKV_BRACES(entry.key, entry.value));
|
||||
action.accept(new BasicEntryKV_BRACES(entry.key, entry.value), input);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -2030,32 +1841,6 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> E reduce(E identity, BiFunction<E, MAP.Entry KEY_VALUE_GENERIC_TYPE, E> operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
E state = identity;
|
||||
for(AVL_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) {
|
||||
state = operator.apply(state, new BasicEntryKV_BRACES(entry.key, entry.value));
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE reduce(ObjectObjectUnaryOperator<MAP.Entry KEY_VALUE_GENERIC_TYPE, MAP.Entry KEY_VALUE_GENERIC_TYPE> operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
MAP.Entry KEY_VALUE_GENERIC_TYPE state = null;
|
||||
boolean empty = true;
|
||||
for(AVL_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) {
|
||||
if(empty) {
|
||||
empty = false;
|
||||
state = new BasicEntryKV_BRACES(entry.key, entry.value);
|
||||
continue;
|
||||
}
|
||||
state = operator.apply(state, new BasicEntryKV_BRACES(entry.key, entry.value));
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
@@ -2131,9 +1916,6 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public KeySet KEY_VALUE_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, boolean fromInclusive, KEY_TYPE toElement, boolean toInclusive) {
|
||||
return new KeySetKV_BRACES(m.subMap(fromElement, fromInclusive, toElement, toInclusive));
|
||||
@@ -2210,10 +1992,10 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
||||
public <E> void forEach(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE<E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
for(AVL_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = start(), end = end();entry != null && (end == null || (end != previous(entry)));entry = next(entry))
|
||||
action.accept(input, entry.key);
|
||||
action.accept(entry.key, input);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -2240,43 +2022,6 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
return true;
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public KEY_TYPE reduce(KEY_TYPE identity, SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = identity;
|
||||
for(AVL_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = start(), end = end();entry != null && (end == null || (end != previous(entry)));entry = next(entry))
|
||||
state = operator.APPLY_KEY_VALUE(state, entry.key);
|
||||
return state;
|
||||
}
|
||||
|
||||
#else
|
||||
@Override
|
||||
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_SPECIAL_TYPE state = identity;
|
||||
for(AVL_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = start(), end = end();entry != null && (end == null || (end != previous(entry)));entry = next(entry))
|
||||
state = operator.apply(state, entry.key);
|
||||
return state;
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public KEY_TYPE reduce(SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = EMPTY_KEY_VALUE;
|
||||
boolean empty = true;
|
||||
for(AVL_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = start(), end = end();entry != null && (end == null || (end != previous(entry)));entry = next(entry)) {
|
||||
if(empty) {
|
||||
empty = false;
|
||||
state = entry.key;
|
||||
continue;
|
||||
}
|
||||
state = operator.APPLY_KEY_VALUE(state, entry.key);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
@@ -2284,15 +2029,6 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
if(filter.TEST_VALUE(entry.key)) return entry.key;
|
||||
return EMPTY_KEY_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
int result = 0;
|
||||
for(AVL_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = start(), end = end();entry != null && (end == null || (end != previous(entry)));entry = next(entry))
|
||||
if(filter.TEST_VALUE(entry.key)) result++;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
final class Values extends VALUE_ABSTRACT_COLLECTION VALUE_GENERIC_TYPE {
|
||||
@@ -2334,10 +2070,10 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
}
|
||||
|
||||
@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_OBJECT_CONSUMER VVS_GENERIC_TYPE<E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
for(AVL_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = first;entry != null;entry = entry.next())
|
||||
action.accept(input, entry.value);
|
||||
action.accept(entry.value, input);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -2364,43 +2100,6 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
return true;
|
||||
}
|
||||
|
||||
#if !VALUE_OBJECT
|
||||
@Override
|
||||
public VALUE_TYPE reduce(VALUE_TYPE identity, VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
VALUE_TYPE state = identity;
|
||||
for(AVL_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = first;entry != null;entry = entry.next())
|
||||
state = operator.APPLY_VALUE(state, entry.value);
|
||||
return state;
|
||||
}
|
||||
|
||||
#else
|
||||
@Override
|
||||
public <VALUE_SPECIAL_TYPE> VALUE_SPECIAL_TYPE reduce(VALUE_SPECIAL_TYPE identity, BiFunction<VALUE_SPECIAL_TYPE, VALUE_TYPE, VALUE_SPECIAL_TYPE> operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
VALUE_SPECIAL_TYPE state = identity;
|
||||
for(AVL_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = first;entry != null;entry = entry.next())
|
||||
state = operator.apply(state, entry.value);
|
||||
return state;
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public VALUE_TYPE reduce(VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
VALUE_TYPE state = EMPTY_VALUE;
|
||||
boolean empty = true;
|
||||
for(AVL_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) {
|
||||
if(empty) {
|
||||
empty = false;
|
||||
state = entry.value;
|
||||
continue;
|
||||
}
|
||||
state = operator.APPLY_VALUE(state, entry.value);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
@@ -2408,15 +2107,6 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
if(filter.VALUE_TEST_VALUE(entry.value)) return entry.value;
|
||||
return EMPTY_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
int result = 0;
|
||||
for(AVL_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = first;entry != null;entry = entry.next())
|
||||
if(filter.VALUE_TEST_VALUE(entry.value)) result++;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
final class EntryIterator extends MapEntryIterator implements ObjectListIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> {
|
||||
@@ -2576,22 +2266,6 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
Entry KEY_VALUE_GENERIC_TYPE copy() {
|
||||
Entry KEY_VALUE_GENERIC_TYPE entry = new EntryKV_BRACES(key, value, null);
|
||||
entry.state = state;
|
||||
if(left != null) {
|
||||
Entry KEY_VALUE_GENERIC_TYPE newLeft = left.copy();
|
||||
entry.left = newLeft;
|
||||
newLeft.parent = entry;
|
||||
}
|
||||
if(right != null) {
|
||||
Entry KEY_VALUE_GENERIC_TYPE newRight = right.copy();
|
||||
entry.right = newRight;
|
||||
newRight.parent = entry;
|
||||
}
|
||||
return entry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE ENTRY_KEY() {
|
||||
return key;
|
||||
@@ -2617,43 +2291,6 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(obj instanceof Map.Entry) {
|
||||
if(obj instanceof MAP.Entry) {
|
||||
MAP.Entry KEY_VALUE_GENERIC_TYPE entry = (MAP.Entry KEY_VALUE_GENERIC_TYPE)obj;
|
||||
#if TYPE_OBJECT
|
||||
if(entry.ENTRY_KEY() == null) return false;
|
||||
#endif
|
||||
return KEY_EQUALS(key, entry.ENTRY_KEY()) && VALUE_EQUALS(value, entry.ENTRY_VALUE());
|
||||
}
|
||||
Map.Entry<?, ?> entry = (Map.Entry<?, ?>)obj;
|
||||
Object otherKey = entry.getKey();
|
||||
if(otherKey == null) return false;
|
||||
Object otherValue = entry.getValue();
|
||||
#if TYPE_OBJECT && VALUE_OBJECT
|
||||
return KEY_EQUALS(key, otherKey) && VALUE_EQUALS(value, otherValue);
|
||||
#else if TYPE_OBJECT
|
||||
return otherValue instanceof CLASS_VALUE_TYPE && KEY_EQUALS(key, otherKey) && VALUE_EQUALS(value, CLASS_TO_VALUE(otherValue));
|
||||
#else if VALUE_OBJECT
|
||||
return otherKey instanceof CLASS_TYPE && KEY_EQUALS(key, CLASS_TO_KEY(otherKey)) && VALUE_EQUALS(value, otherValue);
|
||||
#else
|
||||
return otherKey instanceof CLASS_TYPE && otherValue instanceof CLASS_VALUE_TYPE && KEY_EQUALS(key, CLASS_TO_KEY(otherKey)) && VALUE_EQUALS(value, CLASS_TO_VALUE(otherValue));
|
||||
#endif
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return KEY_TO_HASH(key) ^ VALUE_TO_HASH(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return KEY_TO_STRING(key) + "=" + VALUE_TO_STRING(value);
|
||||
}
|
||||
|
||||
int getHeight() { return state; }
|
||||
|
||||
void updateHeight() { state = (1 + Math.max(left == null ? -1 : left.getHeight(), right == null ? -1 : right.getHeight())); }
|
||||
|
||||
+21
-399
@@ -7,13 +7,14 @@ import java.util.Comparator;
|
||||
import java.util.Objects;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||
#endif
|
||||
#if !TYPE_OBJECT && !VALUE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.functions.consumer.BI_OBJECT_CONSUMER;
|
||||
#endif
|
||||
#if !TYPE_OBJECT && !VALUE_BOOLEAN
|
||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||
@@ -21,9 +22,6 @@ import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||
import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
|
||||
import speiger.src.collections.PACKAGE.functions.function.FUNCTION;
|
||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||
#if !SAME_TYPE
|
||||
import speiger.src.collections.PACKAGE.functions.function.SINGLE_UNARY_OPERATOR;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.maps.abstracts.ABSTRACT_MAP;
|
||||
import speiger.src.collections.PACKAGE.maps.interfaces.MAP;
|
||||
@@ -37,7 +35,6 @@ import speiger.src.collections.PACKAGE.utils.maps.MAPS;
|
||||
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_ITERATOR;
|
||||
import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_SUPPLIER;
|
||||
#if !SAME_TYPE
|
||||
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_UNARY_OPERATOR;
|
||||
import speiger.src.collections.VALUE_PACKAGE.lists.VALUE_LIST_ITERATOR;
|
||||
@@ -55,10 +52,7 @@ import speiger.src.collections.objects.functions.function.Object2BooleanFunction
|
||||
#endif
|
||||
#endif
|
||||
#if !SAME_TYPE
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.objects.functions.consumer.VALUE_BI_FROM_OBJECT_CONSUMER;
|
||||
|
||||
#endif
|
||||
import speiger.src.collections.VALUE_PACKAGE.functions.consumer.VALUE_BI_OBJECT_CONSUMER;
|
||||
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE;
|
||||
#endif
|
||||
#if !TYPE_OBJECT && !VALUE_OBJECT
|
||||
@@ -69,10 +63,6 @@ import speiger.src.collections.objects.utils.ObjectIterators;
|
||||
import speiger.src.collections.objects.collections.ObjectIterator;
|
||||
#endif
|
||||
#if !TYPE_OBJECT
|
||||
#if !VALUE_OBJECT
|
||||
import speiger.src.collections.objects.functions.function.ObjectObjectUnaryOperator;
|
||||
|
||||
#endif
|
||||
import speiger.src.collections.objects.sets.AbstractObjectSet;
|
||||
import speiger.src.collections.objects.sets.ObjectSet;
|
||||
#endif
|
||||
@@ -233,9 +223,6 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
#endif
|
||||
@Override
|
||||
public VALUE_TYPE put(KEY_TYPE key, VALUE_TYPE value) {
|
||||
#if TYPE_OBJECT
|
||||
validate(key);
|
||||
#endif
|
||||
if(tree == null) {
|
||||
tree = first = last = new EntryKV_BRACES(key, value, null);
|
||||
size++;
|
||||
@@ -270,10 +257,6 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE putIfAbsent(KEY_TYPE key, VALUE_TYPE value) {
|
||||
#if TYPE_OBJECT
|
||||
validate(key);
|
||||
#endif
|
||||
|
||||
if(tree == null) {
|
||||
tree = first = last = new EntryKV_BRACES(key, value, null);
|
||||
size++;
|
||||
@@ -309,9 +292,6 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
#if VALUE_PRIMITIVES
|
||||
@Override
|
||||
public VALUE_TYPE addTo(KEY_TYPE key, VALUE_TYPE value) {
|
||||
#if TYPE_OBJECT
|
||||
validate(key);
|
||||
#endif
|
||||
if(tree == null) {
|
||||
tree = first = last = new EntryKV_BRACES(key, value, null);
|
||||
size++;
|
||||
@@ -519,10 +499,6 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
#if TYPE_OBJECT
|
||||
validate(key);
|
||||
#endif
|
||||
Entry KEY_VALUE_GENERIC_TYPE entry = findNode(key);
|
||||
if(entry == null) {
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, getDefaultReturnValue());
|
||||
@@ -541,10 +517,6 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_ABSENT(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
#if TYPE_OBJECT
|
||||
validate(key);
|
||||
#endif
|
||||
Entry KEY_VALUE_GENERIC_TYPE entry = findNode(key);
|
||||
if(entry == null) {
|
||||
VALUE_TYPE newValue = mappingFunction.GET_VALUE(key);
|
||||
@@ -552,43 +524,13 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
put(key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
if(VALUE_EQUALS(entry.value, getDefaultReturnValue())) {
|
||||
VALUE_TYPE newValue = mappingFunction.GET_VALUE(key);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
entry.value = newValue;
|
||||
}
|
||||
return entry.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENT(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
|
||||
Objects.requireNonNull(valueProvider);
|
||||
#if TYPE_OBJECT
|
||||
validate(key);
|
||||
#endif
|
||||
Entry KEY_VALUE_GENERIC_TYPE entry = findNode(key);
|
||||
if(entry == null) {
|
||||
VALUE_TYPE newValue = valueProvider.VALUE_GET_KEY();
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
put(key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
if(VALUE_EQUALS(entry.value, getDefaultReturnValue())) {
|
||||
VALUE_TYPE newValue = valueProvider.VALUE_GET_KEY();
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
entry.value = newValue;
|
||||
}
|
||||
return entry.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
#if TYPE_OBJECT
|
||||
validate(key);
|
||||
#endif
|
||||
Entry KEY_VALUE_GENERIC_TYPE entry = findNode(key);
|
||||
if(entry == null || VALUE_EQUALS(entry.value, getDefaultReturnValue())) return getDefaultReturnValue();
|
||||
if(entry == null) return getDefaultReturnValue();
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, entry.value);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
removeNode(entry);
|
||||
@@ -600,12 +542,8 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE MERGE(KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
#if TYPE_OBJECT
|
||||
validate(key);
|
||||
#endif
|
||||
Entry KEY_VALUE_GENERIC_TYPE entry = findNode(key);
|
||||
VALUE_TYPE newValue = entry == null || VALUE_EQUALS(entry.value, getDefaultReturnValue()) ? value : mappingFunction.APPLY_VALUE(entry.value, value);
|
||||
VALUE_TYPE newValue = entry == null ? value : mappingFunction.APPLY_VALUE(entry.value, value);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
if(entry != null)
|
||||
removeNode(entry);
|
||||
@@ -621,7 +559,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
for(MAP.Entry KEY_VALUE_GENERIC_TYPE entry : MAPS.fastIterable(m)) {
|
||||
KEY_TYPE key = entry.ENTRY_KEY();
|
||||
Entry KEY_VALUE_GENERIC_TYPE subEntry = findNode(key);
|
||||
VALUE_TYPE newValue = subEntry == null || VALUE_EQUALS(subEntry.value, getDefaultReturnValue()) ? entry.ENTRY_VALUE() : mappingFunction.APPLY_VALUE(subEntry.value, entry.ENTRY_VALUE());
|
||||
VALUE_TYPE newValue = subEntry == null ? entry.ENTRY_VALUE() : mappingFunction.APPLY_VALUE(subEntry.value, entry.ENTRY_VALUE());
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
if(subEntry != null)
|
||||
removeNode(subEntry);
|
||||
@@ -657,21 +595,6 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
return new KeyIterator(findNode(key));
|
||||
}
|
||||
|
||||
public RB_TREE_MAP KEY_VALUE_GENERIC_TYPE copy() {
|
||||
RB_TREE_MAP KEY_VALUE_GENERIC_TYPE set = new RB_TREE_MAPKV_BRACES();
|
||||
set.size = size;
|
||||
if(tree != null) {
|
||||
set.tree = tree.copy();
|
||||
Entry KEY_VALUE_GENERIC_TYPE lastFound = null;
|
||||
for(Entry KEY_VALUE_GENERIC_TYPE entry = tree;entry != null;entry = entry.left) lastFound = entry;
|
||||
set.first = lastFound;
|
||||
lastFound = null;
|
||||
for(Entry KEY_VALUE_GENERIC_TYPE entry = tree;entry != null;entry = entry.right) lastFound = entry;
|
||||
set.last = lastFound;
|
||||
}
|
||||
return set;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SORTED_SET KEY_GENERIC_TYPE keySet() {
|
||||
return navigableKeySet();
|
||||
@@ -905,7 +828,6 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
}
|
||||
}
|
||||
|
||||
protected void validate(KEY_TYPE k) { compare(k, k); }
|
||||
protected int compare(KEY_TYPE k, KEY_TYPE v) { return comparator != null ? comparator.compare(k, v) : COMPAREABLE_TO_KEY(k, v);}
|
||||
protected static GENERIC_KEY_VALUE_BRACES boolean isBlack(Entry KEY_VALUE_GENERIC_TYPE p) { return p == null || p.isBlack(); }
|
||||
protected static GENERIC_KEY_VALUE_BRACES Entry KEY_VALUE_GENERIC_TYPE parentOf(Entry KEY_VALUE_GENERIC_TYPE p) { return (p == null ? null : p.parent); }
|
||||
@@ -1251,8 +1173,6 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
abstract RB_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE next(RB_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry);
|
||||
abstract RB_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE previous(RB_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry);
|
||||
|
||||
@Override
|
||||
public NavigableSubMap KEY_VALUE_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public abstract NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE descendingMap();
|
||||
@Override
|
||||
@@ -1586,21 +1506,8 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
@Deprecated
|
||||
public boolean contains(Object o) {
|
||||
if(o instanceof Map.Entry) {
|
||||
if(o instanceof MAP.Entry) {
|
||||
MAP.Entry KEY_VALUE_GENERIC_TYPE entry = (MAP.Entry KEY_VALUE_GENERIC_TYPE)o;
|
||||
if(entry.getKey() == null && comparator() == null) return false;
|
||||
RB_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE subEntry = m.findNode(entry.ENTRY_KEY());
|
||||
if(subEntry != null) return VALUE_EQUALS(entry.ENTRY_VALUE(), subEntry.value);
|
||||
}
|
||||
else {
|
||||
Map.Entry<?, ?> entry = (Map.Entry<?, ?>)o;
|
||||
if(entry.getKey() == null && comparator() == null) return false;
|
||||
#if !TYPE_OBJECT
|
||||
if(!(entry.getKey() instanceof CLASS_TYPE)) return false;
|
||||
#endif
|
||||
RB_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE subEntry = m.findNode((CLASS_TYPE)entry.getKey());
|
||||
if(subEntry != null) return Objects.equals(entry.getValue(), VALUE_TO_OBJ(subEntry.value));
|
||||
}
|
||||
if(o instanceof MAP.Entry) return NavigableSubMap.this.containsKey(((MAP.Entry KEY_VALUE_GENERIC_TYPE)o).ENTRY_KEY());
|
||||
return NavigableSubMap.this.containsKey(((Map.Entry<?, ?>)o).getKey());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -1633,10 +1540,10 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, ObjectObjectConsumer<E, MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
|
||||
public <E> void forEach(E input, ObjectObjectConsumer<MAP.Entry KEY_VALUE_GENERIC_TYPE, E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
for(RB_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = findLowest(), last = findHighest();entry != null && (last == null || last != previous(entry));entry = next(entry))
|
||||
action.accept(input, new BasicEntryKV_BRACES(entry.key, entry.value));
|
||||
action.accept(new BasicEntryKV_BRACES(entry.key, entry.value), input);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1675,32 +1582,6 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> E reduce(E identity, BiFunction<E, MAP.Entry KEY_VALUE_GENERIC_TYPE, E> operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
E state = identity;
|
||||
for(RB_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = findLowest(), last = findHighest();entry != null && (last == null || last != previous(entry));entry = next(entry)) {
|
||||
state = operator.apply(state, new BasicEntryKV_BRACES(entry.key, entry.value));
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE reduce(ObjectObjectUnaryOperator<MAP.Entry KEY_VALUE_GENERIC_TYPE, MAP.Entry KEY_VALUE_GENERIC_TYPE> operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
MAP.Entry KEY_VALUE_GENERIC_TYPE state = null;
|
||||
boolean empty = true;
|
||||
for(RB_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = findLowest(), last = findHighest();entry != null && (last == null || last != previous(entry));entry = next(entry)) {
|
||||
if(empty) {
|
||||
empty = false;
|
||||
state = new BasicEntryKV_BRACES(entry.key, entry.value);
|
||||
continue;
|
||||
}
|
||||
state = operator.apply(state, new BasicEntryKV_BRACES(entry.key, entry.value));
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
@@ -1712,19 +1593,6 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return 0;
|
||||
int result = 0;
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE subEntry = new BasicEntryKV_BRACES();
|
||||
for(RB_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = findLowest(), last = findHighest();entry != null && (last == null || last != previous(entry));entry = next(entry)) {
|
||||
subEntry.set(entry.key, entry.value);
|
||||
if(filter.getBoolean(subEntry)) result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
final class SubMapValues extends VALUE_ABSTRACT_COLLECTION VALUE_GENERIC_TYPE {
|
||||
@@ -1765,10 +1633,10 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
}
|
||||
|
||||
@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_OBJECT_CONSUMER VVS_GENERIC_TYPE<E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
for(RB_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = findLowest(), last = findHighest();entry != null && (last == null || last != previous(entry));entry = next(entry))
|
||||
action.accept(input, entry.value);
|
||||
action.accept(entry.value, input);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1795,43 +1663,6 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
return true;
|
||||
}
|
||||
|
||||
#if !VALUE_OBJECT
|
||||
@Override
|
||||
public VALUE_TYPE reduce(VALUE_TYPE identity, VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
VALUE_TYPE state = identity;
|
||||
for(RB_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = findLowest(), last = findHighest();entry != null && (last == null || last != previous(entry));entry = next(entry))
|
||||
state = operator.APPLY_VALUE(state, entry.value);
|
||||
return state;
|
||||
}
|
||||
|
||||
#else
|
||||
@Override
|
||||
public <VALUE_SPECIAL_TYPE> VALUE_SPECIAL_TYPE reduce(VALUE_SPECIAL_TYPE identity, BiFunction<VALUE_SPECIAL_TYPE, VALUE_TYPE, VALUE_SPECIAL_TYPE> operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
VALUE_SPECIAL_TYPE state = identity;
|
||||
for(RB_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = findLowest(), last = findHighest();entry != null && (last == null || last != previous(entry));entry = next(entry))
|
||||
state = operator.apply(state, entry.value);
|
||||
return state;
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public VALUE_TYPE reduce(VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
VALUE_TYPE state = EMPTY_VALUE;
|
||||
boolean empty = true;
|
||||
for(RB_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = findLowest(), last = findHighest();entry != null && (last == null || last != previous(entry));entry = next(entry)) {
|
||||
if(empty) {
|
||||
empty = false;
|
||||
state = entry.value;
|
||||
continue;
|
||||
}
|
||||
state = operator.APPLY_VALUE(state, entry.value);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
@@ -1839,15 +1670,6 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
if(filter.VALUE_TEST_VALUE(entry.value)) return entry.value;
|
||||
return EMPTY_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
int result = 0;
|
||||
for(RB_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = findLowest(), last = findHighest();entry != null && (last == null || last != previous(entry));entry = next(entry))
|
||||
if(filter.VALUE_TEST_VALUE(entry.value)) result++;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
final class SubMapEntrySetIterator extends SubMapEntryIterator implements ObjectListIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> {
|
||||
@@ -1992,21 +1814,8 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
@Deprecated
|
||||
public boolean contains(Object o) {
|
||||
if(o instanceof Map.Entry) {
|
||||
if(o instanceof MAP.Entry) {
|
||||
MAP.Entry KEY_VALUE_GENERIC_TYPE entry = (MAP.Entry KEY_VALUE_GENERIC_TYPE)o;
|
||||
if(entry.getKey() == null && comparator() == null) return false;
|
||||
RB_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE subEntry = RB_TREE_MAP.this.findNode(entry.ENTRY_KEY());
|
||||
if(subEntry != null) return VALUE_EQUALS(entry.ENTRY_VALUE(), subEntry.value);
|
||||
}
|
||||
else {
|
||||
Map.Entry<?, ?> entry = (Map.Entry<?, ?>)o;
|
||||
if(entry.getKey() == null && comparator() == null) return false;
|
||||
#if !TYPE_OBJECT
|
||||
if(!(entry.getKey() instanceof CLASS_TYPE)) return false;
|
||||
#endif
|
||||
RB_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE subEntry = RB_TREE_MAP.this.findNode((CLASS_TYPE)entry.getKey());
|
||||
if(subEntry != null) return Objects.equals(entry.getValue(), VALUE_TO_OBJ(subEntry.value));
|
||||
}
|
||||
if(o instanceof MAP.Entry) return RB_TREE_MAP.this.containsKey(((MAP.Entry KEY_VALUE_GENERIC_TYPE)o).ENTRY_KEY());
|
||||
return RB_TREE_MAP.this.containsKey(((Map.Entry<?, ?>)o).getKey());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -2043,10 +1852,10 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, ObjectObjectConsumer<E, MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
|
||||
public <E> void forEach(E input, ObjectObjectConsumer<MAP.Entry KEY_VALUE_GENERIC_TYPE, E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
for(RB_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = first;entry != null;entry = entry.next())
|
||||
action.accept(input, new BasicEntryKV_BRACES(entry.key, entry.value));
|
||||
action.accept(new BasicEntryKV_BRACES(entry.key, entry.value), input);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -2085,32 +1894,6 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> E reduce(E identity, BiFunction<E, MAP.Entry KEY_VALUE_GENERIC_TYPE, E> operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
E state = identity;
|
||||
for(RB_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) {
|
||||
state = operator.apply(state, new BasicEntryKV_BRACES(entry.key, entry.value));
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE reduce(ObjectObjectUnaryOperator<MAP.Entry KEY_VALUE_GENERIC_TYPE, MAP.Entry KEY_VALUE_GENERIC_TYPE> operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
MAP.Entry KEY_VALUE_GENERIC_TYPE state = null;
|
||||
boolean empty = true;
|
||||
for(RB_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) {
|
||||
if(empty) {
|
||||
empty = false;
|
||||
state = new BasicEntryKV_BRACES(entry.key, entry.value);
|
||||
continue;
|
||||
}
|
||||
state = operator.apply(state, new BasicEntryKV_BRACES(entry.key, entry.value));
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
@@ -2122,19 +1905,6 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return 0;
|
||||
int result = 0;
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE subEntry = new BasicEntryKV_BRACES();
|
||||
for(RB_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) {
|
||||
subEntry.set(entry.key, entry.value);
|
||||
if(filter.getBoolean(subEntry)) result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
static final class KeySet KEY_VALUE_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE implements NAVIGABLE_SET KEY_GENERIC_TYPE {
|
||||
@@ -2199,9 +1969,6 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public KeySet KEY_VALUE_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, boolean fromInclusive, KEY_TYPE toElement, boolean toInclusive) {
|
||||
return new KeySetKV_BRACES(m.subMap(fromElement, fromInclusive, toElement, toInclusive));
|
||||
@@ -2278,10 +2045,10 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
||||
public <E> void forEach(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE<E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
for(RB_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = start(), end = end();entry != null && (end == null || (end != previous(entry)));entry = next(entry))
|
||||
action.accept(input, entry.key);
|
||||
action.accept(entry.key, input);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -2308,43 +2075,6 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
return true;
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public KEY_TYPE reduce(KEY_TYPE identity, SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = identity;
|
||||
for(RB_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = start(), end = end();entry != null && (end == null || (end != previous(entry)));entry = next(entry))
|
||||
state = operator.APPLY_KEY_VALUE(state, entry.key);
|
||||
return state;
|
||||
}
|
||||
|
||||
#else
|
||||
@Override
|
||||
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_SPECIAL_TYPE state = identity;
|
||||
for(RB_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = start(), end = end();entry != null && (end == null || (end != previous(entry)));entry = next(entry))
|
||||
state = operator.apply(state, entry.key);
|
||||
return state;
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public KEY_TYPE reduce(SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = EMPTY_KEY_VALUE;
|
||||
boolean empty = true;
|
||||
for(RB_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = start(), end = end();entry != null && (end == null || (end != previous(entry)));entry = next(entry)) {
|
||||
if(empty) {
|
||||
empty = false;
|
||||
state = entry.key;
|
||||
continue;
|
||||
}
|
||||
state = operator.APPLY_KEY_VALUE(state, entry.key);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
@@ -2352,15 +2082,6 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
if(filter.TEST_VALUE(entry.key)) return entry.key;
|
||||
return EMPTY_KEY_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
int result = 0;
|
||||
for(RB_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = start(), end = end();entry != null && (end == null || (end != previous(entry)));entry = next(entry))
|
||||
if(filter.TEST_VALUE(entry.key)) result++;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
final class Values extends VALUE_ABSTRACT_COLLECTION VALUE_GENERIC_TYPE {
|
||||
@@ -2402,10 +2123,10 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
}
|
||||
|
||||
@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_OBJECT_CONSUMER VVS_GENERIC_TYPE<E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
for(RB_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = first;entry != null;entry = entry.next())
|
||||
action.accept(input, entry.value);
|
||||
action.accept(entry.value, input);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -2432,43 +2153,6 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
return true;
|
||||
}
|
||||
|
||||
#if !VALUE_OBJECT
|
||||
@Override
|
||||
public VALUE_TYPE reduce(VALUE_TYPE identity, VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
VALUE_TYPE state = identity;
|
||||
for(RB_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = first;entry != null;entry = entry.next())
|
||||
state = operator.APPLY_VALUE(state, entry.value);
|
||||
return state;
|
||||
}
|
||||
|
||||
#else
|
||||
@Override
|
||||
public <VALUE_SPECIAL_TYPE> VALUE_SPECIAL_TYPE reduce(VALUE_SPECIAL_TYPE identity, BiFunction<VALUE_SPECIAL_TYPE, VALUE_TYPE, VALUE_SPECIAL_TYPE> operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
VALUE_SPECIAL_TYPE state = identity;
|
||||
for(RB_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = first;entry != null;entry = entry.next())
|
||||
state = operator.apply(state, entry.value);
|
||||
return state;
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public VALUE_TYPE reduce(VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
VALUE_TYPE state = EMPTY_VALUE;
|
||||
boolean empty = true;
|
||||
for(RB_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) {
|
||||
if(empty) {
|
||||
empty = false;
|
||||
state = entry.value;
|
||||
continue;
|
||||
}
|
||||
state = operator.APPLY_VALUE(state, entry.value);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
@@ -2476,15 +2160,6 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
if(filter.VALUE_TEST_VALUE(entry.value)) return entry.value;
|
||||
return EMPTY_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
int result = 0;
|
||||
for(RB_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = first;entry != null;entry = entry.next())
|
||||
if(filter.VALUE_TEST_VALUE(entry.value)) result++;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
final class EntryIterator extends MapEntryIterator implements ObjectListIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> {
|
||||
@@ -2646,22 +2321,6 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
Entry KEY_VALUE_GENERIC_TYPE copy() {
|
||||
Entry KEY_VALUE_GENERIC_TYPE entry = new EntryKV_BRACES(key, value, null);
|
||||
entry.state = state;
|
||||
if(left != null) {
|
||||
Entry KEY_VALUE_GENERIC_TYPE newLeft = left.copy();
|
||||
entry.left = newLeft;
|
||||
newLeft.parent = entry;
|
||||
}
|
||||
if(right != null) {
|
||||
Entry KEY_VALUE_GENERIC_TYPE newRight = right.copy();
|
||||
entry.right = newRight;
|
||||
newRight.parent = entry;
|
||||
}
|
||||
return entry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE ENTRY_KEY() {
|
||||
return key;
|
||||
@@ -2687,43 +2346,6 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(obj instanceof Map.Entry) {
|
||||
if(obj instanceof MAP.Entry) {
|
||||
MAP.Entry KEY_VALUE_GENERIC_TYPE entry = (MAP.Entry KEY_VALUE_GENERIC_TYPE)obj;
|
||||
#if TYPE_OBJECT
|
||||
if(entry.ENTRY_KEY() == null) return false;
|
||||
#endif
|
||||
return KEY_EQUALS(key, entry.ENTRY_KEY()) && VALUE_EQUALS(value, entry.ENTRY_VALUE());
|
||||
}
|
||||
Map.Entry<?, ?> entry = (Map.Entry<?, ?>)obj;
|
||||
Object otherKey = entry.getKey();
|
||||
if(otherKey == null) return false;
|
||||
Object otherValue = entry.getValue();
|
||||
#if TYPE_OBJECT && VALUE_OBJECT
|
||||
return KEY_EQUALS(key, otherKey) && VALUE_EQUALS(value, otherValue);
|
||||
#else if TYPE_OBJECT
|
||||
return otherValue instanceof CLASS_VALUE_TYPE && KEY_EQUALS(key, otherKey) && VALUE_EQUALS(value, CLASS_TO_VALUE(otherValue));
|
||||
#else if VALUE_OBJECT
|
||||
return otherKey instanceof CLASS_TYPE && KEY_EQUALS(key, CLASS_TO_KEY(otherKey)) && VALUE_EQUALS(value, otherValue);
|
||||
#else
|
||||
return otherKey instanceof CLASS_TYPE && otherValue instanceof CLASS_VALUE_TYPE && KEY_EQUALS(key, CLASS_TO_KEY(otherKey)) && VALUE_EQUALS(value, CLASS_TO_VALUE(otherValue));
|
||||
#endif
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return KEY_TO_HASH(key) ^ VALUE_TO_HASH(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return KEY_TO_STRING(key) + "=" + VALUE_TO_STRING(value);
|
||||
}
|
||||
|
||||
boolean isBlack() {
|
||||
return (state & BLACK) != 0;
|
||||
}
|
||||
|
||||
+55
-618
File diff suppressed because it is too large
Load Diff
-25
@@ -2,7 +2,6 @@ package speiger.src.collections.PACKAGE.maps.interfaces;
|
||||
|
||||
import java.util.NavigableMap;
|
||||
import speiger.src.collections.PACKAGE.sets.NAVIGABLE_SET;
|
||||
import speiger.src.collections.PACKAGE.utils.maps.MAPS;
|
||||
|
||||
/**
|
||||
* A Type Specific Navigable Map interface with a couple helper methods
|
||||
@@ -11,8 +10,6 @@ import speiger.src.collections.PACKAGE.utils.maps.MAPS;
|
||||
*/
|
||||
public interface NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE extends SORTED_MAP KEY_VALUE_GENERIC_TYPE, NavigableMap<CLASS_TYPE, CLASS_VALUE_TYPE>
|
||||
{
|
||||
@Override
|
||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE copy();
|
||||
/** @return a Type Specific desendingMap */
|
||||
@Override
|
||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE descendingMap();
|
||||
@@ -35,28 +32,6 @@ public interface NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE extends SORTED_MAP KEY_VAL
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollLastEntry();
|
||||
|
||||
/**
|
||||
* Creates a Wrapped NavigableMap that is Synchronized
|
||||
* @return a new NavigableMap that is synchronized
|
||||
* @see MAPS#synchronize
|
||||
*/
|
||||
public default NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE synchronize() { return MAPS.synchronize(this); }
|
||||
|
||||
/**
|
||||
* Creates a Wrapped NavigableMap that is Synchronized
|
||||
* @param mutex is the controller of the synchronization block
|
||||
* @return a new NavigableMap Wrapper that is synchronized
|
||||
* @see MAPS#synchronize
|
||||
*/
|
||||
public default NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE synchronize(Object mutex) { return MAPS.synchronize(this, mutex); }
|
||||
|
||||
/**
|
||||
* Creates a Wrapped NavigableMap that is unmodifiable
|
||||
* @return a new NavigableMap Wrapper that is unmodifiable
|
||||
* @see MAPS#unmodifiable
|
||||
*/
|
||||
public default NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE unmodifiable() { return MAPS.unmodifiable(this); }
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
/**
|
||||
* A Type Specific SubMap method to reduce boxing/unboxing
|
||||
|
||||
-26
@@ -10,7 +10,6 @@ import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_COLLECTION;
|
||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.sets.SET;
|
||||
import speiger.src.collections.PACKAGE.utils.maps.MAPS;
|
||||
import speiger.src.collections.objects.sets.ObjectSortedSet;
|
||||
import speiger.src.collections.objects.collections.ObjectBidirectionalIterator;
|
||||
|
||||
@@ -76,36 +75,11 @@ public interface SORTED_MAP KEY_VALUE_GENERIC_TYPE extends SortedMap<CLASS_TYPE,
|
||||
@Override
|
||||
public COMPARATOR KEY_GENERIC_TYPE comparator();
|
||||
|
||||
@Override
|
||||
public SORTED_MAP KEY_VALUE_GENERIC_TYPE copy();
|
||||
|
||||
@Override
|
||||
public SET KEY_GENERIC_TYPE keySet();
|
||||
@Override
|
||||
public VALUE_COLLECTION VALUE_GENERIC_TYPE values();
|
||||
|
||||
/**
|
||||
* Creates a Wrapped SortedMap that is Synchronized
|
||||
* @return a new SortedMap that is synchronized
|
||||
* @see MAPS#synchronize
|
||||
*/
|
||||
public default SORTED_MAP KEY_VALUE_GENERIC_TYPE synchronize() { return MAPS.synchronize(this); }
|
||||
|
||||
/**
|
||||
* Creates a Wrapped SortedMap that is Synchronized
|
||||
* @param mutex is the controller of the synchronization block
|
||||
* @return a new SortedMap Wrapper that is synchronized
|
||||
* @see MAPS#synchronize
|
||||
*/
|
||||
public default SORTED_MAP KEY_VALUE_GENERIC_TYPE synchronize(Object mutex) { return MAPS.synchronize(this, mutex); }
|
||||
|
||||
/**
|
||||
* Creates a Wrapped SortedMap that is unmodifiable
|
||||
* @return a new SortedMap Wrapper that is unmodifiable
|
||||
* @see MAPS#unmodifiable
|
||||
*/
|
||||
public default SORTED_MAP KEY_VALUE_GENERIC_TYPE unmodifiable() { return MAPS.unmodifiable(this); }
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
/**
|
||||
* A Type Specific SubMap method to reduce boxing/unboxing
|
||||
|
||||
-46
@@ -1,46 +0,0 @@
|
||||
package speiger.src.collections.PACKAGE.queues;
|
||||
|
||||
#if TYPE_OBJECT
|
||||
import java.util.Objects;
|
||||
#endif
|
||||
import java.util.StringJoiner;
|
||||
|
||||
/**
|
||||
* Helper class that implements all the essential methods for the PriorityQueues
|
||||
* @Type(T)
|
||||
*/
|
||||
public abstract class ABSTRACT_PRIORITY_QUEUE KEY_GENERIC_TYPE implements PRIORITY_QUEUE KEY_GENERIC_TYPE
|
||||
{
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(obj instanceof PRIORITY_QUEUE) {
|
||||
PRIORITY_QUEUE KEY_GENERIC_TYPE queue = (PRIORITY_QUEUE KEY_GENERIC_TYPE)obj;
|
||||
if(queue.size() != size()) return false;
|
||||
for(int i = 0,m=size();i<m;i++) {
|
||||
if(KEY_EQUALS_NOT(queue.peek(i), peek(i))) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = 1;
|
||||
for (int i = 0,m=size();i<m;i++) {
|
||||
result = 31 * result + KEY_TO_HASH(peek(i));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
if(isEmpty()) return "[]";
|
||||
StringJoiner joiner = new StringJoiner(", ", "[", "]");
|
||||
for (int i = 0,m=size();i<m;i++) {
|
||||
joiner.add(KEY_TO_STRING(peek(i)));
|
||||
}
|
||||
return joiner.toString();
|
||||
}
|
||||
}
|
||||
+10
-76
@@ -1,10 +1,9 @@
|
||||
package speiger.src.collections.PACKAGE.queues;
|
||||
|
||||
import java.util.Arrays;
|
||||
#if TYPE_OBJECT
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.BiFunction;
|
||||
#endif
|
||||
import java.util.Objects;
|
||||
import java.util.NoSuchElementException;
|
||||
@@ -14,9 +13,8 @@ import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
#endif
|
||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||
import speiger.src.collections.PACKAGE.functions.consumer.BI_OBJECT_CONSUMER;
|
||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||
import speiger.src.collections.utils.ITrimmable;
|
||||
|
||||
/**
|
||||
@@ -24,7 +22,7 @@ import speiger.src.collections.utils.ITrimmable;
|
||||
* Its specific implementation uses a backing array that grows and shrinks as it is needed.
|
||||
* @Type(T)
|
||||
*/
|
||||
public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEUE KEY_GENERIC_TYPE implements PRIORITY_DEQUEUE KEY_GENERIC_TYPE, ITrimmable
|
||||
public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE implements PRIORITY_DEQUEUE KEY_GENERIC_TYPE, ITrimmable
|
||||
{
|
||||
/** Max Possible ArraySize without the JVM Crashing */
|
||||
private static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8;
|
||||
@@ -36,8 +34,6 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEUE K
|
||||
protected int first;
|
||||
/** The Last Index pointer */
|
||||
protected int last;
|
||||
/** The Minimum Capacity of the Queue **/
|
||||
protected int minCapacity;
|
||||
|
||||
/**
|
||||
* Constructor using a initial array
|
||||
@@ -66,9 +62,7 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEUE K
|
||||
*/
|
||||
public ARRAY_FIFO_QUEUE(KEY_TYPE[] values, int offset, int size) {
|
||||
if (values.length < size) throw new IllegalArgumentException("Initial array (" + values.length + ") is smaller then the expected size (" + size + ")");
|
||||
if(values.length <= 0) values = NEW_KEY_ARRAY(MIN_CAPACITY);
|
||||
else if(values.length < MIN_CAPACITY) values = Arrays.copyOf(values, MIN_CAPACITY);
|
||||
minCapacity = MIN_CAPACITY;
|
||||
if(values.length <= 0) values = NEW_KEY_ARRAY(1);
|
||||
array = values;
|
||||
first = offset;
|
||||
last = (offset + size) % array.length;
|
||||
@@ -82,8 +76,7 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEUE K
|
||||
*/
|
||||
public ARRAY_FIFO_QUEUE(int capacity) {
|
||||
if (capacity < 0) throw new IllegalArgumentException("Initial capacity (" + capacity + ") is negative");
|
||||
array = NEW_KEY_ARRAY(Math.max(MIN_CAPACITY, capacity));
|
||||
minCapacity = array.length;
|
||||
array = NEW_KEY_ARRAY(Math.max(1, capacity));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -229,16 +222,6 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEUE K
|
||||
@Override
|
||||
public void onChanged() {}
|
||||
|
||||
@Override
|
||||
public ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE copy() {
|
||||
ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE queue = new ARRAY_FIFO_QUEUEBRACES();
|
||||
queue.first = first;
|
||||
queue.last = last;
|
||||
queue.minCapacity = minCapacity;
|
||||
queue.array = Arrays.copyOf(array, array.length);
|
||||
return queue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public COMPARATOR KEY_SUPER_GENERIC_TYPE comparator() { return null; }
|
||||
|
||||
@@ -252,11 +235,11 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEUE K
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
||||
public <E> void forEach(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE<E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
if(first == last) return;
|
||||
for(int i = 0,m=size();i<m;i++)
|
||||
action.accept(input, array[(first + i) % array.length]);
|
||||
action.accept(array[(first + i) % array.length], input);
|
||||
clearAndTrim(0);
|
||||
}
|
||||
|
||||
@@ -301,58 +284,9 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEUE K
|
||||
return EMPTY_VALUE;
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = identity;
|
||||
for(int i = 0,m=size();i<m;i++) {
|
||||
state = operator.APPLY_VALUE(state, array[(first + i) % array.length]);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
#else
|
||||
@Override
|
||||
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_SPECIAL_TYPE state = identity;
|
||||
for(int i = 0,m=size();i<m;i++) {
|
||||
state = operator.APPLY_VALUE(state, array[(first + i) % array.length]);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = EMPTY_VALUE;
|
||||
boolean empty = true;
|
||||
for(int i = 0,m=size();i<m;i++) {
|
||||
if(empty) {
|
||||
empty = false;
|
||||
state = array[(first + i) % array.length];
|
||||
continue;
|
||||
}
|
||||
state = operator.APPLY_VALUE(state, array[(first + i) % array.length]);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
int result = 0;
|
||||
for(int i = 0,m=size();i<m;i++) {
|
||||
if(filter.TEST_VALUE(array[(first + i) % array.length])) result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean trim(int size) {
|
||||
int newSize = Math.max(Math.max(size, size()), minCapacity);
|
||||
int newSize = Math.max(size, size());
|
||||
if(newSize >= array.length) return false;
|
||||
KEY_TYPE[] newArray = NEW_KEY_ARRAY(newSize);
|
||||
if(first <= last) System.arraycopy(array, first, newArray, 0, last - first);
|
||||
@@ -373,7 +307,7 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEUE K
|
||||
*/
|
||||
@Override
|
||||
public void clearAndTrim(int size) {
|
||||
int newSize = Math.max(minCapacity, size);
|
||||
int newSize = Math.max(MIN_CAPACITY, size);
|
||||
if(array.length <= newSize) {
|
||||
clear();
|
||||
return;
|
||||
@@ -395,7 +329,7 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEUE K
|
||||
|
||||
protected void reduce() {
|
||||
final int size = size();
|
||||
if (array.length > minCapacity && size <= array.length / 4) resize(size, Math.max(array.length / 2, minCapacity));
|
||||
if (array.length > MIN_CAPACITY && size <= array.length / 4) resize(size, array.length / 2);
|
||||
}
|
||||
|
||||
protected void expand() {
|
||||
|
||||
+4
-65
@@ -5,7 +5,6 @@ import java.util.NoSuchElementException;
|
||||
#if TYPE_OBJECT
|
||||
import java.util.Comparator;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.BiFunction;
|
||||
#endif
|
||||
import java.util.Objects;
|
||||
|
||||
@@ -15,9 +14,8 @@ import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
#endif
|
||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||
import speiger.src.collections.PACKAGE.functions.consumer.BI_OBJECT_CONSUMER;
|
||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||
import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
||||
|
||||
/**
|
||||
@@ -26,7 +24,7 @@ import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
||||
* It is highly suggested to use HeapPriorityQueue otherwise, unless you know why you need this specific implementation
|
||||
* @Type(T)
|
||||
*/
|
||||
public class ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEUE KEY_GENERIC_TYPE
|
||||
public class ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE implements PRIORITY_QUEUE KEY_GENERIC_TYPE
|
||||
{
|
||||
/** The Backing Array */
|
||||
protected transient KEY_TYPE[] array = EMPTY_KEY_ARRAY;
|
||||
@@ -264,9 +262,9 @@ public class ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUE
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
||||
public <E> void forEach(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE<E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
for(int i = 0,m=size;i<m;i++) action.accept(input, dequeue());
|
||||
for(int i = 0,m=size;i<m;i++) action.accept(dequeue(), input);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -296,45 +294,6 @@ public class ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUE
|
||||
return true;
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = identity;
|
||||
for(int i = 0;i<size;i++) {
|
||||
state = operator.APPLY_VALUE(state, array[i]);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
#else
|
||||
@Override
|
||||
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_SPECIAL_TYPE state = identity;
|
||||
for(int i = 0;i<size;i++) {
|
||||
state = operator.APPLY_VALUE(state, array[i]);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = EMPTY_VALUE;
|
||||
boolean empty = true;
|
||||
for(int i = 0;i<size;i++) {
|
||||
if(empty) {
|
||||
empty = false;
|
||||
state = array[i];
|
||||
continue;
|
||||
}
|
||||
state = operator.APPLY_VALUE(state, array[i]);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
@@ -348,31 +307,11 @@ public class ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUE
|
||||
return EMPTY_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
int result = 0;
|
||||
for(int i = 0;i<size;i++) {
|
||||
if(filter.TEST_VALUE(array[i])) result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITERATOR KEY_GENERIC_TYPE iterator() {
|
||||
return new Iter();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE copy() {
|
||||
ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE queue = new ARRAY_PRIORITY_QUEUEBRACES();
|
||||
queue.firstIndex = firstIndex;
|
||||
queue.size = size;
|
||||
queue.comparator = comparator;
|
||||
queue.array = Arrays.copyOf(array, array.length);
|
||||
return queue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public COMPARATOR KEY_SUPER_GENERIC_TYPE comparator() {
|
||||
return comparator;
|
||||
|
||||
+4
-64
@@ -5,7 +5,6 @@ import java.util.NoSuchElementException;
|
||||
#if TYPE_OBJECT
|
||||
import java.util.Comparator;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.BiFunction;
|
||||
#endif
|
||||
import java.util.Objects;
|
||||
|
||||
@@ -15,9 +14,8 @@ import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
#endif
|
||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||
import speiger.src.collections.PACKAGE.functions.consumer.BI_OBJECT_CONSUMER;
|
||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||
import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
||||
|
||||
/**
|
||||
@@ -25,7 +23,7 @@ import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
||||
* It is a ArrayBased Alternative to TreeSets that has less object allocations
|
||||
* @Type(T)
|
||||
*/
|
||||
public class HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEUE KEY_GENERIC_TYPE
|
||||
public class HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE implements PRIORITY_QUEUE KEY_GENERIC_TYPE
|
||||
{
|
||||
/** The Backing Array */
|
||||
protected transient KEY_TYPE[] array = EMPTY_KEY_ARRAY;
|
||||
@@ -251,9 +249,9 @@ public class HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEU
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
||||
public <E> void forEach(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE<E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
for(int i = 0,m=size;i<m;i++) action.accept(input, dequeue());
|
||||
for(int i = 0,m=size;i<m;i++) action.accept(dequeue(), input);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -283,45 +281,6 @@ public class HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEU
|
||||
return true;
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = identity;
|
||||
for(int i = 0;i<size;i++) {
|
||||
state = operator.APPLY_VALUE(state, array[i]);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
#else
|
||||
@Override
|
||||
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_SPECIAL_TYPE state = identity;
|
||||
for(int i = 0;i<size;i++) {
|
||||
state = operator.APPLY_VALUE(state, array[i]);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = EMPTY_VALUE;
|
||||
boolean empty = true;
|
||||
for(int i = 0;i<size;i++) {
|
||||
if(empty) {
|
||||
empty = false;
|
||||
state = array[i];
|
||||
continue;
|
||||
}
|
||||
state = operator.APPLY_VALUE(state, array[i]);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
@@ -335,16 +294,6 @@ public class HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEU
|
||||
return EMPTY_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
int result = 0;
|
||||
for(int i = 0;i<size;i++) {
|
||||
if(filter.TEST_VALUE(array[i])) result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
protected boolean removeIndex(int index) {
|
||||
array[index] = array[--size];
|
||||
#if TYPE_OBJECT
|
||||
@@ -360,15 +309,6 @@ public class HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEU
|
||||
ARRAYS.shiftDown(array, size, 0, comparator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE copy() {
|
||||
HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE queue = new HEAP_PRIORITY_QUEUEBRACES();
|
||||
queue.size = size;
|
||||
queue.comparator = comparator;
|
||||
queue.array = Arrays.copyOf(array, array.length);
|
||||
return queue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public COMPARATOR KEY_SUPER_GENERIC_TYPE comparator() {
|
||||
return comparator;
|
||||
|
||||
-76
@@ -1,13 +1,5 @@
|
||||
package speiger.src.collections.PACKAGE.queues;
|
||||
|
||||
#if TYPE_OBJECT
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.utils.PRIORITY_QUEUES;
|
||||
|
||||
/**
|
||||
* A Type Speciifc PriorityDeque or Dequeue interface to allow implementations like FIFO queues.
|
||||
* @Type(T)
|
||||
@@ -19,56 +11,6 @@ public interface PRIORITY_DEQUEUE KEY_GENERIC_TYPE extends PRIORITY_QUEUE KEY_GE
|
||||
* @param e the element that should be inserted into the first place
|
||||
*/
|
||||
public void enqueueFirst(KEY_TYPE e);
|
||||
|
||||
/**
|
||||
* Method to mass insert a elements into the first Index of the PriorityDequeue.
|
||||
* @param e the elements that should be inserted
|
||||
*/
|
||||
public default void enqueueAllFirst(KEY_TYPE... e) {
|
||||
enqueueAllFirst(e, 0, e.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to mass insert a elements into the first Index of the PriorityDequeue.
|
||||
* @param e the elements that should be inserted
|
||||
* @param length the amount of elements that should be inserted
|
||||
*/
|
||||
public default void enqueueAllFirst(KEY_TYPE[] e, int length) {
|
||||
enqueueAllFirst(e, 0, length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to mass insert a elements into the first Index of the PriorityDequeue.
|
||||
* @param e the elements that should be inserted
|
||||
* @param offset the offset where in the array should be started
|
||||
* @param length the amount of elements that should be inserted
|
||||
*/
|
||||
public default void enqueueAllFirst(KEY_TYPE[] e, int offset, int length) {
|
||||
for(int i = 0;i<length;i++)
|
||||
enqueueFirst(e[i+offset]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to mass insert elements into first Index of the PriorityDequeue.
|
||||
* @param c the elements that should be inserted from the Collection
|
||||
*/
|
||||
public default void enqueueAllFirst(COLLECTION KEY_GENERIC_TYPE c) {
|
||||
for(ITERATOR KEY_GENERIC_TYPE iter = c.iterator();iter.hasNext();)
|
||||
enqueueFirst(iter.NEXT());
|
||||
}
|
||||
|
||||
#if TYPE_OBJECT
|
||||
/**
|
||||
* Method to mass insert elements into first Index of the PriorityDequeue.
|
||||
* This method exists to add support for Java Collections to make it more useable
|
||||
* @param c the elements that should be inserted from the Collection
|
||||
*/
|
||||
public default void enqueueAllFirst(Collection<? extends CLASS_TYPE> c) {
|
||||
for(Iterator<? extends CLASS_TYPE> iter = c.iterator();iter.hasNext();)
|
||||
enqueueFirst(iter.next());
|
||||
}
|
||||
|
||||
#endif
|
||||
/**
|
||||
* A Method to remove a element from the last place instead of the first
|
||||
* @return the last element inserted
|
||||
@@ -80,22 +22,4 @@ public interface PRIORITY_DEQUEUE KEY_GENERIC_TYPE extends PRIORITY_QUEUE KEY_GE
|
||||
* @return the Last Element within the dequeue without deleting it
|
||||
*/
|
||||
public default KEY_TYPE last() { return peek(size()-1); }
|
||||
|
||||
/**
|
||||
* Creates a Wrapped PriorityDequeue that is Synchronized
|
||||
* @return a new PriorityDequeue that is synchronized
|
||||
* @see PRIORITY_QUEUES#synchronize
|
||||
*/
|
||||
public default PRIORITY_DEQUEUE KEY_GENERIC_TYPE synchronizeQueue() { return PRIORITY_QUEUES.synchronize(this); }
|
||||
|
||||
/**
|
||||
* Creates a Wrapped PriorityDequeue that is Synchronized
|
||||
* @param mutex is the controller of the synchronization block
|
||||
* @return a new PriorityDequeue Wrapper that is synchronized
|
||||
* @see PRIORITY_QUEUES#synchronize
|
||||
*/
|
||||
public default PRIORITY_DEQUEUE KEY_GENERIC_TYPE synchronizeQueue(Object mutex) { return PRIORITY_QUEUES.synchronize(this, mutex); }
|
||||
|
||||
@Override
|
||||
public PRIORITY_DEQUEUE KEY_GENERIC_TYPE copy();
|
||||
}
|
||||
+1
-95
@@ -2,18 +2,11 @@ package speiger.src.collections.PACKAGE.queues;
|
||||
|
||||
#if TYPE_OBJECT
|
||||
import java.util.Comparator;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
import speiger.src.collections.ints.functions.function.Int2ObjectFunction;
|
||||
import speiger.src.collections.objects.collections.ObjectIterator;
|
||||
#else
|
||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||
import speiger.src.collections.PACKAGE.collections.ITERABLE;
|
||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.utils.PRIORITY_QUEUES;
|
||||
|
||||
|
||||
/**
|
||||
* A Simple PriorityQueue (or Queue) interface that provides with the nessesary functions to interact with it, without cluttering with the Collection interface.
|
||||
@@ -40,57 +33,6 @@ public interface PRIORITY_QUEUE KEY_GENERIC_TYPE extends ITERABLE KEY_GENERIC_TY
|
||||
* @param e the element that should be inserted
|
||||
*/
|
||||
public void enqueue(KEY_TYPE e);
|
||||
|
||||
/**
|
||||
* Method to mass insert elements into the PriorityQueue
|
||||
* @param e the elements that should be inserted
|
||||
*/
|
||||
public default void enqueueAll(KEY_TYPE... e) {
|
||||
enqueueAll(e, 0, e.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to mass insert elements into the PriorityQueue
|
||||
* @param e the elements that should be inserted
|
||||
* @param length the amount of elements that should be inserted
|
||||
*/
|
||||
public default void enqueueAll(KEY_TYPE[] e, int length) {
|
||||
enqueueAll(e, 0, length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to mass insert elements into the PriorityQueue
|
||||
* @param e the elements that should be inserted
|
||||
* @param offset the offset where in the array should be started
|
||||
* @param length the amount of elements that should be inserted
|
||||
*/
|
||||
public default void enqueueAll(KEY_TYPE[] e, int offset, int length) {
|
||||
for(int i = 0;i<length;i++)
|
||||
enqueue(e[i+offset]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to mass insert elements into the PriorityQueue
|
||||
* @param c the elements that should be inserted from the Collection
|
||||
*/
|
||||
public default void enqueueAll(COLLECTION KEY_GENERIC_TYPE c) {
|
||||
for(ITERATOR KEY_GENERIC_TYPE iter = c.iterator();iter.hasNext();)
|
||||
enqueue(iter.NEXT());
|
||||
}
|
||||
|
||||
#if TYPE_OBJECT
|
||||
/**
|
||||
* Method to mass insert elements into the PriorityQueue
|
||||
* This method exists to add support for Java Collections to make it more useable
|
||||
* @param c the elements that should be inserted from the Collection
|
||||
*/
|
||||
public default void enqueueAll(Collection<? extends CLASS_TYPE> c) {
|
||||
for(Iterator<? extends CLASS_TYPE> iter = c.iterator();iter.hasNext();)
|
||||
enqueue(iter.next());
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Method to extract a element from the PriorityQueue
|
||||
* @return a element from the Queue
|
||||
@@ -128,15 +70,6 @@ public interface PRIORITY_QUEUE KEY_GENERIC_TYPE extends ITERABLE KEY_GENERIC_TY
|
||||
*/
|
||||
public void onChanged();
|
||||
|
||||
/**
|
||||
* A Function that does a shallow clone of the PriorityQueue itself.
|
||||
* This function is more optimized then a copy constructor since the PriorityQueue does not have to be unsorted/resorted.
|
||||
* It can be compared to Cloneable but with less exception risk
|
||||
* @return a Shallow Copy of the PriorityQueue
|
||||
* @note Wrappers and view PriorityQueues will not support this feature
|
||||
*/
|
||||
public PRIORITY_QUEUE KEY_GENERIC_TYPE copy();
|
||||
|
||||
/**
|
||||
* @return the sorter of the Queue, can be null
|
||||
*/
|
||||
@@ -148,22 +81,6 @@ public interface PRIORITY_QUEUE KEY_GENERIC_TYPE extends ITERABLE KEY_GENERIC_TY
|
||||
*/
|
||||
public ITERATOR KEY_GENERIC_TYPE iterator();
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Creates a Wrapped PriorityQueue that is Synchronized
|
||||
* @return a new PriorityQueue that is synchronized
|
||||
* @see PRIORITY_QUEUES#synchronize
|
||||
*/
|
||||
public default PRIORITY_QUEUE KEY_GENERIC_TYPE synchronizeQueue() { return PRIORITY_QUEUES.synchronize(this); }
|
||||
|
||||
/**
|
||||
* Creates a Wrapped PriorityQueue that is Synchronized
|
||||
* @param mutex is the controller of the synchronization block
|
||||
* @return a new PriorityQueue Wrapper that is synchronized
|
||||
* @see PRIORITY_QUEUES#synchronize
|
||||
*/
|
||||
public default PRIORITY_QUEUE KEY_GENERIC_TYPE synchronizeQueue(Object mutex) { return PRIORITY_QUEUES.synchronize(this, mutex); }
|
||||
|
||||
/**
|
||||
* A method to drop the contents of the Queue without clearing the queue
|
||||
* @Type(E)
|
||||
@@ -178,15 +95,4 @@ public interface PRIORITY_QUEUE KEY_GENERIC_TYPE extends ITERABLE KEY_GENERIC_TY
|
||||
* @note if the Type is generic then a Object Array is created instead of a Type Array
|
||||
*/
|
||||
public GENERIC_SPECIAL_KEY_BRACES<E> KEY_SPECIAL_TYPE[] TO_ARRAY(KEY_SPECIAL_TYPE[] input);
|
||||
#if TYPE_OBJECT
|
||||
/**
|
||||
* A Helper function that simplifies the process of creating a new Array.
|
||||
* @param action the array creation function
|
||||
* @return an array containing all of the elements in this collection
|
||||
* @see Collection#toArray(Object[])
|
||||
*/
|
||||
default KEY_TYPE[] TO_ARRAY(Int2ObjectFunction<KEY_TYPE[]> action) {
|
||||
return TO_ARRAY(action.get(size()));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
+6
-144
@@ -4,7 +4,6 @@ import java.util.Collection;
|
||||
#if TYPE_OBJECT
|
||||
import java.util.Comparator;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.BiFunction;
|
||||
#endif
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
@@ -14,9 +13,8 @@ import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
#endif
|
||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||
import speiger.src.collections.PACKAGE.functions.consumer.BI_OBJECT_CONSUMER;
|
||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
|
||||
@@ -213,9 +211,6 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
#endif
|
||||
@Override
|
||||
public boolean add(KEY_TYPE o) {
|
||||
#if TYPE_OBJECT
|
||||
validate(o);
|
||||
#endif
|
||||
if(tree == null) {
|
||||
tree = first = last = new EntryBRACES(o, null);
|
||||
size++;
|
||||
@@ -245,7 +240,7 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
}
|
||||
fixAfterInsertion(adding);
|
||||
size++;
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -309,10 +304,10 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
||||
public <E> void forEach(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE<E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next())
|
||||
action.accept(input, entry.key);
|
||||
action.accept(entry.key, input);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -351,55 +346,6 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
return EMPTY_VALUE;
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = identity;
|
||||
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) {
|
||||
state = operator.APPLY_VALUE(state, entry.key);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
#else
|
||||
@Override
|
||||
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_SPECIAL_TYPE state = identity;
|
||||
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) {
|
||||
state = operator.APPLY_VALUE(state, entry.key);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = EMPTY_VALUE;
|
||||
boolean empty = true;
|
||||
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) {
|
||||
if(empty) {
|
||||
empty = false;
|
||||
state = entry.key;
|
||||
continue;
|
||||
}
|
||||
state = operator.APPLY_VALUE(state, entry.key);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
int result = 0;
|
||||
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) {
|
||||
if(filter.TEST_VALUE(entry.key)) result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
protected Entry KEY_GENERIC_TYPE findNode(KEY_TYPE o) {
|
||||
Entry KEY_GENERIC_TYPE node = tree;
|
||||
int compare;
|
||||
@@ -582,21 +528,6 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
tree = null;
|
||||
}
|
||||
|
||||
public AVL_TREE_SET KEY_GENERIC_TYPE copy() {
|
||||
AVL_TREE_SET KEY_GENERIC_TYPE set = new AVL_TREE_SETBRACES();
|
||||
set.size = size;
|
||||
if(tree != null) {
|
||||
set.tree = tree.copy();
|
||||
Entry KEY_GENERIC_TYPE lastFound = null;
|
||||
for(Entry KEY_GENERIC_TYPE entry = tree;entry != null;entry = entry.left) lastFound = entry;
|
||||
set.first = lastFound;
|
||||
lastFound = null;
|
||||
for(Entry KEY_GENERIC_TYPE entry = tree;entry != null;entry = entry.right) lastFound = entry;
|
||||
set.last = lastFound;
|
||||
}
|
||||
return set;
|
||||
}
|
||||
|
||||
@Override
|
||||
public COMPARATOR KEY_GENERIC_TYPE comparator() { return comparator; }
|
||||
|
||||
@@ -655,7 +586,6 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
}
|
||||
}
|
||||
|
||||
protected void validate(KEY_TYPE k) { compare(k, k); }
|
||||
protected int compare(KEY_TYPE k, KEY_TYPE v) { return comparator != null ? comparator.compare(k, v) : COMPAREABLE_TO_KEY(k, v);}
|
||||
|
||||
/** From CLR */
|
||||
@@ -1069,9 +999,6 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
return fromStart && toEnd ? set.size() : iterator().skip(Integer.MAX_VALUE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SubSet KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) {
|
||||
Objects.requireNonNull(action);
|
||||
@@ -1081,10 +1008,10 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
||||
public <E> void forEach(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE<E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
for(Entry KEY_GENERIC_TYPE entry = start();entry != null && inRange(entry.key);entry = next(entry))
|
||||
action.accept(input, entry.key);
|
||||
action.accept(entry.key, input);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1114,45 +1041,6 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
return true;
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = identity;
|
||||
for(Entry KEY_GENERIC_TYPE entry = start();entry != null && inRange(entry.key);entry = next(entry)) {
|
||||
state = operator.APPLY_VALUE(state, entry.key);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
#else
|
||||
@Override
|
||||
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_SPECIAL_TYPE state = identity;
|
||||
for(Entry KEY_GENERIC_TYPE entry = start();entry != null && inRange(entry.key);entry = next(entry)) {
|
||||
state = operator.APPLY_VALUE(state, entry.key);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = EMPTY_VALUE;
|
||||
boolean empty = true;
|
||||
for(Entry KEY_GENERIC_TYPE entry = start();entry != null && inRange(entry.key);entry = next(entry)) {
|
||||
if(empty) {
|
||||
empty = false;
|
||||
state = entry.key;
|
||||
continue;
|
||||
}
|
||||
state = operator.APPLY_VALUE(state, entry.key);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
@@ -1162,16 +1050,6 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
return EMPTY_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
int result = 0;
|
||||
for(Entry KEY_GENERIC_TYPE entry = start();entry != null && inRange(entry.key);entry = next(entry)) {
|
||||
if(filter.TEST_VALUE(entry.key)) result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
class SubSetIterator implements LIST_ITERATOR KEY_GENERIC_TYPE
|
||||
{
|
||||
Entry KEY_GENERIC_TYPE previous;
|
||||
@@ -1352,22 +1230,6 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
Entry KEY_GENERIC_TYPE copy() {
|
||||
Entry KEY_GENERIC_TYPE entry = new EntryBRACES(key, null);
|
||||
entry.state = state;
|
||||
if(left != null) {
|
||||
Entry KEY_GENERIC_TYPE newLeft = left.copy();
|
||||
entry.left = newLeft;
|
||||
newLeft.parent = entry;
|
||||
}
|
||||
if(right != null) {
|
||||
Entry KEY_GENERIC_TYPE newRight = right.copy();
|
||||
entry.right = newRight;
|
||||
newRight.parent = entry;
|
||||
}
|
||||
return entry;
|
||||
}
|
||||
|
||||
int getHeight() { return state; }
|
||||
|
||||
void updateHeight() { state = (1 + Math.max(left == null ? -1 : left.getHeight(), right == null ? -1 : right.getHeight())); }
|
||||
|
||||
+20
-9
@@ -1,8 +1,7 @@
|
||||
package speiger.src.collections.PACKAGE.sets;
|
||||
|
||||
#if TYPE_OBJECT
|
||||
import java.util.Iterator;
|
||||
import java.util.Objects;
|
||||
#endif
|
||||
import java.util.Set;
|
||||
|
||||
import speiger.src.collections.PACKAGE.collections.ABSTRACT_COLLECTION;
|
||||
@@ -16,15 +15,13 @@ public abstract class ABSTRACT_SET KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
||||
{
|
||||
@Override
|
||||
public abstract ITERATOR KEY_GENERIC_TYPE iterator();
|
||||
@Override
|
||||
public ABSTRACT_SET KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hashCode = 0;
|
||||
int hashCode = 1;
|
||||
ITERATOR KEY_GENERIC_TYPE i = iterator();
|
||||
while(i.hasNext())
|
||||
hashCode += KEY_TO_HASH(i.NEXT());
|
||||
hashCode = 31 * hashCode + KEY_TO_HASH(i.NEXT());
|
||||
return hashCode;
|
||||
}
|
||||
|
||||
@@ -36,10 +33,24 @@ public abstract class ABSTRACT_SET KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
||||
return false;
|
||||
Set<?> l = (Set<?>)o;
|
||||
if(l.size() != size()) return false;
|
||||
try {
|
||||
return containsAll(l);
|
||||
} catch (ClassCastException | NullPointerException unused) {
|
||||
#if !TYPE_OBJECT
|
||||
if(l instanceof SET)
|
||||
{
|
||||
ITERATOR e1 = iterator();
|
||||
ITERATOR e2 = ((SET)l).iterator();
|
||||
while (e1.hasNext() && e2.hasNext()) {
|
||||
if(!(KEY_EQUALS(e1.NEXT(), e2.NEXT())))
|
||||
return false;
|
||||
}
|
||||
return !(e1.hasNext() || e2.hasNext());
|
||||
}
|
||||
#endif
|
||||
Iterator<CLASS_TYPE> e1 = iterator();
|
||||
Iterator<?> e2 = l.iterator();
|
||||
while (e1.hasNext() && e2.hasNext()) {
|
||||
if(!Objects.equals(e1.next(), e2.next()))
|
||||
return false;
|
||||
}
|
||||
return !(e1.hasNext() || e2.hasNext());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ import java.util.Collection;
|
||||
#if TYPE_OBJECT
|
||||
import java.util.Comparator;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.BiFunction;
|
||||
#endif
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Objects;
|
||||
@@ -17,9 +16,8 @@ import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
|
||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||
import speiger.src.collections.PACKAGE.functions.consumer.BI_OBJECT_CONSUMER;
|
||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
@@ -74,8 +72,8 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
||||
* @throws NegativeArraySizeException if the length is negative
|
||||
*/
|
||||
public ARRAY_SET(KEY_TYPE[] array, int length) {
|
||||
this(length);
|
||||
addAll(array, length);
|
||||
data = Arrays.copyOf(array, length);
|
||||
size = length;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -229,21 +227,6 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeAll(COLLECTION KEY_GENERIC_TYPE c, CONSUMER KEY_GENERIC_TYPE r) {
|
||||
int j = 0;
|
||||
for(int i = 0;i<size;i++) {
|
||||
if(!c.contains(data[i])) data[j++] = data[i];
|
||||
else r.accept(data[i]);
|
||||
}
|
||||
boolean result = j != size;
|
||||
#if TYPE_OBJECT
|
||||
Arrays.fill(data, j, size, null);
|
||||
#endif
|
||||
size = j;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c) {
|
||||
int j = 0;
|
||||
@@ -259,21 +242,6 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c, CONSUMER KEY_GENERIC_TYPE r) {
|
||||
int j = 0;
|
||||
for(int i = 0;i<size;i++) {
|
||||
if(c.contains(data[i])) data[j++] = data[i];
|
||||
else r.accept(data[i]);
|
||||
}
|
||||
boolean result = j != size;
|
||||
#if TYPE_OBJECT
|
||||
Arrays.fill(data, j, size, null);
|
||||
#endif
|
||||
size = j;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Primitive
|
||||
public boolean removeAll(Collection<?> c) {
|
||||
@@ -382,10 +350,10 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
||||
public <E> void forEach(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE<E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
for(int i = 0;i<size;i++)
|
||||
action.accept(input, data[i]);
|
||||
action.accept(data[i], input);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -424,55 +392,6 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
||||
return EMPTY_VALUE;
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = identity;
|
||||
for(int i = 0;i<size;i++) {
|
||||
state = operator.APPLY_VALUE(state, data[i]);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
#else
|
||||
@Override
|
||||
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_SPECIAL_TYPE state = identity;
|
||||
for(int i = 0;i<size;i++) {
|
||||
state = operator.APPLY_VALUE(state, data[i]);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = EMPTY_VALUE;
|
||||
boolean empty = true;
|
||||
for(int i = 0;i<size;i++) {
|
||||
if(empty) {
|
||||
empty = false;
|
||||
state = data[i];
|
||||
continue;
|
||||
}
|
||||
state = operator.APPLY_VALUE(state, data[i]);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
int result = 0;
|
||||
for(int i = 0;i<size;i++) {
|
||||
if(filter.TEST_VALUE(data[i])) result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
protected int findIndex(KEY_TYPE o) {
|
||||
for(int i = size-1;i>=0;i--)
|
||||
@@ -521,13 +440,6 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
||||
return new SubSet(fromIndex, size - fromIndex);
|
||||
}
|
||||
|
||||
public ARRAY_SET KEY_GENERIC_TYPE copy() {
|
||||
ARRAY_SET KEY_GENERIC_TYPE set = new ARRAY_SETBRACES();
|
||||
set.data = Arrays.copyOf(data, data.length);
|
||||
set.size = size;
|
||||
return set;
|
||||
}
|
||||
|
||||
@Override
|
||||
public COMPARATOR KEY_GENERIC_TYPE comparator() {
|
||||
return null;
|
||||
@@ -548,7 +460,6 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
||||
public KEY_TYPE[] TO_ARRAY(KEY_TYPE[] a) {
|
||||
if(a == null || a.length < size()) return Arrays.copyOf(data, size());
|
||||
System.arraycopy(data, 0, a, 0, size());
|
||||
if (a.length > size) a[size] = EMPTY_KEY_VALUE;
|
||||
return a;
|
||||
}
|
||||
|
||||
@@ -569,7 +480,6 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
||||
else if(a.length < size()) a = (E[])ObjectArrays.newArray(a.getClass().getComponentType(), size());
|
||||
for(int i = 0;i<size();i++)
|
||||
a[i] = (E)KEY_TO_OBJ(data[i]);
|
||||
if (a.length > size) a[size] = null;
|
||||
return a;
|
||||
}
|
||||
|
||||
@@ -756,9 +666,6 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SubSet copy() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public SORTED_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) {
|
||||
int fromIndex = findIndex(fromElement);
|
||||
@@ -843,7 +750,6 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
||||
|
||||
@Override
|
||||
public KEY_TYPE NEXT() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
lastReturned = index;
|
||||
return data[index++];
|
||||
}
|
||||
@@ -855,7 +761,6 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
||||
|
||||
@Override
|
||||
public KEY_TYPE PREVIOUS() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
lastReturned = index;
|
||||
return data[index--];
|
||||
}
|
||||
@@ -928,7 +833,6 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
||||
|
||||
@Override
|
||||
public KEY_TYPE NEXT() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
lastReturned = index;
|
||||
return data[index++];
|
||||
}
|
||||
@@ -940,7 +844,6 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
||||
|
||||
@Override
|
||||
public KEY_TYPE PREVIOUS() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
lastReturned = index;
|
||||
return data[index--];
|
||||
}
|
||||
@@ -957,9 +860,11 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
if(lastReturned == -1) throw new IllegalStateException();
|
||||
if(lastReturned == -1)
|
||||
throw new IllegalStateException();
|
||||
ARRAY_SET.this.remove(data[lastReturned]);
|
||||
if(lastReturned < index) index--;
|
||||
if(lastReturned < index)
|
||||
index--;
|
||||
lastReturned = -1;
|
||||
}
|
||||
|
||||
|
||||
+6
-100
@@ -3,9 +3,7 @@ package speiger.src.collections.PACKAGE.sets;
|
||||
#if TYPE_OBJECT
|
||||
import java.util.Comparator;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.BiFunction;
|
||||
#endif
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
@@ -18,9 +16,8 @@ import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
#endif
|
||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||
import speiger.src.collections.PACKAGE.functions.consumer.BI_OBJECT_CONSUMER;
|
||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||
import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
||||
import speiger.src.collections.PACKAGE.utils.ITERATORS;
|
||||
@@ -53,12 +50,6 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
|
||||
/** The Last Index in the Map */
|
||||
protected int lastIndex = -1;
|
||||
|
||||
/**
|
||||
* Helper constructor to optimize the copying
|
||||
* Only accessible through implementations
|
||||
*/
|
||||
protected IMMUTABLE_HASH_SET() {}
|
||||
|
||||
/**
|
||||
* Helper constructor that allow to create a set from unboxed values
|
||||
* @param array the elements that should be put into the set
|
||||
@@ -190,18 +181,7 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
|
||||
{
|
||||
KEY_TYPE o = a[i];
|
||||
if(KEY_EQUALS_NULL(o)) {
|
||||
if(!containsNull) {
|
||||
size++;
|
||||
if(prev != -1) {
|
||||
newLinks[prev] ^= ((newLinks[prev] ^ (newSize & 0xFFFFFFFFL)) & 0xFFFFFFFFL);
|
||||
newLinks[newSize] ^= ((newLinks[newSize] ^ ((prev & 0xFFFFFFFFL) << 32)) & 0xFFFFFFFF00000000L);
|
||||
prev = newSize;
|
||||
}
|
||||
else {
|
||||
prev = firstIndex = newSize;
|
||||
newLinks[newSize] = -1L;
|
||||
}
|
||||
}
|
||||
if(!containsNull) size++;
|
||||
containsNull = true;
|
||||
continue;
|
||||
}
|
||||
@@ -210,7 +190,7 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
|
||||
KEY_TYPE current = newKeys[pos];
|
||||
if(KEY_EQUALS_NOT_NULL(current)) {
|
||||
if(KEY_EQUALS(current, o)) continue;
|
||||
while(KEY_EQUALS_NOT_NULL((current = newKeys[pos = (++pos & newMask)]))) {
|
||||
while(KEY_EQUALS_NOT_NULL((current = newKeys[pos = (++pos & mask)]))) {
|
||||
if(KEY_EQUALS(current, o)) {
|
||||
found = false;
|
||||
break;
|
||||
@@ -231,7 +211,7 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
|
||||
}
|
||||
}
|
||||
}
|
||||
nullIndex = newSize;
|
||||
nullIndex = size;
|
||||
mask = newMask;
|
||||
keys = newKeys;
|
||||
links = newLinks;
|
||||
@@ -317,11 +297,11 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
||||
public <E> void forEach(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE<E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
action.accept(input, keys[index]);
|
||||
action.accept(keys[index], input);
|
||||
index = (int)links[index];
|
||||
}
|
||||
}
|
||||
@@ -332,7 +312,6 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
if(filter.TEST_VALUE(keys[index])) return true;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -343,7 +322,6 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
if(filter.TEST_VALUE(keys[index])) return false;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -354,78 +332,20 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
if(!filter.TEST_VALUE(keys[index])) return false;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = identity;
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
state = operator.APPLY_VALUE(state, keys[index]);
|
||||
index = (int)links[index];
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
#else
|
||||
@Override
|
||||
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_SPECIAL_TYPE state = identity;
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
state = operator.APPLY_VALUE(state, keys[index]);
|
||||
index = (int)links[index];
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = EMPTY_VALUE;
|
||||
boolean empty = true;
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
if(empty) {
|
||||
state = keys[index];
|
||||
empty = false;
|
||||
}
|
||||
else state = operator.APPLY_VALUE(state, keys[index]);
|
||||
index = (int)links[index];
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
if(filter.TEST_VALUE(keys[index])) return keys[index];
|
||||
index = (int)links[index];
|
||||
}
|
||||
return EMPTY_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
int result = 0;
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
if(filter.TEST_VALUE(keys[index])) result++;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE iterator() {
|
||||
return new SetIterator();
|
||||
@@ -436,20 +356,6 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
|
||||
return new SetIterator(fromElement);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMMUTABLE_HASH_SET KEY_GENERIC_TYPE copy() {
|
||||
IMMUTABLE_HASH_SET KEY_GENERIC_TYPE set = new IMMUTABLE_HASH_SETBRACES();
|
||||
set.containsNull = containsNull;
|
||||
set.firstIndex = firstIndex;
|
||||
set.lastIndex = lastIndex;
|
||||
set.size = size;
|
||||
set.mask = mask;
|
||||
set.nullIndex = nullIndex;
|
||||
set.keys = Arrays.copyOf(keys, keys.length);
|
||||
set.links = Arrays.copyOf(links, links.length);
|
||||
return set;
|
||||
}
|
||||
|
||||
@Override
|
||||
public COMPARATOR KEY_GENERIC_TYPE comparator() { return null; }
|
||||
|
||||
|
||||
+3
-82
@@ -3,9 +3,7 @@ package speiger.src.collections.PACKAGE.sets;
|
||||
#if TYPE_OBJECT
|
||||
import java.util.Comparator;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.BiFunction;
|
||||
#endif
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
@@ -24,9 +22,8 @@ import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.utils.ITERATORS;
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
#endif
|
||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||
import speiger.src.collections.PACKAGE.functions.consumer.BI_OBJECT_CONSUMER;
|
||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||
import speiger.src.collections.PACKAGE.utils.STRATEGY;
|
||||
import speiger.src.collections.utils.HashUtil;
|
||||
import speiger.src.collections.utils.SanityChecks;
|
||||
@@ -537,11 +534,11 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
||||
public <E> void forEach(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE<E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
action.accept(input, keys[index]);
|
||||
action.accept(keys[index], input);
|
||||
index = (int)links[index];
|
||||
}
|
||||
}
|
||||
@@ -552,7 +549,6 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
if(filter.TEST_VALUE(keys[index])) return true;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -563,7 +559,6 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
if(filter.TEST_VALUE(keys[index])) return false;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -574,78 +569,20 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
if(!filter.TEST_VALUE(keys[index])) return false;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = identity;
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
state = operator.APPLY_VALUE(state, keys[index]);
|
||||
index = (int)links[index];
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
#else
|
||||
@Override
|
||||
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_SPECIAL_TYPE state = identity;
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
state = operator.APPLY_VALUE(state, keys[index]);
|
||||
index = (int)links[index];
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = EMPTY_VALUE;
|
||||
boolean empty = true;
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
if(empty) {
|
||||
state = keys[index];
|
||||
empty = false;
|
||||
}
|
||||
else state = operator.APPLY_VALUE(state, keys[index]);
|
||||
index = (int)links[index];
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
if(filter.TEST_VALUE(keys[index])) return keys[index];
|
||||
index = (int)links[index];
|
||||
}
|
||||
return EMPTY_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
int result = 0;
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
if(filter.TEST_VALUE(keys[index])) result++;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE iterator() {
|
||||
return new SetIterator();
|
||||
@@ -656,22 +593,6 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
||||
return new SetIterator(fromElement);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE copy() {
|
||||
LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE set = new LINKED_CUSTOM_HASH_SETBRACES(0, loadFactor, strategy);
|
||||
set.minCapacity = minCapacity;
|
||||
set.mask = mask;
|
||||
set.maxFill = maxFill;
|
||||
set.nullIndex = nullIndex;
|
||||
set.containsNull = containsNull;
|
||||
set.size = size;
|
||||
set.keys = Arrays.copyOf(keys, keys.length);
|
||||
set.links = Arrays.copyOf(links, links.length);
|
||||
set.firstIndex = firstIndex;
|
||||
set.lastIndex = lastIndex;
|
||||
return set;
|
||||
}
|
||||
|
||||
@Override
|
||||
public COMPARATOR KEY_GENERIC_TYPE comparator() { return null; }
|
||||
|
||||
|
||||
+3
-82
@@ -3,14 +3,12 @@ package speiger.src.collections.PACKAGE.sets;
|
||||
#if TYPE_OBJECT
|
||||
import java.util.Comparator;
|
||||
#endif
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Objects;
|
||||
#if TYPE_OBJECT
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.BiFunction;
|
||||
#endif
|
||||
|
||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||
@@ -22,9 +20,8 @@ import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
#endif
|
||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||
import speiger.src.collections.PACKAGE.functions.consumer.BI_OBJECT_CONSUMER;
|
||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||
import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.utils.ITERATORS;
|
||||
@@ -392,11 +389,11 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
||||
public <E> void forEach(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE<E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
action.accept(input, keys[index]);
|
||||
action.accept(keys[index], input);
|
||||
index = (int)links[index];
|
||||
}
|
||||
}
|
||||
@@ -407,7 +404,6 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
if(filter.TEST_VALUE(keys[index])) return true;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -418,7 +414,6 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
if(filter.TEST_VALUE(keys[index])) return false;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -429,78 +424,20 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
if(!filter.TEST_VALUE(keys[index])) return false;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = identity;
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
state = operator.APPLY_VALUE(state, keys[index]);
|
||||
index = (int)links[index];
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
#else
|
||||
@Override
|
||||
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_SPECIAL_TYPE state = identity;
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
state = operator.APPLY_VALUE(state, keys[index]);
|
||||
index = (int)links[index];
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = EMPTY_VALUE;
|
||||
boolean empty = true;
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
if(empty) {
|
||||
state = keys[index];
|
||||
empty = false;
|
||||
}
|
||||
else state = operator.APPLY_VALUE(state, keys[index]);
|
||||
index = (int)links[index];
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
if(filter.TEST_VALUE(keys[index])) return keys[index];
|
||||
index = (int)links[index];
|
||||
}
|
||||
return EMPTY_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
int result = 0;
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
if(filter.TEST_VALUE(keys[index])) result++;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNodeAdded(int pos) {
|
||||
if(size == 0) {
|
||||
@@ -627,22 +564,6 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
||||
return new SetIterator(fromElement);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LINKED_HASH_SET KEY_GENERIC_TYPE copy() {
|
||||
LINKED_HASH_SET KEY_GENERIC_TYPE set = new LINKED_HASH_SETBRACES(0, loadFactor);
|
||||
set.minCapacity = minCapacity;
|
||||
set.mask = mask;
|
||||
set.maxFill = maxFill;
|
||||
set.nullIndex = nullIndex;
|
||||
set.containsNull = containsNull;
|
||||
set.size = size;
|
||||
set.keys = Arrays.copyOf(keys, keys.length);
|
||||
set.links = Arrays.copyOf(links, links.length);
|
||||
set.firstIndex = firstIndex;
|
||||
set.lastIndex = lastIndex;
|
||||
return set;
|
||||
}
|
||||
|
||||
@Override
|
||||
public COMPARATOR KEY_GENERIC_TYPE comparator() { return null; }
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ import java.util.NavigableSet;
|
||||
|
||||
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.collections.SPLIT_ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.utils.SETS;
|
||||
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
||||
|
||||
/**
|
||||
@@ -116,33 +115,7 @@ public interface NAVIGABLE_SET KEY_GENERIC_TYPE extends NavigableSet<CLASS_TYPE>
|
||||
/** @return a Type Specific desendingSet */
|
||||
@Override
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE descendingSet();
|
||||
@Override
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE copy();
|
||||
|
||||
#if !TYPE_BOOLEAN
|
||||
/**
|
||||
* Creates a Wrapped NavigableSet that is Synchronized
|
||||
* @return a new NavigableSet that is synchronized
|
||||
* @see SETS#synchronize
|
||||
*/
|
||||
public default NAVIGABLE_SET KEY_GENERIC_TYPE synchronize() { return SETS.synchronize(this); }
|
||||
|
||||
/**
|
||||
* Creates a Wrapped NavigableSet that is Synchronized
|
||||
* @param mutex is the controller of the synchronization block
|
||||
* @return a new NavigableSet Wrapper that is synchronized
|
||||
* @see SETS#synchronize
|
||||
*/
|
||||
public default NAVIGABLE_SET KEY_GENERIC_TYPE synchronize(Object mutex) { return SETS.synchronize(this, mutex); }
|
||||
|
||||
/**
|
||||
* Creates a Wrapped NavigableSet that is unmodifiable
|
||||
* @return a new NavigableSet Wrapper that is unmodifiable
|
||||
* @see SETS#unmodifiable
|
||||
*/
|
||||
public default NAVIGABLE_SET KEY_GENERIC_TYPE unmodifiable() { return SETS.unmodifiable(this); }
|
||||
|
||||
#endif
|
||||
/**
|
||||
* A Type Specific Type Splititerator to reduce boxing/unboxing
|
||||
* @return type specific splititerator
|
||||
|
||||
+7
-89
@@ -2,13 +2,11 @@ package speiger.src.collections.PACKAGE.sets;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.ConcurrentModificationException;
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Objects;
|
||||
#if TYPE_OBJECT
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.BiFunction;
|
||||
#endif
|
||||
|
||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||
@@ -19,9 +17,8 @@ import speiger.src.collections.PACKAGE.lists.LIST;
|
||||
import speiger.src.collections.PACKAGE.utils.ITERATORS;
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
#endif
|
||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||
import speiger.src.collections.PACKAGE.functions.consumer.BI_OBJECT_CONSUMER;
|
||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||
import speiger.src.collections.PACKAGE.utils.STRATEGY;
|
||||
|
||||
import speiger.src.collections.utils.HashUtil;
|
||||
@@ -432,10 +429,7 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T
|
||||
int newMask = newSize - 1;
|
||||
KEY_TYPE[] newKeys = NEW_KEY_ARRAY(newSize + 1);
|
||||
for(int i = nullIndex, pos = 0, j = (size - (containsNull ? 1 : 0));j-- != 0;) {
|
||||
while(true) {
|
||||
if(--i < 0) throw new ConcurrentModificationException("Set was modified during rehash");
|
||||
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) break;
|
||||
}
|
||||
while(strategy.equals(keys[--i], EMPTY_KEY_VALUE));
|
||||
if(!strategy.equals(newKeys[pos = HashUtil.mix(KEY_TO_HASH(keys[i])) & newMask], EMPTY_KEY_VALUE))
|
||||
while(!strategy.equals(newKeys[pos = (++pos & newMask)], EMPTY_KEY_VALUE));
|
||||
newKeys[pos] = keys[i];
|
||||
@@ -451,19 +445,6 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T
|
||||
return new SetIterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CUSTOM_HASH_SET KEY_GENERIC_TYPE copy() {
|
||||
CUSTOM_HASH_SET KEY_GENERIC_TYPE set = new CUSTOM_HASH_SETBRACES(0, loadFactor, strategy);
|
||||
set.minCapacity = minCapacity;
|
||||
set.mask = mask;
|
||||
set.maxFill = maxFill;
|
||||
set.nullIndex = nullIndex;
|
||||
set.containsNull = containsNull;
|
||||
set.size = size;
|
||||
set.keys = Arrays.copyOf(keys, keys.length);
|
||||
return set;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
if(size == 0) return;
|
||||
@@ -487,12 +468,12 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
||||
public <E> void forEach(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE<E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
if(size() <= 0) return;
|
||||
if(containsNull) action.accept(input, keys[nullIndex]);
|
||||
if(containsNull) action.accept(keys[nullIndex], input);
|
||||
for(int i = nullIndex-1;i>=0;i--) {
|
||||
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) action.accept(input, keys[i]);
|
||||
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) action.accept(keys[i], input);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -529,54 +510,6 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T
|
||||
return true;
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = identity;
|
||||
if(containsNull) state = operator.APPLY_VALUE(state, keys[nullIndex]);
|
||||
for(int i = nullIndex-1;i>=0;i--) {
|
||||
if(strategy.equals(keys[i], EMPTY_KEY_VALUE)) continue;
|
||||
state = operator.APPLY_VALUE(state, keys[i]);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
#else
|
||||
@Override
|
||||
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_SPECIAL_TYPE state = identity;
|
||||
if(containsNull) state = operator.APPLY_VALUE(state, keys[nullIndex]);
|
||||
for(int i = nullIndex-1;i>=0;i--) {
|
||||
if(strategy.equals(keys[i], EMPTY_KEY_VALUE)) continue;
|
||||
state = operator.APPLY_VALUE(state, keys[i]);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = EMPTY_VALUE;
|
||||
boolean empty = true;
|
||||
if(containsNull) {
|
||||
state = keys[nullIndex];
|
||||
empty = false;
|
||||
}
|
||||
for(int i = 0;i<size;i++) {
|
||||
if(strategy.equals(keys[i], EMPTY_KEY_VALUE)) continue;
|
||||
if(empty) {
|
||||
empty = false;
|
||||
state = keys[i];
|
||||
continue;
|
||||
}
|
||||
state = operator.APPLY_VALUE(state, keys[i]);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
@@ -588,21 +521,8 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T
|
||||
return EMPTY_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return 0;
|
||||
int result = 0;
|
||||
if(containsNull && filter.TEST_VALUE(keys[nullIndex])) result++;
|
||||
for(int i = nullIndex-1;i>=0;i--) {
|
||||
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE) && filter.TEST_VALUE(keys[i])) result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private class SetIterator implements ITERATOR KEY_GENERIC_TYPE {
|
||||
int pos = nullIndex;
|
||||
int returnedPos = -1;
|
||||
int lastReturned = -1;
|
||||
int nextIndex = Integer.MIN_VALUE;
|
||||
boolean returnNull = containsNull;
|
||||
@@ -635,7 +555,6 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T
|
||||
@Override
|
||||
public KEY_TYPE NEXT() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
returnedPos = pos;
|
||||
if(nextIndex < 0){
|
||||
lastReturned = Integer.MAX_VALUE;
|
||||
KEY_TYPE value = wrapped.GET_KEY(nextIndex);
|
||||
@@ -654,10 +573,9 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T
|
||||
containsNull = false;
|
||||
keys[nullIndex] = EMPTY_KEY_VALUE;
|
||||
}
|
||||
else if(returnedPos >= 0) shiftKeys(returnedPos);
|
||||
else if(pos >= 0) shiftKeys(pos);
|
||||
else {
|
||||
CUSTOM_HASH_SET.this.remove(wrapped.GET_KEY(-returnedPos - 1));
|
||||
lastReturned = -1;
|
||||
CUSTOM_HASH_SET.this.remove(wrapped.GET_KEY(-pos - 1));
|
||||
return;
|
||||
}
|
||||
size--;
|
||||
|
||||
+7
-89
@@ -2,13 +2,11 @@ package speiger.src.collections.PACKAGE.sets;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.ConcurrentModificationException;
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Objects;
|
||||
#if TYPE_OBJECT
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.BiFunction;
|
||||
#endif
|
||||
|
||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||
@@ -19,9 +17,8 @@ import speiger.src.collections.PACKAGE.lists.LIST;
|
||||
import speiger.src.collections.PACKAGE.utils.ITERATORS;
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
#endif
|
||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||
import speiger.src.collections.PACKAGE.functions.consumer.BI_OBJECT_CONSUMER;
|
||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||
import speiger.src.collections.utils.HashUtil;
|
||||
import speiger.src.collections.utils.ITrimmable;
|
||||
import speiger.src.collections.utils.SanityChecks;
|
||||
@@ -340,12 +337,12 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
||||
public <E> void forEach(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE<E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
if(size() <= 0) return;
|
||||
if(containsNull) action.accept(input, keys[nullIndex]);
|
||||
if(containsNull) action.accept(keys[nullIndex], input);
|
||||
for(int i = nullIndex-1;i>=0;i--) {
|
||||
if(KEY_EQUALS_NOT_NULL(keys[i])) action.accept(input, keys[i]);
|
||||
if(KEY_EQUALS_NOT_NULL(keys[i])) action.accept(keys[i], input);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -382,54 +379,6 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
|
||||
return true;
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = identity;
|
||||
if(containsNull) state = operator.APPLY_VALUE(state, keys[nullIndex]);
|
||||
for(int i = nullIndex-1;i>=0;i--) {
|
||||
if(KEY_EQUALS_NULL(keys[i])) continue;
|
||||
state = operator.APPLY_VALUE(state, keys[i]);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
#else
|
||||
@Override
|
||||
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_SPECIAL_TYPE state = identity;
|
||||
if(containsNull) state = operator.APPLY_VALUE(state, keys[nullIndex]);
|
||||
for(int i = nullIndex-1;i>=0;i--) {
|
||||
if(KEY_EQUALS_NULL(keys[i])) continue;
|
||||
state = operator.APPLY_VALUE(state, keys[i]);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = EMPTY_VALUE;
|
||||
boolean empty = true;
|
||||
if(containsNull) {
|
||||
state = keys[nullIndex];
|
||||
empty = false;
|
||||
}
|
||||
for(int i = 0;i<size;i++) {
|
||||
if(KEY_EQUALS_NULL(keys[i])) continue;
|
||||
if(empty) {
|
||||
empty = false;
|
||||
state = keys[i];
|
||||
continue;
|
||||
}
|
||||
state = operator.APPLY_VALUE(state, keys[i]);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
@@ -441,18 +390,6 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
|
||||
return EMPTY_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return 0;
|
||||
int result = 0;
|
||||
if(containsNull && filter.TEST_VALUE(keys[nullIndex])) result++;
|
||||
for(int i = nullIndex-1;i>=0;i--) {
|
||||
if(KEY_EQUALS_NOT_NULL(keys[i]) && filter.TEST_VALUE(keys[i])) result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void ensureCapacity(int newCapacity) {
|
||||
int size = HashUtil.arraySize(newCapacity, loadFactor);
|
||||
if(size > nullIndex) rehash(size);
|
||||
@@ -512,10 +449,7 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
|
||||
int newMask = newSize - 1;
|
||||
KEY_TYPE[] newKeys = NEW_KEY_ARRAY(newSize + 1);
|
||||
for(int i = nullIndex, pos = 0, j = (size - (containsNull ? 1 : 0));j-- != 0;) {
|
||||
while(true) {
|
||||
if(--i < 0) throw new ConcurrentModificationException("Set was modified during rehash");
|
||||
if(KEY_EQUALS_NOT_NULL(keys[i])) break;
|
||||
}
|
||||
while(KEY_EQUALS_NULL(keys[--i]));
|
||||
if(KEY_EQUALS_NOT_NULL(newKeys[pos = HashUtil.mix(KEY_TO_HASH(keys[i])) & newMask]))
|
||||
while(KEY_EQUALS_NOT_NULL(newKeys[pos = (++pos & newMask)]));
|
||||
newKeys[pos] = keys[i];
|
||||
@@ -531,19 +465,6 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
|
||||
return new SetIterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public HASH_SET KEY_GENERIC_TYPE copy() {
|
||||
HASH_SET KEY_GENERIC_TYPE set = new HASH_SETBRACES(0, loadFactor);
|
||||
set.minCapacity = minCapacity;
|
||||
set.mask = mask;
|
||||
set.maxFill = maxFill;
|
||||
set.nullIndex = nullIndex;
|
||||
set.containsNull = containsNull;
|
||||
set.size = size;
|
||||
set.keys = Arrays.copyOf(keys, keys.length);
|
||||
return set;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
if(size == 0) return;
|
||||
@@ -559,7 +480,6 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
|
||||
|
||||
private class SetIterator implements ITERATOR KEY_GENERIC_TYPE {
|
||||
int pos = nullIndex;
|
||||
int returnedPos = -1;
|
||||
int lastReturned = -1;
|
||||
int nextIndex = Integer.MIN_VALUE;
|
||||
boolean returnNull = containsNull;
|
||||
@@ -593,7 +513,6 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
|
||||
@Override
|
||||
public KEY_TYPE NEXT() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
returnedPos = pos;
|
||||
if(nextIndex < 0){
|
||||
lastReturned = Integer.MAX_VALUE;
|
||||
KEY_TYPE value = wrapped.GET_KEY(nextIndex);
|
||||
@@ -612,10 +531,9 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
|
||||
containsNull = false;
|
||||
keys[nullIndex] = EMPTY_KEY_VALUE;
|
||||
}
|
||||
else if(returnedPos >= 0) shiftKeys(returnedPos);
|
||||
else if(pos >= 0) shiftKeys(pos);
|
||||
else {
|
||||
HASH_SET.this.remove(wrapped.GET_KEY(-returnedPos - 1));
|
||||
lastReturned = -1;
|
||||
HASH_SET.this.remove(wrapped.GET_KEY(-pos - 1));
|
||||
return;
|
||||
}
|
||||
size--;
|
||||
|
||||
+6
-144
@@ -4,7 +4,6 @@ import java.util.Collection;
|
||||
#if TYPE_OBJECT
|
||||
import java.util.Comparator;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.BiFunction;
|
||||
#endif
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
@@ -14,9 +13,8 @@ import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
#endif
|
||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||
import speiger.src.collections.PACKAGE.functions.consumer.BI_OBJECT_CONSUMER;
|
||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
|
||||
@@ -213,9 +211,6 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
#endif
|
||||
@Override
|
||||
public boolean add(KEY_TYPE o) {
|
||||
#if TYPE_OBJECT
|
||||
validate(o);
|
||||
#endif
|
||||
if(tree == null) {
|
||||
tree = first = last = new EntryBRACES(o, null);
|
||||
size++;
|
||||
@@ -245,7 +240,7 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
}
|
||||
fixAfterInsertion(adding);
|
||||
size++;
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -309,10 +304,10 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
||||
public <E> void forEach(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE<E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next())
|
||||
action.accept(input, entry.key);
|
||||
action.accept(entry.key, input);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -342,45 +337,6 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
return true;
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = identity;
|
||||
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) {
|
||||
state = operator.APPLY_VALUE(state, entry.key);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
#else
|
||||
@Override
|
||||
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_SPECIAL_TYPE state = identity;
|
||||
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) {
|
||||
state = operator.APPLY_VALUE(state, entry.key);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = EMPTY_VALUE;
|
||||
boolean empty = true;
|
||||
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) {
|
||||
if(empty) {
|
||||
empty = false;
|
||||
state = entry.key;
|
||||
continue;
|
||||
}
|
||||
state = operator.APPLY_VALUE(state, entry.key);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
@@ -390,16 +346,6 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
return EMPTY_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
int result = 0;
|
||||
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) {
|
||||
if(filter.TEST_VALUE(entry.key)) result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
protected Entry KEY_GENERIC_TYPE findNode(KEY_TYPE o) {
|
||||
Entry KEY_GENERIC_TYPE node = tree;
|
||||
int compare;
|
||||
@@ -584,21 +530,6 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
tree = null;
|
||||
}
|
||||
|
||||
public RB_TREE_SET KEY_GENERIC_TYPE copy() {
|
||||
RB_TREE_SET KEY_GENERIC_TYPE set = new RB_TREE_SETBRACES();
|
||||
set.size = size;
|
||||
if(tree != null) {
|
||||
set.tree = tree.copy();
|
||||
Entry KEY_GENERIC_TYPE lastFound = null;
|
||||
for(Entry KEY_GENERIC_TYPE entry = tree;entry != null;entry = entry.left) lastFound = entry;
|
||||
set.first = lastFound;
|
||||
lastFound = null;
|
||||
for(Entry KEY_GENERIC_TYPE entry = tree;entry != null;entry = entry.right) lastFound = entry;
|
||||
set.last = lastFound;
|
||||
}
|
||||
return set;
|
||||
}
|
||||
|
||||
@Override
|
||||
public COMPARATOR KEY_GENERIC_TYPE comparator() { return comparator; }
|
||||
|
||||
@@ -663,7 +594,6 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
}
|
||||
}
|
||||
|
||||
protected void validate(KEY_TYPE k) { compare(k, k); }
|
||||
protected int compare(KEY_TYPE k, KEY_TYPE v) { return comparator != null ? comparator.compare(k, v) : COMPAREABLE_TO_KEY(k, v);}
|
||||
protected static GENERIC_KEY_BRACES boolean isBlack(Entry KEY_GENERIC_TYPE p) { return p == null || p.isBlack(); }
|
||||
protected static GENERIC_KEY_BRACES Entry KEY_GENERIC_TYPE parentOf(Entry KEY_GENERIC_TYPE p) { return (p == null ? null : p.parent); }
|
||||
@@ -1130,9 +1060,6 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
return fromStart && toEnd ? set.size() : iterator().skip(Integer.MAX_VALUE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SubSet KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) {
|
||||
Objects.requireNonNull(action);
|
||||
@@ -1142,10 +1069,10 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
||||
public <E> void forEach(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE<E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
for(Entry KEY_GENERIC_TYPE entry = start();entry != null && inRange(entry.key);entry = next(entry))
|
||||
action.accept(input, entry.key);
|
||||
action.accept(entry.key, input);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1175,45 +1102,6 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
return true;
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = identity;
|
||||
for(Entry KEY_GENERIC_TYPE entry = start();entry != null && inRange(entry.key);entry = next(entry)) {
|
||||
state = operator.APPLY_VALUE(state, entry.key);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
#else
|
||||
@Override
|
||||
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_SPECIAL_TYPE state = identity;
|
||||
for(Entry KEY_GENERIC_TYPE entry = start();entry != null && inRange(entry.key);entry = next(entry)) {
|
||||
state = operator.APPLY_VALUE(state, entry.key);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = EMPTY_VALUE;
|
||||
boolean empty = true;
|
||||
for(Entry KEY_GENERIC_TYPE entry = start();entry != null && inRange(entry.key);entry = next(entry)) {
|
||||
if(empty) {
|
||||
empty = false;
|
||||
state = entry.key;
|
||||
continue;
|
||||
}
|
||||
state = operator.APPLY_VALUE(state, entry.key);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
@@ -1223,16 +1111,6 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
return EMPTY_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
int result = 0;
|
||||
for(Entry KEY_GENERIC_TYPE entry = start();entry != null && inRange(entry.key);entry = next(entry)) {
|
||||
if(filter.TEST_VALUE(entry.key)) result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
class SubSetIterator implements LIST_ITERATOR KEY_GENERIC_TYPE
|
||||
{
|
||||
Entry KEY_GENERIC_TYPE previous;
|
||||
@@ -1416,22 +1294,6 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
Entry KEY_GENERIC_TYPE copy() {
|
||||
Entry KEY_GENERIC_TYPE entry = new EntryBRACES(key, null);
|
||||
entry.state = state;
|
||||
if(left != null) {
|
||||
Entry KEY_GENERIC_TYPE newLeft = left.copy();
|
||||
entry.left = newLeft;
|
||||
newLeft.parent = entry;
|
||||
}
|
||||
if(right != null) {
|
||||
Entry KEY_GENERIC_TYPE newRight = right.copy();
|
||||
entry.right = newRight;
|
||||
newRight.parent = entry;
|
||||
}
|
||||
return entry;
|
||||
}
|
||||
|
||||
boolean isBlack() {
|
||||
return (state & BLACK) != 0;
|
||||
}
|
||||
|
||||
@@ -5,12 +5,8 @@ import java.util.Set;
|
||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.collections.SPLIT_ITERATOR;
|
||||
#if !TYPE_BOOLEAN
|
||||
import speiger.src.collections.PACKAGE.utils.SETS;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
||||
|
||||
|
||||
/**
|
||||
* A Type Specific Set class to reduce boxing/unboxing
|
||||
* @Type(T)
|
||||
@@ -20,9 +16,6 @@ public interface SET KEY_GENERIC_TYPE extends Set<CLASS_TYPE>, COLLECTION KEY_GE
|
||||
@Override
|
||||
public ITERATOR KEY_GENERIC_TYPE iterator();
|
||||
|
||||
@Override
|
||||
public SET KEY_GENERIC_TYPE copy();
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
/**
|
||||
* A Type Specific remove function to reduce boxing/unboxing
|
||||
@@ -53,31 +46,6 @@ public interface SET KEY_GENERIC_TYPE extends Set<CLASS_TYPE>, COLLECTION KEY_GE
|
||||
public default boolean remove(Object o) {
|
||||
return COLLECTION.super.remove(o);
|
||||
}
|
||||
|
||||
#endif
|
||||
#if !TYPE_BOOLEAN
|
||||
/**
|
||||
* Creates a Wrapped Set that is Synchronized
|
||||
* @return a new Set that is synchronized
|
||||
* @see SETS#synchronize
|
||||
*/
|
||||
public default SET KEY_GENERIC_TYPE synchronize() { return SETS.synchronize(this); }
|
||||
|
||||
/**
|
||||
* Creates a Wrapped Set that is Synchronized
|
||||
* @param mutex is the controller of the synchronization block
|
||||
* @return a new Set Wrapper that is synchronized
|
||||
* @see SETS#synchronize
|
||||
*/
|
||||
public default SET KEY_GENERIC_TYPE synchronize(Object mutex) { return SETS.synchronize(this, mutex); }
|
||||
|
||||
/**
|
||||
* Creates a Wrapped Set that is unmodifiable
|
||||
* @return a new Set Wrapper that is unmodifiable
|
||||
* @see SETS#unmodifiable
|
||||
*/
|
||||
public default SET KEY_GENERIC_TYPE unmodifiable() { return SETS.unmodifiable(this); }
|
||||
|
||||
#endif
|
||||
/**
|
||||
* A Type Specific Type Splititerator to reduce boxing/unboxing
|
||||
|
||||
@@ -9,7 +9,6 @@ import java.util.Comparator;
|
||||
#else
|
||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.utils.SETS;
|
||||
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
||||
|
||||
/**
|
||||
@@ -61,9 +60,6 @@ public interface SORTED_SET KEY_GENERIC_TYPE extends SET KEY_GENERIC_TYPE, Sorte
|
||||
@Override
|
||||
public COMPARATOR KEY_GENERIC_TYPE comparator();
|
||||
|
||||
@Override
|
||||
public SORTED_SET KEY_GENERIC_TYPE copy();
|
||||
|
||||
@Override
|
||||
public BI_ITERATOR KEY_GENERIC_TYPE iterator();
|
||||
/**
|
||||
@@ -74,30 +70,6 @@ public interface SORTED_SET KEY_GENERIC_TYPE extends SET KEY_GENERIC_TYPE, Sorte
|
||||
*/
|
||||
public BI_ITERATOR KEY_GENERIC_TYPE iterator(KEY_TYPE fromElement);
|
||||
|
||||
#if !TYPE_BOOLEAN
|
||||
/**
|
||||
* Creates a Wrapped SortedSet that is Synchronized
|
||||
* @return a new SortedSet that is synchronized
|
||||
* @see SETS#synchronize
|
||||
*/
|
||||
public default SORTED_SET KEY_GENERIC_TYPE synchronize() { return SETS.synchronize(this); }
|
||||
|
||||
/**
|
||||
* Creates a Wrapped SortedSet that is Synchronized
|
||||
* @param mutex is the controller of the synchronization block
|
||||
* @return a new SortedSet Wrapper that is synchronized
|
||||
* @see SETS#synchronize
|
||||
*/
|
||||
public default SORTED_SET KEY_GENERIC_TYPE synchronize(Object mutex) { return SETS.synchronize(this, mutex); }
|
||||
|
||||
/**
|
||||
* Creates a Wrapped SortedSet that is unmodifiable
|
||||
* @return a new SortedSet Wrapper that is unmodifiable
|
||||
* @see SETS#unmodifiable
|
||||
*/
|
||||
public default SORTED_SET KEY_GENERIC_TYPE unmodifiable() { return SETS.unmodifiable(this); }
|
||||
|
||||
#endif
|
||||
/**
|
||||
* A Type Specific Type Splititerator to reduce boxing/unboxing
|
||||
* @return type specific splititerator
|
||||
|
||||
+5
-67
@@ -1,9 +1,6 @@
|
||||
package speiger.src.collections.PACKAGE.utils;
|
||||
|
||||
import java.util.Collection;
|
||||
#if TYPE_OBJECT
|
||||
import java.util.function.BiFunction;
|
||||
#endif
|
||||
import java.util.function.Predicate;
|
||||
#if PRIMITIVES
|
||||
import java.util.function.JAVA_PREDICATE;
|
||||
@@ -18,9 +15,7 @@ import speiger.src.collections.objects.utils.ObjectArrays;
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||
|
||||
/**
|
||||
* A Helper class for Collections
|
||||
*/
|
||||
@@ -97,16 +92,18 @@ public class COLLECTIONS
|
||||
public boolean add(KEY_TYPE o) { synchronized(mutex) { return c.add(o); } }
|
||||
@Override
|
||||
public boolean addAll(Collection<? extends CLASS_TYPE> c) { synchronized(mutex) { return this.c.addAll(c); } }
|
||||
|
||||
@Override
|
||||
public boolean addAll(COLLECTION KEY_GENERIC_TYPE c) { synchronized(mutex) { return this.c.addAll(c); } }
|
||||
@Override
|
||||
public boolean addAll(KEY_TYPE[] e, int offset, int length) { synchronized(mutex) { return c.addAll(e, offset, length); } }
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public boolean contains(KEY_TYPE o) { synchronized(mutex) { return c.contains(o); } }
|
||||
|
||||
#else
|
||||
@Override
|
||||
public boolean contains(Object o) { synchronized(mutex) { return c.contains(o); } }
|
||||
|
||||
#endif
|
||||
@Override
|
||||
@Primitive
|
||||
@@ -133,9 +130,6 @@ public class COLLECTIONS
|
||||
return c.iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public COLLECTION KEY_GENERIC_TYPE copy() { synchronized(mutex) { return c.copy(); } }
|
||||
|
||||
@Override
|
||||
@Primitive
|
||||
public boolean remove(Object o) { synchronized(mutex) { return c.remove(o); } }
|
||||
@@ -152,11 +146,7 @@ public class COLLECTIONS
|
||||
@Override
|
||||
public boolean removeAll(COLLECTION KEY_GENERIC_TYPE c) { synchronized(mutex) { return this.c.removeAll(c); } }
|
||||
@Override
|
||||
public boolean removeAll(COLLECTION KEY_GENERIC_TYPE c, CONSUMER KEY_GENERIC_TYPE r) { synchronized(mutex) { return this.c.removeAll(c, r); } }
|
||||
@Override
|
||||
public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c) { synchronized(mutex) { return this.c.retainAll(c); } }
|
||||
@Override
|
||||
public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c, CONSUMER KEY_GENERIC_TYPE r) { synchronized(mutex) { return this.c.retainAll(c, r); } }
|
||||
#if PRIMITIVES
|
||||
@Override
|
||||
public boolean remIf(JAVA_PREDICATE filter){ synchronized(mutex) { return c.remIf(filter); } }
|
||||
@@ -189,26 +179,6 @@ public class COLLECTIONS
|
||||
public boolean equals(Object obj) { synchronized(mutex) { return c.equals(obj); } }
|
||||
@Override
|
||||
public String toString() { synchronized(mutex) { return c.toString(); } }
|
||||
@Override
|
||||
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) { synchronized(mutex) { c.forEach(input, action); } }
|
||||
@Override
|
||||
public boolean matchesAny(PREDICATE KEY_GENERIC_TYPE filter) { synchronized(mutex) { return c.matchesAny(filter); } }
|
||||
@Override
|
||||
public boolean matchesNone(PREDICATE KEY_GENERIC_TYPE filter) { synchronized(mutex) { return c.matchesNone(filter); } }
|
||||
@Override
|
||||
public boolean matchesAll(PREDICATE KEY_GENERIC_TYPE filter) { synchronized(mutex) { return c.matchesAll(filter); } }
|
||||
#if TYPE_OBJECT
|
||||
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) { synchronized(mutex) { return c.reduce(identity, operator); } }
|
||||
#else
|
||||
@Override
|
||||
public KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) { synchronized(mutex) { return c.reduce(identity, operator); } }
|
||||
#endif
|
||||
@Override
|
||||
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) { synchronized(mutex) { return c.reduce(operator); } }
|
||||
@Override
|
||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) { synchronized(mutex) { return c.findFirst(filter); } }
|
||||
@Override
|
||||
public int count(PREDICATE KEY_GENERIC_TYPE filter) { synchronized(mutex) { return c.count(filter); } }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -228,8 +198,6 @@ public class COLLECTIONS
|
||||
public boolean addAll(Collection<? extends CLASS_TYPE> c) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean addAll(COLLECTION KEY_GENERIC_TYPE c) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean addAll(KEY_TYPE[] e, int offset, int length) { throw new UnsupportedOperationException(); }
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public boolean contains(KEY_TYPE o) { return c.contains(o); }
|
||||
@@ -254,8 +222,6 @@ public class COLLECTIONS
|
||||
@Override
|
||||
public ITERATOR KEY_GENERIC_TYPE iterator() { return ITERATORS.unmodifiable(c.iterator()); }
|
||||
@Override
|
||||
public COLLECTION KEY_GENERIC_TYPE copy() { return c.copy(); }
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean remove(Object o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
@@ -274,11 +240,7 @@ public class COLLECTIONS
|
||||
@Override
|
||||
public boolean removeAll(COLLECTION KEY_GENERIC_TYPE c) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean removeAll(COLLECTION KEY_GENERIC_TYPE c, CONSUMER KEY_GENERIC_TYPE r) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c, CONSUMER KEY_GENERIC_TYPE r) { throw new UnsupportedOperationException(); }
|
||||
#if PRIMITIVES
|
||||
@Override
|
||||
public boolean remIf(JAVA_PREDICATE filter){ throw new UnsupportedOperationException(); }
|
||||
@@ -311,26 +273,6 @@ public class COLLECTIONS
|
||||
public boolean equals(Object obj) { return c.equals(obj); }
|
||||
@Override
|
||||
public String toString() { return c.toString(); }
|
||||
@Override
|
||||
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) { c.forEach(input, action); }
|
||||
@Override
|
||||
public boolean matchesAny(PREDICATE KEY_GENERIC_TYPE filter) { return c.matchesAny(filter); }
|
||||
@Override
|
||||
public boolean matchesNone(PREDICATE KEY_GENERIC_TYPE filter) { return c.matchesNone(filter); }
|
||||
@Override
|
||||
public boolean matchesAll(PREDICATE KEY_GENERIC_TYPE filter) { return c.matchesAll(filter); }
|
||||
#if TYPE_OBJECT
|
||||
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) { return c.reduce(identity, operator); }
|
||||
#else
|
||||
@Override
|
||||
public KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) { return c.reduce(identity, operator); }
|
||||
#endif
|
||||
@Override
|
||||
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) { return c.reduce(operator); }
|
||||
@Override
|
||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) { return c.findFirst(filter); }
|
||||
@Override
|
||||
public int count(PREDICATE KEY_GENERIC_TYPE filter) { return c.count(filter); }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -343,8 +285,6 @@ public class COLLECTIONS
|
||||
|
||||
@Override
|
||||
public boolean addAll(COLLECTION KEY_GENERIC_TYPE c) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean addAll(KEY_TYPE[] e, int offset, int length) { throw new UnsupportedOperationException(); }
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
@@ -416,7 +356,5 @@ public class COLLECTIONS
|
||||
public void clear() {}
|
||||
@Override
|
||||
public int size() { return 0; }
|
||||
@Override
|
||||
public EmptyCollection KEY_GENERIC_TYPE copy() { return this; }
|
||||
}
|
||||
}
|
||||
@@ -1,43 +1,19 @@
|
||||
package speiger.src.collections.PACKAGE.utils;
|
||||
|
||||
import java.util.Objects;
|
||||
#if TYPE_BOOLEAN
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
#endif
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import speiger.src.collections.PACKAGE.collections.ITERABLE;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.objects.collections.ObjectIterable;
|
||||
import speiger.src.collections.objects.collections.ObjectIterator;
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.functions.function.TO_OBJECT_FUNCTION;
|
||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||
#if !TYPE_BOOLEAN
|
||||
import speiger.src.collections.PACKAGE.sets.HASH_SET;
|
||||
import speiger.src.collections.PACKAGE.sets.SET;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* A Helper class for Iterables
|
||||
*/
|
||||
public class ITERABLES
|
||||
{
|
||||
/**
|
||||
* A Helper function that maps a Java-Iterable into a new Type.
|
||||
* @param iterable the iterable that should be mapped
|
||||
* @param mapper the function that decides what the result turns into.
|
||||
* @Type(T)
|
||||
* @param <E> The return type.
|
||||
* @return a iterable that is mapped to a new result
|
||||
*/
|
||||
public static GENERIC_KEY_SPECIAL_BRACES<E> ObjectIterable<E> map(Iterable<? extends CLASS_TYPE> iterable, TO_OBJECT_FUNCTION KKS_GENERIC_TYPE<E> mapper) {
|
||||
return new MappedIterable<>(wrap(iterable), mapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that maps a Iterable into a new Type.
|
||||
* @param iterable the iterable that should be mapped
|
||||
@@ -50,19 +26,6 @@ public class ITERABLES
|
||||
return new MappedIterable<>(iterable, mapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that flatMaps a Java-Iterable into a new Type.
|
||||
* @param iterable the iterable that should be flatMapped
|
||||
* @param mapper the function that decides what the result turns into.
|
||||
* @Type(T)
|
||||
* @param <V> The return type supplier.
|
||||
* @param <E> The return type.
|
||||
* @return a iterable that is flatMapped to a new result
|
||||
*/
|
||||
public static GENERIC_KEY_SPECIAL_BRACES<E, V extends Iterable<E>> ObjectIterable<E> flatMap(Iterable<? extends CLASS_TYPE> iterable, TO_OBJECT_FUNCTION KKS_GENERIC_TYPE<V> mapper) {
|
||||
return new FlatMappedIterable<>(wrap(iterable), mapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that flatMaps a Iterable into a new Type.
|
||||
* @param iterable the iterable that should be flatMapped
|
||||
@@ -76,18 +39,6 @@ public class ITERABLES
|
||||
return new FlatMappedIterable<>(iterable, mapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that flatMaps a Java-Iterable into a new Type.
|
||||
* @param iterable the iterable that should be flatMapped
|
||||
* @param mapper the function that decides what the result turns into.
|
||||
* @Type(T)
|
||||
* @param <E> The return type.
|
||||
* @return a iterable that is flatMapped to a new result
|
||||
*/
|
||||
public static GENERIC_KEY_SPECIAL_BRACES<E> ObjectIterable<E> arrayFlatMap(Iterable<? extends CLASS_TYPE> iterable, TO_OBJECT_FUNCTION KKS_GENERIC_TYPE<E[]> mapper) {
|
||||
return new FlatMappedArrayIterable<>(wrap(iterable), mapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that flatMaps a Iterable into a new Type.
|
||||
* @param iterable the iterable that should be flatMapped
|
||||
@@ -100,17 +51,6 @@ public class ITERABLES
|
||||
return new FlatMappedArrayIterable<>(iterable, mapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that filters out all desired elements from a Java-Iterable
|
||||
* @param iterable that should be filtered.
|
||||
* @param filter the filter that decides that should be let through
|
||||
* @Type(T)
|
||||
* @return a filtered iterable
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES ITERABLE KEY_GENERIC_TYPE filter(Iterable<? extends CLASS_TYPE> iterable, PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
return new FilteredIterableBRACES(wrap(iterable), filter);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that filters out all desired elements
|
||||
* @param iterable that should be filtered.
|
||||
@@ -122,106 +62,6 @@ public class ITERABLES
|
||||
return new FilteredIterableBRACES(iterable, filter);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that filters out all duplicated elements.
|
||||
* @param iterable that should be distinct
|
||||
* @Type(T)
|
||||
* @return a distinct iterable
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES ITERABLE KEY_GENERIC_TYPE distinct(ITERABLE KEY_GENERIC_TYPE iterable) {
|
||||
return new DistinctIterableBRACES(iterable);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that filters out all duplicated elements from a Java Iterable.
|
||||
* @param iterable that should be distinct
|
||||
* @Type(T)
|
||||
* @return a distinct iterable
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES ITERABLE KEY_GENERIC_TYPE distinct(Iterable<? extends CLASS_TYPE> iterable) {
|
||||
return new DistinctIterableBRACES(wrap(iterable));
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that hard limits the Iterable to a specific size
|
||||
* @param iterable that should be limited
|
||||
* @param limit the amount of elements it should be limited to
|
||||
* @Type(T)
|
||||
* @return a limited iterable
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES ITERABLE KEY_GENERIC_TYPE limit(ITERABLE KEY_GENERIC_TYPE iterable, long limit) {
|
||||
return new LimitedIterableBRACES(iterable, limit);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that hard limits the Iterable to a specific size from a Java Iterable
|
||||
* @param iterable that should be limited
|
||||
* @param limit the amount of elements it should be limited to
|
||||
* @Type(T)
|
||||
* @return a limited iterable
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES ITERABLE KEY_GENERIC_TYPE limit(Iterable<? extends CLASS_TYPE> iterable, long limit) {
|
||||
return new LimitedIterableBRACES(wrap(iterable), limit);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that allows to preview the result of a Iterable.
|
||||
* @param iterable that should be peeked at
|
||||
* @param action callback that receives the value before the iterable returns it
|
||||
* @Type(T)
|
||||
* @return a peeked iterable
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES ITERABLE KEY_GENERIC_TYPE peek(ITERABLE KEY_GENERIC_TYPE iterable, CONSUMER KEY_GENERIC_TYPE action) {
|
||||
return new PeekIterableBRACES(iterable, action);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that allows to preview the result of a Iterable from a Java Iterable
|
||||
* @param iterable that should be peeked at
|
||||
* @param action callback that receives the value before the iterable returns it
|
||||
* @Type(T)
|
||||
* @return a peeked iterable
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES ITERABLE KEY_GENERIC_TYPE peek(Iterable<? extends CLASS_TYPE> iterable, CONSUMER KEY_GENERIC_TYPE action) {
|
||||
return new PeekIterableBRACES(wrap(iterable), action);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Wrapper function that wraps a Java-Iterable into a Type Specific Iterable
|
||||
* @param iterable that should be wrapped
|
||||
* @Type(T)
|
||||
* @return a type specific iterable
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES ITERABLE KEY_GENERIC_TYPE wrap(Iterable<? extends CLASS_TYPE> iterable) {
|
||||
return new WrappedIterableBRACES(iterable);
|
||||
}
|
||||
|
||||
private static class WrappedIterable KEY_GENERIC_TYPE implements ITERABLE KEY_GENERIC_TYPE
|
||||
{
|
||||
Iterable<? extends CLASS_TYPE> iterable;
|
||||
|
||||
public WrappedIterable(Iterable<? extends CLASS_TYPE> iterable) {
|
||||
this.iterable = iterable;
|
||||
}
|
||||
|
||||
public ITERATOR KEY_GENERIC_TYPE iterator() {
|
||||
return ITERATORS.wrap(iterable.iterator());
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public void forEach(CONSUMER action) {
|
||||
Objects.requireNonNull(action);
|
||||
iterable.forEach(action);
|
||||
}
|
||||
#else
|
||||
public void forEach(Consumer<? super CLASS_TYPE> action) {
|
||||
Objects.requireNonNull(action);
|
||||
iterable.forEach(action);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
private static class MappedIterable KSS_GENERIC_TYPE<E, T> implements ObjectIterable<T>
|
||||
{
|
||||
ITERABLE KEY_SPECIAL_GENERIC_TYPE<E> iterable;
|
||||
@@ -235,12 +75,6 @@ public class ITERABLES
|
||||
public ObjectIterator<T> iterator() {
|
||||
return ITERATORS.map(iterable.iterator(), mapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEach(Consumer<? super T> action) {
|
||||
Objects.requireNonNull(action);
|
||||
iterable.forEach(E -> action.accept(mapper.GET_VALUE(E)));
|
||||
}
|
||||
}
|
||||
|
||||
private static class FlatMappedIterable KSS_GENERIC_TYPE<E, T,[SPACE]V extends Iterable<T>> implements ObjectIterable<T>
|
||||
@@ -257,13 +91,6 @@ public class ITERABLES
|
||||
public ObjectIterator<T> iterator() {
|
||||
return ITERATORS.flatMap(iterable.iterator(), mapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEach(Consumer<? super T> action) {
|
||||
Objects.requireNonNull(action);
|
||||
iterable.forEach(E -> mapper.GET_VALUE(E).forEach(action));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class FlatMappedArrayIterable KSS_GENERIC_TYPE<E, T> implements ObjectIterable<T>
|
||||
@@ -280,15 +107,6 @@ public class ITERABLES
|
||||
public ObjectIterator<T> iterator() {
|
||||
return ITERATORS.arrayFlatMap(iterable.iterator(), mapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEach(Consumer<? super T> action) {
|
||||
Objects.requireNonNull(action);
|
||||
iterable.forEach(E -> {
|
||||
T[] array = mapper.GET_VALUE(E);
|
||||
for(int i = 0,m=array.length;i<m;action.accept(array[i++]));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private static class FilteredIterable KEY_GENERIC_TYPE implements ITERABLE KEY_GENERIC_TYPE
|
||||
@@ -305,124 +123,5 @@ public class ITERABLES
|
||||
public ITERATOR KEY_GENERIC_TYPE iterator() {
|
||||
return ITERATORS.filter(iterable.iterator(), filter);
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public void forEach(CONSUMER action) {
|
||||
Objects.requireNonNull(action);
|
||||
iterable.forEach(T -> { if(!filter.TEST_VALUE(T)) action.accept(T); } );
|
||||
}
|
||||
#else
|
||||
public void forEach(Consumer<? super CLASS_TYPE> action) {
|
||||
Objects.requireNonNull(action);
|
||||
iterable.forEach(T -> { if(!filter.TEST_VALUE(T)) action.accept(T); } );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
private static class LimitedIterable KEY_GENERIC_TYPE implements ITERABLE KEY_GENERIC_TYPE
|
||||
{
|
||||
ITERABLE KEY_GENERIC_TYPE iterable;
|
||||
long limit;
|
||||
|
||||
public LimitedIterable(ITERABLE KEY_GENERIC_TYPE iterable, long limit) {
|
||||
this.iterable = iterable;
|
||||
this.limit = limit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITERATOR KEY_GENERIC_TYPE iterator() {
|
||||
return ITERATORS.limit(iterable.iterator(), limit);
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public void forEach(CONSUMER action) {
|
||||
Objects.requireNonNull(action);
|
||||
AtomicLong counter = new AtomicLong();
|
||||
iterable.forEach(T -> {
|
||||
if(counter.get() >= limit) return;
|
||||
counter.incrementAndGet();
|
||||
action.accept(T);
|
||||
});
|
||||
}
|
||||
#else
|
||||
public void forEach(Consumer<? super CLASS_TYPE> action) {
|
||||
Objects.requireNonNull(action);
|
||||
AtomicLong counter = new AtomicLong();
|
||||
iterable.forEach(T -> {
|
||||
if(counter.get() >= limit) return;
|
||||
counter.incrementAndGet();
|
||||
action.accept(T);
|
||||
});
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
private static class DistinctIterable KEY_GENERIC_TYPE implements ITERABLE KEY_GENERIC_TYPE
|
||||
{
|
||||
ITERABLE KEY_GENERIC_TYPE iterable;
|
||||
|
||||
public DistinctIterable(ITERABLE KEY_GENERIC_TYPE iterable) {
|
||||
this.iterable = iterable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITERATOR KEY_GENERIC_TYPE iterator() {
|
||||
return ITERATORS.distinct(iterable.iterator());
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public void forEach(CONSUMER action) {
|
||||
Objects.requireNonNull(action);
|
||||
#if TYPE_BOOLEAN
|
||||
AtomicInteger result = new AtomicInteger();
|
||||
iterable.forEach(T -> {
|
||||
if(((result.get() & (T ? 2 : 1)) != 0)) return;
|
||||
result.getAndAdd(T ? 2 : 1);
|
||||
action.accept(T);
|
||||
});
|
||||
#else
|
||||
SET KEY_GENERIC_TYPE filtered = new HASH_SETBRACES();
|
||||
iterable.forEach(T -> { if(filtered.add(T)) action.accept(T); });
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
public void forEach(Consumer<? super CLASS_TYPE> action) {
|
||||
Objects.requireNonNull(action);
|
||||
SET KEY_GENERIC_TYPE filtered = new HASH_SETBRACES();
|
||||
iterable.forEach(T -> { if(filtered.add(T)) action.accept(T); });
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
private static class PeekIterable KEY_GENERIC_TYPE implements ITERABLE KEY_GENERIC_TYPE
|
||||
{
|
||||
ITERABLE KEY_GENERIC_TYPE iterable;
|
||||
CONSUMER KEY_GENERIC_TYPE action;
|
||||
|
||||
public PeekIterable(ITERABLE KEY_GENERIC_TYPE iterable, CONSUMER KEY_GENERIC_TYPE action) {
|
||||
this.iterable = iterable;
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITERATOR KEY_GENERIC_TYPE iterator() {
|
||||
return ITERATORS.peek(iterable.iterator(), action);
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public void forEach(CONSUMER action) {
|
||||
Objects.requireNonNull(action);
|
||||
iterable.forEach(this.action.andThen(action));
|
||||
}
|
||||
#else
|
||||
public void forEach(Consumer<? super CLASS_TYPE> action) {
|
||||
Objects.requireNonNull(action);
|
||||
iterable.forEach(this.action.andThen(action));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -2,15 +2,11 @@ package speiger.src.collections.PACKAGE.utils;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
#if TYPE_OBJECT
|
||||
import java.util.function.CONSUMER;
|
||||
#endif
|
||||
|
||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.objects.collections.ObjectIterator;
|
||||
import speiger.src.collections.objects.utils.ObjectIterators;
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.functions.function.TO_OBJECT_FUNCTION;
|
||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||
@@ -19,10 +15,6 @@ import speiger.src.collections.PACKAGE.lists.LIST;
|
||||
import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||
#if !TYPE_BOOLEAN
|
||||
import speiger.src.collections.PACKAGE.sets.HASH_SET;
|
||||
import speiger.src.collections.PACKAGE.sets.SET;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* A Helper class for Iterators
|
||||
@@ -97,18 +89,6 @@ public class ITERATORS
|
||||
return iterator instanceof UnmodifiableListIterator ? iterator : new UnmodifiableListIteratorBRACES(iterator);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that maps a Java-Iterator into a new Type.
|
||||
* @param iterator that should be mapped
|
||||
* @param mapper the function that decides what the result turns into.
|
||||
* @Type(T)
|
||||
* @param <E> The return type.
|
||||
* @return a iterator that is mapped to a new result
|
||||
*/
|
||||
public static GENERIC_KEY_SPECIAL_BRACES<E> ObjectIterator<E> map(Iterator<? extends CLASS_TYPE> iterator, TO_OBJECT_FUNCTION KKS_GENERIC_TYPE<E> mapper) {
|
||||
return new MappedIterator<>(wrap(iterator), mapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that maps a Iterator into a new Type.
|
||||
* @param iterator that should be mapped
|
||||
@@ -121,19 +101,6 @@ public class ITERATORS
|
||||
return new MappedIterator<>(iterator, mapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that flatMaps a Java-Iterator into a new Type.
|
||||
* @param iterator that should be flatMapped
|
||||
* @param mapper the function that decides what the result turns into.
|
||||
* @Type(T)
|
||||
* @param <V> The return type supplier.
|
||||
* @param <E> The return type.
|
||||
* @return a iterator that is flatMapped to a new result
|
||||
*/
|
||||
public static GENERIC_KEY_SPECIAL_BRACES<E, V extends Iterable<E>> ObjectIterator<E> flatMap(Iterator<? extends CLASS_TYPE> iterator, TO_OBJECT_FUNCTION KKS_GENERIC_TYPE<V> mapper) {
|
||||
return new FlatMappedIterator<>(wrap(iterator), mapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that flatMaps a Iterator into a new Type.
|
||||
* @param iterator that should be flatMapped
|
||||
@@ -147,18 +114,6 @@ public class ITERATORS
|
||||
return new FlatMappedIterator<>(iterator, mapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that flatMaps a Java-Iterator into a new Type.
|
||||
* @param iterator that should be flatMapped
|
||||
* @param mapper the function that decides what the result turns into.
|
||||
* @Type(T)
|
||||
* @param <E> The return type.
|
||||
* @return a iterator that is flatMapped to a new result
|
||||
*/
|
||||
public static GENERIC_KEY_SPECIAL_BRACES<E> ObjectIterator<E> arrayFlatMap(Iterator<? extends CLASS_TYPE> iterator, TO_OBJECT_FUNCTION KKS_GENERIC_TYPE<E[]> mapper) {
|
||||
return new FlatMappedArrayIterator<>(wrap(iterator), mapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that flatMaps a Iterator into a new Type.
|
||||
* @param iterator that should be flatMapped
|
||||
@@ -171,17 +126,6 @@ public class ITERATORS
|
||||
return new FlatMappedArrayIterator<>(iterator, mapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that filters out all desired elements from a Java-Iterator
|
||||
* @param iterator that should be filtered.
|
||||
* @param filter the filter that decides that should be let through
|
||||
* @Type(T)
|
||||
* @return a filtered iterator
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES ITERATOR KEY_GENERIC_TYPE filter(Iterator<? extends CLASS_TYPE> iterator, PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
return new FilteredIteratorBRACES(wrap(iterator), filter);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that filters out all desired elements
|
||||
* @param iterator that should be filtered.
|
||||
@@ -193,70 +137,6 @@ public class ITERATORS
|
||||
return new FilteredIteratorBRACES(iterator, filter);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that filters out all duplicated elements.
|
||||
* @param iterator that should be distinct
|
||||
* @Type(T)
|
||||
* @return a distinct iterator
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES ITERATOR KEY_GENERIC_TYPE distinct(ITERATOR KEY_GENERIC_TYPE iterator) {
|
||||
return new DistinctIteratorBRACES(iterator);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that filters out all duplicated elements from a Java Iterator.
|
||||
* @param iterator that should be distinct
|
||||
* @Type(T)
|
||||
* @return a distinct iterator
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES ITERATOR KEY_GENERIC_TYPE distinct(Iterator<? extends CLASS_TYPE> iterator) {
|
||||
return new DistinctIteratorBRACES(wrap(iterator));
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that hard limits the Iterator to a specific size
|
||||
* @param iterator that should be limited
|
||||
* @param limit the amount of elements it should be limited to
|
||||
* @Type(T)
|
||||
* @return a limited iterator
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES ITERATOR KEY_GENERIC_TYPE limit(ITERATOR KEY_GENERIC_TYPE iterator, long limit) {
|
||||
return new LimitedIteratorBRACES(iterator, limit);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that hard limits the Iterator to a specific size from a Java Iterator
|
||||
* @param iterator that should be limited
|
||||
* @param limit the amount of elements it should be limited to
|
||||
* @Type(T)
|
||||
* @return a limited iterator
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES ITERATOR KEY_GENERIC_TYPE limit(Iterator<? extends CLASS_TYPE> iterator, long limit) {
|
||||
return new LimitedIteratorBRACES(wrap(iterator), limit);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that allows to preview the result of a Iterator.
|
||||
* @param iterator that should be peeked at
|
||||
* @param action callback that receives the value before the iterator returns it
|
||||
* @Type(T)
|
||||
* @return a peeked iterator
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES ITERATOR KEY_GENERIC_TYPE peek(ITERATOR KEY_GENERIC_TYPE iterator, CONSUMER KEY_GENERIC_TYPE action) {
|
||||
return new PeekIteratorBRACES(iterator, action);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that allows to preview the result of a Iterator from a Java Iterator
|
||||
* @param iterator that should be peeked at
|
||||
* @param action callback that receives the value before the iterator returns it
|
||||
* @Type(T)
|
||||
* @return a peeked iterator
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES ITERATOR KEY_GENERIC_TYPE peek(Iterator<? extends CLASS_TYPE> iterator, CONSUMER KEY_GENERIC_TYPE action) {
|
||||
return new PeekIteratorBRACES(wrap(iterator), action);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to convert a Object Iterator into a Primitive Iterator
|
||||
* @param iterator that should be converted to a unboxing iterator
|
||||
@@ -871,57 +751,6 @@ public class ITERATORS
|
||||
}
|
||||
}
|
||||
|
||||
private static class DistinctIterator KEY_GENERIC_TYPE implements ITERATOR KEY_GENERIC_TYPE
|
||||
{
|
||||
ITERATOR KEY_GENERIC_TYPE iterator;
|
||||
#if TYPE_BOOLEAN
|
||||
int filtered;
|
||||
#else
|
||||
SET KEY_GENERIC_TYPE filtered = new HASH_SETBRACES();
|
||||
#endif
|
||||
KEY_TYPE lastFound;
|
||||
boolean foundNext = false;
|
||||
|
||||
public DistinctIterator(ITERATOR KEY_GENERIC_TYPE iterator) {
|
||||
this.iterator = iterator;
|
||||
}
|
||||
|
||||
void compute() {
|
||||
if(foundNext) return;
|
||||
#if TYPE_BOOLEAN
|
||||
if(filtered == 3) return;
|
||||
#endif
|
||||
while(iterator.hasNext()) {
|
||||
lastFound = iterator.NEXT();
|
||||
#if TYPE_BOOLEAN
|
||||
if((filtered & (lastFound ? 1 : 2)) == 0) {
|
||||
filtered |= (lastFound ? 1 : 2);
|
||||
foundNext = true;
|
||||
break;
|
||||
}
|
||||
#else
|
||||
if(filtered.add(lastFound)) {
|
||||
foundNext = true;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
compute();
|
||||
return foundNext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE NEXT() {
|
||||
if(!hasNext()) throw new IllegalStateException("End of Iterator");
|
||||
foundNext = false;
|
||||
return lastFound;
|
||||
}
|
||||
}
|
||||
|
||||
private static class FilteredIterator KEY_GENERIC_TYPE implements ITERATOR KEY_GENERIC_TYPE
|
||||
{
|
||||
ITERATOR KEY_GENERIC_TYPE iterator;
|
||||
@@ -958,51 +787,4 @@ public class ITERATORS
|
||||
return lastFound;
|
||||
}
|
||||
}
|
||||
|
||||
private static class LimitedIterator KEY_GENERIC_TYPE implements ITERATOR KEY_GENERIC_TYPE
|
||||
{
|
||||
ITERATOR KEY_GENERIC_TYPE iterator;
|
||||
long limit;
|
||||
|
||||
public LimitedIterator(ITERATOR KEY_GENERIC_TYPE iterator, long limit) {
|
||||
this.iterator = iterator;
|
||||
this.limit = limit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return limit > 0 && iterator.hasNext();
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE NEXT() {
|
||||
if(!hasNext()) throw new IllegalStateException("End of Iterator");
|
||||
limit--;
|
||||
return iterator.NEXT();
|
||||
}
|
||||
}
|
||||
|
||||
private static class PeekIterator KEY_GENERIC_TYPE implements ITERATOR KEY_GENERIC_TYPE
|
||||
{
|
||||
ITERATOR KEY_GENERIC_TYPE iterator;
|
||||
CONSUMER KEY_GENERIC_TYPE action;
|
||||
|
||||
public PeekIterator(ITERATOR KEY_GENERIC_TYPE iterator, CONSUMER KEY_GENERIC_TYPE action) {
|
||||
this.iterator = iterator;
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return iterator.hasNext();
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE NEXT() {
|
||||
if(!hasNext()) throw new IllegalStateException("End of Iterator");
|
||||
KEY_TYPE result = iterator.NEXT();
|
||||
action.accept(result);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,9 +5,6 @@ import java.util.Objects;
|
||||
import java.util.Random;
|
||||
import java.util.RandomAccess;
|
||||
import java.util.function.Consumer;
|
||||
#if PRIMITIVES
|
||||
import java.nio.JAVA_BUFFER;
|
||||
#endif
|
||||
|
||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||
#if !TYPE_OBJECT
|
||||
@@ -200,8 +197,6 @@ public class LISTS
|
||||
@Override
|
||||
public KEY_TYPE REMOVE(int index) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public KEY_TYPE swapRemove(int index) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void addElements(int from, KEY_TYPE[] a, int offset, int length) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public KEY_TYPE[] getElements(int from, KEY_TYPE[] a, int offset, int length) {
|
||||
@@ -209,10 +204,6 @@ public class LISTS
|
||||
a[offset] = element;
|
||||
return a;
|
||||
}
|
||||
#if PRIMITIVES
|
||||
@Override
|
||||
public void fillBuffer(JAVA_BUFFER buffer) { buffer.put(element); }
|
||||
#endif
|
||||
|
||||
@Override
|
||||
public void removeElements(int from, int to) { throw new UnsupportedOperationException(); }
|
||||
@@ -225,9 +216,6 @@ public class LISTS
|
||||
#endif
|
||||
@Override
|
||||
public int size() { return 1; }
|
||||
|
||||
@Override
|
||||
public SingletonList KEY_GENERIC_TYPE copy() { return new SingletonListBRACES(element); }
|
||||
}
|
||||
|
||||
private static class SynchronizedArrayList KEY_GENERIC_TYPE extends SynchronizedList KEY_GENERIC_TYPE implements IARRAY KEY_GENERIC_TYPE
|
||||
@@ -333,12 +321,6 @@ public class LISTS
|
||||
@Override
|
||||
public KEY_TYPE REMOVE(int index) { synchronized(mutex) { return l.REMOVE(index); } }
|
||||
|
||||
@Override
|
||||
public KEY_TYPE swapRemove(int index) { synchronized(mutex) { return l.swapRemove(index); } }
|
||||
|
||||
@Override
|
||||
public boolean REMOVE_SWAP(KEY_TYPE e) { synchronized(mutex) { return l.REMOVE_SWAP(e); } }
|
||||
|
||||
@Override
|
||||
@Primitive
|
||||
public int indexOf(Object e) { synchronized(mutex) { return l.indexOf(e); } }
|
||||
@@ -372,9 +354,6 @@ public class LISTS
|
||||
@Override
|
||||
public <K> K[] extractElements(int from, int to, Class<K> clz) { synchronized(mutex) { return l.extractElements(from, to, clz); } }
|
||||
|
||||
#endif
|
||||
#if PRIMITIVES
|
||||
public void fillBuffer(JAVA_BUFFER buffer) { synchronized(mutex) { l.fillBuffer(buffer); } }
|
||||
#endif
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE listIterator() {
|
||||
@@ -388,14 +367,11 @@ public class LISTS
|
||||
|
||||
@Override
|
||||
public LIST KEY_GENERIC_TYPE subList(int from, int to) {
|
||||
return LISTS.synchronize(l.subList(from, to));
|
||||
return synchronize(l.subList(from, to));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void size(int size) { synchronized(mutex) { l.size(size); } }
|
||||
|
||||
@Override
|
||||
public LIST KEY_GENERIC_TYPE copy() { synchronized(mutex) { return l.copy(); } }
|
||||
}
|
||||
|
||||
private static class UnmodifiableRandomList KEY_GENERIC_TYPE extends UnmodifiableList KEY_GENERIC_TYPE implements RandomAccess
|
||||
@@ -452,12 +428,6 @@ public class LISTS
|
||||
@Override
|
||||
public KEY_TYPE REMOVE(int index) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public KEY_TYPE swapRemove(int index) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public boolean REMOVE_SWAP(KEY_TYPE e) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
@Primitive
|
||||
public int indexOf(Object e) { return l.indexOf(e); }
|
||||
@@ -493,10 +463,6 @@ public class LISTS
|
||||
@Override
|
||||
public <K> K[] extractElements(int from, int to, Class<K> clz) { throw new UnsupportedOperationException(); }
|
||||
|
||||
#endif
|
||||
#if PRIMITIVES
|
||||
public void fillBuffer(JAVA_BUFFER buffer) { l.fillBuffer(buffer); }
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE listIterator() {
|
||||
@@ -510,14 +476,11 @@ public class LISTS
|
||||
|
||||
@Override
|
||||
public LIST KEY_GENERIC_TYPE subList(int from, int to) {
|
||||
return LISTS.unmodifiable(l.subList(from, to));
|
||||
return unmodifiable(l.subList(from, to));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void size(int size) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public LIST KEY_GENERIC_TYPE copy() { return l.copy(); }
|
||||
}
|
||||
|
||||
private static class EmptyList KEY_GENERIC_TYPE extends COLLECTIONS.EmptyCollection KEY_GENERIC_TYPE implements LIST KEY_GENERIC_TYPE
|
||||
@@ -551,12 +514,6 @@ public class LISTS
|
||||
@Override
|
||||
public KEY_TYPE REMOVE(int index) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public KEY_TYPE swapRemove(int index) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public boolean REMOVE_SWAP(KEY_TYPE e) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public int indexOf(Object e) { return -1; }
|
||||
|
||||
@@ -606,8 +563,5 @@ public class LISTS
|
||||
|
||||
@Override
|
||||
public void size(int size) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public EmptyList KEY_GENERIC_TYPE copy() { return this; }
|
||||
}
|
||||
}
|
||||
|
||||
-42
@@ -1,23 +1,15 @@
|
||||
package speiger.src.collections.PACKAGE.utils;
|
||||
|
||||
#if TYPE_OBJECT
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.function.Consumer;
|
||||
#endif
|
||||
|
||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.queues.PRIORITY_DEQUEUE;
|
||||
import speiger.src.collections.PACKAGE.queues.PRIORITY_QUEUE;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||
|
||||
/**
|
||||
* A Helper class for PriorityQueues
|
||||
@@ -94,14 +86,6 @@ public class PRIORITY_QUEUES
|
||||
public void clear() { synchronized(mutex) { queue.clear(); } }
|
||||
@Override
|
||||
public void enqueue(KEY_TYPE e) { synchronized(mutex) { queue.enqueue(e); } }
|
||||
@Override
|
||||
public void enqueueAll(KEY_TYPE[] e, int offset, int length) { synchronized(mutex) { queue.enqueueAll(e, offset, length); } }
|
||||
@Override
|
||||
public void enqueueAll(COLLECTION KEY_GENERIC_TYPE c) { synchronized(mutex) { queue.enqueueAll(c); } }
|
||||
#if TYPE_OBJECT
|
||||
@Override
|
||||
public void enqueueAll(Collection<? extends CLASS_TYPE> c) { synchronized(mutex) { queue.enqueueAll(c); } }
|
||||
#endif
|
||||
@Override
|
||||
public KEY_TYPE dequeue() { synchronized(mutex) { return queue.dequeue(); } }
|
||||
@Override
|
||||
@@ -116,22 +100,6 @@ public class PRIORITY_QUEUES
|
||||
public COMPARATOR KEY_SUPER_GENERIC_TYPE comparator() { synchronized(mutex) { return queue.comparator(); } }
|
||||
@Override
|
||||
public GENERIC_SPECIAL_KEY_BRACES<E> KEY_SPECIAL_TYPE[] TO_ARRAY(KEY_SPECIAL_TYPE[] input) { synchronized(mutex) { return queue.TO_ARRAY(input); } }
|
||||
@Override
|
||||
public PRIORITY_QUEUE KEY_GENERIC_TYPE copy() { synchronized(mutex) { return queue.copy(); } }
|
||||
@Override
|
||||
public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) { synchronized(mutex) { queue.forEach(action); } }
|
||||
@Override
|
||||
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) { synchronized(mutex) { queue.forEach(input, action); } }
|
||||
@Override
|
||||
public boolean matchesAny(PREDICATE KEY_GENERIC_TYPE filter) { synchronized(mutex) { return queue.matchesAny(filter); } }
|
||||
@Override
|
||||
public boolean matchesNone(PREDICATE KEY_GENERIC_TYPE filter) { synchronized(mutex) { return queue.matchesNone(filter); } }
|
||||
@Override
|
||||
public boolean matchesAll(PREDICATE KEY_GENERIC_TYPE filter) { synchronized(mutex) { return queue.matchesAll(filter); } }
|
||||
@Override
|
||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) { synchronized(mutex) { return queue.findFirst(filter); } }
|
||||
@Override
|
||||
public int count(PREDICATE KEY_GENERIC_TYPE filter) { synchronized(mutex) { return queue.count(filter); } }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -153,17 +121,7 @@ public class PRIORITY_QUEUES
|
||||
|
||||
@Override
|
||||
public void enqueueFirst(KEY_TYPE e) { synchronized(mutex) { dequeue.enqueueFirst(e); } }
|
||||
@Override
|
||||
public void enqueueAllFirst(KEY_TYPE[] e, int offset, int length) { synchronized(mutex) { dequeue.enqueueAllFirst(e, offset, length); } }
|
||||
@Override
|
||||
public void enqueueAllFirst(COLLECTION KEY_GENERIC_TYPE c) { synchronized(mutex) { dequeue.enqueueAllFirst(c); } }
|
||||
#if TYPE_OBJECT
|
||||
@Override
|
||||
public void enqueueAllFirst(Collection<? extends CLASS_TYPE> c) { synchronized(mutex) { dequeue.enqueueAllFirst(c); } }
|
||||
#endif
|
||||
@Override
|
||||
public KEY_TYPE dequeueLast() { synchronized(mutex) { return dequeue.dequeueLast(); } }
|
||||
@Override
|
||||
public PRIORITY_DEQUEUE KEY_GENERIC_TYPE copy() { synchronized(mutex) { return dequeue.copy(); } }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -190,9 +190,6 @@ public class SETS
|
||||
}
|
||||
@Override
|
||||
public int size() { return 1; }
|
||||
|
||||
@Override
|
||||
public SingletonSet KEY_GENERIC_TYPE copy() { return new SingletonSetBRACES(element); }
|
||||
}
|
||||
|
||||
private static class EmptySet KEY_GENERIC_TYPE extends EmptyCollection KEY_GENERIC_TYPE implements SET KEY_GENERIC_TYPE
|
||||
@@ -201,8 +198,6 @@ public class SETS
|
||||
@Override
|
||||
public boolean remove(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
#endif
|
||||
@Override
|
||||
public EmptySet KEY_GENERIC_TYPE copy() { return this; }
|
||||
}
|
||||
|
||||
#if !TYPE_BOOLEAN
|
||||
@@ -251,31 +246,28 @@ public class SETS
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, boolean fromInclusive, KEY_TYPE toElement, boolean toInclusive) { return unmodifiable(n.subSet(fromElement, fromInclusive, toElement, toInclusive)); }
|
||||
|
||||
@Override
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, boolean fromInclusive, KEY_TYPE toElement, boolean toInclusive) { return SETS.unmodifiable(n.subSet(fromElement, fromInclusive, toElement, toInclusive)); }
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement, boolean inclusive) { return unmodifiable(n.headSet(toElement, inclusive)); }
|
||||
|
||||
@Override
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement, boolean inclusive) { return SETS.unmodifiable(n.headSet(toElement, inclusive)); }
|
||||
|
||||
@Override
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement, boolean inclusive) { return SETS.unmodifiable(n.tailSet(fromElement, inclusive)); }
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement, boolean inclusive) { return unmodifiable(n.tailSet(fromElement, inclusive)); }
|
||||
|
||||
@Override
|
||||
public BI_ITERATOR KEY_GENERIC_TYPE descendingIterator() { return ITERATORS.unmodifiable(n.descendingIterator()); }
|
||||
|
||||
@Override
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE descendingSet() { return SETS.unmodifiable(n.descendingSet()); }
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE descendingSet() { return unmodifiable(n.descendingSet()); }
|
||||
|
||||
@Override
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) { return SETS.unmodifiable(n.subSet(fromElement, toElement)); }
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) { return unmodifiable(n.subSet(fromElement, toElement)); }
|
||||
|
||||
@Override
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement) { return SETS.unmodifiable(n.headSet(toElement)); }
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement) { return unmodifiable(n.headSet(toElement)); }
|
||||
|
||||
@Override
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) { return SETS.unmodifiable(n.tailSet(fromElement)); }
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) { return unmodifiable(n.tailSet(fromElement)); }
|
||||
}
|
||||
|
||||
private static class UnmodifiableSortedSet KEY_GENERIC_TYPE extends UnmodifiableSet KEY_GENERIC_TYPE implements SORTED_SET KEY_GENERIC_TYPE
|
||||
@@ -309,16 +301,13 @@ public class SETS
|
||||
public BI_ITERATOR KEY_GENERIC_TYPE iterator(KEY_TYPE fromElement) { return ITERATORS.unmodifiable(s.iterator(fromElement)); }
|
||||
|
||||
@Override
|
||||
public SORTED_SET KEY_GENERIC_TYPE copy() { return s.copy(); }
|
||||
public SORTED_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) { return unmodifiable(s.subSet(fromElement, toElement)); }
|
||||
|
||||
@Override
|
||||
public SORTED_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) { return SETS.unmodifiable(s.subSet(fromElement, toElement)); }
|
||||
public SORTED_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement) { return unmodifiable(s.headSet(toElement)); }
|
||||
|
||||
@Override
|
||||
public SORTED_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement) { return SETS.unmodifiable(s.headSet(toElement)); }
|
||||
|
||||
@Override
|
||||
public SORTED_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) { return SETS.unmodifiable(s.tailSet(fromElement)); }
|
||||
public SORTED_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) { return unmodifiable(s.tailSet(fromElement)); }
|
||||
|
||||
@Override
|
||||
public KEY_TYPE FIRST_KEY() { return s.FIRST_KEY(); }
|
||||
@@ -347,9 +336,6 @@ public class SETS
|
||||
s = c;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SET KEY_GENERIC_TYPE copy() { return s.copy(); }
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public boolean remove(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@@ -427,31 +413,28 @@ public class SETS
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE copy() { synchronized(mutex) { return n.copy(); } }
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, boolean fromInclusive, KEY_TYPE toElement, boolean toInclusive) { synchronized(mutex) { return synchronize(n.subSet(fromElement, fromInclusive, toElement, toInclusive), mutex); } }
|
||||
|
||||
@Override
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, boolean fromInclusive, KEY_TYPE toElement, boolean toInclusive) { synchronized(mutex) { return SETS.synchronize(n.subSet(fromElement, fromInclusive, toElement, toInclusive), mutex); } }
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement, boolean inclusive) { synchronized(mutex) { return synchronize(n.headSet(toElement, inclusive), mutex); } }
|
||||
|
||||
@Override
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement, boolean inclusive) { synchronized(mutex) { return SETS.synchronize(n.headSet(toElement, inclusive), mutex); } }
|
||||
|
||||
@Override
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement, boolean inclusive) { synchronized(mutex) { return SETS.synchronize(n.tailSet(fromElement, inclusive), mutex); } }
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement, boolean inclusive) { synchronized(mutex) { return synchronize(n.tailSet(fromElement, inclusive), mutex); } }
|
||||
|
||||
@Override
|
||||
public BI_ITERATOR KEY_GENERIC_TYPE descendingIterator() { synchronized(mutex) { return n.descendingIterator(); } }
|
||||
|
||||
@Override
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE descendingSet() { synchronized(mutex) { return SETS.synchronize(n.descendingSet(), mutex); } }
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE descendingSet() { synchronized(mutex) { return synchronize(n.descendingSet(), mutex); } }
|
||||
|
||||
@Override
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) { synchronized(mutex) { return SETS.synchronize(n.subSet(fromElement, toElement), mutex); } }
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) { synchronized(mutex) { return synchronize(n.subSet(fromElement, toElement), mutex); } }
|
||||
|
||||
@Override
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement) { synchronized(mutex) { return SETS.synchronize(n.headSet(toElement), mutex); } }
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement) { synchronized(mutex) { return synchronize(n.headSet(toElement), mutex); } }
|
||||
|
||||
@Override
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) { synchronized(mutex) { return SETS.synchronize(n.tailSet(fromElement), mutex); } }
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) { synchronized(mutex) { return synchronize(n.tailSet(fromElement), mutex); } }
|
||||
}
|
||||
|
||||
private static class SynchronizedSortedTrimSet KEY_GENERIC_TYPE extends SynchronizedSortedSet KEY_GENERIC_TYPE implements ITrimmable
|
||||
@@ -511,16 +494,13 @@ public class SETS
|
||||
public BI_ITERATOR KEY_GENERIC_TYPE iterator(KEY_TYPE fromElement) { synchronized(mutex) { return s.iterator(fromElement); } }
|
||||
|
||||
@Override
|
||||
public SORTED_SET KEY_GENERIC_TYPE copy() { synchronized(mutex) { return s.copy(); } }
|
||||
public SORTED_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) { synchronized(mutex) { return synchronize(s.subSet(fromElement, toElement), mutex); } }
|
||||
|
||||
@Override
|
||||
public SORTED_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) { synchronized(mutex) { return SETS.synchronize(s.subSet(fromElement, toElement), mutex); } }
|
||||
public SORTED_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement) { synchronized(mutex) { return synchronize(s.headSet(toElement), mutex); } }
|
||||
|
||||
@Override
|
||||
public SORTED_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement) { synchronized(mutex) { return SETS.synchronize(s.headSet(toElement), mutex); } }
|
||||
|
||||
@Override
|
||||
public SORTED_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) { synchronized(mutex) { return SETS.synchronize(s.tailSet(fromElement), mutex); } }
|
||||
public SORTED_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) { synchronized(mutex) { return synchronize(s.tailSet(fromElement), mutex); } }
|
||||
|
||||
@Override
|
||||
public KEY_TYPE FIRST_KEY() { synchronized(mutex) { return s.FIRST_KEY(); } }
|
||||
@@ -558,21 +538,24 @@ public class SETS
|
||||
|
||||
private static class SynchronizedSet KEY_GENERIC_TYPE extends SynchronizedCollection KEY_GENERIC_TYPE implements SET KEY_GENERIC_TYPE
|
||||
{
|
||||
#if !TYPE_OBJECT
|
||||
SET KEY_GENERIC_TYPE s;
|
||||
#endif
|
||||
|
||||
SynchronizedSet(SET KEY_GENERIC_TYPE c) {
|
||||
super(c);
|
||||
#if !TYPE_OBJECT
|
||||
s = c;
|
||||
#endif
|
||||
}
|
||||
|
||||
SynchronizedSet(SET KEY_GENERIC_TYPE c, Object mutex) {
|
||||
super(c, mutex);
|
||||
#if !TYPE_OBJECT
|
||||
s = c;
|
||||
#endif
|
||||
}
|
||||
|
||||
@Override
|
||||
public SET KEY_GENERIC_TYPE copy() { synchronized(mutex) { return s.copy(); } }
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public boolean remove(KEY_TYPE o) { synchronized(mutex) { return s.remove(o); } }
|
||||
|
||||
+38
-54
@@ -277,8 +277,6 @@ public class MAPS
|
||||
@Override
|
||||
public VALUE_TYPE getOrDefault(KEY_TYPE key, VALUE_TYPE defaultValue) { return EQUALS_KEY_TYPE(key, this.key) ? value : defaultValue; }
|
||||
#endif
|
||||
@Override
|
||||
public SingletonMap KEY_VALUE_GENERIC_TYPE copy() { return new SingletonMapKV_BRACES(key, value); }
|
||||
@Override
|
||||
public SET KEY_GENERIC_TYPE keySet() {
|
||||
if(keySet == null) keySet = SETS.singleton(key);
|
||||
@@ -331,8 +329,6 @@ public class MAPS
|
||||
public VALUE_COLLECTION VALUE_GENERIC_TYPE values() { return VALUE_COLLECTIONS.empty(); }
|
||||
@Override
|
||||
public ObjectSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> ENTRY_SET() { return ObjectSets.empty(); }
|
||||
@Override
|
||||
public EmptyMap KEY_VALUE_GENERIC_TYPE copy() { return this; }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -368,31 +364,31 @@ public class MAPS
|
||||
}
|
||||
|
||||
@Override
|
||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE descendingMap() { return MAPS.synchronize(map.descendingMap()); }
|
||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE descendingMap() { return synchronize(map.descendingMap()); }
|
||||
@Override
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE navigableKeySet() { return SETS.unmodifiable(map.navigableKeySet()); }
|
||||
@Override
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE descendingKeySet() { return SETS.unmodifiable(map.descendingKeySet()); }
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE firstEntry() { return MAPS.unmodifiable(map.firstEntry()); }
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE firstEntry() { return unmodifiable(map.firstEntry()); }
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE lastEntry() { return MAPS.unmodifiable(map.lastEntry()); }
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE lastEntry() { return unmodifiable(map.lastEntry()); }
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollFirstEntry() { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollLastEntry() { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE subMap(KEY_TYPE fromKey, boolean fromInclusive, KEY_TYPE toKey, boolean toInclusive) { return MAPS.unmodifiable(map.subMap(fromKey, fromInclusive, toKey, toInclusive)); }
|
||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE subMap(KEY_TYPE fromKey, boolean fromInclusive, KEY_TYPE toKey, boolean toInclusive) { return unmodifiable(map.subMap(fromKey, fromInclusive, toKey, toInclusive)); }
|
||||
@Override
|
||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE headMap(KEY_TYPE toKey, boolean inclusive) { return MAPS.unmodifiable(map.headMap(toKey, inclusive)); }
|
||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE headMap(KEY_TYPE toKey, boolean inclusive) { return unmodifiable(map.headMap(toKey, inclusive)); }
|
||||
@Override
|
||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE tailMap(KEY_TYPE fromKey, boolean inclusive) { return MAPS.unmodifiable(map.tailMap(fromKey, inclusive)); }
|
||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE tailMap(KEY_TYPE fromKey, boolean inclusive) { return unmodifiable(map.tailMap(fromKey, inclusive)); }
|
||||
@Override
|
||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE subMap(KEY_TYPE fromKey, KEY_TYPE toKey) { return MAPS.unmodifiable(map.subMap(fromKey, toKey)); }
|
||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE subMap(KEY_TYPE fromKey, KEY_TYPE toKey) { return unmodifiable(map.subMap(fromKey, toKey)); }
|
||||
@Override
|
||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE headMap(KEY_TYPE toKey) { return MAPS.unmodifiable(map.headMap(toKey)); }
|
||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE headMap(KEY_TYPE toKey) { return unmodifiable(map.headMap(toKey)); }
|
||||
@Override
|
||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE tailMap(KEY_TYPE fromKey) { return MAPS.unmodifiable(map.tailMap(fromKey)); }
|
||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE tailMap(KEY_TYPE fromKey) { return unmodifiable(map.tailMap(fromKey)); }
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public void setDefaultMaxValue(KEY_TYPE e) { throw new UnsupportedOperationException(); }
|
||||
@@ -412,15 +408,13 @@ public class MAPS
|
||||
@Override
|
||||
public KEY_TYPE ceilingKey(KEY_TYPE key) { return map.ceilingKey(key); }
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE lowerEntry(KEY_TYPE key) { return MAPS.unmodifiable(map.lowerEntry(key)); }
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE lowerEntry(KEY_TYPE key) { return unmodifiable(map.lowerEntry(key)); }
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE higherEntry(KEY_TYPE key) { return MAPS.unmodifiable(map.higherEntry(key)); }
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE higherEntry(KEY_TYPE key) { return unmodifiable(map.higherEntry(key)); }
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE floorEntry(KEY_TYPE key) { return MAPS.unmodifiable(map.floorEntry(key)); }
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE floorEntry(KEY_TYPE key) { return unmodifiable(map.floorEntry(key)); }
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE ceilingEntry(KEY_TYPE key) { return MAPS.unmodifiable(map.ceilingEntry(key)); }
|
||||
@Override
|
||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE ceilingEntry(KEY_TYPE key) { return unmodifiable(map.ceilingEntry(key)); }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -451,11 +445,11 @@ public class MAPS
|
||||
@Override
|
||||
public COMPARATOR KEY_GENERIC_TYPE comparator() { return map.comparator(); }
|
||||
@Override
|
||||
public SORTED_MAP KEY_VALUE_GENERIC_TYPE subMap(KEY_TYPE fromKey, KEY_TYPE toKey) { return MAPS.unmodifiable(map.subMap(fromKey, toKey)); }
|
||||
public SORTED_MAP KEY_VALUE_GENERIC_TYPE subMap(KEY_TYPE fromKey, KEY_TYPE toKey) { return unmodifiable(map.subMap(fromKey, toKey)); }
|
||||
@Override
|
||||
public SORTED_MAP KEY_VALUE_GENERIC_TYPE headMap(KEY_TYPE toKey) { return MAPS.unmodifiable(map.headMap(toKey)); }
|
||||
public SORTED_MAP KEY_VALUE_GENERIC_TYPE headMap(KEY_TYPE toKey) { return unmodifiable(map.headMap(toKey)); }
|
||||
@Override
|
||||
public SORTED_MAP KEY_VALUE_GENERIC_TYPE tailMap(KEY_TYPE fromKey) { return MAPS.unmodifiable(map.tailMap(fromKey)); }
|
||||
public SORTED_MAP KEY_VALUE_GENERIC_TYPE tailMap(KEY_TYPE fromKey) { return unmodifiable(map.tailMap(fromKey)); }
|
||||
@Override
|
||||
public KEY_TYPE FIRST_ENTRY_KEY() { return map.FIRST_ENTRY_KEY(); }
|
||||
@Override
|
||||
@@ -468,8 +462,6 @@ public class MAPS
|
||||
public VALUE_TYPE FIRST_ENTRY_VALUE() { return map.FIRST_ENTRY_VALUE(); }
|
||||
@Override
|
||||
public VALUE_TYPE LAST_ENTRY_VALUE() { return map.LAST_ENTRY_VALUE(); }
|
||||
@Override
|
||||
public SORTED_MAP KEY_VALUE_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -509,8 +501,6 @@ public class MAPS
|
||||
@Override
|
||||
public VALUE_TYPE getOrDefault(KEY_TYPE key, VALUE_TYPE defaultValue) { return map.getOrDefault(key, defaultValue); }
|
||||
#endif
|
||||
@Override
|
||||
public MAP KEY_VALUE_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public SET KEY_GENERIC_TYPE keySet() {
|
||||
@@ -548,7 +538,7 @@ public class MAPS
|
||||
|
||||
@Override
|
||||
public void forEach(Consumer<? super MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
|
||||
s.forEach(T -> action.accept(MAPS.unmodifiable(T)));
|
||||
s.forEach(T -> action.accept(unmodifiable(T)));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -558,7 +548,7 @@ public class MAPS
|
||||
@Override
|
||||
public boolean hasNext() { return iter.hasNext(); }
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE next() { return MAPS.unmodifiable(iter.next()); }
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE next() { return unmodifiable(iter.next()); }
|
||||
};
|
||||
}
|
||||
|
||||
@@ -583,7 +573,7 @@ public class MAPS
|
||||
}
|
||||
|
||||
@Override
|
||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE descendingMap() { synchronized(mutex) { return MAPS.synchronize(map.descendingMap(), mutex); } }
|
||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE descendingMap() { synchronized(mutex) { return synchronize(map.descendingMap(), mutex); } }
|
||||
@Override
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE navigableKeySet() { synchronized(mutex) { return SETS.synchronize(map.navigableKeySet(), mutex); } }
|
||||
@Override
|
||||
@@ -597,17 +587,17 @@ public class MAPS
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollLastEntry() { synchronized(mutex) { return map.pollLastEntry(); } }
|
||||
@Override
|
||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE subMap(KEY_TYPE fromKey, boolean fromInclusive, KEY_TYPE toKey, boolean toInclusive) { synchronized(mutex) { return MAPS.synchronize(map.subMap(fromKey, fromInclusive, toKey, toInclusive), mutex); } }
|
||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE subMap(KEY_TYPE fromKey, boolean fromInclusive, KEY_TYPE toKey, boolean toInclusive) { synchronized(mutex) { return synchronize(map.subMap(fromKey, fromInclusive, toKey, toInclusive), mutex); } }
|
||||
@Override
|
||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE headMap(KEY_TYPE toKey, boolean inclusive) { synchronized(mutex) { return MAPS.synchronize(map.headMap(toKey, inclusive), mutex); } }
|
||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE headMap(KEY_TYPE toKey, boolean inclusive) { synchronized(mutex) { return synchronize(map.headMap(toKey, inclusive), mutex); } }
|
||||
@Override
|
||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE tailMap(KEY_TYPE fromKey, boolean inclusive) { synchronized(mutex) { return MAPS.synchronize(map.tailMap(fromKey, inclusive), mutex); } }
|
||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE tailMap(KEY_TYPE fromKey, boolean inclusive) { synchronized(mutex) { return synchronize(map.tailMap(fromKey, inclusive), mutex); } }
|
||||
@Override
|
||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE subMap(KEY_TYPE fromKey, KEY_TYPE toKey) { synchronized(mutex) { return MAPS.synchronize(map.subMap(fromKey, toKey), mutex); } }
|
||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE subMap(KEY_TYPE fromKey, KEY_TYPE toKey) { synchronized(mutex) { return synchronize(map.subMap(fromKey, toKey), mutex); } }
|
||||
@Override
|
||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE headMap(KEY_TYPE toKey) { synchronized(mutex) { return MAPS.synchronize(map.headMap(toKey), mutex); } }
|
||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE headMap(KEY_TYPE toKey) { synchronized(mutex) { return synchronize(map.headMap(toKey), mutex); } }
|
||||
@Override
|
||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE tailMap(KEY_TYPE fromKey) { synchronized(mutex) { return MAPS.synchronize(map.tailMap(fromKey), mutex); } }
|
||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE tailMap(KEY_TYPE fromKey) { synchronized(mutex) { return synchronize(map.tailMap(fromKey), mutex); } }
|
||||
@Override
|
||||
public KEY_TYPE lowerKey(KEY_TYPE key) { synchronized(mutex) { return map.lowerKey(key); } }
|
||||
@Override
|
||||
@@ -624,27 +614,25 @@ public class MAPS
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE floorEntry(KEY_TYPE key) { synchronized(mutex) { return map.floorEntry(key); } }
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE ceilingEntry(KEY_TYPE key) { synchronized(mutex) { return map.ceilingEntry(key); } }
|
||||
@Override
|
||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
||||
#if !TYPE_OBJECT
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
@Deprecated
|
||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE subMap(CLASS_TYPE fromKey, boolean fromInclusive, CLASS_TYPE toKey, boolean toInclusive) { synchronized(mutex) { return MAPS.synchronize(map.subMap(fromKey, fromInclusive, toKey, toInclusive), mutex); } }
|
||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE subMap(CLASS_TYPE fromKey, boolean fromInclusive, CLASS_TYPE toKey, boolean toInclusive) { synchronized(mutex) { return synchronize(map.subMap(fromKey, fromInclusive, toKey, toInclusive), mutex); } }
|
||||
@Override
|
||||
@Deprecated
|
||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE headMap(CLASS_TYPE toKey, boolean inclusive) { synchronized(mutex) { return MAPS.synchronize(map.headMap(toKey, inclusive), mutex); } }
|
||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE headMap(CLASS_TYPE toKey, boolean inclusive) { synchronized(mutex) { return synchronize(map.headMap(toKey, inclusive), mutex); } }
|
||||
@Override
|
||||
@Deprecated
|
||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE tailMap(CLASS_TYPE fromKey, boolean inclusive) { synchronized(mutex) { return MAPS.synchronize(map.tailMap(fromKey, inclusive), mutex); } }
|
||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE tailMap(CLASS_TYPE fromKey, boolean inclusive) { synchronized(mutex) { return synchronize(map.tailMap(fromKey, inclusive), mutex); } }
|
||||
@Override
|
||||
@Deprecated
|
||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE subMap(CLASS_TYPE fromKey, CLASS_TYPE toKey) { synchronized(mutex) { return MAPS.synchronize(map.subMap(fromKey, toKey), mutex); } }
|
||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE subMap(CLASS_TYPE fromKey, CLASS_TYPE toKey) { synchronized(mutex) { return synchronize(map.subMap(fromKey, toKey), mutex); } }
|
||||
@Override
|
||||
@Deprecated
|
||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE headMap(CLASS_TYPE toKey) { synchronized(mutex) { return MAPS.synchronize(map.headMap(toKey), mutex); } }
|
||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE headMap(CLASS_TYPE toKey) { synchronized(mutex) { return synchronize(map.headMap(toKey), mutex); } }
|
||||
@Override
|
||||
@Deprecated
|
||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE tailMap(CLASS_TYPE fromKey) { synchronized(mutex) { return MAPS.synchronize(map.tailMap(fromKey), mutex); } }
|
||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE tailMap(CLASS_TYPE fromKey) { synchronized(mutex) { return synchronize(map.tailMap(fromKey), mutex); } }
|
||||
@Override
|
||||
public void setDefaultMaxValue(KEY_TYPE e) { synchronized(mutex) { map.setDefaultMaxValue(e); } }
|
||||
@Override
|
||||
@@ -713,11 +701,11 @@ public class MAPS
|
||||
@Override
|
||||
public COMPARATOR KEY_GENERIC_TYPE comparator() { synchronized(mutex) { return map.comparator(); } }
|
||||
@Override
|
||||
public SORTED_MAP KEY_VALUE_GENERIC_TYPE subMap(KEY_TYPE fromKey, KEY_TYPE toKey) { synchronized(mutex) { return MAPS.synchronize(map.subMap(fromKey, toKey), mutex); } }
|
||||
public SORTED_MAP KEY_VALUE_GENERIC_TYPE subMap(KEY_TYPE fromKey, KEY_TYPE toKey) { synchronized(mutex) { return synchronize(map.subMap(fromKey, toKey), mutex); } }
|
||||
@Override
|
||||
public SORTED_MAP KEY_VALUE_GENERIC_TYPE headMap(KEY_TYPE toKey) { synchronized(mutex) { return MAPS.synchronize(map.headMap(toKey), mutex); } }
|
||||
public SORTED_MAP KEY_VALUE_GENERIC_TYPE headMap(KEY_TYPE toKey) { synchronized(mutex) { return synchronize(map.headMap(toKey), mutex); } }
|
||||
@Override
|
||||
public SORTED_MAP KEY_VALUE_GENERIC_TYPE tailMap(KEY_TYPE fromKey) { synchronized(mutex) { return MAPS.synchronize(map.tailMap(fromKey), mutex); } }
|
||||
public SORTED_MAP KEY_VALUE_GENERIC_TYPE tailMap(KEY_TYPE fromKey) { synchronized(mutex) { return synchronize(map.tailMap(fromKey), mutex); } }
|
||||
@Override
|
||||
public KEY_TYPE FIRST_ENTRY_KEY() { synchronized(mutex) { return map.FIRST_ENTRY_KEY(); } }
|
||||
@Override
|
||||
@@ -730,8 +718,6 @@ public class MAPS
|
||||
public VALUE_TYPE FIRST_ENTRY_VALUE() { synchronized(mutex) { return map.FIRST_ENTRY_VALUE(); } }
|
||||
@Override
|
||||
public VALUE_TYPE LAST_ENTRY_VALUE() { synchronized(mutex) { return map.LAST_ENTRY_VALUE(); } }
|
||||
@Override
|
||||
public SORTED_MAP KEY_VALUE_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
@Deprecated
|
||||
@@ -741,13 +727,13 @@ public class MAPS
|
||||
public CLASS_TYPE lastKey() { synchronized(mutex) { return map.lastKey(); } }
|
||||
@Override
|
||||
@Deprecated
|
||||
public SORTED_MAP KEY_VALUE_GENERIC_TYPE subMap(CLASS_TYPE fromKey, CLASS_TYPE toKey) { synchronized(mutex) { return MAPS.synchronize(map.subMap(fromKey, toKey), mutex); } }
|
||||
public SORTED_MAP KEY_VALUE_GENERIC_TYPE subMap(CLASS_TYPE fromKey, CLASS_TYPE toKey) { synchronized(mutex) { return synchronize(map.subMap(fromKey, toKey), mutex); } }
|
||||
@Override
|
||||
@Deprecated
|
||||
public SORTED_MAP KEY_VALUE_GENERIC_TYPE headMap(CLASS_TYPE toKey) { synchronized(mutex) { return MAPS.synchronize(map.headMap(toKey), mutex); } }
|
||||
public SORTED_MAP KEY_VALUE_GENERIC_TYPE headMap(CLASS_TYPE toKey) { synchronized(mutex) { return synchronize(map.headMap(toKey), mutex); } }
|
||||
@Override
|
||||
@Deprecated
|
||||
public SORTED_MAP KEY_VALUE_GENERIC_TYPE tailMap(CLASS_TYPE fromKey) { synchronized(mutex) { return MAPS.synchronize(map.tailMap(fromKey), mutex); } }
|
||||
public SORTED_MAP KEY_VALUE_GENERIC_TYPE tailMap(CLASS_TYPE fromKey) { synchronized(mutex) { return synchronize(map.tailMap(fromKey), mutex); } }
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -845,8 +831,6 @@ public class MAPS
|
||||
@Override
|
||||
public int size() { synchronized(mutex) { return super.size(); } }
|
||||
@Override
|
||||
public MAP KEY_VALUE_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public SET KEY_GENERIC_TYPE keySet() {
|
||||
if(keys == null) keys = SETS.synchronize(map.keySet(), mutex);
|
||||
return keys;
|
||||
|
||||
@@ -79,26 +79,6 @@ public class HashUtil
|
||||
return x + 1L;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function that finds out how many bits are required to store the number Provided
|
||||
* @param value to get the required bits to store.
|
||||
* @return the required bits to store that number
|
||||
* @note Really useful for compression. Reducing data that is inserted into a GZIP algorithm.
|
||||
*/
|
||||
public static int getRequiredBits(int value) {
|
||||
return Integer.bitCount(nextPowerOfTwo(value+1)-1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function that finds out how many bits are required to store the number Provided
|
||||
* @param value to get the required bits to store.
|
||||
* @return the required bits to store that number
|
||||
* @note Really useful for compression. Reducing data that is inserted into a GZIP algorithm.
|
||||
*/
|
||||
public static int getRequiredBits(long value) {
|
||||
return Long.bitCount(nextPowerOfTwo(value+1L)-1L);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function that creates the ideal array size for HashMap
|
||||
* @param size the original array size
|
||||
|
||||
@@ -16,5 +16,5 @@ public interface IArray extends RandomAccess, ITrimmable
|
||||
*
|
||||
* @param size the desired minimum capacity
|
||||
*/
|
||||
public void ensureCapacity(int size);
|
||||
void ensureCapacity(int size);
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ public interface ITrimmable
|
||||
* Trims the original collection down to the size of the current elements
|
||||
* @return if the internal array has been trimmed.
|
||||
*/
|
||||
public default boolean trim() {
|
||||
default boolean trim() {
|
||||
return trim(0);
|
||||
}
|
||||
|
||||
@@ -19,12 +19,12 @@ public interface ITrimmable
|
||||
* @param size the requested trim size.
|
||||
* @return if the internal array has been trimmed.
|
||||
*/
|
||||
public boolean trim(int size);
|
||||
boolean trim(int size);
|
||||
|
||||
/**
|
||||
* Trims the collection down to the original size and clears all present elements with it.
|
||||
*/
|
||||
public default void clearAndTrim() {
|
||||
default void clearAndTrim() {
|
||||
clearAndTrim(0);
|
||||
}
|
||||
|
||||
@@ -33,5 +33,5 @@ public interface ITrimmable
|
||||
* @param size the amount of elements that should be allowed
|
||||
* @note this will enforce minimum size of the collection itself
|
||||
*/
|
||||
public void clearAndTrim(int size);
|
||||
void clearAndTrim(int size);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package speiger.src.collections.utils;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ForkJoinPool;
|
||||
import java.util.concurrent.ForkJoinTask;
|
||||
@@ -8,15 +11,15 @@ import java.util.concurrent.ForkJoinTask;
|
||||
* Helper class that provides functions that are shared within the library.
|
||||
* On top of that it provides some helper functions that allow control of some internals of the Library
|
||||
*/
|
||||
public class SanityChecks
|
||||
public final class SanityChecks
|
||||
{
|
||||
/** Max Possible ArraySize without the JVM Crashing */
|
||||
public static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8;
|
||||
private static ForkJoinPool WORK_POOL = ForkJoinPool.commonPool();
|
||||
private static boolean FORCE_IGNORE_PARALLELISM = false;
|
||||
private static ThreadLocal<Random> RANDOM = ThreadLocal.withInitial(Random::new);
|
||||
private static ThreadLocal<Boolean> FORCE_ASYNC = ThreadLocal.withInitial(() -> false);
|
||||
private static ThreadLocal<Boolean> FORCE_TASK_POOL = ThreadLocal.withInitial(() -> false);
|
||||
private static final ThreadLocal<Random> RANDOM = ThreadLocal.withInitial(Random::new);
|
||||
private static final ThreadLocal<Boolean> FORCE_ASYNC = ThreadLocal.withInitial(() -> false);
|
||||
private static final ThreadLocal<Boolean> FORCE_TASK_POOL = ThreadLocal.withInitial(() -> false);
|
||||
|
||||
/**
|
||||
* Internal function to cast a Integer to a Byte
|
||||
@@ -72,8 +75,8 @@ public class SanityChecks
|
||||
* @throws IllegalStateException if offset or accessSize is negative or the range goes out of the array-size
|
||||
*/
|
||||
public static void checkArrayCapacity(int arraySize, int offset, int accessSize) {
|
||||
if(offset < 0) throw new IndexOutOfBoundsException("Offset is negative ("+offset+")");
|
||||
else if(accessSize < 0) throw new IllegalArgumentException("Size is negative ("+accessSize+")");
|
||||
if(offset < 0) throw new IllegalStateException("Offset is negative ("+offset+")");
|
||||
else if(accessSize < 0) throw new IllegalStateException("Size is negative ("+accessSize+")");
|
||||
else if(arraySize < offset + accessSize) throw new IndexOutOfBoundsException("Index (" + (offset + accessSize) + ") is not in size (" + arraySize + ")");
|
||||
}
|
||||
|
||||
@@ -90,8 +93,8 @@ public class SanityChecks
|
||||
* @param task the Task to invoke
|
||||
* @param <T> the type of the task
|
||||
*/
|
||||
public static <T> void invokeTask(ForkJoinTask<T> task) {
|
||||
if(FORCE_ASYNC.get().booleanValue()) invokeAsyncTask(task);
|
||||
public static <T> void invokeTask(@NotNull ForkJoinTask<T> task) {
|
||||
if(FORCE_ASYNC.get()) invokeAsyncTask(task);
|
||||
else getPool().invoke(task);
|
||||
}
|
||||
|
||||
@@ -100,7 +103,7 @@ public class SanityChecks
|
||||
* @param task the Task to invoke
|
||||
* @param <T> the type of the task
|
||||
*/
|
||||
public static <T> void invokeAsyncTask(ForkJoinTask<T> task) {
|
||||
public static <T> void invokeAsyncTask(@NotNull ForkJoinTask<T> task) {
|
||||
getPool().execute(task);
|
||||
}
|
||||
|
||||
@@ -109,12 +112,12 @@ public class SanityChecks
|
||||
* @note this method is not thread-save. It is only there to provide control over how Library specific Threaded tasks are handled.
|
||||
* @param pool The ForkJoinPool that should receive the tasks. If null {@link ForkJoinPool#commonPool()} is set instead
|
||||
*/
|
||||
public static void setWorkPool(ForkJoinPool pool) {
|
||||
public static void setWorkPool(@Nullable ForkJoinPool pool) {
|
||||
WORK_POOL = pool == null ? ForkJoinPool.commonPool() : pool;
|
||||
}
|
||||
|
||||
private static ForkJoinPool getPool() {
|
||||
if(FORCE_TASK_POOL.get().booleanValue()) {
|
||||
private static @NotNull ForkJoinPool getPool() {
|
||||
if(FORCE_TASK_POOL.get()) {
|
||||
ForkJoinPool pool = ForkJoinTask.getPool();
|
||||
if(pool != null) return pool;
|
||||
}
|
||||
@@ -126,7 +129,7 @@ public class SanityChecks
|
||||
* @return if the Current Thread has not to await task completion.
|
||||
*/
|
||||
public static boolean isForcedAsync() {
|
||||
return FORCE_ASYNC.get().booleanValue();
|
||||
return FORCE_ASYNC.get();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -134,7 +137,7 @@ public class SanityChecks
|
||||
* @return if the task checks the current pool to be executed in if it is valid.
|
||||
*/
|
||||
public static boolean isForcedTaskPool() {
|
||||
return FORCE_TASK_POOL.get().booleanValue();
|
||||
return FORCE_TASK_POOL.get();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -142,7 +145,7 @@ public class SanityChecks
|
||||
* @param value it tasks should not be awaited for
|
||||
*/
|
||||
public static void setForcedAsync(boolean value) {
|
||||
FORCE_ASYNC.set(Boolean.valueOf(value));
|
||||
FORCE_ASYNC.set(value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -150,7 +153,7 @@ public class SanityChecks
|
||||
* @param value if the current thread should check if it is a ThreadPoolWorker.
|
||||
*/
|
||||
public static void setForcedTaskPool(boolean value) {
|
||||
FORCE_TASK_POOL.set(Boolean.valueOf(value));
|
||||
FORCE_TASK_POOL.set(value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -164,7 +167,7 @@ public class SanityChecks
|
||||
/**
|
||||
* @return Thread Specific Random needed for internal functions in this library.
|
||||
*/
|
||||
public static Random getRandom() {
|
||||
public static @NotNull Random getRandom() {
|
||||
return RANDOM.get();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package speiger.src.collections.utils;
|
||||
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* The Stack Interface represents the Last-In-First-Out layout (LIFO).
|
||||
* It provides a simple {@link #push(Object)}, {@link #pop()} function,
|
||||
@@ -14,40 +16,40 @@ public interface Stack<T>
|
||||
* Inserts a given Object on top of the stack
|
||||
* @param e the Object to insert
|
||||
*/
|
||||
public void push(T e);
|
||||
void push(@NotNull T e);
|
||||
|
||||
/**
|
||||
* Removes the Object on top of the stack.
|
||||
* @return the element that is on top of the stack
|
||||
* @throws ArrayIndexOutOfBoundsException if the stack is empty
|
||||
*/
|
||||
public T pop();
|
||||
@NotNull T pop();
|
||||
|
||||
/**
|
||||
* Provides the amount of elements currently in the stack
|
||||
* @return amount of elements in the list
|
||||
*/
|
||||
public int size();
|
||||
int size();
|
||||
|
||||
|
||||
/**
|
||||
* @return if the stack is empty
|
||||
*/
|
||||
public default boolean isEmpty() {
|
||||
default boolean isEmpty() {
|
||||
return size() == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the stack
|
||||
*/
|
||||
public void clear();
|
||||
void clear();
|
||||
|
||||
/**
|
||||
* Provides the Object on top of the stack
|
||||
* @return the element that is on top of the stack
|
||||
* @throws ArrayIndexOutOfBoundsException if the stack is empty
|
||||
*/
|
||||
public default T top() {
|
||||
default @NotNull T top() {
|
||||
return peek(0);
|
||||
}
|
||||
|
||||
@@ -58,5 +60,5 @@ public interface Stack<T>
|
||||
* @return the element that was requested
|
||||
* @throws ArrayIndexOutOfBoundsException if the index is out of bounds
|
||||
*/
|
||||
public T peek(int index);
|
||||
@NotNull T peek(int index);
|
||||
}
|
||||
|
||||
@@ -135,16 +135,6 @@ public abstract class BaseInt2IntMapTest
|
||||
Assert.assertTrue(map.remove(PUT_VALUE_ARRAY[51], PUT_ARRAY[51]));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSort()
|
||||
{
|
||||
if(!getValidMapTests().contains(MapTests.COPY)) return;
|
||||
Int2IntMap map = createMap(TEST_ARRAY, TEST_ARRAY);
|
||||
Int2IntMap copy = map.copy();
|
||||
Assert.assertFalse(map == copy);
|
||||
Assert.assertEquals(map, copy);
|
||||
}
|
||||
|
||||
public static class Strategy implements IntStrategy
|
||||
{
|
||||
@Override
|
||||
|
||||
@@ -118,14 +118,6 @@ public abstract class BaseIntCollectionTest extends BaseIntIterableTest
|
||||
Assert.assertTrue(collection.removeAll(Arrays.asList(IntArrays.wrap(CONTAINS_ARRAY))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveAllListener() {
|
||||
if(!getValidCollectionTests().contains(CollectionTest.REMOVE_ALL_LISTENER)) return;
|
||||
IntCollection collection = create(TEST_ARRAY);
|
||||
Assert.assertTrue(collection.removeAll(create(CONTAINS_ARRAY), T -> {}));
|
||||
Assert.assertFalse(collection.removeAll(create(CONTAINS_ARRAY), T -> Assert.assertTrue(false)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRetainAll() {
|
||||
if(!getValidCollectionTests().contains(CollectionTest.RETAIN_ALL)) return;
|
||||
@@ -143,23 +135,6 @@ public abstract class BaseIntCollectionTest extends BaseIntIterableTest
|
||||
Assert.assertTrue(collection.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRetainAllListener() {
|
||||
if(!getValidCollectionTests().contains(CollectionTest.RETAIN_ALL_LISTENER)) return;
|
||||
IntCollection collection = create(TEST_ARRAY);
|
||||
IntCollection retained = create(CONTAINS_ARRAY);
|
||||
Assert.assertTrue(collection.retainAll(retained, T -> {}));
|
||||
Assert.assertFalse(collection.retainAll(retained, T -> Assert.assertTrue(false)));
|
||||
Assert.assertEquals(CONTAINS_ARRAY.length, collection.size());
|
||||
int[] retainedArray = retained.toIntArray();
|
||||
int[] collectionArray = collection.toIntArray();
|
||||
IntArrays.stableSort(retainedArray);
|
||||
IntArrays.stableSort(collectionArray);
|
||||
Assert.assertArrayEquals(retainedArray, collectionArray);
|
||||
collection.retainAll(IntCollections.EMPTY, T -> {});
|
||||
Assert.assertTrue(collection.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToArray() {
|
||||
if(!getValidCollectionTests().contains(CollectionTest.TO_ARRAY)) return;
|
||||
@@ -203,13 +178,4 @@ public abstract class BaseIntCollectionTest extends BaseIntIterableTest
|
||||
Assert.assertEquals(base, IntCollections.synchronize(collection).toString());
|
||||
Assert.assertEquals(base, IntCollections.unmodifiable(collection).toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCopy() {
|
||||
if(!getValidCollectionTests().contains(CollectionTest.COPY)) return;
|
||||
IntCollection collection = create(BULK_ADD_ARRAY);
|
||||
IntCollection copy = collection.copy();
|
||||
Assert.assertFalse(collection == copy);
|
||||
Assert.assertEquals(collection, copy);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package speiger.src.collections.ints.base;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.EnumSet;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
@@ -9,11 +8,6 @@ import org.junit.Test;
|
||||
|
||||
import speiger.src.collections.ints.collections.IntIterable;
|
||||
import speiger.src.collections.ints.collections.IntIterator;
|
||||
import speiger.src.collections.ints.lists.IntArrayList;
|
||||
import speiger.src.collections.ints.utils.IntArrays;
|
||||
import speiger.src.collections.ints.utils.IntIterators;
|
||||
import speiger.src.collections.objects.utils.ObjectArrays;
|
||||
import speiger.src.collections.objects.utils.ObjectIterators;
|
||||
import speiger.src.collections.tests.IterableTest;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
@@ -21,7 +15,6 @@ public abstract class BaseIntIterableTest
|
||||
{
|
||||
protected static final int[] EMPTY_ARRAY = new int[0];
|
||||
protected static final int[] TEST_ARRAY = IntStream.range(0, 100).toArray();
|
||||
protected static final int[] DISTINCT_ARRAY = IntStream.range(0, 100).flatMap(T -> Arrays.stream(new int[]{T, T})).toArray();
|
||||
|
||||
protected abstract IntIterable create(int[] data);
|
||||
|
||||
@@ -72,103 +65,4 @@ public abstract class BaseIntIterableTest
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStreamCount() {
|
||||
if(getValidIterableTests().contains(IterableTest.STREAM_COUNT)) {
|
||||
long expected = IntStream.of(TEST_ARRAY).filter(T -> T % 2 == 0).count();
|
||||
int size = create(TEST_ARRAY).count(T -> T % 2 == 0);
|
||||
Assert.assertEquals(expected, size);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStreamFilter() {
|
||||
if(getValidIterableTests().contains(IterableTest.STREAM_FILTER)) {
|
||||
int[] expected = IntStream.of(TEST_ARRAY).filter(T -> T % 2 == 0).toArray();
|
||||
int[] actual = IntIterators.pour(create(TEST_ARRAY).filter(T -> T % 2 == 0).iterator()).toIntArray();
|
||||
IntArrays.stableSort(actual);
|
||||
Assert.assertArrayEquals(expected, actual);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStreamFindFirst() {
|
||||
if(getValidIterableTests().contains(IterableTest.STREAM_FIND_FIRST)) {
|
||||
int expected = IntStream.of(TEST_ARRAY).filter(T -> T / 50 > 0).findFirst().getAsInt();
|
||||
int actual = create(TEST_ARRAY).findFirst(T -> T / 50 > 0);
|
||||
Assert.assertEquals(expected, actual);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void teastStreamDistinct() {
|
||||
if(getValidIterableTests().contains(IterableTest.STREAM_DISTINCT)) {
|
||||
int[] expected = IntStream.of(DISTINCT_ARRAY).distinct().toArray();
|
||||
int[] actual = IntIterators.pour(create(DISTINCT_ARRAY).distinct().iterator()).toIntArray();
|
||||
IntArrays.stableSort(actual);
|
||||
Assert.assertArrayEquals(expected, actual);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStreamLimit() {
|
||||
if(getValidIterableTests().contains(IterableTest.STREAM_LIMIT)) {
|
||||
int[] expected = IntStream.of(TEST_ARRAY).limit(25).toArray();
|
||||
int[] actual = IntIterators.pour(create(TEST_ARRAY).limit(25).iterator()).toIntArray();
|
||||
Assert.assertEquals(expected.length, actual.length);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStreamMap() {
|
||||
if(getValidIterableTests().contains(IterableTest.STREAM_MAP)) {
|
||||
Integer[] expected = IntStream.of(TEST_ARRAY).mapToObj(Integer::new).toArray(Integer[]::new);
|
||||
Integer[] actual = ObjectIterators.pour(create(TEST_ARRAY).map(Integer::new).iterator()).toArray(Integer[]::new);
|
||||
ObjectArrays.stableSort(actual);
|
||||
Assert.assertArrayEquals(expected, actual);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStreamMatches() {
|
||||
if(getValidIterableTests().contains(IterableTest.STREAM_MATCHES)) {
|
||||
IntIterable iterable = create(TEST_ARRAY);
|
||||
Assert.assertTrue(iterable.matchesAll(T -> T >= 0));
|
||||
Assert.assertFalse(iterable.matchesAll(T -> T < 0));
|
||||
Assert.assertTrue(iterable.matchesAny(T -> T % 2 != 0));
|
||||
Assert.assertFalse(iterable.matchesAny(T -> T % 2 >= 2));
|
||||
Assert.assertTrue(iterable.matchesNone(T -> T % 2 >= 2));
|
||||
Assert.assertFalse(iterable.matchesNone(T -> T % 2 != 0));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStreamPeek() {
|
||||
if(getValidIterableTests().contains(IterableTest.STREAM_PEEK)) {
|
||||
int[] peekCount = new int[2];
|
||||
create(TEST_ARRAY).peek(T -> peekCount[0]++).forEach(T -> peekCount[1]++);
|
||||
Assert.assertEquals(TEST_ARRAY.length, peekCount[0]);
|
||||
Assert.assertEquals(TEST_ARRAY.length, peekCount[1]);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStreamPour() {
|
||||
if(getValidIterableTests().contains(IterableTest.STREAM_POUR)) {
|
||||
int[] expected = TEST_ARRAY;
|
||||
int[] actual = create(TEST_ARRAY).pour(new IntArrayList()).toIntArray();
|
||||
IntArrays.stableSort(actual);
|
||||
Assert.assertArrayEquals(expected, actual);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStreamReduce() {
|
||||
if(getValidIterableTests().contains(IterableTest.STREAM_REDUCE)) {
|
||||
int expected = IntStream.of(TEST_ARRAY).reduce(0, Integer::sum);
|
||||
int actual = create(TEST_ARRAY).reduce(0, Integer::sum);
|
||||
Assert.assertEquals(expected, actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -64,16 +64,6 @@ public abstract class BaseIntListTest extends BaseIntCollectionTest
|
||||
for(int i = 0;i<ADD_ARRAY.length;i++) Assert.assertEquals(ADD_ARRAY[i], list.getInt(i));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSpecialAdd() {
|
||||
if(getValidListTests().contains(ListTest.ADD_SPECIAL)) return;
|
||||
IntList list = create(TEST_ARRAY);
|
||||
Assert.assertFalse(list.addIfAbsent(50));
|
||||
Assert.assertTrue(list.addIfPresent(50));
|
||||
Assert.assertTrue(list.addIfAbsent(150));
|
||||
Assert.assertFalse(list.addIfAbsent(150));
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void testIndex() {
|
||||
@@ -183,17 +173,6 @@ public abstract class BaseIntListTest extends BaseIntCollectionTest
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSwapRemove() {
|
||||
if(getValidListTests().contains(ListTest.REMOVE_SWAP)) return;
|
||||
IntList list = create(TEST_ARRAY);
|
||||
Assert.assertEquals(TEST_ARRAY[50], list.swapRemove(50));
|
||||
Assert.assertEquals(TEST_ARRAY[TEST_ARRAY.length-1], list.getInt(50));
|
||||
list = create(TEST_ARRAY);
|
||||
Assert.assertTrue(list.swapRemoveInt(50));
|
||||
Assert.assertFalse(list.swapRemoveInt(50));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListIterator() {
|
||||
if(getValidListTests().contains(ListTest.LIST_ITERATOR)) return;
|
||||
|
||||
@@ -120,13 +120,4 @@ public abstract class BaseIntPriorityQueueTest extends BaseIntIterableTest
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCopy() {
|
||||
if(!getValidPriorityQueueTests().contains(PriorityQueueTest.COPY)) return;
|
||||
IntPriorityQueue queue = create(TEST_ARRAY);
|
||||
IntPriorityQueue copy = queue.copy();
|
||||
Assert.assertFalse(queue == copy);
|
||||
Assert.assertEquals(queue, copy);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,13 +22,6 @@ public class ObjectArrayListTest
|
||||
testCastable(ObjectArrayList.wrap("Test", "Testing", "Testing stuff"), true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptyCreation()
|
||||
{
|
||||
ObjectArrayList<String> test = ObjectArrayList.of(String.class);
|
||||
Assert.assertTrue(test.isCastable());
|
||||
}
|
||||
|
||||
public <T> void testCastable(IObjectArray<T> castable, boolean result)
|
||||
{
|
||||
Assert.assertTrue(castable.isCastable() == result);
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
package speiger.src.collections.objects.list;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
import com.google.common.collect.testing.ListTestSuiteBuilder;
|
||||
import com.google.common.collect.testing.TestStringListGenerator;
|
||||
import com.google.common.collect.testing.features.CollectionFeature;
|
||||
import com.google.common.collect.testing.features.CollectionSize;
|
||||
import com.google.common.collect.testing.features.ListFeature;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
import speiger.src.collections.objects.lists.ImmutableObjectList;
|
||||
import speiger.src.collections.objects.lists.ObjectArrayList;
|
||||
import speiger.src.collections.objects.lists.ObjectLinkedList;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public class ObjectListTests extends TestCase
|
||||
{
|
||||
public static Test suite()
|
||||
{
|
||||
TestSuite suite = new TestSuite("Lists");
|
||||
suite.addTest(suite("ArrayList", T -> new ObjectArrayList<>(T)));
|
||||
suite.addTest(suite("LinkedList", T -> new ObjectLinkedList<>(T)));
|
||||
suite.addTest(immutableSuite("ImmutableList", T -> new ImmutableObjectList<>(T)));
|
||||
return suite;
|
||||
}
|
||||
|
||||
public static Test suite(String name, Function<String[], List<String>> factory)
|
||||
{
|
||||
return ListTestSuiteBuilder.using(new TestStringListGenerator() {
|
||||
@Override
|
||||
protected List<String> create(String[] elements) { return factory.apply(elements); }
|
||||
}).named(name).withFeatures(ListFeature.GENERAL_PURPOSE, CollectionFeature.ALLOWS_NULL_VALUES, CollectionSize.ANY).createTestSuite();
|
||||
}
|
||||
|
||||
public static Test immutableSuite(String name, Function<String[], List<String>> factory)
|
||||
{
|
||||
return ListTestSuiteBuilder.using(new TestStringListGenerator() {
|
||||
@Override
|
||||
protected List<String> create(String[] elements) { return factory.apply(elements); }
|
||||
}).named(name).withFeatures(CollectionFeature.ALLOWS_NULL_VALUES, CollectionSize.ANY).createTestSuite();
|
||||
}
|
||||
}
|
||||
@@ -1,115 +0,0 @@
|
||||
package speiger.src.collections.objects.map;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.google.common.collect.testing.AnEnum;
|
||||
import com.google.common.collect.testing.MapTestSuiteBuilder;
|
||||
import com.google.common.collect.testing.TestEnumMapGenerator;
|
||||
import com.google.common.collect.testing.TestStringMapGenerator;
|
||||
import com.google.common.collect.testing.features.CollectionFeature;
|
||||
import com.google.common.collect.testing.features.CollectionSize;
|
||||
import com.google.common.collect.testing.features.MapFeature;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
import speiger.src.collections.objects.maps.impl.customHash.Object2ObjectLinkedOpenCustomHashMap;
|
||||
import speiger.src.collections.objects.maps.impl.customHash.Object2ObjectOpenCustomHashMap;
|
||||
import speiger.src.collections.objects.maps.impl.hash.Object2ObjectLinkedOpenHashMap;
|
||||
import speiger.src.collections.objects.maps.impl.hash.Object2ObjectOpenHashMap;
|
||||
import speiger.src.collections.objects.maps.impl.immutable.ImmutableObject2ObjectOpenHashMap;
|
||||
import speiger.src.collections.objects.maps.impl.misc.Enum2ObjectMap;
|
||||
import speiger.src.collections.objects.maps.impl.misc.LinkedEnum2ObjectMap;
|
||||
import speiger.src.collections.objects.maps.impl.misc.Object2ObjectArrayMap;
|
||||
import speiger.src.collections.objects.maps.impl.tree.Object2ObjectAVLTreeMap;
|
||||
import speiger.src.collections.objects.maps.impl.tree.Object2ObjectRBTreeMap;
|
||||
import speiger.src.collections.objects.utils.ObjectStrategy;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public class ObjectMapTests extends TestCase
|
||||
{
|
||||
public static Test suite()
|
||||
{
|
||||
TestSuite suite = new TestSuite("Maps");
|
||||
suite.addTest(suite("HashMap", Object2ObjectOpenHashMap::new, true));
|
||||
suite.addTest(suite("LinkedHashMap", Object2ObjectLinkedOpenHashMap::new, true));
|
||||
suite.addTest(suite("CustomHashMap", () -> new Object2ObjectOpenCustomHashMap<>(Strategy.INSTANCE), true));
|
||||
suite.addTest(suite("LinkedCustomHashMap", () -> new Object2ObjectLinkedOpenCustomHashMap<>(Strategy.INSTANCE), true));
|
||||
suite.addTest(suite("RBTreeMap_NonNull", Object2ObjectRBTreeMap::new, false));
|
||||
suite.addTest(suite("AVLTreeMap_NonNull", Object2ObjectAVLTreeMap::new, false));
|
||||
suite.addTest(suite("RBTreeMap_Null", () -> new Object2ObjectRBTreeMap<String, String>(Comparator.nullsFirst(Comparator.naturalOrder())), true));
|
||||
suite.addTest(suite("AVLTreeMap_Null", () -> new Object2ObjectAVLTreeMap<String, String>(Comparator.nullsFirst(Comparator.naturalOrder())), true));
|
||||
suite.addTest(immutableSuit("ImmutableMap", ImmutableObject2ObjectOpenHashMap::new));
|
||||
suite.addTest(suite("ArrayMap", Object2ObjectArrayMap::new, true));
|
||||
suite.addTest(enumSuite("EnumMap", () -> new Enum2ObjectMap<>(AnEnum.class)));
|
||||
suite.addTest(enumSuite("LinkedEnumMap", () -> new LinkedEnum2ObjectMap<>(AnEnum.class)));
|
||||
return suite;
|
||||
}
|
||||
|
||||
public static Test suite(String name, Supplier<Map<String, String>> factory, boolean allowNull)
|
||||
{
|
||||
MapTestSuiteBuilder<String, String> builder = MapTestSuiteBuilder.using(new TestStringMapGenerator() {
|
||||
@Override
|
||||
protected Map<String, String> create(Map.Entry<String, String>[] entries) {
|
||||
Map<String, String> map = factory.get();
|
||||
for(Map.Entry<String, String> entry : entries) {
|
||||
map.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
return map;
|
||||
}
|
||||
}).named(name).withFeatures(CollectionSize.ANY, MapFeature.GENERAL_PURPOSE, MapFeature.ALLOWS_NULL_VALUES, CollectionFeature.SUPPORTS_ITERATOR_REMOVE);
|
||||
if(allowNull) builder.withFeatures(MapFeature.ALLOWS_NULL_KEYS, MapFeature.ALLOWS_ANY_NULL_QUERIES);
|
||||
return builder.createTestSuite();
|
||||
}
|
||||
|
||||
public static Test immutableSuit(String name, BiFunction<String[], String[], Map<String, String>> factory) {
|
||||
MapTestSuiteBuilder<String, String> builder = MapTestSuiteBuilder.using(new TestStringMapGenerator() {
|
||||
@Override
|
||||
protected Map<String, String> create(Map.Entry<String, String>[] entries) {
|
||||
String[] keys = new String[entries.length];
|
||||
String[] values = new String[entries.length];
|
||||
for(int i = 0;i<entries.length;i++) {
|
||||
keys[i] = entries[i].getKey();
|
||||
values[i] = entries[i].getValue();
|
||||
}
|
||||
return factory.apply(keys, values);
|
||||
}
|
||||
}).named(name).withFeatures(CollectionSize.ANY, MapFeature.ALLOWS_NULL_KEYS, MapFeature.ALLOWS_NULL_VALUES, MapFeature.ALLOWS_ANY_NULL_QUERIES);
|
||||
return builder.createTestSuite();
|
||||
}
|
||||
|
||||
public static Test enumSuite(String name, Supplier<Map<AnEnum, String>> factory)
|
||||
{
|
||||
MapTestSuiteBuilder<AnEnum, String> builder = MapTestSuiteBuilder.using(new TestEnumMapGenerator() {
|
||||
@Override
|
||||
protected Map<AnEnum, String> create(Map.Entry<AnEnum, String>[] entries) {
|
||||
Map<AnEnum, String> map = factory.get();
|
||||
for(Map.Entry<AnEnum, String> entry : entries) {
|
||||
map.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
return map;
|
||||
}
|
||||
}).named(name).withFeatures(CollectionSize.ANY, MapFeature.GENERAL_PURPOSE, MapFeature.ALLOWS_NULL_VALUES, CollectionFeature.SUPPORTS_ITERATOR_REMOVE);
|
||||
return builder.createTestSuite();
|
||||
}
|
||||
|
||||
private static class Strategy implements ObjectStrategy<String>
|
||||
{
|
||||
static final Strategy INSTANCE = new Strategy();
|
||||
|
||||
@Override
|
||||
public int hashCode(String o) {
|
||||
return Objects.hashCode(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(String key, String value) {
|
||||
return Objects.equals(key, value);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
package speiger.src.collections.objects.set;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
|
||||
import com.google.common.collect.testing.SetTestSuiteBuilder;
|
||||
import com.google.common.collect.testing.TestStringSetGenerator;
|
||||
import com.google.common.collect.testing.features.CollectionFeature;
|
||||
import com.google.common.collect.testing.features.CollectionSize;
|
||||
import com.google.common.collect.testing.features.SetFeature;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
import speiger.src.collections.objects.sets.ImmutableObjectOpenHashSet;
|
||||
import speiger.src.collections.objects.sets.ObjectAVLTreeSet;
|
||||
import speiger.src.collections.objects.sets.ObjectArraySet;
|
||||
import speiger.src.collections.objects.sets.ObjectLinkedOpenCustomHashSet;
|
||||
import speiger.src.collections.objects.sets.ObjectLinkedOpenHashSet;
|
||||
import speiger.src.collections.objects.sets.ObjectOpenCustomHashSet;
|
||||
import speiger.src.collections.objects.sets.ObjectOpenHashSet;
|
||||
import speiger.src.collections.objects.sets.ObjectRBTreeSet;
|
||||
import speiger.src.collections.objects.utils.ObjectStrategy;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public class ObjectSetTests extends TestCase
|
||||
{
|
||||
public static Test suite()
|
||||
{
|
||||
TestSuite suite = new TestSuite("Sets");
|
||||
suite.addTest(suite("HashSet", ObjectOpenHashSet::new, true));
|
||||
suite.addTest(suite("LinkedHashSet", ObjectLinkedOpenHashSet::new, true));
|
||||
suite.addTest(suite("CustomHashSet", T -> new ObjectOpenCustomHashSet<>(T, Strategy.INSTANCE), true));
|
||||
suite.addTest(suite("LinkedCustomHashSet", T -> new ObjectLinkedOpenCustomHashSet<>(T, Strategy.INSTANCE), true));
|
||||
suite.addTest(immutableSuite("ImmutableHashSet", ImmutableObjectOpenHashSet::new));
|
||||
suite.addTest(suite("ArraySet", ObjectArraySet::new, true));
|
||||
suite.addTest(suite("RBTreeSet_NonNull", ObjectRBTreeSet::new, false));
|
||||
suite.addTest(suite("AVLTreeSet_NonNull", ObjectAVLTreeSet::new, false));
|
||||
suite.addTest(suite("RBTreeSet_Null", T -> new ObjectRBTreeSet<>(T, Comparator.nullsFirst(Comparator.naturalOrder())), true));
|
||||
suite.addTest(suite("AVLTreeSet_Null", T -> new ObjectAVLTreeSet<>(T, Comparator.nullsFirst(Comparator.naturalOrder())), true));
|
||||
return suite;
|
||||
}
|
||||
|
||||
public static Test suite(String name, Function<String[], Set<String>> factory, boolean allowNull)
|
||||
{
|
||||
SetTestSuiteBuilder<String> generator = SetTestSuiteBuilder.using(new TestStringSetGenerator() {
|
||||
@Override
|
||||
protected Set<String> create(String[] elements) { return factory.apply(elements); }
|
||||
}).named(name).withFeatures(CollectionSize.ANY, SetFeature.GENERAL_PURPOSE);
|
||||
if(allowNull) generator.withFeatures(CollectionFeature.ALLOWS_NULL_VALUES);
|
||||
return generator.createTestSuite();
|
||||
}
|
||||
|
||||
|
||||
public static Test immutableSuite(String name, Function<String[], Set<String>> factory)
|
||||
{
|
||||
return SetTestSuiteBuilder.using(new TestStringSetGenerator() {
|
||||
@Override
|
||||
protected Set<String> create(String[] elements) { return factory.apply(elements); }
|
||||
}).named(name).withFeatures(CollectionSize.ANY, CollectionFeature.ALLOWS_NULL_VALUES).createTestSuite();
|
||||
}
|
||||
|
||||
private static class Strategy implements ObjectStrategy<String>
|
||||
{
|
||||
static final Strategy INSTANCE = new Strategy();
|
||||
|
||||
@Override
|
||||
public int hashCode(String o) {
|
||||
return Objects.hashCode(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(String key, String value) {
|
||||
return Objects.equals(key, value);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -11,12 +11,9 @@ public enum CollectionTest
|
||||
REMOVE,
|
||||
REMOVE_IF,
|
||||
REMOVE_ALL,
|
||||
REMOVE_ALL_LISTENER,
|
||||
RETAIN_ALL,
|
||||
RETAIN_ALL_LISTENER,
|
||||
TO_ARRAY,
|
||||
CLEAR,
|
||||
WRAPPER,
|
||||
TO_STRING,
|
||||
COPY;
|
||||
TO_STRING;
|
||||
}
|
||||
|
||||
@@ -7,15 +7,5 @@ public enum IterableTest
|
||||
ITERATOR_FOR_EACH,
|
||||
ITERATOR_LOOP,
|
||||
ITERATOR_REMOVAL,
|
||||
ITERATOR_SKIP,
|
||||
STREAM_COUNT,
|
||||
STREAM_FILTER,
|
||||
STREAM_FIND_FIRST,
|
||||
STREAM_DISTINCT,
|
||||
STREAM_LIMIT,
|
||||
STREAM_MAP,
|
||||
STREAM_MATCHES,
|
||||
STREAM_PEEK,
|
||||
STREAM_POUR,
|
||||
STREAM_REDUCE;
|
||||
ITERATOR_SKIP;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ public enum ListTest
|
||||
ADD_INDEX_COLLECTION,
|
||||
ADD_INDEX_LIST,
|
||||
ADD_ELEMENTS,
|
||||
ADD_SPECIAL,
|
||||
INDEX,
|
||||
LAST_INDEX,
|
||||
GET,
|
||||
@@ -18,7 +17,6 @@ public enum ListTest
|
||||
SORT,
|
||||
REPLACE,
|
||||
REMOVE,
|
||||
REMOVE_SWAP,
|
||||
REMOVE_ELEMENTS,
|
||||
EXTRACT_ELEMENTS,
|
||||
LIST_ITERATOR,
|
||||
|
||||
@@ -11,6 +11,5 @@ public enum MapTests
|
||||
MERGE,
|
||||
GET,
|
||||
ITERATORS,
|
||||
REMOVE,
|
||||
COPY;
|
||||
REMOVE;
|
||||
}
|
||||
|
||||
@@ -7,5 +7,4 @@ public enum PriorityQueueTest
|
||||
PEEK,
|
||||
REMOVE,
|
||||
TO_ARRAY,
|
||||
COPY;
|
||||
}
|
||||
Reference in New Issue
Block a user