Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
21ccbee3b2 | ||
|
|
58a9eb38b4 | ||
|
|
2f1525ab57 | ||
|
|
9f46091282 | ||
|
|
3d39d5526d | ||
|
|
c6f656ee66 | ||
|
|
f0139d1a22 | ||
|
|
58e20bb513 | ||
|
|
502f22cea3 | ||
|
|
90e3b7110a | ||
|
|
a26106cc89 | ||
|
|
d002f0094f | ||
|
|
042460a338 | ||
|
|
20927a97eb | ||
|
|
ebe75b0fea | ||
|
|
a6be24c59d | ||
|
|
afdd27648e | ||
|
|
7e475b5472 | ||
|
|
e65fde736b | ||
|
|
bf0b4172de | ||
|
|
961b47a58c | ||
|
|
330be87338 | ||
|
|
4b30ce12c9 | ||
|
|
0be7dba5d3 | ||
|
|
6eaa992f5f | ||
|
|
9b23d713ff | ||
|
|
85d230c561 | ||
|
|
6afed5e174 | ||
|
|
640a1a8161 | ||
|
|
274d37c4d6 | ||
|
|
a89c812c06 | ||
|
|
6af0656216 | ||
|
|
e76db94136 | ||
|
|
7011101b05 | ||
|
|
d0599b99ec | ||
|
|
d7c5b9ad7d | ||
|
|
d2c81e7779 | ||
|
|
ef5fdbd377 | ||
|
|
5e67e45910 | ||
|
|
63ef68fb95 | ||
|
|
0f9751bf70 | ||
|
|
bcc2ffdc13 | ||
|
|
2da4588430 | ||
|
|
ed9ce60af4 | ||
|
|
4dd3a4a6e8 | ||
|
|
efd29bbe7e | ||
|
|
96458bd8b6 | ||
|
|
477f3c9f40 | ||
|
|
3f6e7fbb88 | ||
|
|
5650c6e69b | ||
|
|
61df32b7b2 | ||
|
|
859d00da16 | ||
|
|
9df95c0fc3 | ||
|
|
d6d2c0a396 | ||
|
|
127eb71968 | ||
|
|
6005d0fd39 | ||
|
|
290e626f07 | ||
|
|
e30d011273 | ||
|
|
4c52636c23 | ||
|
|
aa580c1772 | ||
|
|
8f7d49b280 | ||
|
|
342b0cece9 | ||
|
|
3ce52668df | ||
|
|
ce9343348e | ||
|
|
8d9f7a6761 | ||
|
|
1b1ec4b87a | ||
|
|
cc92ef953a | ||
|
|
8d8c30c9a7 | ||
|
|
d44ad2d42e | ||
|
|
2ed090e989 | ||
|
|
dafb162797 | ||
|
|
57280b8285 | ||
|
|
c9fc963670 | ||
|
|
cc87cae145 | ||
|
|
f53d61a5bc | ||
|
|
b29874189c | ||
|
|
6722f399db | ||
|
|
8e39acef45 | ||
|
|
b065ebe9ba | ||
|
|
25a7cd060a | ||
|
|
21f330260e | ||
|
|
99e9afe7b1 | ||
|
|
5118ae8b1f | ||
|
|
03b23f0e3c | ||
|
|
ca33c9eb9e | ||
|
|
b4374fdd4d | ||
|
|
455ee64a88 | ||
|
|
893b371017 | ||
|
|
5fa9baae7a | ||
|
|
70d565c785 | ||
|
|
5c27e332cd | ||
|
|
f2d919bae5 | ||
|
|
7d4c77332b | ||
|
|
d1186d4f82 | ||
|
|
3b8a02ac51 | ||
|
|
f356d4ab57 | ||
|
|
b07bc85114 | ||
|
|
c37746cd84 | ||
|
|
fb7c417394 |
@@ -6,12 +6,6 @@
|
||||
<attribute name="gradle_used_by_scope" value="main,test"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="bin/main" path="src/main/resources">
|
||||
<attributes>
|
||||
<attribute name="gradle_scope" value="main"/>
|
||||
<attribute name="gradle_used_by_scope" value="main,test"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="bin/test" path="src/test/java">
|
||||
<attributes>
|
||||
<attribute name="gradle_scope" value="test"/>
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
name: Latest Build
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
pull_request:
|
||||
branches: [ master ]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
jdk: [8, 11, 17, 20, 21]
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
|
||||
- name: Set up JDK ${{ matrix.jdk }}
|
||||
uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: ${{ matrix.jdk }}
|
||||
|
||||
- name: Validate Gradle wrapper
|
||||
uses: gradle/actions/wrapper-validation@v6
|
||||
|
||||
- name: Make gradlew executable
|
||||
run: chmod +x ./gradlew
|
||||
|
||||
- name: Build with Gradle
|
||||
run: ./gradlew build
|
||||
@@ -0,0 +1,84 @@
|
||||
name: Unit Tests
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Unit Tests
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Set up JDK 11
|
||||
uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: temurin
|
||||
java-version: 11
|
||||
cache: gradle
|
||||
|
||||
- name: Make gradlew executable
|
||||
run: chmod +x ./gradlew
|
||||
- name: Build and Test
|
||||
run: |
|
||||
./gradlew generateTestSource test jacocoTestReport --info -Dfull_test_suite=true
|
||||
./gradlew --stop
|
||||
|
||||
- name: Publish Test Result
|
||||
uses: EnricoMi/publish-unit-test-result-action@v2
|
||||
id: test-results
|
||||
if: always()
|
||||
with:
|
||||
junit_files: build/test-results/**/*.xml
|
||||
fail_on: nothing
|
||||
ignore_runs: true
|
||||
json_thousands_separator: .
|
||||
time_unit: milliseconds
|
||||
|
||||
- name: Create Badge Color
|
||||
shell: bash
|
||||
run: |
|
||||
case ${{ fromJSON( steps.test-results.outputs.json ).conclusion }} in
|
||||
success)
|
||||
echo "BADGE_COLOR=31c653" >> $GITHUB_ENV
|
||||
;;
|
||||
failure)
|
||||
echo "BADGE_COLOR=800000" >> $GITHUB_ENV
|
||||
;;
|
||||
neutral)
|
||||
echo "BADGE_COLOR=696969" >> $GITHUB_ENV
|
||||
;;
|
||||
esac
|
||||
|
||||
- name: Create Test Badge
|
||||
uses: emibcn/badge-action@v2
|
||||
with:
|
||||
label: Tests
|
||||
status: '${{ fromJSON( steps.test-results.outputs.json ).conclusion }}, Passed: ${{ fromJSON( steps.test-results.outputs.json ).formatted.stats.tests_succ }}, Skipped: ${{ fromJSON( steps.test-results.outputs.json ).formatted.stats.tests_skip }}, Failed: ${{ fromJSON( steps.test-results.outputs.json ).formatted.stats.tests_fail }}'
|
||||
color: ${{ env.BADGE_COLOR }}
|
||||
path: tests.svg
|
||||
|
||||
- name: Create Coverage Badge
|
||||
id: jacoco
|
||||
uses: cicirello/jacoco-badge-generator@v2
|
||||
with:
|
||||
jacoco-csv-file: build/reports/jacoco/test/jacocoTestReport.csv
|
||||
badges-directory: null
|
||||
intervals: 95 80 70 60 50 0
|
||||
|
||||
- name: Upload Test Badge
|
||||
uses: exuanbo/actions-deploy-gist@v1
|
||||
with:
|
||||
token: ${{ secrets.GIST_TOKEN }}
|
||||
gist_id: 280257cd19cbe1dda3789bebd4ff65cf
|
||||
file_path: tests.svg
|
||||
|
||||
- name: Upload Coverage Badge
|
||||
uses: exuanbo/actions-deploy-gist@v1
|
||||
with:
|
||||
token: ${{ secrets.GIST_TOKEN }}
|
||||
gist_id: 280257cd19cbe1dda3789bebd4ff65cf
|
||||
file_path: jacoco.svg
|
||||
@@ -1,36 +0,0 @@
|
||||
# This workflow uses actions that are not certified by GitHub.
|
||||
# They are provided by a third-party and are governed by
|
||||
# separate terms of service, privacy policy, and support
|
||||
# documentation.
|
||||
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
|
||||
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle
|
||||
|
||||
name: Latest Build
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
pull_request:
|
||||
branches: [ master ]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
jdk: [8, 11, 14, 16, 17]
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Set up JDK ${{ matrix.jdk }}
|
||||
uses: actions/setup-java@v1
|
||||
with:
|
||||
java-version: ${{ matrix.jdk }}
|
||||
- name: Validate Gradle wrapper
|
||||
uses: gradle/wrapper-validation-action@e6e38bacfdf1a337459f332974bb2327a31aaf4b
|
||||
- name: Make gradlew executable
|
||||
run: chmod +x ./gradlew
|
||||
- name: Build with Gradle
|
||||
run: ./gradlew build
|
||||
@@ -0,0 +1,27 @@
|
||||
name: Measure coverage
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ debug ]
|
||||
jobs:
|
||||
build:
|
||||
name: Code Quality Check
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
with:
|
||||
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
|
||||
- name: Set up JDK 11
|
||||
uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: 11
|
||||
cache: 'gradle'
|
||||
- name: Make gradlew executable
|
||||
run: chmod +x ./gradlew
|
||||
- name: Build and analyze
|
||||
run: ./gradlew generateTestSource test jacocoTestReport --info -Dfull_test_suite=true
|
||||
- name: Upload to CodeCov
|
||||
env:
|
||||
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
|
||||
run: bash <(curl -s https://codecov.io/bash) -t $CODECOV_TOKEN
|
||||
@@ -0,0 +1,39 @@
|
||||
name: Unit Tests
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches: [ master ]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Unit Tests
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Set up JDK 11
|
||||
uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: temurin
|
||||
java-version: 11
|
||||
cache: gradle
|
||||
|
||||
- name: Make gradlew executable
|
||||
run: chmod +x ./gradlew
|
||||
- name: Build and Test
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: ./gradlew generateTestSource test jacocoTestReport --info -Dfull_test_suite=true
|
||||
|
||||
- name: Publish Test Result
|
||||
uses: EnricoMi/publish-unit-test-result-action@v2
|
||||
id: test-results
|
||||
if: always()
|
||||
with:
|
||||
junit_files: build/test-results/**/*.xml
|
||||
fail_on: nothing
|
||||
ignore_runs: true
|
||||
json_thousands_separator: .
|
||||
time_unit: milliseconds
|
||||
+14
@@ -30,5 +30,19 @@ gradle-app.setting
|
||||
/src/main/java/speiger/src/collections/doubles/*
|
||||
/src/main/java/speiger/src/collections/objects/*
|
||||
|
||||
#Generated Tests
|
||||
/src/test/java/speiger/src/testers/booleans/*
|
||||
/src/test/java/speiger/src/testers/bytes/*
|
||||
/src/test/java/speiger/src/testers/shorts/*
|
||||
/src/test/java/speiger/src/testers/chars/*
|
||||
/src/test/java/speiger/src/testers/ints/*
|
||||
/src/test/java/speiger/src/testers/longs/*
|
||||
/src/test/java/speiger/src/testers/floats/*
|
||||
/src/test/java/speiger/src/testers/doubles/*
|
||||
/src/test/java/speiger/src/testers/objects/*
|
||||
/src/test/java/speiger/src/tests/*
|
||||
|
||||
#Cache result
|
||||
/src/builder/resources/speiger/assets/collections/cache.bin
|
||||
/src/builder/resources/speiger/assets/testers/cache.bin
|
||||
/src/builder/resources/speiger/assets/tests/cache.bin
|
||||
|
||||
@@ -2,21 +2,22 @@
|
||||
<projectDescription>
|
||||
<name>Primitive-Collections</name>
|
||||
<comment></comment>
|
||||
<projects/>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
|
||||
</natures>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments/>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
|
||||
<arguments/>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<linkedResources/>
|
||||
<filteredResources/>
|
||||
</projectDescription>
|
||||
|
||||
@@ -1,5 +1,61 @@
|
||||
# Changelog of versions
|
||||
|
||||
### Version 0.9.0
|
||||
- Added: getFirst/getLast/removeFirst/removeLast to List.class.
|
||||
- Added: Dedicated Set toArray implementations.
|
||||
- Added: ToArray/pushTop functions to Stack.class.
|
||||
- Added: ComputeNonDefault functions which will contain the current behavior of the Compute function, while the Compute will be changed to be more java compliant!
|
||||
- Added: List.reversed, which returns a SubList that has all elements in reversed order and also inserts reversed.
|
||||
- Added: Iterators.infinite as an option that will create a Infinite Iterator based on the inputed one.
|
||||
- Added: List.indexedIterator which allows you to create a iterator with a customized iteration indecies. Useful if you want to transform lists output.
|
||||
- Added: PriorityQueue.contains is now a function
|
||||
- Added: Iterators/Async Builders now support MapToPrimitiveType function on the object variant. So more processing can be done. (Will be expanded upon later versions)
|
||||
- Fixed: SetValue wasn't working on forEach implementations.
|
||||
- Fixed: Compute functions now perform with primitives more java compliant. Meaning that getDefaultReturnValue function no longer is seen as null.
|
||||
- Fixed: Supplier was using the wrong dataType in their function name.
|
||||
- Updated: SimpleCodeGenerator 1.3.0 is now being used which allows for iterative code support.
|
||||
- Breaking Change: Map.compute/IfAbsent/Present and Map.supplyIfAbsent if the value is a primitive it will no longer accept the defaultReturnValue() as "null" if that functionality is desired then use: computeNonDefault which contains the functionality!
|
||||
|
||||
### Version 0.8.1
|
||||
- Added: getFirst/getLast/removeFirst/removeLast to List.class.
|
||||
- Added: Dedicated Set toArray implementations.
|
||||
- Added: ToArray/pushTop functions to Stack.class.
|
||||
- Added: ComputeNonDefault functions which will contain the current behavior of the Compute function, while the Compute will be changed to be more java compliant!
|
||||
- Added: List.reversed, which returns a SubList that has all elements in reversed order and also inserts reversed.
|
||||
- Added: Iterators.infinite as an option that will create a Infinite Iterator based on the inputed one.
|
||||
- Added: List.indexedIterator which allows you to create a iterator with a customized iteration indecies. Useful if you want to transform lists output.
|
||||
- Added: PriorityQueue.contains is now a function
|
||||
- Added: Iterators/Async Builders now support MapToPrimitiveType function on the object variant. So more processing can be done. (Will be expanded upon later versions)
|
||||
- Fixed: SetValue wasn't working on forEach implementations.
|
||||
- Fixed: Compute functions now perform with primitives more java compliant. Meaning that getDefaultReturnValue function no longer is seen as null.
|
||||
- Fixed: Supplier was using the wrong dataType in their function name.
|
||||
- Updated: SimpleCodeGenerator 1.3.0 is now being used which allows for iterative code support.
|
||||
|
||||
### Version 0.8.0
|
||||
- Added: getFirst/getLast/removeFirst/removeLast to Lists
|
||||
- Added: Dedicated implementations for toArray into TreeSets
|
||||
- Fixed: forEach methods in Maps now can use "setValue" functions.
|
||||
|
||||
### Version 0.8.0
|
||||
- Added: ISizeProvider interface (Optimization Helper)
|
||||
- Added: ISizeProvider into most Iterable implementations (Distinct/Filter/FlatMap/ArrayFlatMap don't support it, for obvious reasons)
|
||||
- Added: ToArray function into Iterable which uses ISizeProvider to reduce overhead of duplicating arrays.
|
||||
- Added: Functions that have the same type, Int2IntFunction as example, have now a identity function.
|
||||
- Added: Functions of a BooleanValue have now alwaysTrue/False function.
|
||||
- Added: ForEachIndexed for all Iterable implementations
|
||||
- Added: RandomGenerator support (Java17), though requires self compilation
|
||||
- Added: Optimizations for HashUtils next power of function.
|
||||
- Added: toArray() now returns a cached empty array if the collection is empty.
|
||||
- Added: toArray function for AsyncBuilder
|
||||
- Added: Modularization to the library where feature can be disabled as needed. (Requires Self-Compilation)
|
||||
- Fixed: putIfAbsent now replaces defaultValues
|
||||
- Fixed: OpenHashSet/Map and their Custom Variants no longer rely on List implementations.
|
||||
- Fixed: ObjectCopyOnWriteList.of did create a ObjectArrayList instead of the CopyOnWrite variant.
|
||||
- Removed: BooleanSet and Maps that start with a Boolean classes since they can not be used anyways.
|
||||
- Breaking Change: Function classes now use the "apply/applyAs/test" format from Java itself, instead of the "get" format. This cleans up a lot of things. But will break existing function class implementations
|
||||
- Breaking Change: Classes that used PrimitiveCollection functions now default to java functions where applicable, this is to increase compat.
|
||||
- Breaking Change: Some function classes now get closer to javas terms. (Predicate/UnaryOperator etc)
|
||||
|
||||
### Version 0.7.0
|
||||
- Added: Over 11 Million Unit Tests to this library to ensure quality.
|
||||
- Added: ArrayList size constructor now throws IllegalStateException if the size parameter is negative
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
### Extra Features
|
||||
|
||||
Primitive Collections comes with a few extra features that are disabled by default.
|
||||
These will be enabled as soon they become relevant or never at all.
|
||||
|
||||
But some of these can be already unlocked when the target version changes.
|
||||
|
||||
If you compile the library for yourself you will automatically gain access to said features.
|
||||
|
||||
### Java17 Exclusive Features
|
||||
Java17 has some new features that can sadly not really be back-ported but the library still supports them if it is compiled with java17
|
||||
|
||||
- RandomGenerator: Java17 has added [RandomGenerator.class](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/random/RandomGenerator.html).
|
||||
This allows to use custom random implementations without having to re-implement them yourselves.
|
||||
|
||||
|
||||
### ModuleSettings
|
||||
Primitive Collections is a huge library.
|
||||
But maybe you only use like 5-10 different classes.
|
||||
Normally you would use tools like "Proguard" to get rid of classes that you don't use.
|
||||
But since a lot of classes have dependencies on each other this would only do so much.
|
||||
|
||||
This is where the [ModuleSettings](ModuleSettings.json) come into play.
|
||||
It allows you to turn of implementations as you wish and adjusts the code that everything still works.
|
||||
|
||||
There is 3 layers of control inside of the ModuleSettings.
|
||||
- Modules directly at the top that turn off everything.
|
||||
- Type Specific configurations, where you can for example turn of everything thats "Long" based.
|
||||
- And then there is each type specific module settings.
|
||||
|
||||
Allowing for greater control without having to edit hundreds of lines of code.
|
||||
On top of that:
|
||||
Any Setting that isn't "Present" can be defined as "Enabled" or "Disabled" using the "Default" argument.
|
||||
If "Default" is missing, then it will just default to "Enabled".
|
||||
So if you want to disable just 1 thing you can keep that 1 thing and delete the rest of the Setting.
|
||||
It will still work as the same.
|
||||
The default settings just come with everything so you can see what is controllable.
|
||||
Note: If a global Module setting is disabled but a dependency needs said Module, it will enable only the required classes.
|
||||
If a Module type (Float-Collection as example) is specifically disabled, the Dependency Resolver will throw errors telling you whats wrong.
|
||||
|
||||
How to compile the Code with the ModuleSettings enabled:
|
||||
```
|
||||
/gradlew.bat generateLimitSource build -x test
|
||||
```
|
||||
+2625
File diff suppressed because it is too large
Load Diff
@@ -1,8 +1,12 @@
|
||||

|
||||

|
||||
[](https://jitpack.io/#Speiger/Primitive-Collections)
|
||||

|
||||
[](https://opensource.org/licenses/Apache-2.0)
|
||||

|
||||

|
||||

|
||||

|
||||
[](https://codecov.io/gh/Speiger/Primitive-Collections)
|
||||

|
||||
# Primitive-Collections
|
||||
This is a Simple Primitive Collections Library aimed to outperform Java's Collection Library and FastUtil.
|
||||
Both in Performance and Quality of Life Features.
|
||||
@@ -14,6 +18,10 @@ Benchmarks can be found here: [[Charts]](https://github.com/Speiger/Primitive-Co
|
||||
[Here](features.md) you find a set of features added to Primitive Collections.
|
||||
These are designed to improve performance or to provide Quality of Life.
|
||||
|
||||
[Here](EXTRAS.md) you also find features that can be used when you compile the library for yourself.
|
||||
These features are not used by default to have a wider range of compat, or require self compilation.
|
||||
Such as pruning classes that are not needed in your code.
|
||||
|
||||
## Main Features:
|
||||
- ArrayLists / LinkedLists / CopyOnWriteLists
|
||||
- HashSets/Maps (Linked & HashControl)
|
||||
@@ -36,14 +44,21 @@ To ensure that problems can be dealt with even if it is breaking the current API
|
||||
|
||||
# How to install
|
||||
Using Jitpack Gradle
|
||||
```gradle
|
||||
```groovy
|
||||
repositories {
|
||||
maven {
|
||||
url = "https://jitpack.io"
|
||||
}
|
||||
}
|
||||
dependencies {
|
||||
implementation 'com.github.Speiger:Primitive-Collections:0.7.0'
|
||||
implementation 'com.github.Speiger:Primitive-Collections:0.9.0'
|
||||
}
|
||||
```
|
||||
|
||||
Using Maven Central
|
||||
```groovy
|
||||
dependencies {
|
||||
implementation 'io.github.speiger:Primitive-Collections:0.9.0'
|
||||
}
|
||||
```
|
||||
|
||||
@@ -68,7 +83,11 @@ Please if you want to contribute follow the [Rule-Sheet](RuleSheet.md). It keeps
|
||||
# How to Build
|
||||
|
||||
The SourceCode can be generated via:
|
||||
```
|
||||
/gradlew.bat generateSource
|
||||
```
|
||||
|
||||
to generate SourceCode and build the jar:
|
||||
```
|
||||
/gradlew.bat build
|
||||
```
|
||||
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
# Security Policy
|
||||
|
||||
## Supported Versions
|
||||
|
||||
Due to how the releases work, only the latest versions will be supported.
|
||||
|
||||
## Reporting a Vulnerability
|
||||
|
||||
If you have discovered a security vulnerability in this project, please report it privately.
|
||||
**Please refrain from posting in public issues.**
|
||||
This gives me time to process issues that are being found, and reduces the possiblity of abuse while patches are being created.
|
||||
Please disclose it [here](https://github.com/Speiger/Primitive-Collections/security/advisories/new).
|
||||
|
||||
Please consider that this project is developed by a single person.
|
||||
So please provide a reasonable timeframe when reporting.
|
||||
+255
-24
@@ -1,5 +1,6 @@
|
||||
plugins {
|
||||
id 'java-library'
|
||||
id "jacoco"
|
||||
}
|
||||
|
||||
tasks.withType(JavaCompile) {
|
||||
@@ -9,6 +10,7 @@ tasks.withType(JavaCompile) {
|
||||
apply plugin: 'java'
|
||||
apply plugin: 'eclipse'
|
||||
apply plugin: 'maven-publish'
|
||||
apply plugin: 'signing'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
@@ -18,16 +20,22 @@ repositories {
|
||||
}
|
||||
|
||||
archivesBaseName = 'Primitive Collections'
|
||||
version = '0.7.0';
|
||||
version = RELEASE_VERSION;
|
||||
|
||||
sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = JavaVersion.current();
|
||||
|
||||
System.out.println("Java Version: "+compileJava.sourceCompatibility)
|
||||
|
||||
java {
|
||||
withJavadocJar()
|
||||
withSourcesJar()
|
||||
}
|
||||
|
||||
javadoc {
|
||||
options.tags = [ "implSpec", "note" ]
|
||||
}
|
||||
|
||||
|
||||
eclipse {
|
||||
classpath {
|
||||
downloadJavadoc = true
|
||||
@@ -39,14 +47,16 @@ sourceSets {
|
||||
builder
|
||||
}
|
||||
|
||||
|
||||
configurations {
|
||||
builderCompile.extendsFrom compile
|
||||
}
|
||||
|
||||
dependencies {
|
||||
builderImplementation 'de.speiger:Simple-Code-Generator:1.1.4'
|
||||
builderImplementation 'com.google.code.gson:gson:2.10'
|
||||
builderImplementation 'de.speiger:Simple-Code-Generator:1.3.0'
|
||||
testImplementation 'junit:junit:4.12'
|
||||
testImplementation 'com.google.guava:guava-testlib:31.0.1-jre'
|
||||
testImplementation 'com.google.guava:guava-testlib:33.6.0-jre'
|
||||
|
||||
}
|
||||
|
||||
@@ -62,7 +72,7 @@ task generateGithubSource(type: JavaExec) {
|
||||
description = 'Builds the sourcecode for Github Actions'
|
||||
classpath = sourceSets.builder.runtimeClasspath
|
||||
main = 'speiger.src.builder.PrimitiveCollectionsBuilder'
|
||||
args = ['false', 'true']
|
||||
args = ['silent']
|
||||
}
|
||||
|
||||
task forceGenerateSource(type: JavaExec) {
|
||||
@@ -70,17 +80,31 @@ task forceGenerateSource(type: JavaExec) {
|
||||
description = 'Builds the sourcecode forceful'
|
||||
classpath = sourceSets.builder.runtimeClasspath
|
||||
main = 'speiger.src.builder.PrimitiveCollectionsBuilder'
|
||||
args = ['true']
|
||||
args = ['force']
|
||||
}
|
||||
|
||||
task javadocJar(type: Jar) {
|
||||
from javadoc
|
||||
classifier = 'javadoc'
|
||||
task generateTestSource(type: JavaExec) {
|
||||
group = 'internal'
|
||||
description = 'Builds the sourcecode for the Tests'
|
||||
classpath = sourceSets.builder.runtimeClasspath
|
||||
main = 'speiger.src.builder.PrimitiveCollectionsBuilder'
|
||||
args = ['tests', 'silent']
|
||||
}
|
||||
|
||||
task srcJar(type: Jar) {
|
||||
from sourceSets.main.allSource
|
||||
classifier = 'sources'
|
||||
task forceGenerateTestSource(type: JavaExec) {
|
||||
group = 'internal'
|
||||
description = 'Builds the sourcecode for the Tests'
|
||||
classpath = sourceSets.builder.runtimeClasspath
|
||||
main = 'speiger.src.builder.PrimitiveCollectionsBuilder'
|
||||
args = ['tests', 'silent', 'force']
|
||||
}
|
||||
|
||||
task generateLimitSource(type: JavaExec) {
|
||||
group = 'internal'
|
||||
description = 'Builds the Sourcecode with the ModuleSettings.json applied'
|
||||
classpath = sourceSets.builder.runtimeClasspath
|
||||
main = 'speiger.src.builder.PrimitiveCollectionsBuilder'
|
||||
args = ['silent', 'load']
|
||||
}
|
||||
|
||||
compileJava.dependsOn generateGithubSource
|
||||
@@ -89,22 +113,159 @@ javadoc.failOnError = false
|
||||
javadoc.options.memberLevel = JavadocMemberLevel.PUBLIC
|
||||
javadoc.options.quiet()
|
||||
|
||||
artifacts {
|
||||
archives javadocJar
|
||||
archives srcJar
|
||||
|
||||
task testBooleans(type: Test) {
|
||||
group 'tests'
|
||||
description 'Tests all Boolean Collections'
|
||||
filter {
|
||||
excludeTestsMatching "speiger.src.testers.**.*"
|
||||
includeTestsMatching "speiger.src.tests.booleans.**.*"
|
||||
}
|
||||
useJUnit()
|
||||
ignoreFailures = true
|
||||
maxHeapSize = maxMemory
|
||||
}
|
||||
|
||||
task testBytes(type: Test) {
|
||||
group 'tests'
|
||||
description 'Tests all Byte Collections'
|
||||
filter {
|
||||
excludeTestsMatching "speiger.src.testers.**.*"
|
||||
includeTestsMatching "speiger.src.tests.bytes.**.*"
|
||||
}
|
||||
useJUnit()
|
||||
ignoreFailures = true
|
||||
maxHeapSize = maxMemory
|
||||
maxParallelForks = testThreads as Integer
|
||||
}
|
||||
|
||||
task testShorts(type: Test) {
|
||||
group 'tests'
|
||||
description 'Tests all Short Collections'
|
||||
filter {
|
||||
excludeTestsMatching "speiger.src.testers.**.*"
|
||||
includeTestsMatching "speiger.src.tests.shorts.**.*"
|
||||
}
|
||||
useJUnit()
|
||||
ignoreFailures = true
|
||||
maxHeapSize = maxMemory
|
||||
maxParallelForks = testThreads as Integer
|
||||
}
|
||||
|
||||
task testChars(type: Test) {
|
||||
group 'tests'
|
||||
description 'Tests all Character Collections'
|
||||
filter {
|
||||
excludeTestsMatching "speiger.src.testers.**.*"
|
||||
includeTestsMatching "speiger.src.tests.chars.**.*"
|
||||
}
|
||||
useJUnit()
|
||||
ignoreFailures = true
|
||||
maxHeapSize = maxMemory
|
||||
maxParallelForks = testThreads as Integer
|
||||
}
|
||||
|
||||
task testInts(type: Test) {
|
||||
group 'tests'
|
||||
description 'Tests all Int Collections'
|
||||
filter {
|
||||
excludeTestsMatching "speiger.src.testers.**.*"
|
||||
includeTestsMatching "speiger.src.tests.ints.**.*"
|
||||
}
|
||||
useJUnit()
|
||||
ignoreFailures = true
|
||||
maxHeapSize = maxMemory
|
||||
maxParallelForks = testThreads as Integer
|
||||
}
|
||||
|
||||
task testLongs(type: Test) {
|
||||
group 'tests'
|
||||
description 'Tests all Long Collections'
|
||||
filter {
|
||||
excludeTestsMatching "speiger.src.testers.**.*"
|
||||
includeTestsMatching "speiger.src.tests.longs.**.*"
|
||||
}
|
||||
useJUnit()
|
||||
ignoreFailures = true
|
||||
maxHeapSize = maxMemory
|
||||
maxParallelForks = testThreads as Integer
|
||||
}
|
||||
|
||||
task testFloats(type: Test) {
|
||||
group 'tests'
|
||||
description 'Tests all Float Collections'
|
||||
filter {
|
||||
excludeTestsMatching "speiger.src.testers.**.*"
|
||||
includeTestsMatching "speiger.src.tests.floats.**.*"
|
||||
}
|
||||
useJUnit()
|
||||
ignoreFailures = true
|
||||
maxHeapSize = maxMemory
|
||||
maxParallelForks = testThreads as Integer
|
||||
}
|
||||
|
||||
task testDoubles(type: Test) {
|
||||
group 'tests'
|
||||
description 'Tests all Double Collections'
|
||||
filter {
|
||||
excludeTestsMatching "speiger.src.testers.**.*"
|
||||
includeTestsMatching "speiger.src.tests.doubles.**.*"
|
||||
}
|
||||
useJUnit()
|
||||
ignoreFailures = true
|
||||
maxHeapSize = maxMemory
|
||||
maxParallelForks = testThreads as Integer
|
||||
}
|
||||
|
||||
task testObjects(type: Test) {
|
||||
group 'tests'
|
||||
description 'Tests all Object Collections'
|
||||
filter {
|
||||
excludeTestsMatching "speiger.src.testers.**.*"
|
||||
includeTestsMatching "speiger.src.tests.objects.**.*"
|
||||
}
|
||||
useJUnit()
|
||||
ignoreFailures = true
|
||||
maxHeapSize = maxMemory
|
||||
maxParallelForks = testThreads as Integer
|
||||
}
|
||||
|
||||
if(System.getProperty("full_test_suite", "false").toBoolean()) {
|
||||
test.dependsOn testBooleans
|
||||
test.dependsOn testBytes
|
||||
test.dependsOn testShorts
|
||||
test.dependsOn testChars
|
||||
test.dependsOn testInts
|
||||
test.dependsOn testLongs
|
||||
test.dependsOn testFloats
|
||||
test.dependsOn testDoubles
|
||||
test.dependsOn testObjects
|
||||
}
|
||||
|
||||
test {
|
||||
useJUnit()
|
||||
filter {
|
||||
excludeTestsMatching "speiger.src.testers.**.*"
|
||||
excludeTestsMatching "speiger.src.tests.**.*"
|
||||
excludeTestsMatching "tests.**.*"
|
||||
}
|
||||
useJUnit()
|
||||
ignoreFailures = true
|
||||
maxHeapSize = maxMemory
|
||||
}
|
||||
|
||||
jacocoTestReport {
|
||||
executionData fileTree(project.buildDir.absolutePath).include("jacoco/*.exec")
|
||||
reports {
|
||||
xml.required = true
|
||||
html.required = true
|
||||
csv.required = true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
publishing {
|
||||
Properties props = new Properties()
|
||||
if(file("$buildDir/credentials.properties").exists()) {
|
||||
props.load(new FileInputStream("$buildDir/credentials.properties"))
|
||||
}
|
||||
publications {
|
||||
mavenJava(MavenPublication) {
|
||||
personal(MavenPublication) {
|
||||
pom {
|
||||
name = 'Primitive Collections'
|
||||
description = 'A Primitive Collection library that reduces memory usage and improves performance'
|
||||
@@ -113,8 +274,6 @@ publishing {
|
||||
artifactId = project.archivesBaseName.replace(" ", "-")
|
||||
groupId = 'de.speiger'
|
||||
from components.java
|
||||
artifact tasks.srcJar
|
||||
artifact tasks.javadocJar
|
||||
licenses {
|
||||
license {
|
||||
name = 'The Apache License, Version 2.0'
|
||||
@@ -139,11 +298,83 @@ publishing {
|
||||
}
|
||||
repositories {
|
||||
maven {
|
||||
name = "Speiger_Maven"
|
||||
def auth = System.getenv("Speiger_Maven_Auth")?.split(';');
|
||||
url version.endsWith('SNAPSHOT') ? "https://maven.speiger.com/repository/debug" : "https://maven.speiger.com/repository/main"
|
||||
credentials(PasswordCredentials) {
|
||||
username props.mavenUser
|
||||
password props.mavenPassword
|
||||
username auth?[0]
|
||||
password auth?[1]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tasks.withType(PublishToMavenRepository) {
|
||||
def predicate = provider {
|
||||
(repository == publishing.repositories.mavenCentral && publication == publishing.publications.maven) ||
|
||||
(repository != publishing.repositories.mavenCentral && publication != publishing.publications.maven)
|
||||
}
|
||||
onlyIf("publishing binary to the external repository, or binary and sources to the internal one") {
|
||||
predicate.get()
|
||||
}
|
||||
}
|
||||
|
||||
tasks.withType(PublishToMavenLocal) {
|
||||
def predicate = provider {
|
||||
publication == publishing.publications.personal
|
||||
}
|
||||
onlyIf("publishing binary and sources") {
|
||||
predicate.get()
|
||||
}
|
||||
}
|
||||
|
||||
//Maven central Start
|
||||
//Disabling due to java8 incompat, only needed to manually publishing anyways
|
||||
|
||||
//signing.useGpgCmd()
|
||||
//
|
||||
//import com.vanniktech.maven.publish.SonatypeHost
|
||||
//import com.vanniktech.maven.publish.JavaLibrary
|
||||
//import com.vanniktech.maven.publish.JavadocJar
|
||||
//
|
||||
//mavenPublishing {
|
||||
// configure(new JavaLibrary(new JavadocJar.None(), true))
|
||||
//}
|
||||
//
|
||||
//mavenPublishing {
|
||||
// publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL)
|
||||
//
|
||||
// signAllPublications()
|
||||
// pom {
|
||||
// name = 'Primitive Collections'
|
||||
// description = 'A Primitive Collection library that reduces memory usage and improves performance'
|
||||
// url = 'https://github.com/Speiger/Primitive-Collections'
|
||||
// version = project.version
|
||||
// group = 'io.github.speiger'
|
||||
// licenses {
|
||||
// license {
|
||||
// name = 'The Apache License, Version 2.0'
|
||||
// url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// developers {
|
||||
// developer {
|
||||
// id = 'speiger'
|
||||
// name = 'Speiger'
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// scm {
|
||||
// connection = 'scm:git:git://github.com/Speiger/Primitive-Collections.git'
|
||||
// developerConnection = 'scm:git:ssh://github.com:Speiger/Primitive-Collections.git'
|
||||
// url = 'https://github.com/Speiger/Primitive-Collections'
|
||||
// }
|
||||
//
|
||||
// issueManagement {
|
||||
// system = 'github'
|
||||
// url = 'https://github.com/Speiger/Primitive-Collections/issues'
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
//
|
||||
@@ -1 +1,6 @@
|
||||
org.gradle.jvmargs=-Xmx3G
|
||||
|
||||
maxMemory = 2048m
|
||||
testThreads = 4
|
||||
|
||||
RELEASE_VERSION = 0.9.0
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
||||
@@ -3,15 +3,15 @@ package speiger.src.builder;
|
||||
@SuppressWarnings("javadoc")
|
||||
public enum ClassType
|
||||
{
|
||||
BOOLEAN("boolean", "Boolean", "Boolean", "booleans", "BOOLEAN", "false"),
|
||||
BYTE("byte", "Byte", "Byte", "bytes", "BYTE", "(byte)0"),
|
||||
SHORT("short", "Short", "Short", "shorts", "SHORT", "(short)0"),
|
||||
CHAR("char", "Character", "Char", "chars", "CHAR", "(char)0"),
|
||||
INT("int", "Integer", "Int", "ints", "INT", "0"),
|
||||
LONG("long", "Long", "Long", "longs", "LONG", "0L"),
|
||||
FLOAT("float", "Float", "Float", "floats", "FLOAT", "0F"),
|
||||
DOUBLE("double", "Double", "Double", "doubles", "DOUBLE", "0D"),
|
||||
OBJECT("T", "T", "Object", "objects", "OBJECT", "null");
|
||||
BOOLEAN("boolean", "Boolean", "Boolean", "booleans", "BOOLEAN", "false", "false"),
|
||||
BYTE("byte", "Byte", "Byte", "bytes", "BYTE", "(byte)0", "(byte)-1"),
|
||||
SHORT("short", "Short", "Short", "shorts", "SHORT", "(short)0", "(short)-1"),
|
||||
CHAR("char", "Character", "Char", "chars", "CHAR", "(char)0", "(char)-1"),
|
||||
INT("int", "Integer", "Int", "ints", "INT", "0", "-1"),
|
||||
LONG("long", "Long", "Long", "longs", "LONG", "0L", "-1L"),
|
||||
FLOAT("float", "Float", "Float", "floats", "FLOAT", "0F", "-1F"),
|
||||
DOUBLE("double", "Double", "Double", "doubles", "DOUBLE", "0D", "-1D"),
|
||||
OBJECT("T", "T", "Object", "objects", "OBJECT", "null", "null");
|
||||
|
||||
String keyType;
|
||||
String classType;
|
||||
@@ -19,8 +19,9 @@ public enum ClassType
|
||||
String pathType;
|
||||
String capType;
|
||||
String emptyValue;
|
||||
String invalidValue;
|
||||
|
||||
private ClassType(String keyType, String classType, String fileType, String pathType, String capType, String emptyValue)
|
||||
private ClassType(String keyType, String classType, String fileType, String pathType, String capType, String emptyValue, String invalidValue)
|
||||
{
|
||||
this.keyType = keyType;
|
||||
this.classType = classType;
|
||||
@@ -28,6 +29,7 @@ public enum ClassType
|
||||
this.pathType = pathType;
|
||||
this.capType = capType;
|
||||
this.emptyValue = emptyValue;
|
||||
this.invalidValue = invalidValue;
|
||||
}
|
||||
|
||||
public String getKeyType()
|
||||
@@ -50,6 +52,11 @@ public enum ClassType
|
||||
return classType;
|
||||
}
|
||||
|
||||
public String getClassPath()
|
||||
{
|
||||
return this == OBJECT ? "Object" : classType;
|
||||
}
|
||||
|
||||
public String getClassType(boolean value)
|
||||
{
|
||||
return value && this == OBJECT ? "V" : classType;
|
||||
@@ -90,6 +97,11 @@ public enum ClassType
|
||||
return emptyValue;
|
||||
}
|
||||
|
||||
public String getInvalidValue()
|
||||
{
|
||||
return invalidValue;
|
||||
}
|
||||
|
||||
public boolean isObject()
|
||||
{
|
||||
return this == OBJECT;
|
||||
@@ -102,7 +114,7 @@ public enum ClassType
|
||||
|
||||
public boolean needsCustomJDKType()
|
||||
{
|
||||
return this == BYTE || this == SHORT || this == CHAR || this == FLOAT;
|
||||
return this == BOOLEAN || this == BYTE || this == SHORT || this == CHAR || this == FLOAT;
|
||||
}
|
||||
|
||||
public boolean needsCast()
|
||||
@@ -121,6 +133,12 @@ public enum ClassType
|
||||
}
|
||||
}
|
||||
|
||||
public String getApply(ClassType other) {
|
||||
if(other == BOOLEAN) return "test";
|
||||
if(other == ClassType.OBJECT) return "apply";
|
||||
return "applyAs"+other.getFileType();
|
||||
}
|
||||
|
||||
public String getEquals(boolean not)
|
||||
{
|
||||
switch(this)
|
||||
|
||||
@@ -1,452 +0,0 @@
|
||||
package speiger.src.builder;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.function.UnaryOperator;
|
||||
|
||||
import speiger.src.builder.mappers.ArgumentMapper;
|
||||
import speiger.src.builder.mappers.IMapper;
|
||||
import speiger.src.builder.mappers.InjectMapper;
|
||||
import speiger.src.builder.mappers.LineMapper;
|
||||
import speiger.src.builder.mappers.SimpleMapper;
|
||||
import speiger.src.builder.processor.TemplateProcess;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public class GlobalVariables
|
||||
{
|
||||
List<IMapper> operators = new ArrayList<>();
|
||||
Set<String> flags = new LinkedHashSet<>();
|
||||
ClassType type;
|
||||
ClassType valueType;
|
||||
|
||||
public GlobalVariables(ClassType type, ClassType subType)
|
||||
{
|
||||
this.type = type;
|
||||
valueType = subType;
|
||||
}
|
||||
|
||||
public GlobalVariables createVariables()
|
||||
{
|
||||
addSimpleMapper("VALUE_PACKAGE", valueType.getPathType());
|
||||
addSimpleMapper("PACKAGE", type.getPathType());
|
||||
addSimpleMapper("CLASS_TYPE", type.getClassType());
|
||||
addSimpleMapper("CLASS_VALUE_TYPE", valueType.getClassValueType());
|
||||
addSimpleMapper("KEY_TYPE", type.getKeyType());
|
||||
addSimpleMapper("KEY_SPECIAL_TYPE", type.isObject() ? "E" : type.getKeyType());
|
||||
addSimpleMapper("VALUE_TYPE", valueType.getValueType());
|
||||
addSimpleMapper("VALUE_SPECIAL_TYPE", valueType.isObject() ? "E" : valueType.getKeyType());
|
||||
|
||||
addSimpleMapper("EMPTY_KEY_VALUE", type.getEmptyValue());
|
||||
addSimpleMapper("EMPTY_VALUE", valueType.getEmptyValue());
|
||||
|
||||
addSimpleMapper(" KEY_GENERIC_TYPE", type.isObject() ? "<"+type.getKeyType()+">" : "");
|
||||
addSimpleMapper(" KEY_KEY_GENERIC_TYPE", type.isObject() ? "<"+type.getKeyType()+", "+type.getKeyType()+">" : "");
|
||||
|
||||
addSimpleMapper(" VALUE_GENERIC_TYPE", valueType.isObject() ? "<"+valueType.getValueType()+">" : "");
|
||||
addSimpleMapper(" VALUE_VALUE_GENERIC_TYPE", valueType.isObject() ? "<"+valueType.getValueType()+", "+valueType.getValueType()+">" : "");
|
||||
|
||||
addSimpleMapper(" KEY_VALUE_GENERIC_TYPE", type.isObject() ? (valueType.isObject() ? "<"+type.getKeyType()+", "+valueType.getValueType()+">" : "<"+type.getKeyType()+">") : (valueType.isObject() ? "<"+valueType.getValueType()+">" : ""));
|
||||
addSimpleMapper(" KEY_VALUE_VALUE_GENERIC_TYPE", type.isObject() ? (valueType.isObject() ? "<"+type.getKeyType()+", "+valueType.getValueType()+", "+valueType.getValueType()+">" : "<"+type.getKeyType()+">") : (valueType.isObject() ? "<"+valueType.getValueType()+", "+valueType.getValueType()+">" : ""));
|
||||
|
||||
addSimpleMapper(" NO_GENERIC_TYPE", type.isObject() ? "<?>" : "");
|
||||
addSimpleMapper(" NO_KV_GENERIC_TYPE", type.isObject() ? (valueType.isObject() ? "<?, ?>" : "<?>") : valueType.isObject() ? "<?>" : "");
|
||||
addSimpleMapper(" KEY_COMPAREABLE_TYPE", type.isObject() ? "<"+type.getKeyType()+" extends Comparable<T>>" : "");
|
||||
|
||||
addSimpleMapper(" KEY_SUPER_GENERIC_TYPE", type.isObject() ? "<? super "+type.getKeyType()+">" : "");
|
||||
addSimpleMapper(" VALUE_SUPER_GENERIC_TYPE", valueType.isObject() ? "<? super "+valueType.getValueType()+">" : "");
|
||||
addSimpleMapper(" KEY_VALUE_SUPER_GENERIC_TYPE", type.isObject() ? (valueType.isObject() ? "<? super "+type.getKeyType()+", ? super "+valueType.getValueType()+">" : "<? super "+type.getKeyType()+">") : (valueType.isObject() ? "<? super "+valueType.getValueType()+">" : ""));
|
||||
|
||||
addSimpleMapper(" KEY_ENUM_VALUE_GENERIC_TYPE", type.isObject() ? (valueType.isObject() ? "<"+type.getKeyType()+" extends Enum<"+type.getKeyType()+">, "+valueType.getValueType()+">" : "<"+type.getKeyType()+" extends Enum<"+type.getKeyType()+">>") : (valueType.isObject() ? "<"+valueType.getValueType()+">" : ""));
|
||||
addSimpleMapper(" KEY_VALUE_ENUM_GENERIC_TYPE", type.isObject() ? (valueType.isObject() ? "<"+type.getKeyType()+", "+valueType.getValueType()+" extends Enum<"+valueType.getValueType()+">>" : "<"+type.getKeyType()+">") : (valueType.isObject() ? "<"+valueType.getValueType()+" extends Enum<"+valueType.getValueType()+">>" : ""));
|
||||
|
||||
addInjectMapper(" KEY_SPECIAL_GENERIC_TYPE", type.isObject() ? "<%s>" : "").removeBraces().setBraceType("<>");
|
||||
addInjectMapper(" VALUE_SPECIAL_GENERIC_TYPE", valueType.isObject() ? "<%s>" : "").removeBraces().setBraceType("<>");
|
||||
addInjectMapper(" KSK_GENERIC_TYPE", type.isObject() ? "<%s, "+type.getKeyType()+">" : "<%s>").removeBraces().setBraceType("<>");
|
||||
addInjectMapper(" KKS_GENERIC_TYPE", type.isObject() ? "<"+type.getKeyType()+", %s>" : "<%s>").removeBraces().setBraceType("<>");
|
||||
addArgumentMapper(" KSS_GENERIC_TYPE", type.isObject() ? "<%1$s, %2$s>" : "<%2$s>").removeBraces().setBraceType("<>");
|
||||
addInjectMapper(" VSV_GENERIC_TYPE", valueType.isObject() ? "<%s, "+valueType.getValueType()+">" : "<%s>").removeBraces().setBraceType("<>");
|
||||
addInjectMapper(" VVS_GENERIC_TYPE", valueType.isObject() ? "<"+valueType.getValueType()+", %s>" : "<%s>").removeBraces().setBraceType("<>");
|
||||
addArgumentMapper(" VSS_GENERIC_TYPE", valueType.isObject() ? "<%1$s, %2$s>" : "<%2$s>").removeBraces().setBraceType("<>");
|
||||
|
||||
addSimpleMapper(" GENERIC_KEY_BRACES", type.isObject() ? " <"+type.getKeyType()+">" : "");
|
||||
addSimpleMapper(" GENERIC_VALUE_BRACES", valueType.isObject() ? " <"+valueType.getValueType()+">" : "");
|
||||
addInjectMapper(" GENERIC_SPECIAL_KEY_BRACES", type.isObject() ? " <%s>" : "").removeBraces().setBraceType("<>");
|
||||
addInjectMapper(" GENERIC_SPECIAL_VALUE_BRACES", valueType.isObject() ? " <%s>" : "").removeBraces().setBraceType("<>");
|
||||
addSimpleMapper(" GENERIC_KEY_ENUM_VALUE_BRACES", type.isObject() ? (valueType.isObject() ? " <"+type.getKeyType()+" extends Enum<"+type.getKeyType()+">, "+valueType.getValueType()+">" : " <"+type.getKeyType()+" extends Enum<"+type.getKeyType()+">>") : (valueType.isObject() ? " <"+valueType.getValueType()+">" : ""));
|
||||
|
||||
addInjectMapper(" GENERIC_KEY_SPECIAL_BRACES", type.isObject() ? " <"+type.getKeyType()+", %s>" : " <%s>").removeBraces().setBraceType("<>");
|
||||
addInjectMapper(" GENERIC_VALUE_SPECIAL_BRACES", valueType.isObject() ? " <"+valueType.getKeyType()+", %s>" : " <%s>").removeBraces().setBraceType("<>");
|
||||
|
||||
addSimpleMapper(" GENERIC_KEY_VALUE_BRACES", type.isObject() ? (valueType.isObject() ? " <"+type.getKeyType()+", "+valueType.getValueType()+">" : " <"+type.getKeyType()+">") : (valueType.isObject() ? " <"+valueType.getValueType()+">" : ""));
|
||||
addSimpleMapper(" COMPAREABLE_KEY_BRACES", type.isObject() ? " <"+type.getKeyType()+" extends Comparable<T>>" : "");
|
||||
addSimpleMapper("KV_BRACES", type.isObject() || valueType.isObject() ? "<>" : "");
|
||||
addSimpleMapper("BRACES", type.isObject() ? "<>" : "");
|
||||
if(type.needsCustomJDKType())
|
||||
{
|
||||
addSimpleMapper("JAVA_TYPE", type.getCustomJDKType().getKeyType());
|
||||
addSimpleMapper("SANITY_CAST", "castTo"+type.getFileType());
|
||||
}
|
||||
addSimpleMapper("JAVA_CLASS", type.getCustomJDKType().getClassType());
|
||||
if(valueType.needsCustomJDKType())
|
||||
{
|
||||
addSimpleMapper("SANITY_CAST_VALUE", "castTo"+valueType.getFileType());
|
||||
}
|
||||
addComment("@ArrayType", "@param <%s> the type of array that the operation should be applied");
|
||||
addComment("@Type", "@param <%s> the type of elements maintained by this Collection");
|
||||
addValueComment("@ValueArrayType", "@param <%s> the type of array that the operation should be applied");
|
||||
addValueComment("@ValueType", "@param <%s> the type of elements maintained by this Collection");
|
||||
addAnnontion("@PrimitiveOverride", "@Override");
|
||||
addSimpleMapper("@PrimitiveDoc", "");
|
||||
addAnnontion("@Primitive", "@Deprecated");
|
||||
addValueAnnontion("@ValuePrimitiveOverride", "@Override");
|
||||
addValueAnnontion("@ValuePrimitive", "@Deprecated");
|
||||
return this;
|
||||
}
|
||||
|
||||
public GlobalVariables createHelperVariables()
|
||||
{
|
||||
createHelperVars(type, false, "KEY");
|
||||
createHelperVars(valueType, true, "VALUE");
|
||||
return this;
|
||||
}
|
||||
|
||||
private void createHelperVars(ClassType type, boolean value, String fix)
|
||||
{
|
||||
addArgumentMapper("EQUALS_"+fix+"_TYPE", "Objects.equals(%2$s, "+(type.isObject() ? "%1$s" : fix+"_TO_OBJ(%1$s)")+")").removeBraces();
|
||||
addInjectMapper(fix+"_EQUALS_NOT_NULL", type.getComparableValue()+" != "+(type.isPrimitiveBlocking() || type.needsCast() ? type.getEmptyValue() : "0")).removeBraces();
|
||||
addInjectMapper(fix+"_EQUALS_NULL", type.getComparableValue()+" == "+(type.isPrimitiveBlocking() || type.needsCast() ? type.getEmptyValue() : "0")).removeBraces();
|
||||
addArgumentMapper(fix+"_EQUALS_NOT", type.getEquals(true)).removeBraces();
|
||||
addArgumentMapper(fix+"_EQUALS", type.getEquals(false)).removeBraces();
|
||||
|
||||
addArgumentMapper("COMPAREABLE_TO_"+fix, type.isObject() ? "((Comparable<"+type.getKeyType(value)+">)%1$s).compareTo(("+type.getKeyType(value)+")%2$s)" : type.getClassType(value)+".compare(%1$s, %2$s)").removeBraces();
|
||||
addArgumentMapper("COMPARE_TO_"+fix, type.isObject() ? "%1$s.compareTo(%2$s)" : type.getClassType(value)+".compare(%1$s, %2$s)").removeBraces();
|
||||
|
||||
addInjectMapper(fix+"_TO_OBJ", type.isObject() ? "%s" : type.getClassType(value)+".valueOf(%s)").removeBraces();
|
||||
addInjectMapper("OBJ_TO_"+fix, type.isObject() ? "%s" : "%s."+type.getKeyType(value)+"Value()").removeBraces();
|
||||
addInjectMapper("CLASS_TO_"+fix, type.isObject() ? "("+type.getKeyType(value)+")%s" : "(("+type.getClassType(value)+")%s)."+type.getKeyType(value)+"Value()").removeBraces();
|
||||
|
||||
addInjectMapper(fix+"_TO_HASH", type.isObject() ? "Objects.hashCode(%s)" : type.getClassType(value)+".hashCode(%s)").removeBraces();
|
||||
addInjectMapper(fix+"_TO_STRING", type.isObject() ? "Objects.toString(%s)" : type.getClassType(value)+".toString(%s)").removeBraces();
|
||||
|
||||
addSimpleMapper("CAST_"+fix+"_ARRAY ", type.isObject() ? "("+fix+"_TYPE[])" : "");
|
||||
addSimpleMapper("EMPTY_"+fix+"_ARRAY", type.isObject() ? "("+fix+"_TYPE[])ARRAYS.EMPTY_ARRAY" : "ARRAYS.EMPTY_ARRAY");
|
||||
addInjectMapper("NEW_"+fix+"_ARRAY", type.isObject() ? "("+fix+"_TYPE[])new Object[%s]" : "new "+fix+"_TYPE[%s]").removeBraces();
|
||||
addInjectMapper("NEW_SPECIAL_"+fix+"_ARRAY", type.isObject() ? "(E[])new Object[%s]" : "new "+fix+"_TYPE[%s]").removeBraces();
|
||||
addInjectMapper("NEW_CLASS"+(value ? "_VALUE" : "")+"_ARRAY", type.isObject() ? "(CLASS_TYPE[])new Object[%s]" : "new CLASS_TYPE[%s]").removeBraces();
|
||||
}
|
||||
|
||||
public GlobalVariables createPreFunctions()
|
||||
{
|
||||
addSimpleMapper("ENTRY_SET", type.getFileType().toLowerCase()+"2"+valueType.getFileType()+"EntrySet");
|
||||
return this;
|
||||
}
|
||||
|
||||
public GlobalVariables createClassTypes()
|
||||
{
|
||||
addSimpleMapper("JAVA_PREDICATE", type.isPrimitiveBlocking() ? "" : type.getCustomJDKType().getFileType()+"Predicate");
|
||||
addSimpleMapper("JAVA_CONSUMER", type.isPrimitiveBlocking() ? "" : "java.util.function."+type.getCustomJDKType().getFileType()+"Consumer");
|
||||
addSimpleMapper("JAVA_SUPPLIER", type.isPrimitiveBlocking() ? "" : "java.util.function."+type.getCustomJDKType().getFileType()+"Supplier");
|
||||
addSimpleMapper("JAVA_FUNCTION", type.getFunctionClass(valueType));
|
||||
addSimpleMapper("JAVA_BINARY_OPERATOR", type == ClassType.BOOLEAN ? "" : (type.isObject() ? "java.util.function.BinaryOperator" : "java.util.function."+type.getCustomJDKType().getFileType()+"BinaryOperator"));
|
||||
addSimpleMapper("JAVA_UNARY_OPERATOR", type.isObject() ? "BinaryOperator" : type == ClassType.BOOLEAN ? "" : type.getCustomJDKType().getFileType()+"UnaryOperator");
|
||||
addSimpleMapper("JAVA_SPLIT_ITERATOR", type.isPrimitiveBlocking() ? "Spliterator" : "Of"+type.getCustomJDKType().getFileType());
|
||||
addSimpleMapper("JAVA_STREAM", type.isPrimitiveBlocking() ? "" : type.getCustomJDKType().getFileType()+"Stream");
|
||||
addSimpleMapper("JAVA_BUFFER", type.getFileType()+"Buffer");
|
||||
|
||||
//Final Classes
|
||||
addClassMapper("ARRAY_LIST", "ArrayList");
|
||||
addAbstractMapper("COPY_ON_WRITE_LIST", "CopyOnWrite%sArrayList");
|
||||
addClassMapper("ASYNC_BUILDER", "AsyncBuilder");
|
||||
addClassMapper("LINKED_LIST", "LinkedList");
|
||||
addAbstractMapper("IMMUTABLE_LIST", "Immutable%sList");
|
||||
addClassMapper("ARRAY_FIFO_QUEUE", "ArrayFIFOQueue");
|
||||
addClassMapper("ARRAY_PRIORITY_QUEUE", "ArrayPriorityQueue");
|
||||
addClassMapper("HEAP_PRIORITY_QUEUE", "HeapPriorityQueue");
|
||||
addClassMapper("LINKED_CUSTOM_HASH_SET", "LinkedOpenCustomHashSet");
|
||||
addClassMapper("LINKED_HASH_SET", "LinkedOpenHashSet");
|
||||
addAbstractMapper("IMMUTABLE_HASH_SET", "Immutable%sOpenHashSet");
|
||||
addClassMapper("CUSTOM_HASH_SET", "OpenCustomHashSet");
|
||||
addClassMapper("HASH_SET", "OpenHashSet");
|
||||
addAbstractBiMapper("IMMUTABLE_HASH_MAP", "Immutable%sOpenHashMap", "2");
|
||||
addBiClassMapper("LINKED_CUSTOM_HASH_MAP", "LinkedOpenCustomHashMap", "2");
|
||||
addBiClassMapper("LINKED_HASH_MAP", "LinkedOpenHashMap", "2");
|
||||
addBiClassMapper("CUSTOM_HASH_MAP", "OpenCustomHashMap", "2");
|
||||
addBiClassMapper("CONCURRENT_HASH_MAP", "ConcurrentOpenHashMap", "2");
|
||||
addBiClassMapper("AVL_TREE_MAP", "AVLTreeMap", "2");
|
||||
addBiClassMapper("RB_TREE_MAP", "RBTreeMap", "2");
|
||||
addFunctionValueMappers("LINKED_ENUM_MAP", valueType.isObject() ? "LinkedEnum2ObjectMap" : "LinkedEnum2%sMap");
|
||||
addFunctionValueMappers("ENUM_MAP", valueType.isObject() ? "Enum2ObjectMap" : "Enum2%sMap");
|
||||
addBiClassMapper("HASH_MAP", "OpenHashMap", "2");
|
||||
addBiClassMapper("ARRAY_MAP", "ArrayMap", "2");
|
||||
addBiClassMapper("IMMUTABLE_PAIR", "ImmutablePair", "");
|
||||
addBiClassMapper("MUTABLE_PAIR", "MutablePair", "");
|
||||
addClassMapper("RB_TREE_SET", "RBTreeSet");
|
||||
addClassMapper("AVL_TREE_SET", "AVLTreeSet");
|
||||
addClassMapper("ARRAY_SET", "ArraySet");
|
||||
|
||||
//Abstract Classes
|
||||
addAbstractMapper("ABSTRACT_COLLECTION", "Abstract%sCollection");
|
||||
addAbstractMapper("ABSTRACT_PRIORITY_QUEUE", "Abstract%sPriorityQueue");
|
||||
addAbstractMapper("ABSTRACT_SET", "Abstract%sSet");
|
||||
addAbstractMapper("ABSTRACT_LIST", "Abstract%sList");
|
||||
addAbstractBiMapper("ABSTRACT_MAP", "Abstract%sMap", "2");
|
||||
addClassMapper("SUB_LIST", "SubList");
|
||||
addAbstractMapper("BASE_TASK", "Base%sTask");
|
||||
|
||||
//Helper Classes
|
||||
addClassMapper("LISTS", "Lists");
|
||||
addClassMapper("SETS", "Sets");
|
||||
addClassMapper("COLLECTIONS", "Collections");
|
||||
addClassMapper("ARRAYS", "Arrays");
|
||||
addClassMapper("PRIORITY_QUEUES", "PriorityQueues");
|
||||
addClassMapper("SPLIT_ITERATORS", "Splititerators");
|
||||
addClassMapper("ITERATORS", "Iterators");
|
||||
addClassMapper("ITERABLES", "Iterables");
|
||||
addBiClassMapper("MAPS", "Maps", "2");
|
||||
|
||||
//Interfaces
|
||||
addClassMapper("LIST_ITERATOR", "ListIterator");
|
||||
addClassMapper("BI_ITERATOR", "BidirectionalIterator");
|
||||
addBiClassMapper("BI_CONSUMER", "Consumer", "");
|
||||
addClassMapper("BI_TO_OBJECT_CONSUMER", "ObjectConsumer");
|
||||
addAbstractMapper("BI_FROM_OBJECT_CONSUMER", "Object%sConsumer");
|
||||
addClassMapper("SPLIT_ITERATOR", "Splititerator");
|
||||
addClassMapper("ITERATOR", "Iterator");
|
||||
addClassMapper("ITERABLE", "Iterable");
|
||||
addClassMapper("COLLECTION", "Collection");
|
||||
addClassMapper("TO_OBJECT_FUNCTION", "2ObjectFunction");
|
||||
addBiClassMapper("FUNCTION", "Function", "2");
|
||||
addClassMapper("LIST_ITER", "ListIter");
|
||||
addClassMapper("LIST", "List");
|
||||
addBiClassMapper("NAVIGABLE_MAP", "NavigableMap", "2");
|
||||
addBiClassMapper("ORDERED_MAP", "OrderedMap", "2");
|
||||
addBiClassMapper("SORTED_MAP", "SortedMap", "2");
|
||||
addBiClassMapper("CONCURRENT_MAP", "ConcurrentMap", "2");
|
||||
addBiClassMapper("MAP", "Map", "2");
|
||||
addClassMapper("NAVIGABLE_SET", "NavigableSet");
|
||||
addBiClassMapper("PAIR", "Pair", "");
|
||||
addClassMapper("PRIORITY_QUEUE", "PriorityQueue");
|
||||
addClassMapper("PRIORITY_DEQUEUE", "PriorityDequeue");
|
||||
addClassMapper("PREDICATE", "2BooleanFunction");
|
||||
addClassMapper("SORTED_SET", "SortedSet");
|
||||
addClassMapper("ORDERED_SET", "OrderedSet");
|
||||
addClassMapper("SET", "Set");
|
||||
addClassMapper("STRATEGY", "Strategy");
|
||||
addClassMapper("STACK", "Stack");
|
||||
addClassMapper("SUPPLIER", "Supplier");
|
||||
addAbstractMapper("SINGLE_UNARY_OPERATOR", "%1$s%1$sUnaryOperator");
|
||||
addClassMapper("TASK", "Task");
|
||||
addBiClassMapper("UNARY_OPERATOR", "UnaryOperator", "");
|
||||
if(type.isObject())
|
||||
{
|
||||
if(!valueType.isObject()) addSimpleMapper("VALUE_CONSUMER", valueType.getFileType()+"Consumer");
|
||||
else addSimpleMapper("VALUE_CONSUMER", "Consumer");
|
||||
addSimpleMapper("CONSUMER", "Consumer");
|
||||
addSimpleMapper("COMPARATOR", "Comparator");
|
||||
addSimpleMapper("IARRAY", "IObjectArray");
|
||||
}
|
||||
else
|
||||
{
|
||||
if(valueType.isObject())
|
||||
{
|
||||
addSimpleMapper("VALUE_CONSUMER", "Consumer");
|
||||
addSimpleMapper("CONSUMER", type.getFileType()+"Consumer");
|
||||
}
|
||||
else addClassMapper("CONSUMER", "Consumer");
|
||||
addClassMapper("COMPARATOR", "Comparator");
|
||||
addFunctionMappers("IARRAY", "I%sArray");
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public GlobalVariables createFunctions()
|
||||
{
|
||||
addSimpleMapper("APPLY_KEY_VALUE", type.isObject() ? "apply" : "applyAs"+type.getNonFileType());
|
||||
addSimpleMapper("APPLY_VALUE", valueType.isObject() ? "apply" : "applyAs"+valueType.getNonFileType());
|
||||
addSimpleMapper("APPLY_CAST", "applyAs"+type.getCustomJDKType().getNonFileType());
|
||||
addSimpleMapper("APPLY", type.isObject() ? "apply" : "applyAs"+type.getNonFileType());
|
||||
addFunctionValueMapper("BULK_MERGE", "mergeAll");
|
||||
addFunctionValueMappers("COMPUTE_IF_ABSENT", "compute%sIfAbsent");
|
||||
addFunctionValueMappers("COMPUTE_IF_PRESENT", "compute%sIfPresent");
|
||||
addFunctionValueMapper("COMPUTE", "compute");
|
||||
addFunctionMapper("DEQUEUE_LAST", "dequeueLast");
|
||||
addFunctionMapper("DEQUEUE", "dequeue");
|
||||
addFunctionMappers("POLL_FIRST_ENTRY_KEY", "pollFirst%sKey");
|
||||
addFunctionMappers("POLL_LAST_ENTRY_KEY", "pollLast%sKey");
|
||||
addFunctionMapper("POLL_FIRST_KEY", "pollFirst");
|
||||
addFunctionMapper("POLL_LAST_KEY", "pollLast");
|
||||
addFunctionMappers("FIRST_ENTRY_KEY", "first%sKey");
|
||||
addFunctionValueMappers("FIRST_ENTRY_VALUE", "first%sValue");
|
||||
addFunctionMapper("FIRST_KEY", "first");
|
||||
addFunctionMappers("LAST_ENTRY_KEY", "last%sKey");
|
||||
addFunctionValueMappers("LAST_ENTRY_VALUE", "last%sValue");
|
||||
addFunctionMappers("ENTRY_KEY", "get%sKey");
|
||||
addFunctionValueMappers("ENTRY_VALUE", "get%sValue");
|
||||
addFunctionMappers("KEY_ENTRY", "set%sKey");
|
||||
addFunctionValueMappers("VALUE_ENTRY", "set%sValue");
|
||||
addFunctionMapper("GET_KEY", "get");
|
||||
if(type.isObject()) addFunctionValueMapper("GET_VALUE", valueType.isObject() ? "getObject" : "get");
|
||||
else addSimpleMapper("GET_VALUE", "get");
|
||||
addSimpleMapper("GET_JAVA", type.isObject() ? "get" : "getAs"+type.getCustomJDKType().getNonFileType());
|
||||
addFunctionMapper("LAST_KEY", "last");
|
||||
addFunctionValueMapper("MERGE", "merge");
|
||||
addFunctionMapper("NEXT", "next");
|
||||
addFunctionMapper("PREVIOUS", "previous");
|
||||
addFunctionMapper("REMOVE_SWAP", "swapRemove");
|
||||
if(type.isObject()) addFunctionMapper("REMOVE_VALUE", "rem");
|
||||
else addSimpleMapper("REMOVE_VALUE", "remove");
|
||||
addFunctionMapper("REMOVE_KEY", "rem");
|
||||
addFunctionMapper("REMOVE_LAST", "removeLast");
|
||||
addFunctionMapper("REMOVE", "remove");
|
||||
addFunctionValueMappers("REPLACE_VALUES", valueType.isObject() ? "replaceObjects" : "replace%ss");
|
||||
addFunctionMappers("REPLACE", type.isObject() ? "replaceObjects" : "replace%ss");
|
||||
addFunctionMappers("SORT", "sort%ss");
|
||||
addFunctionValueMappers("SUPPLY_IF_ABSENT", "supply%sIfAbsent");
|
||||
addSimpleMapper("VALUE_TEST_VALUE", valueType.isObject() ? "getBoolean" : "get");
|
||||
addSimpleMapper("TEST_VALUE", type.isObject() ? "getBoolean" : "get");
|
||||
addSimpleMapper("NEW_STREAM", type.isPrimitiveBlocking() ? "" : type.getCustomJDKType().getKeyType()+"Stream");
|
||||
addSimpleMapper("TO_ARRAY", "to"+type.getNonFileType()+"Array");
|
||||
addSimpleMapper("[SPACE]", " ");
|
||||
return this;
|
||||
}
|
||||
|
||||
public GlobalVariables createFlags()
|
||||
{
|
||||
flags.add("TYPE_"+type.getCapType());
|
||||
flags.add("VALUE_"+valueType.getCapType());
|
||||
if(type == valueType) flags.add("SAME_TYPE");
|
||||
if(type.hasFunction(valueType)) flags.add("JDK_FUNCTION");
|
||||
if(!type.needsCustomJDKType()) flags.add("JDK_TYPE");
|
||||
if(!type.isPrimitiveBlocking()) flags.add("PRIMITIVES");
|
||||
if(!valueType.isPrimitiveBlocking()) flags.add("VALUE_PRIMITIVES");
|
||||
if(valueType.needsCustomJDKType()) flags.add("JDK_VALUE");
|
||||
return this;
|
||||
}
|
||||
|
||||
public TemplateProcess create(String fileName, String splitter, boolean valueOnly)
|
||||
{
|
||||
TemplateProcess process = new TemplateProcess(String.format(fileName+".java", (splitter != null ? type.getFileType()+splitter+valueType.getFileType() : (valueOnly ? valueType : type).getFileType())));
|
||||
process.setPathBuilder(new PathBuilder(type.getPathType()));
|
||||
process.addFlags(flags);
|
||||
process.addMappers(operators);
|
||||
return process;
|
||||
}
|
||||
|
||||
public ClassType getType()
|
||||
{
|
||||
return type;
|
||||
}
|
||||
|
||||
private void addClassMapper(String pattern, String replacement)
|
||||
{
|
||||
operators.add(new SimpleMapper(type.name()+"[VALUE_"+pattern+"]", "VALUE_"+pattern, valueType.getFileType()+replacement));
|
||||
operators.add(new SimpleMapper(type.name()+"["+pattern+"]", pattern, type.getFileType()+replacement));
|
||||
}
|
||||
|
||||
private void addBiClassMapper(String pattern, String replacement, String splitter)
|
||||
{
|
||||
operators.add(new SimpleMapper(type.name()+"[KEY_"+pattern+"]", "KEY_"+pattern, type.getFileType()+splitter+type.getFileType()+replacement));
|
||||
operators.add(new SimpleMapper(type.name()+"[VALUE_"+pattern+"]", "VALUE_"+pattern, valueType.getFileType()+splitter+valueType.getFileType()+replacement));
|
||||
operators.add(new SimpleMapper(type.name()+"["+pattern+"]", pattern, type.getFileType()+splitter+valueType.getFileType()+replacement));
|
||||
}
|
||||
|
||||
private void addAbstractMapper(String pattern, String replacement)
|
||||
{
|
||||
operators.add(new SimpleMapper(type.name()+"[VALUE_"+pattern+"]", "VALUE_"+pattern, String.format(replacement, valueType.getFileType())));
|
||||
operators.add(new SimpleMapper(type.name()+"["+pattern+"]", pattern, String.format(replacement, type.getFileType())));
|
||||
}
|
||||
|
||||
private void addAbstractBiMapper(String pattern, String replacement, String splitter)
|
||||
{
|
||||
operators.add(new SimpleMapper(type.name()+"["+pattern+"]", pattern, String.format(replacement, type.getFileType()+splitter+valueType.getFileType())));
|
||||
}
|
||||
|
||||
private void addFunctionMapper(String pattern, String replacement)
|
||||
{
|
||||
operators.add(new SimpleMapper(type.name()+"[VALUE_"+pattern+"]", "VALUE_"+pattern, replacement+valueType.getNonFileType()));
|
||||
operators.add(new SimpleMapper(type.name()+"["+pattern+"]", pattern, replacement+type.getNonFileType()));
|
||||
}
|
||||
|
||||
private void addFunctionValueMapper(String pattern, String replacement)
|
||||
{
|
||||
operators.add(new SimpleMapper(type.name()+"["+pattern+"]", pattern, replacement+valueType.getNonFileType()));
|
||||
}
|
||||
|
||||
private void addFunctionMappers(String pattern, String replacement)
|
||||
{
|
||||
operators.add(new SimpleMapper(type.name()+"[VALUE_"+pattern+"]", "VALUE_"+pattern, String.format(replacement, valueType.getNonFileType())));
|
||||
operators.add(new SimpleMapper(type.name()+"["+pattern+"]", pattern, String.format(replacement, type.getNonFileType())));
|
||||
}
|
||||
|
||||
private void addFunctionValueMappers(String pattern, String replacement)
|
||||
{
|
||||
operators.add(new SimpleMapper(type.name()+"["+pattern+"]", pattern, String.format(replacement, valueType.getNonFileType())));
|
||||
}
|
||||
|
||||
private void addSimpleMapper(String pattern, String replacement)
|
||||
{
|
||||
operators.add(new SimpleMapper(type.name()+"["+pattern+"]", pattern, replacement));
|
||||
}
|
||||
|
||||
private void addAnnontion(String pattern, String value)
|
||||
{
|
||||
if(type == ClassType.OBJECT) operators.add(new LineMapper(type.name()+"["+pattern+"]", pattern));
|
||||
else operators.add(new SimpleMapper(type.name()+"["+pattern+"]", pattern, value));
|
||||
}
|
||||
|
||||
private void addValueAnnontion(String pattern, String value)
|
||||
{
|
||||
if(valueType == ClassType.OBJECT) operators.add(new LineMapper(valueType.name()+"["+pattern+"]", pattern));
|
||||
else operators.add(new SimpleMapper(valueType.name()+"["+pattern+"]", pattern, value));
|
||||
}
|
||||
|
||||
private void addComment(String pattern, String value)
|
||||
{
|
||||
if(type == ClassType.OBJECT) operators.add(new InjectMapper(type.name()+"["+pattern+"]", pattern, value).removeBraces());
|
||||
else operators.add(new LineMapper(type.name()+"["+pattern+"]", pattern));
|
||||
}
|
||||
|
||||
private void addValueComment(String pattern, String value)
|
||||
{
|
||||
if(valueType == ClassType.OBJECT) operators.add(new InjectMapper(valueType.name()+"["+pattern+"]", pattern, value).removeBraces());
|
||||
else operators.add(new LineMapper(valueType.name()+"["+pattern+"]", pattern));
|
||||
}
|
||||
|
||||
private InjectMapper addInjectMapper(String pattern, String replacement)
|
||||
{
|
||||
InjectMapper mapper = new InjectMapper(type.name()+"["+pattern+"]", pattern, replacement);
|
||||
operators.add(mapper);
|
||||
return mapper;
|
||||
}
|
||||
|
||||
private ArgumentMapper addArgumentMapper(String pattern, String replacement)
|
||||
{
|
||||
return addArgumentMapper(pattern, replacement, ", ");
|
||||
}
|
||||
|
||||
private ArgumentMapper addArgumentMapper(String pattern, String replacement, String splitter)
|
||||
{
|
||||
ArgumentMapper mapper = new ArgumentMapper(type.name()+"["+pattern+"]", pattern, replacement, splitter);
|
||||
operators.add(mapper);
|
||||
return mapper;
|
||||
}
|
||||
|
||||
class PathBuilder implements UnaryOperator<Path>
|
||||
{
|
||||
String before;
|
||||
|
||||
public PathBuilder(String before)
|
||||
{
|
||||
this.before = before;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Path apply(Path t)
|
||||
{
|
||||
return t.subpath(0, 6).resolve(before).resolve(t.subpath(6, t.getNameCount()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
package speiger.src.builder;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.function.UnaryOperator;
|
||||
|
||||
import speiger.src.builder.mappers.IMapper;
|
||||
import speiger.src.builder.processor.TemplateProcess;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public class ModulePackage
|
||||
{
|
||||
private static final BiConsumer<String, RequiredType> VOID = (K, V) -> {};
|
||||
public static final ClassType[] TYPE = ClassType.values();
|
||||
final ClassType keyType;
|
||||
final ClassType valueType;
|
||||
Set<String> blocked = new HashSet<>();
|
||||
Map<String, String> nameRemapper = new HashMap<>();
|
||||
Map<String, String> splitters = new HashMap<>();
|
||||
List<Predicate<String>> blockedFilters = new ArrayList<>();
|
||||
List<IMapper> mappers = new ArrayList<>();
|
||||
Set<String> flags = new LinkedHashSet<>();
|
||||
Set<String> globalFlags;
|
||||
Map<String, Integer> flaggedValues = new HashMap<>();
|
||||
BiConsumer<String, RequiredType> requirements = VOID;
|
||||
|
||||
public ModulePackage(Set<String> globalFlags, ClassType keyType, ClassType valueType) {
|
||||
this.globalFlags = globalFlags;
|
||||
this.keyType = keyType;
|
||||
this.valueType = valueType;
|
||||
}
|
||||
|
||||
public void finish() {
|
||||
requirements = VOID;
|
||||
mappers.sort(Comparator.comparing(IMapper::getSearchValue, Comparator.comparingInt(String::length).reversed()));
|
||||
mappers.sort(Comparator.comparing(IMapper::getSearchValue, this::sort));
|
||||
}
|
||||
|
||||
public void setRequirements(BiConsumer<String, RequiredType> requirements) {
|
||||
this.requirements = requirements;
|
||||
}
|
||||
|
||||
public boolean isSame() {
|
||||
return keyType == valueType;
|
||||
}
|
||||
|
||||
public boolean isEnumValid() {
|
||||
return keyType == ClassType.OBJECT;
|
||||
}
|
||||
|
||||
public ClassType getKeyType() {
|
||||
return keyType;
|
||||
}
|
||||
|
||||
public ClassType getValueType() {
|
||||
return valueType;
|
||||
}
|
||||
|
||||
public void addFlag(String flag) {
|
||||
flags.add(flag);
|
||||
}
|
||||
|
||||
public void addGlobalFlag(String flag) {
|
||||
globalFlags.add(flag);
|
||||
}
|
||||
|
||||
public void addValue(String key, int value) {
|
||||
flaggedValues.put(key, value);
|
||||
}
|
||||
|
||||
public void addRequirement(String fileName, RequiredType type) {
|
||||
requirements.accept(fileName, type);
|
||||
}
|
||||
|
||||
public void addMapper(IMapper mapper) {
|
||||
mappers.add(mapper);
|
||||
}
|
||||
|
||||
public void addBlockedFilter(Predicate<String> filter) {
|
||||
blockedFilters.add(filter);
|
||||
}
|
||||
|
||||
public void addBlockedFiles(String... names) {
|
||||
blocked.addAll(Arrays.asList(names));
|
||||
}
|
||||
|
||||
public void addSplitter(String fileName, String splitter) {
|
||||
splitters.put(fileName, splitter);
|
||||
}
|
||||
|
||||
public void addRemapper(String fileName, String actualName) {
|
||||
nameRemapper.put(fileName, actualName);
|
||||
}
|
||||
|
||||
public void process(String fileName, Consumer<TemplateProcess> result) {
|
||||
if(isBlocked(fileName)) return;
|
||||
String splitter = String.format(splitters.getOrDefault(fileName, keyType.getFileType()), keyType.getFileType(), valueType.getFileType());
|
||||
String newName = String.format(nameRemapper.getOrDefault(fileName, "%s"+fileName), splitter);
|
||||
TemplateProcess process = new TemplateProcess(newName+".java");
|
||||
process.setPathBuilder(new PathBuilder(keyType.getPathType()));
|
||||
process.addFlags(flags);
|
||||
process.addFlags(globalFlags);
|
||||
process.addMappers(mappers);
|
||||
process.addValues(flaggedValues);
|
||||
result.accept(process);
|
||||
}
|
||||
|
||||
private boolean isBlocked(String fileName) {
|
||||
if(blocked.contains(fileName)) return true;
|
||||
for(int i = 0,m=blockedFilters.size();i<m;i++) {
|
||||
if(blockedFilters.get(i).test(fileName)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static List<ModulePackage> createPackages(Set<String> globalFlags) {
|
||||
List<ModulePackage> list = new ArrayList<>();
|
||||
for(ClassType key : TYPE) {
|
||||
for(ClassType value : TYPE) {
|
||||
list.add(new ModulePackage(globalFlags, key, value));
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
private int sort(String key, String value) {
|
||||
if(value.contains(key)) return 1;
|
||||
else if(key.contains(value)) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
class PathBuilder implements UnaryOperator<Path> {
|
||||
String before;
|
||||
|
||||
public PathBuilder(String before) {
|
||||
this.before = before;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Path apply(Path t) {
|
||||
return t.subpath(0, 6).resolve(before).resolve(t.subpath(6, t.getNameCount()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,8 @@ import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
@@ -16,177 +17,157 @@ import java.util.StringJoiner;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import speiger.src.builder.modules.AsyncModule;
|
||||
import speiger.src.builder.modules.BaseModule;
|
||||
import speiger.src.builder.modules.CollectionModule;
|
||||
import speiger.src.builder.modules.FunctionModule;
|
||||
import speiger.src.builder.modules.JavaModule;
|
||||
import speiger.src.builder.modules.ListModule;
|
||||
import speiger.src.builder.modules.MapModule;
|
||||
import speiger.src.builder.modules.PairModule;
|
||||
import speiger.src.builder.modules.PrioQueueModule;
|
||||
import speiger.src.builder.modules.SetModule;
|
||||
import speiger.src.builder.processor.TemplateProcess;
|
||||
import speiger.src.builder.processor.TemplateProcessor;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public class PrimitiveCollectionsBuilder extends TemplateProcessor
|
||||
{
|
||||
Map<String, EnumSet<ClassType>> blocked = new HashMap<>();
|
||||
Map<String, String> nameRemapper = new HashMap<>();
|
||||
Map<String, String> biRequired = new HashMap<>();
|
||||
Set<String> enumRequired = new HashSet<>();
|
||||
public static final ClassType[] TYPE = ClassType.values();
|
||||
List<GlobalVariables> variables = new ArrayList<>();
|
||||
List<GlobalVariables> biVariables = new ArrayList<>();
|
||||
List<GlobalVariables> enumVariables = new ArrayList<>();
|
||||
private static final int SPECIAL = 0x1; //Detects if the Builder is generating tests
|
||||
private static final int LOAD = 0x2; //If Configs should be loaded
|
||||
private static final int ANTI_SAVE = SPECIAL | LOAD; //If save should be disabled since load/save shouldn't happen at the same time.
|
||||
private static final int SAVE = 0x4; //if the configuration should be created
|
||||
Set<String> globalFlags = new HashSet<>();
|
||||
List<ModulePackage> simplePackages = new ArrayList<>();
|
||||
List<ModulePackage> biPackages = new ArrayList<>();
|
||||
List<ModulePackage> enumPackages = new ArrayList<>();
|
||||
Map<String, RequiredType> requirements = new HashMap<>();
|
||||
SettingsManager manager = new SettingsManager();
|
||||
int flags;
|
||||
|
||||
public PrimitiveCollectionsBuilder()
|
||||
{
|
||||
public PrimitiveCollectionsBuilder() {
|
||||
this(false);
|
||||
}
|
||||
|
||||
public PrimitiveCollectionsBuilder(boolean silencedSuccess)
|
||||
{
|
||||
public PrimitiveCollectionsBuilder(boolean silencedSuccess) {
|
||||
super(silencedSuccess, Paths.get("src/builder/resources/speiger/assets/collections/templates/"), Paths.get("src/main/java/speiger/src/collections/"), Paths.get("src/builder/resources/speiger/assets/collections/"));
|
||||
}
|
||||
|
||||
public PrimitiveCollectionsBuilder(Path sourceFolder, Path outputFolder, Path dataFolder)
|
||||
{
|
||||
public PrimitiveCollectionsBuilder(Path sourceFolder, Path outputFolder, Path dataFolder) {
|
||||
this(false, sourceFolder, outputFolder, dataFolder);
|
||||
}
|
||||
|
||||
public PrimitiveCollectionsBuilder(boolean silencedSuccess, Path sourceFolder, Path outputFolder, Path dataFolder)
|
||||
{
|
||||
public PrimitiveCollectionsBuilder(boolean silencedSuccess, Path sourceFolder, Path outputFolder, Path dataFolder) {
|
||||
super(silencedSuccess, sourceFolder, outputFolder, dataFolder);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isFileValid(Path fileName)
|
||||
{
|
||||
return true;
|
||||
private PrimitiveCollectionsBuilder setFlags(int flags) {
|
||||
this.flags = flags;
|
||||
if((flags & ANTI_SAVE) != 0) {
|
||||
this.flags &= ~SAVE;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
private static PrimitiveCollectionsBuilder createTests(boolean silent, int flags) {
|
||||
return new PrimitiveCollectionsBuilder(silent,
|
||||
Paths.get("src/builder/resources/speiger/assets/tests/templates/"),
|
||||
Paths.get("src/test/java/speiger/src/tests/"),
|
||||
Paths.get("src/builder/resources/speiger/assets/tests/")).setFlags(flags | SPECIAL);
|
||||
}
|
||||
|
||||
private static PrimitiveCollectionsBuilder createTesters(boolean silent, int flags) {
|
||||
return new PrimitiveCollectionsBuilder(silent,
|
||||
Paths.get("src/builder/resources/speiger/assets/testers/templates/"),
|
||||
Paths.get("src/test/java/speiger/src/testers/"),
|
||||
Paths.get("src/builder/resources/speiger/assets/testers/")).setFlags(flags | SPECIAL);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean relativePackages()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
protected boolean isFileValid(Path fileName) { return true; }
|
||||
@Override
|
||||
protected boolean relativePackages() { return true; }
|
||||
@Override
|
||||
protected boolean debugUnusedMappers() { return false; }
|
||||
|
||||
@Override
|
||||
protected boolean debugUnusedMappers()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void afterFinish()
|
||||
{
|
||||
if(getVersion() > 8)
|
||||
{
|
||||
protected void afterFinish() {
|
||||
if((flags & SPECIAL) == 0 && getVersion() > 8) {
|
||||
Path basePath = Paths.get("src/main/java");
|
||||
try(BufferedWriter writer = Files.newBufferedWriter(basePath.resolve("module-info.java")))
|
||||
{
|
||||
try(BufferedWriter writer = Files.newBufferedWriter(basePath.resolve("module-info.java"))) {
|
||||
writer.write(getModuleInfo(basePath));
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
catch(Exception e) { e.printStackTrace(); }
|
||||
}
|
||||
}
|
||||
|
||||
public List<BaseModule> createModules() {
|
||||
List<BaseModule> modules = new ArrayList<>();
|
||||
modules.add(JavaModule.INSTANCE);
|
||||
modules.add(FunctionModule.INSTANCE);
|
||||
modules.add(CollectionModule.INSTANCE);
|
||||
modules.add(PrioQueueModule.INSTANCE);
|
||||
modules.add(ListModule.INSTANCE);
|
||||
modules.add(SetModule.INSTANCE);
|
||||
modules.add(MapModule.INSTANCE);
|
||||
modules.add(PairModule.INSTANCE);
|
||||
modules.add(AsyncModule.INSTANCE);
|
||||
return modules;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
prepPackages();
|
||||
//Init Modules here
|
||||
addModules(createModules());
|
||||
finishPackages();
|
||||
}
|
||||
|
||||
public void addModules(List<BaseModule> modules) {
|
||||
for(int i = 0,m=modules.size();i<m;i++) {
|
||||
modules.get(i).setManager(manager);
|
||||
}
|
||||
manager.resolve();
|
||||
for(int i = 0,m=modules.size();i<m;i++) {
|
||||
biPackages.forEach(modules.get(i)::init);
|
||||
}
|
||||
modules.forEach(BaseModule::cleanup);
|
||||
}
|
||||
|
||||
private void finishPackages() {
|
||||
biPackages.forEach(ModulePackage::finish);
|
||||
if((flags & SAVE) != 0) manager.save();
|
||||
}
|
||||
|
||||
private void prepPackages() {
|
||||
if((flags & LOAD) != 0) manager.load();
|
||||
for(ModulePackage entry : ModulePackage.createPackages(globalFlags)) {
|
||||
entry.setRequirements(requirements::put);
|
||||
biPackages.add(entry);
|
||||
if(entry.isSame()) simplePackages.add(entry);
|
||||
if(entry.isEnumValid()) enumPackages.add(entry);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init()
|
||||
{
|
||||
variables.clear();
|
||||
for(ClassType clzType : TYPE)
|
||||
{
|
||||
for(ClassType subType : TYPE)
|
||||
{
|
||||
create(clzType, subType);
|
||||
}
|
||||
}
|
||||
enumRequired.add("EnumMap");
|
||||
enumRequired.add("LinkedEnumMap");
|
||||
biRequired.put("BiConsumer", "");
|
||||
biRequired.put("UnaryOperator", "");
|
||||
biRequired.put("Pair", "");
|
||||
biRequired.put("MutablePair", "");
|
||||
biRequired.put("ImmutablePair", "");
|
||||
addBiClass("Function", "Maps", "Map", "SortedMap", "OrderedMap", "NavigableMap", "ConcurrentMap", "AbstractMap", "ConcurrentOpenHashMap", "ImmutableOpenHashMap", "OpenHashMap", "LinkedOpenHashMap", "OpenCustomHashMap", "LinkedOpenCustomHashMap", "ArrayMap", "RBTreeMap", "AVLTreeMap");
|
||||
nameRemapper.put("BiConsumer", "%sConsumer");
|
||||
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");
|
||||
nameRemapper.put("LinkedEnumMap", "LinkedEnum2%sMap");
|
||||
nameRemapper.put("ImmutableList", "Immutable%sList");
|
||||
nameRemapper.put("CopyOnWriteList", "CopyOnWrite%sArrayList");
|
||||
nameRemapper.put("ImmutableOpenHashSet", "Immutable%sOpenHashSet");
|
||||
nameRemapper.put("ImmutableOpenHashMap", "Immutable%sOpenHashMap");
|
||||
|
||||
addBlockage(ClassType.OBJECT, "Consumer", "Comparator", "Stack");
|
||||
addBlockage(ClassType.BOOLEAN, "ArraySet", "AVLTreeSet", "RBTreeSet", "SortedSet", "OrderedSet", "NavigableSet", "OpenHashSet", "OpenCustomHashSet", "LinkedOpenHashSet", "LinkedOpenCustomHashSet");
|
||||
addBlockage(ClassType.BOOLEAN, "ConcurrentOpenHashMap", "ImmutableOpenHashMap", "ImmutableOpenHashSet", "SortedMap", "OrderedMap", "NavigableMap", "ConcurrentMap", "OpenHashMap", "LinkedOpenHashMap", "OpenCustomHashMap", "LinkedOpenCustomHashMap", "ArrayMap", "RBTreeMap", "AVLTreeMap");
|
||||
}
|
||||
|
||||
protected void create(ClassType mainType, ClassType subType)
|
||||
{
|
||||
GlobalVariables type = new GlobalVariables(mainType, subType);
|
||||
type.createFlags();
|
||||
type.createHelperVariables();
|
||||
type.createVariables();
|
||||
type.createPreFunctions();
|
||||
type.createClassTypes();
|
||||
type.createFunctions();
|
||||
if(mainType == subType) variables.add(type);
|
||||
biVariables.add(type);
|
||||
if(mainType.isObject()) enumVariables.add(type);
|
||||
}
|
||||
|
||||
protected void addBiClass(String...classNames)
|
||||
{
|
||||
for(String s : classNames)
|
||||
{
|
||||
biRequired.put(s, "2");
|
||||
public void createProcesses(String fileName, Consumer<TemplateProcess> process) {
|
||||
List<ModulePackage> packages = getPackagesByRequirement(requirements.get(fileName));
|
||||
for(int i = 0,m=packages.size();i<m;i++) {
|
||||
packages.get(i).process(fileName, process);
|
||||
}
|
||||
}
|
||||
|
||||
protected void addBlockage(ClassType type, String...args)
|
||||
{
|
||||
for(String s : args)
|
||||
{
|
||||
EnumSet<ClassType> set = blocked.get(s);
|
||||
if(set == null)
|
||||
{
|
||||
set = EnumSet.noneOf(ClassType.class);
|
||||
blocked.put(s, set);
|
||||
}
|
||||
set.add(type);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createProcesses(String name, Consumer<TemplateProcess> acceptor)
|
||||
{
|
||||
String splitter = biRequired.get(name);
|
||||
boolean valueRequired = enumRequired.contains(name);
|
||||
List<GlobalVariables> vars = getVariablesByClass(name, splitter != null);
|
||||
EnumSet<ClassType> types = blocked.get(name);
|
||||
for(int i = 0,m=vars.size();i<m;i++)
|
||||
{
|
||||
GlobalVariables type = vars.get(i);
|
||||
if(types == null || !types.contains(type.getType()))
|
||||
{
|
||||
acceptor.accept(type.create(nameRemapper.getOrDefault(name, "%s"+name), splitter, valueRequired));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected List<GlobalVariables> getVariablesByClass(String name, boolean bi) {
|
||||
if(enumRequired.contains(name)) return enumVariables;
|
||||
if(bi) return biVariables;
|
||||
return variables;
|
||||
protected List<ModulePackage> getPackagesByRequirement(RequiredType type) {
|
||||
if(type == null) return simplePackages;
|
||||
if(type == RequiredType.BI_CLASS) return biPackages;
|
||||
if(type == RequiredType.ENUM) return enumPackages;
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
private String getModuleInfo(Path basePath) {
|
||||
StringJoiner joiner = new StringJoiner("\n", "", "\n");
|
||||
try(Stream<Path> stream = Files.walk(getOutputFolder()))
|
||||
{
|
||||
try(Stream<Path> stream = Files.walk(getOutputFolder())) {
|
||||
stream.filter(Files::isDirectory)
|
||||
.filter(this::containsFiles)
|
||||
.map(basePath::relativize)
|
||||
@@ -194,8 +175,7 @@ public class PrimitiveCollectionsBuilder extends TemplateProcessor
|
||||
.map(this::sanitize)
|
||||
.forEach(T -> joiner.add("\texports "+T+";"));
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
@@ -206,58 +186,43 @@ public class PrimitiveCollectionsBuilder extends TemplateProcessor
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
private String sanitize(String input)
|
||||
{
|
||||
private String sanitize(String input) {
|
||||
return input.replace("\\", ".").replace("/", ".");
|
||||
}
|
||||
|
||||
private boolean containsFiles(Path path)
|
||||
{
|
||||
try(Stream<Path> stream = Files.walk(path, 1))
|
||||
{
|
||||
private boolean containsFiles(Path path) {
|
||||
try(Stream<Path> stream = Files.walk(path, 1)) {
|
||||
return stream.filter(Files::isRegularFile).findFirst().isPresent();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
catch(Exception e) { e.printStackTrace(); }
|
||||
return false;
|
||||
}
|
||||
|
||||
private int getVersion()
|
||||
{
|
||||
private int getVersion() {
|
||||
String version = System.getProperty("java.version");
|
||||
if(version.startsWith("1.")) return Integer.parseInt(version.substring(2, 3));
|
||||
int dot = version.indexOf(".");
|
||||
return Integer.parseInt(dot != -1 ? version.substring(0, dot) : version);
|
||||
}
|
||||
|
||||
public static void main(String...args)
|
||||
{
|
||||
public static void main(String...args) {
|
||||
try
|
||||
{
|
||||
if(args.length == 0) {
|
||||
new PrimitiveCollectionsBuilder().process(false);
|
||||
} else if(args.length == 1) {
|
||||
new PrimitiveCollectionsBuilder().process(Boolean.parseBoolean(args[0]));
|
||||
} else if(args.length == 2) {
|
||||
new PrimitiveCollectionsBuilder(Boolean.parseBoolean(args[1])).process(Boolean.parseBoolean(args[0]));
|
||||
} else if(args.length == 3) {
|
||||
new PrimitiveCollectionsBuilder(Paths.get(args[0]), Paths.get(args[1]), Paths.get(args[2])).process(false);
|
||||
} else if(args.length == 4) {
|
||||
new PrimitiveCollectionsBuilder(false, Paths.get(args[0]), Paths.get(args[1]), Paths.get(args[2])).process(Boolean.parseBoolean(args[3]));
|
||||
} else if(args.length == 4) {
|
||||
new PrimitiveCollectionsBuilder(Boolean.parseBoolean(args[4]), Paths.get(args[0]), Paths.get(args[1]), Paths.get(args[2])).process(Boolean.parseBoolean(args[3]));
|
||||
} else {
|
||||
System.out.println("Invalid argument count passed in");
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
catch(InterruptedException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
catch(IOException e)
|
||||
Set<String> flags = new HashSet<>(Arrays.asList(args));
|
||||
boolean silent = flags.contains("silent");
|
||||
boolean force = flags.contains("force");
|
||||
boolean tests = flags.contains("tests");
|
||||
boolean forceTests = flags.contains("force-tests");
|
||||
boolean load = flags.contains("load");
|
||||
boolean save = flags.contains("save");
|
||||
int flag = (load ? LOAD : 0) | (save ? SAVE : 0);
|
||||
new PrimitiveCollectionsBuilder(silent).setFlags(flag).process(force);
|
||||
if(tests) {
|
||||
createTests(silent, flag).process(force || forceTests);
|
||||
createTesters(silent, flag).process(force || forceTests);
|
||||
}
|
||||
}
|
||||
catch(InterruptedException | IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package speiger.src.builder;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public enum RequiredType
|
||||
{
|
||||
BI_CLASS,
|
||||
ENUM
|
||||
}
|
||||
@@ -0,0 +1,217 @@
|
||||
package speiger.src.builder;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.google.gson.internal.Streams;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
|
||||
import speiger.src.builder.dependencies.IDependency;
|
||||
import speiger.src.builder.dependencies.IDependency.LoadingState;
|
||||
import speiger.src.builder.modules.BaseModule;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public class SettingsManager
|
||||
{
|
||||
boolean loaded;
|
||||
Map<String, LoadingState> parsedData = new TreeMap<>();
|
||||
JsonObject data = new JsonObject();
|
||||
Set<String> moduleNames = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
|
||||
Set<IDependency> allDependencies = new LinkedHashSet<>();
|
||||
|
||||
public void resolve() {
|
||||
if(!loaded) return;
|
||||
Set<IDependency> roots = new LinkedHashSet<>();
|
||||
Set<IDependency> leafs = new LinkedHashSet<>();
|
||||
for(IDependency entry : allDependencies) {
|
||||
if(entry.isRoot()) {
|
||||
roots.add(entry);
|
||||
}
|
||||
if(entry.isLeaf()) {
|
||||
leafs.add(entry);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* This has to be 2 iteration passes.
|
||||
* Due to Key Value Pairs, first pass does all initials keys, and the second pass processes the values.
|
||||
* May require more passes but extremely unlikely
|
||||
*/
|
||||
for(int i = 0;i<2;i++) {
|
||||
for(ClassType keyType : ModulePackage.TYPE) {
|
||||
for(ClassType valueType : ModulePackage.TYPE) {
|
||||
for(IDependency entry : roots) {
|
||||
entry.resolveRequirements(keyType, valueType);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<String> errors = new ArrayList<>();
|
||||
for(ClassType keyType : ModulePackage.TYPE) {
|
||||
for(ClassType valueType : ModulePackage.TYPE) {
|
||||
for(IDependency entry : leafs) {
|
||||
entry.validateDependency(errors::add, keyType, valueType);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(errors.size() > 0) {
|
||||
throw new IllegalStateException("Issues with dependencies found: "+String.join("\n", errors));
|
||||
}
|
||||
}
|
||||
|
||||
public void addModule(BaseModule module) {
|
||||
if(loaded) {
|
||||
if(module.isBiModule()) {
|
||||
for(ClassType keyType : ModulePackage.TYPE) {
|
||||
for(ClassType valueType : ModulePackage.TYPE) {
|
||||
if(!module.isModuleValid(keyType, valueType)) continue;
|
||||
for(IDependency dependency : module.getDependencies(keyType, valueType)) {
|
||||
dependency.set(parsedData);
|
||||
allDependencies.add(dependency);
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
for(ClassType keyType : ModulePackage.TYPE) {
|
||||
if(!module.isModuleValid(keyType, keyType)) continue;
|
||||
for(IDependency dependency : module.getDependencies(keyType, keyType)) {
|
||||
dependency.set(parsedData);
|
||||
allDependencies.add(dependency);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
String moduleName = module.getModuleName();
|
||||
moduleNames.add(moduleName);
|
||||
data.addProperty(moduleName, true);
|
||||
if(module.isBiModule()) {
|
||||
for(ClassType keyType : ModulePackage.TYPE) {
|
||||
for(ClassType valueType : ModulePackage.TYPE) {
|
||||
if(!module.isModuleValid(keyType, valueType)) continue;
|
||||
JsonObject obj = new JsonObject();
|
||||
for(IDependency dependency : module.getDependencies(keyType, valueType)) {
|
||||
String key = dependency.getName();
|
||||
if(key != null) obj.addProperty(key, true);
|
||||
}
|
||||
addModule(keyType, valueType, true, moduleName, obj);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
for(ClassType keyType : ModulePackage.TYPE) {
|
||||
if(!module.isModuleValid(keyType, keyType)) continue;
|
||||
JsonObject obj = new JsonObject();
|
||||
for(IDependency dependency : module.getDependencies(keyType, keyType)) {
|
||||
String key = dependency.getName();
|
||||
if(key != null) obj.addProperty(key, true);
|
||||
}
|
||||
addModule(keyType, keyType, false, moduleName, obj);
|
||||
}
|
||||
}
|
||||
|
||||
public void printModuleSettings(List<BaseModule> modules) {
|
||||
JsonObject data = new JsonObject();
|
||||
for(BaseModule module : modules) {
|
||||
String moduleName = module.getModuleName();
|
||||
if(module.isBiModule()) {
|
||||
for(ClassType keyType : ModulePackage.TYPE) {
|
||||
for(ClassType valueType : ModulePackage.TYPE) {
|
||||
if(!module.isModuleValid(keyType, valueType)) continue;
|
||||
JsonObject obj = new JsonObject();
|
||||
for(IDependency dependency : module.getDependencies(keyType, valueType)) {
|
||||
String key = dependency.getName();
|
||||
if(key != null) obj.addProperty(key, dependency.isLoaded(keyType, valueType).getJsonResult());
|
||||
}
|
||||
addModule(data, keyType, valueType, true, moduleName, obj);
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
for(ClassType keyType : ModulePackage.TYPE) {
|
||||
if(!module.isModuleValid(keyType, keyType)) continue;
|
||||
JsonObject obj = new JsonObject();
|
||||
for(IDependency dependency : module.getDependencies(keyType, keyType)) {
|
||||
String key = dependency.getName();
|
||||
if(key != null) obj.addProperty(key, dependency.isLoaded(keyType, keyType).getJsonResult());
|
||||
}
|
||||
addModule(data, keyType, keyType, false, moduleName, obj);
|
||||
}
|
||||
}
|
||||
try {
|
||||
System.out.println();
|
||||
JsonWriter writer = new JsonWriter(new OutputStreamWriter(System.out));
|
||||
writer.setIndent("\t");
|
||||
Streams.write(data, writer);
|
||||
writer.flush();
|
||||
System.out.println();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void load() {
|
||||
try(BufferedReader reader = Files.newBufferedReader(Paths.get("ModulSettings.json"))) {
|
||||
data = JsonParser.parseReader(reader).getAsJsonObject();
|
||||
loaded = true;
|
||||
IDependency.flatten("", false, data, parsedData);
|
||||
JsonElement element = data.get("Default");
|
||||
LoadingState.setOptionalResolver(LoadingState.of(element == null ? true : element.getAsBoolean()));
|
||||
}
|
||||
catch(Exception e) { e.printStackTrace(); }
|
||||
}
|
||||
|
||||
public void save() {
|
||||
data.asMap().keySet().removeAll(moduleNames);
|
||||
JsonObject result = new JsonObject();
|
||||
for(String s : moduleNames) {
|
||||
result.addProperty(s, true);
|
||||
}
|
||||
result.asMap().putAll(data.asMap());
|
||||
|
||||
try(JsonWriter writer = new JsonWriter(Files.newBufferedWriter(Paths.get("ModulSettings.json")))) {
|
||||
writer.setIndent("\t");
|
||||
Streams.write(result, writer);
|
||||
}
|
||||
catch(Exception e) { e.printStackTrace(); }
|
||||
}
|
||||
|
||||
private void addModule(JsonObject data, ClassType keyType, ClassType valueType, boolean bi, String moduleName, JsonObject obj) {
|
||||
JsonObject result = getObject(data, keyType.getClassPath(), true);
|
||||
if(bi) {
|
||||
result = getObject(result, valueType.getClassPath(), true);
|
||||
}
|
||||
result.add(moduleName, obj);
|
||||
}
|
||||
|
||||
private void addModule(ClassType keyType, ClassType valueType, boolean bi, String moduleName, JsonObject obj) {
|
||||
JsonObject result = getObject(data, keyType.getClassPath(), true);
|
||||
if(bi) {
|
||||
result = getObject(result, valueType.getClassPath(), true);
|
||||
}
|
||||
result.add(moduleName, obj);
|
||||
}
|
||||
|
||||
private JsonObject getObject(JsonObject data, String name, boolean create) {
|
||||
JsonObject obj = data.getAsJsonObject(name);
|
||||
if(obj == null) {
|
||||
obj = new JsonObject();
|
||||
data.add(name, obj);
|
||||
if(create) obj.addProperty("Enabled", true);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
package speiger.src.builder.dependencies;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.StringJoiner;
|
||||
import java.util.TreeSet;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import speiger.src.builder.ClassType;
|
||||
import speiger.src.builder.dependencies.Requirements.Requirement;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public abstract class BaseDependency implements IDependency {
|
||||
protected static boolean FETCH_FAILURES = false;
|
||||
protected static Set<String> FAILURE_KEYS = new TreeSet<>();
|
||||
|
||||
protected final String name;
|
||||
protected final boolean biType;
|
||||
protected Map<String, LoadingState> dependencies;
|
||||
protected List<IDependency> children = new ArrayList<>();
|
||||
protected List<Requirement> requirements = new ArrayList<>();
|
||||
protected ClassType keyType;
|
||||
protected ClassType valueType;
|
||||
|
||||
public BaseDependency(String name, boolean biType) {
|
||||
this.name = name;
|
||||
this.biType = biType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(Map<String, LoadingState> dependency) {
|
||||
dependencies = dependency;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IDependency addDependency(Requirement require) {
|
||||
requirements.add(require);
|
||||
require.dependency.addChild(this);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addChild(IDependency child) {
|
||||
children.add(child);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLeaf() {
|
||||
return children.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRoot() {
|
||||
return requirements.isEmpty();
|
||||
}
|
||||
|
||||
protected LoadingState getGlobalState() {
|
||||
return dependencies.getOrDefault(name, LoadingState.OPTIONAL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLocalStateKey(ClassType keyType, ClassType valueType) {
|
||||
return (biType ? keyType.getClassPath()+"-"+valueType.getClassPath() : keyType.getClassPath())+"-"+name;
|
||||
}
|
||||
|
||||
protected LoadingState getLocalState(ClassType keyType, ClassType valueType) {
|
||||
return dependencies.getOrDefault(getLocalStateKey(keyType, valueType), LoadingState.OPTIONAL);
|
||||
}
|
||||
|
||||
protected LoadingState getReqirementState(ClassType keyType, ClassType valueType) {
|
||||
LoadingState state = requirements.isEmpty() ? LoadingState.REQUIRED : LoadingState.OPTIONAL;
|
||||
for(int i = 0,m=requirements.size();i<m;i++) {
|
||||
state = state.merge(requirements.get(i).test(keyType, valueType));
|
||||
}
|
||||
return state.resolveIfUndefined();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resolveRequirements(ClassType keyType, ClassType valueType) {
|
||||
if(!children.isEmpty()) {
|
||||
for(IDependency child : children) {
|
||||
if(child == this) continue;
|
||||
child.resolveRequirements(keyType, valueType);
|
||||
}
|
||||
}
|
||||
if(getLocalState(keyType, valueType) == LoadingState.REQUIRED) {
|
||||
for(Requirement req : requirements) {
|
||||
dependencies.putIfAbsent(req.key(keyType, valueType), LoadingState.REQUIRED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validateDependency(Consumer<String> result, ClassType keyType, ClassType valueType) {
|
||||
if(getLocalState(keyType, valueType) == LoadingState.REQUIRED) {
|
||||
FETCH_FAILURES = true;
|
||||
for(Requirement req : requirements) {
|
||||
req.test(keyType, valueType);
|
||||
}
|
||||
FETCH_FAILURES = false;
|
||||
if(FAILURE_KEYS.size() > 0) {
|
||||
int size = FAILURE_KEYS.size();
|
||||
StringJoiner joiner = new StringJoiner("], [", "[", "]");
|
||||
FAILURE_KEYS.forEach(joiner::add);
|
||||
FAILURE_KEYS.clear();
|
||||
String joins = size > 1 ? "["+joiner.toString()+"]" : joiner.toString();
|
||||
|
||||
result.accept("["+getLocalStateKey(keyType, valueType)+"] Requires "+joins+" but it specifically has been disabled!");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(ClassType key, ClassType value) {
|
||||
this.keyType = key;
|
||||
this.valueType = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
if(keyType == null || keyType == null) return false;
|
||||
return isLoaded(keyType, valueType).getJsonResult();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package speiger.src.builder.dependencies;
|
||||
|
||||
import speiger.src.builder.ClassType;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public class FunctionDependency extends BaseDependency {
|
||||
ModuleDependency owner;
|
||||
|
||||
public FunctionDependency(ModuleDependency owner, String name) {
|
||||
super(name, owner.biType);
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoadingState isLoaded(ClassType key, ClassType value) {
|
||||
if(dependencies == null) return LoadingState.REQUIRED;
|
||||
LoadingState result = getLocalState(key, value);
|
||||
if(FETCH_FAILURES && result == LoadingState.REJECTED) {
|
||||
FAILURE_KEYS.add(getLocalStateKey(key, value));
|
||||
}
|
||||
return result.resolveIfUndefined().merge(getReqirementState(key, value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLocalStateKey(ClassType keyType, ClassType valueType) {
|
||||
return (biType ? keyType.getClassPath()+"-"+valueType.getClassPath() : keyType.getClassPath())+"-"+owner.getName()+"-"+name;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
package speiger.src.builder.dependencies;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
|
||||
import speiger.src.builder.ClassType;
|
||||
import speiger.src.builder.dependencies.Requirements.Requirement;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public interface IDependency {
|
||||
|
||||
|
||||
public void set(Map<String, LoadingState> dependency);
|
||||
public void set(ClassType key, ClassType value);
|
||||
public LoadingState isLoaded(ClassType key, ClassType value);
|
||||
public String getLocalStateKey(ClassType keyType, ClassType valueType);
|
||||
public boolean isEnabled();
|
||||
public boolean isLeaf();
|
||||
public boolean isRoot();
|
||||
|
||||
public String getName();
|
||||
public void validateDependency(Consumer<String> result, ClassType keyType, ClassType valueType);
|
||||
public void resolveRequirements(ClassType keyType, ClassType valueType);
|
||||
|
||||
public void addChild(IDependency child);
|
||||
public <T extends IDependency> T addDependency(Requirement require);
|
||||
public default <T extends IDependency> T addKeyDependency(IDependency dependency) { return addDependency(new Requirement(dependency, Requirements.KEY_TEST, Requirements.KEY_GETTER)); }
|
||||
public default <T extends IDependency> T addValueDependency(IDependency dependency) { return addDependency(new Requirement(dependency, Requirements.VALUE_TEST, Requirements.VALUE_GETTER)); }
|
||||
public default <T extends IDependency> T addEntryDependency(IDependency dependency) { return addDependency(new Requirement(dependency, Requirements.ENTRY_TEST, Requirements.ENTRY_GETTER)); }
|
||||
public default <T extends IDependency> T addTypeDependency(IDependency dependency, ClassType type) { return addDependency(new Requirement(dependency, Requirements.typedTest(type), Requirements.typedKey(type))); }
|
||||
public default <T extends IDependency> T addOptionalTypeDependency(IDependency dependency, ClassType type, boolean key) { return addDependency(new Requirement(dependency, Requirements.optionalTest(type, key), Requirements.optionalKey(type, key))); }
|
||||
public default <T extends IDependency> T addOptionalTypeDependency(ClassType type, boolean key) { return addDependency(new Requirement(this, Requirements.optionalTest(type, key), Requirements.optionalKey(type, key))); }
|
||||
|
||||
|
||||
public static void flatten(String prefix, boolean applyMiddle, JsonObject object, Map<String, LoadingState> result) {
|
||||
if(applyMiddle) prefix+="-";
|
||||
for(Entry<String, JsonElement> entry : object.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
JsonElement value = entry.getValue();
|
||||
if(value instanceof JsonPrimitive) {
|
||||
String entryKey = prefix+key;
|
||||
if("Enabled".equalsIgnoreCase(key)) {
|
||||
entryKey = prefix.substring(0, prefix.length()-1);
|
||||
}
|
||||
result.put(entryKey, LoadingState.of(((JsonPrimitive)value).getAsBoolean()));
|
||||
}
|
||||
if(value instanceof JsonObject) {
|
||||
flatten(prefix+key, true, (JsonObject)value, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static enum LoadingState {
|
||||
OPTIONAL,
|
||||
REQUIRED,
|
||||
REJECTED;
|
||||
|
||||
private static LoadingState RESOLVED = LoadingState.REQUIRED;
|
||||
|
||||
public static LoadingState of(boolean value) {
|
||||
return value ? REQUIRED : REJECTED;
|
||||
}
|
||||
|
||||
public LoadingState merge(LoadingState merge) {
|
||||
return ordinal() > merge.ordinal() ? this : merge;
|
||||
}
|
||||
|
||||
public LoadingState replaceIfUndefined(LoadingState state) {
|
||||
return this == OPTIONAL ? state : this;
|
||||
}
|
||||
|
||||
public LoadingState resolveIfUndefined() {
|
||||
return this == OPTIONAL ? RESOLVED : this;
|
||||
}
|
||||
|
||||
public LoadingState mergeDown(LoadingState merge) {
|
||||
if(merge == REJECTED || ordinal() > merge.ordinal()) {
|
||||
return this;
|
||||
}
|
||||
return merge;
|
||||
}
|
||||
|
||||
public LoadingState mergeUp(LoadingState merge) {
|
||||
if(merge == REQUIRED || ordinal() > merge.ordinal()) {
|
||||
return this;
|
||||
}
|
||||
return merge;
|
||||
}
|
||||
|
||||
public static void setOptionalResolver(LoadingState state) {
|
||||
RESOLVED = state;
|
||||
}
|
||||
|
||||
public boolean getJsonResult() {
|
||||
LoadingState state = this == OPTIONAL ? RESOLVED : this;
|
||||
return state == REQUIRED;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package speiger.src.builder.dependencies;
|
||||
|
||||
import speiger.src.builder.ClassType;
|
||||
import speiger.src.builder.modules.BaseModule;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public class ModuleDependency extends BaseDependency {
|
||||
BaseModule owner;
|
||||
|
||||
public ModuleDependency(BaseModule owner, boolean biType) {
|
||||
super(owner.getModuleName(), biType);
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
public FunctionDependency createDependency(String name) {
|
||||
FunctionDependency result = new FunctionDependency(this, name);
|
||||
if(biType) result.addEntryDependency(this);
|
||||
else result.addKeyDependency(this);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoadingState isLoaded(ClassType key, ClassType value) {
|
||||
if(dependencies == null) return LoadingState.REQUIRED;
|
||||
LoadingState result = getLocalState(key, value);
|
||||
if(FETCH_FAILURES && result == LoadingState.REJECTED) {
|
||||
FAILURE_KEYS.add(getLocalStateKey(key, value));
|
||||
}
|
||||
return result.replaceIfUndefined(getGlobalState()).resolveIfUndefined().merge(getReqirementState(key, value));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package speiger.src.builder.dependencies;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import speiger.src.builder.ClassType;
|
||||
import speiger.src.builder.dependencies.IDependency.LoadingState;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public class Requirements {
|
||||
public static final RequirementTest KEY_TEST = (T, K, V) -> T.isLoaded(K, K);
|
||||
public static final RequirementTest VALUE_TEST = (T, K, V) -> T.isLoaded(V, V);
|
||||
public static final RequirementTest ENTRY_TEST = (T, K, V) -> T.isLoaded(K, V);
|
||||
|
||||
public static RequirementTest typedTest(ClassType type) {
|
||||
return (T, K, V) -> T.isLoaded(type, type);
|
||||
}
|
||||
|
||||
public static RequirementTest optionalTest(ClassType type, boolean key) {
|
||||
return (T, K, V) -> (key ? K : V) != type ? T.isLoaded(type, type) : LoadingState.REQUIRED;
|
||||
}
|
||||
|
||||
public static final RequirementKey KEY_GETTER = (T, K, V) -> T.getLocalStateKey(K, K);
|
||||
public static final RequirementKey VALUE_GETTER = (T, K, V) -> T.getLocalStateKey(V, V);
|
||||
public static final RequirementKey ENTRY_GETTER = (T, K, V) -> T.getLocalStateKey(K, V);
|
||||
|
||||
public static RequirementKey typedKey(ClassType type) {
|
||||
return (T, K, V) -> T.getLocalStateKey(type, type);
|
||||
}
|
||||
|
||||
public static RequirementKey optionalKey(ClassType type, boolean key) {
|
||||
return (T, K, V) -> (key ? K : V) != type ? T.getLocalStateKey(type, type) : "";
|
||||
}
|
||||
|
||||
|
||||
|
||||
public interface RequirementTest {
|
||||
public LoadingState test(IDependency test, ClassType keyType, ClassType valueType);
|
||||
}
|
||||
|
||||
public static interface RequirementKey {
|
||||
public String key(IDependency test, ClassType keyType, ClassType valueType);
|
||||
}
|
||||
|
||||
public static interface RequirementResolver {
|
||||
public void resolve(IDependency test, Consumer<String> result, ClassType keyType, ClassType valueType);
|
||||
}
|
||||
|
||||
public static class Requirement {
|
||||
IDependency dependency;
|
||||
RequirementTest test;
|
||||
RequirementKey key;
|
||||
|
||||
public Requirement(IDependency dependency, RequirementTest test, RequirementKey key) {
|
||||
this.dependency = dependency;
|
||||
this.test = test;
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public LoadingState test(ClassType keyType, ClassType valueType) {
|
||||
return test.test(dependency, keyType, valueType);
|
||||
}
|
||||
|
||||
public String key(ClassType keyType, ClassType valueType) {
|
||||
return key.key(dependency, keyType, valueType);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package speiger.src.builder.modules;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import speiger.src.builder.ClassType;
|
||||
import speiger.src.builder.dependencies.IDependency;
|
||||
import speiger.src.builder.dependencies.ModuleDependency;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public class AsyncModule extends BaseModule
|
||||
{
|
||||
public static final BaseModule INSTANCE = new AsyncModule();
|
||||
public static final ModuleDependency MODULE = new ModuleDependency(INSTANCE, false).addKeyDependency(JavaModule.MODULE);
|
||||
|
||||
@Override
|
||||
public String getModuleName() { return "Async"; }
|
||||
@Override
|
||||
protected void loadVariables() {}
|
||||
@Override
|
||||
protected void loadRemappers() {}
|
||||
@Override
|
||||
protected void loadTestClasses() {}
|
||||
@Override
|
||||
protected void loadFunctions() {}
|
||||
@Override
|
||||
public List<IDependency> getDependencies(ClassType keyType, ClassType valueType) { return Arrays.asList(MODULE); }
|
||||
@Override
|
||||
protected void loadBlockades() {
|
||||
if(!MODULE.isEnabled()) {
|
||||
addBlockedFiles("AsyncBuilder", "Task");
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected void loadFlags() {
|
||||
if(MODULE.isEnabled()) {
|
||||
addKeyFlag("ASYNC_MODULE");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadClasses()
|
||||
{
|
||||
//Implementation Classes
|
||||
addClassMapper("ASYNC_BUILDER", "AsyncBuilder");
|
||||
|
||||
//Abstract Classes
|
||||
addAbstractMapper("BASE_TASK", "Base%sTask");
|
||||
|
||||
//Interfaces
|
||||
addClassMapper("TASK", "Task");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,198 @@
|
||||
package speiger.src.builder.modules;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import speiger.src.builder.ClassType;
|
||||
import speiger.src.builder.ModulePackage;
|
||||
import speiger.src.builder.RequiredType;
|
||||
import speiger.src.builder.SettingsManager;
|
||||
import speiger.src.builder.dependencies.IDependency;
|
||||
import speiger.src.builder.mappers.ArgumentMapper;
|
||||
import speiger.src.builder.mappers.InjectMapper;
|
||||
import speiger.src.builder.mappers.LineMapper;
|
||||
import speiger.src.builder.mappers.SimpleMapper;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public abstract class BaseModule
|
||||
{
|
||||
SettingsManager manager;
|
||||
ModulePackage entry;
|
||||
protected ClassType keyType;
|
||||
protected ClassType valueType;
|
||||
|
||||
public final void setManager(SettingsManager manager) {
|
||||
this.manager = manager;
|
||||
manager.addModule(this);
|
||||
}
|
||||
|
||||
public final void init(ModulePackage entry) {
|
||||
this.entry = entry;
|
||||
keyType = entry.getKeyType();
|
||||
valueType = entry.getValueType();
|
||||
for(IDependency dependency : getDependencies(keyType, valueType)) {
|
||||
dependency.set(keyType, valueType);
|
||||
}
|
||||
loadVariables();
|
||||
loadClasses();
|
||||
loadTestClasses();
|
||||
loadFunctions();
|
||||
loadRemappers();
|
||||
loadBlockades();
|
||||
loadFlags();
|
||||
}
|
||||
|
||||
public final void cleanup() {
|
||||
entry = null;
|
||||
keyType = null;
|
||||
valueType = null;
|
||||
manager = null;
|
||||
}
|
||||
|
||||
protected abstract void loadVariables();
|
||||
protected abstract void loadClasses();
|
||||
protected abstract void loadTestClasses();
|
||||
protected abstract void loadFunctions();
|
||||
protected abstract void loadRemappers();
|
||||
protected abstract void loadBlockades();
|
||||
protected abstract void loadFlags();
|
||||
|
||||
public abstract String getModuleName();
|
||||
public boolean isBiModule() { return false; }
|
||||
public List<IDependency> getDependencies(ClassType keyType, ClassType valueType) { return Collections.emptyList(); }
|
||||
public boolean isModuleValid(ClassType keyType, ClassType valueType) { return true; }
|
||||
|
||||
public ClassType keyType() { return keyType; }
|
||||
public ClassType valueType() { return valueType; }
|
||||
|
||||
protected void addFlag(String name) {
|
||||
entry.addFlag(name);
|
||||
}
|
||||
|
||||
protected void addValue(String name, int value) {
|
||||
entry.addValue(name, value);
|
||||
}
|
||||
|
||||
protected void addKeyFlag(String name) {
|
||||
entry.addFlag(name);
|
||||
entry.addGlobalFlag(keyType.getCapType()+"_"+name);
|
||||
}
|
||||
|
||||
protected void addBiRequirement(String fileName) {
|
||||
entry.addRequirement(fileName, RequiredType.BI_CLASS);
|
||||
entry.addSplitter(fileName, "%1$s2%2$s");
|
||||
}
|
||||
|
||||
protected void addEnumRequirement(String fileName) {
|
||||
entry.addRequirement(fileName, RequiredType.ENUM);
|
||||
entry.addSplitter(fileName, "%2$s");
|
||||
|
||||
}
|
||||
|
||||
protected void addBiRequirement(String fileName, String splitter) {
|
||||
entry.addRequirement(fileName, RequiredType.BI_CLASS);
|
||||
entry.addSplitter(fileName, "%1$s"+splitter+"%2$s");
|
||||
}
|
||||
|
||||
protected void addRequirement(String fileName, String splitter, RequiredType type) {
|
||||
entry.addRequirement(fileName, type);
|
||||
entry.addSplitter(fileName, splitter);
|
||||
}
|
||||
|
||||
protected void addRemapper(String fileName, String actualName) {
|
||||
entry.addRemapper(fileName, actualName);
|
||||
}
|
||||
|
||||
protected void addBlockedFiles(String... name) {
|
||||
entry.addBlockedFiles(name);
|
||||
}
|
||||
|
||||
protected void addBlockedFilter(Predicate<String> filter) {
|
||||
entry.addBlockedFilter(filter);
|
||||
}
|
||||
|
||||
protected void addClassMapper(String pattern, String replacement) {
|
||||
entry.addMapper(new SimpleMapper("VALUE_"+pattern, "VALUE_"+pattern, valueType.getFileType()+replacement));
|
||||
entry.addMapper(new SimpleMapper(pattern, pattern, keyType.getFileType()+replacement));
|
||||
}
|
||||
|
||||
protected void addBiClassMapper(String pattern, String replacement, String splitter) {
|
||||
entry.addMapper(new SimpleMapper("KEY_"+pattern, "KEY_"+pattern, keyType.getFileType()+splitter+keyType.getFileType()+replacement));
|
||||
entry.addMapper(new SimpleMapper("VALUE_"+pattern, "VALUE_"+pattern, valueType.getFileType()+splitter+valueType.getFileType()+replacement));
|
||||
entry.addMapper(new SimpleMapper(pattern, pattern, keyType.getFileType()+splitter+valueType.getFileType()+replacement));
|
||||
}
|
||||
|
||||
protected void addAbstractMapper(String pattern, String replacement) {
|
||||
entry.addMapper(new SimpleMapper("VALUE_"+pattern, "VALUE_"+pattern, String.format(replacement, valueType.getFileType())));
|
||||
entry.addMapper(new SimpleMapper(pattern, pattern, String.format(replacement, keyType.getFileType())));
|
||||
}
|
||||
|
||||
protected void addAbstractBiMapper(String pattern, String replacement, String splitter) {
|
||||
entry.addMapper(new SimpleMapper(pattern, pattern, String.format(replacement, keyType.getFileType()+splitter+valueType.getFileType())));
|
||||
}
|
||||
|
||||
protected void addFunctionMapper(String pattern, String replacement) {
|
||||
entry.addMapper(new SimpleMapper("VALUE_"+pattern, "VALUE_"+pattern, replacement+valueType.getNonFileType()));
|
||||
entry.addMapper(new SimpleMapper(pattern, pattern, replacement+keyType.getNonFileType()));
|
||||
}
|
||||
|
||||
protected void addFunctionValueMapper(String pattern, String replacement) {
|
||||
entry.addMapper(new SimpleMapper(pattern, pattern, replacement+valueType.getNonFileType()));
|
||||
}
|
||||
|
||||
protected void addFunctionMappers(String pattern, String replacement) {
|
||||
entry.addMapper(new SimpleMapper("VALUE_"+pattern, "VALUE_"+pattern, String.format(replacement, valueType.getNonFileType())));
|
||||
entry.addMapper(new SimpleMapper(pattern, pattern, String.format(replacement, keyType.getNonFileType())));
|
||||
}
|
||||
|
||||
protected void addFunctionValueMappers(String pattern, String replacement) {
|
||||
entry.addMapper(new SimpleMapper(pattern, pattern, String.format(replacement, valueType.getNonFileType())));
|
||||
}
|
||||
|
||||
protected void addSimpleMapper(String pattern, String replacement) {
|
||||
entry.addMapper(new SimpleMapper(pattern, pattern, replacement));
|
||||
}
|
||||
|
||||
protected void addAnnontion(String pattern, String value) {
|
||||
if(keyType == ClassType.OBJECT) entry.addMapper(new LineMapper(pattern, pattern));
|
||||
else entry.addMapper(new SimpleMapper(pattern, pattern, value));
|
||||
}
|
||||
|
||||
protected void addValueAnnontion(String pattern, String value) {
|
||||
if(valueType == ClassType.OBJECT) entry.addMapper(new LineMapper(pattern, pattern));
|
||||
else entry.addMapper(new SimpleMapper(pattern, pattern, value));
|
||||
}
|
||||
|
||||
protected void addComment(String pattern, String value) {
|
||||
if(keyType == ClassType.OBJECT) entry.addMapper(new InjectMapper(pattern, pattern, value).removeBraces());
|
||||
else entry.addMapper(new LineMapper(pattern, pattern));
|
||||
}
|
||||
|
||||
protected void addValueComment(String pattern, String value) {
|
||||
if(valueType == ClassType.OBJECT) entry.addMapper(new InjectMapper(pattern, pattern, value).removeBraces());
|
||||
else entry.addMapper(new LineMapper(pattern, pattern));
|
||||
}
|
||||
|
||||
protected InjectMapper addInjectMapper(String pattern, String replacement) {
|
||||
InjectMapper mapper = new InjectMapper(pattern, pattern, replacement);
|
||||
entry.addMapper(mapper);
|
||||
return mapper;
|
||||
}
|
||||
|
||||
protected ArgumentMapper addArgumentMapper(String pattern, String replacement) {
|
||||
return addArgumentMapper(pattern, replacement, ", ");
|
||||
}
|
||||
|
||||
protected ArgumentMapper addArgumentMapper(String pattern, String replacement, String splitter) {
|
||||
ArgumentMapper mapper = new ArgumentMapper(pattern, pattern, replacement, splitter);
|
||||
entry.addMapper(mapper);
|
||||
return mapper;
|
||||
}
|
||||
|
||||
public static <T> T make(T input, Consumer<T> processor) {
|
||||
processor.accept(input);
|
||||
return input;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
package speiger.src.builder.modules;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import speiger.src.builder.ClassType;
|
||||
import speiger.src.builder.dependencies.FunctionDependency;
|
||||
import speiger.src.builder.dependencies.IDependency;
|
||||
import speiger.src.builder.dependencies.ModuleDependency;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public class CollectionModule extends BaseModule
|
||||
{
|
||||
public static final BaseModule INSTANCE = new CollectionModule();
|
||||
public static final ModuleDependency MODULE = new ModuleDependency(INSTANCE, false)
|
||||
.addKeyDependency(FunctionModule.MODULE)
|
||||
.addOptionalTypeDependency(FunctionModule.MODULE, ClassType.OBJECT, true)
|
||||
.addOptionalTypeDependency(FunctionModule.MODULE, ClassType.INT, true)
|
||||
.addOptionalTypeDependency(ClassType.OBJECT, true);
|
||||
public static final FunctionDependency STREAMS = MODULE.createDependency("Streams");
|
||||
public static final FunctionDependency SPLIT_ITERATORS = MODULE.createDependency("Splititerators").addKeyDependency(STREAMS);
|
||||
public static final FunctionDependency IARRAY = MODULE.createDependency("IArray");
|
||||
public static final FunctionDependency STRATEGY = MODULE.createDependency("Strategy");
|
||||
|
||||
@Override
|
||||
public String getModuleName() { return "Collection"; }
|
||||
@Override
|
||||
protected void loadVariables() {}
|
||||
@Override
|
||||
public List<IDependency> getDependencies(ClassType keyType, ClassType valueType) { return Arrays.asList(MODULE, STREAMS, SPLIT_ITERATORS, IARRAY, STRATEGY); }
|
||||
|
||||
@Override
|
||||
protected void loadFlags() {
|
||||
if(MODULE.isEnabled()) addKeyFlag("COLLECTION_MODULE");
|
||||
if(STREAMS.isEnabled()) addKeyFlag("STREAM_FEATURE");
|
||||
if(SPLIT_ITERATORS.isEnabled()) addKeyFlag("SPLIT_ITERATOR_FEATURE");
|
||||
if(IARRAY.isEnabled()) addKeyFlag("IARRAY_FEATURE");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadBlockades() {
|
||||
if(!MODULE.isEnabled()) {
|
||||
addBlockedFiles("Iterable", "Iterables", "Iterator", "Iterators", "BidirectionalIterator", "ListIterator");
|
||||
addBlockedFiles("Arrays", "Collection", "OrderedCollection", "AbstractCollection", "Collections", "Stack");
|
||||
}
|
||||
if(!SPLIT_ITERATORS.isEnabled()) addBlockedFiles("Splititerator", "Splititerators");
|
||||
if(!IARRAY.isEnabled()) addBlockedFiles("IArray");
|
||||
if(!STRATEGY.isEnabled()) addBlockedFiles("Strategy");
|
||||
|
||||
if(keyType.isObject())
|
||||
{
|
||||
addBlockedFiles("Stack");
|
||||
addBlockedFiles("CollectionStreamTester");
|
||||
}
|
||||
if(keyType == ClassType.BOOLEAN)
|
||||
{
|
||||
addBlockedFiles("CollectionRemoveIfTester", "CollectionStreamTester");
|
||||
addBlockedFilter(T -> T.endsWith("Tester") && T.startsWith("Iterable"));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadRemappers()
|
||||
{
|
||||
//Main Classes
|
||||
addRemapper("IArray", "I%sArray");
|
||||
addRemapper("AbstractCollection", "Abstract%sCollection");
|
||||
|
||||
//Test Classes
|
||||
addRemapper("AbstractIteratorTester", "Abstract%sIteratorTester");
|
||||
addRemapper("MinimalCollection", "Minimal%sCollection");
|
||||
addRemapper("TestCollectionGenerator", "Test%sCollectionGenerator");
|
||||
addRemapper("AbstractContainerTester", "Abstract%sContainerTester");
|
||||
addRemapper("AbstractCollectionTester", "Abstract%sCollectionTester");
|
||||
addRemapper("SimpleTestGenerator", "Simple%sTestGenerator");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadFunctions()
|
||||
{
|
||||
addFunctionMapper("NEXT", "next");
|
||||
addSimpleMapper("NEW_STREAM", keyType.isPrimitiveBlocking() ? "" : keyType.getCustomJDKType().getKeyType()+"Stream");
|
||||
addFunctionMapper("PREVIOUS", "previous");
|
||||
addFunctionMapper("REMOVE_KEY", "rem");
|
||||
addSimpleMapper("TO_ARRAY", "to"+keyType.getNonFileType()+"Array");
|
||||
addSimpleMapper("VALUE_TO_ARRAY", "to"+valueType.getNonFileType()+"Array");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadClasses()
|
||||
{
|
||||
//Abstract Classes
|
||||
addAbstractMapper("ABSTRACT_COLLECTION", "Abstract%sCollection");
|
||||
addAbstractMapper("REVERSED_ORDERED_COLLECTION", "Reverse%sOrderedCollection");
|
||||
|
||||
//Helper Classes
|
||||
addClassMapper("ARRAYS", "Arrays");
|
||||
addClassMapper("COLLECTIONS", "Collections");
|
||||
addClassMapper("ITERABLES", "Iterables");
|
||||
addClassMapper("SPLIT_ITERATORS", "Splititerators");
|
||||
addClassMapper("ITERATORS", "Iterators");
|
||||
|
||||
//Interfaces
|
||||
addClassMapper("COLLECTION", "Collection");
|
||||
addClassMapper("ORDERED_COLLECTION", "OrderedCollection");
|
||||
addClassMapper("ITERABLE", "Iterable");
|
||||
addClassMapper("SPLIT_ITERATOR", "Splititerator");
|
||||
addClassMapper("LIST_ITERATOR", "ListIterator");
|
||||
addClassMapper("BI_ITERATOR", "BidirectionalIterator");
|
||||
addClassMapper("ITERATOR", "Iterator");
|
||||
if(keyType.isObject()) addSimpleMapper("STACK", "Stack");
|
||||
else addClassMapper("STACK", "Stack");
|
||||
addClassMapper("STRATEGY", "Strategy");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadTestClasses()
|
||||
{
|
||||
//Implementation Classes
|
||||
addAbstractMapper("MINIMAL_COLLECTION", "Minimal%sCollection");
|
||||
addClassMapper("BIDIRECTIONAL_ITERATOR_TESTER", "BidirectionalteratorTester");
|
||||
addClassMapper("LIST_ITERATOR_TESTER", "ListIteratorTester");
|
||||
addClassMapper("ITERATOR_TESTER", "IteratorTester");
|
||||
addClassMapper("COLLECTION_TEST_BUILDER", "CollectionTestSuiteBuilder");
|
||||
addClassMapper("COLLECTION_CONSTRUCTOR_TESTS", "CollectionConstructorTests");
|
||||
|
||||
//Abstract Classes
|
||||
addAbstractMapper("ABSTRACT_COLLECTION_TESTER", "Abstract%sCollectionTester");
|
||||
addAbstractMapper("ABSTRACT_CONTAINER_TESTER", "Abstract%sContainerTester");
|
||||
addAbstractMapper("ABSTRACT_ITERATOR_TESTER", "Abstract%sIteratorTester");
|
||||
|
||||
//Helper Classes
|
||||
addAbstractMapper("TEST_COLLECTION_GENERATOR", "Test%sCollectionGenerator");
|
||||
addAbstractMapper("SIMPLE_TEST_GENERATOR", "Simple%sTestGenerator");
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
package speiger.src.builder.modules;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import speiger.src.builder.ClassType;
|
||||
import speiger.src.builder.RequiredType;
|
||||
import speiger.src.builder.dependencies.IDependency;
|
||||
import speiger.src.builder.dependencies.ModuleDependency;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public class FunctionModule extends BaseModule
|
||||
{
|
||||
public static final BaseModule INSTANCE = new FunctionModule();
|
||||
public static final ModuleDependency MODULE = new ModuleDependency(INSTANCE, false).addKeyDependency(JavaModule.MODULE);
|
||||
|
||||
@Override
|
||||
public String getModuleName() { return "Function"; }
|
||||
@Override
|
||||
public boolean isBiModule() { return true; }
|
||||
@Override
|
||||
protected void loadVariables() {}
|
||||
@Override
|
||||
protected void loadFlags() {}
|
||||
@Override
|
||||
protected void loadTestClasses() {}
|
||||
|
||||
@Override
|
||||
public List<IDependency> getDependencies(ClassType keyType, ClassType valueType) {
|
||||
return Arrays.asList(MODULE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadBlockades()
|
||||
{
|
||||
if(keyType.isObject()) addBlockedFiles("Consumer", "Comparator");
|
||||
if(!MODULE.isEnabled()) addBlockedFiles("Consumer", "BiConsumer", "Comparator", "Supplier", "Optional", "Function", "UnaryOperator");
|
||||
if(!keyType.needsCustomJDKType()) addBlockedFiles("Optional");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadRemappers()
|
||||
{
|
||||
addBiRequirement("BiConsumer", "");
|
||||
addBiRequirement("UnaryOperator", "");
|
||||
if(valueType == ClassType.BOOLEAN) {
|
||||
addRequirement("Function", "%1$s", RequiredType.BI_CLASS);
|
||||
addRemapper("Function", (keyType.isObject() ? "" : "%s")+"Predicate");
|
||||
}
|
||||
else if(keyType.isObject() && !valueType.isObject()) {
|
||||
addRequirement("Function", "%2$s", RequiredType.BI_CLASS);
|
||||
addRemapper("Function", "To%sFunction");
|
||||
}
|
||||
else if(keyType == valueType) {
|
||||
addRequirement("Function", "%1$s", RequiredType.BI_CLASS);
|
||||
addRemapper("Function", (keyType.isObject() ? "" : "%s")+"UnaryOperator");
|
||||
}
|
||||
else if(valueType.isObject()) {
|
||||
addRequirement("Function", "%1$s", RequiredType.BI_CLASS);
|
||||
addRemapper("Function", "%sFunction");
|
||||
}
|
||||
else addBiRequirement("Function");
|
||||
addRemapper("BiConsumer", "%sConsumer");
|
||||
addRemapper("Optional", "Optional%s");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadFunctions()
|
||||
{
|
||||
addSimpleMapper("APPLY", keyType.getApply(valueType));
|
||||
addSimpleMapper("SUPPLY_GET", keyType.isObject() ? "get" : "getAs"+keyType.getNonFileType());
|
||||
addSimpleMapper("VALUE_SUPPLY_GET", valueType.isObject() ? "get" : "getAs"+valueType.getNonFileType());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadClasses()
|
||||
{
|
||||
//Interfaces
|
||||
addBiClassMapper("BI_CONSUMER", "Consumer", "");
|
||||
addClassMapper("BI_TO_OBJECT_CONSUMER", "ObjectConsumer");
|
||||
addAbstractMapper("BI_FROM_OBJECT_CONSUMER", "Object%sConsumer");
|
||||
addAbstractMapper("BI_FROM_INT_CONSUMER", "Int%sConsumer");
|
||||
if(keyType.isObject()) {
|
||||
addSimpleMapper("TO_OBJECT_FUNCTION", keyType.getNonFileType()+"UnaryOperator");
|
||||
addSimpleMapper("VALUE_TO_OBJECT_FUNCTION", valueType.isObject() ? "UnaryOperator" : valueType.getFileType()+"Function");
|
||||
}
|
||||
else {
|
||||
addSimpleMapper("TO_OBJECT_FUNCTION", keyType.getNonFileType()+"Function");
|
||||
addSimpleMapper("VALUE_TO_OBJECT_FUNCTION", valueType.isObject() ? "UnaryOperator" : valueType.getFileType()+"Function");
|
||||
}
|
||||
if(valueType == ClassType.BOOLEAN) addFunctionMappers("FUNCTION", "%sPredicate");
|
||||
else if(keyType.isObject() && !valueType.isObject()) addFunctionValueMappers("FUNCTION", "To%sFunction");
|
||||
else if(keyType == valueType) addFunctionMappers("FUNCTION", "%sUnaryOperator");
|
||||
else if(valueType.isObject()) addFunctionMappers("FUNCTION", "%sFunction");
|
||||
else addBiClassMapper("FUNCTION", "Function", "2");
|
||||
|
||||
addFunctionMappers("PREDICATE", "%sPredicate");
|
||||
addClassMapper("SUPPLIER", "Supplier");
|
||||
addSimpleMapper("OPTIONAL", keyType.isObject() ? "Optional" : String.format("Optional%s", keyType.getFileType()));
|
||||
addSimpleMapper("VALUE_OPTIONAL", valueType.isObject() ? "Optional" : String.format("Optional%s", valueType.getFileType()));
|
||||
addAbstractMapper("SINGLE_UNARY_OPERATOR", "%1$s%1$sUnaryOperator");
|
||||
addBiClassMapper("UNARY_OPERATOR", "UnaryOperator", "");
|
||||
if(keyType.isObject())
|
||||
{
|
||||
if(!valueType.isObject()) addSimpleMapper("VALUE_CONSUMER", valueType.getFileType()+"Consumer");
|
||||
else addSimpleMapper("VALUE_CONSUMER", "Consumer");
|
||||
addSimpleMapper("CONSUMER", "Consumer");
|
||||
addSimpleMapper("IARRAY", "IObjectArray");
|
||||
}
|
||||
else
|
||||
{
|
||||
if(valueType.isObject())
|
||||
{
|
||||
addSimpleMapper("VALUE_CONSUMER", "Consumer");
|
||||
addSimpleMapper("CONSUMER", keyType.getFileType()+"Consumer");
|
||||
}
|
||||
else addClassMapper("CONSUMER", "Consumer");
|
||||
addFunctionMappers("IARRAY", "I%sArray");
|
||||
}
|
||||
addSimpleMapper("VALUE_COMPARATOR", valueType.isObject() ? "Comparator" : String.format("%sComparator", valueType.getNonFileType()));
|
||||
addSimpleMapper("COMPARATOR", keyType.isObject() ? "Comparator" : String.format("%sComparator", keyType.getNonFileType()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,235 @@
|
||||
package speiger.src.builder.modules;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import speiger.src.builder.ClassType;
|
||||
import speiger.src.builder.dependencies.IDependency;
|
||||
import speiger.src.builder.dependencies.ModuleDependency;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public class JavaModule extends BaseModule
|
||||
{
|
||||
public static final BaseModule INSTANCE = new JavaModule();
|
||||
public static final ModuleDependency MODULE = new ModuleDependency(INSTANCE, false);
|
||||
|
||||
@Override
|
||||
public String getModuleName() { return "Base"; }
|
||||
@Override
|
||||
protected void loadVariables()
|
||||
{
|
||||
createHelperVars(keyType, false, "KEY");
|
||||
createHelperVars(valueType, true, "VALUE");
|
||||
loadBaseVariables();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IDependency> getDependencies(ClassType keyType, ClassType valueType) {
|
||||
return Arrays.asList(MODULE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadFlags()
|
||||
{
|
||||
addFlag("TYPE_"+keyType.getCapType());
|
||||
addFlag("VALUE_"+valueType.getCapType());
|
||||
addValue("JAVA_VERSION", getVersion());
|
||||
if(keyType == valueType) addFlag("SAME_TYPE");
|
||||
if(keyType.hasFunction(valueType)) addFlag("JDK_FUNCTION");
|
||||
if(!keyType.needsCustomJDKType()) addFlag("JDK_TYPE");
|
||||
if(!keyType.isPrimitiveBlocking()) addFlag("PRIMITIVES");
|
||||
if(!valueType.isPrimitiveBlocking()) addFlag("VALUE_PRIMITIVES");
|
||||
if(!valueType.needsCustomJDKType()) addFlag("JDK_VALUE");
|
||||
}
|
||||
|
||||
private int getVersion() {
|
||||
String version = System.getProperty("java.version");
|
||||
if(version.startsWith("1.")) return Integer.parseInt(version.substring(2, 3));
|
||||
int dot = version.indexOf(".");
|
||||
return Integer.parseInt(dot != -1 ? version.substring(0, dot) : version);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadRemappers() {}
|
||||
@Override
|
||||
protected void loadBlockades() {}
|
||||
|
||||
@Override
|
||||
protected void loadFunctions()
|
||||
{
|
||||
addSimpleMapper("APPLY_KEY_VALUE", keyType.isObject() ? "apply" : "applyAs"+keyType.getNonFileType());
|
||||
addSimpleMapper("APPLY_VALUE", valueType.isObject() ? "apply" : "applyAs"+valueType.getNonFileType());
|
||||
addSimpleMapper("APPLY_CAST", "applyAs"+keyType.getCustomJDKType().getNonFileType());
|
||||
addSimpleMapper("GET_OPTIONAL", keyType.isObject() ? "ofNullable" : "of");
|
||||
addSimpleMapper("GET_OPTIONAL_VALUE", valueType.isObject() ? "ofNullable" : "of");
|
||||
|
||||
//Shared by Maps and Pairs so moved to java.
|
||||
addFunctionMappers("ENTRY_KEY", "get%sKey");
|
||||
addFunctionValueMappers("ENTRY_VALUE", "get%sValue");
|
||||
addFunctionMappers("KEY_ENTRY", "set%sKey");
|
||||
addFunctionValueMappers("VALUE_ENTRY", "set%sValue");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadClasses()
|
||||
{
|
||||
if(getVersion() >= 17) addSimpleMapper("RANDOM", "RandomGenerator");
|
||||
else addSimpleMapper("RANDOM", "Random");
|
||||
addSimpleMapper("JAVA_PREDICATE", keyType.isPrimitiveBlocking() ? "" : keyType.getCustomJDKType().getFileType()+"Predicate");
|
||||
addSimpleMapper("JAVA_CONSUMER", keyType.isPrimitiveBlocking() ? "" : "java.util.function."+keyType.getCustomJDKType().getFileType()+"Consumer");
|
||||
addSimpleMapper("JAVA_SUPPLIER", keyType.isPrimitiveBlocking() ? "" : "java.util.function."+keyType.getCustomJDKType().getFileType()+"Supplier");
|
||||
addSimpleMapper("JAVA_FUNCTION", keyType.getFunctionClass(valueType));
|
||||
addSimpleMapper("JAVA_BINARY_OPERATOR", keyType == ClassType.BOOLEAN ? "" : (keyType.isObject() ? "java.util.function.BinaryOperator" : "java.util.function."+keyType.getCustomJDKType().getFileType()+"BinaryOperator"));
|
||||
addSimpleMapper("JAVA_UNARY_OPERATOR", keyType.isObject() ? "BinaryOperator" : keyType == ClassType.BOOLEAN ? "" : keyType.getCustomJDKType().getFileType()+"UnaryOperator");
|
||||
addSimpleMapper("JAVA_SPLIT_ITERATOR", keyType.isPrimitiveBlocking() ? "Spliterator" : "Of"+keyType.getCustomJDKType().getFileType());
|
||||
addSimpleMapper("JAVA_STREAM", keyType.isPrimitiveBlocking() ? "" : keyType.getCustomJDKType().getFileType()+"Stream");
|
||||
addSimpleMapper("JAVA_BUFFER", keyType.getFileType()+"Buffer");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadTestClasses()
|
||||
{
|
||||
addClassMapper("HELPERS", "Helpers");
|
||||
addClassMapper("SAMPLE_ELEMENTS", "Samples");
|
||||
}
|
||||
|
||||
private void loadBaseVariables()
|
||||
{
|
||||
addSimpleMapper("VALUE_PACKAGE", valueType.getPathType());
|
||||
addSimpleMapper("PACKAGE", keyType.getPathType());
|
||||
addSimpleMapper("CLASS_TYPE", keyType.getClassType());
|
||||
addSimpleMapper("CLASS_VALUE_TYPE", valueType.getClassValueType());
|
||||
addSimpleMapper("KEY_TYPE", keyType.getKeyType());
|
||||
addSimpleMapper("KEY_OBJECT_TYPE", keyType.isObject() ? "Object" : keyType.getKeyType());
|
||||
addSimpleMapper("KEY_STRING_TYPE", keyType.isObject() ? "String" : keyType.getKeyType());
|
||||
addSimpleMapper("KEY_SPECIAL_TYPE", keyType.isObject() ? "E" : keyType.getKeyType());
|
||||
addSimpleMapper("CLASS_OBJECT_TYPE", keyType.getClassType());
|
||||
addSimpleMapper("CLASS_OBJECT_VALUE_TYPE", valueType.getClassValueType());
|
||||
addSimpleMapper("CLASS_STRING_TYPE", keyType.isObject() ? "String" : keyType.getClassType());
|
||||
addSimpleMapper("CLASS_STRING_VALUE_TYPE", valueType.isObject() ? "String" : valueType.getClassValueType());
|
||||
addSimpleMapper("VALUE_TYPE", valueType.getValueType());
|
||||
addSimpleMapper("VALUE_OBJECT_TYPE", valueType.isObject() ? "Object" : valueType.getValueType());
|
||||
addSimpleMapper("VALUE_STRING_TYPE", valueType.isObject() ? "String" : valueType.getValueType());
|
||||
addSimpleMapper("VALUE_SPECIAL_TYPE", valueType.isObject() ? "E" : valueType.getKeyType());
|
||||
addSimpleMapper("KEY_JAVA_TYPE", keyType.getCustomJDKType().getKeyType());
|
||||
addSimpleMapper("VALUE_JAVA_TYPE", keyType.getCustomJDKType().getKeyType());
|
||||
|
||||
addSimpleMapper("EMPTY_KEY_VALUE", keyType.getEmptyValue());
|
||||
addSimpleMapper("EMPTY_VALUE", valueType.getEmptyValue());
|
||||
|
||||
addSimpleMapper("INVALID_KEY_VALUE", keyType.getInvalidValue());
|
||||
addSimpleMapper("INVALID_VALUE", valueType.getInvalidValue());
|
||||
|
||||
addSimpleMapper(" KEY_STRING_GENERIC_TYPE", keyType.isObject() ? "<String>" : "");
|
||||
addSimpleMapper(" VALUE_STRING_GENERIC_TYPE", valueType.isObject() ? "<String>" : "");
|
||||
addSimpleMapper(" KEY_VALUE_STRING_GENERIC_TYPE", keyType.isObject() ? (valueType.isObject() ? "<String, String>" : "<String>") : (valueType.isObject() ? "<String>" : ""));
|
||||
|
||||
addSimpleMapper(" KEY_SAME_GENERIC_TYPE", keyType.isObject() ? "<T, T>" : "");
|
||||
addSimpleMapper(" VALUE_SAME_GENERIC_TYPE", keyType.isObject() ? "<V, V>" : "");
|
||||
|
||||
addSimpleMapper(" KEY_GENERIC_TYPE", keyType.isObject() ? "<"+keyType.getKeyType()+">" : "");
|
||||
addSimpleMapper(" KEY_KEY_GENERIC_TYPE", keyType.isObject() ? "<"+keyType.getKeyType()+", "+keyType.getKeyType()+">" : "");
|
||||
addSimpleMapper(" KEY_CLASS_GENERIC_TYPE", keyType.isObject() ? "<"+keyType.getClassType()+">" : "");
|
||||
|
||||
|
||||
addSimpleMapper(" VALUE_GENERIC_TYPE", valueType.isObject() ? "<"+valueType.getValueType()+">" : "");
|
||||
addSimpleMapper(" VALUE_VALUE_GENERIC_TYPE", valueType.isObject() ? "<"+valueType.getValueType()+", "+valueType.getValueType()+">" : "");
|
||||
addSimpleMapper(" VALUE_CLASS_GENERIC_TYPE", valueType.isObject() ? "<"+valueType.getClassValueType()+">" : "");
|
||||
|
||||
addSimpleMapper(" KEY_VALUE_GENERIC_TYPE", keyType.isObject() ? (valueType.isObject() ? "<"+keyType.getKeyType()+", "+valueType.getValueType()+">" : "<"+keyType.getKeyType()+">") : (valueType.isObject() ? "<"+valueType.getValueType()+">" : ""));
|
||||
addSimpleMapper(" KEY_VALUE_VALUE_GENERIC_TYPE", keyType.isObject() ? (valueType.isObject() ? "<"+keyType.getKeyType()+", "+valueType.getValueType()+", "+valueType.getValueType()+">" : "<"+keyType.getKeyType()+">") : (valueType.isObject() ? "<"+valueType.getValueType()+", "+valueType.getValueType()+">" : ""));
|
||||
addInjectMapper(" KEY_VALUE_SPECIAL_GENERIC_TYPE", keyType.isObject() ? (valueType.isObject() ? "<"+keyType.getKeyType()+", "+valueType.getValueType()+", %s>" : "<"+keyType.getKeyType()+", %s>") : (valueType.isObject() ? "<"+valueType.getValueType()+", %s>" : "<%s>")).setBraceType("<>").removeBraces();
|
||||
|
||||
addSimpleMapper(" NO_GENERIC_TYPE", keyType.isObject() ? "<?>" : "");
|
||||
addSimpleMapper(" NO_KV_GENERIC_TYPE", keyType.isObject() ? (valueType.isObject() ? "<?, ?>" : "<?>") : valueType.isObject() ? "<?>" : "");
|
||||
addSimpleMapper(" KEY_COMPAREABLE_TYPE", keyType.isObject() ? "<"+keyType.getKeyType()+" extends Comparable<T>>" : "");
|
||||
|
||||
addSimpleMapper(" KEY_SUPER_GENERIC_TYPE", keyType.isObject() ? "<? super "+keyType.getKeyType()+">" : "");
|
||||
addSimpleMapper(" VALUE_SUPER_GENERIC_TYPE", valueType.isObject() ? "<? super "+valueType.getValueType()+">" : "");
|
||||
addSimpleMapper(" KEY_VALUE_SUPER_GENERIC_TYPE", keyType.isObject() ? (valueType.isObject() ? "<? super "+keyType.getKeyType()+", ? super "+valueType.getValueType()+">" : "<? super "+keyType.getKeyType()+">") : (valueType.isObject() ? "<? super "+valueType.getValueType()+">" : ""));
|
||||
|
||||
addSimpleMapper(" KEY_UNKNOWN_GENERIC_TYPE", keyType.isObject() ? "<? extends "+keyType.getKeyType()+">" : "");
|
||||
addSimpleMapper(" VALUE_UNKNOWN_GENERIC_TYPE", valueType.isObject() ? "<? extends "+valueType.getValueType()+">" : "");
|
||||
addSimpleMapper(" KEY_VALUE_UNKNOWN_GENERIC_TYPE", keyType.isObject() ? (valueType.isObject() ? "<? extends "+keyType.getKeyType()+", ? extends "+valueType.getValueType()+">" : "<? extends "+keyType.getKeyType()+">") : (valueType.isObject() ? "<? extends "+valueType.getValueType()+">" : ""));
|
||||
|
||||
addSimpleMapper(" KEY_ENUM_VALUE_GENERIC_TYPE", keyType.isObject() ? (valueType.isObject() ? "<"+keyType.getKeyType()+" extends Enum<"+keyType.getKeyType()+">, "+valueType.getValueType()+">" : "<"+keyType.getKeyType()+" extends Enum<"+keyType.getKeyType()+">>") : (valueType.isObject() ? "<"+valueType.getValueType()+">" : ""));
|
||||
addSimpleMapper(" KEY_VALUE_ENUM_GENERIC_TYPE", keyType.isObject() ? (valueType.isObject() ? "<"+keyType.getKeyType()+", "+valueType.getValueType()+" extends Enum<"+valueType.getValueType()+">>" : "<"+keyType.getKeyType()+">") : (valueType.isObject() ? "<"+valueType.getValueType()+" extends Enum<"+valueType.getValueType()+">>" : ""));
|
||||
|
||||
addInjectMapper(" KEY_SPECIAL_GENERIC_TYPE", keyType.isObject() ? "<%s>" : "").removeBraces().setBraceType("<>");
|
||||
addInjectMapper(" VALUE_SPECIAL_GENERIC_TYPE", valueType.isObject() ? "<%s>" : "").removeBraces().setBraceType("<>");
|
||||
addInjectMapper(" KSK_GENERIC_TYPE", keyType.isObject() ? "<%s, "+keyType.getKeyType()+">" : "<%s>").removeBraces().setBraceType("<>");
|
||||
addInjectMapper(" KKS_GENERIC_TYPE", keyType.isObject() ? "<"+keyType.getKeyType()+", %s>" : "<%s>").removeBraces().setBraceType("<>");
|
||||
addArgumentMapper(" KSS_GENERIC_TYPE", keyType.isObject() ? "<%1$s, %2$s>" : "<%2$s>").removeBraces().setBraceType("<>");
|
||||
addInjectMapper(" SK_GENERIC_TYPE", keyType.isObject() ? "<%s, "+keyType.getKeyType()+">" : "").removeBraces().setBraceType("<>");
|
||||
addInjectMapper(" KS_GENERIC_TYPE", keyType.isObject() ? "<"+keyType.getKeyType()+", %s>" : "").removeBraces().setBraceType("<>");
|
||||
addInjectMapper(" VSV_GENERIC_TYPE", valueType.isObject() ? "<%s, "+valueType.getValueType()+">" : "<%s>").removeBraces().setBraceType("<>");
|
||||
addInjectMapper(" VVS_GENERIC_TYPE", valueType.isObject() ? "<"+valueType.getValueType()+", %s>" : "<%s>").removeBraces().setBraceType("<>");
|
||||
addArgumentMapper(" VSS_GENERIC_TYPE", valueType.isObject() ? "<%1$s, %2$s>" : "<%2$s>").removeBraces().setBraceType("<>");
|
||||
addInjectMapper(" SV_GENERIC_TYPE", valueType.isObject() ? "<%s, "+valueType.getValueType()+">" : "").removeBraces().setBraceType("<>");
|
||||
addInjectMapper(" VS_GENERIC_TYPE", valueType.isObject() ? "<"+valueType.getValueType()+", %s>" : "").removeBraces().setBraceType("<>");
|
||||
|
||||
|
||||
addSimpleMapper(" GENERIC_KEY_BRACES", keyType.isObject() ? " <"+keyType.getKeyType()+">" : "");
|
||||
addSimpleMapper(" GENERIC_VALUE_BRACES", valueType.isObject() ? " <"+valueType.getValueType()+">" : "");
|
||||
addInjectMapper(" GENERIC_SPECIAL_KEY_BRACES", keyType.isObject() ? " <%s>" : "").removeBraces().setBraceType("<>");
|
||||
addInjectMapper(" GENERIC_SPECIAL_VALUE_BRACES", valueType.isObject() ? " <%s>" : "").removeBraces().setBraceType("<>");
|
||||
addSimpleMapper(" GENERIC_KEY_ENUM_VALUE_BRACES", keyType.isObject() ? (valueType.isObject() ? " <"+keyType.getKeyType()+" extends Enum<"+keyType.getKeyType()+">, "+valueType.getValueType()+">" : " <"+keyType.getKeyType()+" extends Enum<"+keyType.getKeyType()+">>") : (valueType.isObject() ? " <"+valueType.getValueType()+">" : ""));
|
||||
|
||||
addInjectMapper(" GENERIC_KEY_SPECIAL_BRACES", keyType.isObject() ? " <"+keyType.getKeyType()+", %s>" : " <%s>").removeBraces().setBraceType("<>");
|
||||
addInjectMapper(" GENERIC_VALUE_SPECIAL_BRACES", valueType.isObject() ? " <"+valueType.getKeyType()+", %s>" : " <%s>").removeBraces().setBraceType("<>");
|
||||
|
||||
addSimpleMapper(" GENERIC_KEY_VALUE_BRACES", keyType.isObject() ? (valueType.isObject() ? " <"+keyType.getKeyType()+", "+valueType.getValueType()+">" : " <"+keyType.getKeyType()+">") : (valueType.isObject() ? " <"+valueType.getValueType()+">" : ""));
|
||||
addSimpleMapper(" COMPAREABLE_KEY_BRACES", keyType.isObject() ? " <"+keyType.getKeyType()+" extends Comparable<T>>" : "");
|
||||
addSimpleMapper("KV_BRACES", keyType.isObject() || valueType.isObject() ? "<>" : "");
|
||||
addSimpleMapper("VALUE_BRACES", valueType.isObject() ? "<>" : "");
|
||||
addSimpleMapper("BRACES", keyType.isObject() ? "<>" : "");
|
||||
if(keyType.needsCustomJDKType())
|
||||
{
|
||||
addSimpleMapper("JAVA_TYPE", keyType.getCustomJDKType().getKeyType());
|
||||
addSimpleMapper("SANITY_CAST", "castTo"+keyType.getFileType());
|
||||
}
|
||||
addSimpleMapper("JAVA_CLASS", keyType.getCustomJDKType().getClassType());
|
||||
if(valueType.needsCustomJDKType())
|
||||
{
|
||||
addSimpleMapper("SANITY_CAST_VALUE", "castTo"+valueType.getFileType());
|
||||
}
|
||||
addSimpleMapper("[SPACE]", " ");
|
||||
addComment("@ArrayType", "@param <%s> the keyType of array that the operation should be applied");
|
||||
addComment("@Type", "@param <%s> the keyType of elements maintained by this Collection");
|
||||
addValueComment("@ValueArrayType", "@param <%s> the keyType of array that the operation should be applied");
|
||||
addValueComment("@ValueType", "@param <%s> the keyType of elements maintained by this Collection");
|
||||
addSimpleMapper("@Java21", getVersion() >= 21 ? "@Override" : "");
|
||||
addAnnontion("@PrimitiveOverride", "@Override");
|
||||
addSimpleMapper("@PrimitiveDoc", "");
|
||||
addAnnontion("@Primitive", "@Deprecated");
|
||||
addValueAnnontion("@ValuePrimitiveOverride", "@Override");
|
||||
addValueAnnontion("@ValuePrimitive", "@Deprecated");
|
||||
}
|
||||
|
||||
private void createHelperVars(ClassType type, boolean value, String fix)
|
||||
{
|
||||
addArgumentMapper("EQUALS_"+fix+"_TYPE", "Objects.equals(%2$s, "+(type.isObject() ? "%1$s" : fix+"_TO_OBJ(%1$s)")+")").removeBraces();
|
||||
addInjectMapper(fix+"_EQUALS_NOT_NULL", type.getComparableValue()+" != "+(type.isPrimitiveBlocking() || type.needsCast() ? type.getEmptyValue() : "0")).removeBraces();
|
||||
addInjectMapper(fix+"_EQUALS_NULL", type.getComparableValue()+" == "+(type.isPrimitiveBlocking() || type.needsCast() ? type.getEmptyValue() : "0")).removeBraces();
|
||||
addArgumentMapper(fix+"_EQUALS_NOT", type.getEquals(true)).removeBraces();
|
||||
addArgumentMapper(fix+"_EQUALS", type.getEquals(false)).removeBraces();
|
||||
addSimpleMapper("FILE_"+fix+"_TYPE", type.getFileType());
|
||||
|
||||
addArgumentMapper("COMPAREABLE_TO_"+fix, type.isObject() ? "((Comparable<"+type.getKeyType(value)+">)%1$s).compareTo(("+type.getKeyType(value)+")%2$s)" : type.getClassType(value)+".compare(%1$s, %2$s)").removeBraces();
|
||||
addArgumentMapper("COMPARE_TO_"+fix, type.isObject() ? "%1$s.compareTo(%2$s)" : type.getClassType(value)+".compare(%1$s, %2$s)").removeBraces();
|
||||
|
||||
addInjectMapper(fix+"_TO_OBJ", type.isObject() ? "%s" : type.getClassType(value)+".valueOf(%s)").removeBraces();
|
||||
addInjectMapper("OBJ_TO_"+fix, type.isObject() ? "%s" : "%s."+type.getKeyType(value)+"Value()").removeBraces();
|
||||
addInjectMapper("CLASS_TO_"+fix, type.isObject() ? "("+type.getKeyType(value)+")%s" : "(("+type.getClassType(value)+")%s)."+type.getKeyType(value)+"Value()").removeBraces();
|
||||
|
||||
addInjectMapper(fix+"_TO_HASH", type.isObject() ? "Objects.hashCode(%s)" : type.getClassType(value)+".hashCode(%s)").removeBraces();
|
||||
addInjectMapper(fix+"_TO_STRING", type.isObject() ? "Objects.toString(%s)" : type.getClassType(value)+".toString(%s)").removeBraces();
|
||||
|
||||
addSimpleMapper("CAST_"+fix+"_ARRAY ", type.isObject() ? "("+fix+"_TYPE[])" : "");
|
||||
addSimpleMapper("EMPTY_"+fix+"_ARRAY", type.isObject() ? "("+fix+"_TYPE[])ARRAYS.EMPTY_ARRAY" : "ARRAYS.EMPTY_ARRAY");
|
||||
addInjectMapper("NEW_"+fix+"_ARRAY", type.isObject() ? "("+fix+"_TYPE[])new Object[%s]" : "new "+fix+"_TYPE[%s]").removeBraces();
|
||||
addInjectMapper("NEW_SPECIAL_"+fix+"_ARRAY", type.isObject() ? "(E[])new Object[%s]" : "new "+fix+"_TYPE[%s]").removeBraces();
|
||||
if(value) addInjectMapper("NEW_CLASS_VALUE_ARRAY", type.isObject() ? "(CLASS_VALUE_TYPE[])new Object[%s]" : "new CLASS_VALUE_TYPE[%s]").removeBraces();
|
||||
else addInjectMapper("NEW_CLASS_ARRAY", type.isObject() ? "(CLASS_TYPE[])new Object[%s]" : "new CLASS_TYPE[%s]").removeBraces();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
package speiger.src.builder.modules;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import speiger.src.builder.ClassType;
|
||||
import speiger.src.builder.dependencies.FunctionDependency;
|
||||
import speiger.src.builder.dependencies.IDependency;
|
||||
import speiger.src.builder.dependencies.ModuleDependency;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public class ListModule extends BaseModule
|
||||
{
|
||||
public static final BaseModule INSTANCE = new ListModule();
|
||||
public static final ModuleDependency MODULE = new ModuleDependency(INSTANCE, false).addKeyDependency(CollectionModule.MODULE).addKeyDependency(CollectionModule.SPLIT_ITERATORS);
|
||||
public static final FunctionDependency IMPLEMENTATION = MODULE.createDependency("Implementations");
|
||||
public static final FunctionDependency WRAPPERS = MODULE.createDependency("Wrappers");
|
||||
public static final FunctionDependency ARRAY_LIST = MODULE.createDependency("ArrayList").addKeyDependency(IMPLEMENTATION);
|
||||
public static final FunctionDependency LINKED_LIST = MODULE.createDependency("LinkedList").addKeyDependency(IMPLEMENTATION);
|
||||
public static final FunctionDependency IMMUTABLE_LIST = MODULE.createDependency("ImmutableList").addKeyDependency(IMPLEMENTATION);
|
||||
public static final FunctionDependency COPY_ON_WRITE_LIST = MODULE.createDependency("CopyOnWriteList").addKeyDependency(IMPLEMENTATION);
|
||||
|
||||
@Override
|
||||
public String getModuleName() { return "List"; }
|
||||
@Override
|
||||
public List<IDependency> getDependencies(ClassType keyType, ClassType valueType) { return Arrays.asList(MODULE, IMPLEMENTATION, WRAPPERS, ARRAY_LIST, LINKED_LIST, IMMUTABLE_LIST, COPY_ON_WRITE_LIST); }
|
||||
@Override
|
||||
protected void loadVariables() {}
|
||||
@Override
|
||||
protected void loadFlags() {
|
||||
if(MODULE.isEnabled()) addKeyFlag("LIST_MODULE");
|
||||
if(WRAPPERS.isEnabled()) addKeyFlag("LISTS_FEATURE");
|
||||
if(ARRAY_LIST.isEnabled()) addKeyFlag("ARRAY_LIST_FEATURE");
|
||||
if(LINKED_LIST.isEnabled()) addKeyFlag("LINKED_LIST_FEATURE");
|
||||
if(IMMUTABLE_LIST.isEnabled()) addKeyFlag("IMMUTABLE_LIST_FEATURE");
|
||||
if(COPY_ON_WRITE_LIST.isEnabled()) addKeyFlag("COPY_ON_WRITE_LIST_FEATURE");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadBlockades()
|
||||
{
|
||||
if(!WRAPPERS.isEnabled()) addBlockedFiles("Lists");
|
||||
if(!ARRAY_LIST.isEnabled()) addBlockedFiles("ArrayList");
|
||||
if(!LINKED_LIST.isEnabled()) addBlockedFiles("LinkedList");
|
||||
if(!IMMUTABLE_LIST.isEnabled()) addBlockedFiles("ImmutableList");
|
||||
if(!COPY_ON_WRITE_LIST.isEnabled()) addBlockedFiles("CopyOnWriteList");
|
||||
if(!MODULE.isEnabled()) addBlockedFiles("List", "AbstractList");
|
||||
|
||||
|
||||
if(keyType.isObject()) addBlockedFiles("ListFillBufferTester");
|
||||
if(keyType == ClassType.BOOLEAN) addBlockedFiles("ListFillBufferTester", "ListReplaceAllTester");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected void loadRemappers()
|
||||
{
|
||||
//Main Classes
|
||||
addRemapper("AbstractList", "Abstract%sList");
|
||||
addRemapper("ImmutableList", "Immutable%sList");
|
||||
addRemapper("CopyOnWriteList", "CopyOnWrite%sArrayList");
|
||||
|
||||
//Test Classes
|
||||
addRemapper("AbstractListTester", "Abstract%sListTester");
|
||||
addRemapper("AbstractListIndexOfTester", "Abstract%sListIndexOfTester");
|
||||
addRemapper("TestListGenerator", "Test%sListGenerator");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadFunctions()
|
||||
{
|
||||
addFunctionMapper("GET_KEY", "get");
|
||||
addFunctionMapper("GET_FIRST_KEY", "getFirst");
|
||||
addFunctionMapper("GET_LAST_KEY", "getLast");
|
||||
addFunctionMapper("REMOVE_FIRST_KEY", "removeFirst");
|
||||
addFunctionMapper("REMOVE_LAST_KEY", "removeLast");
|
||||
addFunctionMapper("REMOVE_SWAP", "swapRemove");
|
||||
addFunctionMappers("REPLACE", keyType.isObject() ? "replaceObjects" : "replace%ss");
|
||||
addFunctionMappers("SORT", "sort%ss");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadClasses()
|
||||
{
|
||||
//Implementation Classes
|
||||
addClassMapper("ARRAY_LIST", "ArrayList");
|
||||
addAbstractMapper("COPY_ON_WRITE_LIST", "CopyOnWrite%sArrayList");
|
||||
addClassMapper("LINKED_LIST", "LinkedList");
|
||||
addAbstractMapper("IMMUTABLE_LIST", "Immutable%sList");
|
||||
|
||||
//Abstract Classes
|
||||
addAbstractMapper("ABSTRACT_LIST", "Abstract%sList");
|
||||
|
||||
//SubClasses
|
||||
addClassMapper("SUB_LIST", "SubList");
|
||||
addClassMapper("LIST_ITER", "ListIter");
|
||||
|
||||
//Helper Classes
|
||||
addClassMapper("LISTS", "Lists");
|
||||
|
||||
//Interfaces
|
||||
addClassMapper("LIST", "List");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadTestClasses()
|
||||
{
|
||||
//Implementation Classes
|
||||
addClassMapper("LIST_TEST_BUILDER", "ListTestSuiteBuilder");
|
||||
addClassMapper("LIST_TESTS", "ListTests");
|
||||
|
||||
//Abstract Classes
|
||||
addAbstractMapper("ABSTRACT_LIST_INDEX_OF_TESTER", "Abstract%sListIndexOfTester");
|
||||
addAbstractMapper("ABSTRACT_LIST_TESTER", "Abstract%sListTester");
|
||||
|
||||
//Helper classes
|
||||
addAbstractMapper("TEST_LIST_GENERATOR", "Test%sListGenerator");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,308 @@
|
||||
package speiger.src.builder.modules;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import speiger.src.builder.ClassType;
|
||||
import speiger.src.builder.dependencies.FunctionDependency;
|
||||
import speiger.src.builder.dependencies.IDependency;
|
||||
import speiger.src.builder.dependencies.ModuleDependency;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public class MapModule extends BaseModule
|
||||
{
|
||||
public static final BaseModule INSTANCE = new MapModule();
|
||||
public static final ModuleDependency MODULE = new ModuleDependency(INSTANCE, true)
|
||||
.addKeyDependency(SetModule.MODULE)
|
||||
.addValueDependency(CollectionModule.MODULE)
|
||||
.addEntryDependency(SetModule.MODULE)
|
||||
.addTypeDependency(SetModule.MODULE, ClassType.OBJECT);
|
||||
public static final FunctionDependency IMPLEMENTATION = MODULE.createDependency("Implementations");
|
||||
public static final FunctionDependency WRAPPERS = MODULE.createDependency("Wrappers").addKeyDependency(SetModule.WRAPPERS).addOptionalTypeDependency(SetModule.WRAPPERS, ClassType.OBJECT, true);
|
||||
|
||||
public static final FunctionDependency ORDERED_MAP = MODULE.createDependency("OrderedMap").addKeyDependency(SetModule.ORDERED_SET).addOptionalTypeDependency(SetModule.ORDERED_SET, ClassType.OBJECT, true);
|
||||
public static final FunctionDependency SORTED_MAP = MODULE.createDependency("SortedMap").addKeyDependency(SetModule.SORTED_SET).addOptionalTypeDependency(SetModule.SORTED_SET, ClassType.OBJECT, true);
|
||||
|
||||
public static final FunctionDependency ARRAY_MAP = MODULE.createDependency("ArrayMap").addEntryDependency(ORDERED_MAP).addEntryDependency(IMPLEMENTATION);
|
||||
public static final FunctionDependency IMMUTABLE_MAP = MODULE.createDependency("ImmutableMap").addEntryDependency(IMPLEMENTATION);
|
||||
|
||||
public static final FunctionDependency HASH_MAP = MODULE.createDependency("HashMap").addEntryDependency(IMPLEMENTATION);
|
||||
public static final FunctionDependency LINKED_MAP = MODULE.createDependency("LinkedHashMap").addEntryDependency(HASH_MAP).addEntryDependency(ORDERED_MAP);
|
||||
|
||||
public static final FunctionDependency CUSTOM_MAP = MODULE.createDependency("CustomHashMap").addEntryDependency(IMPLEMENTATION).addKeyDependency(CollectionModule.STRATEGY);
|
||||
public static final FunctionDependency LINKED_CUSTOM_MAP = MODULE.createDependency("LinkedCustomHashMap").addEntryDependency(CUSTOM_MAP).addEntryDependency(ORDERED_MAP);
|
||||
|
||||
public static final FunctionDependency ENUM_MAP = MODULE.createDependency("EnumMap").addEntryDependency(IMPLEMENTATION);
|
||||
public static final FunctionDependency LINKED_ENUM_MAP = MODULE.createDependency("LinkedEnumMap").addEntryDependency(ENUM_MAP).addEntryDependency(ORDERED_MAP);
|
||||
|
||||
public static final FunctionDependency REF_MAP = MODULE.createDependency("ReferenceHashMap").addEntryDependency(IMPLEMENTATION);
|
||||
public static final FunctionDependency LINKED_REF_MAP = MODULE.createDependency("LinkedReferenceMap").addEntryDependency(REF_MAP).addEntryDependency(ORDERED_MAP);
|
||||
|
||||
|
||||
public static final FunctionDependency CONCURRENT_MAP = MODULE.createDependency("ConcurrentMap").addEntryDependency(IMPLEMENTATION);
|
||||
public static final FunctionDependency AVL_TREE_MAP = MODULE.createDependency("AVLTreeMap").addEntryDependency(SORTED_MAP).addEntryDependency(IMPLEMENTATION);
|
||||
public static final FunctionDependency RB_TREE_MAP = MODULE.createDependency("RBTreeMap").addEntryDependency(SORTED_MAP).addEntryDependency(IMPLEMENTATION);
|
||||
|
||||
@Override
|
||||
public String getModuleName() { return "Map"; }
|
||||
@Override
|
||||
public boolean isBiModule() { return true; }
|
||||
@Override
|
||||
protected void loadVariables() {}
|
||||
@Override
|
||||
public boolean isModuleValid(ClassType keyType, ClassType valueType) { return keyType != ClassType.BOOLEAN; }
|
||||
@Override
|
||||
public List<IDependency> getDependencies(ClassType keyType, ClassType valueType) {
|
||||
List<IDependency> dependencies = new ArrayList<>(Arrays.asList(MODULE, ORDERED_MAP, SORTED_MAP, IMPLEMENTATION, WRAPPERS, ARRAY_MAP, IMMUTABLE_MAP, HASH_MAP, LINKED_MAP, CUSTOM_MAP, LINKED_CUSTOM_MAP, CONCURRENT_MAP, AVL_TREE_MAP, RB_TREE_MAP));
|
||||
if(keyType == ClassType.OBJECT) dependencies.addAll(Arrays.asList(ENUM_MAP, LINKED_ENUM_MAP, REF_MAP, LINKED_REF_MAP));
|
||||
return dependencies;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadFlags()
|
||||
{
|
||||
if(MODULE.isEnabled()) addFlag("MAP_MODULE");
|
||||
if(WRAPPERS.isEnabled()) addFlag("MAPS_FEATURE");
|
||||
if(ORDERED_MAP.isEnabled()) addFlag("ORDERED_MAP_FEATURE");
|
||||
if(ARRAY_MAP.isEnabled()) addFlag("ARRAY_MAP_FEATURE");
|
||||
if(LINKED_MAP.isEnabled()) addFlag("LINKED_MAP_FEATURE");
|
||||
if(LINKED_CUSTOM_MAP.isEnabled()) addFlag("LINKED_CUSTOM_MAP_FEATURE");
|
||||
if(LINKED_ENUM_MAP.isEnabled()) addFlag("LINKED_ENUM_MAP_FEATURE");
|
||||
|
||||
if(SORTED_MAP.isEnabled()) addFlag("SORTED_MAP_FEATURE");
|
||||
if(AVL_TREE_MAP.isEnabled()) addFlag("AVL_TREE_MAP_FEATURE");
|
||||
if(RB_TREE_MAP.isEnabled()) addFlag("RB_TREE_MAP_FEATURE");
|
||||
|
||||
if(REF_MAP.isEnabled()) addFlag("REF_MAP_FEATURE");
|
||||
if(LINKED_REF_MAP.isEnabled()) addFlag("LINKED_REF_MAP_FEATURE");
|
||||
|
||||
|
||||
if(CONCURRENT_MAP.isEnabled()) addFlag("CONCURRENT_MAP_FEATURE");
|
||||
if(IMMUTABLE_MAP.isEnabled()) addFlag("IMMUTABLE_MAP_FEATURE");
|
||||
if(HASH_MAP.isEnabled()) addFlag("MAP_FEATURE");
|
||||
if(CUSTOM_MAP.isEnabled()) addFlag("CUSTOM_MAP_FEATURE");
|
||||
if(ENUM_MAP.isEnabled()) addFlag("ENUM_MAP_FEATURE");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadBlockades()
|
||||
{
|
||||
if(!MODULE.isEnabled()) addBlockedFiles("Map", "AbstractMap");
|
||||
if(!WRAPPERS.isEnabled()) addBlockedFiles("Maps");
|
||||
if(!IMMUTABLE_MAP.isEnabled()) addBlockedFiles("ImmutableOpenHashMap");
|
||||
if(!CONCURRENT_MAP.isEnabled()) addBlockedFiles("ConcurrentMap", "ConcurrentOpenHashMap");
|
||||
if(!ORDERED_MAP.isEnabled()) addBlockedFiles("OrderedMap");
|
||||
if(!REF_MAP.isEnabled()) addBlockedFiles("ReferenceHashMap");
|
||||
if(!LINKED_REF_MAP.isEnabled()) addBlockedFiles("LinkedReferenceHashMap");
|
||||
if(!HASH_MAP.isEnabled()) addBlockedFiles("OpenHashMap");
|
||||
if(!LINKED_MAP.isEnabled()) addBlockedFiles("LinkedOpenHashMap");
|
||||
if(!CUSTOM_MAP.isEnabled()) addBlockedFiles("OpenCustomHashMap");
|
||||
if(!LINKED_CUSTOM_MAP.isEnabled()) addBlockedFiles("LinkedOpenCustomHashMap");
|
||||
if(!ENUM_MAP.isEnabled()) addBlockedFiles("EnumMap");
|
||||
if(!LINKED_ENUM_MAP.isEnabled()) addBlockedFiles("LinkedEnumMap");
|
||||
if(!ARRAY_MAP.isEnabled()) addBlockedFiles("ArrayMap");
|
||||
if(!SORTED_MAP.isEnabled()) addBlockedFiles("SortedMap", "NavigableMap");
|
||||
if(!AVL_TREE_MAP.isEnabled()) addBlockedFiles("AVLTreeMap");
|
||||
if(!RB_TREE_MAP.isEnabled()) addBlockedFiles("RBTreeMap");
|
||||
|
||||
if(keyType == ClassType.BOOLEAN)
|
||||
{
|
||||
//Main Classes
|
||||
addBlockedFiles("SortedMap", "NavigableMap", "RBTreeMap", "AVLTreeMap");
|
||||
addBlockedFiles("OrderedMap", "ArrayMap", "LinkedOpenHashMap", "LinkedOpenCustomHashMap");
|
||||
addBlockedFiles("ConcurrentMap", "ConcurrentOpenHashMap");
|
||||
addBlockedFiles("Map", "Maps", "AbstractMap", "ImmutableOpenHashMap", "OpenHashMap", "OpenCustomHashMap");
|
||||
|
||||
//Test Classes
|
||||
addBlockedFiles("TestMap", "MapTests", "MapTestSuiteBuilder", "MapConstructorTests", "TestMapGenerator", "SimpleMapTestGenerator", "DerivedMapGenerators", "AbstractMapTester");
|
||||
addBlockedFiles("TestSortedMapGenerator", "OrderedMapTestSuiteBuilder", "NavigableMapTestSuiteBuilder", "SortedMapTestSuiteBuilder");
|
||||
addBlockedFiles("TestOrderedMapGenerator");
|
||||
addBlockedFilter(T -> T.endsWith("Tester") && (T.startsWith("Map") || T.startsWith("OrderedMap") || T.startsWith("SortedMap") || T.startsWith("NavigableMap")));
|
||||
}
|
||||
if(valueType == ClassType.OBJECT) {
|
||||
addBlockedFiles("MapComputeIfAbsentNonDefaultTester", "MapComputeIfPresentNonDefaultTester", "MapComputeNonDefaultTester", "MapSupplyIfAbsentNonDefaultTester");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadRemappers()
|
||||
{
|
||||
//Main Classes
|
||||
addBiRequirement("Map");
|
||||
addBiRequirement("SortedMap");
|
||||
addBiRequirement("OrderedMap");
|
||||
addBiRequirement("NavigableMap");
|
||||
addBiRequirement("ConcurrentMap");
|
||||
addBiRequirement("AbstractMap");
|
||||
addEnumRequirement("EnumMap");
|
||||
addEnumRequirement("LinkedEnumMap");
|
||||
addEnumRequirement("ReferenceHashMap");
|
||||
addEnumRequirement("LinkedReferenceHashMap");
|
||||
addBiRequirement("ConcurrentOpenHashMap");
|
||||
addBiRequirement("ImmutableOpenHashMap");
|
||||
addBiRequirement("OpenHashMap");
|
||||
addBiRequirement("LinkedOpenHashMap");
|
||||
addBiRequirement("OpenCustomHashMap");
|
||||
addBiRequirement("LinkedOpenCustomHashMap");
|
||||
addBiRequirement("ArrayMap");
|
||||
addBiRequirement("RBTreeMap");
|
||||
addBiRequirement("AVLTreeMap");
|
||||
addBiRequirement("Maps");
|
||||
|
||||
addRemapper("AbstractMap", "Abstract%sMap");
|
||||
addRemapper("EnumMap", "Enum2%sMap");
|
||||
addRemapper("LinkedEnumMap", "LinkedEnum2%sMap");
|
||||
addRemapper("ReferenceHashMap", "Reference2%sHashMap");
|
||||
addRemapper("LinkedReferenceHashMap", "Reference2%sLinkedHashMap");
|
||||
addRemapper("ImmutableOpenHashMap", "Immutable%sOpenHashMap");
|
||||
|
||||
//Test Classes
|
||||
addBiRequirement("TestMapGenerator");
|
||||
addBiRequirement("TestSortedMapGenerator");
|
||||
addBiRequirement("TestOrderedMapGenerator");
|
||||
addBiRequirement("SimpleMapTestGenerator");
|
||||
addBiRequirement("DerivedMapGenerators");
|
||||
addBiRequirement("AbstractMapTester");
|
||||
addBiRequirement("MapTestSuiteBuilder");
|
||||
addBiRequirement("SortedMapTestSuiteBuilder");
|
||||
addBiRequirement("NavigableMapTestSuiteBuilder");
|
||||
addBiRequirement("OrderedMapTestSuiteBuilder");
|
||||
addBiRequirement("MapTests");
|
||||
addBiRequirement("MapConstructorTests");
|
||||
addBiRequirement("TestMap");
|
||||
addBiRequirement("MapAddToTester");
|
||||
addBiRequirement("MapSubFromTester");
|
||||
addBiRequirement("MapClearTester");
|
||||
addBiRequirement("MapComputeIfAbsentTester");
|
||||
addBiRequirement("MapComputeIfPresentTester");
|
||||
addBiRequirement("MapComputeTester");
|
||||
addBiRequirement("MapComputeIfAbsentNonDefaultTester");
|
||||
addBiRequirement("MapComputeIfPresentNonDefaultTester");
|
||||
addBiRequirement("MapComputeNonDefaultTester");
|
||||
addBiRequirement("MapCopyTester");
|
||||
addBiRequirement("MapContainsTester");
|
||||
addBiRequirement("MapContainsKeyTester");
|
||||
addBiRequirement("MapContainsValueTester");
|
||||
addBiRequirement("MapCreatorTester");
|
||||
addBiRequirement("MapEntrySetTester");
|
||||
addBiRequirement("MapEqualsTester");
|
||||
addBiRequirement("MapForEachTester");
|
||||
addBiRequirement("MapGetOrDefaultTester");
|
||||
addBiRequirement("MapGetTester");
|
||||
addBiRequirement("MapHashCodeTester");
|
||||
addBiRequirement("MapIsEmptyTester");
|
||||
addBiRequirement("MapMergeTester");
|
||||
addBiRequirement("MapMergeBulkTester");
|
||||
addBiRequirement("MapPutAllArrayTester");
|
||||
addBiRequirement("MapPutAllTester");
|
||||
addBiRequirement("MapPutIfAbsentTester");
|
||||
addBiRequirement("MapPutTester");
|
||||
addBiRequirement("MapRemoveEntryTester");
|
||||
addBiRequirement("MapRemoveOrDefaultTester");
|
||||
addBiRequirement("MapRemoveTester");
|
||||
addBiRequirement("MapReplaceAllTester");
|
||||
addBiRequirement("MapReplaceEntryTester");
|
||||
addBiRequirement("MapReplaceTester");
|
||||
addBiRequirement("MapSizeTester");
|
||||
addBiRequirement("MapSupplyIfAbsentTester");
|
||||
addBiRequirement("MapSupplyIfAbsentNonDefaultTester");
|
||||
addBiRequirement("MapToStringTester");
|
||||
addBiRequirement("NavigableMapNavigationTester");
|
||||
addBiRequirement("SortedMapNavigationTester");
|
||||
addBiRequirement("OrderedMapNavigationTester");
|
||||
addBiRequirement("OrderedMapMoveTester");
|
||||
addBiRequirement("OrderedMapPutTester");
|
||||
addBiRequirement("MapConstructorTester");
|
||||
|
||||
addRemapper("TestMapGenerator", "Test%sMapGenerator");
|
||||
addRemapper("TestSortedMapGenerator", "Test%sSortedMapGenerator");
|
||||
addRemapper("TestOrderedMapGenerator", "Test%sOrderedMapGenerator");
|
||||
addRemapper("SimpleMapTestGenerator", "Simple%sMapTestGenerator");
|
||||
addRemapper("DerivedMapGenerators", "Derived%sMapGenerators");
|
||||
addRemapper("AbstractMapTester", "Abstract%sMapTester");
|
||||
addRemapper("TestMap", "Test%sMap");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadFunctions()
|
||||
{
|
||||
addFunctionValueMapper("BULK_MERGE", "mergeAll");
|
||||
addFunctionValueMappers("COMPUTE_IF_ABSENT", "compute%sIfAbsent");
|
||||
addFunctionValueMappers("COMPUTE_IF_PRESENT", "compute%sIfPresent");
|
||||
addFunctionValueMapper("COMPUTE", "compute");
|
||||
addFunctionMapper("DEQUEUE_LAST", "dequeueLast");
|
||||
addFunctionMapper("DEQUEUE", "dequeue");
|
||||
addSimpleMapper("ENTRY_SET", keyType.getFileType().toLowerCase()+"2"+valueType.getFileType()+"EntrySet");
|
||||
addFunctionMappers("FIRST_ENTRY_KEY", "first%sKey");
|
||||
addFunctionValueMappers("FIRST_ENTRY_VALUE", "first%sValue");
|
||||
if(keyType.isObject()) addFunctionValueMapper("GET_VALUE", valueType.isObject() ? "getObject" : "get");
|
||||
else addSimpleMapper("GET_VALUE", "get");
|
||||
addFunctionMappers("LAST_ENTRY_KEY", "last%sKey");
|
||||
addFunctionValueMappers("LAST_ENTRY_VALUE", "last%sValue");
|
||||
addFunctionValueMapper("MERGE", "merge");
|
||||
addFunctionMappers("POLL_FIRST_ENTRY_KEY", "pollFirst%sKey");
|
||||
addFunctionMappers("POLL_LAST_ENTRY_KEY", "pollLast%sKey");
|
||||
if(keyType.isObject()) addFunctionMapper("REMOVE_VALUE", "rem");
|
||||
else addSimpleMapper("REMOVE_VALUE", "remove");
|
||||
addFunctionMapper("REMOVE", "remove");
|
||||
addFunctionValueMappers("REPLACE_VALUES", valueType.isObject() ? "replaceObjects" : "replace%ss");
|
||||
addFunctionValueMappers("SUPPLY_IF_ABSENT", "supply%sIfAbsent");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadClasses()
|
||||
{
|
||||
//Implementation Classes
|
||||
addAbstractBiMapper("IMMUTABLE_HASH_MAP", "Immutable%sOpenHashMap", "2");
|
||||
addBiClassMapper("LINKED_CUSTOM_HASH_MAP", "LinkedOpenCustomHashMap", "2");
|
||||
addBiClassMapper("LINKED_HASH_MAP", "LinkedOpenHashMap", "2");
|
||||
addBiClassMapper("CUSTOM_HASH_MAP", "OpenCustomHashMap", "2");
|
||||
addBiClassMapper("CONCURRENT_HASH_MAP", "ConcurrentOpenHashMap", "2");
|
||||
addBiClassMapper("AVL_TREE_MAP", "AVLTreeMap", "2");
|
||||
addBiClassMapper("RB_TREE_MAP", "RBTreeMap", "2");
|
||||
addFunctionValueMappers("LINKED_ENUM_MAP", valueType.isObject() ? "LinkedEnum2ObjectMap" : "LinkedEnum2%sMap");
|
||||
addFunctionValueMappers("ENUM_MAP", valueType.isObject() ? "Enum2ObjectMap" : "Enum2%sMap");
|
||||
addFunctionValueMappers("REF_MAP", valueType.isObject() ? "Reference2ObjectHashMap" : "Reference2%sHashMap");
|
||||
addFunctionValueMappers("LINKED_REF_MAP", valueType.isObject() ? "Reference2ObjectLinkedHashMap" : "Reference2%sLinkedHashMap");
|
||||
addBiClassMapper("HASH_MAP", "OpenHashMap", "2");
|
||||
addBiClassMapper("ARRAY_MAP", "ArrayMap", "2");
|
||||
|
||||
//Abstract Classes
|
||||
addAbstractBiMapper("ABSTRACT_MAP", "Abstract%sMap", "2");
|
||||
addAbstractBiMapper("REVERSED_ORDERED_MAP", "Reversed%sOrderedMap", "2");
|
||||
|
||||
//Helper Classes
|
||||
addBiClassMapper("MAPS", "Maps", "2");
|
||||
|
||||
//Interfaces
|
||||
addBiClassMapper("NAVIGABLE_MAP", "NavigableMap", "2");
|
||||
addBiClassMapper("ORDERED_MAP", "OrderedMap", "2");
|
||||
addBiClassMapper("SORTED_MAP", "SortedMap", "2");
|
||||
addBiClassMapper("CONCURRENT_MAP", "ConcurrentMap", "2");
|
||||
addBiClassMapper("MAP", "Map", "2");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadTestClasses()
|
||||
{
|
||||
//Implementation Classes
|
||||
addAbstractBiMapper("SIMPLE_TEST_MAP", "Test%sMap", "2");
|
||||
addBiClassMapper("MAP_TESTS", "MapTests", "2");
|
||||
addAbstractBiMapper("NAVIGABLE_MAP_TEST_BUILDER", "%sNavigableMapTestSuiteBuilder", "2");
|
||||
addAbstractBiMapper("SORTED_MAP_TEST_BUILDER", "%sSortedMapTestSuiteBuilder", "2");
|
||||
addAbstractBiMapper("ORDERED_MAP_TEST_BUILDER", "%sOrderedMapTestSuiteBuilder", "2");
|
||||
addAbstractBiMapper("MAP_TEST_BUILDER", "%sMapTestSuiteBuilder", "2");
|
||||
|
||||
//Abstract Classes
|
||||
addAbstractBiMapper("ABSTRACT_MAP_TESTER", "Abstract%sMapTester", "2");
|
||||
|
||||
//Helper Classes
|
||||
addAbstractBiMapper("MAP_CONSTRUCTOR_TESTS", "%sMapConstructorTests", "2");
|
||||
addAbstractBiMapper("SIMPLE_MAP_TEST_GENERATOR", "Simple%sMapTestGenerator", "2");
|
||||
addAbstractBiMapper("DERIVED_MAP_GENERATORS", "Derived%sMapGenerators", "2");
|
||||
addAbstractBiMapper("TEST_ORDERED_MAP_GENERATOR", "Test%sOrderedMapGenerator", "2");
|
||||
addAbstractBiMapper("TEST_SORTED_MAP_GENERATOR", "Test%sSortedMapGenerator", "2");
|
||||
addAbstractBiMapper("TEST_MAP_GENERATOR", "Test%sMapGenerator", "2");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package speiger.src.builder.modules;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import speiger.src.builder.ClassType;
|
||||
import speiger.src.builder.dependencies.FunctionDependency;
|
||||
import speiger.src.builder.dependencies.IDependency;
|
||||
import speiger.src.builder.dependencies.ModuleDependency;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public class PairModule extends BaseModule
|
||||
{
|
||||
public static final BaseModule INSTANCE = new PairModule();
|
||||
public static final ModuleDependency MODULE = new ModuleDependency(INSTANCE, true).addKeyDependency(JavaModule.MODULE);
|
||||
public static final FunctionDependency IMMUTABLE = MODULE.createDependency("Immutable");
|
||||
public static final FunctionDependency MUTABLE = MODULE.createDependency("Mutable");
|
||||
|
||||
|
||||
// public static final DependencyModule MODULE = new BiTypeModule(INSTANCE);
|
||||
// public static final DependencyFunction IMMUTABLE = MODULE.createFunction("Immutable");
|
||||
// public static final DependencyFunction MUTABLE = MODULE.createFunction("Mutable");
|
||||
|
||||
@Override
|
||||
public String getModuleName() { return "Pair"; }
|
||||
@Override
|
||||
public boolean isBiModule() { return true; }
|
||||
@Override
|
||||
protected void loadVariables() {}
|
||||
@Override
|
||||
protected void loadFunctions() {}
|
||||
@Override
|
||||
protected void loadTestClasses() {}
|
||||
@Override
|
||||
public List<IDependency> getDependencies(ClassType keyType, ClassType valueType) { return Arrays.asList(MODULE, IMMUTABLE, MUTABLE); }
|
||||
|
||||
@Override
|
||||
protected void loadFlags() {
|
||||
if(MODULE.isEnabled()) addFlag("PAIR_MODULE");
|
||||
if(MUTABLE.isEnabled()) addFlag("MUTABLE_PAIR");
|
||||
if(IMMUTABLE.isEnabled()) addFlag("IMMUTABLE_PAIR");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadBlockades() {
|
||||
if(!MODULE.isEnabled()) addBlockedFiles("Pair");
|
||||
if(!MUTABLE.isEnabled()) addBlockedFiles("MutablePair");
|
||||
if(!IMMUTABLE.isEnabled()) addBlockedFiles("ImmutablePair");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadRemappers() {
|
||||
//Main Classes
|
||||
addBiRequirement("Pair", "");
|
||||
addBiRequirement("MutablePair", "");
|
||||
addBiRequirement("ImmutablePair", "");
|
||||
|
||||
//Test Classes
|
||||
addBiRequirement("PairTester", "");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadClasses() {
|
||||
//Implementations
|
||||
addBiClassMapper("IMMUTABLE_PAIR", "ImmutablePair", "");
|
||||
addBiClassMapper("MUTABLE_PAIR", "MutablePair", "");
|
||||
|
||||
//Interfaces
|
||||
addBiClassMapper("PAIR", "Pair", "");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
package speiger.src.builder.modules;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import speiger.src.builder.ClassType;
|
||||
import speiger.src.builder.dependencies.FunctionDependency;
|
||||
import speiger.src.builder.dependencies.IDependency;
|
||||
import speiger.src.builder.dependencies.ModuleDependency;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public class PrioQueueModule extends BaseModule
|
||||
{
|
||||
public static final BaseModule INSTANCE = new PrioQueueModule();
|
||||
public static final ModuleDependency MODULE = new ModuleDependency(INSTANCE, false).addKeyDependency(CollectionModule.MODULE);
|
||||
public static final FunctionDependency IMPLEMENTATION = MODULE.createDependency("Implementations");
|
||||
public static final FunctionDependency WRAPPERS = MODULE.createDependency("Wrappers");
|
||||
public static final FunctionDependency DEQUEUE = MODULE.createDependency("Dequeue");
|
||||
|
||||
public static final FunctionDependency FIFO_QUEUE = MODULE.createDependency("FiFoQueue").addKeyDependency(DEQUEUE).addKeyDependency(IMPLEMENTATION);
|
||||
public static final FunctionDependency HEAP_QUEUE = MODULE.createDependency("HeapQueue").addKeyDependency(IMPLEMENTATION);
|
||||
public static final FunctionDependency ARRAY_PRIO_QUEUE = MODULE.createDependency("ArrayPrioQueue").addKeyDependency(IMPLEMENTATION);
|
||||
|
||||
|
||||
@Override
|
||||
public String getModuleName() { return "PriorityQueue"; }
|
||||
@Override
|
||||
protected void loadVariables() {}
|
||||
@Override
|
||||
protected void loadFunctions() {}
|
||||
@Override
|
||||
public List<IDependency> getDependencies(ClassType keyType, ClassType valueType) { return Arrays.asList(MODULE, WRAPPERS, IMPLEMENTATION, DEQUEUE, FIFO_QUEUE, HEAP_QUEUE, ARRAY_PRIO_QUEUE); }
|
||||
|
||||
@Override
|
||||
protected void loadFlags() {
|
||||
if(MODULE.isEnabled()) addFlag("QUEUE_MODULE");
|
||||
if(WRAPPERS.isEnabled()) addKeyFlag("QUEUES_FEATURE");
|
||||
if(DEQUEUE.isEnabled()) addKeyFlag("DEQUEUE_FEATURE");
|
||||
if(FIFO_QUEUE.isEnabled()) addKeyFlag("FIFO_QUEUE_FEATURE");
|
||||
if(HEAP_QUEUE.isEnabled()) addKeyFlag("HEAP_QUEUE_FEATURE");
|
||||
if(ARRAY_PRIO_QUEUE.isEnabled()) addKeyFlag("ARRAY_QUEUE_FEATURE");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadBlockades() {
|
||||
if(!MODULE.isEnabled()) addBlockedFiles("PriorityQueue", "AbstractPriorityQueue");
|
||||
if(!WRAPPERS.isEnabled()) addBlockedFiles("PriorityQueues");
|
||||
if(!DEQUEUE.isEnabled()) addBlockedFiles("PriorityDequeue");
|
||||
if(!FIFO_QUEUE.isEnabled()) addBlockedFiles("ArrayFIFOQueue");
|
||||
if(!HEAP_QUEUE.isEnabled()) addBlockedFiles("HeapPriorityQueue");
|
||||
if(!ARRAY_PRIO_QUEUE.isEnabled()) addBlockedFiles("ArrayPriorityQueue");
|
||||
|
||||
if(keyType == ClassType.BOOLEAN) {
|
||||
addBlockedFiles("QueueTests");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadRemappers() {
|
||||
//Main Classes
|
||||
addRemapper("AbstractPriorityQueue", "Abstract%sPriorityQueue");
|
||||
|
||||
//Test Classes
|
||||
addRemapper("TestQueueGenerator", "Test%sQueueGenerator");
|
||||
addRemapper("AbstractQueueTester", "Abstract%sQueueTester");
|
||||
addRemapper("SimpleQueueTestGenerator", "Simple%sQueueTestGenerator");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadClasses() {
|
||||
//Implementation Classes
|
||||
addClassMapper("ARRAY_FIFO_QUEUE", "ArrayFIFOQueue");
|
||||
addClassMapper("ARRAY_PRIORITY_QUEUE", "ArrayPriorityQueue");
|
||||
addClassMapper("HEAP_PRIORITY_QUEUE", "HeapPriorityQueue");
|
||||
|
||||
//Abstract Classes
|
||||
addAbstractMapper("ABSTRACT_PRIORITY_QUEUE", "Abstract%sPriorityQueue");
|
||||
|
||||
//Helper Classes
|
||||
addClassMapper("PRIORITY_QUEUES", "PriorityQueues");
|
||||
|
||||
//Interfaces
|
||||
addClassMapper("PRIORITY_QUEUE", "PriorityQueue");
|
||||
addClassMapper("PRIORITY_DEQUEUE", "PriorityDequeue");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadTestClasses()
|
||||
{
|
||||
//Implementation Classes
|
||||
addClassMapper("DEQUEUE_TEST_BUILDER", "DequeueTestSuiteBuilder");
|
||||
addClassMapper("QUEUE_TEST_BUILDER", "QueueTestSuiteBuilder");
|
||||
addClassMapper("QUEUE_TESTS", "QueueTests");
|
||||
|
||||
//Abstract Classes
|
||||
addAbstractMapper("ABSTRACT_QUEUE_TESTER", "Abstract%sQueueTester");
|
||||
|
||||
//Helper Classes
|
||||
addAbstractMapper("SIMPLE_QUEUE_TEST_GENERATOR", "Simple%sQueueTestGenerator");
|
||||
addAbstractMapper("TEST_QUEUE_GENERATOR", "Test%sQueueGenerator");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
package speiger.src.builder.modules;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import speiger.src.builder.ClassType;
|
||||
import speiger.src.builder.dependencies.FunctionDependency;
|
||||
import speiger.src.builder.dependencies.IDependency;
|
||||
import speiger.src.builder.dependencies.ModuleDependency;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public class SetModule extends BaseModule
|
||||
{
|
||||
public static final BaseModule INSTANCE = new SetModule();
|
||||
public static final ModuleDependency MODULE = new ModuleDependency(INSTANCE, false).addKeyDependency(CollectionModule.MODULE).addKeyDependency(CollectionModule.SPLIT_ITERATORS);
|
||||
public static final FunctionDependency IMPLEMENTATION = MODULE.createDependency("Implementations");
|
||||
public static final FunctionDependency WRAPPERS = MODULE.createDependency("Wrappers");
|
||||
public static final FunctionDependency ORDERED_SET = MODULE.createDependency("OrderedSet");
|
||||
public static final FunctionDependency SORTED_SET = MODULE.createDependency("SortedSet");
|
||||
public static final FunctionDependency ARRAY_SET = MODULE.createDependency("ArraySet").addKeyDependency(ORDERED_SET).addKeyDependency(IMPLEMENTATION);
|
||||
public static final FunctionDependency IMMUTABLE_SET = MODULE.createDependency("ImmutableSet").addKeyDependency(ORDERED_SET).addKeyDependency(IMPLEMENTATION);
|
||||
public static final FunctionDependency HASH_SET = MODULE.createDependency("HashSet").addKeyDependency(IMPLEMENTATION);
|
||||
public static final FunctionDependency LINKED_SET = MODULE.createDependency("LinkedHashSet").addKeyDependency(ORDERED_SET).addKeyDependency(HASH_SET);
|
||||
public static final FunctionDependency CUSTOM_SET = MODULE.createDependency("CustomHashSet").addKeyDependency(IMPLEMENTATION).addKeyDependency(CollectionModule.STRATEGY);
|
||||
public static final FunctionDependency LINKED_CUSTOM_SET = MODULE.createDependency("LinkedCustomHashSet").addKeyDependency(ORDERED_SET).addKeyDependency(CUSTOM_SET);
|
||||
public static final FunctionDependency AVL_TREE_SET = MODULE.createDependency("AVLTreeSet").addKeyDependency(SORTED_SET).addKeyDependency(IMPLEMENTATION);
|
||||
public static final FunctionDependency RB_TREE_SET = MODULE.createDependency("RBTreeSet").addKeyDependency(SORTED_SET).addKeyDependency(IMPLEMENTATION);
|
||||
|
||||
@Override
|
||||
public String getModuleName() { return "Set"; }
|
||||
@Override
|
||||
protected void loadVariables() {}
|
||||
|
||||
@Override
|
||||
public boolean isModuleValid(ClassType keyType, ClassType valueType) { return keyType != ClassType.BOOLEAN; }
|
||||
@Override
|
||||
public List<IDependency> getDependencies(ClassType keyType, ClassType valueType) { return Arrays.asList(MODULE, WRAPPERS, ORDERED_SET, SORTED_SET, IMPLEMENTATION, ARRAY_SET, IMMUTABLE_SET, HASH_SET, LINKED_SET, CUSTOM_SET, LINKED_CUSTOM_SET, AVL_TREE_SET, RB_TREE_SET); }
|
||||
|
||||
@Override
|
||||
protected void loadFlags()
|
||||
{
|
||||
if(MODULE.isEnabled()) addFlag("SET_MODULE");
|
||||
if(WRAPPERS.isEnabled()) addFlag("SETS_FEATURE");
|
||||
if(ORDERED_SET.isEnabled()) addFlag("ORDERED_SET_FEATURE");
|
||||
if(SORTED_SET.isEnabled()) addFlag("SORTED_SET_FEATURE");
|
||||
if(IMMUTABLE_SET.isEnabled()) addFlag("IMMUTABLE_SET_FEATURE");
|
||||
if(ARRAY_SET.isEnabled()) addFlag("ARRAY_SET_FEATURE");
|
||||
if(HASH_SET.isEnabled()) addFlag("HASH_SET_FEATURE");
|
||||
if(LINKED_SET.isEnabled()) addFlag("LINKED_SET_FEATURE");
|
||||
if(CUSTOM_SET.isEnabled()) addFlag("CUSTOM_HASH_SET_FEATURE");
|
||||
if(LINKED_CUSTOM_SET.isEnabled()) addFlag("LINKED_CUSTOM_SET_FEATURE");
|
||||
if(AVL_TREE_SET.isEnabled()) addFlag("AVL_TREE_SET_FEATURE");
|
||||
if(RB_TREE_SET.isEnabled()) addFlag("RB_TREE_SET_FEATURE");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadBlockades()
|
||||
{
|
||||
if(!MODULE.isEnabled()) addBlockedFiles("Set", "AbstractSet");
|
||||
if(!WRAPPERS.isEnabled()) addBlockedFiles("Sets");
|
||||
if(!IMMUTABLE_SET.isEnabled()) addBlockedFiles("ImmutableOpenHashSet");
|
||||
if(!ORDERED_SET.isEnabled()) addBlockedFiles("OrderedSet");
|
||||
if(!HASH_SET.isEnabled()) addBlockedFiles("OpenHashSet");
|
||||
if(!LINKED_SET.isEnabled()) addBlockedFiles("LinkedOpenHashSet");
|
||||
if(!CUSTOM_SET.isEnabled()) addBlockedFiles("OpenCustomHashSet");
|
||||
if(!LINKED_CUSTOM_SET.isEnabled()) addBlockedFiles("LinkedOpenCustomHashSet");
|
||||
if(!ARRAY_SET.isEnabled()) addBlockedFiles("ArraySet");
|
||||
if(!SORTED_SET.isEnabled()) addBlockedFiles("SortedSet", "NavigableSet");
|
||||
if(!AVL_TREE_SET.isEnabled()) addBlockedFiles("AVLTreeSet");
|
||||
if(!RB_TREE_SET.isEnabled()) addBlockedFiles("RBTreeSet");
|
||||
|
||||
if(keyType == ClassType.BOOLEAN)
|
||||
{
|
||||
//Main Classes
|
||||
addBlockedFiles("SortedSet", "NavigableSet", "AVLTreeSet", "RBTreeSet");
|
||||
addBlockedFiles("OrderedSet", "ArraySet", "LinkedOpenHashSet", "LinkedOpenCustomHashSet");
|
||||
addBlockedFiles("Set", "Sets", "AbstractSet", "OpenHashSet", "OpenCustomHashSet", "ImmutableOpenHashSet");
|
||||
|
||||
//Test Classes
|
||||
addBlockedFiles("SetTests", "SetTestSuiteBuilder", "TestSetGenerator");
|
||||
addBlockedFiles("OrderedSetTestSuiteBuilder", "TestOrderedSetGenerator", "OrderedSetMoveTester", "OrderedSetNavigationTester", "OrderedSetIterationTester");
|
||||
addBlockedFiles("SortedSetTestSuiteBuilder", "TestSortedSetGenerator", "SortedSetNaviationTester", "SortedSetSubsetTestSetGenerator", "SortedSetIterationTester", "SortedSetNaviationTester");
|
||||
addBlockedFiles("NavigableSetTestSuiteBuilder", "TestNavigableSetGenerator", "NavigableSetNavigationTester");
|
||||
addBlockedFiles("MinimalSet", "AbstractSetTester", "SetAddAllTester", "SetAddTester", "SetCreationTester", "SetEqualsTester", "SetRemoveTester");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadRemappers()
|
||||
{
|
||||
//Main Classes
|
||||
addRemapper("AbstractSet", "Abstract%sSet");
|
||||
addRemapper("ImmutableOpenHashSet", "Immutable%sOpenHashSet");
|
||||
|
||||
//Test Classes
|
||||
addRemapper("MinimalSet", "Minimal%sSet");
|
||||
addRemapper("TestNavigableSetGenerator", "Test%sNavigableSetGenerator");
|
||||
addRemapper("TestSortedSetGenerator", "Test%sSortedSetGenerator");
|
||||
addRemapper("TestOrderedSetGenerator", "Test%sOrderedSetGenerator");
|
||||
addRemapper("TestSetGenerator", "Test%sSetGenerator");
|
||||
addRemapper("AbstractSetTester", "Abstract%sSetTester");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadFunctions()
|
||||
{
|
||||
addFunctionMapper("POLL_FIRST_KEY", "pollFirst");
|
||||
addFunctionMapper("POLL_LAST_KEY", "pollLast");
|
||||
addFunctionMapper("FIRST_KEY", "first");
|
||||
addFunctionMapper("LAST_KEY", "last");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadTestClasses()
|
||||
{
|
||||
//Implementation Classes
|
||||
addAbstractMapper("MINIMAL_SET", "Minimal%sSet");
|
||||
addClassMapper("ORDERED_SET_TEST_BUILDER", "OrderedSetTestSuiteBuilder");
|
||||
addClassMapper("SORTED_SET_TEST_BUILDER", "SortedSetTestSuiteBuilder");
|
||||
addClassMapper("NAVIGABLE_SET_TEST_BUILDER", "NavigableSetTestSuiteBuilder");
|
||||
addClassMapper("SET_TEST_BUILDER", "SetTestSuiteBuilder");
|
||||
addClassMapper("SET_TESTS", "SetTests");
|
||||
|
||||
//Abstract Classes
|
||||
addAbstractMapper("ABSTRACT_SET_TESTER", "Abstract%sSetTester");
|
||||
|
||||
//Helper Classes
|
||||
addClassMapper("SUB_SORTED_SET_CLASS_GENERATOR", "SortedSetSubsetTestSetGenerator");
|
||||
addClassMapper("SUB_NAVIGABLE_SET_CLASS_GENERATOR", "NavigableSetSubsetTestSetGenerator");
|
||||
addAbstractMapper("TEST_NAVIGABLE_SET_GENERATOR", "Test%sNavigableSetGenerator");
|
||||
addAbstractMapper("TEST_SORTED_SET_GENERATOR", "Test%sSortedSetGenerator");
|
||||
addAbstractMapper("TEST_ORDERED_SET_GENERATOR", "Test%sOrderedSetGenerator");
|
||||
addAbstractMapper("TEST_SET_GENERATOR", "Test%sSetGenerator");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadClasses()
|
||||
{
|
||||
//Implementation Classes
|
||||
addClassMapper("LINKED_CUSTOM_HASH_SET", "LinkedOpenCustomHashSet");
|
||||
addClassMapper("LINKED_HASH_SET", "LinkedOpenHashSet");
|
||||
addAbstractMapper("IMMUTABLE_HASH_SET", "Immutable%sOpenHashSet");
|
||||
addClassMapper("CUSTOM_HASH_SET", "OpenCustomHashSet");
|
||||
addClassMapper("HASH_SET", "OpenHashSet");
|
||||
addClassMapper("RB_TREE_SET", "RBTreeSet");
|
||||
addClassMapper("AVL_TREE_SET", "AVLTreeSet");
|
||||
addClassMapper("ARRAY_SET", "ArraySet");
|
||||
|
||||
//Abstract Classes
|
||||
addAbstractMapper("ABSTRACT_SET", "Abstract%sSet");
|
||||
addAbstractMapper("REVERSED_ORDERED_SET", "Reversed%sOrderedSet");
|
||||
|
||||
//Helper Classes
|
||||
addClassMapper("SETS", "Sets");
|
||||
|
||||
//Interfaces
|
||||
addClassMapper("NAVIGABLE_SET", "NavigableSet");
|
||||
addClassMapper("SORTED_SET", "SortedSet");
|
||||
addClassMapper("ORDERED_SET", "OrderedSet");
|
||||
addClassMapper("SET", "Set");
|
||||
}
|
||||
}
|
||||
+82
@@ -1,15 +1,22 @@
|
||||
package speiger.src.collections.PACKAGE.collections;
|
||||
|
||||
import java.util.Collection;
|
||||
#if ORDERED_MAP_FEATURE
|
||||
import java.util.function.Supplier;
|
||||
#endif
|
||||
import java.util.Objects;
|
||||
import java.util.AbstractCollection;
|
||||
#if TYPE_OBJECT
|
||||
import java.util.function.Consumer;
|
||||
#endif
|
||||
|
||||
#if ORDERED_MAP_FEATURE
|
||||
import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
|
||||
#endif
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
import speiger.src.collections.PACKAGE.utils.ITERATORS;
|
||||
import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
||||
#endif
|
||||
|
||||
/**
|
||||
@@ -245,6 +252,7 @@ public abstract class ABSTRACT_COLLECTION KEY_GENERIC_TYPE extends AbstractColle
|
||||
*/
|
||||
@Override
|
||||
public KEY_TYPE[] TO_ARRAY() {
|
||||
if(isEmpty()) return ARRAYS.EMPTY_ARRAY;
|
||||
return TO_ARRAY(new KEY_TYPE[size()]);
|
||||
}
|
||||
|
||||
@@ -260,5 +268,79 @@ public abstract class ABSTRACT_COLLECTION KEY_GENERIC_TYPE extends AbstractColle
|
||||
if (a.length > size()) a[size()] = EMPTY_KEY_VALUE;
|
||||
return a;
|
||||
}
|
||||
|
||||
#endif
|
||||
#if ORDERED_MAP_FEATURE
|
||||
public static class REVERSED_ORDERED_COLLECTION KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION KEY_GENERIC_TYPE implements ORDERED_COLLECTION KEY_GENERIC_TYPE {
|
||||
ORDERED_COLLECTION KEY_GENERIC_TYPE collection;
|
||||
Supplier<ITERATOR KEY_GENERIC_TYPE> reverseIterator;
|
||||
|
||||
public REVERSED_ORDERED_COLLECTION(ORDERED_COLLECTION KEY_GENERIC_TYPE collection, Supplier<ITERATOR KEY_GENERIC_TYPE> reverseIterator) {
|
||||
this.collection = collection;
|
||||
this.reverseIterator = reverseIterator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean add(KEY_TYPE o) { return collection.add(o); }
|
||||
@Override
|
||||
public ORDERED_COLLECTION KEY_GENERIC_TYPE reversed() { return collection; }
|
||||
@Override
|
||||
public void addFirst(KEY_TYPE e) { collection.addLast(e); }
|
||||
@Override
|
||||
public void addLast(KEY_TYPE e) { collection.addFirst(e); }
|
||||
@Override
|
||||
#if !TYPE_OBJECT
|
||||
public boolean contains(KEY_TYPE e) { return collection.contains(e); }
|
||||
#else
|
||||
public boolean contains(Object e) { return collection.contains(e); }
|
||||
#endif
|
||||
@Override
|
||||
#if !TYPE_OBJECT
|
||||
public boolean REMOVE_KEY(KEY_TYPE e) { return collection.REMOVE_KEY(e); }
|
||||
#else
|
||||
public boolean remove(Object e) { return collection.remove(e); }
|
||||
#endif
|
||||
@Override
|
||||
public void clear() { collection.clear(); }
|
||||
@Override
|
||||
public KEY_TYPE GET_FIRST_KEY() { return collection.GET_LAST_KEY(); }
|
||||
@Override
|
||||
public KEY_TYPE REMOVE_FIRST_KEY() { return collection.REMOVE_LAST_KEY(); }
|
||||
@Override
|
||||
public KEY_TYPE GET_LAST_KEY() { return collection.GET_FIRST_KEY(); }
|
||||
@Override
|
||||
public KEY_TYPE REMOVE_LAST_KEY() { return collection.REMOVE_FIRST_KEY(); }
|
||||
@Override
|
||||
public ITERATOR KEY_GENERIC_TYPE iterator() { return reverseIterator.get(); }
|
||||
@Override
|
||||
public int size() { return collection.size(); }
|
||||
}
|
||||
|
||||
public static class ReverseBiIterator KEY_GENERIC_TYPE implements LIST_ITERATOR KEY_GENERIC_TYPE {
|
||||
LIST_ITERATOR KEY_GENERIC_TYPE it;
|
||||
|
||||
public ReverseBiIterator(LIST_ITERATOR KEY_GENERIC_TYPE it) {
|
||||
this.it = it;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE NEXT() { return it.PREVIOUS(); }
|
||||
@Override
|
||||
public boolean hasNext() { return it.hasPrevious(); }
|
||||
@Override
|
||||
public boolean hasPrevious() { return it.hasNext(); }
|
||||
@Override
|
||||
public KEY_TYPE PREVIOUS() { return it.NEXT(); }
|
||||
@Override
|
||||
public void remove() { it.remove(); }
|
||||
@Override
|
||||
public int nextIndex() { return it.previousIndex(); }
|
||||
@Override
|
||||
public int previousIndex() { return it.nextIndex(); }
|
||||
@Override
|
||||
public void set(KEY_TYPE e) { it.set(e); }
|
||||
@Override
|
||||
public void add(KEY_TYPE e) { it.add(e); }
|
||||
}
|
||||
#endif
|
||||
}
|
||||
+2
-10
@@ -1,19 +1,11 @@
|
||||
package speiger.src.collections.PACKAGE.collections;
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.objects.collections.ObjectBidirectionalIterator;
|
||||
/**
|
||||
* A Type-Specific {@link ObjectBidirectionalIterator} to reduce (un)boxing
|
||||
*/
|
||||
public interface BI_ITERATOR KEY_GENERIC_TYPE extends ITERATOR KEY_GENERIC_TYPE, ObjectBidirectionalIterator<CLASS_TYPE>
|
||||
#else
|
||||
/**
|
||||
* This is a basically a {@link java.util.ListIterator} without the index functions.
|
||||
* Allowing to have a simple Bidirectional Iterator without having to keep track of the Iteration index.
|
||||
* @Type(T)
|
||||
*/
|
||||
public interface BI_ITERATOR KEY_GENERIC_TYPE extends ITERATOR KEY_GENERIC_TYPE
|
||||
#endif
|
||||
{
|
||||
/**
|
||||
* Returns true if the Iterator has a Previous element
|
||||
@@ -29,11 +21,11 @@ public interface BI_ITERATOR KEY_GENERIC_TYPE extends ITERATOR KEY_GENERIC_TYPE
|
||||
public KEY_TYPE PREVIOUS();
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
/** {@inheritDoc}
|
||||
/**
|
||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||
* @deprecated Please use the corresponding type-specific function instead.
|
||||
* @return the Previous element of the iterator.+
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public default CLASS_TYPE previous() {
|
||||
return KEY_TO_OBJ(PREVIOUS());
|
||||
|
||||
+15
-4
@@ -5,24 +5,29 @@ import java.util.Collection;
|
||||
import java.util.Objects;
|
||||
import java.util.function.JAVA_PREDICATE;
|
||||
import java.util.function.Predicate;
|
||||
#if SPLIT_ITERATOR_FEATURE && STREAM_FEATURE
|
||||
import java.util.stream.JAVA_STREAM;
|
||||
import java.util.stream.StreamSupport;
|
||||
#endif
|
||||
#endif
|
||||
#if TYPE_OBJECT
|
||||
import java.util.function.Consumer;
|
||||
import speiger.src.collections.ints.functions.function.Int2ObjectFunction;
|
||||
import java.util.function.IntFunction;
|
||||
#else
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
#endif
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.utils.COLLECTIONS;
|
||||
import speiger.src.collections.utils.ISizeProvider;
|
||||
import speiger.src.collections.utils.SanityChecks;
|
||||
|
||||
/**
|
||||
* A Type-Specific {@link Collection} that reduces (un)boxing
|
||||
* @Type(T)
|
||||
*/
|
||||
public interface COLLECTION KEY_GENERIC_TYPE extends Collection<CLASS_TYPE>, ITERABLE KEY_GENERIC_TYPE
|
||||
public interface COLLECTION KEY_GENERIC_TYPE extends Collection<CLASS_TYPE>, ITERABLE KEY_GENERIC_TYPE, ISizeProvider
|
||||
{
|
||||
#if !TYPE_OBJECT
|
||||
/**
|
||||
@@ -174,11 +179,12 @@ public interface COLLECTION KEY_GENERIC_TYPE extends Collection<CLASS_TYPE>, ITE
|
||||
/**
|
||||
* A Helper function that simplifies the process of creating a new Array.
|
||||
* @param action the array creation function
|
||||
* @param <E> the returning arrayType
|
||||
* @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()));
|
||||
default <E> E[] TO_ARRAY(IntFunction<E[]> action) {
|
||||
return TO_ARRAY(action.apply(size()));
|
||||
}
|
||||
|
||||
#else
|
||||
@@ -290,6 +296,7 @@ public interface COLLECTION KEY_GENERIC_TYPE extends Collection<CLASS_TYPE>, ITE
|
||||
*/
|
||||
public default COLLECTION KEY_GENERIC_TYPE unmodifiable() { return COLLECTIONS.unmodifiable(this); }
|
||||
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
#if PRIMITIVES
|
||||
/**
|
||||
* Returns a Java-Type-Specific Stream to reduce boxing/unboxing.
|
||||
@@ -302,11 +309,15 @@ public interface COLLECTION KEY_GENERIC_TYPE extends Collection<CLASS_TYPE>, ITE
|
||||
* @return a Stream of the closest java type
|
||||
*/
|
||||
default JAVA_STREAM parallelPrimitiveStream() { return StreamSupport.NEW_STREAM(SPLIT_ITERATORS.createJavaSplititerator(this, 0), true); }
|
||||
|
||||
#endif
|
||||
#if STREAM_FEATURE
|
||||
/**
|
||||
* A Type Specific Type Splititerator to reduce boxing/unboxing
|
||||
* @return type specific splititerator
|
||||
*/
|
||||
@Override
|
||||
default SPLIT_ITERATOR KEY_GENERIC_TYPE spliterator() { return SPLIT_ITERATORS.createSplititerator(this, 0); }
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
+181
-16
@@ -2,6 +2,13 @@ package speiger.src.collections.PACKAGE.collections;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.function.Consumer;
|
||||
#if JDK_FUNCTION
|
||||
import java.util.function.PREDICATE;
|
||||
#endif
|
||||
#if JDK_TYPE
|
||||
import java.util.OPTIONAL;
|
||||
#endif
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
@@ -9,23 +16,74 @@ import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
import speiger.src.collections.objects.collections.ObjectIterable;
|
||||
#else
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.IntFunction;
|
||||
import java.util.Comparator;
|
||||
|
||||
#if BOOLEAN_COLLECTION_MODULE
|
||||
import speiger.src.collections.booleans.collections.BooleanIterable;
|
||||
#endif
|
||||
#iterate
|
||||
#argument OUTPUT_ITERABLE ByteIterable ShortIterable IntIterable LongIterable FloatIterable DoubleIterable
|
||||
#argument MAPPER ToByteFunction ToShortFunction ToIntFunction ToLongFunction ToFloatFunction ToDoubleFunction
|
||||
#argument PACKAGE bytes shorts ints longs floats doubles
|
||||
#argument FILTER_TYPE BYTE_COLLECTION_MODULE SHORT_COLLECTION_MODULE INT_COLLECTION_MODULE LONG_COLLECTION_MODULE FLOAT_COLLECTION_MODULE DOUBLE_COLLECTION_MODULE
|
||||
#if FILTER_TYPE
|
||||
import speiger.src.collections.objects.functions.function.MAPPER;
|
||||
import speiger.src.collections.PACKAGE.collections.OUTPUT_ITERABLE;
|
||||
#endif
|
||||
#enditerate
|
||||
#endif
|
||||
#if !JDK_TYPE
|
||||
import speiger.src.collections.PACKAGE.functions.OPTIONAL;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.functions.function.TO_OBJECT_FUNCTION;
|
||||
import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
|
||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||
#if !JDK_FUNCTION
|
||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||
import speiger.src.collections.PACKAGE.lists.LIST;
|
||||
import speiger.src.collections.PACKAGE.lists.ARRAY_LIST;
|
||||
#if !TYPE_BOOLEAN
|
||||
import speiger.src.collections.PACKAGE.sets.SET;
|
||||
import speiger.src.collections.PACKAGE.sets.LINKED_HASH_SET;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||
#if ARRAY_LIST_FEATURE || LINKED_LIST_FEATURE
|
||||
import speiger.src.collections.PACKAGE.lists.LIST;
|
||||
#if ARRAY_LIST_FEATURE
|
||||
import speiger.src.collections.PACKAGE.lists.ARRAY_LIST;
|
||||
#else
|
||||
import speiger.src.collections.PACKAGE.lists.LINKED_LIST;
|
||||
#endif
|
||||
#endif
|
||||
#if SET_MODULE && !TYPE_BOOLEAN
|
||||
#if LINKED_SET_FEATURE || LINKED_CUSTOM_SET_FEATURE || SET_FEATURE || CUSTOM_SET_FEATURE || RB_TREE_SET_FEATURE || AVL_TREE_SET_FEATURE || ARRAY_SET_FEATURE
|
||||
import speiger.src.collections.PACKAGE.sets.SET;
|
||||
#if LINKED_SET_FEATURE
|
||||
import speiger.src.collections.PACKAGE.sets.LINKED_HASH_SET;
|
||||
#else if LINKED_CUSTOM_SET_FEATURE
|
||||
import speiger.src.collections.PACKAGE.sets.LINKED_CUSTOM_HASH_SET;
|
||||
#else if SET_FEATURE
|
||||
import speiger.src.collections.PACKAGE.sets.HASH_SET;
|
||||
#else if CUSTOM_SET_FEATURE
|
||||
import speiger.src.collections.PACKAGE.sets.CUSTOM_HASH_SET;
|
||||
#else if RB_TREE_SET_FEATURE
|
||||
import speiger.src.collections.PACKAGE.sets.RB_TREE_SET;
|
||||
#else if AVL_TREE_SET_FEATURE
|
||||
import speiger.src.collections.PACKAGE.sets.AVL_TREE_SET;
|
||||
#else if ARRAY_SET_FEATURE
|
||||
import speiger.src.collections.PACKAGE.sets.ARRAY_SET;
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
||||
#if ASYNC_MODULE
|
||||
import speiger.src.collections.PACKAGE.utils.ASYNC_BUILDER;
|
||||
#endif
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.utils.ITERABLES;
|
||||
import speiger.src.collections.PACKAGE.utils.ITERATORS;
|
||||
#if !LINKED_HASH_SET_FEATURE && LINKED_CUSTOM_HASH_SET_FEATURE
|
||||
import speiger.src.collections.PACKAGE.utils.STRATEGY;
|
||||
#endif
|
||||
import speiger.src.collections.utils.ISizeProvider;
|
||||
|
||||
/**
|
||||
* A Type-Specific {@link Iterable} that reduces (un)boxing
|
||||
@@ -72,6 +130,17 @@ public interface ITERABLE KEY_GENERIC_TYPE extends Iterable<CLASS_TYPE>
|
||||
}
|
||||
|
||||
#endif
|
||||
/**
|
||||
* A Indexed forEach implementation that allows you to keep track of how many elements were already iterated over.
|
||||
* @param action The action to be performed for each element
|
||||
* @throws java.lang.NullPointerException if the specified action is null
|
||||
*/
|
||||
public default void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
|
||||
Objects.requireNonNull(action);
|
||||
int index = 0;
|
||||
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();action.accept(index++, iter.NEXT()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to reduce Lambda usage and allow for more method references, since these are faster/cleaner.
|
||||
* @param input the object that should be included
|
||||
@@ -84,6 +153,7 @@ public interface ITERABLE KEY_GENERIC_TYPE extends Iterable<CLASS_TYPE>
|
||||
iterator().forEachRemaining(input, action);
|
||||
}
|
||||
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
/**
|
||||
* A Type Specific Type Splititerator to reduce boxing/unboxing
|
||||
* @return type specific splititerator
|
||||
@@ -91,6 +161,8 @@ public interface ITERABLE KEY_GENERIC_TYPE extends Iterable<CLASS_TYPE>
|
||||
@Override
|
||||
default SPLIT_ITERATOR KEY_GENERIC_TYPE spliterator() { return SPLIT_ITERATORS.createUnknownSplititerator(iterator(), 0); }
|
||||
|
||||
#endif
|
||||
#if ASYNC_MODULE
|
||||
/**
|
||||
* Creates a Async Builder for moving work of the thread.
|
||||
* It is not designed to split the work to multithreaded work, so using this keep it singlethreaded, but it allows to be moved to another thread.
|
||||
@@ -101,6 +173,7 @@ public interface ITERABLE KEY_GENERIC_TYPE extends Iterable<CLASS_TYPE>
|
||||
return new ASYNC_BUILDERBRACES(this);
|
||||
}
|
||||
|
||||
#endif
|
||||
/**
|
||||
* A Helper function to reduce the usage of Streams and allows to convert a Iterable to something else.
|
||||
* @param mapper the mapping function
|
||||
@@ -111,12 +184,32 @@ public interface ITERABLE KEY_GENERIC_TYPE extends Iterable<CLASS_TYPE>
|
||||
return ITERABLES.map(this, mapper);
|
||||
}
|
||||
|
||||
#if TYPE_OBJECT
|
||||
#iterate
|
||||
#argument OUTPUT_ITERABLE BooleanIterable ByteIterable ShortIterable IntIterable LongIterable FloatIterable DoubleIterable
|
||||
#argument MAPPER Predicate ToByteFunction ToShortFunction ToIntFunction ToLongFunction ToFloatFunction ToDoubleFunction
|
||||
#argument DATA_TYPE Boolean Byte Short Int Long Float Double
|
||||
#argument FILTER_TYPE BOOLEAN_COLLECTION_MODULE BYTE_COLLECTION_MODULE SHORT_COLLECTION_MODULE INT_COLLECTION_MODULE LONG_COLLECTION_MODULE FLOAT_COLLECTION_MODULE DOUBLE_COLLECTION_MODULE
|
||||
#if FILTER_TYPE
|
||||
/**
|
||||
* A Helper function to reduce the usage of Streams and allows to convert a Iterable to something else.
|
||||
* @param mapper the mapping function
|
||||
* @return a new Iterable that returns the desired result
|
||||
*/
|
||||
default OUTPUT_ITERABLE mapToDATA_TYPE(MAPPER<T> mapper) {
|
||||
return ITERABLES.mapToDATA_TYPE(this, mapper);
|
||||
}
|
||||
|
||||
#endif
|
||||
#enditerate
|
||||
#endif
|
||||
/**
|
||||
* A Helper function to reduce the usage of Streams and allows to convert a Iterable to something else.
|
||||
* @param mapper the flatMapping function
|
||||
* @param <V> The return type supplier.
|
||||
* @param <E> The return type.
|
||||
* @return a new Iterable that returns the desired result
|
||||
* @note does not support TO_ARRAY optimizations.
|
||||
*/
|
||||
default <E, V extends Iterable<E>> ObjectIterable<E> flatMap(TO_OBJECT_FUNCTION KKS_GENERIC_TYPE<V> mapper) {
|
||||
return ITERABLES.flatMap(this, mapper);
|
||||
@@ -127,6 +220,7 @@ public interface ITERABLE KEY_GENERIC_TYPE extends Iterable<CLASS_TYPE>
|
||||
* @param mapper the flatMapping function
|
||||
* @param <E> The return type.
|
||||
* @return a new Iterable that returns the desired result
|
||||
* @note does not support TO_ARRAY optimizations.
|
||||
*/
|
||||
default <E> ObjectIterable<E> arrayflatMap(TO_OBJECT_FUNCTION KKS_GENERIC_TYPE<E[]> mapper) {
|
||||
return ITERABLES.arrayFlatMap(this, mapper);
|
||||
@@ -136,6 +230,7 @@ public interface ITERABLE KEY_GENERIC_TYPE extends Iterable<CLASS_TYPE>
|
||||
* A Helper function to reduce the usage of Streams and allows to filter out unwanted elements
|
||||
* @param filter the elements that should be kept.
|
||||
* @return a Iterable that filtered out all unwanted elements
|
||||
* @note does not support TO_ARRAY optimizations.
|
||||
*/
|
||||
default ITERABLE KEY_GENERIC_TYPE filter(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
return ITERABLES.filter(this, filter);
|
||||
@@ -144,11 +239,21 @@ public interface ITERABLE KEY_GENERIC_TYPE extends Iterable<CLASS_TYPE>
|
||||
/**
|
||||
* 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
|
||||
* @note does not support TO_ARRAY optimizations.
|
||||
*/
|
||||
default ITERABLE KEY_GENERIC_TYPE distinct() {
|
||||
return ITERABLES.distinct(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function to reduce the usage of Streams and allows to repeat elements a desired amount of times
|
||||
* @param repeats how many times the elements should be repeated
|
||||
* @return a Iterable that is repeating multiple times
|
||||
*/
|
||||
default ITERABLE KEY_GENERIC_TYPE repeat(int repeats) {
|
||||
return ITERABLES.repeat(this, repeats);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
@@ -187,21 +292,81 @@ public interface ITERABLE KEY_GENERIC_TYPE extends Iterable<CLASS_TYPE>
|
||||
return collection;
|
||||
}
|
||||
|
||||
#if ARRAY_LIST_FEATURE || LINKED_LIST_FEATURE
|
||||
/**
|
||||
* A Helper function that reduces the usage of streams and allows to collect all elements as a ArrayList
|
||||
* @return a new ArrayList of all elements
|
||||
*/
|
||||
default LIST KEY_GENERIC_TYPE pourAsList() {
|
||||
#if ARRAY_LIST_FEATURE
|
||||
return pour(new ARRAY_LISTBRACES());
|
||||
#else
|
||||
return pour(new LINKED_LISTBRACES());
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !TYPE_BOOLEAN
|
||||
#endif
|
||||
#if !TYPE_BOOLEAN && SET_MODULE
|
||||
#if LINKED_SET_FEATURE || LINKED_CUSTOM_SET_FEATURE || SET_FEATURE || CUSTOM_SET_FEATURE || RB_TREE_SET_FEATURE || AVL_TREE_SET_FEATURE || ARRAY_SET_FEATURE
|
||||
/**
|
||||
* A Helper function that reduces the usage of streams and allows to collect all elements as a LinkedHashSet
|
||||
* @return a new LinkedHashSet of all elements
|
||||
*/
|
||||
default SET KEY_GENERIC_TYPE pourAsSet() {
|
||||
#if LINKED_SET_FEATURE
|
||||
return pour(new LINKED_HASH_SETBRACES());
|
||||
#else if LINKED_CUSTOM_SET_FEATURE
|
||||
return pour(new LINKED_CUSTOM_HASH_SETBRACES(STRATEGY.normalStrategy()));
|
||||
#else if SET_FEATURE
|
||||
return pour(new HASH_SETBRACES());
|
||||
#else if CUSTOM_SET_FEATURE
|
||||
return pour(new CUSTOM_HASH_SETBRACES(STRATEGY.normalStrategy()));
|
||||
#else if RB_TREE_SET_FEATURE
|
||||
return pour(new RB_Tree_SETBRACES());
|
||||
#else if AVL_TREE_SET_FEATURE
|
||||
return pour(new AVL_Tree_SETBRACES());
|
||||
#else if ARRAY_SET_FEATURE
|
||||
return pour(new ARRAY_SETBRACES());
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
#if TYPE_OBJECT
|
||||
/**
|
||||
* A Helper function that reduces the usage of streams and allows to collect all elements as a Array
|
||||
* @param action is the creator function of said Array to ensure type is kept.
|
||||
* @param <E> the returning arrayType
|
||||
* @return a new Array of all elements
|
||||
*/
|
||||
default <E> E[] TO_ARRAY(IntFunction<E[]> action) {
|
||||
ISizeProvider prov = ISizeProvider.of(this);
|
||||
if(prov != null) {
|
||||
int size = prov.size();
|
||||
if(size >= 0) {
|
||||
E[] array = action.apply(size);
|
||||
ITERATORS.unwrap(array, iterator());
|
||||
return array;
|
||||
}
|
||||
}
|
||||
return ARRAYS.pour(iterator(), action);
|
||||
}
|
||||
#else
|
||||
/**
|
||||
* A Helper function that reduces the usage of streams and allows to collect all elements as a Array
|
||||
* @return a new Array of all elements
|
||||
*/
|
||||
default KEY_TYPE[] TO_ARRAY() {
|
||||
ISizeProvider prov = ISizeProvider.of(this);
|
||||
if(prov != null) {
|
||||
int size = prov.size();
|
||||
if(size >= 0) {
|
||||
KEY_TYPE[] array = NEW_KEY_ARRAY(size);
|
||||
ITERATORS.unwrap(array, iterator());
|
||||
return array;
|
||||
}
|
||||
}
|
||||
return ARRAYS.pour(iterator());
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -213,7 +378,7 @@ public interface ITERABLE KEY_GENERIC_TYPE extends Iterable<CLASS_TYPE>
|
||||
default boolean matchesAny(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
||||
if(filter.TEST_VALUE(iter.NEXT())) return true;
|
||||
if(filter.test(iter.NEXT())) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -226,7 +391,7 @@ public interface ITERABLE KEY_GENERIC_TYPE extends Iterable<CLASS_TYPE>
|
||||
default boolean matchesNone(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
||||
if(filter.TEST_VALUE(iter.NEXT())) return false;
|
||||
if(filter.test(iter.NEXT())) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -239,7 +404,7 @@ public interface ITERABLE KEY_GENERIC_TYPE extends Iterable<CLASS_TYPE>
|
||||
default boolean matchesAll(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
||||
if(!filter.TEST_VALUE(iter.NEXT())) return false;
|
||||
if(!filter.test(iter.NEXT())) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -249,13 +414,13 @@ public interface ITERABLE KEY_GENERIC_TYPE extends Iterable<CLASS_TYPE>
|
||||
* @param filter that should be applied
|
||||
* @return the found value or the null equivalent variant.
|
||||
*/
|
||||
default KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
default OPTIONAL KEY_GENERIC_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
||||
KEY_TYPE entry = iter.NEXT();
|
||||
if(filter.TEST_VALUE(entry)) return entry;
|
||||
if(filter.test(entry)) return OPTIONAL.GET_OPTIONAL(entry);
|
||||
}
|
||||
return EMPTY_VALUE;
|
||||
return OPTIONAL.empty();
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@@ -300,7 +465,7 @@ public interface ITERABLE KEY_GENERIC_TYPE extends Iterable<CLASS_TYPE>
|
||||
* @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) {
|
||||
default OPTIONAL KEY_GENERIC_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = EMPTY_VALUE;
|
||||
boolean empty = true;
|
||||
@@ -312,7 +477,7 @@ public interface ITERABLE KEY_GENERIC_TYPE extends Iterable<CLASS_TYPE>
|
||||
}
|
||||
state = operator.APPLY_VALUE(state, iter.NEXT());
|
||||
}
|
||||
return state;
|
||||
return empty ? OPTIONAL.empty() : OPTIONAL.GET_OPTIONAL(state);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -324,7 +489,7 @@ public interface ITERABLE KEY_GENERIC_TYPE extends Iterable<CLASS_TYPE>
|
||||
Objects.requireNonNull(filter);
|
||||
int result = 0;
|
||||
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
||||
if(filter.TEST_VALUE(iter.NEXT())) result++;
|
||||
if(filter.test(iter.NEXT())) result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
package speiger.src.collections.PACKAGE.collections;
|
||||
|
||||
#if JAVA_VERSION>=21
|
||||
import java.util.SequencedCollection;
|
||||
|
||||
public interface ORDERED_COLLECTION KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, SequencedCollection<CLASS_TYPE> {
|
||||
#else
|
||||
public interface ORDERED_COLLECTION KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE {
|
||||
#endif
|
||||
@Java21
|
||||
ORDERED_COLLECTION KEY_GENERIC_TYPE reversed();
|
||||
|
||||
/**
|
||||
* A method to add an element to the start of a collection
|
||||
* @param e that should be added at the start.
|
||||
*/
|
||||
public void addFirst(KEY_TYPE e);
|
||||
|
||||
/**
|
||||
* A method to add an element to the end of a collection
|
||||
* @param e that should be added at the end.
|
||||
*/
|
||||
public void addLast(KEY_TYPE e);
|
||||
|
||||
/**
|
||||
* A method to get the first element in the collection
|
||||
* @return first element in the collection
|
||||
*/
|
||||
public KEY_TYPE GET_FIRST_KEY();
|
||||
/**
|
||||
* A method to get and remove the first element in the collection
|
||||
* @return first element in the collection
|
||||
*/
|
||||
public KEY_TYPE REMOVE_FIRST_KEY();
|
||||
/**
|
||||
* A method to get the last element in the collection
|
||||
* @return last element in the collection
|
||||
*/
|
||||
public KEY_TYPE GET_LAST_KEY();
|
||||
/**
|
||||
* A method to get and remove the last element in the collection
|
||||
* @return last element in the collection
|
||||
*/
|
||||
public KEY_TYPE REMOVE_LAST_KEY();
|
||||
|
||||
#if JAVA_VERSION>=21 && !TYPE_OBJECT
|
||||
@Override
|
||||
@Deprecated
|
||||
default void addFirst(CLASS_TYPE e) {
|
||||
addFirst(OBJ_TO_KEY(e));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
default void addLast(CLASS_TYPE e) {
|
||||
addLast(OBJ_TO_KEY(e));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
default CLASS_TYPE getFirst() {
|
||||
return KEY_TO_OBJ(GET_FIRST_KEY());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
default CLASS_TYPE getLast() {
|
||||
return KEY_TO_OBJ(GET_LAST_KEY());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
default CLASS_TYPE removeFirst() {
|
||||
return KEY_TO_OBJ(REMOVE_FIRST_KEY());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
default CLASS_TYPE removeLast() {
|
||||
return KEY_TO_OBJ(REMOVE_LAST_KEY());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package speiger.src.collections.PACKAGE.collections;
|
||||
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import speiger.src.collections.utils.Stack;
|
||||
|
||||
/**
|
||||
@@ -14,6 +16,14 @@ public interface STACK
|
||||
*/
|
||||
public void push(KEY_TYPE e);
|
||||
|
||||
/**
|
||||
* Helper function that pushes the top element on top of the stack again.
|
||||
* @throws NoSuchElementException if the stack is empty
|
||||
*/
|
||||
public default void pushTop() {
|
||||
push(top());
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the Object on top of the stack.
|
||||
* @return the element that is on top of the stack
|
||||
@@ -59,4 +69,19 @@ public interface STACK
|
||||
public default boolean isEmpty() {
|
||||
return size() == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* A method to drop the contents of the Stack without clearing the stack
|
||||
* @Type(E)
|
||||
* @return the contents of the stack into a seperate array.
|
||||
*/
|
||||
public default GENERIC_SPECIAL_KEY_BRACES<E> KEY_SPECIAL_TYPE[] TO_ARRAY() { return TO_ARRAY(NEW_SPECIAL_KEY_ARRAY(size())); }
|
||||
/**
|
||||
* A method to drop the contents of the Stack without clearing the stack
|
||||
* @param input where the elements should be inserted to. If it does not fit then it creates a new appropiatly created array
|
||||
* @Type(E)
|
||||
* @return the contents of the stack into a seperate array.
|
||||
* @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);
|
||||
}
|
||||
+89
@@ -0,0 +1,89 @@
|
||||
package speiger.src.collections.PACKAGE.functions;
|
||||
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public final class OPTIONAL KEY_GENERIC_TYPE {
|
||||
private static final OPTIONAL NO_GENERIC_TYPE EMPTY = new OPTIONALBRACES();
|
||||
|
||||
private final boolean isPresent;
|
||||
private final KEY_TYPE value;
|
||||
|
||||
private OPTIONAL() {
|
||||
this.isPresent = false;
|
||||
this.value = EMPTY_VALUE;
|
||||
}
|
||||
|
||||
private OPTIONAL(KEY_TYPE value) {
|
||||
this.isPresent = true;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public static OPTIONAL KEY_GENERIC_TYPE empty() {
|
||||
return EMPTY;
|
||||
}
|
||||
|
||||
public static OPTIONAL KEY_GENERIC_TYPE of(KEY_TYPE value) {
|
||||
return new OPTIONALBRACES(value);
|
||||
}
|
||||
|
||||
public KEY_TYPE SUPPLY_GET() {
|
||||
if(!isPresent) throw new NoSuchElementException("No value present");
|
||||
return value;
|
||||
}
|
||||
|
||||
public boolean isPresent() {
|
||||
return isPresent;
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return !isPresent;
|
||||
}
|
||||
|
||||
public void ifPresent(CONSUMER KEY_GENERIC_TYPE consumer) {
|
||||
if(isPresent) consumer.accept(value);
|
||||
}
|
||||
|
||||
public void ifPresentOrElse(CONSUMER KEY_GENERIC_TYPE action, Runnable emptyAction) {
|
||||
if (isPresent) action.accept(value);
|
||||
else emptyAction.run();
|
||||
}
|
||||
|
||||
public KEY_TYPE orElse(KEY_TYPE other) {
|
||||
return isPresent ? value : other;
|
||||
}
|
||||
|
||||
public KEY_TYPE orElseGet(SUPPLIER KEY_GENERIC_TYPE other) {
|
||||
return isPresent ? value : other.SUPPLY_GET();
|
||||
}
|
||||
|
||||
public KEY_TYPE orElseThrow() {
|
||||
if (!isPresent) throw new NoSuchElementException("No value present");
|
||||
return value;
|
||||
}
|
||||
|
||||
public <X extends Throwable> KEY_TYPE orElseThrow(Supplier<? extends X> exceptionSupplier) throws X {
|
||||
if(isPresent) return value;
|
||||
else throw exceptionSupplier.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(obj == this) return true;
|
||||
if(obj instanceof OPTIONAL) {
|
||||
OPTIONAL KEY_GENERIC_TYPE other = (OPTIONAL KEY_GENERIC_TYPE)obj;
|
||||
return (isPresent && other.isPresent ? KEY_EQUALS(value, other.value) : isPresent == other.isPresent);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return isPresent ? KEY_TO_HASH(value) : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return isPresent ? "OPTIONAL["+value+"]" : "OPTIONAL.empty";
|
||||
}
|
||||
}
|
||||
+1
-8
@@ -15,12 +15,5 @@ public interface SUPPLIER KEY_GENERIC_TYPE
|
||||
/**
|
||||
* @return the supplied value
|
||||
*/
|
||||
public KEY_TYPE GET_KEY();
|
||||
#if JDK_TYPE && PRIMITIVES
|
||||
|
||||
@Override
|
||||
public default KEY_TYPE GET_JAVA() {
|
||||
return GET_KEY();
|
||||
}
|
||||
#endif
|
||||
public KEY_TYPE SUPPLY_GET();
|
||||
}
|
||||
+73
-18
@@ -1,6 +1,6 @@
|
||||
package speiger.src.collections.PACKAGE.functions.function;
|
||||
|
||||
#if JDK_FUNCTION && VALUE_BOOLEAN
|
||||
#if VALUE_BOOLEAN || SAME_TYPE
|
||||
import java.util.Objects;
|
||||
#endif
|
||||
|
||||
@@ -21,12 +21,67 @@ public interface FUNCTION KEY_VALUE_GENERIC_TYPE
|
||||
* @param k the value that should be processed
|
||||
* @return the result of the function
|
||||
*/
|
||||
public VALUE_TYPE GET_VALUE(KEY_TYPE k);
|
||||
public VALUE_TYPE APPLY(KEY_TYPE k);
|
||||
|
||||
#if JDK_FUNCTION
|
||||
#if SAME_TYPE
|
||||
/**
|
||||
* Creates a Default function that returns the input provided.
|
||||
* @Type(T)
|
||||
* @return a input returning function
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES FUNCTION KEY_SAME_GENERIC_TYPE identity() {
|
||||
return T -> T;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a composed function that first applies the {@code before}
|
||||
* function to its input, and then applies this function to the result.
|
||||
* If evaluation of either function throws an exception, it is relayed to
|
||||
* the caller of the composed function.
|
||||
*
|
||||
* @Type(I)
|
||||
* @param before the function that should be used first
|
||||
* @return a composed function with a different starting function.
|
||||
*/
|
||||
public default GENERIC_SPECIAL_VALUE_BRACES<I> FUNCTION SV_GENERIC_TYPE<I> compose(FUNCTION SK_GENERIC_TYPE<I> before) {
|
||||
Objects.requireNonNull(before);
|
||||
return T -> APPLY(before.APPLY(T));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a composed function that first applies this function to
|
||||
* its input, and then applies the {@code after} function to the result.
|
||||
* If evaluation of either function throws an exception, it is relayed to
|
||||
* the caller of the composed function.
|
||||
*
|
||||
* @Type(I)
|
||||
* @param after the function that should be used last
|
||||
* @return a composed function with a different starting function.
|
||||
*/
|
||||
public default GENERIC_SPECIAL_VALUE_BRACES<I> FUNCTION KS_GENERIC_TYPE<I> andThen(FUNCTION VS_GENERIC_TYPE<I> after) {
|
||||
Objects.requireNonNull(after);
|
||||
return T -> after.APPLY(APPLY(T));
|
||||
}
|
||||
|
||||
#endif
|
||||
#if VALUE_BOOLEAN
|
||||
@Override
|
||||
public default VALUE_TYPE test(KEY_TYPE k) { return GET_VALUE(k); }
|
||||
/**
|
||||
* Creates a Always true function that may be useful if you don't need to process information or just want a default.
|
||||
* @Type(T)
|
||||
* @return a default returning function
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES FUNCTION KEY_GENERIC_TYPE alwaysTrue() {
|
||||
return T -> true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Always false function that may be useful if you don't need to process information or just want a default.
|
||||
* @Type(T)
|
||||
* @return a default returning function
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES FUNCTION KEY_GENERIC_TYPE alwaysFalse() {
|
||||
return T -> false;
|
||||
}
|
||||
|
||||
/**
|
||||
* A Type specific and-function helper function that reduces boxing/unboxing
|
||||
@@ -35,19 +90,26 @@ public interface FUNCTION KEY_VALUE_GENERIC_TYPE
|
||||
*/
|
||||
public default FUNCTION KEY_VALUE_GENERIC_TYPE andType(FUNCTION KEY_VALUE_GENERIC_TYPE other) {
|
||||
Objects.requireNonNull(other);
|
||||
return T -> GET_VALUE(T) && other.GET_VALUE(T);
|
||||
return T -> APPLY(T) && other.APPLY(T);
|
||||
}
|
||||
|
||||
#if JDK_FUNCTION
|
||||
@Override
|
||||
@Deprecated
|
||||
public default FUNCTION KEY_VALUE_GENERIC_TYPE and(JAVA_FUNCTION KEY_VALUE_SUPER_GENERIC_TYPE other) {
|
||||
Objects.requireNonNull(other);
|
||||
return T -> GET_VALUE(T) && other.test(T);
|
||||
return T -> APPLY(T) && other.APPLY(T);
|
||||
}
|
||||
|
||||
@Override
|
||||
#else
|
||||
/**
|
||||
* A type specific inverter function
|
||||
* @return the same function but inverts the result
|
||||
*/
|
||||
#endif
|
||||
public default FUNCTION KEY_VALUE_GENERIC_TYPE negate() {
|
||||
return T -> !GET_VALUE(T);
|
||||
return T -> !APPLY(T);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -57,23 +119,16 @@ public interface FUNCTION KEY_VALUE_GENERIC_TYPE
|
||||
*/
|
||||
public default FUNCTION KEY_VALUE_GENERIC_TYPE orType(FUNCTION KEY_VALUE_GENERIC_TYPE other) {
|
||||
Objects.requireNonNull(other);
|
||||
return T -> GET_VALUE(T) || other.GET_VALUE(T);
|
||||
return T -> APPLY(T) || other.APPLY(T);
|
||||
}
|
||||
|
||||
#if JDK_FUNCTION
|
||||
@Override
|
||||
@Deprecated
|
||||
public default FUNCTION KEY_VALUE_GENERIC_TYPE or(JAVA_FUNCTION KEY_VALUE_SUPER_GENERIC_TYPE other) {
|
||||
Objects.requireNonNull(other);
|
||||
return T -> GET_VALUE(T) || other.test(T);
|
||||
return T -> APPLY(T) || other.APPLY(T);
|
||||
}
|
||||
#else if VALUE_OBJECT
|
||||
|
||||
@Override
|
||||
public default VALUE_TYPE apply(KEY_TYPE k) { return GET_VALUE(k); }
|
||||
#else
|
||||
|
||||
@Override
|
||||
public default VALUE_TYPE APPLY_VALUE(KEY_TYPE k) { return GET_VALUE(k); }
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
+310
-4
@@ -1,16 +1,25 @@
|
||||
package speiger.src.collections.PACKAGE.lists;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Objects;
|
||||
import java.util.RandomAccess;
|
||||
|
||||
import speiger.src.collections.PACKAGE.collections.ABSTRACT_COLLECTION;
|
||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
import speiger.src.collections.PACKAGE.collections.SPLIT_ITERATOR;
|
||||
#endif
|
||||
#if INT_LIST_MODULE && !TYPE_INT
|
||||
import speiger.src.collections.ints.lists.IntList;
|
||||
#endif
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
||||
#endif
|
||||
import speiger.src.collections.utils.SanityChecks;
|
||||
|
||||
/**
|
||||
@@ -66,8 +75,7 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean addAll(Collection<? extends CLASS_TYPE> c)
|
||||
{
|
||||
public boolean addAll(Collection<? extends CLASS_TYPE> c) {
|
||||
return c instanceof COLLECTION ? addAll((COLLECTION KEY_GENERIC_TYPE)c) : addAll(size(), c);
|
||||
}
|
||||
|
||||
@@ -221,6 +229,11 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
||||
return new SubList(this, 0, fromIndex, toIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LIST KEY_GENERIC_TYPE reversed() {
|
||||
return new ReversedList(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITERATOR KEY_GENERIC_TYPE iterator() {
|
||||
return listIterator(0);
|
||||
@@ -237,6 +250,18 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
||||
return new LIST_ITER(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE indexedIterator(int...indecies) {
|
||||
return new IndexedIterator(indecies);
|
||||
}
|
||||
|
||||
#if INT_LIST_MODULE
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE indexedIterator(IntList indecies) {
|
||||
return new ListIndexedIterator(indecies);
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public void size(int size) {
|
||||
while(size > size()) add(EMPTY_KEY_VALUE);
|
||||
@@ -245,6 +270,138 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
||||
|
||||
public ABSTRACT_LIST KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
||||
|
||||
private class ReversedList extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
{
|
||||
final ABSTRACT_LIST KEY_GENERIC_TYPE list;
|
||||
|
||||
public ReversedList(ABSTRACT_LIST KEY_GENERIC_TYPE list) {
|
||||
this.list = list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(int index, KEY_TYPE e) {
|
||||
list.add(list.size() - index - 1, e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAll(int index, COLLECTION KEY_GENERIC_TYPE c) {
|
||||
return addCollection(index, c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAll(int index, LIST KEY_GENERIC_TYPE c) {
|
||||
if(c instanceof RandomAccess) {
|
||||
for(int i = 0,m=c.size();i<m;i++) {
|
||||
list.add(list.size() - index - i - 1, c.GET_KEY(i));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return addCollection(index, c);
|
||||
}
|
||||
|
||||
private boolean addCollection(int index, COLLECTION KEY_GENERIC_TYPE c) {
|
||||
int i = 0;
|
||||
for(ITERATOR KEY_GENERIC_TYPE iter = c.iterator();iter.hasNext();i++) {
|
||||
list.add(list.size() - index - i - 1, iter.NEXT());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAll(int index, Collection<? extends CLASS_TYPE> c) {
|
||||
int i = 0;
|
||||
for(Iterator<? extends CLASS_TYPE> iter = c.iterator();iter.hasNext();i++) {
|
||||
list.add(list.size() - index - i - 1, iter.next());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE GET_KEY(int index) {
|
||||
return list.GET_KEY(list.size() - index - 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE set(int index, KEY_TYPE e) {
|
||||
return list.set(list.size() - index - 1, e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE REMOVE(int index) {
|
||||
return list.REMOVE(list.size() - index - 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addElements(int from, KEY_TYPE[] a, int offset, int length) {
|
||||
for(int i = 0,m=length;i<m;i++) {
|
||||
list.add(list.size() - from - i - 1, a[i+offset]);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE[] getElements(int from, KEY_TYPE[] a, int offset, int length) {
|
||||
return reverse(list.getElements(list.size() - from - 1, a, offset, length));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeElements(int from, int to) {
|
||||
list.removeElements(list.size() - to - 1, list.size() - from - 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE swapRemove(int index) {
|
||||
return list.swapRemove(list.size() - index - 1);
|
||||
}
|
||||
#if TYPE_OBJECT
|
||||
@Override
|
||||
public <K> K[] extractElements(int from, int to, Class<K> type) {
|
||||
return reverse(list.extractElements(list.size() - to - 1, list.size() - from - 1, type));
|
||||
}
|
||||
|
||||
#else
|
||||
@Override
|
||||
public KEY_TYPE[] extractElements(int from, int to) {
|
||||
return reverse(list.extractElements(list.size() - to - 1, list.size() - from - 1));
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public int size() {
|
||||
return list.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
list.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public LIST KEY_GENERIC_TYPE reversed() {
|
||||
return list;
|
||||
}
|
||||
|
||||
#if TYPE_OBJECT
|
||||
private <K> K[] reverse(K[] data) {
|
||||
for (int i = 0, mid = data.length >> 1, j = data.length - 1; i < mid; i++, j--) {
|
||||
K t = data[i];
|
||||
data[i] = data[j];
|
||||
data[j] = t;
|
||||
}
|
||||
return data;
|
||||
}
|
||||
#else
|
||||
private KEY_TYPE[] reverse(KEY_TYPE[] data) {
|
||||
for (int i = 0, mid = data.length >> 1, j = data.length - 1; i < mid; i++, j--) {
|
||||
KEY_TYPE t = data[i];
|
||||
data[i] = data[j];
|
||||
data[j] = t;
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
private class SubList extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
{
|
||||
final ABSTRACT_LIST KEY_GENERIC_TYPE list;
|
||||
@@ -379,9 +536,10 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
||||
public int size() {
|
||||
return size;
|
||||
}
|
||||
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
@Override
|
||||
public SPLIT_ITERATOR KEY_GENERIC_TYPE spliterator() { return SPLIT_ITERATORS.createSplititerator(this, 16464); }
|
||||
#endif
|
||||
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE listIterator(int index) {
|
||||
@@ -491,6 +649,154 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
||||
}
|
||||
}
|
||||
|
||||
#if INT_LIST_MODULE
|
||||
private class ListIndexedIterator implements LIST_ITERATOR KEY_GENERIC_TYPE {
|
||||
IntList indecies;
|
||||
int index;
|
||||
int lastReturned = -1;
|
||||
|
||||
ListIndexedIterator(IntList indecies) {
|
||||
this.indecies = indecies;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return index < indecies.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE NEXT() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
int i = index++;
|
||||
return GET_KEY((lastReturned = indecies.getInt(i)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPrevious() {
|
||||
return index > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE PREVIOUS() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
index--;
|
||||
return GET_KEY((lastReturned = indecies.getInt(index)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int nextIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int previousIndex() {
|
||||
return index-1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void add(KEY_TYPE e) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public void set(KEY_TYPE e) {
|
||||
if(lastReturned == -1) throw new IllegalStateException();
|
||||
ABSTRACT_LIST.this.set(lastReturned, e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int skip(int amount) {
|
||||
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
||||
int steps = Math.min(amount, indecies.size() - index);
|
||||
index += steps;
|
||||
if(steps > 0) lastReturned = Math.min(index-1, indecies.size()-1);
|
||||
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;
|
||||
if(steps > 0) lastReturned = Math.max(index, 0);
|
||||
return steps;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
private class IndexedIterator implements LIST_ITERATOR KEY_GENERIC_TYPE {
|
||||
int[] indecies;
|
||||
int index;
|
||||
int lastReturned = -1;
|
||||
|
||||
IndexedIterator(int[] indecies) {
|
||||
this.indecies = indecies;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return index < indecies.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE NEXT() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
int i = index++;
|
||||
return GET_KEY((lastReturned = indecies[i]));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPrevious() {
|
||||
return index > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE PREVIOUS() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
index--;
|
||||
return GET_KEY((lastReturned = indecies[index]));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int nextIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int previousIndex() {
|
||||
return index-1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void add(KEY_TYPE e) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public void set(KEY_TYPE e) {
|
||||
if(lastReturned == -1) throw new IllegalStateException();
|
||||
ABSTRACT_LIST.this.set(lastReturned, e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int skip(int amount) {
|
||||
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
||||
int steps = Math.min(amount, indecies.length - index);
|
||||
index += steps;
|
||||
if(steps > 0) lastReturned = Math.min(index-1, indecies.length-1);
|
||||
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;
|
||||
if(steps > 0) lastReturned = Math.max(index, 0);
|
||||
return steps;
|
||||
}
|
||||
}
|
||||
|
||||
private class LIST_ITER implements LIST_ITERATOR KEY_GENERIC_TYPE {
|
||||
int index;
|
||||
int lastReturned = -1;
|
||||
@@ -568,7 +874,7 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
||||
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
||||
int steps = Math.min(amount, index);
|
||||
index -= steps;
|
||||
if(steps > 0) lastReturned = Math.min(index, size()-1);
|
||||
if(steps > 0) lastReturned = Math.max(index, 0);
|
||||
return steps;
|
||||
}
|
||||
}
|
||||
|
||||
+100
-24
@@ -7,14 +7,33 @@ import java.util.Comparator;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.Objects;
|
||||
#if JDK_TYPE
|
||||
import java.util.OPTIONAL;
|
||||
#if SPLIT_ITERATOR_FEATURE && STREAM_FEATURE
|
||||
#if TYPE_OBJECT
|
||||
import java.util.stream.Stream;
|
||||
import java.util.stream.Collector;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#if TYPE_OBJECT
|
||||
#if IARRAY_FEATURE || TYPE_OBJECT
|
||||
import java.util.function.Consumer;
|
||||
#endif
|
||||
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.IntFunction;
|
||||
#endif
|
||||
#if !TYPE_OBJECT && JDK_FUNCTION
|
||||
import java.util.function.PREDICATE;
|
||||
#endif
|
||||
import java.util.function.Predicate;
|
||||
import java.util.function.UnaryOperator;
|
||||
#if PRIMITIVES
|
||||
#if !JDK_FUNCTION
|
||||
import java.util.function.JAVA_PREDICATE;
|
||||
#endif
|
||||
import java.util.function.JAVA_UNARY_OPERATOR;
|
||||
import java.nio.JAVA_BUFFER;
|
||||
#endif
|
||||
@@ -24,47 +43,58 @@ import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||
import speiger.src.collections.PACKAGE.collections.STACK;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
#if !JDK_TYPE
|
||||
import speiger.src.collections.PACKAGE.functions.OPTIONAL;
|
||||
#endif
|
||||
#if !TYPE_OBJECT
|
||||
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;
|
||||
#if !JDK_FUNCTION
|
||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
||||
#endif
|
||||
import speiger.src.collections.objects.utils.ObjectArrays;
|
||||
import speiger.src.collections.PACKAGE.utils.ITERATORS;
|
||||
#if TYPE_OBJECT
|
||||
import speiger.src.collections.utils.Stack;
|
||||
#else
|
||||
import speiger.src.collections.objects.utils.ObjectArrays;
|
||||
#endif
|
||||
#if PRIMITIVES
|
||||
#if PRIMITIVES && SPLIT_ITERATOR_FEATURE && STREAM_FEATURE
|
||||
import java.util.stream.JAVA_STREAM;
|
||||
import java.util.stream.StreamSupport;
|
||||
#endif
|
||||
#if IARRAY_FEATURE
|
||||
import speiger.src.collections.PACKAGE.utils.IARRAY;
|
||||
#endif
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
import speiger.src.collections.PACKAGE.collections.SPLIT_ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
||||
#endif
|
||||
#if !IARRAY_FEATURE
|
||||
import speiger.src.collections.utils.IArray;
|
||||
#endif
|
||||
import speiger.src.collections.utils.SanityChecks;
|
||||
|
||||
#if TYPE_OBJECT
|
||||
/**
|
||||
* A Type-Specific Array-based implementation of list that is written to reduce (un)boxing
|
||||
*
|
||||
* <p>This implementation is optimized to improve how data is processed with interfaces like {@link IARRAY}, {@link Stack}
|
||||
#if IARRAY_FEATURE
|
||||
* <p>This implementation is optimized to improve how data is processed with interfaces like {@link IARRAY}, {@link STACK}
|
||||
#else
|
||||
* <p>This implementation is optimized to improve how data is processed with interfaces like {@link IArray}, {@link STACK}
|
||||
#endif
|
||||
* and with optimized functions that use type-specific implementations for primitives and optimized logic for bulkactions.
|
||||
*
|
||||
* @Type(T)
|
||||
*/
|
||||
public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE implements IARRAY<KEY_TYPE>, Stack<KEY_TYPE>
|
||||
#if IARRAY_FEATURE
|
||||
public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE implements IARRAY KEY_GENERIC_TYPE, STACK KEY_GENERIC_TYPE
|
||||
#else
|
||||
/**
|
||||
* A Type-Specific Array-based implementation of list that is written to reduce (un)boxing
|
||||
*
|
||||
* <p>This implementation is optimized to improve how data is processed with interfaces like {@link IARRAY}, {@link STACK}
|
||||
* and with optimized functions that use type-specific implementations for primitives and optimized logic for bulkactions.
|
||||
*/
|
||||
public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE implements IARRAY, STACK
|
||||
public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE implements IArray, STACK KEY_GENERIC_TYPE
|
||||
#endif
|
||||
{
|
||||
static final int DEFAULT_ARRAY_SIZE = 10;
|
||||
@@ -202,6 +232,42 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
return list;
|
||||
}
|
||||
|
||||
#endif
|
||||
#if JDK_TYPE && SPLIT_ITERATOR_FEATURE && STREAM_FEATURE
|
||||
#if TYPE_OBJECT
|
||||
/**
|
||||
* Creates a Collector for a ArrayList
|
||||
* @Type(T)
|
||||
* @return a collector
|
||||
*/
|
||||
public static <T> Collector<T, ObjectArrayList<T>, ObjectArrayList<T>> toList() {
|
||||
return Collector.of(ObjectArrayList::new, ObjectArrayList::add, ObjectArrayList::merge);
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects a Stream to a ArrayList
|
||||
* @Type(T)
|
||||
* @return a list with the contents of the Stream
|
||||
*/
|
||||
public static <T> ARRAY_LIST KEY_GENERIC_TYPE toList(Stream<T> stream) {
|
||||
return stream.collect(ObjectArrayList::new, ObjectArrayList::add, ObjectArrayList::merge);
|
||||
}
|
||||
|
||||
private ObjectArrayList<T> merge(ObjectArrayList<T> a) {
|
||||
addAll(a);
|
||||
return this;
|
||||
}
|
||||
|
||||
#else
|
||||
/**
|
||||
* Collects a Stream to a ArrayList
|
||||
* @return a list with the contents of the Stream
|
||||
*/
|
||||
public static ARRAY_LIST toList(JAVA_STREAM stream) {
|
||||
return stream.collect(ARRAY_LIST::new, ARRAY_LIST::add, ARRAY_LIST::addAll);
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
/**
|
||||
* Appends the specified element to the end of this list.
|
||||
@@ -587,6 +653,7 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
return data[(size() - 1) - index];
|
||||
}
|
||||
|
||||
#if IARRAY_FEATURE
|
||||
/**
|
||||
* Provides the Underlying Array in the Implementation
|
||||
* @return underlying Array
|
||||
@@ -606,6 +673,7 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
return data.getClass() != Object[].class;
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
/**
|
||||
* A Type Specific foreach function that reduces (un)boxing
|
||||
@@ -639,7 +707,7 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
public boolean matchesAny(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(int i = 0;i<size;i++) {
|
||||
if(filter.TEST_VALUE(data[i])) return true;
|
||||
if(filter.test(data[i])) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -648,7 +716,7 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
public boolean matchesNone(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(int i = 0;i<size;i++) {
|
||||
if(filter.TEST_VALUE(data[i])) return false;
|
||||
if(filter.test(data[i])) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -657,18 +725,18 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
public boolean matchesAll(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(int i = 0;i<size;i++) {
|
||||
if(!filter.TEST_VALUE(data[i])) return false;
|
||||
if(!filter.test(data[i])) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
public OPTIONAL KEY_GENERIC_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(int i = 0;i<size;i++) {
|
||||
if(filter.TEST_VALUE(data[i])) return data[i];
|
||||
if(filter.test(data[i])) return OPTIONAL.GET_OPTIONAL(data[i]);
|
||||
}
|
||||
return EMPTY_VALUE;
|
||||
return OPTIONAL.empty();
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@@ -695,7 +763,7 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
public OPTIONAL KEY_GENERIC_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = EMPTY_VALUE;
|
||||
boolean empty = true;
|
||||
@@ -707,7 +775,7 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
}
|
||||
state = operator.APPLY_VALUE(state, data[i]);
|
||||
}
|
||||
return state;
|
||||
return empty ? OPTIONAL.empty() : OPTIONAL.GET_OPTIONAL(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -715,7 +783,7 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
Objects.requireNonNull(filter);
|
||||
int result = 0;
|
||||
for(int i = 0;i<size;i++) {
|
||||
if(filter.TEST_VALUE(data[i])) result++;
|
||||
if(filter.test(data[i])) result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -1026,6 +1094,7 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
@Override
|
||||
@Primitive
|
||||
public Object[] toArray() {
|
||||
if(size == 0) return ObjectArrays.EMPTY_ARRAY;
|
||||
Object[] obj = new Object[size];
|
||||
for(int i = 0;i<size;i++)
|
||||
obj[i] = KEY_TO_OBJ(data[i]);
|
||||
@@ -1061,6 +1130,12 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
return a;
|
||||
}
|
||||
|
||||
#else
|
||||
@Override
|
||||
public <E> E[] toArray(IntFunction<E[]> action) {
|
||||
return super.toArray(action);
|
||||
}
|
||||
|
||||
#endif
|
||||
/**
|
||||
* A function to return the size of the list
|
||||
@@ -1159,8 +1234,8 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + size);
|
||||
}
|
||||
|
||||
|
||||
#if PRIMITIVES
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
#if PRIMITIVES && STREAM_FEATURE
|
||||
/**
|
||||
* Returns a Java-Type-Specific Stream to reduce boxing/unboxing.
|
||||
* @return a Stream of the closest java type
|
||||
@@ -1177,4 +1252,5 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
*/
|
||||
@Override
|
||||
public SPLIT_ITERATOR KEY_GENERIC_TYPE spliterator() { return SPLIT_ITERATORS.createArraySplititerator(data, size, 16464); }
|
||||
#endif
|
||||
}
|
||||
+86
-18
@@ -8,16 +8,31 @@ import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Objects;
|
||||
#if JDK_TYPE
|
||||
import java.util.OPTIONAL;
|
||||
#if SPLIT_ITERATOR_FEATURE && STREAM_FEATURE
|
||||
#if TYPE_OBJECT
|
||||
import java.util.stream.Stream;
|
||||
import java.util.stream.Collector;
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
#if TYPE_OBJECT
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.IntFunction;
|
||||
#endif
|
||||
#if !TYPE_OBJECT && JDK_FUNCTION
|
||||
import java.util.function.PREDICATE;
|
||||
#endif
|
||||
import java.util.function.Predicate;
|
||||
import java.util.function.UnaryOperator;
|
||||
#if PRIMITIVES
|
||||
#if !JDK_FUNCTION
|
||||
import java.util.function.JAVA_PREDICATE;
|
||||
#endif
|
||||
import java.util.function.JAVA_UNARY_OPERATOR;
|
||||
import java.nio.JAVA_BUFFER;
|
||||
#endif
|
||||
@@ -27,26 +42,34 @@ import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||
import speiger.src.collections.PACKAGE.collections.STACK;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
#if !JDK_TYPE
|
||||
import speiger.src.collections.PACKAGE.functions.OPTIONAL;
|
||||
#endif
|
||||
#if !TYPE_OBJECT
|
||||
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;
|
||||
#if !JDK_FUNCTION
|
||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
||||
#endif
|
||||
import speiger.src.collections.objects.utils.ObjectArrays;
|
||||
import speiger.src.collections.PACKAGE.utils.ITERATORS;
|
||||
#if TYPE_OBJECT
|
||||
import speiger.src.collections.utils.Stack;
|
||||
#else
|
||||
import speiger.src.collections.objects.utils.ObjectArrays;
|
||||
#endif
|
||||
#if PRIMITIVES
|
||||
#if PRIMITIVES && STREAM_FEATURE && SPLIT_ITERATOR_FEATURE
|
||||
import java.util.stream.JAVA_STREAM;
|
||||
import java.util.stream.StreamSupport;
|
||||
#endif
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
import speiger.src.collections.PACKAGE.collections.SPLIT_ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
||||
#endif
|
||||
import speiger.src.collections.utils.ITrimmable;
|
||||
import speiger.src.collections.utils.SanityChecks;
|
||||
|
||||
@@ -148,14 +171,49 @@ public class COPY_ON_WRITE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENER
|
||||
* @Type(T)
|
||||
* @return a typed List
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES ARRAY_LIST KEY_GENERIC_TYPE of(Class<KEY_TYPE> c) {
|
||||
ARRAY_LIST KEY_GENERIC_TYPE list = new ARRAY_LISTBRACES();
|
||||
public static GENERIC_KEY_BRACES COPY_ON_WRITE_LIST KEY_GENERIC_TYPE of(Class<KEY_TYPE> c) {
|
||||
COPY_ON_WRITE_LIST KEY_GENERIC_TYPE list = new COPY_ON_WRITE_LISTBRACES();
|
||||
list.data = (KEY_TYPE[])ObjectArrays.newArray(c, 0);
|
||||
return list;
|
||||
}
|
||||
|
||||
#endif
|
||||
#if JDK_TYPE && SPLIT_ITERATOR_FEATURE && STREAM_FEATURE
|
||||
#if TYPE_OBJECT
|
||||
/**
|
||||
* Creates a Collector for a CopyOnWriteArrayList
|
||||
* @Type(T)
|
||||
* @return a collector
|
||||
*/
|
||||
public static <T> Collector<T, CopyOnWriteObjectArrayList<T>, CopyOnWriteObjectArrayList<T>> toList() {
|
||||
return Collector.of(CopyOnWriteObjectArrayList::new, CopyOnWriteObjectArrayList::add, CopyOnWriteObjectArrayList::merge);
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects a Stream to a CopyOnWriteArrayList
|
||||
* @Type(T)
|
||||
* @return a list with the contents of the Stream
|
||||
*/
|
||||
public static <T> CopyOnWriteObjectArrayList KEY_GENERIC_TYPE toList(Stream<T> stream) {
|
||||
return stream.collect(CopyOnWriteObjectArrayList::new, CopyOnWriteObjectArrayList::add, CopyOnWriteObjectArrayList::merge);
|
||||
}
|
||||
|
||||
private CopyOnWriteObjectArrayList<T> merge(CopyOnWriteObjectArrayList<T> a) {
|
||||
addAll(a);
|
||||
return this;
|
||||
}
|
||||
|
||||
#else
|
||||
/**
|
||||
* Collects a Stream to a CopyOnWriteArrayList
|
||||
* @return a list with the contents of the Stream
|
||||
*/
|
||||
public static COPY_ON_WRITE_LIST toList(JAVA_STREAM stream) {
|
||||
return stream.collect(COPY_ON_WRITE_LIST::new, COPY_ON_WRITE_LIST::add, COPY_ON_WRITE_LIST::addAll);
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
private void setArray(KEY_TYPE[] data) {
|
||||
this.data = data;
|
||||
}
|
||||
@@ -524,7 +582,7 @@ public class COPY_ON_WRITE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENER
|
||||
* @return if the element was found.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
@Primitive
|
||||
public boolean contains(Object o) {
|
||||
return indexOf(o) != -1;
|
||||
}
|
||||
@@ -535,7 +593,7 @@ public class COPY_ON_WRITE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENER
|
||||
* @return the index of the element if found. (if not found then -1)
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
@Primitive
|
||||
public int indexOf(Object o) {
|
||||
KEY_TYPE[] data = this.data;
|
||||
#if TYPE_OBJECT
|
||||
@@ -559,7 +617,7 @@ public class COPY_ON_WRITE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENER
|
||||
* @return the last index of the element if found. (if not found then -1)
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
@Primitive
|
||||
public int lastIndexOf(Object o) {
|
||||
KEY_TYPE[] data = this.data;
|
||||
#if TYPE_OBJECT
|
||||
@@ -773,7 +831,7 @@ public class COPY_ON_WRITE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENER
|
||||
Objects.requireNonNull(filter);
|
||||
KEY_TYPE[] data = this.data;
|
||||
for(int i = 0,m=data.length;i<m;i++) {
|
||||
if(filter.TEST_VALUE(data[i])) return true;
|
||||
if(filter.test(data[i])) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -783,7 +841,7 @@ public class COPY_ON_WRITE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENER
|
||||
Objects.requireNonNull(filter);
|
||||
KEY_TYPE[] data = this.data;
|
||||
for(int i = 0,m=data.length;i<m;i++) {
|
||||
if(filter.TEST_VALUE(data[i])) return false;
|
||||
if(filter.test(data[i])) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -793,19 +851,19 @@ public class COPY_ON_WRITE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENER
|
||||
Objects.requireNonNull(filter);
|
||||
KEY_TYPE[] data = this.data;
|
||||
for(int i = 0,m=data.length;i<m;i++) {
|
||||
if(!filter.TEST_VALUE(data[i])) return false;
|
||||
if(!filter.test(data[i])) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
public OPTIONAL KEY_GENERIC_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
KEY_TYPE[] data = this.data;
|
||||
for(int i = 0,m=data.length;i<m;i++) {
|
||||
if(filter.TEST_VALUE(data[i])) return data[i];
|
||||
if(filter.test(data[i])) return OPTIONAL.GET_OPTIONAL(data[i]);
|
||||
}
|
||||
return EMPTY_VALUE;
|
||||
return OPTIONAL.empty();
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@@ -834,7 +892,7 @@ public class COPY_ON_WRITE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENER
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
public OPTIONAL KEY_GENERIC_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE[] data = this.data;
|
||||
KEY_TYPE state = EMPTY_VALUE;
|
||||
@@ -847,7 +905,7 @@ public class COPY_ON_WRITE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENER
|
||||
}
|
||||
state = operator.APPLY_VALUE(state, data[i]);
|
||||
}
|
||||
return state;
|
||||
return empty ? OPTIONAL.empty() : OPTIONAL.GET_OPTIONAL(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -856,7 +914,7 @@ public class COPY_ON_WRITE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENER
|
||||
KEY_TYPE[] data = this.data;
|
||||
int result = 0;
|
||||
for(int i = 0,m=data.length;i<m;i++) {
|
||||
if(filter.TEST_VALUE(data[i])) result++;
|
||||
if(filter.test(data[i])) result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -1282,6 +1340,7 @@ public class COPY_ON_WRITE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENER
|
||||
public Object[] toArray() {
|
||||
KEY_TYPE[] data = this.data;
|
||||
int size = data.length;
|
||||
if(size == 0) return ObjectArrays.EMPTY_ARRAY;
|
||||
Object[] obj = new Object[size];
|
||||
for(int i = 0;i<size;i++)
|
||||
obj[i] = KEY_TO_OBJ(data[i]);
|
||||
@@ -1320,6 +1379,11 @@ public class COPY_ON_WRITE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENER
|
||||
if (a.length > size) a[size] = EMPTY_KEY_VALUE;
|
||||
return a;
|
||||
}
|
||||
#else
|
||||
@Override
|
||||
public <E> E[] toArray(IntFunction<E[]> action) {
|
||||
return super.toArray(action);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1409,7 +1473,8 @@ public class COPY_ON_WRITE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENER
|
||||
throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + data.length);
|
||||
}
|
||||
|
||||
#if PRIMITIVES
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
#if PRIMITIVES && STREAM_FEATURE
|
||||
/**
|
||||
* Returns a Java-Type-Specific Stream to reduce boxing/unboxing.
|
||||
* @return a Stream of the closest java type
|
||||
@@ -1427,6 +1492,7 @@ public class COPY_ON_WRITE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENER
|
||||
@Override
|
||||
public SPLIT_ITERATOR KEY_GENERIC_TYPE spliterator() { return SPLIT_ITERATORS.createArraySplititerator(data, data.length, 16464); }
|
||||
|
||||
#endif
|
||||
static final class COWIterator KEY_GENERIC_TYPE implements LIST_ITERATOR KEY_GENERIC_TYPE
|
||||
{
|
||||
KEY_TYPE[] data;
|
||||
@@ -2080,9 +2146,11 @@ public class COPY_ON_WRITE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENER
|
||||
}
|
||||
}
|
||||
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
@Override
|
||||
public SPLIT_ITERATOR KEY_GENERIC_TYPE spliterator() { return SPLIT_ITERATORS.createSplititerator(this, 16464); }
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE listIterator(int index) {
|
||||
if(index < 0 || index > size()) throw new IndexOutOfBoundsException();
|
||||
|
||||
+80
-15
@@ -3,18 +3,40 @@ package speiger.src.collections.PACKAGE.lists;
|
||||
import java.util.Arrays;
|
||||
#if TYPE_OBJECT
|
||||
import java.util.Comparator;
|
||||
#else if !TYPE_BOOLEAN
|
||||
import java.util.stream.JAVA_STREAM;
|
||||
import java.util.stream.StreamSupport;
|
||||
#endif
|
||||
import java.util.Collection;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Objects;
|
||||
#if JDK_TYPE
|
||||
import java.util.OPTIONAL;
|
||||
#if SPLIT_ITERATOR_FEATURE && STREAM_FEATURE
|
||||
#if PRIMITIVES
|
||||
import java.util.function.Supplier;
|
||||
#else
|
||||
import java.util.stream.Stream;
|
||||
import java.util.stream.Collector;
|
||||
#endif
|
||||
|
||||
import speiger.src.collections.PACKAGE.utils.COLLECTIONS;
|
||||
#endif
|
||||
#endif
|
||||
#if TYPE_OBJECT
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Consumer;
|
||||
#endif
|
||||
import java.util.function.Predicate;
|
||||
import java.util.function.UnaryOperator;
|
||||
#if !TYPE_OBJECT && JDK_FUNCTION
|
||||
import java.util.function.PREDICATE;
|
||||
#endif
|
||||
#if PRIMITIVES
|
||||
#if !JDK_FUNCTION
|
||||
import java.util.function.JAVA_PREDICATE;
|
||||
#endif
|
||||
|
||||
import java.util.function.JAVA_UNARY_OPERATOR;
|
||||
#endif
|
||||
|
||||
@@ -22,19 +44,22 @@ import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
#if !JDK_TYPE
|
||||
import speiger.src.collections.PACKAGE.functions.OPTIONAL;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
||||
#endif
|
||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||
#if !JDK_FUNCTION
|
||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||
#endif
|
||||
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
|
||||
import java.util.stream.JAVA_STREAM;
|
||||
import java.util.stream.StreamSupport;
|
||||
#endif
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
import speiger.src.collections.PACKAGE.collections.SPLIT_ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
||||
#endif
|
||||
import speiger.src.collections.utils.SanityChecks;
|
||||
|
||||
#if TYPE_OBJECT
|
||||
@@ -111,6 +136,42 @@ public class IMMUTABLE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_T
|
||||
data = Arrays.copyOfRange(a, offset, offset+length);
|
||||
}
|
||||
|
||||
#if JDK_TYPE && SPLIT_ITERATOR_FEATURE && STREAM_FEATURE
|
||||
#if TYPE_OBJECT
|
||||
/**
|
||||
* Creates a Collector for a ImmutableList
|
||||
* @Type(T)
|
||||
* @return a collector
|
||||
*/
|
||||
public static <T> Collector<T, COLLECTION<T>, ImmutableObjectList<T>> toList() {
|
||||
return Collector.of(COLLECTIONS::wrapper, COLLECTION::add, ImmutableObjectList::merge, E -> new IMMUTABLE_LIST<>(E.toArray((T[])new Object[E.size()])));
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects a Stream to a ImmutableList
|
||||
* @Type(T)
|
||||
* @return a list with the contents of the Stream
|
||||
*/
|
||||
public static <T> ImmutableObjectList KEY_GENERIC_TYPE toList(Stream<T> stream) {
|
||||
return stream.collect(toList());
|
||||
}
|
||||
|
||||
private static <T> COLLECTION<T> merge(COLLECTION<T> a, COLLECTION<T> b) {
|
||||
a.addAll(b);
|
||||
return a;
|
||||
}
|
||||
|
||||
#else
|
||||
/**
|
||||
* Collects a Stream to a ImmutableList
|
||||
* @return a list with the contents of the Stream
|
||||
*/
|
||||
public static IMMUTABLE_LIST toList(JAVA_STREAM stream) {
|
||||
return new IMMUTABLE_LIST(stream.collect((Supplier<COLLECTION>)COLLECTIONS::wrapper, COLLECTION::add, COLLECTION::addAll).TO_ARRAY());
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
@Override
|
||||
public boolean add(KEY_TYPE e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
@@ -129,7 +190,8 @@ public class IMMUTABLE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_T
|
||||
|
||||
@Override
|
||||
public KEY_TYPE[] getElements(int from, KEY_TYPE[] a, int offset, int length) {
|
||||
SanityChecks.checkArrayCapacity(data.length, offset, length);
|
||||
SanityChecks.checkArrayCapacity(a.length, offset, length);
|
||||
SanityChecks.checkArrayCapacity(data.length, from, length);
|
||||
System.arraycopy(data, from, a, offset, length);
|
||||
return a;
|
||||
}
|
||||
@@ -301,7 +363,7 @@ public class IMMUTABLE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_T
|
||||
public boolean matchesAny(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(int i = 0,m=data.length;i<m;i++) {
|
||||
if(filter.TEST_VALUE(data[i])) return true;
|
||||
if(filter.test(data[i])) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -310,7 +372,7 @@ public class IMMUTABLE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_T
|
||||
public boolean matchesNone(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(int i = 0,m=data.length;i<m;i++) {
|
||||
if(filter.TEST_VALUE(data[i])) return false;
|
||||
if(filter.test(data[i])) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -319,18 +381,18 @@ public class IMMUTABLE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_T
|
||||
public boolean matchesAll(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(int i = 0,m=data.length;i<m;i++) {
|
||||
if(!filter.TEST_VALUE(data[i])) return false;
|
||||
if(!filter.test(data[i])) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
public OPTIONAL KEY_GENERIC_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(int i = 0,m=data.length;i<m;i++) {
|
||||
if(filter.TEST_VALUE(data[i])) return data[i];
|
||||
if(filter.test(data[i])) return OPTIONAL.GET_OPTIONAL(data[i]);
|
||||
}
|
||||
return EMPTY_VALUE;
|
||||
return OPTIONAL.empty();
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@@ -357,7 +419,7 @@ public class IMMUTABLE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_T
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
public OPTIONAL KEY_GENERIC_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = EMPTY_VALUE;
|
||||
boolean empty = true;
|
||||
@@ -369,7 +431,7 @@ public class IMMUTABLE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_T
|
||||
}
|
||||
state = operator.APPLY_VALUE(state, data[i]);
|
||||
}
|
||||
return state;
|
||||
return empty ? OPTIONAL.empty() : OPTIONAL.GET_OPTIONAL(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -377,7 +439,7 @@ public class IMMUTABLE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_T
|
||||
Objects.requireNonNull(filter);
|
||||
int result = 0;
|
||||
for(int i = 0,m=data.length;i<m;i++) {
|
||||
if(filter.TEST_VALUE(data[i])) result++;
|
||||
if(filter.test(data[i])) result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -436,6 +498,7 @@ public class IMMUTABLE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_T
|
||||
@Override
|
||||
@Primitive
|
||||
public Object[] toArray() {
|
||||
if(data.length == 0) return ObjectArrays.EMPTY_ARRAY;
|
||||
Object[] obj = new Object[data.length];
|
||||
for(int i = 0,m=data.length;i<m;i++)
|
||||
obj[i] = KEY_TO_OBJ(data[i]);
|
||||
@@ -487,7 +550,8 @@ public class IMMUTABLE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_T
|
||||
throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + data.length);
|
||||
}
|
||||
|
||||
#if PRIMITIVES
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
#if PRIMITIVES && STREAM_FEATURE
|
||||
/**
|
||||
* Returns a Java-Type-Specific Stream to reduce boxing/unboxing.
|
||||
* @return a Stream of the closest java type
|
||||
@@ -505,6 +569,7 @@ public class IMMUTABLE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_T
|
||||
@Override
|
||||
public SPLIT_ITERATOR KEY_GENERIC_TYPE spliterator() { return SPLIT_ITERATORS.createArraySplititerator(data, data.length, 16464); }
|
||||
|
||||
#endif
|
||||
private class LIST_ITER implements LIST_ITERATOR KEY_GENERIC_TYPE {
|
||||
int index;
|
||||
|
||||
|
||||
+148
-34
@@ -1,7 +1,9 @@
|
||||
package speiger.src.collections.PACKAGE.lists;
|
||||
|
||||
#if TYPE_OBJECT
|
||||
#if DEQUEUE_FEATURE
|
||||
import java.util.Comparator;
|
||||
#endif
|
||||
import java.util.function.BiFunction;
|
||||
#else if PRIMITIVES
|
||||
import java.nio.JAVA_BUFFER;
|
||||
@@ -9,45 +11,76 @@ import java.nio.JAVA_BUFFER;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.Objects;
|
||||
#if JDK_TYPE
|
||||
import java.util.OPTIONAL;
|
||||
#if SPLIT_ITERATOR_FEATURE && STREAM_FEATURE
|
||||
#if TYPE_OBJECT
|
||||
import java.util.stream.Stream;
|
||||
import java.util.stream.Collector;
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
import java.util.NoSuchElementException;
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
import java.util.Spliterator;
|
||||
#if PRIMITIVES
|
||||
import java.util.Spliterator.JAVA_SPLIT_ITERATOR;
|
||||
#endif
|
||||
import java.util.function.Consumer;
|
||||
#endif
|
||||
import java.util.function.Predicate;
|
||||
#if TYPE_OBJECT
|
||||
import java.util.function.IntFunction;
|
||||
#endif
|
||||
#if !TYPE_OBJECT && JDK_FUNCTION
|
||||
import java.util.function.PREDICATE;
|
||||
#endif
|
||||
import java.util.function.UnaryOperator;
|
||||
#if PRIMITIVES
|
||||
#if !JDK_FUNCTION
|
||||
import java.util.function.JAVA_PREDICATE;
|
||||
#endif
|
||||
import java.util.function.JAVA_UNARY_OPERATOR;
|
||||
#endif
|
||||
#if !JDK_TYPE
|
||||
import speiger.src.collections.PACKAGE.functions.OPTIONAL;
|
||||
#endif
|
||||
import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
|
||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||
#if !JDK_FUNCTION
|
||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||
#endif
|
||||
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;
|
||||
#if DEQUEUE_FEATURE
|
||||
import speiger.src.collections.PACKAGE.queues.PRIORITY_DEQUEUE;
|
||||
#endif
|
||||
#if !TYPE_OBJECT
|
||||
#if DEQUEUE_FEATURE
|
||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
#endif
|
||||
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
#endif
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
||||
#endif
|
||||
import speiger.src.collections.objects.utils.ObjectArrays;
|
||||
#if TYPE_OBJECT
|
||||
import speiger.src.collections.utils.Stack;
|
||||
#else
|
||||
import speiger.src.collections.objects.utils.ObjectArrays;
|
||||
#endif
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
#if PRIMITIVES
|
||||
import java.util.stream.JAVA_STREAM;
|
||||
import java.util.stream.StreamSupport;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.collections.SPLIT_ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
||||
#endif
|
||||
import speiger.src.collections.utils.SanityChecks;
|
||||
|
||||
/**
|
||||
@@ -62,10 +95,10 @@ import speiger.src.collections.utils.SanityChecks;
|
||||
*
|
||||
* @Type(T)
|
||||
*/
|
||||
#if TYPE_OBJECT
|
||||
public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE implements PRIORITY_DEQUEUE KEY_GENERIC_TYPE, Stack KEY_GENERIC_TYPE
|
||||
#else
|
||||
#if DEQUEUE_FEATURE
|
||||
public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE implements PRIORITY_DEQUEUE KEY_GENERIC_TYPE, STACK KEY_GENERIC_TYPE
|
||||
#else
|
||||
public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE implements STACK KEY_GENERIC_TYPE
|
||||
#endif
|
||||
{
|
||||
Entry KEY_GENERIC_TYPE first;
|
||||
@@ -133,6 +166,42 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
for(int i = offset,m=offset+length;i<m;add(a[i++]));
|
||||
}
|
||||
|
||||
#if JDK_TYPE && SPLIT_ITERATOR_FEATURE && STREAM_FEATURE
|
||||
#if TYPE_OBJECT
|
||||
/**
|
||||
* Creates a Collector for a LinkedList
|
||||
* @Type(T)
|
||||
* @return a collector
|
||||
*/
|
||||
public static <T> Collector<T, ObjectLinkedList<T>, ObjectLinkedList<T>> toList() {
|
||||
return Collector.of(ObjectLinkedList::new, ObjectLinkedList::add, ObjectLinkedList::merge);
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects a Stream to a LinkedList
|
||||
* @Type(T)
|
||||
* @return a list with the contents of the Stream
|
||||
*/
|
||||
public static <T> ObjectLinkedList KEY_GENERIC_TYPE toList(Stream<T> stream) {
|
||||
return stream.collect(ObjectLinkedList::new, ObjectLinkedList::add, ObjectLinkedList::merge);
|
||||
}
|
||||
|
||||
private ObjectLinkedList<T> merge(ObjectLinkedList<T> a) {
|
||||
addAll(a);
|
||||
return this;
|
||||
}
|
||||
|
||||
#else
|
||||
/**
|
||||
* Collects a Stream to a LinkedList
|
||||
* @return a list with the contents of the Stream
|
||||
*/
|
||||
public static LINKED_LIST toList(JAVA_STREAM stream) {
|
||||
return stream.collect(LINKED_LIST::new, LINKED_LIST::add, LINKED_LIST::addAll);
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
@Override
|
||||
public boolean add(KEY_TYPE e) {
|
||||
add(size(), e);
|
||||
@@ -222,6 +291,7 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
return true;
|
||||
}
|
||||
|
||||
#if DEQUEUE_FEATURE
|
||||
@Override
|
||||
public void enqueue(KEY_TYPE e) {
|
||||
add(e);
|
||||
@@ -232,6 +302,7 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
add(0, e);
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public void push(KEY_TYPE e) {
|
||||
add(e);
|
||||
@@ -291,18 +362,41 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
return a;
|
||||
}
|
||||
|
||||
#if DEQUEUE_FEATURE
|
||||
@Override
|
||||
public KEY_TYPE first() {
|
||||
return GET_FIRST_KEY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE last() {
|
||||
return GET_LAST_KEY();
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public KEY_TYPE GET_FIRST_KEY() {
|
||||
if(first == null) throw new NoSuchElementException();
|
||||
return first.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE last() {
|
||||
public KEY_TYPE GET_LAST_KEY() {
|
||||
if(last == null) throw new NoSuchElementException();
|
||||
return last.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE REMOVE_FIRST_KEY() {
|
||||
if(first == null) throw new NoSuchElementException();
|
||||
return unlinkFirst(first);
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE REMOVE_LAST_KEY() {
|
||||
return pop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE peek(int index) {
|
||||
return GET_KEY((size() - 1) - index);
|
||||
@@ -373,6 +467,7 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
return new ListIter(getNode(index), index);
|
||||
}
|
||||
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
#if PRIMITIVES
|
||||
/**
|
||||
* Returns a Java-Type-Specific Stream to reduce boxing/unboxing.
|
||||
@@ -393,6 +488,7 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
@Override
|
||||
public SPLIT_ITERATOR KEY_GENERIC_TYPE spliterator() { return new TypeSplitIteratorBRACES(this, first, 0); }
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) {
|
||||
Objects.requireNonNull(action);
|
||||
@@ -401,6 +497,14 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
|
||||
Objects.requireNonNull(action);
|
||||
int index = 0;
|
||||
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next)
|
||||
action.accept(index++, entry.value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
@@ -412,7 +516,7 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
public boolean matchesAny(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next) {
|
||||
if(filter.TEST_VALUE(entry.value)) return true;
|
||||
if(filter.test(entry.value)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -421,7 +525,7 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
public boolean matchesNone(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next) {
|
||||
if(filter.TEST_VALUE(entry.value)) return false;
|
||||
if(filter.test(entry.value)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -430,18 +534,18 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
public boolean matchesAll(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next) {
|
||||
if(!filter.TEST_VALUE(entry.value)) return false;
|
||||
if(!filter.test(entry.value)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
public OPTIONAL KEY_GENERIC_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next) {
|
||||
if(filter.TEST_VALUE(entry.value)) return entry.value;
|
||||
if(filter.test(entry.value)) return OPTIONAL.GET_OPTIONAL(entry.value);
|
||||
}
|
||||
return EMPTY_VALUE;
|
||||
return OPTIONAL.empty();
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@@ -468,7 +572,7 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
public OPTIONAL KEY_GENERIC_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = EMPTY_VALUE;
|
||||
boolean empty = true;
|
||||
@@ -480,7 +584,7 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
}
|
||||
state = operator.APPLY_VALUE(state, entry.value);
|
||||
}
|
||||
return state;
|
||||
return empty ? OPTIONAL.empty() : OPTIONAL.GET_OPTIONAL(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -488,7 +592,7 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
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++;
|
||||
if(filter.test(entry.value)) result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -525,6 +629,7 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
}
|
||||
|
||||
#endif
|
||||
#if DEQUEUE_FEATURE
|
||||
@Override
|
||||
public void onChanged() {}
|
||||
@Override
|
||||
@@ -538,25 +643,24 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
|
||||
@Override
|
||||
public KEY_TYPE dequeueLast() {
|
||||
return pop();
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public KEY_TYPE pop() {
|
||||
if(last == null) throw new NoSuchElementException();
|
||||
return unlinkLast(last);
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE pop() {
|
||||
return dequeueLast();
|
||||
}
|
||||
|
||||
#if DEQUEUE_FEATURE
|
||||
@Override
|
||||
public boolean removeFirst(KEY_TYPE e) {
|
||||
if(size == 0) return false;
|
||||
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next) {
|
||||
if(KEY_EQUALS(entry.value, e)) {
|
||||
unlink(entry);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
#if TYPE_OBJECT
|
||||
return remove(e);
|
||||
#else
|
||||
return REMOVE_KEY(e);
|
||||
#endif
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -571,6 +675,7 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
return false;
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public KEY_TYPE swapRemove(int index) {
|
||||
checkRange(index);
|
||||
@@ -653,7 +758,14 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
#else
|
||||
@Override
|
||||
public boolean REMOVE_KEY(KEY_TYPE e) {
|
||||
return removeFirst(e);
|
||||
if(size == 0) return false;
|
||||
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next) {
|
||||
if(KEY_EQUALS(entry.value, e)) {
|
||||
unlink(entry);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -931,6 +1043,7 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
#endif
|
||||
@Override
|
||||
public Object[] toArray() {
|
||||
if(size == 0) return ObjectArrays.EMPTY_ARRAY;
|
||||
Object[] obj = new Object[size];
|
||||
int i = 0;
|
||||
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next) {
|
||||
@@ -965,7 +1078,7 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
|
||||
#else
|
||||
@Override
|
||||
public T[] toArray(Int2ObjectFunction<T[]> action) {
|
||||
public <E> E[] toArray(IntFunction<E[]> action) {
|
||||
return super.toArray(action);
|
||||
}
|
||||
|
||||
@@ -1108,8 +1221,7 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
Entry KEY_GENERIC_TYPE prev;
|
||||
Entry KEY_GENERIC_TYPE next;
|
||||
|
||||
public Entry(KEY_TYPE value, Entry KEY_GENERIC_TYPE prev, Entry KEY_GENERIC_TYPE next)
|
||||
{
|
||||
public Entry(KEY_TYPE value, Entry KEY_GENERIC_TYPE prev, Entry KEY_GENERIC_TYPE next) {
|
||||
this.value = value;
|
||||
this.prev = prev;
|
||||
this.next = next;
|
||||
@@ -1194,6 +1306,7 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
}
|
||||
}
|
||||
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
private static class TypeSplitIterator KEY_GENERIC_TYPE implements SPLIT_ITERATOR KEY_GENERIC_TYPE
|
||||
{
|
||||
static final int BATCH_UNIT = 1 << 10;
|
||||
@@ -1338,4 +1451,5 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
@@ -5,23 +5,34 @@ import java.nio.JAVA_BUFFER;
|
||||
#endif
|
||||
import java.util.List;
|
||||
#if !TYPE_OBJECT && !TYPE_BOOLEAN
|
||||
import java.util.Objects;
|
||||
import java.util.function.JAVA_UNARY_OPERATOR;
|
||||
import java.util.function.UnaryOperator;
|
||||
#else if TYPE_OBJECT
|
||||
#endif
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Comparator;
|
||||
#if !TYPE_BOOLEAN
|
||||
import java.util.function.UnaryOperator;
|
||||
#endif
|
||||
import java.util.Comparator;
|
||||
|
||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||
import speiger.src.collections.PACKAGE.collections.ORDERED_COLLECTION;
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
import speiger.src.collections.PACKAGE.collections.SPLIT_ITERATOR;
|
||||
#endif
|
||||
import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
||||
#if LISTS_FEATURE
|
||||
import speiger.src.collections.PACKAGE.utils.LISTS;
|
||||
#endif
|
||||
#if INT_LIST_MODULE && !TYPE_INT
|
||||
import speiger.src.collections.ints.lists.IntList;
|
||||
#endif
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
||||
#endif
|
||||
#if TYPE_BYTE || TYPE_SHORT || TYPE_CHAR || TYPE_FLOAT
|
||||
import speiger.src.collections.utils.SanityChecks;
|
||||
#endif
|
||||
@@ -30,7 +41,7 @@ import speiger.src.collections.utils.SanityChecks;
|
||||
* A Type Specific List interface that reduces boxing/unboxing and adds a couple extra quality of life features
|
||||
* @Type(T)
|
||||
*/
|
||||
public interface LIST KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, List<CLASS_TYPE>
|
||||
public interface LIST KEY_GENERIC_TYPE extends ORDERED_COLLECTION KEY_GENERIC_TYPE, List<CLASS_TYPE>
|
||||
{
|
||||
#if !TYPE_OBJECT
|
||||
/**
|
||||
@@ -95,6 +106,64 @@ public interface LIST KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, List
|
||||
*/
|
||||
public boolean addAll(int index, LIST KEY_GENERIC_TYPE c);
|
||||
|
||||
/**
|
||||
* A method to add an element to the start of a list
|
||||
* @param e that should be added at the start.
|
||||
*/
|
||||
@Override
|
||||
public default void addFirst(KEY_TYPE e) {
|
||||
add(0, e);
|
||||
}
|
||||
|
||||
/**
|
||||
* A method to add an element to the end of a list
|
||||
* @param e that should be added at the end.
|
||||
*/
|
||||
@Override
|
||||
public default void addLast(KEY_TYPE e) {
|
||||
add(e);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method that returns the first element of a List.
|
||||
* This function was introduced due to how annoying it is to get/remove the last element of a list.
|
||||
* This simplifies this process a bit.
|
||||
* @return first element of the list
|
||||
*/
|
||||
public default KEY_TYPE GET_FIRST_KEY() {
|
||||
return GET_KEY(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method that returns the last element of a List.
|
||||
* This function was introduced due to how annoying it is to get/remove the last element of a list.
|
||||
* This simplifies this process a bit.
|
||||
* @return last element of the list
|
||||
*/
|
||||
public default KEY_TYPE GET_LAST_KEY() {
|
||||
return GET_KEY(size() - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method that removes and returns the first element of a List.
|
||||
* This function was introduced due to how annoying it is to get/remove the last element of a list.
|
||||
* This simplifies this process a bit.
|
||||
* @return first element of the list and removes it
|
||||
*/
|
||||
public default KEY_TYPE REMOVE_FIRST_KEY() {
|
||||
return REMOVE(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method that removes and returns the last element of a List.
|
||||
* This function was introduced due to how annoying it is to get/remove the last element of a list.
|
||||
* This simplifies this process a bit.
|
||||
* @return last element of the list and removes it
|
||||
*/
|
||||
public default KEY_TYPE REMOVE_LAST_KEY() {
|
||||
return REMOVE(size() - 1);
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
/**
|
||||
* A Type-Specific get function to reduce (un)boxing
|
||||
@@ -358,6 +427,16 @@ public interface LIST KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, List
|
||||
}
|
||||
|
||||
#endif
|
||||
/**
|
||||
* A Indexed forEach implementation that allows you to keep track of how many elements were already iterated over.
|
||||
* @param action The action to be performed for each element
|
||||
* @throws java.lang.NullPointerException if the specified action is null
|
||||
*/
|
||||
@Override
|
||||
public default void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
|
||||
Objects.requireNonNull(action);
|
||||
for(int i = 0,m=size();i<m;action.accept(i, GET_KEY(i++)));
|
||||
}
|
||||
/**
|
||||
* A Type-Specific Iterator of listIterator
|
||||
* @see java.util.List#listIterator
|
||||
@@ -372,6 +451,26 @@ public interface LIST KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, List
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE listIterator(int index);
|
||||
|
||||
/**
|
||||
* Creates a Iterator that follows the indecies provided.<br>
|
||||
* For example if the Lists Contents is:<br> -1, 0 1 <br>and the indecies are: <br>0, 1, 2, 2, 1, 0<br>
|
||||
* then the iterator will return the following values: <br>-1, 0, 1, 1, 0, -1
|
||||
* @param indecies that should be used for the iteration.
|
||||
* @return a custom indexed iterator
|
||||
*/
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE indexedIterator(int...indecies);
|
||||
|
||||
#if INT_LIST_MODULE
|
||||
/**
|
||||
* Creates a Iterator that follows the indecies provided.<br>
|
||||
* For example if the Lists Contents is:<br> -1, 0 1 <br>and the indecies are: <br>0, 1, 2, 2, 1, 0<br>
|
||||
* then the iterator will return the following values: <br>-1, 0, 1, 1, 0, -1
|
||||
* @param indecies that should be used for the iteration.
|
||||
* @return a custom indexed iterator
|
||||
*/
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE indexedIterator(IntList indecies);
|
||||
|
||||
#endif
|
||||
/**
|
||||
* A Type-Specific List of subList
|
||||
* @see java.util.List#subList(int, int)
|
||||
@@ -379,6 +478,13 @@ public interface LIST KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, List
|
||||
@Override
|
||||
public LIST KEY_GENERIC_TYPE subList(int from, int to);
|
||||
|
||||
/**
|
||||
* A Type-Specific List Helper that shows all elements in reverse.
|
||||
* @return a list wrapper that has all elements reversed!
|
||||
*/
|
||||
public LIST KEY_GENERIC_TYPE reversed();
|
||||
|
||||
#if LISTS_FEATURE
|
||||
/**
|
||||
* Creates a Wrapped List that is Synchronized
|
||||
* @return a new List that is synchronized
|
||||
@@ -401,6 +507,7 @@ public interface LIST KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, List
|
||||
*/
|
||||
public default LIST KEY_GENERIC_TYPE unmodifiable() { return LISTS.unmodifiable(this); }
|
||||
|
||||
#endif
|
||||
/**
|
||||
* A function to ensure the elements are within the requested size.
|
||||
* If smaller then the stored elements they get removed as needed.
|
||||
@@ -420,9 +527,56 @@ public interface LIST KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, List
|
||||
@Override
|
||||
@Deprecated
|
||||
public default boolean add(CLASS_TYPE e) {
|
||||
return COLLECTION.super.add(e);
|
||||
return ORDERED_COLLECTION.super.add(e);
|
||||
}
|
||||
|
||||
#if JAVA_VERSION>=21
|
||||
#if !TYPE_OBJECT
|
||||
/** {@inheritDoc}
|
||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||
* @deprecated Please use the corresponding type-specific function instead.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
default void addFirst(CLASS_TYPE e) {
|
||||
addFirst(OBJ_TO_KEY(e));
|
||||
}
|
||||
/** {@inheritDoc}
|
||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||
* @deprecated Please use the corresponding type-specific function instead.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
default void addLast(CLASS_TYPE e) {
|
||||
addLast(OBJ_TO_KEY(e));
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
@Deprecated
|
||||
default CLASS_TYPE getFirst() {
|
||||
return KEY_TO_OBJ(GET_FIRST_KEY());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
default CLASS_TYPE getLast() {
|
||||
return KEY_TO_OBJ(GET_LAST_KEY());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
default CLASS_TYPE removeFirst() {
|
||||
return KEY_TO_OBJ(REMOVE_FIRST_KEY());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
default CLASS_TYPE removeLast() {
|
||||
return KEY_TO_OBJ(REMOVE_LAST_KEY());
|
||||
}
|
||||
|
||||
#endif
|
||||
/** {@inheritDoc}
|
||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||
* @deprecated Please use the corresponding type-specific function instead.
|
||||
@@ -470,7 +624,7 @@ public interface LIST KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, List
|
||||
@Override
|
||||
@Deprecated
|
||||
public default boolean contains(Object o) {
|
||||
return COLLECTION.super.contains(o);
|
||||
return ORDERED_COLLECTION.super.contains(o);
|
||||
}
|
||||
|
||||
/** {@inheritDoc}
|
||||
@@ -480,7 +634,7 @@ public interface LIST KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, List
|
||||
@Override
|
||||
@Deprecated
|
||||
public default boolean remove(Object o) {
|
||||
return COLLECTION.super.remove(o);
|
||||
return ORDERED_COLLECTION.super.remove(o);
|
||||
}
|
||||
|
||||
/** {@inheritDoc}
|
||||
@@ -510,10 +664,12 @@ public interface LIST KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, List
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
/**
|
||||
* A Type Specific Type Splititerator to reduce boxing/unboxing
|
||||
* @return type specific splititerator
|
||||
*/
|
||||
@Override
|
||||
default SPLIT_ITERATOR KEY_GENERIC_TYPE spliterator() { return SPLIT_ITERATORS.createSplititerator(this, 0); }
|
||||
#endif
|
||||
}
|
||||
+267
-17
@@ -3,15 +3,31 @@ package speiger.src.collections.PACKAGE.maps.abstracts;
|
||||
import java.util.AbstractMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
#if VALUE_BOOLEAN && JDK_FUNCTION
|
||||
import java.util.function.PREDICATE;
|
||||
#endif
|
||||
|
||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
|
||||
#if !VALUE_BOOLEAN || !JDK_FUNCTION
|
||||
import speiger.src.collections.PACKAGE.functions.function.FUNCTION;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||
import speiger.src.collections.PACKAGE.maps.interfaces.MAP;
|
||||
#if ORDERED_MAP_FEATURE
|
||||
import speiger.src.collections.PACKAGE.maps.interfaces.ORDERED_MAP;
|
||||
import speiger.src.collections.PACKAGE.sets.ORDERED_SET;
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ORDERED_COLLECTION;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.objects.sets.AbstractObjectSet;
|
||||
import speiger.src.collections.objects.sets.ObjectOrderedSet;
|
||||
#endif
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.sets.ABSTRACT_SET;
|
||||
import speiger.src.collections.PACKAGE.sets.SET;
|
||||
#if MAPS_FEATURE
|
||||
import speiger.src.collections.PACKAGE.utils.maps.MAPS;
|
||||
#endif
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ABSTRACT_COLLECTION;
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_COLLECTION;
|
||||
#if !SAME_TYPE
|
||||
@@ -19,6 +35,7 @@ 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;
|
||||
import speiger.src.collections.objects.collections.ObjectIterable;
|
||||
#if !TYPE_OBJECT && !VALUE_OBJECT
|
||||
import speiger.src.collections.objects.collections.ObjectIterator;
|
||||
#endif
|
||||
@@ -34,7 +51,7 @@ import speiger.src.collections.utils.SanityChecks;
|
||||
*/
|
||||
public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE extends AbstractMap<CLASS_TYPE, CLASS_VALUE_TYPE> implements MAP KEY_VALUE_GENERIC_TYPE
|
||||
{
|
||||
protected VALUE_TYPE defaultReturnValue = EMPTY_VALUE;
|
||||
protected VALUE_TYPE defaultReturnValue = INVALID_VALUE;
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE getDefaultReturnValue() {
|
||||
@@ -47,6 +64,22 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE extends AbstractMap<CL
|
||||
return this;
|
||||
}
|
||||
|
||||
protected ObjectIterable<MAP.Entry KEY_VALUE_GENERIC_TYPE> getFastIterable(MAP KEY_VALUE_GENERIC_TYPE map) {
|
||||
#if MAPS_FEATURE
|
||||
return MAPS.fastIterable(map);
|
||||
#else
|
||||
return map.ENTRY_SET();
|
||||
#endif
|
||||
}
|
||||
|
||||
protected ObjectIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> getFastIterator(MAP KEY_VALUE_GENERIC_TYPE map) {
|
||||
#if MAPS_FEATURE
|
||||
return MAPS.fastIterator(map);
|
||||
#else
|
||||
return map.ENTRY_SET().iterator();
|
||||
#endif
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP KEY_VALUE_GENERIC_TYPE copy() {
|
||||
throw new UnsupportedOperationException();
|
||||
@@ -63,14 +96,14 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE extends AbstractMap<CL
|
||||
#if VALUE_PRIMITIVES
|
||||
@Override
|
||||
public void addToAll(MAP KEY_VALUE_GENERIC_TYPE m) {
|
||||
for(MAP.Entry KEY_VALUE_GENERIC_TYPE entry : MAPS.fastIterable(m))
|
||||
for(MAP.Entry KEY_VALUE_GENERIC_TYPE entry : getFastIterable(m))
|
||||
addTo(entry.ENTRY_KEY(), entry.ENTRY_VALUE());
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public void putAll(MAP KEY_VALUE_GENERIC_TYPE m) {
|
||||
for(ObjectIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> iter = MAPS.fastIterator(m);iter.hasNext();) {
|
||||
for(ObjectIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> iter = getFastIterator(m);iter.hasNext();) {
|
||||
MAP.Entry KEY_VALUE_GENERIC_TYPE entry = iter.next();
|
||||
put(entry.ENTRY_KEY(), entry.ENTRY_VALUE());
|
||||
}
|
||||
@@ -95,13 +128,13 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE extends AbstractMap<CL
|
||||
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]);
|
||||
for(int i = 0;i<size;i++) put(OBJ_TO_KEY(keys[i]), OBJ_TO_VALUE(values[i]));
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public void putAllIfAbsent(MAP KEY_VALUE_GENERIC_TYPE m) {
|
||||
for(MAP.Entry KEY_VALUE_GENERIC_TYPE entry : MAPS.fastIterable(m))
|
||||
for(MAP.Entry KEY_VALUE_GENERIC_TYPE entry : getFastIterable(m))
|
||||
putIfAbsent(entry.ENTRY_KEY(), entry.ENTRY_VALUE());
|
||||
}
|
||||
|
||||
@@ -161,14 +194,14 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE extends AbstractMap<CL
|
||||
|
||||
@Override
|
||||
public void REPLACE_VALUES(MAP KEY_VALUE_GENERIC_TYPE m) {
|
||||
for(MAP.Entry KEY_VALUE_GENERIC_TYPE entry : MAPS.fastIterable(m))
|
||||
for(MAP.Entry KEY_VALUE_GENERIC_TYPE entry : getFastIterable(m))
|
||||
replace(entry.ENTRY_KEY(), entry.ENTRY_VALUE());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void REPLACE_VALUES(UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
for(ObjectIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> iter = MAPS.fastIterator(this);iter.hasNext();) {
|
||||
for(ObjectIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> iter = getFastIterator(this);iter.hasNext();) {
|
||||
MAP.Entry KEY_VALUE_GENERIC_TYPE entry = iter.next();
|
||||
entry.setValue(mappingFunction.APPLY_VALUE(entry.ENTRY_KEY(), entry.ENTRY_VALUE()));
|
||||
}
|
||||
@@ -177,6 +210,96 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE extends AbstractMap<CL
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
#if !VALUE_OBJECT
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, GET_VALUE(key));
|
||||
#else
|
||||
VALUE_TYPE value = GET_VALUE(key);
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, value);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
if(VALUE_EQUALS_NOT(value, getDefaultReturnValue()) || containsKey(key)) {
|
||||
remove(key);
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
#endif
|
||||
put(key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_ABSENT(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
#if VALUE_OBJECT
|
||||
VALUE_TYPE value;
|
||||
if((value = GET_VALUE(key)) == getDefaultReturnValue() || !containsKey(key)) {
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY(key);
|
||||
if(VALUE_EQUALS_NOT(newValue, getDefaultReturnValue())) {
|
||||
put(key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
}
|
||||
return value;
|
||||
#else
|
||||
if(!containsKey(key)) {
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY(key);
|
||||
put(key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
return get(key);
|
||||
#endif
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENT(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
|
||||
Objects.requireNonNull(valueProvider);
|
||||
#if VALUE_OBJECT
|
||||
VALUE_TYPE value;
|
||||
if((value = GET_VALUE(key)) == getDefaultReturnValue() || !containsKey(key)) {
|
||||
VALUE_TYPE newValue = valueProvider.VALUE_SUPPLY_GET();
|
||||
if(VALUE_EQUALS_NOT(newValue, getDefaultReturnValue())) {
|
||||
put(key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
}
|
||||
return value;
|
||||
#else
|
||||
if(!containsKey(key)) {
|
||||
VALUE_TYPE newValue = valueProvider.VALUE_SUPPLY_GET();
|
||||
put(key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
return get(key);
|
||||
#endif
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
#if VALUE_OBJECT
|
||||
VALUE_TYPE value;
|
||||
if(VALUE_EQUALS_NOT((value = GET_VALUE(key)), getDefaultReturnValue()) || containsKey(key)) {
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, value);
|
||||
if(VALUE_EQUALS_NOT(newValue, getDefaultReturnValue())) {
|
||||
put(key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
remove(key);
|
||||
}
|
||||
#else
|
||||
if(containsKey(key)) {
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, GET_VALUE(key));
|
||||
put(key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
#endif
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
#if !VALUE_OBJECT
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTENonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
VALUE_TYPE value = GET_VALUE(key);
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, value);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
@@ -191,11 +314,11 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE extends AbstractMap<CL
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_ABSENT(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
public VALUE_TYPE COMPUTE_IF_ABSENTNonDefault(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
VALUE_TYPE value;
|
||||
if((value = GET_VALUE(key)) == getDefaultReturnValue() || !containsKey(key)) {
|
||||
VALUE_TYPE newValue = mappingFunction.GET_VALUE(key);
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY(key);
|
||||
if(VALUE_EQUALS_NOT(newValue, getDefaultReturnValue())) {
|
||||
put(key, newValue);
|
||||
return newValue;
|
||||
@@ -205,11 +328,11 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE extends AbstractMap<CL
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENT(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENTNonDefault(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();
|
||||
VALUE_TYPE newValue = valueProvider.VALUE_SUPPLY_GET();
|
||||
if(VALUE_EQUALS_NOT(newValue, getDefaultReturnValue())) {
|
||||
put(key, newValue);
|
||||
return newValue;
|
||||
@@ -219,7 +342,7 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE extends AbstractMap<CL
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENTNonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
VALUE_TYPE value;
|
||||
if(VALUE_EQUALS_NOT((value = GET_VALUE(key)), getDefaultReturnValue()) || containsKey(key)) {
|
||||
@@ -233,6 +356,7 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE extends AbstractMap<CL
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public VALUE_TYPE MERGE(KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
@@ -246,7 +370,7 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE extends AbstractMap<CL
|
||||
@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)) {
|
||||
for(MAP.Entry KEY_VALUE_GENERIC_TYPE entry : getFastIterable(m)) {
|
||||
KEY_TYPE key = entry.ENTRY_KEY();
|
||||
VALUE_TYPE oldValue = GET_VALUE(key);
|
||||
VALUE_TYPE newValue = VALUE_EQUALS(oldValue, getDefaultReturnValue()) ? entry.ENTRY_VALUE() : mappingFunction.APPLY_VALUE(oldValue, entry.ENTRY_VALUE());
|
||||
@@ -298,7 +422,7 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE extends AbstractMap<CL
|
||||
@Override
|
||||
public void forEach(BI_CONSUMER KEY_VALUE_GENERIC_TYPE action) {
|
||||
Objects.requireNonNull(action);
|
||||
for(ObjectIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> iter = MAPS.fastIterator(this);iter.hasNext();) {
|
||||
for(ObjectIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> iter = getFastIterator(this);iter.hasNext();) {
|
||||
MAP.Entry KEY_VALUE_GENERIC_TYPE entry = iter.next();
|
||||
action.accept(entry.ENTRY_KEY(), entry.ENTRY_VALUE());
|
||||
}
|
||||
@@ -332,7 +456,7 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE extends AbstractMap<CL
|
||||
@Override
|
||||
public ITERATOR KEY_GENERIC_TYPE iterator() {
|
||||
return new ITERATOR KEY_GENERIC_TYPE() {
|
||||
ObjectIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> iter = MAPS.fastIterator(ABSTRACT_MAP.this);
|
||||
ObjectIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> iter = getFastIterator(ABSTRACT_MAP.this);
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return iter.hasNext();
|
||||
@@ -383,7 +507,7 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE extends AbstractMap<CL
|
||||
@Override
|
||||
public VALUE_ITERATOR VALUE_GENERIC_TYPE iterator() {
|
||||
return new VALUE_ITERATOR VALUE_GENERIC_TYPE() {
|
||||
ObjectIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> iter = MAPS.fastIterator(ABSTRACT_MAP.this);
|
||||
ObjectIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> iter = getFastIterator(ABSTRACT_MAP.this);
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return iter.hasNext();
|
||||
@@ -423,11 +547,137 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE extends AbstractMap<CL
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 0;
|
||||
ObjectIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> iter = MAPS.fastIterator(this);
|
||||
ObjectIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> iter = getFastIterator(this);
|
||||
while(iter.hasNext()) hash += iter.next().hashCode();
|
||||
return hash;
|
||||
}
|
||||
|
||||
public static class REVERSED_ORDERED_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE implements ORDERED_MAP KEY_VALUE_GENERIC_TYPE {
|
||||
ORDERED_MAP KEY_VALUE_GENERIC_TYPE map;
|
||||
|
||||
public REVERSED_ORDERED_MAP(ORDERED_MAP KEY_VALUE_GENERIC_TYPE map) {
|
||||
this.map = map;
|
||||
}
|
||||
@Override
|
||||
public ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE setDefaultReturnValue(VALUE_TYPE v) {
|
||||
map.setDefaultReturnValue(v);
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
public VALUE_TYPE getDefaultReturnValue() { return map.getDefaultReturnValue(); }
|
||||
@Override
|
||||
public ORDERED_MAP KEY_VALUE_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE put(KEY_TYPE key, VALUE_TYPE value) { return map.put(key, value); }
|
||||
@Override
|
||||
public VALUE_TYPE putIfAbsent(KEY_TYPE key, VALUE_TYPE value) { return map.putIfAbsent(key, value); }
|
||||
#if VALUE_PRIMITIVES
|
||||
@Override
|
||||
public VALUE_TYPE addTo(KEY_TYPE key, VALUE_TYPE value) { return map.addTo(key, value); }
|
||||
@Override
|
||||
public VALUE_TYPE subFrom(KEY_TYPE key, VALUE_TYPE value) { return map.subFrom(key, value); }
|
||||
#endif
|
||||
@Override
|
||||
public VALUE_TYPE REMOVE_VALUE(KEY_TYPE key) { return map.REMOVE_VALUE(key); }
|
||||
#if !TYPE_OBJECT || !VALUE_OBJECT
|
||||
@Override
|
||||
public boolean remove(KEY_TYPE key, VALUE_TYPE value) { return map.remove(key, value); }
|
||||
#endif
|
||||
@Override
|
||||
public VALUE_TYPE REMOVE_VALUEOrDefault(KEY_TYPE key, VALUE_TYPE defaultValue) { return map.REMOVE_VALUEOrDefault(key, defaultValue); }
|
||||
@Override
|
||||
#if TYPE_OBJECT
|
||||
public boolean containsKey(Object key) { return map.containsKey(key); }
|
||||
#else
|
||||
public boolean containsKey(KEY_TYPE key) { return map.containsKey(key); }
|
||||
#endif
|
||||
@Override
|
||||
#if VALUE_OBJECT
|
||||
public boolean containsValue(Object value) { return map.containsValue(value); }
|
||||
#else
|
||||
public boolean containsValue(VALUE_TYPE value) { return map.containsValue(value); }
|
||||
#endif
|
||||
@Override
|
||||
public boolean replace(KEY_TYPE key, VALUE_TYPE oldValue, VALUE_TYPE newValue) { return map.replace(key, oldValue, newValue); }
|
||||
@Override
|
||||
public VALUE_TYPE replace(KEY_TYPE key, VALUE_TYPE value) { return map.replace(key, value); }
|
||||
@Override
|
||||
public void REPLACE_VALUES(MAP KEY_VALUE_GENERIC_TYPE m) { map.REPLACE_VALUES(m); }
|
||||
@Override
|
||||
public void REPLACE_VALUES(UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { map.REPLACE_VALUES(mappingFunction); }
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { return map.COMPUTE(key, mappingFunction); }
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_ABSENT(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) { return map.COMPUTE_IF_ABSENT(key, mappingFunction); }
|
||||
@Override
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENT(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) { return map.SUPPLY_IF_ABSENT(key, valueProvider); }
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { return map.COMPUTE_IF_PRESENT(key, mappingFunction); }
|
||||
#if !VALUE_OBJECT
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTENonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { return map.COMPUTENonDefault(key, mappingFunction); }
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_ABSENTNonDefault(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) { return map.COMPUTE_IF_ABSENTNonDefault(key, mappingFunction); }
|
||||
@Override
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENTNonDefault(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) { return map.SUPPLY_IF_ABSENTNonDefault(key, valueProvider); }
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENTNonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { return map.COMPUTE_IF_PRESENTNonDefault(key, mappingFunction); }
|
||||
#endif
|
||||
@Override
|
||||
public VALUE_TYPE MERGE(KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) { return map.MERGE(key, value, mappingFunction); }
|
||||
#if !TYPE_OBJECT || !VALUE_OBJECT
|
||||
@Override
|
||||
public VALUE_TYPE getOrDefault(KEY_TYPE key, VALUE_TYPE defaultValue) { return map.getOrDefault(key, defaultValue); }
|
||||
#endif
|
||||
@Override
|
||||
public VALUE_TYPE GET_VALUE(KEY_TYPE key) { return map.GET_VALUE(key); }
|
||||
@Override
|
||||
public VALUE_TYPE putAndMoveToFirst(KEY_TYPE key, VALUE_TYPE value) { return map.putAndMoveToLast(key, value); }
|
||||
@Override
|
||||
public VALUE_TYPE putAndMoveToLast(KEY_TYPE key, VALUE_TYPE value) { return map.putAndMoveToFirst(key, value); }
|
||||
@Override
|
||||
public VALUE_TYPE putFirst(KEY_TYPE key, VALUE_TYPE value) { return map.putLast(key, value); }
|
||||
@Override
|
||||
public VALUE_TYPE putLast(KEY_TYPE key, VALUE_TYPE value) { return map.putFirst(key, value); }
|
||||
@Override
|
||||
public boolean moveToFirst(KEY_TYPE key) { return map.moveToLast(key); }
|
||||
@Override
|
||||
public boolean moveToLast(KEY_TYPE key) { return map.moveToFirst(key); }
|
||||
@Override
|
||||
public VALUE_TYPE getAndMoveToFirst(KEY_TYPE key) { return map.getAndMoveToLast(key); }
|
||||
@Override
|
||||
public VALUE_TYPE getAndMoveToLast(KEY_TYPE key) { return map.getAndMoveToFirst(key); }
|
||||
@Override
|
||||
public KEY_TYPE FIRST_ENTRY_KEY() { return map.LAST_ENTRY_KEY(); }
|
||||
@Override
|
||||
public KEY_TYPE POLL_FIRST_ENTRY_KEY() { return map.POLL_LAST_ENTRY_KEY(); }
|
||||
@Override
|
||||
public KEY_TYPE LAST_ENTRY_KEY() { return map.FIRST_ENTRY_KEY(); }
|
||||
@Override
|
||||
public KEY_TYPE POLL_LAST_ENTRY_KEY() { return map.POLL_FIRST_ENTRY_KEY(); }
|
||||
@Override
|
||||
public VALUE_TYPE FIRST_ENTRY_VALUE() { return map.LAST_ENTRY_VALUE(); }
|
||||
@Override
|
||||
public VALUE_TYPE LAST_ENTRY_VALUE() { return map.FIRST_ENTRY_VALUE(); }
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE firstEntry() { return map.lastEntry(); }
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE lastEntry() { return map.firstEntry(); }
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollFirstEntry() { return map.pollLastEntry(); }
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollLastEntry() { return map.pollFirstEntry(); }
|
||||
@Override
|
||||
public ObjectOrderedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> ENTRY_SET() { return new AbstractObjectSet.ReversedObjectOrderedSet<>(map.ENTRY_SET()); }
|
||||
@Override
|
||||
public ORDERED_SET KEY_GENERIC_TYPE keySet() { return new ABSTRACT_SET.REVERSED_ORDERED_SETBRACES(map.keySet()); }
|
||||
@Override
|
||||
public VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE values() { return map.values().reversed(); }
|
||||
@Override
|
||||
public ORDERED_MAP KEY_VALUE_GENERIC_TYPE reversed() { return map; }
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A Simple Type Specific Entry class to reduce boxing/unboxing
|
||||
* @Type(T)
|
||||
|
||||
+316
-67
@@ -4,10 +4,19 @@ import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.locks.StampedLock;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
import java.util.function.BiFunction;
|
||||
#if !TYPE_OBJECT && JDK_TYPE
|
||||
import java.util.function.PREDICATE;
|
||||
import java.util.OPTIONAL;
|
||||
#endif
|
||||
#if !SAME_TYPE && JDK_VALUE && !VALUE_OBJECT
|
||||
import java.util.function.VALUE_PREDICATE;
|
||||
import java.util.VALUE_OPTIONAL;
|
||||
#endif
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
||||
@@ -17,15 +26,29 @@ 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.ints.functions.consumer.BI_FROM_INT_CONSUMER;
|
||||
#if !TYPE_OBJECT && !VALUE_OBJECT
|
||||
import speiger.src.collections.ints.functions.consumer.IntObjectConsumer;
|
||||
#endif
|
||||
#if !SAME_TYPE && !TYPE_INT
|
||||
import speiger.src.collections.ints.functions.consumer.VALUE_BI_FROM_INT_CONSUMER;
|
||||
#endif
|
||||
#if !TYPE_INT || !SAME_TYPE
|
||||
import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
|
||||
#endif
|
||||
#if !VALUE_BOOLEAN || !JDK_TYPE
|
||||
import speiger.src.collections.PACKAGE.functions.function.FUNCTION;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||
#if !SAME_TYPE
|
||||
import speiger.src.collections.PACKAGE.functions.function.SINGLE_UNARY_OPERATOR;
|
||||
#endif
|
||||
#if !TYPE_OBJECT && !VALUE_BOOLEAN
|
||||
#if !TYPE_OBJECT && !JDK_TYPE
|
||||
import speiger.src.collections.PACKAGE.functions.OPTIONAL;
|
||||
#if!VALUE_BOOLEAN
|
||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||
#endif
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.maps.abstracts.ABSTRACT_MAP;
|
||||
import speiger.src.collections.PACKAGE.maps.interfaces.MAP;
|
||||
import speiger.src.collections.PACKAGE.maps.interfaces.CONCURRENT_MAP;
|
||||
@@ -43,6 +66,7 @@ import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_UNARY_OPER
|
||||
#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.collections.VALUE_BI_ITERATOR;
|
||||
import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_CONSUMER;
|
||||
@@ -54,17 +78,14 @@ import speiger.src.collections.objects.functions.function.ObjectObjectUnaryOpera
|
||||
#if !TYPE_OBJECT && !VALUE_OBJECT || !VALUE_OBJECT
|
||||
import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer;
|
||||
#endif
|
||||
#if !TYPE_OBJECT || !VALUE_BOOLEAN
|
||||
#if !VALUE_OBJECT || SAME_TYPE
|
||||
import speiger.src.collections.objects.functions.function.Object2BooleanFunction;
|
||||
#endif
|
||||
#endif
|
||||
#if !SAME_TYPE
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.objects.functions.consumer.VALUE_BI_FROM_OBJECT_CONSUMER;
|
||||
#endif
|
||||
|
||||
#if !JDK_VALUE
|
||||
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE;
|
||||
import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_OPTIONAL;
|
||||
#endif
|
||||
#endif
|
||||
#if VALUE_OBJECT
|
||||
import speiger.src.collections.objects.collections.ObjectIterator;
|
||||
@@ -525,6 +546,36 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
|
||||
return getSegment(hash).computeIfPresent(hash, key, mappingFunction);
|
||||
}
|
||||
|
||||
#if !VALUE_OBJECT
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTENonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
int hash = getHashCode(key);
|
||||
return getSegment(hash).computeNonDefault(hash, key, mappingFunction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_ABSENTNonDefault(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
int hash = getHashCode(key);
|
||||
return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENTNonDefault(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
|
||||
Objects.requireNonNull(valueProvider);
|
||||
int hash = getHashCode(key);
|
||||
return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENTNonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
int hash = getHashCode(key);
|
||||
return getSegment(hash).computeIfPresentNonDefault(hash, key, mappingFunction);
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public VALUE_TYPE MERGE(KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
@@ -638,7 +689,7 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
|
||||
try {
|
||||
int index = seg.firstIndex;
|
||||
while(index != -1){
|
||||
action.accept(new BasicEntryKV_BRACES(seg.keys[index], seg.values[index]));
|
||||
action.accept(new ValueMapEntry(index, i));
|
||||
index = (int)seg.links[index];
|
||||
}
|
||||
}
|
||||
@@ -650,14 +701,14 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
|
||||
|
||||
@Override
|
||||
public void fastForEach(Consumer<? super MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
|
||||
MapEntry entry = new MapEntry();
|
||||
for(int i = 0,m=segments.length;i<m;i++) {
|
||||
Segment KEY_VALUE_GENERIC_TYPE seg = segments[i];
|
||||
long stamp = seg.readLock();
|
||||
try {
|
||||
int index = seg.firstIndex;
|
||||
while(index != -1){
|
||||
entry.set(seg.keys[index], seg.values[index]);
|
||||
entry.set(index, i);
|
||||
action.accept(entry);
|
||||
index = (int)seg.links[index];
|
||||
}
|
||||
@@ -668,6 +719,26 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEachIndexed(IntObjectConsumer<MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
|
||||
Objects.requireNonNull(action);
|
||||
int count = 0;
|
||||
for(int i = 0,m=segments.length;i<m;i++) {
|
||||
Segment KEY_VALUE_GENERIC_TYPE seg = segments[i];
|
||||
long stamp = seg.readLock();
|
||||
try {
|
||||
int index = seg.firstIndex;
|
||||
while(index != -1) {
|
||||
action.accept(count++, new ValueMapEntry(index, i));
|
||||
index = (int)seg.links[index];
|
||||
}
|
||||
}
|
||||
finally {
|
||||
seg.unlockRead(stamp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, ObjectObjectConsumer<E, MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
|
||||
Objects.requireNonNull(action);
|
||||
@@ -677,7 +748,7 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
|
||||
try {
|
||||
int index = seg.firstIndex;
|
||||
while(index != -1) {
|
||||
action.accept(input, new BasicEntryKV_BRACES(seg.keys[index], seg.values[index]));
|
||||
action.accept(input, new ValueMapEntry(index, i));
|
||||
index = (int)seg.links[index];
|
||||
}
|
||||
}
|
||||
@@ -688,17 +759,17 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matchesAny(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
public boolean matchesAny(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
|
||||
MapEntry entry = new MapEntry();
|
||||
for(int i = 0,m=segments.length;i<m;i++) {
|
||||
Segment KEY_VALUE_GENERIC_TYPE seg = segments[i];
|
||||
long stamp = seg.readLock();
|
||||
try {
|
||||
int index = seg.firstIndex;
|
||||
while(index != -1) {
|
||||
entry.set(seg.keys[index], seg.values[index]);
|
||||
if(filter.getBoolean(entry)) return true;
|
||||
entry.set(index, i);
|
||||
if(filter.test(entry)) return true;
|
||||
index = (int)seg.links[index];
|
||||
}
|
||||
}
|
||||
@@ -710,17 +781,17 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matchesNone(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
public boolean matchesNone(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
|
||||
MapEntry entry = new MapEntry();
|
||||
for(int i = 0,m=segments.length;i<m;i++) {
|
||||
Segment KEY_VALUE_GENERIC_TYPE seg = segments[i];
|
||||
long stamp = seg.readLock();
|
||||
try {
|
||||
int index = seg.firstIndex;
|
||||
while(index != -1) {
|
||||
entry.set(seg.keys[index], seg.values[index]);
|
||||
if(filter.getBoolean(entry)) return false;
|
||||
entry.set(index, i);
|
||||
if(filter.test(entry)) return false;
|
||||
index = (int)seg.links[index];
|
||||
}
|
||||
}
|
||||
@@ -732,17 +803,17 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matchesAll(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
public boolean matchesAll(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
|
||||
MapEntry entry = new MapEntry();
|
||||
for(int i = 0,m=segments.length;i<m;i++) {
|
||||
Segment KEY_VALUE_GENERIC_TYPE seg = segments[i];
|
||||
long stamp = seg.readLock();
|
||||
try {
|
||||
int index = seg.firstIndex;
|
||||
while(index != -1) {
|
||||
entry.set(seg.keys[index], seg.values[index]);
|
||||
if(!filter.getBoolean(entry)) return false;
|
||||
entry.set(index, i);
|
||||
if(!filter.test(entry)) return false;
|
||||
index = (int)seg.links[index];
|
||||
}
|
||||
}
|
||||
@@ -763,7 +834,7 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
|
||||
try {
|
||||
int index = seg.firstIndex;
|
||||
while(index != -1) {
|
||||
state = operator.apply(state, new BasicEntryKV_BRACES(seg.keys[index], seg.values[index]));
|
||||
state = operator.apply(state, new ValueMapEntry(index, i));
|
||||
index = (int)seg.links[index];
|
||||
}
|
||||
}
|
||||
@@ -775,7 +846,7 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE reduce(ObjectObjectUnaryOperator<MAP.Entry KEY_VALUE_GENERIC_TYPE, MAP.Entry KEY_VALUE_GENERIC_TYPE> operator) {
|
||||
public Optional<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;
|
||||
@@ -787,11 +858,11 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
|
||||
while(index != -1) {
|
||||
if(empty) {
|
||||
empty = false;
|
||||
state = new BasicEntryKV_BRACES(seg.keys[index], seg.values[index]);
|
||||
state = new ValueMapEntry(index, i);
|
||||
index = (int)seg.links[index];
|
||||
continue;
|
||||
}
|
||||
state = operator.apply(state, new BasicEntryKV_BRACES(seg.keys[index], seg.values[index]));
|
||||
state = operator.apply(state, new ValueMapEntry(index, i));
|
||||
index = (int)seg.links[index];
|
||||
}
|
||||
}
|
||||
@@ -799,21 +870,21 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
|
||||
seg.unlockRead(stamp);
|
||||
}
|
||||
}
|
||||
return state;
|
||||
return empty ? Optional.empty() : Optional.ofNullable(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
public Optional<MAP.Entry KEY_VALUE_GENERIC_TYPE> findFirst(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
|
||||
MapEntry entry = new MapEntry();
|
||||
for(int i = 0,m=segments.length;i<m;i++) {
|
||||
Segment KEY_VALUE_GENERIC_TYPE seg = segments[i];
|
||||
int index = seg.firstIndex;
|
||||
long stamp = seg.readLock();
|
||||
try {
|
||||
while(index != -1) {
|
||||
entry.set(seg.keys[index], seg.values[index]);
|
||||
if(filter.getBoolean(entry)) return entry;
|
||||
entry.set(index, i);
|
||||
if(filter.test(entry)) return Optional.ofNullable(entry);
|
||||
index = (int)seg.links[index];
|
||||
}
|
||||
}
|
||||
@@ -821,22 +892,22 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
|
||||
seg.unlockRead(stamp);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
public int count(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
int result = 0;
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
|
||||
MapEntry entry = new MapEntry();
|
||||
for(int i = 0,m=segments.length;i<m;i++) {
|
||||
Segment KEY_VALUE_GENERIC_TYPE seg = segments[i];
|
||||
long stamp = seg.readLock();
|
||||
try {
|
||||
int index = seg.firstIndex;
|
||||
while(index != -1) {
|
||||
entry.set(seg.keys[index], seg.values[index]);
|
||||
if(filter.getBoolean(entry)) result++;
|
||||
entry.set(index, i);
|
||||
if(filter.test(entry)) result++;
|
||||
index = (int)seg.links[index];
|
||||
}
|
||||
}
|
||||
@@ -977,6 +1048,26 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
|
||||
Objects.requireNonNull(action);
|
||||
int count = 0;
|
||||
for(int i = 0,m=segments.length;i<m;i++) {
|
||||
Segment KEY_VALUE_GENERIC_TYPE seg = segments[i];
|
||||
long stamp = seg.readLock();
|
||||
try {
|
||||
int index = seg.firstIndex;
|
||||
while(index != -1){
|
||||
action.accept(count++, seg.keys[index]);
|
||||
index = (int)seg.links[index];
|
||||
}
|
||||
}
|
||||
finally {
|
||||
seg.unlockRead(stamp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
@@ -1005,7 +1096,7 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
|
||||
try {
|
||||
int index = seg.firstIndex;
|
||||
while(index != -1){
|
||||
if(filter.TEST_VALUE(seg.keys[index])) return true;
|
||||
if(filter.test(seg.keys[index])) return true;
|
||||
index = (int)seg.links[index];
|
||||
}
|
||||
}
|
||||
@@ -1025,7 +1116,7 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
|
||||
try {
|
||||
int index = seg.firstIndex;
|
||||
while(index != -1){
|
||||
if(filter.TEST_VALUE(seg.keys[index])) return false;
|
||||
if(filter.test(seg.keys[index])) return false;
|
||||
index = (int)seg.links[index];
|
||||
}
|
||||
}
|
||||
@@ -1045,7 +1136,7 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
|
||||
try {
|
||||
int index = seg.firstIndex;
|
||||
while(index != -1){
|
||||
if(!filter.TEST_VALUE(seg.keys[index])) return false;
|
||||
if(!filter.test(seg.keys[index])) return false;
|
||||
index = (int)seg.links[index];
|
||||
}
|
||||
}
|
||||
@@ -1102,7 +1193,7 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public KEY_TYPE reduce(SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
public OPTIONAL KEY_GENERIC_TYPE reduce(SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = EMPTY_KEY_VALUE;
|
||||
boolean empty = true;
|
||||
@@ -1126,11 +1217,11 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
|
||||
seg.unlockRead(stamp);
|
||||
}
|
||||
}
|
||||
return state;
|
||||
return empty ? OPTIONAL.empty() : OPTIONAL.GET_OPTIONAL(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
public OPTIONAL KEY_GENERIC_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(int i = 0,m=segments.length;i<m;i++) {
|
||||
Segment KEY_VALUE_GENERIC_TYPE seg = segments[i];
|
||||
@@ -1138,7 +1229,7 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
|
||||
try {
|
||||
int index = seg.firstIndex;
|
||||
while(index != -1){
|
||||
if(filter.TEST_VALUE(seg.keys[index])) return seg.keys[index];
|
||||
if(filter.test(seg.keys[index])) return OPTIONAL.GET_OPTIONAL(seg.keys[index]);
|
||||
index = (int)seg.links[index];
|
||||
}
|
||||
}
|
||||
@@ -1146,7 +1237,7 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
|
||||
seg.unlockRead(stamp);
|
||||
}
|
||||
}
|
||||
return EMPTY_KEY_VALUE;
|
||||
return OPTIONAL.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1159,7 +1250,7 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
|
||||
try {
|
||||
int index = seg.firstIndex;
|
||||
while(index != -1){
|
||||
if(filter.TEST_VALUE(seg.keys[index])) result++;
|
||||
if(filter.test(seg.keys[index])) result++;
|
||||
index = (int)seg.links[index];
|
||||
}
|
||||
}
|
||||
@@ -1225,6 +1316,26 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEachIndexed(VALUE_BI_FROM_INT_CONSUMER VALUE_GENERIC_TYPE action) {
|
||||
Objects.requireNonNull(action);
|
||||
int count = 0;
|
||||
for(int i = 0,m=segments.length;i<m;i++) {
|
||||
Segment KEY_VALUE_GENERIC_TYPE seg = segments[i];
|
||||
long stamp = seg.readLock();
|
||||
try {
|
||||
int index = seg.firstIndex;
|
||||
while(index != -1){
|
||||
action.accept(count++, seg.values[index]);
|
||||
index = (int)seg.links[index];
|
||||
}
|
||||
}
|
||||
finally {
|
||||
seg.unlockRead(stamp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, VALUE_BI_FROM_OBJECT_CONSUMER VSV_GENERIC_TYPE<E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
@@ -1253,7 +1364,7 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
|
||||
try {
|
||||
int index = seg.firstIndex;
|
||||
while(index != -1){
|
||||
if(filter.VALUE_TEST_VALUE(seg.values[index])) return true;
|
||||
if(filter.test(seg.values[index])) return true;
|
||||
index = (int)seg.links[index];
|
||||
}
|
||||
}
|
||||
@@ -1273,7 +1384,7 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
|
||||
try {
|
||||
int index = seg.firstIndex;
|
||||
while(index != -1) {
|
||||
if(filter.VALUE_TEST_VALUE(seg.values[index])) return false;
|
||||
if(filter.test(seg.values[index])) return false;
|
||||
index = (int)seg.links[index];
|
||||
}
|
||||
}
|
||||
@@ -1293,7 +1404,7 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
|
||||
try {
|
||||
int index = seg.firstIndex;
|
||||
while(index != -1) {
|
||||
if(!filter.VALUE_TEST_VALUE(seg.values[index])) return false;
|
||||
if(!filter.test(seg.values[index])) return false;
|
||||
index = (int)seg.links[index];
|
||||
}
|
||||
}
|
||||
@@ -1350,7 +1461,7 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public VALUE_TYPE reduce(VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
|
||||
public VALUE_OPTIONAL VALUE_GENERIC_TYPE reduce(VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
VALUE_TYPE state = EMPTY_VALUE;
|
||||
boolean empty = true;
|
||||
@@ -1374,20 +1485,20 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
|
||||
seg.unlockRead(stamp);
|
||||
}
|
||||
}
|
||||
return state;
|
||||
return empty ? VALUE_OPTIONAL.empty() : VALUE_OPTIONAL.GET_OPTIONAL_VALUE(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
||||
public VALUE_OPTIONAL VALUE_GENERIC_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return EMPTY_VALUE;
|
||||
if(size() <= 0) return VALUE_OPTIONAL.empty();
|
||||
for(int i = 0,m=segments.length;i<m;i++) {
|
||||
Segment KEY_VALUE_GENERIC_TYPE seg = segments[i];
|
||||
long stamp = seg.readLock();
|
||||
try {
|
||||
int index = seg.firstIndex;
|
||||
while(index != -1){
|
||||
if(filter.VALUE_TEST_VALUE(seg.values[index])) return seg.values[index];
|
||||
if(filter.test(seg.values[index])) return VALUE_OPTIONAL.GET_OPTIONAL_VALUE(seg.values[index]);
|
||||
index = (int)seg.links[index];
|
||||
}
|
||||
}
|
||||
@@ -1395,7 +1506,7 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
|
||||
seg.unlockRead(stamp);
|
||||
}
|
||||
}
|
||||
return EMPTY_VALUE;
|
||||
return VALUE_OPTIONAL.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1408,7 +1519,7 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
|
||||
try {
|
||||
int index = seg.firstIndex;
|
||||
while(index != -1){
|
||||
if(filter.VALUE_TEST_VALUE(seg.values[index])) result++;
|
||||
if(filter.test(seg.values[index])) result++;
|
||||
index = (int)seg.links[index];
|
||||
}
|
||||
}
|
||||
@@ -1445,12 +1556,12 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE next() {
|
||||
return entry = new MapEntry(nextEntry(), currentSegment());
|
||||
return entry = new ValueMapEntry(nextEntry(), currentSegment());
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE previous() {
|
||||
return entry = new MapEntry(previousEntry(), currentSegment());
|
||||
return entry = new ValueMapEntry(previousEntry(), currentSegment());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1635,6 +1746,33 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
|
||||
}
|
||||
}
|
||||
|
||||
protected class ValueMapEntry extends MapEntry {
|
||||
protected KEY_TYPE key;
|
||||
protected VALUE_TYPE value;
|
||||
|
||||
public ValueMapEntry(int index, int segmentIndex) {
|
||||
super(index, segmentIndex);
|
||||
key = segments[segmentIndex].keys[index];
|
||||
value = segments[segmentIndex].values[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE ENTRY_KEY() {
|
||||
return key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE ENTRY_VALUE() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE setValue(VALUE_TYPE value) {
|
||||
this.value = value;
|
||||
return super.setValue(value);
|
||||
}
|
||||
}
|
||||
|
||||
protected class MapEntry implements MAP.Entry KEY_VALUE_GENERIC_TYPE, Map.Entry<CLASS_TYPE, CLASS_VALUE_TYPE> {
|
||||
int index = -1;
|
||||
int segmentIndex = -1;
|
||||
@@ -1670,7 +1808,7 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
|
||||
long stamp = seg.writeLock();
|
||||
try
|
||||
{
|
||||
VALUE_TYPE oldValue = ENTRY_VALUE();
|
||||
VALUE_TYPE oldValue = seg.values[index];
|
||||
seg.values[index] = value;
|
||||
return oldValue;
|
||||
}
|
||||
@@ -1812,6 +1950,11 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
|
||||
insert(-slot-1, key, value);
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
else if(VALUE_EQUALS(values[slot], getDefaultReturnValue())) {
|
||||
VALUE_TYPE oldValue = values[slot];
|
||||
values[slot] = value;
|
||||
return oldValue;
|
||||
}
|
||||
return values[slot];
|
||||
}
|
||||
finally {
|
||||
@@ -2114,6 +2257,110 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
|
||||
int index = findIndex(hash, key);
|
||||
if(index < 0) {
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, getDefaultReturnValue());
|
||||
#if VALUE_OBJECT
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
#endif
|
||||
insert(-index-1, key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
|
||||
#if VALUE_OBJECT
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
removeIndex(index);
|
||||
return newValue;
|
||||
}
|
||||
#endif
|
||||
values[index] = newValue;
|
||||
return newValue;
|
||||
}
|
||||
finally {
|
||||
unlockWrite(stamp);
|
||||
}
|
||||
}
|
||||
|
||||
protected VALUE_TYPE computeIfAbsent(int hash, KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
long stamp = writeLock();
|
||||
try {
|
||||
int index = findIndex(hash, key);
|
||||
if(index < 0) {
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY(key);
|
||||
#if VALUE_OBJECT
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
#endif
|
||||
insert(-index-1, key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
VALUE_TYPE newValue = values[index];
|
||||
#if VALUE_OBJECT
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
newValue = mappingFunction.APPLY(key);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
values[index] = newValue;
|
||||
}
|
||||
#endif
|
||||
return newValue;
|
||||
}
|
||||
finally {
|
||||
unlockWrite(stamp);
|
||||
}
|
||||
}
|
||||
|
||||
protected VALUE_TYPE supplyIfAbsent(int hash, KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
|
||||
long stamp = writeLock();
|
||||
try {
|
||||
int index = findIndex(hash, key);
|
||||
if(index < 0) {
|
||||
VALUE_TYPE newValue = valueProvider.VALUE_SUPPLY_GET();
|
||||
#if VALUE_OBJECT
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
#endif
|
||||
insert(-index-1, key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
VALUE_TYPE newValue = values[index];
|
||||
#if VALUE_OBJECT
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
newValue = valueProvider.VALUE_SUPPLY_GET();
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
values[index] = newValue;
|
||||
}
|
||||
#endif
|
||||
return newValue;
|
||||
}
|
||||
finally {
|
||||
unlockWrite(stamp);
|
||||
}
|
||||
}
|
||||
|
||||
protected VALUE_TYPE computeIfPresent(int hash, KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
long stamp = writeLock();
|
||||
try {
|
||||
int index = findIndex(hash, key);
|
||||
#if !VALUE_OBJECT
|
||||
if(index < 0) return getDefaultReturnValue();
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
|
||||
#else
|
||||
if(index < 0 || VALUE_EQUALS(values[index], getDefaultReturnValue())) return getDefaultReturnValue();
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
removeIndex(index);
|
||||
return newValue;
|
||||
}
|
||||
#endif
|
||||
values[index] = newValue;
|
||||
return newValue;
|
||||
}
|
||||
finally {
|
||||
unlockWrite(stamp);
|
||||
}
|
||||
}
|
||||
|
||||
protected VALUE_TYPE computeNonDefault(int hash, KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
long stamp = writeLock();
|
||||
try {
|
||||
int index = findIndex(hash, key);
|
||||
if(index < 0) {
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, getDefaultReturnValue());
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
insert(-index-1, key, newValue);
|
||||
return newValue;
|
||||
@@ -2131,19 +2378,20 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
|
||||
}
|
||||
}
|
||||
|
||||
protected VALUE_TYPE computeIfAbsent(int hash, KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
#if !VALUE_OBJECT
|
||||
protected VALUE_TYPE computeIfAbsentNonDefault(int hash, KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
long stamp = writeLock();
|
||||
try {
|
||||
int index = findIndex(hash, key);
|
||||
if(index < 0) {
|
||||
VALUE_TYPE newValue = mappingFunction.GET_VALUE(key);
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY(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 = mappingFunction.GET_VALUE(key);
|
||||
newValue = mappingFunction.APPLY(key);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
values[index] = newValue;
|
||||
}
|
||||
@@ -2154,19 +2402,19 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
|
||||
}
|
||||
}
|
||||
|
||||
protected VALUE_TYPE supplyIfAbsent(int hash, KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
|
||||
protected VALUE_TYPE supplyIfAbsentNonDefault(int hash, KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
|
||||
long stamp = writeLock();
|
||||
try {
|
||||
int index = findIndex(hash, key);
|
||||
if(index < 0) {
|
||||
VALUE_TYPE newValue = valueProvider.VALUE_GET_KEY();
|
||||
VALUE_TYPE newValue = valueProvider.VALUE_SUPPLY_GET();
|
||||
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();
|
||||
newValue = valueProvider.VALUE_SUPPLY_GET();
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
values[index] = newValue;
|
||||
}
|
||||
@@ -2177,7 +2425,7 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
|
||||
}
|
||||
}
|
||||
|
||||
protected VALUE_TYPE computeIfPresent(int hash, KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
protected VALUE_TYPE computeIfPresentNonDefault(int hash, KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
long stamp = writeLock();
|
||||
try {
|
||||
int index = findIndex(hash, key);
|
||||
@@ -2195,6 +2443,7 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
protected VALUE_TYPE merge(int hash, KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
long stamp = writeLock();
|
||||
try {
|
||||
|
||||
+316
-129
@@ -3,19 +3,39 @@ package speiger.src.collections.PACKAGE.maps.impl.customHash;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Predicate;
|
||||
#if !TYPE_OBJECT && JDK_TYPE
|
||||
import java.util.function.PREDICATE;
|
||||
import java.util.OPTIONAL;
|
||||
#endif
|
||||
#if !SAME_TYPE && JDK_VALUE && !VALUE_OBJECT
|
||||
import java.util.function.VALUE_PREDICATE;
|
||||
import java.util.VALUE_OPTIONAL;
|
||||
#endif
|
||||
|
||||
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||
#endif
|
||||
#if !TYPE_OBJECT || VALUE_BOOLEAN
|
||||
import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
|
||||
#if !TYPE_OBJECT && !VALUE_OBJECT
|
||||
import speiger.src.collections.ints.functions.consumer.IntObjectConsumer;
|
||||
#endif
|
||||
#if !SAME_TYPE && !TYPE_INT
|
||||
import speiger.src.collections.ints.functions.consumer.VALUE_BI_FROM_INT_CONSUMER;
|
||||
#endif
|
||||
#if !TYPE_OBJECT && !JDK_TYPE
|
||||
import speiger.src.collections.PACKAGE.functions.OPTIONAL;
|
||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||
#endif
|
||||
#if !TYPE_INT || !SAME_TYPE
|
||||
import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
|
||||
#endif
|
||||
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;
|
||||
@@ -24,7 +44,7 @@ import speiger.src.collections.PACKAGE.sets.ABSTRACT_SET;
|
||||
import speiger.src.collections.PACKAGE.sets.ORDERED_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.collections.VALUE_ORDERED_COLLECTION;
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ITERATOR;
|
||||
#if !SAME_TYPE
|
||||
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_UNARY_OPERATOR;
|
||||
@@ -36,17 +56,15 @@ import speiger.src.collections.VALUE_PACKAGE.lists.VALUE_LIST_ITERATOR;
|
||||
#if !TYPE_OBJECT && !VALUE_OBJECT || !VALUE_OBJECT
|
||||
import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer;
|
||||
#endif
|
||||
#if !TYPE_OBJECT || !VALUE_BOOLEAN
|
||||
#if !VALUE_OBJECT || SAME_TYPE
|
||||
import speiger.src.collections.objects.functions.function.Object2BooleanFunction;
|
||||
#endif
|
||||
#endif
|
||||
#if !SAME_TYPE
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.objects.functions.consumer.VALUE_BI_FROM_OBJECT_CONSUMER;
|
||||
|
||||
#endif
|
||||
#if !JDK_VALUE
|
||||
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE;
|
||||
import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_OPTIONAL;
|
||||
#endif
|
||||
#endif
|
||||
#if !TYPE_OBJECT
|
||||
#if !VALUE_OBJECT
|
||||
@@ -220,13 +238,13 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
if(containsNull) {
|
||||
VALUE_TYPE lastValue = values[nullIndex];
|
||||
values[nullIndex] = value;
|
||||
moveToFirstIndex(nullIndex);
|
||||
moveToFirstIndex(nullIndex, false);
|
||||
return lastValue;
|
||||
}
|
||||
values[nullIndex] = value;
|
||||
containsNull = true;
|
||||
onNodeAdded(nullIndex);
|
||||
moveToFirstIndex(nullIndex);
|
||||
moveToFirstIndex(nullIndex, true);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(strategy.hashCode(key)) & mask;
|
||||
@@ -234,7 +252,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
if(strategy.equals(keys[pos], key)) {
|
||||
VALUE_TYPE lastValue = values[pos];
|
||||
values[pos] = value;
|
||||
moveToFirstIndex(pos);
|
||||
moveToFirstIndex(pos, false);
|
||||
return lastValue;
|
||||
}
|
||||
pos = ++pos & mask;
|
||||
@@ -242,7 +260,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
keys[pos] = key;
|
||||
values[pos] = value;
|
||||
onNodeAdded(pos);
|
||||
moveToFirstIndex(pos);
|
||||
moveToFirstIndex(pos, true);
|
||||
}
|
||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||
return getDefaultReturnValue();
|
||||
@@ -254,13 +272,13 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
if(containsNull) {
|
||||
VALUE_TYPE lastValue = values[nullIndex];
|
||||
values[nullIndex] = value;
|
||||
moveToLastIndex(nullIndex);
|
||||
moveToLastIndex(nullIndex, false);
|
||||
return lastValue;
|
||||
}
|
||||
values[nullIndex] = value;
|
||||
containsNull = true;
|
||||
onNodeAdded(nullIndex);
|
||||
moveToLastIndex(nullIndex);
|
||||
moveToLastIndex(nullIndex, true);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(strategy.hashCode(key)) & mask;
|
||||
@@ -268,7 +286,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
if(strategy.equals(keys[pos], key)) {
|
||||
VALUE_TYPE lastValue = values[pos];
|
||||
values[pos] = value;
|
||||
moveToLastIndex(pos);
|
||||
moveToLastIndex(pos, false);
|
||||
return lastValue;
|
||||
}
|
||||
pos = ++pos & mask;
|
||||
@@ -276,7 +294,55 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
keys[pos] = key;
|
||||
values[pos] = value;
|
||||
onNodeAdded(pos);
|
||||
moveToLastIndex(pos);
|
||||
moveToLastIndex(pos, true);
|
||||
}
|
||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE putFirst(KEY_TYPE key, VALUE_TYPE value) {
|
||||
if(strategy.equals(key, EMPTY_KEY_VALUE)) {
|
||||
if(containsNull) return values[nullIndex];
|
||||
values[nullIndex] = value;
|
||||
containsNull = true;
|
||||
onNodeAdded(nullIndex);
|
||||
moveToFirstIndex(nullIndex, true);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(strategy.hashCode(key)) & mask;
|
||||
while(!strategy.equals(keys[pos], EMPTY_KEY_VALUE)) {
|
||||
if(strategy.equals(keys[pos], key)) return values[pos];
|
||||
pos = ++pos & mask;
|
||||
}
|
||||
keys[pos] = key;
|
||||
values[pos] = value;
|
||||
onNodeAdded(pos);
|
||||
moveToFirstIndex(pos, true);
|
||||
}
|
||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE putLast(KEY_TYPE key, VALUE_TYPE value) {
|
||||
if(strategy.equals(key, EMPTY_KEY_VALUE)) {
|
||||
if(containsNull) return values[nullIndex];
|
||||
values[nullIndex] = value;
|
||||
containsNull = true;
|
||||
onNodeAdded(nullIndex);
|
||||
moveToLastIndex(nullIndex, true);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(strategy.hashCode(key)) & mask;
|
||||
while(!strategy.equals(keys[pos], EMPTY_KEY_VALUE)) {
|
||||
if(strategy.equals(keys[pos], key)) return values[pos];
|
||||
pos = ++pos & mask;
|
||||
}
|
||||
keys[pos] = key;
|
||||
values[pos] = value;
|
||||
onNodeAdded(pos);
|
||||
moveToLastIndex(pos, true);
|
||||
}
|
||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||
return getDefaultReturnValue();
|
||||
@@ -287,7 +353,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
if(isEmpty() || strategy.equals(FIRST_ENTRY_KEY(), key)) return false;
|
||||
if(strategy.equals(key, EMPTY_KEY_VALUE)) {
|
||||
if(containsNull) {
|
||||
moveToFirstIndex(nullIndex);
|
||||
moveToFirstIndex(nullIndex, false);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -295,7 +361,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
int pos = HashUtil.mix(strategy.hashCode(key)) & mask;
|
||||
while(!strategy.equals(keys[pos], EMPTY_KEY_VALUE)) {
|
||||
if(strategy.equals(keys[pos], key)) {
|
||||
moveToFirstIndex(pos);
|
||||
moveToFirstIndex(pos, false);
|
||||
return true;
|
||||
}
|
||||
pos = ++pos & mask;
|
||||
@@ -309,7 +375,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
if(isEmpty() || strategy.equals(LAST_ENTRY_KEY(), key)) return false;
|
||||
if(strategy.equals(key, EMPTY_KEY_VALUE)) {
|
||||
if(containsNull) {
|
||||
moveToLastIndex(nullIndex);
|
||||
moveToLastIndex(nullIndex, false);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -317,7 +383,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
int pos = HashUtil.mix(strategy.hashCode(key)) & mask;
|
||||
while(!strategy.equals(keys[pos], EMPTY_KEY_VALUE)) {
|
||||
if(strategy.equals(keys[pos], key)) {
|
||||
moveToLastIndex(pos);
|
||||
moveToLastIndex(pos, false);
|
||||
return true;
|
||||
}
|
||||
pos = ++pos & mask;
|
||||
@@ -330,7 +396,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
public VALUE_TYPE getAndMoveToFirst(KEY_TYPE key) {
|
||||
int index = findIndex(key);
|
||||
if(index < 0) return getDefaultReturnValue();
|
||||
moveToFirstIndex(index);
|
||||
moveToFirstIndex(index, false);
|
||||
return values[index];
|
||||
}
|
||||
|
||||
@@ -338,7 +404,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
public VALUE_TYPE getAndMoveToLast(KEY_TYPE key) {
|
||||
int index = findIndex(key);
|
||||
if(index < 0) return getDefaultReturnValue();
|
||||
moveToLastIndex(index);
|
||||
moveToLastIndex(index, false);
|
||||
return values[index];
|
||||
}
|
||||
|
||||
@@ -417,6 +483,52 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
return values[lastIndex];
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE firstEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return new BasicEntryKV_BRACES(keys[firstIndex], values[firstIndex]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE lastEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return new BasicEntryKV_BRACES(keys[lastIndex], values[lastIndex]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollFirstEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
int pos = firstIndex;
|
||||
onNodeRemoved(pos);
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE result = new BasicEntryKV_BRACES(keys[pos], values[pos]);
|
||||
size--;
|
||||
if(strategy.equals(result.ENTRY_KEY(), EMPTY_KEY_VALUE)) {
|
||||
containsNull = false;
|
||||
keys[nullIndex] = EMPTY_KEY_VALUE;
|
||||
values[nullIndex] = EMPTY_VALUE;
|
||||
}
|
||||
else shiftKeys(pos);
|
||||
if(nullIndex > minCapacity && size < maxFill / 4 && nullIndex > HashUtil.DEFAULT_MIN_CAPACITY) rehash(nullIndex / 2);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollLastEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
int pos = lastIndex;
|
||||
onNodeRemoved(pos);
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE result = new BasicEntryKV_BRACES(keys[pos], values[pos]);
|
||||
size--;
|
||||
if(strategy.equals(result.ENTRY_KEY(), EMPTY_KEY_VALUE)) {
|
||||
containsNull = false;
|
||||
keys[nullIndex] = EMPTY_KEY_VALUE;
|
||||
values[nullIndex] = EMPTY_VALUE;
|
||||
}
|
||||
else shiftKeys(pos);
|
||||
if(nullIndex > minCapacity && size < maxFill / 4 && nullIndex > HashUtil.DEFAULT_MIN_CAPACITY) rehash(nullIndex / 2);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectOrderedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> ENTRY_SET() {
|
||||
if(entrySet == null) entrySet = new MapEntrySet();
|
||||
@@ -430,9 +542,9 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_COLLECTION VALUE_GENERIC_TYPE values() {
|
||||
public VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE values() {
|
||||
if(valuesC == null) valuesC = new Values();
|
||||
return valuesC;
|
||||
return (VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE)valuesC;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -468,8 +580,8 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
containsNull = false;
|
||||
}
|
||||
|
||||
protected void moveToFirstIndex(int startPos) {
|
||||
if(size == 1 || firstIndex == startPos) return;
|
||||
protected void moveToFirstIndex(int startPos, boolean adding) {
|
||||
if(size == (adding ? 0 : 1) || firstIndex == startPos) return;
|
||||
if(lastIndex == startPos) {
|
||||
lastIndex = (int)(links[startPos] >>> 32);
|
||||
links[lastIndex] |= 0xFFFFFFFFL;
|
||||
@@ -486,8 +598,8 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
firstIndex = startPos;
|
||||
}
|
||||
|
||||
protected void moveToLastIndex(int startPos) {
|
||||
if(size == 1 || lastIndex == startPos) return;
|
||||
protected void moveToLastIndex(int startPos, boolean adding) {
|
||||
if(size == (adding ? 0 : 1) || lastIndex == startPos) return;
|
||||
if(firstIndex == startPos) {
|
||||
firstIndex = (int)links[startPos];
|
||||
links[lastIndex] |= 0xFFFFFFFF00000000L;
|
||||
@@ -601,6 +713,10 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
}
|
||||
|
||||
private class MapEntrySet extends AbstractObjectSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> implements ORDERED_MAP.FastOrderedSet KEY_VALUE_GENERIC_TYPE {
|
||||
@Override
|
||||
public void addFirst(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void addLast(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean addAndMoveToFirst(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
@@ -617,24 +733,24 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE first() {
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE getFirst() {
|
||||
return new BasicEntryKV_BRACES(FIRST_ENTRY_KEY(), FIRST_ENTRY_VALUE());
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE last() {
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE getLast() {
|
||||
return new BasicEntryKV_BRACES(LAST_ENTRY_KEY(), LAST_ENTRY_VALUE());
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollFirst() {
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE removeFirst() {
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(FIRST_ENTRY_KEY(), FIRST_ENTRY_VALUE());
|
||||
POLL_FIRST_ENTRY_KEY();
|
||||
return entry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollLast() {
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE removeLast() {
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(LAST_ENTRY_KEY(), LAST_ENTRY_VALUE());
|
||||
POLL_LAST_ENTRY_KEY();
|
||||
return entry;
|
||||
@@ -642,7 +758,12 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> iterator() {
|
||||
return new EntryIterator();
|
||||
return new EntryIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> reverseIterator() {
|
||||
return new EntryIterator(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -652,7 +773,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> fastIterator() {
|
||||
return new FastEntryIterator();
|
||||
return new FastEntryIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -667,70 +788,82 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
public void forEach(Consumer<? super MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
action.accept(new BasicEntryKV_BRACES(keys[index], values[index]));
|
||||
action.accept(new ValueMapEntry(index));
|
||||
index = (int)links[index];
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fastForEach(Consumer<? super MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
|
||||
MapEntry entry = new MapEntry();
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
entry.set(keys[index], values[index]);
|
||||
entry.set(index);
|
||||
action.accept(entry);
|
||||
index = (int)links[index];
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEachIndexed(IntObjectConsumer<MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
|
||||
Objects.requireNonNull(action);
|
||||
if(size() <= 0) return;
|
||||
int count = 0;
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
action.accept(count++, new ValueMapEntry(index));
|
||||
index = (int)links[index];
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, ObjectObjectConsumer<E, MAP.Entry KEY_VALUE_GENERIC_TYPE> 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(input, new ValueMapEntry(index));
|
||||
index = (int)links[index];
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matchesAny(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
public boolean matchesAny(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return false;
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
|
||||
MapEntry entry = new MapEntry();
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
entry.set(keys[index], values[index]);
|
||||
if(filter.getBoolean(entry)) return true;
|
||||
entry.set(index);
|
||||
if(filter.test(entry)) return true;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matchesNone(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
public boolean matchesNone(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return true;
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
|
||||
MapEntry entry = new MapEntry();
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
entry.set(keys[index], values[index]);
|
||||
if(filter.getBoolean(entry)) return false;
|
||||
entry.set(index);
|
||||
if(filter.test(entry)) return false;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matchesAll(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
public boolean matchesAll(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return true;
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
|
||||
MapEntry entry = new MapEntry();
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
entry.set(keys[index], values[index]);
|
||||
if(!filter.getBoolean(entry)) return false;
|
||||
entry.set(index);
|
||||
if(!filter.test(entry)) return false;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return true;
|
||||
@@ -742,14 +875,14 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
E state = identity;
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
state = operator.apply(state, new BasicEntryKV_BRACES(keys[index], values[index]));
|
||||
state = operator.apply(state, new ValueMapEntry(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) {
|
||||
public Optional<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;
|
||||
@@ -757,40 +890,40 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
while(index != -1) {
|
||||
if(empty) {
|
||||
empty = false;
|
||||
state = new BasicEntryKV_BRACES(keys[index], values[index]);
|
||||
state = new ValueMapEntry(index);
|
||||
index = (int)links[index];
|
||||
continue;
|
||||
}
|
||||
state = operator.apply(state, new BasicEntryKV_BRACES(keys[index], values[index]));
|
||||
state = operator.apply(state, new ValueMapEntry(index));
|
||||
index = (int)links[index];
|
||||
}
|
||||
return state;
|
||||
return empty ? Optional.empty() : Optional.ofNullable(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
public Optional<MAP.Entry KEY_VALUE_GENERIC_TYPE> findFirst(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return null;
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
|
||||
if(size() <= 0) return Optional.empty();
|
||||
MapEntry entry = new MapEntry();
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
entry.set(keys[index], values[index]);
|
||||
if(filter.getBoolean(entry)) return entry;
|
||||
entry.set(index);
|
||||
if(filter.test(entry)) return Optional.ofNullable(entry);
|
||||
index = (int)links[index];
|
||||
}
|
||||
return null;
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
public int count(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return 0;
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
|
||||
MapEntry entry = new MapEntry();
|
||||
int result = 0;
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
entry.set(keys[index], values[index]);
|
||||
if(filter.getBoolean(entry)) result++;
|
||||
entry.set(index);
|
||||
if(filter.test(entry)) result++;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return result;
|
||||
@@ -876,9 +1009,12 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addFirst(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void addLast(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean addAndMoveToFirst(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public boolean addAndMoveToLast(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@@ -894,7 +1030,12 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE iterator() {
|
||||
return new KeyIterator();
|
||||
return new KeyIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE reverseIterator() {
|
||||
return new KeyIterator(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -916,22 +1057,22 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE FIRST_KEY() {
|
||||
public KEY_TYPE GET_FIRST_KEY() {
|
||||
return FIRST_ENTRY_KEY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE POLL_FIRST_KEY() {
|
||||
public KEY_TYPE REMOVE_FIRST_KEY() {
|
||||
return POLL_FIRST_ENTRY_KEY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE LAST_KEY() {
|
||||
public KEY_TYPE GET_LAST_KEY() {
|
||||
return LAST_ENTRY_KEY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE POLL_LAST_KEY() {
|
||||
public KEY_TYPE REMOVE_LAST_KEY() {
|
||||
return POLL_LAST_ENTRY_KEY();
|
||||
}
|
||||
|
||||
@@ -944,6 +1085,18 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
|
||||
Objects.requireNonNull(action);
|
||||
if(size() <= 0) return;
|
||||
int count = 0;
|
||||
int index = firstIndex;
|
||||
while(index != -1){
|
||||
action.accept(count++, keys[index]);
|
||||
index = (int)links[index];
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
@@ -961,7 +1114,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
if(size() <= 0) return false;
|
||||
int index = firstIndex;
|
||||
while(index != -1){
|
||||
if(filter.TEST_VALUE(keys[index])) return true;
|
||||
if(filter.test(keys[index])) return true;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return false;
|
||||
@@ -973,7 +1126,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
if(size() <= 0) return true;
|
||||
int index = firstIndex;
|
||||
while(index != -1){
|
||||
if(filter.TEST_VALUE(keys[index])) return false;
|
||||
if(filter.test(keys[index])) return false;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return true;
|
||||
@@ -985,7 +1138,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
if(size() <= 0) return true;
|
||||
int index = firstIndex;
|
||||
while(index != -1){
|
||||
if(!filter.TEST_VALUE(keys[index])) return false;
|
||||
if(!filter.test(keys[index])) return false;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return true;
|
||||
@@ -1019,7 +1172,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public KEY_TYPE reduce(SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
public OPTIONAL KEY_GENERIC_TYPE reduce(SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = EMPTY_KEY_VALUE;
|
||||
boolean empty = true;
|
||||
@@ -1034,19 +1187,19 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
state = operator.APPLY_KEY_VALUE(state, keys[index]);
|
||||
index = (int)links[index];
|
||||
}
|
||||
return state;
|
||||
return empty ? OPTIONAL.empty() : OPTIONAL.GET_OPTIONAL(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
public OPTIONAL KEY_GENERIC_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return EMPTY_KEY_VALUE;
|
||||
if(size() <= 0) return OPTIONAL.empty();
|
||||
int index = firstIndex;
|
||||
while(index != -1){
|
||||
if(filter.TEST_VALUE(keys[index])) return keys[index];
|
||||
if(filter.test(keys[index])) return OPTIONAL.GET_OPTIONAL(keys[index]);
|
||||
index = (int)links[index];
|
||||
}
|
||||
return EMPTY_KEY_VALUE;
|
||||
return OPTIONAL.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1056,46 +1209,54 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
int result = 0;
|
||||
int index = firstIndex;
|
||||
while(index != -1){
|
||||
if(filter.TEST_VALUE(keys[index])) result++;
|
||||
if(filter.test(keys[index])) result++;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
private class Values extends VALUE_ABSTRACT_COLLECTION VALUE_GENERIC_TYPE {
|
||||
private class Values extends VALUE_ABSTRACT_COLLECTION VALUE_GENERIC_TYPE implements VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE {
|
||||
#if VALUE_OBJECT
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean contains(Object e) {
|
||||
return containsValue(e);
|
||||
}
|
||||
|
||||
public boolean contains(Object e) { return containsValue(e); }
|
||||
#else
|
||||
@Override
|
||||
public boolean contains(VALUE_TYPE e) {
|
||||
return containsValue(e);
|
||||
}
|
||||
|
||||
public boolean contains(VALUE_TYPE e) { return containsValue(e); }
|
||||
#endif
|
||||
@Override
|
||||
public boolean add(VALUE_TYPE o) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public boolean add(VALUE_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_ITERATOR VALUE_GENERIC_TYPE iterator() {
|
||||
return new ValueIterator();
|
||||
}
|
||||
|
||||
public VALUE_ITERATOR VALUE_GENERIC_TYPE iterator() { return new ValueIterator(true); }
|
||||
@Override
|
||||
public int size() {
|
||||
return LINKED_CUSTOM_HASH_MAP.this.size();
|
||||
}
|
||||
|
||||
public int size() { return LINKED_CUSTOM_HASH_MAP.this.size(); }
|
||||
@Override
|
||||
public void clear() {
|
||||
LINKED_CUSTOM_HASH_MAP.this.clear();
|
||||
public void clear() { LINKED_CUSTOM_HASH_MAP.this.clear(); }
|
||||
@Override
|
||||
public VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE reversed() { return new VALUE_ABSTRACT_COLLECTION.VALUE_REVERSED_ORDERED_COLLECTIONVALUE_BRACES(this, this::reverseIterator); }
|
||||
private VALUE_ITERATOR VALUE_GENERIC_TYPE reverseIterator() {
|
||||
return new ValueIterator(false);
|
||||
}
|
||||
@Override
|
||||
public void addFirst(VALUE_TYPE e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void addLast(VALUE_TYPE e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE VALUE_GET_FIRST_KEY() { return FIRST_ENTRY_VALUE(); }
|
||||
@Override
|
||||
public VALUE_TYPE VALUE_REMOVE_FIRST_KEY() {
|
||||
VALUE_TYPE result = FIRST_ENTRY_VALUE();
|
||||
POLL_FIRST_ENTRY_KEY();
|
||||
return result;
|
||||
}
|
||||
@Override
|
||||
public VALUE_TYPE VALUE_GET_LAST_KEY() { return LAST_ENTRY_VALUE(); }
|
||||
@Override
|
||||
public VALUE_TYPE VALUE_REMOVE_LAST_KEY() {
|
||||
VALUE_TYPE result = LAST_ENTRY_VALUE();
|
||||
POLL_LAST_ENTRY_KEY();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1107,6 +1268,18 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEachIndexed(VALUE_BI_FROM_INT_CONSUMER VALUE_GENERIC_TYPE action) {
|
||||
Objects.requireNonNull(action);
|
||||
if(size() <= 0) return;
|
||||
int count = 0;
|
||||
int index = firstIndex;
|
||||
while(index != -1){
|
||||
action.accept(count++, values[index]);
|
||||
index = (int)links[index];
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, VALUE_BI_FROM_OBJECT_CONSUMER VSV_GENERIC_TYPE<E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
@@ -1124,7 +1297,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
if(size() <= 0) return false;
|
||||
int index = firstIndex;
|
||||
while(index != -1){
|
||||
if(filter.VALUE_TEST_VALUE(values[index])) return true;
|
||||
if(filter.test(values[index])) return true;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return false;
|
||||
@@ -1136,7 +1309,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
if(size() <= 0) return true;
|
||||
int index = firstIndex;
|
||||
while(index != -1){
|
||||
if(filter.VALUE_TEST_VALUE(values[index])) return false;
|
||||
if(filter.test(values[index])) return false;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return true;
|
||||
@@ -1148,7 +1321,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
if(size() <= 0) return true;
|
||||
int index = firstIndex;
|
||||
while(index != -1){
|
||||
if(!filter.VALUE_TEST_VALUE(values[index])) return false;
|
||||
if(!filter.test(values[index])) return false;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return true;
|
||||
@@ -1182,7 +1355,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public VALUE_TYPE reduce(VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
|
||||
public VALUE_OPTIONAL VALUE_GENERIC_TYPE reduce(VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
VALUE_TYPE state = EMPTY_VALUE;
|
||||
boolean empty = true;
|
||||
@@ -1197,19 +1370,19 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
state = operator.APPLY_VALUE(state, values[index]);
|
||||
index = (int)links[index];
|
||||
}
|
||||
return state;
|
||||
return empty ? VALUE_OPTIONAL.empty() : VALUE_OPTIONAL.GET_OPTIONAL_VALUE(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
||||
public VALUE_OPTIONAL VALUE_GENERIC_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return EMPTY_VALUE;
|
||||
if(size() <= 0) return VALUE_OPTIONAL.empty();
|
||||
int index = firstIndex;
|
||||
while(index != -1){
|
||||
if(filter.VALUE_TEST_VALUE(values[index])) return values[index];
|
||||
if(filter.test(values[index])) return VALUE_OPTIONAL.GET_OPTIONAL_VALUE(values[index]);
|
||||
index = (int)links[index];
|
||||
}
|
||||
return EMPTY_VALUE;
|
||||
return VALUE_OPTIONAL.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1219,7 +1392,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
int result = 0;
|
||||
int index = firstIndex;
|
||||
while(index != -1){
|
||||
if(filter.VALUE_TEST_VALUE(values[index])) result++;
|
||||
if(filter.test(values[index])) result++;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return result;
|
||||
@@ -1229,7 +1402,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
private class FastEntryIterator extends MapIterator implements ObjectListIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> {
|
||||
MapEntry entry = new MapEntry();
|
||||
|
||||
public FastEntryIterator() {}
|
||||
public FastEntryIterator(boolean start) { super(start); }
|
||||
public FastEntryIterator(KEY_TYPE from) {
|
||||
super(from);
|
||||
}
|
||||
@@ -1256,19 +1429,19 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
private class EntryIterator extends MapIterator implements ObjectListIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> {
|
||||
MapEntry entry;
|
||||
|
||||
public EntryIterator() {}
|
||||
public EntryIterator(boolean start) { super(start); }
|
||||
public EntryIterator(KEY_TYPE from) {
|
||||
super(from);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE next() {
|
||||
return entry = new MapEntry(nextEntry());
|
||||
return entry = new ValueMapEntry(nextEntry());
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE previous() {
|
||||
return entry = new MapEntry(previousEntry());
|
||||
return entry = new ValueMapEntry(previousEntry());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1286,7 +1459,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
|
||||
private class KeyIterator extends MapIterator implements LIST_ITERATOR KEY_GENERIC_TYPE {
|
||||
|
||||
public KeyIterator() {}
|
||||
public KeyIterator(boolean start) { super(start); }
|
||||
public KeyIterator(KEY_TYPE from) {
|
||||
super(from);
|
||||
}
|
||||
@@ -1308,7 +1481,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
}
|
||||
|
||||
private class ValueIterator extends MapIterator implements VALUE_LIST_ITERATOR VALUE_GENERIC_TYPE {
|
||||
public ValueIterator() {}
|
||||
public ValueIterator(boolean start) { super(start); }
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE VALUE_PREVIOUS() {
|
||||
@@ -1329,16 +1502,20 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
}
|
||||
|
||||
private class MapIterator {
|
||||
boolean forward;
|
||||
int previous = -1;
|
||||
int next = -1;
|
||||
int current = -1;
|
||||
int index = 0;
|
||||
|
||||
MapIterator() {
|
||||
next = firstIndex;
|
||||
MapIterator(boolean start) {
|
||||
this.forward = start;
|
||||
if(start) next = firstIndex;
|
||||
else previous = lastIndex;
|
||||
}
|
||||
|
||||
MapIterator(KEY_TYPE from) {
|
||||
this.forward = true;
|
||||
if(strategy.equals(from, EMPTY_KEY_VALUE)) {
|
||||
if(containsNull) {
|
||||
next = (int) links[nullIndex];
|
||||
@@ -1366,11 +1543,11 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return next != -1;
|
||||
return (forward ? next : previous) != -1;
|
||||
}
|
||||
|
||||
public boolean hasPrevious() {
|
||||
return previous != -1;
|
||||
return (forward ? previous : next) != -1;
|
||||
}
|
||||
|
||||
public int nextIndex() {
|
||||
@@ -1430,20 +1607,30 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
|
||||
public int previousEntry() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
current = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
next = current;
|
||||
if(forward) moveBackwards();
|
||||
else moveForwards();
|
||||
if(index >= 0) index--;
|
||||
return current;
|
||||
}
|
||||
|
||||
public int nextEntry() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
if(forward) moveForwards();
|
||||
else moveBackwards();
|
||||
if(index >= 0) index++;
|
||||
return current;
|
||||
}
|
||||
|
||||
private void moveBackwards() {
|
||||
current = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
next = current;
|
||||
}
|
||||
|
||||
private void moveForwards() {
|
||||
current = next;
|
||||
next = (int)(links[current]);
|
||||
previous = current;
|
||||
if(index >= 0) index++;
|
||||
return current;
|
||||
}
|
||||
|
||||
private void ensureIndexKnown() {
|
||||
|
||||
+293
-109
@@ -5,28 +5,49 @@ import java.util.ConcurrentModificationException;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Predicate;
|
||||
#if !TYPE_OBJECT && JDK_TYPE
|
||||
import java.util.function.PREDICATE;
|
||||
import java.util.OPTIONAL;
|
||||
#endif
|
||||
#if !SAME_TYPE && JDK_VALUE && !VALUE_OBJECT
|
||||
import java.util.function.VALUE_PREDICATE;
|
||||
import java.util.VALUE_OPTIONAL;
|
||||
#endif
|
||||
|
||||
#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.ints.functions.consumer.BI_FROM_INT_CONSUMER;
|
||||
#if !TYPE_OBJECT && !VALUE_OBJECT
|
||||
import speiger.src.collections.ints.functions.consumer.IntObjectConsumer;
|
||||
#endif
|
||||
#if !SAME_TYPE && !TYPE_INT
|
||||
import speiger.src.collections.ints.functions.consumer.VALUE_BI_FROM_INT_CONSUMER;
|
||||
#endif
|
||||
#if !TYPE_INT || !SAME_TYPE
|
||||
import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
|
||||
#endif
|
||||
#if !VALUE_BOOLEAN || !JDK_TYPE
|
||||
import speiger.src.collections.PACKAGE.functions.function.FUNCTION;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||
#if !SAME_TYPE
|
||||
import speiger.src.collections.PACKAGE.functions.function.SINGLE_UNARY_OPERATOR;
|
||||
#endif
|
||||
#if !TYPE_OBJECT && !VALUE_BOOLEAN
|
||||
#if !TYPE_OBJECT && !JDK_TYPE
|
||||
import speiger.src.collections.PACKAGE.functions.OPTIONAL;
|
||||
#if !VALUE_BOOLEAN
|
||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.lists.ARRAY_LIST;
|
||||
import speiger.src.collections.PACKAGE.lists.LIST;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.maps.abstracts.ABSTRACT_MAP;
|
||||
import speiger.src.collections.PACKAGE.maps.interfaces.MAP;
|
||||
import speiger.src.collections.PACKAGE.utils.maps.MAPS;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.sets.ABSTRACT_SET;
|
||||
import speiger.src.collections.PACKAGE.sets.SET;
|
||||
@@ -42,6 +63,7 @@ import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_UNARY_OPER
|
||||
#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
|
||||
@@ -52,17 +74,15 @@ import speiger.src.collections.objects.functions.function.ObjectObjectUnaryOpera
|
||||
#if !TYPE_OBJECT && !VALUE_OBJECT || !VALUE_OBJECT
|
||||
import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer;
|
||||
#endif
|
||||
#if !TYPE_OBJECT || !VALUE_BOOLEAN
|
||||
#if !VALUE_OBJECT || SAME_TYPE
|
||||
import speiger.src.collections.objects.functions.function.Object2BooleanFunction;
|
||||
#endif
|
||||
#endif
|
||||
#if !SAME_TYPE
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.objects.functions.consumer.VALUE_BI_FROM_OBJECT_CONSUMER;
|
||||
|
||||
#endif
|
||||
#if !JDK_VALUE
|
||||
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE;
|
||||
import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_OPTIONAL;
|
||||
#endif
|
||||
#endif
|
||||
import speiger.src.collections.objects.collections.ObjectIterator;
|
||||
import speiger.src.collections.objects.sets.AbstractObjectSet;
|
||||
@@ -270,6 +290,11 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
insert(-slot-1, key, value);
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
else if(VALUE_EQUALS(values[slot], getDefaultReturnValue())) {
|
||||
VALUE_TYPE oldValue = values[slot];
|
||||
values[slot] = value;
|
||||
return oldValue;
|
||||
}
|
||||
return values[slot];
|
||||
}
|
||||
|
||||
@@ -519,6 +544,95 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
int index = findIndex(key);
|
||||
if(index < 0) {
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, getDefaultReturnValue());
|
||||
#if VALUE_OBJECT
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
#endif
|
||||
insert(-index-1, key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
|
||||
#if VALUE_OBJECT
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
removeIndex(index);
|
||||
return newValue;
|
||||
}
|
||||
#endif
|
||||
values[index] = newValue;
|
||||
return newValue;
|
||||
}
|
||||
|
||||
@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.APPLY(key);
|
||||
#if VALUE_OBJECT
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
#endif
|
||||
insert(-index-1, key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
VALUE_TYPE newValue = values[index];
|
||||
#if VALUE_OBJECT
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
newValue = mappingFunction.APPLY(key);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
values[index] = newValue;
|
||||
}
|
||||
#endif
|
||||
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_SUPPLY_GET();
|
||||
#if VALUE_OBJECT
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
#endif
|
||||
insert(-index-1, key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
VALUE_TYPE newValue = values[index];
|
||||
#if VALUE_OBJECT
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
newValue = valueProvider.VALUE_SUPPLY_GET();
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
values[index] = newValue;
|
||||
}
|
||||
#endif
|
||||
return newValue;
|
||||
}
|
||||
|
||||
@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 !VALUE_OBJECT
|
||||
if(index < 0) return getDefaultReturnValue();
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
|
||||
#else
|
||||
if(index < 0 || VALUE_EQUALS(values[index], getDefaultReturnValue())) return getDefaultReturnValue();
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
removeIndex(index);
|
||||
return newValue;
|
||||
}
|
||||
#endif
|
||||
values[index] = newValue;
|
||||
return newValue;
|
||||
}
|
||||
|
||||
#if !VALUE_OBJECT
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTENonDefault(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());
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
insert(-index-1, key, newValue);
|
||||
return newValue;
|
||||
@@ -533,18 +647,18 @@ 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) {
|
||||
public VALUE_TYPE COMPUTE_IF_ABSENTNonDefault(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);
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY(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 = mappingFunction.GET_VALUE(key);
|
||||
newValue = mappingFunction.APPLY(key);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
values[index] = newValue;
|
||||
}
|
||||
@@ -552,18 +666,18 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENT(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENTNonDefault(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();
|
||||
VALUE_TYPE newValue = valueProvider.VALUE_SUPPLY_GET();
|
||||
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();
|
||||
newValue = valueProvider.VALUE_SUPPLY_GET();
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
values[index] = newValue;
|
||||
}
|
||||
@@ -571,7 +685,7 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENTNonDefault(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();
|
||||
@@ -584,6 +698,7 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
return newValue;
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public VALUE_TYPE MERGE(KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
@@ -604,7 +719,7 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
@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)) {
|
||||
for(MAP.Entry KEY_VALUE_GENERIC_TYPE entry : getFastIterable(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());
|
||||
@@ -772,6 +887,33 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
}
|
||||
}
|
||||
|
||||
protected class ValueMapEntry extends MapEntry {
|
||||
protected KEY_TYPE key;
|
||||
protected VALUE_TYPE value;
|
||||
|
||||
public ValueMapEntry(int index) {
|
||||
super(index);
|
||||
key = keys[index];
|
||||
value = values[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE ENTRY_KEY() {
|
||||
return key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE ENTRY_VALUE() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE setValue(VALUE_TYPE value) {
|
||||
this.value = value;
|
||||
return super.setValue(value);
|
||||
}
|
||||
}
|
||||
|
||||
protected class MapEntry implements MAP.Entry KEY_VALUE_GENERIC_TYPE, Map.Entry<CLASS_TYPE, CLASS_VALUE_TYPE> {
|
||||
public int index = -1;
|
||||
|
||||
@@ -780,6 +922,10 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
void set(int index) {
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE ENTRY_KEY() {
|
||||
return keys[index];
|
||||
@@ -802,19 +948,19 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
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());
|
||||
return KEY_EQUALS(ENTRY_KEY(), entry.ENTRY_KEY()) && VALUE_EQUALS(ENTRY_VALUE(), 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);
|
||||
return KEY_EQUALS(ENTRY_KEY(), key) && VALUE_EQUALS(ENTRY_VALUE(), value);
|
||||
#else if TYPE_OBJECT
|
||||
return value instanceof CLASS_VALUE_TYPE && KEY_EQUALS(keys[index], key) && VALUE_EQUALS(values[index], CLASS_TO_VALUE(value));
|
||||
return value instanceof CLASS_VALUE_TYPE && KEY_EQUALS(ENTRY_KEY(), key) && VALUE_EQUALS(ENTRY_VALUE(), 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);
|
||||
return key instanceof CLASS_TYPE && KEY_EQUALS(ENTRY_KEY(), CLASS_TO_KEY(key)) && VALUE_EQUALS(ENTRY_VALUE(), 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));
|
||||
return key instanceof CLASS_TYPE && value instanceof CLASS_VALUE_TYPE && KEY_EQUALS(ENTRY_KEY(), CLASS_TO_KEY(key)) && VALUE_EQUALS(ENTRY_VALUE(), CLASS_TO_VALUE(value));
|
||||
#endif
|
||||
}
|
||||
return false;
|
||||
@@ -822,12 +968,12 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return strategy.hashCode(keys[index]) ^ VALUE_TO_HASH(values[index]);
|
||||
return strategy.hashCode(ENTRY_KEY()) ^ VALUE_TO_HASH(ENTRY_VALUE());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return KEY_TO_STRING(keys[index]) + "=" + VALUE_TO_STRING(values[index]);
|
||||
return KEY_TO_STRING(ENTRY_KEY()) + "=" + VALUE_TO_STRING(ENTRY_VALUE());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -844,85 +990,95 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
|
||||
@Override
|
||||
public void forEach(Consumer<? super MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
|
||||
if(containsNull) action.accept(new BasicEntryKV_BRACES(keys[nullIndex], values[nullIndex]));
|
||||
if(containsNull) action.accept(new ValueMapEntry(nullIndex));
|
||||
for(int i = nullIndex-1;i>=0;i--)
|
||||
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) action.accept(new BasicEntryKV_BRACES(keys[i], values[i]));
|
||||
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) action.accept(new ValueMapEntry(i));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fastForEach(Consumer<? super MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
|
||||
MapEntry entry = new MapEntry();
|
||||
if(containsNull) {
|
||||
entry.set(keys[nullIndex], values[nullIndex]);
|
||||
entry.set(nullIndex);
|
||||
action.accept(entry);
|
||||
}
|
||||
for(int i = nullIndex-1;i>=0;i--) {
|
||||
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) {
|
||||
entry.set(keys[i], values[i]);
|
||||
entry.set(i);
|
||||
action.accept(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEachIndexed(IntObjectConsumer<MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
|
||||
Objects.requireNonNull(action);
|
||||
if(size() <= 0) return;
|
||||
if(containsNull) action.accept(0, new ValueMapEntry(nullIndex));
|
||||
for(int i = nullIndex-1, index = containsNull ? 1 : 0;i>=0;i--) {
|
||||
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) action.accept(index++, new ValueMapEntry(i));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, ObjectObjectConsumer<E, MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
|
||||
Objects.requireNonNull(action);
|
||||
if(size() <= 0) return;
|
||||
if(containsNull) action.accept(input, new BasicEntryKV_BRACES(keys[nullIndex], values[nullIndex]));
|
||||
if(containsNull) action.accept(input, new ValueMapEntry(nullIndex));
|
||||
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(input, new ValueMapEntry(i));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matchesAny(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
public boolean matchesAny(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return false;
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
|
||||
MapEntry entry = new MapEntry();
|
||||
if(containsNull) {
|
||||
entry.set(keys[nullIndex], values[nullIndex]);
|
||||
if(filter.getBoolean(entry)) return true;
|
||||
entry.set(nullIndex);
|
||||
if(filter.test(entry)) return true;
|
||||
}
|
||||
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)) return true;
|
||||
entry.set(i);
|
||||
if(filter.test(entry)) return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matchesNone(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
public boolean matchesNone(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return true;
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
|
||||
MapEntry entry = new MapEntry();
|
||||
if(containsNull) {
|
||||
entry.set(keys[nullIndex], values[nullIndex]);
|
||||
if(filter.getBoolean(entry)) return false;
|
||||
entry.set(nullIndex);
|
||||
if(filter.test(entry)) return false;
|
||||
}
|
||||
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)) return false;
|
||||
entry.set(i);
|
||||
if(filter.test(entry)) return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matchesAll(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
public boolean matchesAll(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return true;
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
|
||||
MapEntry entry = new MapEntry();
|
||||
if(containsNull) {
|
||||
entry.set(keys[nullIndex], values[nullIndex]);
|
||||
if(!filter.getBoolean(entry)) return false;
|
||||
entry.set(nullIndex);
|
||||
if(!filter.test(entry)) return false;
|
||||
}
|
||||
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)) return false;
|
||||
entry.set(i);
|
||||
if(!filter.test(entry)) return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
@@ -932,67 +1088,67 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
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]));
|
||||
if(containsNull) state = operator.apply(state, new ValueMapEntry(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]));
|
||||
state = operator.apply(state, new ValueMapEntry(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) {
|
||||
public Optional<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]);
|
||||
state = new ValueMapEntry(nullIndex);
|
||||
empty = false;
|
||||
}
|
||||
for(int i = nullIndex-1;i>=0;i--) {
|
||||
if(strategy.equals(keys[i], EMPTY_KEY_VALUE)) continue;
|
||||
if(empty) {
|
||||
empty = false;
|
||||
state = new BasicEntryKV_BRACES(keys[i], values[i]);
|
||||
state = new ValueMapEntry(i);
|
||||
continue;
|
||||
}
|
||||
state = operator.apply(state, new BasicEntryKV_BRACES(keys[i], values[i]));
|
||||
state = operator.apply(state, new ValueMapEntry(i));
|
||||
}
|
||||
return state;
|
||||
return empty ? Optional.empty() : Optional.ofNullable(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
public Optional<MAP.Entry KEY_VALUE_GENERIC_TYPE> findFirst(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return null;
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
|
||||
if(size() <= 0) return Optional.empty();
|
||||
MapEntry entry = new MapEntry();
|
||||
if(containsNull) {
|
||||
entry.set(keys[nullIndex], values[nullIndex]);
|
||||
if(filter.getBoolean(entry)) return entry;
|
||||
entry.set(nullIndex);
|
||||
if(filter.test(entry)) return Optional.ofNullable(entry);
|
||||
}
|
||||
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)) return entry;
|
||||
entry.set(i);
|
||||
if(filter.test(entry)) return Optional.ofNullable(entry);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
public int count(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return 0;
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
|
||||
MapEntry entry = new MapEntry();
|
||||
int result = 0;
|
||||
if(containsNull) {
|
||||
entry.set(keys[nullIndex], values[nullIndex]);
|
||||
if(filter.getBoolean(entry)) result++;
|
||||
entry.set(nullIndex);
|
||||
if(filter.test(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++;
|
||||
entry.set(i);
|
||||
if(filter.test(entry)) result++;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
@@ -1101,6 +1257,16 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) action.accept(keys[i]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
|
||||
Objects.requireNonNull(action);
|
||||
if(size() <= 0) return;
|
||||
if(containsNull) action.accept(0, keys[nullIndex]);
|
||||
for(int i = nullIndex-1, index = containsNull ? 1 : 0;i>=0;i--) {
|
||||
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) action.accept(index++, keys[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
@@ -1115,9 +1281,9 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
public boolean matchesAny(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return false;
|
||||
if(containsNull && filter.TEST_VALUE(keys[nullIndex])) return true;
|
||||
if(containsNull && filter.test(keys[nullIndex])) return true;
|
||||
for(int i = nullIndex-1;i>=0;i--) {
|
||||
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE) && filter.TEST_VALUE(keys[i])) return true;
|
||||
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE) && filter.test(keys[i])) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -1126,9 +1292,9 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
public boolean matchesNone(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return true;
|
||||
if(containsNull && filter.TEST_VALUE(keys[nullIndex])) return false;
|
||||
if(containsNull && filter.test(keys[nullIndex])) return false;
|
||||
for(int i = nullIndex-1;i>=0;i--) {
|
||||
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE) && filter.TEST_VALUE(keys[i])) return false;
|
||||
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE) && filter.test(keys[i])) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -1137,9 +1303,9 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
public boolean matchesAll(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return true;
|
||||
if(containsNull && !filter.TEST_VALUE(keys[nullIndex])) return false;
|
||||
if(containsNull && !filter.test(keys[nullIndex])) return false;
|
||||
for(int i = nullIndex-1;i>=0;i--) {
|
||||
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE) && !filter.TEST_VALUE(keys[i])) return false;
|
||||
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE) && !filter.test(keys[i])) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -1172,7 +1338,7 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public KEY_TYPE reduce(SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
public OPTIONAL KEY_GENERIC_TYPE reduce(SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = EMPTY_KEY_VALUE;
|
||||
boolean empty = true;
|
||||
@@ -1189,18 +1355,18 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
}
|
||||
state = operator.APPLY_KEY_VALUE(state, keys[i]);
|
||||
}
|
||||
return state;
|
||||
return empty ? OPTIONAL.empty() : OPTIONAL.GET_OPTIONAL(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
public OPTIONAL KEY_GENERIC_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return EMPTY_KEY_VALUE;
|
||||
if(containsNull && filter.TEST_VALUE(keys[nullIndex])) return keys[nullIndex];
|
||||
if(size() <= 0) return OPTIONAL.empty();
|
||||
if(containsNull && filter.test(keys[nullIndex])) return OPTIONAL.GET_OPTIONAL(keys[nullIndex]);
|
||||
for(int i = nullIndex-1;i>=0;i--) {
|
||||
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE) && filter.TEST_VALUE(keys[i])) return keys[i];
|
||||
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE) && filter.test(keys[i])) return OPTIONAL.GET_OPTIONAL(keys[i]);
|
||||
}
|
||||
return EMPTY_KEY_VALUE;
|
||||
return OPTIONAL.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1208,9 +1374,9 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return 0;
|
||||
int result = 0;
|
||||
if(containsNull && filter.TEST_VALUE(keys[nullIndex])) result++;
|
||||
if(containsNull && filter.test(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++;
|
||||
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE) && filter.test(keys[i])) result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -1257,6 +1423,16 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) action.accept(values[i]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEachIndexed(VALUE_BI_FROM_INT_CONSUMER VALUE_GENERIC_TYPE action) {
|
||||
Objects.requireNonNull(action);
|
||||
if(size() <= 0) return;
|
||||
if(containsNull) action.accept(0, values[nullIndex]);
|
||||
for(int i = nullIndex-1, index = containsNull ? 1 : 0;i>=0;i--) {
|
||||
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) action.accept(index++, values[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, VALUE_BI_FROM_OBJECT_CONSUMER VSV_GENERIC_TYPE<E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
@@ -1271,9 +1447,9 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
public boolean matchesAny(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return false;
|
||||
if(containsNull && filter.VALUE_TEST_VALUE(values[nullIndex])) return true;
|
||||
if(containsNull && filter.test(values[nullIndex])) return true;
|
||||
for(int i = nullIndex-1;i>=0;i--) {
|
||||
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE) && filter.VALUE_TEST_VALUE(values[i])) return true;
|
||||
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE) && filter.test(values[i])) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -1282,9 +1458,9 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
public boolean matchesNone(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return true;
|
||||
if(containsNull && filter.VALUE_TEST_VALUE(values[nullIndex])) return false;
|
||||
if(containsNull && filter.test(values[nullIndex])) return false;
|
||||
for(int i = nullIndex-1;i>=0;i--) {
|
||||
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE) && filter.VALUE_TEST_VALUE(values[i])) return false;
|
||||
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE) && filter.test(values[i])) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -1293,9 +1469,9 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
public boolean matchesAll(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return true;
|
||||
if(containsNull && !filter.VALUE_TEST_VALUE(values[nullIndex])) return false;
|
||||
if(containsNull && !filter.test(values[nullIndex])) return false;
|
||||
for(int i = nullIndex-1;i>=0;i--) {
|
||||
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE) && !filter.VALUE_TEST_VALUE(values[i])) return false;
|
||||
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE) && !filter.test(values[i])) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -1328,7 +1504,7 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public VALUE_TYPE reduce(VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
|
||||
public VALUE_OPTIONAL VALUE_GENERIC_TYPE reduce(VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
VALUE_TYPE state = EMPTY_VALUE;
|
||||
boolean empty = true;
|
||||
@@ -1345,18 +1521,18 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
}
|
||||
state = operator.APPLY_VALUE(state, values[i]);
|
||||
}
|
||||
return state;
|
||||
return empty ? VALUE_OPTIONAL.empty() : VALUE_OPTIONAL.GET_OPTIONAL_VALUE(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
||||
public VALUE_OPTIONAL VALUE_GENERIC_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return EMPTY_VALUE;
|
||||
if(containsNull && filter.VALUE_TEST_VALUE(values[nullIndex])) return values[nullIndex];
|
||||
if(size() <= 0) return VALUE_OPTIONAL.empty();
|
||||
if(containsNull && filter.test(values[nullIndex])) return VALUE_OPTIONAL.GET_OPTIONAL_VALUE(values[nullIndex]);
|
||||
for(int i = nullIndex-1;i>=0;i--) {
|
||||
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE) && filter.VALUE_TEST_VALUE(values[i])) return values[i];
|
||||
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE) && filter.test(values[i])) return VALUE_OPTIONAL.GET_OPTIONAL_VALUE(values[i]);
|
||||
}
|
||||
return EMPTY_VALUE;
|
||||
return VALUE_OPTIONAL.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1364,9 +1540,9 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return 0;
|
||||
int result = 0;
|
||||
if(containsNull && filter.VALUE_TEST_VALUE(values[nullIndex])) result++;
|
||||
if(containsNull && filter.test(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++;
|
||||
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE) && filter.test(values[i])) result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -1385,7 +1561,7 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
MapEntry entry;
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE next() {
|
||||
return entry = new MapEntry(nextEntry());
|
||||
return entry = new ValueMapEntry(nextEntry());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1415,7 +1591,8 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
int lastReturned = -1;
|
||||
int nextIndex = Integer.MIN_VALUE;
|
||||
boolean returnNull = containsNull;
|
||||
LIST KEY_GENERIC_TYPE wrapped = null;
|
||||
KEY_TYPE[] wrapped = null;
|
||||
int wrappedIndex = 0;
|
||||
|
||||
public boolean hasNext() {
|
||||
if(nextIndex == Integer.MIN_VALUE) {
|
||||
@@ -1427,7 +1604,7 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
{
|
||||
while(true) {
|
||||
if(--pos < 0) {
|
||||
if(wrapped == null || wrapped.size() <= -pos - 1) break;
|
||||
if(wrapped == null || wrappedIndex <= -pos - 1) break;
|
||||
nextIndex = -pos - 1;
|
||||
break;
|
||||
}
|
||||
@@ -1446,7 +1623,7 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
returnedPos = pos;
|
||||
if(nextIndex < 0){
|
||||
lastReturned = Integer.MAX_VALUE;
|
||||
int value = findIndex(wrapped.GET_KEY(nextIndex));
|
||||
int value = findIndex(wrapped[nextIndex]);
|
||||
if(value < 0) throw new IllegalStateException("Entry ["+nextIndex+"] was removed during Iteration");
|
||||
nextIndex = Integer.MIN_VALUE;
|
||||
return value;
|
||||
@@ -1465,7 +1642,7 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
}
|
||||
else if(returnedPos >= 0) shiftKeys(returnedPos);
|
||||
else {
|
||||
CUSTOM_HASH_MAP.this.remove(wrapped.GET_KEY(-returnedPos - 1));
|
||||
CUSTOM_HASH_MAP.this.remove(wrapped[-returnedPos - 1]);
|
||||
lastReturned = -1;
|
||||
return;
|
||||
}
|
||||
@@ -1488,13 +1665,20 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
if(last <= startPos ? (last >= slot || slot > startPos) : (last >= slot && slot > startPos)) break;
|
||||
startPos = ++startPos & mask;
|
||||
}
|
||||
if(startPos < last) {
|
||||
if(wrapped == null) wrapped = new ARRAY_LISTBRACES(2);
|
||||
wrapped.add(keys[startPos]);
|
||||
}
|
||||
if(startPos < last) addWrapper(keys[startPos]);
|
||||
keys[last] = current;
|
||||
values[last] = values[startPos];
|
||||
}
|
||||
}
|
||||
|
||||
private void addWrapper(KEY_TYPE value) {
|
||||
if(wrapped == null) wrapped = NEW_KEY_ARRAY(2);
|
||||
else if(wrappedIndex >= wrapped.length) {
|
||||
KEY_TYPE[] newArray = NEW_KEY_ARRAY(wrapped.length * 2);
|
||||
System.arraycopy(wrapped, 0, newArray, 0, wrapped.length);
|
||||
wrapped = newArray;
|
||||
}
|
||||
wrapped[wrappedIndex++] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
+317
-127
@@ -3,19 +3,39 @@ package speiger.src.collections.PACKAGE.maps.impl.hash;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Predicate;
|
||||
#if !TYPE_OBJECT && JDK_TYPE
|
||||
import java.util.function.PREDICATE;
|
||||
import java.util.OPTIONAL;
|
||||
#endif
|
||||
#if !SAME_TYPE && JDK_VALUE && !VALUE_OBJECT
|
||||
import java.util.function.VALUE_PREDICATE;
|
||||
import java.util.VALUE_OPTIONAL;
|
||||
#endif
|
||||
|
||||
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||
#endif
|
||||
#if !TYPE_OBJECT || VALUE_BOOLEAN
|
||||
import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
|
||||
#if !TYPE_OBJECT && !VALUE_OBJECT
|
||||
import speiger.src.collections.ints.functions.consumer.IntObjectConsumer;
|
||||
#endif
|
||||
#if !SAME_TYPE && !TYPE_INT
|
||||
import speiger.src.collections.ints.functions.consumer.VALUE_BI_FROM_INT_CONSUMER;
|
||||
#endif
|
||||
#if !TYPE_OBJECT && !JDK_TYPE
|
||||
import speiger.src.collections.PACKAGE.functions.OPTIONAL;
|
||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||
#endif
|
||||
#if !TYPE_INT || !SAME_TYPE
|
||||
import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
|
||||
#endif
|
||||
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;
|
||||
@@ -23,7 +43,7 @@ import speiger.src.collections.PACKAGE.maps.interfaces.ORDERED_MAP;
|
||||
import speiger.src.collections.PACKAGE.sets.ABSTRACT_SET;
|
||||
import speiger.src.collections.PACKAGE.sets.ORDERED_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_ORDERED_COLLECTION;
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ITERATOR;
|
||||
#if !SAME_TYPE
|
||||
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_UNARY_OPERATOR;
|
||||
@@ -35,17 +55,15 @@ import speiger.src.collections.VALUE_PACKAGE.lists.VALUE_LIST_ITERATOR;
|
||||
#if !TYPE_OBJECT && !VALUE_OBJECT || !VALUE_OBJECT
|
||||
import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer;
|
||||
#endif
|
||||
#if !TYPE_OBJECT || !VALUE_BOOLEAN
|
||||
#if !VALUE_OBJECT || SAME_TYPE
|
||||
import speiger.src.collections.objects.functions.function.Object2BooleanFunction;
|
||||
#endif
|
||||
#endif
|
||||
#if !SAME_TYPE
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.objects.functions.consumer.VALUE_BI_FROM_OBJECT_CONSUMER;
|
||||
|
||||
#endif
|
||||
#if !JDK_VALUE
|
||||
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE;
|
||||
import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_OPTIONAL;
|
||||
#endif
|
||||
#endif
|
||||
#if !TYPE_OBJECT
|
||||
#if !VALUE_OBJECT
|
||||
@@ -197,13 +215,13 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
if(containsNull) {
|
||||
VALUE_TYPE lastValue = values[nullIndex];
|
||||
values[nullIndex] = value;
|
||||
moveToFirstIndex(nullIndex);
|
||||
moveToFirstIndex(nullIndex, false);
|
||||
return lastValue;
|
||||
}
|
||||
values[nullIndex] = value;
|
||||
containsNull = true;
|
||||
onNodeAdded(nullIndex);
|
||||
moveToFirstIndex(nullIndex);
|
||||
moveToFirstIndex(nullIndex, true);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(KEY_TO_HASH(key)) & mask;
|
||||
@@ -211,7 +229,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
if(KEY_EQUALS(keys[pos], key)) {
|
||||
VALUE_TYPE lastValue = values[pos];
|
||||
values[pos] = value;
|
||||
moveToFirstIndex(pos);
|
||||
moveToFirstIndex(pos, false);
|
||||
return lastValue;
|
||||
}
|
||||
pos = ++pos & mask;
|
||||
@@ -219,7 +237,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
keys[pos] = key;
|
||||
values[pos] = value;
|
||||
onNodeAdded(pos);
|
||||
moveToFirstIndex(pos);
|
||||
moveToFirstIndex(pos, true);
|
||||
}
|
||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||
return getDefaultReturnValue();
|
||||
@@ -231,13 +249,13 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
if(containsNull) {
|
||||
VALUE_TYPE lastValue = values[nullIndex];
|
||||
values[nullIndex] = value;
|
||||
moveToLastIndex(nullIndex);
|
||||
moveToLastIndex(nullIndex, false);
|
||||
return lastValue;
|
||||
}
|
||||
values[nullIndex] = value;
|
||||
containsNull = true;
|
||||
onNodeAdded(nullIndex);
|
||||
moveToLastIndex(nullIndex);
|
||||
moveToLastIndex(nullIndex, true);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(KEY_TO_HASH(key)) & mask;
|
||||
@@ -245,7 +263,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
if(KEY_EQUALS(keys[pos], key)) {
|
||||
VALUE_TYPE lastValue = values[pos];
|
||||
values[pos] = value;
|
||||
moveToLastIndex(pos);
|
||||
moveToLastIndex(pos, false);
|
||||
return lastValue;
|
||||
}
|
||||
pos = ++pos & mask;
|
||||
@@ -253,7 +271,55 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
keys[pos] = key;
|
||||
values[pos] = value;
|
||||
onNodeAdded(pos);
|
||||
moveToLastIndex(pos);
|
||||
moveToLastIndex(pos, true);
|
||||
}
|
||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE putFirst(KEY_TYPE key, VALUE_TYPE value) {
|
||||
if(KEY_EQUALS_NULL(key)) {
|
||||
if(containsNull) return values[nullIndex];
|
||||
values[nullIndex] = value;
|
||||
containsNull = true;
|
||||
onNodeAdded(nullIndex);
|
||||
moveToFirstIndex(nullIndex, true);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(KEY_TO_HASH(key)) & mask;
|
||||
while(KEY_EQUALS_NOT_NULL(keys[pos])) {
|
||||
if(KEY_EQUALS(keys[pos], key)) return values[pos];
|
||||
pos = ++pos & mask;
|
||||
}
|
||||
keys[pos] = key;
|
||||
values[pos] = value;
|
||||
onNodeAdded(pos);
|
||||
moveToFirstIndex(pos, true);
|
||||
}
|
||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE putLast(KEY_TYPE key, VALUE_TYPE value) {
|
||||
if(KEY_EQUALS_NULL(key)) {
|
||||
if(containsNull) return values[nullIndex];
|
||||
values[nullIndex] = value;
|
||||
containsNull = true;
|
||||
onNodeAdded(nullIndex);
|
||||
moveToLastIndex(nullIndex, true);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(KEY_TO_HASH(key)) & mask;
|
||||
while(KEY_EQUALS_NOT_NULL(keys[pos])) {
|
||||
if(KEY_EQUALS(keys[pos], key)) return values[pos];
|
||||
pos = ++pos & mask;
|
||||
}
|
||||
keys[pos] = key;
|
||||
values[pos] = value;
|
||||
onNodeAdded(pos);
|
||||
moveToLastIndex(pos, true);
|
||||
}
|
||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||
return getDefaultReturnValue();
|
||||
@@ -264,7 +330,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
if(isEmpty() || KEY_EQUALS(FIRST_ENTRY_KEY(), key)) return false;
|
||||
if(KEY_EQUALS_NULL(key)) {
|
||||
if(containsNull) {
|
||||
moveToFirstIndex(nullIndex);
|
||||
moveToFirstIndex(nullIndex, false);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -272,7 +338,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
int pos = HashUtil.mix(KEY_TO_HASH(key)) & mask;
|
||||
while(KEY_EQUALS_NOT_NULL(keys[pos])) {
|
||||
if(KEY_EQUALS(keys[pos], key)) {
|
||||
moveToFirstIndex(pos);
|
||||
moveToFirstIndex(pos, false);
|
||||
return true;
|
||||
}
|
||||
pos = ++pos & mask;
|
||||
@@ -286,7 +352,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
if(isEmpty() || KEY_EQUALS(LAST_ENTRY_KEY(), key)) return false;
|
||||
if(KEY_EQUALS_NULL(key)) {
|
||||
if(containsNull) {
|
||||
moveToLastIndex(nullIndex);
|
||||
moveToLastIndex(nullIndex, false);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -294,7 +360,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
int pos = HashUtil.mix(KEY_TO_HASH(key)) & mask;
|
||||
while(KEY_EQUALS_NOT_NULL(keys[pos])) {
|
||||
if(KEY_EQUALS(keys[pos], key)) {
|
||||
moveToLastIndex(pos);
|
||||
moveToLastIndex(pos, false);
|
||||
return true;
|
||||
}
|
||||
pos = ++pos & mask;
|
||||
@@ -307,7 +373,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
public VALUE_TYPE getAndMoveToFirst(KEY_TYPE key) {
|
||||
int index = findIndex(key);
|
||||
if(index < 0) return getDefaultReturnValue();
|
||||
moveToFirstIndex(index);
|
||||
moveToFirstIndex(index, false);
|
||||
return values[index];
|
||||
}
|
||||
|
||||
@@ -315,7 +381,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
public VALUE_TYPE getAndMoveToLast(KEY_TYPE key) {
|
||||
int index = findIndex(key);
|
||||
if(index < 0) return getDefaultReturnValue();
|
||||
moveToLastIndex(index);
|
||||
moveToLastIndex(index, false);
|
||||
return values[index];
|
||||
}
|
||||
|
||||
@@ -421,6 +487,52 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
return values[lastIndex];
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE firstEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return new BasicEntryKV_BRACES(keys[firstIndex], values[firstIndex]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE lastEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return new BasicEntryKV_BRACES(keys[lastIndex], values[lastIndex]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollFirstEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
int pos = firstIndex;
|
||||
onNodeRemoved(pos);
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE result = new BasicEntryKV_BRACES(keys[pos], values[pos]);
|
||||
size--;
|
||||
if(KEY_EQUALS_NULL(result.ENTRY_KEY())) {
|
||||
containsNull = false;
|
||||
keys[nullIndex] = EMPTY_KEY_VALUE;
|
||||
values[nullIndex] = EMPTY_VALUE;
|
||||
}
|
||||
else shiftKeys(pos);
|
||||
if(nullIndex > minCapacity && size < maxFill / 4 && nullIndex > HashUtil.DEFAULT_MIN_CAPACITY) rehash(nullIndex / 2);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollLastEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
int pos = lastIndex;
|
||||
onNodeRemoved(pos);
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE result = new BasicEntryKV_BRACES(keys[pos], values[pos]);
|
||||
size--;
|
||||
if(KEY_EQUALS_NULL(result.ENTRY_KEY())) {
|
||||
containsNull = false;
|
||||
keys[nullIndex] = EMPTY_KEY_VALUE;
|
||||
values[nullIndex] = EMPTY_VALUE;
|
||||
}
|
||||
else shiftKeys(pos);
|
||||
if(nullIndex > minCapacity && size < maxFill / 4 && nullIndex > HashUtil.DEFAULT_MIN_CAPACITY) rehash(nullIndex / 2);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectOrderedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> ENTRY_SET() {
|
||||
if(entrySet == null) entrySet = new MapEntrySet();
|
||||
@@ -434,9 +546,9 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_COLLECTION VALUE_GENERIC_TYPE values() {
|
||||
public VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE values() {
|
||||
if(valuesC == null) valuesC = new Values();
|
||||
return valuesC;
|
||||
return (VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE)valuesC;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -472,8 +584,8 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
containsNull = false;
|
||||
}
|
||||
|
||||
protected void moveToFirstIndex(int startPos) {
|
||||
if(size == 1 || firstIndex == startPos) return;
|
||||
protected void moveToFirstIndex(int startPos, boolean adding) {
|
||||
if(size == (adding ? 0 : 1) || firstIndex == startPos) return;
|
||||
if(lastIndex == startPos) {
|
||||
lastIndex = (int)(links[startPos] >>> 32);
|
||||
links[lastIndex] |= 0xFFFFFFFFL;
|
||||
@@ -490,8 +602,8 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
firstIndex = startPos;
|
||||
}
|
||||
|
||||
protected void moveToLastIndex(int startPos) {
|
||||
if(size == 1 || lastIndex == startPos) return;
|
||||
protected void moveToLastIndex(int startPos, boolean adding) {
|
||||
if(size == (adding ? 0 : 1) || lastIndex == startPos) return;
|
||||
if(firstIndex == startPos) {
|
||||
firstIndex = (int)links[startPos];
|
||||
links[lastIndex] |= 0xFFFFFFFF00000000L;
|
||||
@@ -605,6 +717,10 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
}
|
||||
|
||||
private class MapEntrySet extends AbstractObjectSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> implements ORDERED_MAP.FastOrderedSet KEY_VALUE_GENERIC_TYPE {
|
||||
@Override
|
||||
public void addFirst(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void addLast(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean addAndMoveToFirst(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
@@ -621,24 +737,24 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE first() {
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE getFirst() {
|
||||
return new BasicEntryKV_BRACES(FIRST_ENTRY_KEY(), FIRST_ENTRY_VALUE());
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE last() {
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE getLast() {
|
||||
return new BasicEntryKV_BRACES(LAST_ENTRY_KEY(), LAST_ENTRY_VALUE());
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollFirst() {
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE removeFirst() {
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(FIRST_ENTRY_KEY(), FIRST_ENTRY_VALUE());
|
||||
POLL_FIRST_ENTRY_KEY();
|
||||
return entry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollLast() {
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE removeLast() {
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(LAST_ENTRY_KEY(), LAST_ENTRY_VALUE());
|
||||
POLL_LAST_ENTRY_KEY();
|
||||
return entry;
|
||||
@@ -646,7 +762,12 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> iterator() {
|
||||
return new EntryIterator();
|
||||
return new EntryIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> reverseIterator() {
|
||||
return new EntryIterator(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -656,7 +777,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> fastIterator() {
|
||||
return new FastEntryIterator();
|
||||
return new FastEntryIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -671,70 +792,82 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
public void forEach(Consumer<? super MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
|
||||
int index = firstIndex;
|
||||
while(index != -1){
|
||||
action.accept(new BasicEntryKV_BRACES(keys[index], values[index]));
|
||||
action.accept(new ValueMapEntry(index));
|
||||
index = (int)links[index];
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fastForEach(Consumer<? super MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
|
||||
MapEntry entry = new MapEntry();
|
||||
int index = firstIndex;
|
||||
while(index != -1){
|
||||
entry.set(keys[index], values[index]);
|
||||
entry.set(index);
|
||||
action.accept(entry);
|
||||
index = (int)links[index];
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEachIndexed(IntObjectConsumer<MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
|
||||
Objects.requireNonNull(action);
|
||||
if(size() <= 0) return;
|
||||
int count = 0;
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
action.accept(count++, new ValueMapEntry(index));
|
||||
index = (int)links[index];
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, ObjectObjectConsumer<E, MAP.Entry KEY_VALUE_GENERIC_TYPE> 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(input, new ValueMapEntry(index));
|
||||
index = (int)links[index];
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matchesAny(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
public boolean matchesAny(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return false;
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
|
||||
MapEntry entry = new MapEntry();
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
entry.set(keys[index], values[index]);
|
||||
if(filter.getBoolean(entry)) return true;
|
||||
entry.set(index);
|
||||
if(filter.test(entry)) return true;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matchesNone(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
public boolean matchesNone(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return true;
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
|
||||
MapEntry entry = new MapEntry();
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
entry.set(keys[index], values[index]);
|
||||
if(filter.getBoolean(entry)) return false;
|
||||
entry.set(index);
|
||||
if(filter.test(entry)) return false;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matchesAll(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
public boolean matchesAll(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return true;
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
|
||||
MapEntry entry = new MapEntry();
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
entry.set(keys[index], values[index]);
|
||||
if(!filter.getBoolean(entry)) return false;
|
||||
entry.set(index);
|
||||
if(!filter.test(entry)) return false;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return true;
|
||||
@@ -746,14 +879,14 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
E state = identity;
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
state = operator.apply(state, new BasicEntryKV_BRACES(keys[index], values[index]));
|
||||
state = operator.apply(state, new ValueMapEntry(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) {
|
||||
public Optional<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;
|
||||
@@ -761,40 +894,40 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
while(index != -1) {
|
||||
if(empty) {
|
||||
empty = false;
|
||||
state = new BasicEntryKV_BRACES(keys[index], values[index]);
|
||||
state = new ValueMapEntry(index);
|
||||
index = (int)links[index];
|
||||
continue;
|
||||
}
|
||||
state = operator.apply(state, new BasicEntryKV_BRACES(keys[index], values[index]));
|
||||
state = operator.apply(state, new ValueMapEntry(index));
|
||||
index = (int)links[index];
|
||||
}
|
||||
return state;
|
||||
return empty ? Optional.empty() : Optional.ofNullable(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
public Optional<MAP.Entry KEY_VALUE_GENERIC_TYPE> findFirst(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return null;
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
|
||||
if(size() <= 0) return Optional.empty();
|
||||
MapEntry entry = new MapEntry();
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
entry.set(keys[index], values[index]);
|
||||
if(filter.getBoolean(entry)) return entry;
|
||||
entry.set(index);
|
||||
if(filter.test(entry)) return Optional.ofNullable(entry);
|
||||
index = (int)links[index];
|
||||
}
|
||||
return null;
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
public int count(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return 0;
|
||||
int result = 0;
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
|
||||
MapEntry entry = new MapEntry();
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
entry.set(keys[index], values[index]);
|
||||
if(filter.getBoolean(entry)) result++;
|
||||
entry.set(index);
|
||||
if(filter.test(entry)) result++;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return result;
|
||||
@@ -875,6 +1008,12 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
@Override
|
||||
public boolean add(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public void addFirst(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public void addLast(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public boolean addAndMoveToFirst(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@@ -893,7 +1032,12 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE iterator() {
|
||||
return new KeyIterator();
|
||||
return new KeyIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE reverseIterator() {
|
||||
return new KeyIterator(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -915,22 +1059,22 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE FIRST_KEY() {
|
||||
public KEY_TYPE GET_FIRST_KEY() {
|
||||
return FIRST_ENTRY_KEY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE POLL_FIRST_KEY() {
|
||||
public KEY_TYPE REMOVE_FIRST_KEY() {
|
||||
return POLL_FIRST_ENTRY_KEY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE LAST_KEY() {
|
||||
public KEY_TYPE GET_LAST_KEY() {
|
||||
return LAST_ENTRY_KEY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE POLL_LAST_KEY() {
|
||||
public KEY_TYPE REMOVE_LAST_KEY() {
|
||||
return POLL_LAST_ENTRY_KEY();
|
||||
}
|
||||
|
||||
@@ -943,6 +1087,18 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
|
||||
Objects.requireNonNull(action);
|
||||
if(size() <= 0) return;
|
||||
int count = 0;
|
||||
int index = firstIndex;
|
||||
while(index != -1){
|
||||
action.accept(count++, keys[index]);
|
||||
index = (int)links[index];
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
@@ -960,7 +1116,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
if(size() <= 0) return false;
|
||||
int index = firstIndex;
|
||||
while(index != -1){
|
||||
if(filter.TEST_VALUE(keys[index])) return true;
|
||||
if(filter.test(keys[index])) return true;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return false;
|
||||
@@ -972,7 +1128,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
if(size() <= 0) return true;
|
||||
int index = firstIndex;
|
||||
while(index != -1){
|
||||
if(filter.TEST_VALUE(keys[index])) return false;
|
||||
if(filter.test(keys[index])) return false;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return true;
|
||||
@@ -984,7 +1140,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
if(size() <= 0) return true;
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
if(!filter.TEST_VALUE(keys[index])) return false;
|
||||
if(!filter.test(keys[index])) return false;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return true;
|
||||
@@ -1018,7 +1174,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public KEY_TYPE reduce(SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
public OPTIONAL KEY_GENERIC_TYPE reduce(SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = EMPTY_KEY_VALUE;
|
||||
boolean empty = true;
|
||||
@@ -1033,19 +1189,19 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
state = operator.APPLY_KEY_VALUE(state, keys[index]);
|
||||
index = (int)links[index];
|
||||
}
|
||||
return state;
|
||||
return empty ? OPTIONAL.empty() : OPTIONAL.GET_OPTIONAL(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
public OPTIONAL KEY_GENERIC_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return EMPTY_KEY_VALUE;
|
||||
if(size() <= 0) return OPTIONAL.empty();
|
||||
int index = firstIndex;
|
||||
while(index != -1){
|
||||
if(filter.TEST_VALUE(keys[index])) return keys[index];
|
||||
if(filter.test(keys[index])) return OPTIONAL.GET_OPTIONAL(keys[index]);
|
||||
index = (int)links[index];
|
||||
}
|
||||
return EMPTY_KEY_VALUE;
|
||||
return OPTIONAL.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1055,48 +1211,57 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
int result = 0;
|
||||
int index = firstIndex;
|
||||
while(index != -1){
|
||||
if(filter.TEST_VALUE(keys[index])) result++;
|
||||
if(filter.test(keys[index])) result++;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
private class Values extends VALUE_ABSTRACT_COLLECTION VALUE_GENERIC_TYPE {
|
||||
private class Values extends VALUE_ABSTRACT_COLLECTION VALUE_GENERIC_TYPE implements VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE {
|
||||
#if VALUE_OBJECT
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean contains(Object e) {
|
||||
return containsValue(e);
|
||||
}
|
||||
public boolean contains(Object e) { return containsValue(e); }
|
||||
|
||||
#else
|
||||
@Override
|
||||
public boolean contains(VALUE_TYPE e) {
|
||||
return containsValue(e);
|
||||
}
|
||||
public boolean contains(VALUE_TYPE e) { return containsValue(e); }
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public boolean add(VALUE_TYPE o) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public boolean add(VALUE_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_ITERATOR VALUE_GENERIC_TYPE iterator() {
|
||||
return new ValueIterator();
|
||||
}
|
||||
|
||||
public VALUE_ITERATOR VALUE_GENERIC_TYPE iterator() { return new ValueIterator(true); }
|
||||
@Override
|
||||
public int size() {
|
||||
return LINKED_HASH_MAP.this.size();
|
||||
}
|
||||
|
||||
public int size() { return LINKED_HASH_MAP.this.size(); }
|
||||
@Override
|
||||
public void clear() {
|
||||
LINKED_HASH_MAP.this.clear();
|
||||
public void clear() { LINKED_HASH_MAP.this.clear(); }
|
||||
@Override
|
||||
public VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE reversed() { return new VALUE_ABSTRACT_COLLECTION.VALUE_REVERSED_ORDERED_COLLECTIONVALUE_BRACES(this, this::reverseIterator); }
|
||||
private VALUE_ITERATOR VALUE_GENERIC_TYPE reverseIterator() {
|
||||
return new ValueIterator(false);
|
||||
}
|
||||
@Override
|
||||
public void addFirst(VALUE_TYPE e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void addLast(VALUE_TYPE e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE VALUE_GET_FIRST_KEY() { return FIRST_ENTRY_VALUE(); }
|
||||
@Override
|
||||
public VALUE_TYPE VALUE_REMOVE_FIRST_KEY() {
|
||||
VALUE_TYPE result = FIRST_ENTRY_VALUE();
|
||||
POLL_FIRST_ENTRY_KEY();
|
||||
return result;
|
||||
}
|
||||
@Override
|
||||
public VALUE_TYPE VALUE_GET_LAST_KEY() { return LAST_ENTRY_VALUE(); }
|
||||
@Override
|
||||
public VALUE_TYPE VALUE_REMOVE_LAST_KEY() {
|
||||
VALUE_TYPE result = LAST_ENTRY_VALUE();
|
||||
POLL_LAST_ENTRY_KEY();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEach(VALUE_CONSUMER VALUE_SUPER_GENERIC_TYPE action) {
|
||||
Objects.requireNonNull(action);
|
||||
@@ -1107,6 +1272,18 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEachIndexed(VALUE_BI_FROM_INT_CONSUMER VALUE_GENERIC_TYPE action) {
|
||||
Objects.requireNonNull(action);
|
||||
if(size() <= 0) return;
|
||||
int count = 0;
|
||||
int index = firstIndex;
|
||||
while(index != -1){
|
||||
action.accept(count++, values[index]);
|
||||
index = (int)links[index];
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, VALUE_BI_FROM_OBJECT_CONSUMER VSV_GENERIC_TYPE<E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
@@ -1124,7 +1301,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
if(size() <= 0) return false;
|
||||
int index = firstIndex;
|
||||
while(index != -1){
|
||||
if(filter.VALUE_TEST_VALUE(values[index])) return true;
|
||||
if(filter.test(values[index])) return true;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return false;
|
||||
@@ -1136,7 +1313,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
if(size() <= 0) return true;
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
if(filter.VALUE_TEST_VALUE(values[index])) return false;
|
||||
if(filter.test(values[index])) return false;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return true;
|
||||
@@ -1148,7 +1325,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
if(size() <= 0) return true;
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
if(!filter.VALUE_TEST_VALUE(values[index])) return false;
|
||||
if(!filter.test(values[index])) return false;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return true;
|
||||
@@ -1182,7 +1359,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public VALUE_TYPE reduce(VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
|
||||
public VALUE_OPTIONAL VALUE_GENERIC_TYPE reduce(VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
VALUE_TYPE state = EMPTY_VALUE;
|
||||
boolean empty = true;
|
||||
@@ -1197,19 +1374,19 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
state = operator.APPLY_VALUE(state, values[index]);
|
||||
index = (int)links[index];
|
||||
}
|
||||
return state;
|
||||
return empty ? VALUE_OPTIONAL.empty() : VALUE_OPTIONAL.GET_OPTIONAL_VALUE(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
||||
public VALUE_OPTIONAL VALUE_GENERIC_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return EMPTY_VALUE;
|
||||
if(size() <= 0) return VALUE_OPTIONAL.empty();
|
||||
int index = firstIndex;
|
||||
while(index != -1){
|
||||
if(filter.VALUE_TEST_VALUE(values[index])) return values[index];
|
||||
if(filter.test(values[index])) return VALUE_OPTIONAL.GET_OPTIONAL_VALUE(values[index]);
|
||||
index = (int)links[index];
|
||||
}
|
||||
return EMPTY_VALUE;
|
||||
return VALUE_OPTIONAL.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1219,7 +1396,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
int result = 0;
|
||||
int index = firstIndex;
|
||||
while(index != -1){
|
||||
if(filter.VALUE_TEST_VALUE(values[index])) result++;
|
||||
if(filter.test(values[index])) result++;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return result;
|
||||
@@ -1229,7 +1406,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
private class FastEntryIterator extends MapIterator implements ObjectListIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> {
|
||||
MapEntry entry = new MapEntry();
|
||||
|
||||
public FastEntryIterator() {}
|
||||
public FastEntryIterator(boolean start) { super(start); }
|
||||
public FastEntryIterator(KEY_TYPE from) {
|
||||
super(from);
|
||||
}
|
||||
@@ -1256,19 +1433,19 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
private class EntryIterator extends MapIterator implements ObjectListIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> {
|
||||
MapEntry entry;
|
||||
|
||||
public EntryIterator() {}
|
||||
public EntryIterator(boolean start) { super(start); }
|
||||
public EntryIterator(KEY_TYPE from) {
|
||||
super(from);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE next() {
|
||||
return entry = new MapEntry(nextEntry());
|
||||
return entry = new ValueMapEntry(nextEntry());
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE previous() {
|
||||
return entry = new MapEntry(previousEntry());
|
||||
return entry = new ValueMapEntry(previousEntry());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1286,7 +1463,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
|
||||
private class KeyIterator extends MapIterator implements LIST_ITERATOR KEY_GENERIC_TYPE {
|
||||
|
||||
public KeyIterator() {}
|
||||
public KeyIterator(boolean start) { super(start); }
|
||||
public KeyIterator(KEY_TYPE from) {
|
||||
super(from);
|
||||
}
|
||||
@@ -1308,7 +1485,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
}
|
||||
|
||||
private class ValueIterator extends MapIterator implements VALUE_LIST_ITERATOR VALUE_GENERIC_TYPE {
|
||||
public ValueIterator() {}
|
||||
public ValueIterator(boolean start) { super(start); }
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE VALUE_PREVIOUS() {
|
||||
@@ -1328,13 +1505,16 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
}
|
||||
|
||||
private class MapIterator {
|
||||
boolean forward;
|
||||
int previous = -1;
|
||||
int next = -1;
|
||||
int current = -1;
|
||||
int index = 0;
|
||||
|
||||
MapIterator() {
|
||||
next = firstIndex;
|
||||
MapIterator(boolean start) {
|
||||
this.forward = start;
|
||||
if(start) next = firstIndex;
|
||||
else previous = lastIndex;
|
||||
}
|
||||
|
||||
MapIterator(KEY_TYPE from) {
|
||||
@@ -1365,11 +1545,11 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return next != -1;
|
||||
return (forward ? next : previous) != -1;
|
||||
}
|
||||
|
||||
public boolean hasPrevious() {
|
||||
return previous != -1;
|
||||
return (forward ? previous : next) != -1;
|
||||
}
|
||||
|
||||
public int nextIndex() {
|
||||
@@ -1429,20 +1609,30 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
|
||||
public int previousEntry() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
current = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
next = current;
|
||||
if(forward) moveBackwards();
|
||||
else moveForwards();
|
||||
if(index >= 0) index--;
|
||||
return current;
|
||||
}
|
||||
|
||||
public int nextEntry() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
if(forward) moveForwards();
|
||||
else moveBackwards();
|
||||
if(index >= 0) index++;
|
||||
return current;
|
||||
}
|
||||
|
||||
private void moveBackwards() {
|
||||
current = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
next = current;
|
||||
}
|
||||
|
||||
private void moveForwards() {
|
||||
current = next;
|
||||
next = (int)(links[current]);
|
||||
previous = current;
|
||||
if(index >= 0) index++;
|
||||
return current;
|
||||
}
|
||||
|
||||
private void ensureIndexKnown() {
|
||||
|
||||
+292
-109
@@ -5,28 +5,49 @@ import java.util.ConcurrentModificationException;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Predicate;
|
||||
#if !TYPE_OBJECT && JDK_TYPE
|
||||
import java.util.function.PREDICATE;
|
||||
import java.util.OPTIONAL;
|
||||
#endif
|
||||
#if !SAME_TYPE && JDK_VALUE && !VALUE_OBJECT
|
||||
import java.util.function.VALUE_PREDICATE;
|
||||
import java.util.VALUE_OPTIONAL;
|
||||
#endif
|
||||
|
||||
#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.ints.functions.consumer.BI_FROM_INT_CONSUMER;
|
||||
#if !TYPE_OBJECT && !VALUE_OBJECT
|
||||
import speiger.src.collections.ints.functions.consumer.IntObjectConsumer;
|
||||
#endif
|
||||
#if !SAME_TYPE && !TYPE_INT
|
||||
import speiger.src.collections.ints.functions.consumer.VALUE_BI_FROM_INT_CONSUMER;
|
||||
#endif
|
||||
#if !TYPE_INT || !SAME_TYPE
|
||||
import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
|
||||
#endif
|
||||
#if !VALUE_BOOLEAN || !JDK_TYPE
|
||||
import speiger.src.collections.PACKAGE.functions.function.FUNCTION;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||
#if !SAME_TYPE
|
||||
import speiger.src.collections.PACKAGE.functions.function.SINGLE_UNARY_OPERATOR;
|
||||
#endif
|
||||
#if !TYPE_OBJECT && !VALUE_BOOLEAN
|
||||
#if !TYPE_OBJECT && !JDK_TYPE
|
||||
import speiger.src.collections.PACKAGE.functions.OPTIONAL;
|
||||
#if !VALUE_BOOLEAN
|
||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.lists.ARRAY_LIST;
|
||||
import speiger.src.collections.PACKAGE.lists.LIST;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.maps.abstracts.ABSTRACT_MAP;
|
||||
import speiger.src.collections.PACKAGE.maps.interfaces.MAP;
|
||||
import speiger.src.collections.PACKAGE.utils.maps.MAPS;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.sets.ABSTRACT_SET;
|
||||
import speiger.src.collections.PACKAGE.sets.SET;
|
||||
@@ -51,17 +72,15 @@ import speiger.src.collections.objects.functions.function.ObjectObjectUnaryOpera
|
||||
#if !TYPE_OBJECT && !VALUE_OBJECT || !VALUE_OBJECT
|
||||
import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer;
|
||||
#endif
|
||||
#if !TYPE_OBJECT || !VALUE_BOOLEAN
|
||||
#if !VALUE_OBJECT || SAME_TYPE
|
||||
import speiger.src.collections.objects.functions.function.Object2BooleanFunction;
|
||||
#endif
|
||||
#endif
|
||||
#if !SAME_TYPE
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.objects.functions.consumer.VALUE_BI_FROM_OBJECT_CONSUMER;
|
||||
#endif
|
||||
|
||||
#if !JDK_VALUE
|
||||
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE;
|
||||
import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_OPTIONAL;
|
||||
#endif
|
||||
#endif
|
||||
import speiger.src.collections.objects.collections.ObjectIterator;
|
||||
import speiger.src.collections.objects.sets.AbstractObjectSet;
|
||||
@@ -245,6 +264,11 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
insert(-slot-1, key, value);
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
else if(VALUE_EQUALS(values[slot], getDefaultReturnValue())) {
|
||||
VALUE_TYPE oldValue = values[slot];
|
||||
values[slot] = value;
|
||||
return oldValue;
|
||||
}
|
||||
return values[slot];
|
||||
}
|
||||
|
||||
@@ -480,6 +504,95 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
int index = findIndex(key);
|
||||
if(index < 0) {
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, getDefaultReturnValue());
|
||||
#if VALUE_OBJECT
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
#endif
|
||||
insert(-index-1, key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
|
||||
#if VALUE_OBJECT
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
removeIndex(index);
|
||||
return newValue;
|
||||
}
|
||||
#endif
|
||||
values[index] = newValue;
|
||||
return newValue;
|
||||
}
|
||||
|
||||
@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.APPLY(key);
|
||||
#if VALUE_OBJECT
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
#endif
|
||||
insert(-index-1, key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
VALUE_TYPE newValue = values[index];
|
||||
#if VALUE_OBJECT
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
newValue = mappingFunction.APPLY(key);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
values[index] = newValue;
|
||||
}
|
||||
#endif
|
||||
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_SUPPLY_GET();
|
||||
#if VALUE_OBJECT
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
#endif
|
||||
insert(-index-1, key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
VALUE_TYPE newValue = values[index];
|
||||
#if VALUE_OBJECT
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
newValue = valueProvider.VALUE_SUPPLY_GET();
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
values[index] = newValue;
|
||||
}
|
||||
#endif
|
||||
return newValue;
|
||||
}
|
||||
|
||||
@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 !VALUE_OBJECT
|
||||
if(index < 0) return getDefaultReturnValue();
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
|
||||
#else
|
||||
if(index < 0 || VALUE_EQUALS(values[index], getDefaultReturnValue())) return getDefaultReturnValue();
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
removeIndex(index);
|
||||
return newValue;
|
||||
}
|
||||
#endif
|
||||
values[index] = newValue;
|
||||
return newValue;
|
||||
}
|
||||
|
||||
#if !VALUE_OBJECT
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTENonDefault(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());
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
insert(-index-1, key, newValue);
|
||||
return newValue;
|
||||
@@ -494,18 +607,18 @@ 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) {
|
||||
public VALUE_TYPE COMPUTE_IF_ABSENTNonDefault(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);
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY(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 = mappingFunction.GET_VALUE(key);
|
||||
newValue = mappingFunction.APPLY(key);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
values[index] = newValue;
|
||||
}
|
||||
@@ -513,18 +626,18 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENT(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENTNonDefault(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();
|
||||
VALUE_TYPE newValue = valueProvider.VALUE_SUPPLY_GET();
|
||||
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();
|
||||
newValue = valueProvider.VALUE_SUPPLY_GET();
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
values[index] = newValue;
|
||||
}
|
||||
@@ -532,7 +645,7 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENTNonDefault(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();
|
||||
@@ -545,6 +658,7 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
return newValue;
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public VALUE_TYPE MERGE(KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
@@ -565,7 +679,7 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
@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)) {
|
||||
for(MAP.Entry KEY_VALUE_GENERIC_TYPE entry : getFastIterable(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());
|
||||
@@ -732,6 +846,33 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
}
|
||||
}
|
||||
|
||||
protected class ValueMapEntry extends MapEntry {
|
||||
protected KEY_TYPE key;
|
||||
protected VALUE_TYPE value;
|
||||
|
||||
public ValueMapEntry(int index) {
|
||||
super(index);
|
||||
key = keys[index];
|
||||
value = values[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE ENTRY_KEY() {
|
||||
return key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE ENTRY_VALUE() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE setValue(VALUE_TYPE value) {
|
||||
this.value = value;
|
||||
return super.setValue(value);
|
||||
}
|
||||
}
|
||||
|
||||
protected class MapEntry implements MAP.Entry KEY_VALUE_GENERIC_TYPE, Map.Entry<CLASS_TYPE, CLASS_VALUE_TYPE> {
|
||||
public int index = -1;
|
||||
|
||||
@@ -740,6 +881,10 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
void set(int index) {
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE ENTRY_KEY() {
|
||||
return keys[index];
|
||||
@@ -762,19 +907,19 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
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());
|
||||
return KEY_EQUALS(ENTRY_KEY(), entry.ENTRY_KEY()) && VALUE_EQUALS(ENTRY_VALUE(), 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);
|
||||
return KEY_EQUALS(ENTRY_KEY(), key) && VALUE_EQUALS(ENTRY_VALUE(), value);
|
||||
#else if TYPE_OBJECT
|
||||
return value instanceof CLASS_VALUE_TYPE && KEY_EQUALS(keys[index], key) && VALUE_EQUALS(values[index], CLASS_TO_VALUE(value));
|
||||
return value instanceof CLASS_VALUE_TYPE && KEY_EQUALS(ENTRY_KEY(), key) && VALUE_EQUALS(ENTRY_VALUE(), 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);
|
||||
return key instanceof CLASS_TYPE && KEY_EQUALS(ENTRY_KEY(), CLASS_TO_KEY(key)) && VALUE_EQUALS(ENTRY_VALUE(), 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));
|
||||
return key instanceof CLASS_TYPE && value instanceof CLASS_VALUE_TYPE && KEY_EQUALS(ENTRY_KEY(), CLASS_TO_KEY(key)) && VALUE_EQUALS(ENTRY_VALUE(), CLASS_TO_VALUE(value));
|
||||
#endif
|
||||
}
|
||||
return false;
|
||||
@@ -782,12 +927,12 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return KEY_TO_HASH(keys[index]) ^ VALUE_TO_HASH(values[index]);
|
||||
return KEY_TO_HASH(ENTRY_KEY()) ^ VALUE_TO_HASH(ENTRY_VALUE());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return KEY_TO_STRING(keys[index]) + "=" + VALUE_TO_STRING(values[index]);
|
||||
return KEY_TO_STRING(ENTRY_KEY()) + "=" + VALUE_TO_STRING(ENTRY_VALUE());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -804,85 +949,95 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
|
||||
@Override
|
||||
public void forEach(Consumer<? super MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
|
||||
if(containsNull) action.accept(new BasicEntryKV_BRACES(keys[nullIndex], values[nullIndex]));
|
||||
if(containsNull) action.accept(new ValueMapEntry(nullIndex));
|
||||
for(int i = nullIndex-1;i>=0;i--)
|
||||
if(KEY_EQUALS_NOT_NULL(keys[i])) action.accept(new BasicEntryKV_BRACES(keys[i], values[i]));
|
||||
if(KEY_EQUALS_NOT_NULL(keys[i])) action.accept(new ValueMapEntry(i));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fastForEach(Consumer<? super MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
|
||||
MapEntry entry = new MapEntry();
|
||||
if(containsNull) {
|
||||
entry.set(keys[nullIndex], values[nullIndex]);
|
||||
entry.set(nullIndex);
|
||||
action.accept(entry);
|
||||
}
|
||||
for(int i = nullIndex-1;i>=0;i--) {
|
||||
if(KEY_EQUALS_NOT_NULL(keys[i])) {
|
||||
entry.set(keys[i], values[i]);
|
||||
entry.set(i);
|
||||
action.accept(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEachIndexed(IntObjectConsumer<MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
|
||||
Objects.requireNonNull(action);
|
||||
if(size() <= 0) return;
|
||||
if(containsNull) action.accept(0, new ValueMapEntry(nullIndex));
|
||||
for(int i = nullIndex-1, index = containsNull ? 1 : 0;i>=0;i--) {
|
||||
if(KEY_EQUALS_NOT_NULL(keys[i])) action.accept(index++, new ValueMapEntry(i));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, ObjectObjectConsumer<E, MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
|
||||
Objects.requireNonNull(action);
|
||||
if(size() <= 0) return;
|
||||
if(containsNull) action.accept(input, new BasicEntryKV_BRACES(keys[nullIndex], values[nullIndex]));
|
||||
if(containsNull) action.accept(input, new ValueMapEntry(nullIndex));
|
||||
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(input, new ValueMapEntry(i));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matchesAny(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
public boolean matchesAny(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return false;
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
|
||||
MapEntry entry = new MapEntry();
|
||||
if(containsNull) {
|
||||
entry.set(keys[nullIndex], values[nullIndex]);
|
||||
if(filter.getBoolean(entry)) return true;
|
||||
entry.set(nullIndex);
|
||||
if(filter.test(entry)) return true;
|
||||
}
|
||||
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)) return true;
|
||||
entry.set(i);
|
||||
if(filter.test(entry)) return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matchesNone(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
public boolean matchesNone(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return true;
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
|
||||
MapEntry entry = new MapEntry();
|
||||
if(containsNull) {
|
||||
entry.set(keys[nullIndex], values[nullIndex]);
|
||||
if(filter.getBoolean(entry)) return false;
|
||||
entry.set(nullIndex);
|
||||
if(filter.test(entry)) return false;
|
||||
}
|
||||
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)) return false;
|
||||
entry.set(i);
|
||||
if(filter.test(entry)) return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matchesAll(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
public boolean matchesAll(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return true;
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
|
||||
MapEntry entry = new MapEntry();
|
||||
if(containsNull) {
|
||||
entry.set(keys[nullIndex], values[nullIndex]);
|
||||
if(!filter.getBoolean(entry)) return false;
|
||||
entry.set(nullIndex);
|
||||
if(!filter.test(entry)) return false;
|
||||
}
|
||||
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)) return false;
|
||||
entry.set(i);
|
||||
if(!filter.test(entry)) return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
@@ -892,67 +1047,67 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
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]));
|
||||
if(containsNull) state = operator.apply(state, new ValueMapEntry(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]));
|
||||
state = operator.apply(state, new ValueMapEntry(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) {
|
||||
public Optional<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]);
|
||||
state = new ValueMapEntry(nullIndex);
|
||||
empty = false;
|
||||
}
|
||||
for(int i = nullIndex-1;i>=0;i--) {
|
||||
if(KEY_EQUALS_NULL(keys[i])) continue;
|
||||
if(empty) {
|
||||
empty = false;
|
||||
state = new BasicEntryKV_BRACES(keys[i], values[i]);
|
||||
state = new ValueMapEntry(i);
|
||||
continue;
|
||||
}
|
||||
state = operator.apply(state, new BasicEntryKV_BRACES(keys[i], values[i]));
|
||||
state = operator.apply(state, new ValueMapEntry(i));
|
||||
}
|
||||
return state;
|
||||
return empty ? Optional.empty() : Optional.ofNullable(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
public Optional<MAP.Entry KEY_VALUE_GENERIC_TYPE> findFirst(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return null;
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
|
||||
if(size() <= 0) return Optional.empty();
|
||||
MapEntry entry = new MapEntry();
|
||||
if(containsNull) {
|
||||
entry.set(keys[nullIndex], values[nullIndex]);
|
||||
if(filter.getBoolean(entry)) return entry;
|
||||
entry.set(nullIndex);
|
||||
if(filter.test(entry)) return Optional.ofNullable(entry);
|
||||
}
|
||||
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)) return entry;
|
||||
entry.set(i);
|
||||
if(filter.test(entry)) return Optional.ofNullable(entry);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
public int count(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return 0;
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
|
||||
MapEntry entry = new MapEntry();
|
||||
int result = 0;
|
||||
if(containsNull) {
|
||||
entry.set(keys[nullIndex], values[nullIndex]);
|
||||
if(filter.getBoolean(entry)) result++;
|
||||
entry.set(nullIndex);
|
||||
if(filter.test(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++;
|
||||
entry.set(i);
|
||||
if(filter.test(entry)) result++;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
@@ -1057,6 +1212,16 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
if(KEY_EQUALS_NOT_NULL(keys[i])) action.accept(keys[i]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
|
||||
Objects.requireNonNull(action);
|
||||
if(size() <= 0) return;
|
||||
if(containsNull) action.accept(0, keys[nullIndex]);
|
||||
for(int i = nullIndex-1, index = containsNull ? 1 : 0;i>=0;i--) {
|
||||
if(KEY_EQUALS_NOT_NULL(keys[i])) action.accept(index++, keys[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
@@ -1071,9 +1236,9 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
public boolean matchesAny(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return false;
|
||||
if(containsNull && filter.TEST_VALUE(keys[nullIndex])) return true;
|
||||
if(containsNull && filter.test(keys[nullIndex])) return true;
|
||||
for(int i = nullIndex-1;i>=0;i--) {
|
||||
if(KEY_EQUALS_NOT_NULL(keys[i]) && filter.TEST_VALUE(keys[i])) return true;
|
||||
if(KEY_EQUALS_NOT_NULL(keys[i]) && filter.test(keys[i])) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -1082,9 +1247,9 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
public boolean matchesNone(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return true;
|
||||
if(containsNull && filter.TEST_VALUE(keys[nullIndex])) return false;
|
||||
if(containsNull && filter.test(keys[nullIndex])) return false;
|
||||
for(int i = nullIndex-1;i>=0;i--) {
|
||||
if(KEY_EQUALS_NOT_NULL(keys[i]) && filter.TEST_VALUE(keys[i])) return false;
|
||||
if(KEY_EQUALS_NOT_NULL(keys[i]) && filter.test(keys[i])) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -1093,9 +1258,9 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
public boolean matchesAll(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return true;
|
||||
if(containsNull && !filter.TEST_VALUE(keys[nullIndex])) return false;
|
||||
if(containsNull && !filter.test(keys[nullIndex])) return false;
|
||||
for(int i = nullIndex-1;i>=0;i--) {
|
||||
if(KEY_EQUALS_NOT_NULL(keys[i]) && !filter.TEST_VALUE(keys[i])) return false;
|
||||
if(KEY_EQUALS_NOT_NULL(keys[i]) && !filter.test(keys[i])) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -1128,7 +1293,7 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public KEY_TYPE reduce(SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
public OPTIONAL KEY_GENERIC_TYPE reduce(SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = EMPTY_KEY_VALUE;
|
||||
boolean empty = true;
|
||||
@@ -1145,18 +1310,18 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
}
|
||||
state = operator.APPLY_KEY_VALUE(state, keys[i]);
|
||||
}
|
||||
return state;
|
||||
return empty ? OPTIONAL.empty() : OPTIONAL.GET_OPTIONAL(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
public OPTIONAL KEY_GENERIC_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return EMPTY_KEY_VALUE;
|
||||
if(containsNull && filter.TEST_VALUE(keys[nullIndex])) return keys[nullIndex];
|
||||
if(size() <= 0) return OPTIONAL.empty();
|
||||
if(containsNull && filter.test(keys[nullIndex])) return OPTIONAL.GET_OPTIONAL(keys[nullIndex]);
|
||||
for(int i = nullIndex-1;i>=0;i--) {
|
||||
if(KEY_EQUALS_NOT_NULL(keys[i]) && filter.TEST_VALUE(keys[i])) return keys[i];
|
||||
if(KEY_EQUALS_NOT_NULL(keys[i]) && filter.test(keys[i])) return OPTIONAL.GET_OPTIONAL(keys[i]);
|
||||
}
|
||||
return EMPTY_KEY_VALUE;
|
||||
return OPTIONAL.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1164,9 +1329,9 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return 0;
|
||||
int result = 0;
|
||||
if(containsNull && filter.TEST_VALUE(keys[nullIndex])) result++;
|
||||
if(containsNull && filter.test(keys[nullIndex])) result++;
|
||||
for(int i = nullIndex-1;i>=0;i--) {
|
||||
if(KEY_EQUALS_NOT_NULL(keys[i]) && filter.TEST_VALUE(keys[i])) result++;
|
||||
if(KEY_EQUALS_NOT_NULL(keys[i]) && filter.test(keys[i])) result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -1213,6 +1378,16 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
if(KEY_EQUALS_NOT_NULL(keys[i])) action.accept(values[i]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEachIndexed(VALUE_BI_FROM_INT_CONSUMER VALUE_GENERIC_TYPE action) {
|
||||
Objects.requireNonNull(action);
|
||||
if(size() <= 0) return;
|
||||
if(containsNull) action.accept(0, values[nullIndex]);
|
||||
for(int i = nullIndex-1, index = containsNull ? 1 : 0;i>=0;i--) {
|
||||
if(KEY_EQUALS_NOT_NULL(keys[i])) action.accept(index++, values[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, VALUE_BI_FROM_OBJECT_CONSUMER VSV_GENERIC_TYPE<E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
@@ -1227,9 +1402,9 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
public boolean matchesAny(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return false;
|
||||
if(containsNull && filter.VALUE_TEST_VALUE(values[nullIndex])) return true;
|
||||
if(containsNull && filter.test(values[nullIndex])) return true;
|
||||
for(int i = nullIndex-1;i>=0;i--) {
|
||||
if(KEY_EQUALS_NOT_NULL(keys[i]) && filter.VALUE_TEST_VALUE(values[i])) return true;
|
||||
if(KEY_EQUALS_NOT_NULL(keys[i]) && filter.test(values[i])) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -1238,9 +1413,9 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
public boolean matchesNone(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return true;
|
||||
if(containsNull && filter.VALUE_TEST_VALUE(values[nullIndex])) return false;
|
||||
if(containsNull && filter.test(values[nullIndex])) return false;
|
||||
for(int i = nullIndex-1;i>=0;i--) {
|
||||
if(KEY_EQUALS_NOT_NULL(keys[i]) && filter.VALUE_TEST_VALUE(values[i])) return false;
|
||||
if(KEY_EQUALS_NOT_NULL(keys[i]) && filter.test(values[i])) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -1249,9 +1424,9 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
public boolean matchesAll(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return true;
|
||||
if(containsNull && !filter.VALUE_TEST_VALUE(values[nullIndex])) return false;
|
||||
if(containsNull && !filter.test(values[nullIndex])) return false;
|
||||
for(int i = nullIndex-1;i>=0;i--) {
|
||||
if(KEY_EQUALS_NOT_NULL(keys[i]) && !filter.VALUE_TEST_VALUE(values[i])) return false;
|
||||
if(KEY_EQUALS_NOT_NULL(keys[i]) && !filter.test(values[i])) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -1284,7 +1459,7 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public VALUE_TYPE reduce(VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
|
||||
public VALUE_OPTIONAL VALUE_GENERIC_TYPE reduce(VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
VALUE_TYPE state = EMPTY_VALUE;
|
||||
boolean empty = true;
|
||||
@@ -1301,18 +1476,18 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
}
|
||||
state = operator.APPLY_VALUE(state, values[i]);
|
||||
}
|
||||
return state;
|
||||
return empty ? VALUE_OPTIONAL.empty() : VALUE_OPTIONAL.GET_OPTIONAL_VALUE(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
||||
public VALUE_OPTIONAL VALUE_GENERIC_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return EMPTY_VALUE;
|
||||
if(containsNull && filter.VALUE_TEST_VALUE(values[nullIndex])) return values[nullIndex];
|
||||
if(size() <= 0) return VALUE_OPTIONAL.empty();
|
||||
if(containsNull && filter.test(values[nullIndex])) return VALUE_OPTIONAL.GET_OPTIONAL_VALUE(values[nullIndex]);
|
||||
for(int i = nullIndex-1;i>=0;i--) {
|
||||
if(KEY_EQUALS_NOT_NULL(keys[i]) && filter.VALUE_TEST_VALUE(values[i])) return values[i];
|
||||
if(KEY_EQUALS_NOT_NULL(keys[i]) && filter.test(values[i])) return VALUE_OPTIONAL.GET_OPTIONAL_VALUE(values[i]);
|
||||
}
|
||||
return EMPTY_VALUE;
|
||||
return VALUE_OPTIONAL.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1320,9 +1495,9 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return 0;
|
||||
int result = 0;
|
||||
if(containsNull && filter.VALUE_TEST_VALUE(values[nullIndex])) result++;
|
||||
if(containsNull && filter.test(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++;
|
||||
if(KEY_EQUALS_NOT_NULL(keys[i]) && filter.test(values[i])) result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -1341,7 +1516,7 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
MapEntry entry;
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE next() {
|
||||
return entry = new MapEntry(nextEntry());
|
||||
return entry = new ValueMapEntry(nextEntry());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1371,7 +1546,8 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
int lastReturned = -1;
|
||||
int nextIndex = Integer.MIN_VALUE;
|
||||
boolean returnNull = containsNull;
|
||||
LIST KEY_GENERIC_TYPE wrapped = null;
|
||||
KEY_TYPE[] wrapped = null;
|
||||
int wrappedIndex = 0;
|
||||
|
||||
public boolean hasNext() {
|
||||
if(nextIndex == Integer.MIN_VALUE) {
|
||||
@@ -1383,7 +1559,7 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
{
|
||||
while(true) {
|
||||
if(--pos < 0) {
|
||||
if(wrapped == null || wrapped.size() <= -pos - 1) break;
|
||||
if(wrapped == null || wrappedIndex <= -pos - 1) break;
|
||||
nextIndex = -pos - 1;
|
||||
break;
|
||||
}
|
||||
@@ -1402,7 +1578,7 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
returnedPos = pos;
|
||||
if(nextIndex < 0){
|
||||
lastReturned = Integer.MAX_VALUE;
|
||||
int value = findIndex(wrapped.GET_KEY(nextIndex));
|
||||
int value = findIndex(wrapped[nextIndex]);
|
||||
if(value < 0) throw new IllegalStateException("Entry ["+nextIndex+"] was removed during Iteration");
|
||||
nextIndex = Integer.MIN_VALUE;
|
||||
return value;
|
||||
@@ -1421,7 +1597,7 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
}
|
||||
else if(returnedPos >= 0) shiftKeys(returnedPos);
|
||||
else {
|
||||
HASH_MAP.this.remove(wrapped.GET_KEY(-returnedPos - 1));
|
||||
HASH_MAP.this.remove(wrapped[-returnedPos - 1]);
|
||||
lastReturned = -1;
|
||||
return;
|
||||
}
|
||||
@@ -1444,13 +1620,20 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
if(last <= startPos ? (last >= slot || slot > startPos) : (last >= slot && slot > startPos)) break;
|
||||
startPos = ++startPos & mask;
|
||||
}
|
||||
if(startPos < last) {
|
||||
if(wrapped == null) wrapped = new ARRAY_LISTBRACES(2);
|
||||
wrapped.add(keys[startPos]);
|
||||
}
|
||||
if(startPos < last) addWrapper(keys[startPos]);
|
||||
keys[last] = current;
|
||||
values[last] = values[startPos];
|
||||
}
|
||||
}
|
||||
|
||||
private void addWrapper(KEY_TYPE value) {
|
||||
if(wrapped == null) wrapped = NEW_KEY_ARRAY(2);
|
||||
else if(wrappedIndex >= wrapped.length) {
|
||||
KEY_TYPE[] newArray = NEW_KEY_ARRAY(wrapped.length * 2);
|
||||
System.arraycopy(wrapped, 0, newArray, 0, wrapped.length);
|
||||
wrapped = newArray;
|
||||
}
|
||||
wrapped[wrappedIndex++] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
+213
-93
@@ -4,19 +4,43 @@ import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Predicate;
|
||||
#if !TYPE_OBJECT && JDK_TYPE
|
||||
import java.util.function.PREDICATE;
|
||||
import java.util.OPTIONAL;
|
||||
#endif
|
||||
#if !SAME_TYPE && JDK_VALUE && !VALUE_OBJECT
|
||||
import java.util.function.VALUE_PREDICATE;
|
||||
import java.util.VALUE_OPTIONAL;
|
||||
#endif
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||
#endif
|
||||
#if !TYPE_OBJECT && !VALUE_BOOLEAN
|
||||
import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
|
||||
#if !TYPE_OBJECT && !VALUE_OBJECT
|
||||
import speiger.src.collections.ints.functions.consumer.IntObjectConsumer;
|
||||
#endif
|
||||
#if !SAME_TYPE && !TYPE_INT
|
||||
import speiger.src.collections.ints.functions.consumer.VALUE_BI_FROM_INT_CONSUMER;
|
||||
#endif
|
||||
#if !TYPE_OBJECT && !JDK_TYPE
|
||||
import speiger.src.collections.PACKAGE.functions.OPTIONAL;
|
||||
#if !VALUE_BOOLEAN
|
||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||
#endif
|
||||
#endif
|
||||
#if !TYPE_INT || !SAME_TYPE
|
||||
import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
|
||||
#endif
|
||||
#if !VALUE_BOOLEAN || !JDK_TYPE
|
||||
import speiger.src.collections.PACKAGE.functions.function.FUNCTION;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||
#if !SAME_TYPE
|
||||
import speiger.src.collections.PACKAGE.functions.function.SINGLE_UNARY_OPERATOR;
|
||||
@@ -28,30 +52,27 @@ import speiger.src.collections.PACKAGE.maps.interfaces.MAP;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.sets.ORDERED_SET;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.utils.maps.MAPS;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
||||
#endif
|
||||
#if !TYPE_OBJECT && !VALUE_OBJECT || !VALUE_OBJECT
|
||||
import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer;
|
||||
#endif
|
||||
#if !TYPE_OBJECT || !VALUE_BOOLEAN
|
||||
#if !VALUE_OBJECT || SAME_TYPE
|
||||
import speiger.src.collections.objects.functions.function.Object2BooleanFunction;
|
||||
#endif
|
||||
#endif
|
||||
#if !SAME_TYPE
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.objects.functions.consumer.VALUE_BI_FROM_OBJECT_CONSUMER;
|
||||
|
||||
#endif
|
||||
#if !JDK_VALUE
|
||||
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE;
|
||||
import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_OPTIONAL;
|
||||
#endif
|
||||
#endif
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.sets.ABSTRACT_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.collections.VALUE_ORDERED_COLLECTION;
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ITERATOR;
|
||||
import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_SUPPLIER;
|
||||
#if !SAME_TYPE
|
||||
@@ -105,7 +126,7 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
/** KeySet cache */
|
||||
protected transient ORDERED_SET KEY_GENERIC_TYPE keySet;
|
||||
/** Values cache */
|
||||
protected transient VALUE_COLLECTION VALUE_GENERIC_TYPE valuesC;
|
||||
protected transient VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE valuesC;
|
||||
|
||||
/** Amount of Elements stored in the HashMap */
|
||||
protected int size;
|
||||
@@ -215,7 +236,7 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
KEY_TYPE[] keys = NEW_KEY_ARRAY(map.size());
|
||||
VALUE_TYPE[] values = NEW_VALUE_ARRAY(keys.length);
|
||||
int index = 0;
|
||||
for(MAP.Entry KEY_VALUE_GENERIC_TYPE entry : MAPS.fastIterable(map)) {
|
||||
for(MAP.Entry KEY_VALUE_GENERIC_TYPE entry : getFastIterable(map)) {
|
||||
keys[index] = entry.ENTRY_KEY();
|
||||
values[index] = entry.ENTRY_VALUE();
|
||||
index++;
|
||||
@@ -306,6 +327,10 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
@Override
|
||||
public VALUE_TYPE putAndMoveToLast(KEY_TYPE key, VALUE_TYPE value) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE putFirst(KEY_TYPE key, VALUE_TYPE value) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE putLast(KEY_TYPE key, VALUE_TYPE value) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean moveToFirst(KEY_TYPE key) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean moveToLast(KEY_TYPE key) { throw new UnsupportedOperationException(); }
|
||||
@@ -429,6 +454,23 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
return values[lastIndex];
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE firstEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return new BasicEntryKV_BRACES(keys[firstIndex], values[firstIndex]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE lastEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return new BasicEntryKV_BRACES(keys[lastIndex], values[lastIndex]);
|
||||
}
|
||||
|
||||
@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 ObjectOrderedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> ENTRY_SET() {
|
||||
if(entrySet == null) entrySet = new MapEntrySet();
|
||||
@@ -442,7 +484,7 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_COLLECTION VALUE_GENERIC_TYPE values() {
|
||||
public VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE values() {
|
||||
if(valuesC == null) valuesC = new Values();
|
||||
return valuesC;
|
||||
}
|
||||
@@ -479,16 +521,22 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@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(); }
|
||||
|
||||
#if !VALUE_OBJECT
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTENonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_ABSENTNonDefault(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENTNonDefault(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENTNonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||
#endif
|
||||
@Override
|
||||
public VALUE_TYPE MERGE(KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@@ -589,6 +637,10 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
}
|
||||
|
||||
private class MapEntrySet extends AbstractObjectSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> implements ORDERED_MAP.FastOrderedSet KEY_VALUE_GENERIC_TYPE {
|
||||
@Override
|
||||
public void addFirst(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void addLast(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean addAndMoveToFirst(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
@@ -601,24 +653,29 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
public boolean moveToLast(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE first() {
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE getFirst() {
|
||||
return new BasicEntryKV_BRACES(FIRST_ENTRY_KEY(), FIRST_ENTRY_VALUE());
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE last() {
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE getLast() {
|
||||
return new BasicEntryKV_BRACES(LAST_ENTRY_KEY(), LAST_ENTRY_VALUE());
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollFirst() { throw new UnsupportedOperationException(); }
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE removeFirst() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollLast() { throw new UnsupportedOperationException(); }
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE removeLast() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> iterator() {
|
||||
return new EntryIterator();
|
||||
return new EntryIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> reverseIterator() {
|
||||
return new EntryIterator(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -628,7 +685,7 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> fastIterator() {
|
||||
return new FastEntryIterator();
|
||||
return new FastEntryIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -659,6 +716,18 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEachIndexed(IntObjectConsumer<MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
|
||||
Objects.requireNonNull(action);
|
||||
if(size() <= 0) return;
|
||||
int count = 0;
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
action.accept(count++, new BasicEntryKV_BRACES(keys[index], values[index]));
|
||||
index = (int)links[index];
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, ObjectObjectConsumer<E, MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
|
||||
Objects.requireNonNull(action);
|
||||
@@ -671,42 +740,42 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matchesAny(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
public boolean matchesAny(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return false;
|
||||
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)) return true;
|
||||
if(filter.test(entry)) return true;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matchesNone(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
public boolean matchesNone(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return true;
|
||||
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)) return false;
|
||||
if(filter.test(entry)) return false;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matchesAll(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
public boolean matchesAll(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return true;
|
||||
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)) return false;
|
||||
if(!filter.test(entry)) return false;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return true;
|
||||
@@ -725,7 +794,7 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE reduce(ObjectObjectUnaryOperator<MAP.Entry KEY_VALUE_GENERIC_TYPE, MAP.Entry KEY_VALUE_GENERIC_TYPE> operator) {
|
||||
public Optional<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;
|
||||
@@ -740,25 +809,25 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
state = operator.apply(state, new BasicEntryKV_BRACES(keys[index], values[index]));
|
||||
index = (int)links[index];
|
||||
}
|
||||
return state;
|
||||
return empty ? Optional.empty() : Optional.ofNullable(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
public Optional<MAP.Entry KEY_VALUE_GENERIC_TYPE> findFirst(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return null;
|
||||
if(size() <= 0) return Optional.empty();
|
||||
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)) return entry;
|
||||
if(filter.test(entry)) return Optional.ofNullable(entry);
|
||||
index = (int)links[index];
|
||||
}
|
||||
return null;
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
public int count(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return 0;
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
|
||||
@@ -766,7 +835,7 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
entry.set(keys[index], values[index]);
|
||||
if(filter.getBoolean(entry)) result++;
|
||||
if(filter.test(entry)) result++;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return result;
|
||||
@@ -829,6 +898,12 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addFirst(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public void addLast(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public boolean addAndMoveToFirst(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@@ -843,7 +918,12 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE iterator() {
|
||||
return new KeyIterator();
|
||||
return new KeyIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE reverseIterator() {
|
||||
return new KeyIterator(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -863,20 +943,20 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
public void clear() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public KEY_TYPE FIRST_KEY() {
|
||||
public KEY_TYPE GET_FIRST_KEY() {
|
||||
return FIRST_ENTRY_KEY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE POLL_FIRST_KEY() { throw new UnsupportedOperationException(); }
|
||||
public KEY_TYPE REMOVE_FIRST_KEY() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public KEY_TYPE LAST_KEY() {
|
||||
public KEY_TYPE GET_LAST_KEY() {
|
||||
return LAST_ENTRY_KEY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE POLL_LAST_KEY() { throw new UnsupportedOperationException(); }
|
||||
public KEY_TYPE REMOVE_LAST_KEY() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) {
|
||||
@@ -887,6 +967,18 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
|
||||
Objects.requireNonNull(action);
|
||||
if(size() <= 0) return;
|
||||
int count = 0;
|
||||
int index = firstIndex;
|
||||
while(index != -1){
|
||||
action.accept(count++, keys[index]);
|
||||
index = (int)links[index];
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
@@ -904,7 +996,7 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
if(size() <= 0) return false;
|
||||
int index = firstIndex;
|
||||
while(index != -1){
|
||||
if(filter.TEST_VALUE(keys[index])) return true;
|
||||
if(filter.test(keys[index])) return true;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return false;
|
||||
@@ -916,7 +1008,7 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
if(size() <= 0) return true;
|
||||
int index = firstIndex;
|
||||
while(index != -1){
|
||||
if(filter.TEST_VALUE(keys[index])) return false;
|
||||
if(filter.test(keys[index])) return false;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return true;
|
||||
@@ -928,7 +1020,7 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
if(size() <= 0) return true;
|
||||
int index = firstIndex;
|
||||
while(index != -1){
|
||||
if(!filter.TEST_VALUE(keys[index])) return false;
|
||||
if(!filter.test(keys[index])) return false;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return true;
|
||||
@@ -962,7 +1054,7 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public KEY_TYPE reduce(SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
public OPTIONAL KEY_GENERIC_TYPE reduce(SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = EMPTY_KEY_VALUE;
|
||||
boolean empty = true;
|
||||
@@ -977,19 +1069,19 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
state = operator.APPLY_KEY_VALUE(state, keys[index]);
|
||||
index = (int)links[index];
|
||||
}
|
||||
return state;
|
||||
return empty ? OPTIONAL.empty() : OPTIONAL.GET_OPTIONAL(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
public OPTIONAL KEY_GENERIC_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return EMPTY_KEY_VALUE;
|
||||
if(size() <= 0) return OPTIONAL.empty();
|
||||
int index = firstIndex;
|
||||
while(index != -1){
|
||||
if(filter.TEST_VALUE(keys[index])) return keys[index];
|
||||
if(filter.test(keys[index])) return OPTIONAL.GET_OPTIONAL(keys[index]);
|
||||
index = (int)links[index];
|
||||
}
|
||||
return EMPTY_KEY_VALUE;
|
||||
return OPTIONAL.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -999,46 +1091,49 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
int index = firstIndex;
|
||||
int result = 0;
|
||||
while(index != -1){
|
||||
if(filter.TEST_VALUE(keys[index])) result++;
|
||||
if(filter.test(keys[index])) result++;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
private class Values extends VALUE_ABSTRACT_COLLECTION VALUE_GENERIC_TYPE {
|
||||
private class Values extends VALUE_ABSTRACT_COLLECTION VALUE_GENERIC_TYPE implements VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE {
|
||||
#if VALUE_OBJECT
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean contains(Object e) {
|
||||
return containsValue(e);
|
||||
}
|
||||
public boolean contains(Object e) { return containsValue(e); }
|
||||
|
||||
#else
|
||||
@Override
|
||||
public boolean contains(VALUE_TYPE e) {
|
||||
return containsValue(e);
|
||||
}
|
||||
public boolean contains(VALUE_TYPE e) { return containsValue(e); }
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public boolean add(VALUE_TYPE o) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public boolean add(VALUE_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_ITERATOR VALUE_GENERIC_TYPE iterator() {
|
||||
return new ValueIterator();
|
||||
}
|
||||
|
||||
public VALUE_ITERATOR VALUE_GENERIC_TYPE iterator() { return new ValueIterator(true); }
|
||||
@Override
|
||||
public int size() {
|
||||
return IMMUTABLE_HASH_MAP.this.size();
|
||||
}
|
||||
|
||||
public int size() { return IMMUTABLE_HASH_MAP.this.size(); }
|
||||
@Override
|
||||
public void clear() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE reversed() { return new VALUE_ABSTRACT_COLLECTION.VALUE_REVERSED_ORDERED_COLLECTIONVALUE_BRACES(this, this::reverseIterator); }
|
||||
private VALUE_ITERATOR VALUE_GENERIC_TYPE reverseIterator() {
|
||||
return new ValueIterator(false);
|
||||
}
|
||||
@Override
|
||||
public void addFirst(VALUE_TYPE e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void addLast(VALUE_TYPE e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE VALUE_GET_FIRST_KEY() { return FIRST_ENTRY_VALUE(); }
|
||||
@Override
|
||||
public VALUE_TYPE VALUE_REMOVE_FIRST_KEY() { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE VALUE_GET_LAST_KEY() { return LAST_ENTRY_VALUE(); }
|
||||
@Override
|
||||
public VALUE_TYPE VALUE_REMOVE_LAST_KEY() { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void forEach(VALUE_CONSUMER VALUE_SUPER_GENERIC_TYPE action) {
|
||||
int index = firstIndex;
|
||||
@@ -1048,6 +1143,18 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEachIndexed(VALUE_BI_FROM_INT_CONSUMER VALUE_GENERIC_TYPE action) {
|
||||
Objects.requireNonNull(action);
|
||||
if(size() <= 0) return;
|
||||
int count = 0;
|
||||
int index = firstIndex;
|
||||
while(index != -1){
|
||||
action.accept(count++, values[index]);
|
||||
index = (int)links[index];
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, VALUE_BI_FROM_OBJECT_CONSUMER VSV_GENERIC_TYPE<E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
@@ -1065,7 +1172,7 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
if(size() <= 0) return false;
|
||||
int index = firstIndex;
|
||||
while(index != -1){
|
||||
if(filter.VALUE_TEST_VALUE(values[index])) return true;
|
||||
if(filter.test(values[index])) return true;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return false;
|
||||
@@ -1077,7 +1184,7 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
if(size() <= 0) return true;
|
||||
int index = firstIndex;
|
||||
while(index != -1){
|
||||
if(filter.VALUE_TEST_VALUE(values[index])) return false;
|
||||
if(filter.test(values[index])) return false;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return true;
|
||||
@@ -1089,7 +1196,7 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
if(size() <= 0) return true;
|
||||
int index = firstIndex;
|
||||
while(index != -1){
|
||||
if(!filter.VALUE_TEST_VALUE(values[index])) return false;
|
||||
if(!filter.test(values[index])) return false;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return true;
|
||||
@@ -1123,7 +1230,7 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public VALUE_TYPE reduce(VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
|
||||
public VALUE_OPTIONAL VALUE_GENERIC_TYPE reduce(VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
VALUE_TYPE state = EMPTY_VALUE;
|
||||
boolean empty = true;
|
||||
@@ -1138,19 +1245,19 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
state = operator.APPLY_VALUE(state, values[index]);
|
||||
index = (int)links[index];
|
||||
}
|
||||
return state;
|
||||
return empty ? VALUE_OPTIONAL.empty() : VALUE_OPTIONAL.GET_OPTIONAL_VALUE(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
||||
public VALUE_OPTIONAL VALUE_GENERIC_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return EMPTY_VALUE;
|
||||
if(size() <= 0) return VALUE_OPTIONAL.empty();
|
||||
int index = firstIndex;
|
||||
while(index != -1){
|
||||
if(filter.VALUE_TEST_VALUE(values[index])) return values[index];
|
||||
if(filter.test(values[index])) return VALUE_OPTIONAL.GET_OPTIONAL_VALUE(values[index]);
|
||||
index = (int)links[index];
|
||||
}
|
||||
return EMPTY_VALUE;
|
||||
return VALUE_OPTIONAL.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1160,7 +1267,7 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
int result = 0;
|
||||
int index = firstIndex;
|
||||
while(index != -1){
|
||||
if(filter.VALUE_TEST_VALUE(values[index])) result++;
|
||||
if(filter.test(values[index])) result++;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return result;
|
||||
@@ -1170,7 +1277,7 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
private class FastEntryIterator extends MapIterator implements ObjectListIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> {
|
||||
MapEntry entry = new MapEntry();
|
||||
|
||||
public FastEntryIterator() {}
|
||||
public FastEntryIterator(boolean start) { super(start); }
|
||||
public FastEntryIterator(KEY_TYPE from) {
|
||||
super(from);
|
||||
}
|
||||
@@ -1196,7 +1303,7 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
|
||||
private class EntryIterator extends MapIterator implements ObjectListIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> {
|
||||
|
||||
public EntryIterator() {}
|
||||
public EntryIterator(boolean start) { super(start); }
|
||||
public EntryIterator(KEY_TYPE from) {
|
||||
super(from);
|
||||
}
|
||||
@@ -1223,7 +1330,7 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
|
||||
private class KeyIterator extends MapIterator implements LIST_ITERATOR KEY_GENERIC_TYPE {
|
||||
|
||||
public KeyIterator() {}
|
||||
public KeyIterator(boolean start) { super(start); }
|
||||
public KeyIterator(KEY_TYPE from) {
|
||||
super(from);
|
||||
}
|
||||
@@ -1245,7 +1352,7 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
}
|
||||
|
||||
private class ValueIterator extends MapIterator implements VALUE_LIST_ITERATOR VALUE_GENERIC_TYPE {
|
||||
public ValueIterator() {}
|
||||
public ValueIterator(boolean start) { super(start); }
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE VALUE_PREVIOUS() {
|
||||
@@ -1266,13 +1373,16 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
}
|
||||
|
||||
private class MapIterator {
|
||||
boolean forward;
|
||||
int previous = -1;
|
||||
int next = -1;
|
||||
int current = -1;
|
||||
int index = 0;
|
||||
|
||||
MapIterator() {
|
||||
next = firstIndex;
|
||||
MapIterator(boolean start) {
|
||||
this.forward = start;
|
||||
if(start) next = firstIndex;
|
||||
else previous = lastIndex;
|
||||
}
|
||||
|
||||
MapIterator(KEY_TYPE from) {
|
||||
@@ -1303,11 +1413,11 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return next != -1;
|
||||
return (forward ? next : previous) != -1;
|
||||
}
|
||||
|
||||
public boolean hasPrevious() {
|
||||
return previous != -1;
|
||||
return (forward ? previous : next) != -1;
|
||||
}
|
||||
|
||||
public int nextIndex() {
|
||||
@@ -1324,20 +1434,30 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
|
||||
public int previousEntry() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
current = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
next = current;
|
||||
if(forward) moveBackwards();
|
||||
else moveForwards();
|
||||
if(index >= 0) index--;
|
||||
return current;
|
||||
}
|
||||
|
||||
public int nextEntry() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
if(forward) moveForwards();
|
||||
else moveBackwards();
|
||||
if(index >= 0) index++;
|
||||
return current;
|
||||
}
|
||||
|
||||
private void moveBackwards() {
|
||||
current = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
next = current;
|
||||
}
|
||||
|
||||
private void moveForwards() {
|
||||
current = next;
|
||||
next = (int)(links[current]);
|
||||
previous = current;
|
||||
if(index >= 0) index++;
|
||||
return current;
|
||||
}
|
||||
|
||||
private void ensureIndexKnown() {
|
||||
|
||||
+401
-137
File diff suppressed because it is too large
Load Diff
+153
-19
@@ -5,6 +5,10 @@ import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Consumer;
|
||||
#if VALUE_BOOLEAN
|
||||
import java.util.function.Predicate;
|
||||
#endif
|
||||
|
||||
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ABSTRACT_COLLECTION;
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_COLLECTION;
|
||||
@@ -18,8 +22,9 @@ import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
|
||||
#if !VALUE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||
#endif
|
||||
#if !VALUE_BOOLEAN
|
||||
import speiger.src.collections.PACKAGE.functions.function.FUNCTION;
|
||||
import speiger.src.collections.PACKAGE.utils.maps.MAPS;
|
||||
#endif
|
||||
import speiger.src.collections.objects.maps.abstracts.ABSTRACT_MAP;
|
||||
import speiger.src.collections.objects.maps.interfaces.MAP;
|
||||
import speiger.src.collections.objects.sets.AbstractObjectSet;
|
||||
@@ -161,7 +166,14 @@ public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE
|
||||
@Override
|
||||
public VALUE_TYPE putIfAbsent(T key, VALUE_TYPE value) {
|
||||
int index = key.ordinal();
|
||||
if(isSet(index)) return values[index];
|
||||
if(isSet(index)) {
|
||||
if(VALUE_EQUALS(values[index], getDefaultReturnValue())) {
|
||||
VALUE_TYPE oldValue = values[index];
|
||||
values[index] = value;
|
||||
return oldValue;
|
||||
}
|
||||
return values[index];
|
||||
}
|
||||
set(index);
|
||||
values[index] = value;
|
||||
return getDefaultReturnValue();
|
||||
@@ -351,6 +363,96 @@ public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE
|
||||
int index = key.ordinal();
|
||||
if(!isSet(index)) {
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, getDefaultReturnValue());
|
||||
#if VALUE_OBJECT
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
#endif
|
||||
set(index);
|
||||
values[index] = newValue;
|
||||
return newValue;
|
||||
}
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
|
||||
#if VALUE_OBJECT
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
clear(index);
|
||||
values[index] = EMPTY_VALUE;
|
||||
return newValue;
|
||||
}
|
||||
#endif
|
||||
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.APPLY(key);
|
||||
#if VALUE_OBJECT
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
#endif
|
||||
set(index);
|
||||
values[index] = newValue;
|
||||
return newValue;
|
||||
}
|
||||
VALUE_TYPE newValue = values[index];
|
||||
#if VALUE_OBJECT
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
newValue = mappingFunction.APPLY(key);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
values[index] = newValue;
|
||||
}
|
||||
#endif
|
||||
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_SUPPLY_GET();
|
||||
#if VALUE_OBJECT
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
#endif
|
||||
set(index);
|
||||
values[index] = newValue;
|
||||
return newValue;
|
||||
}
|
||||
VALUE_TYPE newValue = values[index];
|
||||
#if VALUE_OBJECT
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
newValue = valueProvider.VALUE_SUPPLY_GET();
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
values[index] = newValue;
|
||||
}
|
||||
#endif
|
||||
return newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENT(T key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
int index = key.ordinal();
|
||||
#if !VALUE_OBJECT
|
||||
if(!isSet(index)) return getDefaultReturnValue();
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
|
||||
#else
|
||||
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;
|
||||
}
|
||||
#endif
|
||||
values[index] = newValue;
|
||||
return newValue;
|
||||
}
|
||||
|
||||
#if !VALUE_OBJECT
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTENonDefault(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;
|
||||
@@ -367,10 +469,10 @@ public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_ABSENT(T key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
public VALUE_TYPE COMPUTE_IF_ABSENTNonDefault(T key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
int index = key.ordinal();
|
||||
if(!isSet(index)) {
|
||||
VALUE_TYPE newValue = mappingFunction.GET_VALUE(key);
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY(key);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
set(index);
|
||||
values[index] = newValue;
|
||||
@@ -378,7 +480,7 @@ public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE
|
||||
}
|
||||
VALUE_TYPE newValue = values[index];
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
newValue = mappingFunction.GET_VALUE(key);
|
||||
newValue = mappingFunction.APPLY(key);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
values[index] = newValue;
|
||||
}
|
||||
@@ -386,10 +488,10 @@ public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENT(T key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENTNonDefault(T key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
|
||||
int index = key.ordinal();
|
||||
if(!isSet(index)) {
|
||||
VALUE_TYPE newValue = valueProvider.VALUE_GET_KEY();
|
||||
VALUE_TYPE newValue = valueProvider.VALUE_SUPPLY_GET();
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
set(index);
|
||||
values[index] = newValue;
|
||||
@@ -397,7 +499,7 @@ public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE
|
||||
}
|
||||
VALUE_TYPE newValue = values[index];
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
newValue = valueProvider.VALUE_GET_KEY();
|
||||
newValue = valueProvider.VALUE_SUPPLY_GET();
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
values[index] = newValue;
|
||||
}
|
||||
@@ -405,7 +507,7 @@ public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENT(T key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENTNonDefault(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]);
|
||||
@@ -418,6 +520,7 @@ public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE
|
||||
return newValue;
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public VALUE_TYPE MERGE(T key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
int index = key.ordinal();
|
||||
@@ -442,7 +545,7 @@ public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE
|
||||
@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)) {
|
||||
for(MAP.Entry KEY_VALUE_GENERIC_TYPE entry : getFastIterable(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());
|
||||
@@ -535,7 +638,7 @@ public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE
|
||||
public void forEach(Consumer<? super MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
|
||||
if(size() <= 0) return;
|
||||
for(int i = 0,m=keys.length;i<m;i++) {
|
||||
if(isSet(i)) action.accept(new BasicEntryKV_BRACES(keys[i], values[i]));
|
||||
if(isSet(i)) action.accept(new ValueMapEntry(i));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -618,7 +721,7 @@ 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());
|
||||
return new ValueMapEntry(nextEntry());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -665,6 +768,33 @@ public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE
|
||||
}
|
||||
}
|
||||
|
||||
protected class ValueMapEntry extends MapEntry {
|
||||
protected KEY_TYPE key;
|
||||
protected VALUE_TYPE value;
|
||||
|
||||
public ValueMapEntry(int index) {
|
||||
super(index);
|
||||
key = keys[index];
|
||||
value = values[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE ENTRY_KEY() {
|
||||
return key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE ENTRY_VALUE() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE setValue(VALUE_TYPE value) {
|
||||
this.value = value;
|
||||
return super.setValue(value);
|
||||
}
|
||||
}
|
||||
|
||||
protected class MapEntry implements MAP.Entry KEY_VALUE_GENERIC_TYPE, Map.Entry<CLASS_TYPE, CLASS_VALUE_TYPE> {
|
||||
public int index = -1;
|
||||
|
||||
@@ -673,6 +803,10 @@ public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
void set(int index) {
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE ENTRY_KEY() {
|
||||
return keys[index];
|
||||
@@ -695,19 +829,19 @@ public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE
|
||||
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());
|
||||
return KEY_EQUALS(ENTRY_KEY(), entry.ENTRY_KEY()) && VALUE_EQUALS(ENTRY_VALUE(), 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);
|
||||
return KEY_EQUALS(ENTRY_KEY(), key) && VALUE_EQUALS(ENTRY_VALUE(), value);
|
||||
#else if TYPE_OBJECT
|
||||
return value instanceof CLASS_VALUE_TYPE && KEY_EQUALS(keys[index], key) && VALUE_EQUALS(values[index], CLASS_TO_VALUE(value));
|
||||
return value instanceof CLASS_VALUE_TYPE && KEY_EQUALS(ENTRY_KEY(), key) && VALUE_EQUALS(ENTRY_VALUE(), 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);
|
||||
return key instanceof CLASS_TYPE && KEY_EQUALS(ENTRY_KEY(), CLASS_TO_KEY(key)) && VALUE_EQUALS(ENTRY_VALUE(), 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));
|
||||
return key instanceof CLASS_TYPE && value instanceof CLASS_VALUE_TYPE && KEY_EQUALS(ENTRY_KEY(), CLASS_TO_KEY(key)) && VALUE_EQUALS(ENTRY_VALUE(), CLASS_TO_VALUE(value));
|
||||
#endif
|
||||
}
|
||||
return false;
|
||||
@@ -715,12 +849,12 @@ public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return KEY_TO_HASH(keys[index]) ^ VALUE_TO_HASH(values[index]);
|
||||
return KEY_TO_HASH(ENTRY_KEY()) ^ VALUE_TO_HASH(ENTRY_VALUE());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return KEY_TO_STRING(keys[index]) + "=" + VALUE_TO_STRING(values[index]);
|
||||
return KEY_TO_STRING(ENTRY_KEY()) + "=" + VALUE_TO_STRING(ENTRY_VALUE());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+191
-62
@@ -18,7 +18,7 @@ import speiger.src.collections.PACKAGE.maps.interfaces.ORDERED_MAP;
|
||||
import speiger.src.collections.PACKAGE.sets.ABSTRACT_SET;
|
||||
import speiger.src.collections.PACKAGE.sets.ORDERED_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_ORDERED_COLLECTION;
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ITERATOR;
|
||||
#if !VALUE_OBJECT && !SAME_TYPE
|
||||
import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_CONSUMER;
|
||||
@@ -216,6 +216,28 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE putFirst(T key, VALUE_TYPE value) {
|
||||
int index = key.ordinal();
|
||||
if(isSet(index)) return values[index];
|
||||
set(index);
|
||||
values[index] = value;
|
||||
onNodeAdded(index);
|
||||
moveToFirstIndex(index);
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE putLast(T key, VALUE_TYPE value) {
|
||||
int index = key.ordinal();
|
||||
if(isSet(index)) return values[index];
|
||||
set(index);
|
||||
values[index] = value;
|
||||
onNodeAdded(index);
|
||||
moveToLastIndex(index);
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean moveToFirst(T key) {
|
||||
int index = key.ordinal();
|
||||
@@ -312,6 +334,42 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
return values[lastIndex];
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE firstEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return new BasicEntryKV_BRACES(keys[firstIndex], values[firstIndex]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE lastEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return new BasicEntryKV_BRACES(keys[lastIndex], values[lastIndex]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollFirstEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
int pos = firstIndex;
|
||||
firstIndex = (int)links[pos];
|
||||
if(0 <= firstIndex) links[firstIndex] |= 0xFFFFFFFF00000000L;
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE result = new BasicEntryKV_BRACES(keys[pos], values[pos]);
|
||||
size--;
|
||||
values[result.ENTRY_KEY().ordinal()] = EMPTY_VALUE;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollLastEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
int pos = lastIndex;
|
||||
firstIndex = (int)links[pos];
|
||||
if(0 <= firstIndex) links[firstIndex] |= 0xFFFFFFFF00000000L;
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE result = new BasicEntryKV_BRACES(keys[pos], values[pos]);
|
||||
size--;
|
||||
values[result.ENTRY_KEY().ordinal()] = EMPTY_VALUE;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectOrderedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> ENTRY_SET() {
|
||||
if(entrySet == null) entrySet = new MapEntrySet();
|
||||
@@ -325,9 +383,9 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_COLLECTION VALUE_GENERIC_TYPE values() {
|
||||
public VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE values() {
|
||||
if(valuesC == null) valuesC = new Values();
|
||||
return valuesC;
|
||||
return (VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE)valuesC;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -415,6 +473,10 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
}
|
||||
|
||||
private class MapEntrySet extends AbstractObjectSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> implements ORDERED_MAP.FastOrderedSet KEY_VALUE_GENERIC_TYPE {
|
||||
@Override
|
||||
public void addFirst(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void addLast(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean addAndMoveToFirst(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
@@ -431,24 +493,24 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE first() {
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE getFirst() {
|
||||
return new BasicEntryKV_BRACES(FIRST_ENTRY_KEY(), FIRST_ENTRY_VALUE());
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE last() {
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE getLast() {
|
||||
return new BasicEntryKV_BRACES(LAST_ENTRY_KEY(), LAST_ENTRY_VALUE());
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollFirst() {
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE removeFirst() {
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(FIRST_ENTRY_KEY(), FIRST_ENTRY_VALUE());
|
||||
POLL_FIRST_ENTRY_KEY();
|
||||
return entry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollLast() {
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE removeLast() {
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(LAST_ENTRY_KEY(), LAST_ENTRY_VALUE());
|
||||
POLL_LAST_ENTRY_KEY();
|
||||
return entry;
|
||||
@@ -456,7 +518,12 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> iterator() {
|
||||
return new EntryIterator();
|
||||
return new EntryIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> reverseIterator() {
|
||||
return new EntryIterator(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -466,7 +533,7 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> fastIterator() {
|
||||
return new FastEntryIterator();
|
||||
return new FastEntryIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -480,17 +547,17 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
public void forEach(Consumer<? super MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
|
||||
int index = firstIndex;
|
||||
while(index != -1){
|
||||
action.accept(new BasicEntryKV_BRACES(keys[index], values[index]));
|
||||
action.accept(new ValueMapEntry(index));
|
||||
index = (int)links[index];
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fastForEach(Consumer<? super MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
|
||||
MapEntry entry = new MapEntry();
|
||||
int index = firstIndex;
|
||||
while(index != -1){
|
||||
entry.set(keys[index], values[index]);
|
||||
entry.set(index);
|
||||
action.accept(entry);
|
||||
index = (int)links[index];
|
||||
}
|
||||
@@ -574,7 +641,10 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
public boolean add(T o) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addFirst(T o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void addLast(T o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean addAndMoveToFirst(T o) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@@ -593,7 +663,12 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE iterator() {
|
||||
return new KeyIterator();
|
||||
return new KeyIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE reverseIterator() {
|
||||
return new KeyIterator(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -614,22 +689,22 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
}
|
||||
|
||||
@Override
|
||||
public T FIRST_KEY() {
|
||||
public T GET_FIRST_KEY() {
|
||||
return FIRST_ENTRY_KEY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public T POLL_FIRST_KEY() {
|
||||
public T REMOVE_FIRST_KEY() {
|
||||
return POLL_FIRST_ENTRY_KEY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public T LAST_KEY() {
|
||||
public T GET_LAST_KEY() {
|
||||
return LAST_ENTRY_KEY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public T POLL_LAST_KEY() {
|
||||
public T REMOVE_LAST_KEY() {
|
||||
return POLL_LAST_ENTRY_KEY();
|
||||
}
|
||||
|
||||
@@ -656,41 +731,50 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
#endif
|
||||
}
|
||||
|
||||
private class Values extends VALUE_ABSTRACT_COLLECTION VALUE_GENERIC_TYPE {
|
||||
private class Values extends VALUE_ABSTRACT_COLLECTION VALUE_GENERIC_TYPE implements VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE {
|
||||
#if VALUE_OBJECT
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean contains(Object e) {
|
||||
return containsValue(e);
|
||||
}
|
||||
public boolean contains(Object e) { return containsValue(e); }
|
||||
|
||||
#else
|
||||
@Override
|
||||
public boolean contains(VALUE_TYPE e) {
|
||||
return containsValue(e);
|
||||
}
|
||||
public boolean contains(VALUE_TYPE e) { return containsValue(e); }
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public boolean add(VALUE_TYPE o) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public boolean add(VALUE_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_ITERATOR VALUE_GENERIC_TYPE iterator() {
|
||||
return new ValueIterator();
|
||||
}
|
||||
|
||||
public VALUE_ITERATOR VALUE_GENERIC_TYPE iterator() { return new ValueIterator(true); }
|
||||
@Override
|
||||
public int size() {
|
||||
return LINKED_ENUM_MAP.this.size();
|
||||
}
|
||||
|
||||
public int size() { return LINKED_ENUM_MAP.this.size(); }
|
||||
@Override
|
||||
public void clear() {
|
||||
LINKED_ENUM_MAP.this.clear();
|
||||
public void clear() { LINKED_ENUM_MAP.this.clear(); }
|
||||
@Override
|
||||
public VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE reversed() { return new VALUE_ABSTRACT_COLLECTION.VALUE_REVERSED_ORDERED_COLLECTIONVALUE_BRACES(this, this::reverseIterator); }
|
||||
private VALUE_ITERATOR VALUE_GENERIC_TYPE reverseIterator() {
|
||||
return new ValueIterator(false);
|
||||
}
|
||||
@Override
|
||||
public void addFirst(VALUE_TYPE e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void addLast(VALUE_TYPE e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE VALUE_GET_FIRST_KEY() { return FIRST_ENTRY_VALUE(); }
|
||||
@Override
|
||||
public VALUE_TYPE VALUE_REMOVE_FIRST_KEY() {
|
||||
VALUE_TYPE result = FIRST_ENTRY_VALUE();
|
||||
POLL_FIRST_ENTRY_KEY();
|
||||
return result;
|
||||
}
|
||||
@Override
|
||||
public VALUE_TYPE VALUE_GET_LAST_KEY() { return LAST_ENTRY_VALUE(); }
|
||||
@Override
|
||||
public VALUE_TYPE VALUE_REMOVE_LAST_KEY() {
|
||||
VALUE_TYPE result = LAST_ENTRY_VALUE();
|
||||
POLL_LAST_ENTRY_KEY();
|
||||
return result;
|
||||
}
|
||||
|
||||
#if VALUE_OBJECT
|
||||
@Override
|
||||
public void forEach(Consumer VALUE_SUPER_GENERIC_TYPE action) {
|
||||
@@ -715,7 +799,7 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
private class FastEntryIterator extends MapIterator implements ObjectListIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> {
|
||||
MapEntry entry = new MapEntry();
|
||||
|
||||
public FastEntryIterator() {}
|
||||
public FastEntryIterator(boolean start) { super(start); }
|
||||
public FastEntryIterator(T from) {
|
||||
super(from);
|
||||
}
|
||||
@@ -742,19 +826,19 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
private class EntryIterator extends MapIterator implements ObjectListIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> {
|
||||
MapEntry entry;
|
||||
|
||||
public EntryIterator() {}
|
||||
public EntryIterator(boolean start) { super(start); }
|
||||
public EntryIterator(T from) {
|
||||
super(from);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE next() {
|
||||
return entry = new MapEntry(nextEntry());
|
||||
return entry = new ValueMapEntry(nextEntry());
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE previous() {
|
||||
return entry = new MapEntry(previousEntry());
|
||||
return entry = new ValueMapEntry(previousEntry());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -772,7 +856,7 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
|
||||
private class KeyIterator extends MapIterator implements LIST_ITERATOR KEY_GENERIC_TYPE {
|
||||
|
||||
public KeyIterator() {}
|
||||
public KeyIterator(boolean start) { super(start); }
|
||||
public KeyIterator(T from) {
|
||||
super(from);
|
||||
}
|
||||
@@ -794,7 +878,7 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
}
|
||||
|
||||
private class ValueIterator extends MapIterator implements VALUE_LIST_ITERATOR VALUE_GENERIC_TYPE {
|
||||
public ValueIterator() {}
|
||||
public ValueIterator(boolean start) { super(start); }
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE VALUE_PREVIOUS() {
|
||||
@@ -815,16 +899,20 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
}
|
||||
|
||||
private class MapIterator {
|
||||
boolean forward;
|
||||
int previous = -1;
|
||||
int next = -1;
|
||||
int current = -1;
|
||||
int index = 0;
|
||||
|
||||
MapIterator() {
|
||||
next = firstIndex;
|
||||
MapIterator(boolean start) {
|
||||
this.forward = start;
|
||||
if(start) next = firstIndex;
|
||||
else previous = lastIndex;
|
||||
}
|
||||
|
||||
MapIterator(T from) {
|
||||
this.forward = true;
|
||||
previous = from.ordinal() - 1;
|
||||
index = from.ordinal();
|
||||
next = from.ordinal();
|
||||
@@ -832,11 +920,11 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return next != -1;
|
||||
return (forward ? next : previous) != -1;
|
||||
}
|
||||
|
||||
public boolean hasPrevious() {
|
||||
return previous != -1;
|
||||
return (forward ? previous : next) != -1;
|
||||
}
|
||||
|
||||
public int nextIndex() {
|
||||
@@ -871,20 +959,30 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
|
||||
public int previousEntry() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
current = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
next = current;
|
||||
if(forward) moveBackwards();
|
||||
else moveForwards();
|
||||
if(index >= 0) index--;
|
||||
return current;
|
||||
}
|
||||
|
||||
public int nextEntry() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
if(forward) moveForwards();
|
||||
else moveBackwards();
|
||||
if(index >= 0) index++;
|
||||
return current;
|
||||
}
|
||||
|
||||
private void moveBackwards() {
|
||||
current = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
next = current;
|
||||
}
|
||||
|
||||
private void moveForwards() {
|
||||
current = next;
|
||||
next = (int)(links[current]);
|
||||
previous = current;
|
||||
if(index >= 0) index++;
|
||||
return current;
|
||||
}
|
||||
|
||||
private void ensureIndexKnown() {
|
||||
@@ -903,6 +1001,33 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
}
|
||||
}
|
||||
|
||||
protected class ValueMapEntry extends MapEntry {
|
||||
protected KEY_TYPE key;
|
||||
protected VALUE_TYPE value;
|
||||
|
||||
public ValueMapEntry(int index) {
|
||||
super(index);
|
||||
key = keys[index];
|
||||
value = values[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE ENTRY_KEY() {
|
||||
return key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE ENTRY_VALUE() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE setValue(VALUE_TYPE value) {
|
||||
this.value = value;
|
||||
return super.setValue(value);
|
||||
}
|
||||
}
|
||||
|
||||
protected class MapEntry implements MAP.Entry KEY_VALUE_GENERIC_TYPE, Map.Entry<CLASS_TYPE, CLASS_VALUE_TYPE> {
|
||||
public int index = -1;
|
||||
|
||||
@@ -911,6 +1036,10 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
void set(int index) {
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE ENTRY_KEY() {
|
||||
return keys[index];
|
||||
@@ -933,19 +1062,19 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
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());
|
||||
return KEY_EQUALS(ENTRY_KEY(), entry.ENTRY_KEY()) && VALUE_EQUALS(ENTRY_VALUE(), 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);
|
||||
return KEY_EQUALS(ENTRY_KEY(), key) && VALUE_EQUALS(ENTRY_VALUE(), value);
|
||||
#else if TYPE_OBJECT
|
||||
return value instanceof CLASS_VALUE_TYPE && KEY_EQUALS(keys[index], key) && VALUE_EQUALS(values[index], CLASS_TO_VALUE(value));
|
||||
return value instanceof CLASS_VALUE_TYPE && KEY_EQUALS(ENTRY_KEY(), key) && VALUE_EQUALS(ENTRY_VALUE(), 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);
|
||||
return key instanceof CLASS_TYPE && KEY_EQUALS(ENTRY_KEY(), CLASS_TO_KEY(key)) && VALUE_EQUALS(ENTRY_VALUE(), 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));
|
||||
return key instanceof CLASS_TYPE && value instanceof CLASS_VALUE_TYPE && KEY_EQUALS(ENTRY_KEY(), CLASS_TO_KEY(key)) && VALUE_EQUALS(ENTRY_VALUE(), CLASS_TO_VALUE(value));
|
||||
#endif
|
||||
}
|
||||
return false;
|
||||
@@ -953,12 +1082,12 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return KEY_TO_HASH(keys[index]) ^ VALUE_TO_HASH(values[index]);
|
||||
return KEY_TO_HASH(ENTRY_KEY()) ^ VALUE_TO_HASH(ENTRY_VALUE());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return KEY_TO_STRING(keys[index]) + "=" + VALUE_TO_STRING(values[index]);
|
||||
return KEY_TO_STRING(ENTRY_KEY()) + "=" + VALUE_TO_STRING(ENTRY_VALUE());
|
||||
}
|
||||
}
|
||||
}
|
||||
+1581
File diff suppressed because it is too large
Load Diff
+1572
File diff suppressed because it is too large
Load Diff
+244
-73
@@ -6,9 +6,20 @@ import java.util.Map;
|
||||
import java.util.Comparator;
|
||||
#endif
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Predicate;
|
||||
#if !TYPE_OBJECT && JDK_TYPE
|
||||
import java.util.function.PREDICATE;
|
||||
import java.util.OPTIONAL;
|
||||
#endif
|
||||
#if !SAME_TYPE && JDK_VALUE && !VALUE_OBJECT
|
||||
import java.util.function.VALUE_PREDICATE;
|
||||
import java.util.VALUE_OPTIONAL;
|
||||
#endif
|
||||
|
||||
|
||||
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
||||
#if !TYPE_OBJECT
|
||||
@@ -16,11 +27,25 @@ 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_BOOLEAN
|
||||
import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
|
||||
#if !TYPE_OBJECT && !VALUE_OBJECT
|
||||
import speiger.src.collections.ints.functions.consumer.IntObjectConsumer;
|
||||
#endif
|
||||
#if !SAME_TYPE && !TYPE_INT
|
||||
import speiger.src.collections.ints.functions.consumer.VALUE_BI_FROM_INT_CONSUMER;
|
||||
#endif
|
||||
#if !VALUE_BOOLEAN || !JDK_TYPE
|
||||
import speiger.src.collections.PACKAGE.functions.function.FUNCTION;
|
||||
#endif
|
||||
#if !TYPE_INT || !SAME_TYPE
|
||||
import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
|
||||
#endif
|
||||
#if !TYPE_OBJECT && !JDK_TYPE
|
||||
import speiger.src.collections.PACKAGE.functions.OPTIONAL;
|
||||
#if!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.FUNCTION;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||
#if !SAME_TYPE
|
||||
import speiger.src.collections.PACKAGE.functions.function.SINGLE_UNARY_OPERATOR;
|
||||
@@ -33,7 +58,6 @@ import speiger.src.collections.PACKAGE.sets.NAVIGABLE_SET;
|
||||
#if TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.sets.SET;
|
||||
#endif
|
||||
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;
|
||||
@@ -48,17 +72,15 @@ import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_CONSUMER;
|
||||
#if !TYPE_OBJECT && !VALUE_OBJECT || !VALUE_OBJECT
|
||||
import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer;
|
||||
#endif
|
||||
#if !TYPE_OBJECT || !VALUE_BOOLEAN
|
||||
#if !VALUE_OBJECT || SAME_TYPE
|
||||
import speiger.src.collections.objects.functions.function.Object2BooleanFunction;
|
||||
#endif
|
||||
#endif
|
||||
#if !SAME_TYPE
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.objects.functions.consumer.VALUE_BI_FROM_OBJECT_CONSUMER;
|
||||
|
||||
#endif
|
||||
#if !JDK_VALUE
|
||||
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE;
|
||||
import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_OPTIONAL;
|
||||
#endif
|
||||
#endif
|
||||
#if !TYPE_OBJECT && !VALUE_OBJECT
|
||||
import speiger.src.collections.objects.collections.ObjectBidirectionalIterator;
|
||||
@@ -280,7 +302,10 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
int compare = 0;
|
||||
Node KEY_VALUE_GENERIC_TYPE parent = tree;
|
||||
while(true) {
|
||||
if((compare = compare(key, parent.key)) == 0) return parent.value;
|
||||
if((compare = compare(key, parent.key)) == 0) {
|
||||
if(VALUE_EQUALS(parent.value, getDefaultReturnValue())) return parent.setValue(value);
|
||||
return parent.value;
|
||||
}
|
||||
if(compare < 0) {
|
||||
if(parent.left == null) break;
|
||||
parent = parent.left;
|
||||
@@ -528,6 +553,105 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
#if TYPE_OBJECT
|
||||
validate(key);
|
||||
#endif
|
||||
Node KEY_VALUE_GENERIC_TYPE entry = findNode(key);
|
||||
if(entry == null) {
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, getDefaultReturnValue());
|
||||
#if VALUE_OBJECT
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
#endif
|
||||
put(key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, entry.value);
|
||||
#if VALUE_OBJECT
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
removeNode(entry);
|
||||
return newValue;
|
||||
}
|
||||
#endif
|
||||
entry.value = newValue;
|
||||
return newValue;
|
||||
}
|
||||
|
||||
@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
|
||||
Node KEY_VALUE_GENERIC_TYPE entry = findNode(key);
|
||||
if(entry == null) {
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY(key);
|
||||
#if VALUE_OBJECT
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
#endif
|
||||
put(key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
#if VALUE_OBJECT
|
||||
if(Objects.equals(entry.value, getDefaultReturnValue())) {
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY(key);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
entry.value = newValue;
|
||||
}
|
||||
#endif
|
||||
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
|
||||
Node KEY_VALUE_GENERIC_TYPE entry = findNode(key);
|
||||
if(entry == null) {
|
||||
VALUE_TYPE newValue = valueProvider.VALUE_SUPPLY_GET();
|
||||
#if VALUE_OBJECT
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
#endif
|
||||
put(key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
#if VALUE_OBJECT
|
||||
if(VALUE_EQUALS(entry.value, getDefaultReturnValue())) {
|
||||
VALUE_TYPE newValue = valueProvider.VALUE_SUPPLY_GET();
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
entry.value = newValue;
|
||||
}
|
||||
#endif
|
||||
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
|
||||
Node KEY_VALUE_GENERIC_TYPE entry = findNode(key);
|
||||
#if !VALUE_OBJECT
|
||||
if(entry == null) return getDefaultReturnValue();
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, entry.value);
|
||||
#else
|
||||
if(entry == null || VALUE_EQUALS(entry.value, getDefaultReturnValue())) return getDefaultReturnValue();
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, entry.value);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
removeNode(entry);
|
||||
return newValue;
|
||||
}
|
||||
#endif
|
||||
entry.value = newValue;
|
||||
return newValue;
|
||||
}
|
||||
|
||||
#if !VALUE_OBJECT
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTENonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
#if TYPE_OBJECT
|
||||
validate(key);
|
||||
#endif
|
||||
Node KEY_VALUE_GENERIC_TYPE entry = findNode(key);
|
||||
if(entry == null) {
|
||||
@@ -546,20 +670,20 @@ 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) {
|
||||
public VALUE_TYPE COMPUTE_IF_ABSENTNonDefault(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
#if TYPE_OBJECT
|
||||
validate(key);
|
||||
#endif
|
||||
Node KEY_VALUE_GENERIC_TYPE entry = findNode(key);
|
||||
if(entry == null) {
|
||||
VALUE_TYPE newValue = mappingFunction.GET_VALUE(key);
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY(key);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
put(key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
if(Objects.equals(entry.value, getDefaultReturnValue())) {
|
||||
VALUE_TYPE newValue = mappingFunction.GET_VALUE(key);
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY(key);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
entry.value = newValue;
|
||||
}
|
||||
@@ -567,20 +691,20 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENT(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENTNonDefault(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
|
||||
Objects.requireNonNull(valueProvider);
|
||||
#if TYPE_OBJECT
|
||||
validate(key);
|
||||
#endif
|
||||
Node KEY_VALUE_GENERIC_TYPE entry = findNode(key);
|
||||
if(entry == null) {
|
||||
VALUE_TYPE newValue = valueProvider.VALUE_GET_KEY();
|
||||
VALUE_TYPE newValue = valueProvider.VALUE_SUPPLY_GET();
|
||||
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();
|
||||
VALUE_TYPE newValue = valueProvider.VALUE_SUPPLY_GET();
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
entry.value = newValue;
|
||||
}
|
||||
@@ -588,7 +712,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENTNonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
#if TYPE_OBJECT
|
||||
validate(key);
|
||||
@@ -604,6 +728,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
return newValue;
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public VALUE_TYPE MERGE(KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
@@ -624,7 +749,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
@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)) {
|
||||
for(MAP.Entry KEY_VALUE_GENERIC_TYPE entry : getFastIterable(m)) {
|
||||
KEY_TYPE key = entry.ENTRY_KEY();
|
||||
Node 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());
|
||||
@@ -1144,6 +1269,14 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
action.accept(entry.key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
|
||||
Objects.requireNonNull(action);
|
||||
int index = 0;
|
||||
for(Node KEY_VALUE_GENERIC_TYPE entry = start(), end = end();entry != null && (end == null || (end != previous(entry)));entry = next(entry))
|
||||
action.accept(index++, entry.key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
@@ -1155,7 +1288,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
public boolean matchesAny(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(Node KEY_VALUE_GENERIC_TYPE entry = start(), end = end();entry != null && (end == null || (end != previous(entry)));entry = next(entry))
|
||||
if(filter.TEST_VALUE(entry.key)) return true;
|
||||
if(filter.test(entry.key)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1163,7 +1296,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
public boolean matchesNone(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(Node KEY_VALUE_GENERIC_TYPE entry = start(), end = end();entry != null && (end == null || (end != previous(entry)));entry = next(entry))
|
||||
if(filter.TEST_VALUE(entry.key)) return false;
|
||||
if(filter.test(entry.key)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1171,7 +1304,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
public boolean matchesAll(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(Node KEY_VALUE_GENERIC_TYPE entry = start(), end = end();entry != null && (end == null || (end != previous(entry)));entry = next(entry))
|
||||
if(!filter.TEST_VALUE(entry.key)) return false;
|
||||
if(!filter.test(entry.key)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1197,7 +1330,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public KEY_TYPE reduce(SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
public OPTIONAL KEY_GENERIC_TYPE reduce(SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = EMPTY_KEY_VALUE;
|
||||
boolean empty = true;
|
||||
@@ -1209,15 +1342,15 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
}
|
||||
state = operator.APPLY_KEY_VALUE(state, entry.key);
|
||||
}
|
||||
return state;
|
||||
return empty ? OPTIONAL.empty() : OPTIONAL.GET_OPTIONAL(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
public OPTIONAL KEY_GENERIC_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(Node KEY_VALUE_GENERIC_TYPE entry = start(), end = end();entry != null && (end == null || (end != previous(entry)));entry = next(entry))
|
||||
if(filter.TEST_VALUE(entry.key)) return entry.key;
|
||||
return EMPTY_KEY_VALUE;
|
||||
if(filter.test(entry.key)) return OPTIONAL.GET_OPTIONAL(entry.key);
|
||||
return OPTIONAL.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1225,7 +1358,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
Objects.requireNonNull(filter);
|
||||
int result = 0;
|
||||
for(Node 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++;
|
||||
if(filter.test(entry.key)) result++;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -1645,6 +1778,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
#endif
|
||||
if(!inRange(key)) return getDefaultReturnValue();
|
||||
Node KEY_VALUE_GENERIC_TYPE entry = map.findNode(key);
|
||||
#if VALUE_OBJECT
|
||||
if(entry == null || VALUE_EQUALS(entry.value, getDefaultReturnValue())) return getDefaultReturnValue();
|
||||
VALUE_TYPE newValue = mappingFunction.apply(key, entry.value);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
@@ -1653,6 +1787,11 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
}
|
||||
entry.value = newValue;
|
||||
return newValue;
|
||||
#else
|
||||
if(entry == null) return getDefaultReturnValue();
|
||||
entry.value = mappingFunction.apply(key, entry.value);
|
||||
return entry.value;
|
||||
#endif
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1832,6 +1971,14 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
action.accept(new BasicEntryKV_BRACES(entry.key, entry.value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEachIndexed(IntObjectConsumer<MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
|
||||
Objects.requireNonNull(action);
|
||||
int index = 0;
|
||||
for(Node KEY_VALUE_GENERIC_TYPE entry = subLowest(), last = subHighest();entry != null && (last == null || last != previous(entry));entry = next(entry))
|
||||
action.accept(index++, new BasicEntryKV_BRACES(entry.key, entry.value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, ObjectObjectConsumer<E, MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
|
||||
Objects.requireNonNull(action);
|
||||
@@ -1840,37 +1987,37 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matchesAny(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
public boolean matchesAny(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return false;
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE subEntry = new BasicEntryKV_BRACES();
|
||||
for(Node KEY_VALUE_GENERIC_TYPE entry = subLowest(), last = subHighest();entry != null && (last == null || last != previous(entry));entry = next(entry)) {
|
||||
subEntry.set(entry.key, entry.value);
|
||||
if(filter.getBoolean(subEntry)) return true;
|
||||
if(filter.test(subEntry)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matchesNone(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
public boolean matchesNone(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return true;
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE subEntry = new BasicEntryKV_BRACES();
|
||||
for(Node KEY_VALUE_GENERIC_TYPE entry = subLowest(), last = subHighest();entry != null && (last == null || last != previous(entry));entry = next(entry)) {
|
||||
subEntry.set(entry.key, entry.value);
|
||||
if(filter.getBoolean(subEntry)) return false;
|
||||
if(filter.test(subEntry)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matchesAll(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
public boolean matchesAll(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return true;
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE subEntry = new BasicEntryKV_BRACES();
|
||||
for(Node KEY_VALUE_GENERIC_TYPE entry = subLowest(), last = subHighest();entry != null && (last == null || last != previous(entry));entry = next(entry)) {
|
||||
subEntry.set(entry.key, entry.value);
|
||||
if(!filter.getBoolean(subEntry)) return false;
|
||||
if(!filter.test(subEntry)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -1886,7 +2033,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE reduce(ObjectObjectUnaryOperator<MAP.Entry KEY_VALUE_GENERIC_TYPE, MAP.Entry KEY_VALUE_GENERIC_TYPE> operator) {
|
||||
public Optional<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;
|
||||
@@ -1898,30 +2045,30 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
}
|
||||
state = operator.apply(state, new BasicEntryKV_BRACES(entry.key, entry.value));
|
||||
}
|
||||
return state;
|
||||
return empty ? Optional.empty() : Optional.ofNullable(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
public Optional<MAP.Entry KEY_VALUE_GENERIC_TYPE> findFirst(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return null;
|
||||
if(size() <= 0) return Optional.empty();
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE subEntry = new BasicEntryKV_BRACES();
|
||||
for(Node KEY_VALUE_GENERIC_TYPE entry = subLowest(), last = subHighest();entry != null && (last == null || last != previous(entry));entry = next(entry)) {
|
||||
subEntry.set(entry.key, entry.value);
|
||||
if(filter.getBoolean(subEntry)) return subEntry;
|
||||
if(filter.test(subEntry)) return Optional.ofNullable(subEntry);
|
||||
}
|
||||
return null;
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
public int count(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return 0;
|
||||
int result = 0;
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE subEntry = new BasicEntryKV_BRACES();
|
||||
for(Node KEY_VALUE_GENERIC_TYPE entry = subLowest(), last = subHighest();entry != null && (last == null || last != previous(entry));entry = next(entry)) {
|
||||
subEntry.set(entry.key, entry.value);
|
||||
if(filter.getBoolean(subEntry)) result++;
|
||||
if(filter.test(subEntry)) result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -1964,6 +2111,14 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
action.accept(entry.value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEachIndexed(VALUE_BI_FROM_INT_CONSUMER VALUE_GENERIC_TYPE action) {
|
||||
Objects.requireNonNull(action);
|
||||
int index = 0;
|
||||
for(Node KEY_VALUE_GENERIC_TYPE entry = subLowest(), last = subHighest();entry != null && (last == null || last != previous(entry));entry = next(entry))
|
||||
action.accept(index++, entry.value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, VALUE_BI_FROM_OBJECT_CONSUMER VSV_GENERIC_TYPE<E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
@@ -1975,7 +2130,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
public boolean matchesAny(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(Node KEY_VALUE_GENERIC_TYPE entry = subLowest(), last = subHighest();entry != null && (last == null || last != previous(entry));entry = next(entry))
|
||||
if(filter.VALUE_TEST_VALUE(entry.value)) return true;
|
||||
if(filter.test(entry.value)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1983,7 +2138,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
public boolean matchesNone(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(Node KEY_VALUE_GENERIC_TYPE entry = subLowest(), last = subHighest();entry != null && (last == null || last != previous(entry));entry = next(entry))
|
||||
if(filter.VALUE_TEST_VALUE(entry.value)) return false;
|
||||
if(filter.test(entry.value)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1991,7 +2146,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
public boolean matchesAll(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(Node KEY_VALUE_GENERIC_TYPE entry = subLowest(), last = subHighest();entry != null && (last == null || last != previous(entry));entry = next(entry))
|
||||
if(!filter.VALUE_TEST_VALUE(entry.value)) return false;
|
||||
if(!filter.test(entry.value)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -2017,7 +2172,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public VALUE_TYPE reduce(VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
|
||||
public VALUE_OPTIONAL VALUE_GENERIC_TYPE reduce(VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
VALUE_TYPE state = EMPTY_VALUE;
|
||||
boolean empty = true;
|
||||
@@ -2029,15 +2184,15 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
}
|
||||
state = operator.APPLY_VALUE(state, entry.value);
|
||||
}
|
||||
return state;
|
||||
return empty ? VALUE_OPTIONAL.empty() : VALUE_OPTIONAL.GET_OPTIONAL_VALUE(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
||||
public VALUE_OPTIONAL VALUE_GENERIC_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(Node KEY_VALUE_GENERIC_TYPE entry = subLowest(), last = subHighest();entry != null && (last == null || last != previous(entry));entry = next(entry))
|
||||
if(filter.VALUE_TEST_VALUE(entry.value)) return entry.value;
|
||||
return EMPTY_VALUE;
|
||||
if(filter.test(entry.value)) return VALUE_OPTIONAL.GET_OPTIONAL_VALUE(entry.value);
|
||||
return VALUE_OPTIONAL.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -2045,7 +2200,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
Objects.requireNonNull(filter);
|
||||
int result = 0;
|
||||
for(Node KEY_VALUE_GENERIC_TYPE entry = subLowest(), last = subHighest();entry != null && (last == null || last != previous(entry));entry = next(entry))
|
||||
if(filter.VALUE_TEST_VALUE(entry.value)) result++;
|
||||
if(filter.test(entry.value)) result++;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -2312,6 +2467,14 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
action.accept(entry.value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEachIndexed(VALUE_BI_FROM_INT_CONSUMER VALUE_GENERIC_TYPE action) {
|
||||
Objects.requireNonNull(action);
|
||||
int index = 0;
|
||||
for(Node KEY_VALUE_GENERIC_TYPE entry = first;entry != null;entry = entry.next())
|
||||
action.accept(index++, entry.value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, VALUE_BI_FROM_OBJECT_CONSUMER VSV_GENERIC_TYPE<E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
@@ -2323,7 +2486,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
public boolean matchesAny(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(Node KEY_VALUE_GENERIC_TYPE entry = first;entry != null;entry = entry.next())
|
||||
if(filter.VALUE_TEST_VALUE(entry.value)) return true;
|
||||
if(filter.test(entry.value)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -2331,7 +2494,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
public boolean matchesNone(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(Node KEY_VALUE_GENERIC_TYPE entry = first;entry != null;entry = entry.next())
|
||||
if(filter.VALUE_TEST_VALUE(entry.value)) return false;
|
||||
if(filter.test(entry.value)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -2339,7 +2502,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
public boolean matchesAll(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(Node KEY_VALUE_GENERIC_TYPE entry = first;entry != null;entry = entry.next())
|
||||
if(!filter.VALUE_TEST_VALUE(entry.value)) return false;
|
||||
if(!filter.test(entry.value)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -2365,7 +2528,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public VALUE_TYPE reduce(VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
|
||||
public VALUE_OPTIONAL VALUE_GENERIC_TYPE reduce(VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
VALUE_TYPE state = EMPTY_VALUE;
|
||||
boolean empty = true;
|
||||
@@ -2377,15 +2540,15 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
}
|
||||
state = operator.APPLY_VALUE(state, entry.value);
|
||||
}
|
||||
return state;
|
||||
return empty ? VALUE_OPTIONAL.empty() : VALUE_OPTIONAL.GET_OPTIONAL_VALUE(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
||||
public VALUE_OPTIONAL VALUE_GENERIC_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(Node KEY_VALUE_GENERIC_TYPE entry = first;entry != null;entry = entry.next())
|
||||
if(filter.VALUE_TEST_VALUE(entry.value)) return entry.value;
|
||||
return EMPTY_VALUE;
|
||||
if(filter.test(entry.value)) return VALUE_OPTIONAL.GET_OPTIONAL_VALUE(entry.value);
|
||||
return VALUE_OPTIONAL.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -2393,7 +2556,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
Objects.requireNonNull(filter);
|
||||
int result = 0;
|
||||
for(Node KEY_VALUE_GENERIC_TYPE entry = first;entry != null;entry = entry.next())
|
||||
if(filter.VALUE_TEST_VALUE(entry.value)) result++;
|
||||
if(filter.test(entry.value)) result++;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -2469,6 +2632,14 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
action.accept(new BasicEntryKV_BRACES(entry.key, entry.value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEachIndexed(IntObjectConsumer<MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
|
||||
Objects.requireNonNull(action);
|
||||
int index = 0;
|
||||
for(Node KEY_VALUE_GENERIC_TYPE entry = first;entry != null;entry = entry.next())
|
||||
action.accept(index++, new BasicEntryKV_BRACES(entry.key, entry.value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, ObjectObjectConsumer<E, MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
|
||||
Objects.requireNonNull(action);
|
||||
@@ -2477,37 +2648,37 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matchesAny(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
public boolean matchesAny(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return false;
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE subEntry = new BasicEntryKV_BRACES();
|
||||
for(Node KEY_VALUE_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) {
|
||||
subEntry.set(entry.key, entry.value);
|
||||
if(filter.getBoolean(subEntry)) return true;
|
||||
if(filter.test(subEntry)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matchesNone(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
public boolean matchesNone(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return true;
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE subEntry = new BasicEntryKV_BRACES();
|
||||
for(Node KEY_VALUE_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) {
|
||||
subEntry.set(entry.key, entry.value);
|
||||
if(filter.getBoolean(subEntry)) return false;
|
||||
if(filter.test(subEntry)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matchesAll(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
public boolean matchesAll(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return true;
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE subEntry = new BasicEntryKV_BRACES();
|
||||
for(Node KEY_VALUE_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) {
|
||||
subEntry.set(entry.key, entry.value);
|
||||
if(!filter.getBoolean(subEntry)) return false;
|
||||
if(!filter.test(subEntry)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -2523,7 +2694,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE reduce(ObjectObjectUnaryOperator<MAP.Entry KEY_VALUE_GENERIC_TYPE, MAP.Entry KEY_VALUE_GENERIC_TYPE> operator) {
|
||||
public Optional<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;
|
||||
@@ -2535,30 +2706,30 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
}
|
||||
state = operator.apply(state, new BasicEntryKV_BRACES(entry.key, entry.value));
|
||||
}
|
||||
return state;
|
||||
return empty ? Optional.empty() : Optional.ofNullable(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
public Optional<MAP.Entry KEY_VALUE_GENERIC_TYPE> findFirst(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return null;
|
||||
if(size() <= 0) return Optional.empty();
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE subEntry = new BasicEntryKV_BRACES();
|
||||
for(Node KEY_VALUE_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) {
|
||||
subEntry.set(entry.key, entry.value);
|
||||
if(filter.getBoolean(subEntry)) return subEntry;
|
||||
if(filter.test(subEntry)) return Optional.ofNullable(subEntry);
|
||||
}
|
||||
return null;
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
public int count(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return 0;
|
||||
int result = 0;
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE subEntry = new BasicEntryKV_BRACES();
|
||||
for(Node KEY_VALUE_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) {
|
||||
subEntry.set(entry.key, entry.value);
|
||||
if(filter.getBoolean(subEntry)) result++;
|
||||
if(filter.test(subEntry)) result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
+243
-73
@@ -6,9 +6,19 @@ import java.util.Map;
|
||||
import java.util.Comparator;
|
||||
#endif
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Predicate;
|
||||
#if !TYPE_OBJECT && JDK_TYPE
|
||||
import java.util.function.PREDICATE;
|
||||
import java.util.OPTIONAL;
|
||||
#endif
|
||||
#if !SAME_TYPE && JDK_VALUE && !VALUE_OBJECT
|
||||
import java.util.function.VALUE_PREDICATE;
|
||||
import java.util.VALUE_OPTIONAL;
|
||||
#endif
|
||||
|
||||
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
||||
#if !TYPE_OBJECT
|
||||
@@ -16,11 +26,25 @@ 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_BOOLEAN
|
||||
import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
|
||||
#if !TYPE_OBJECT && !VALUE_OBJECT
|
||||
import speiger.src.collections.ints.functions.consumer.IntObjectConsumer;
|
||||
#endif
|
||||
#if !SAME_TYPE && !TYPE_INT
|
||||
import speiger.src.collections.ints.functions.consumer.VALUE_BI_FROM_INT_CONSUMER;
|
||||
#endif
|
||||
#if !VALUE_BOOLEAN || !JDK_TYPE
|
||||
import speiger.src.collections.PACKAGE.functions.function.FUNCTION;
|
||||
#endif
|
||||
#if !TYPE_INT || !SAME_TYPE
|
||||
import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
|
||||
#endif
|
||||
#if !TYPE_OBJECT && !JDK_TYPE
|
||||
import speiger.src.collections.PACKAGE.functions.OPTIONAL;
|
||||
#if!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.FUNCTION;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||
#if !SAME_TYPE
|
||||
import speiger.src.collections.PACKAGE.functions.function.SINGLE_UNARY_OPERATOR;
|
||||
@@ -33,7 +57,6 @@ import speiger.src.collections.PACKAGE.sets.NAVIGABLE_SET;
|
||||
#if TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.sets.SET;
|
||||
#endif
|
||||
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;
|
||||
@@ -48,17 +71,15 @@ import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_CONSUMER;
|
||||
#if !TYPE_OBJECT && !VALUE_OBJECT || !VALUE_OBJECT
|
||||
import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer;
|
||||
#endif
|
||||
#if !TYPE_OBJECT || !VALUE_BOOLEAN
|
||||
#if !VALUE_OBJECT || SAME_TYPE
|
||||
import speiger.src.collections.objects.functions.function.Object2BooleanFunction;
|
||||
#endif
|
||||
#endif
|
||||
#if !SAME_TYPE
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.objects.functions.consumer.VALUE_BI_FROM_OBJECT_CONSUMER;
|
||||
|
||||
#endif
|
||||
#if !JDK_VALUE
|
||||
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE;
|
||||
import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_OPTIONAL;
|
||||
#endif
|
||||
#endif
|
||||
#if !TYPE_OBJECT && !VALUE_OBJECT
|
||||
import speiger.src.collections.objects.collections.ObjectBidirectionalIterator;
|
||||
@@ -280,7 +301,10 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
int compare = 0;
|
||||
Node KEY_VALUE_GENERIC_TYPE parent = tree;
|
||||
while(true) {
|
||||
if((compare = compare(key, parent.key)) == 0) return parent.value;
|
||||
if((compare = compare(key, parent.key)) == 0) {
|
||||
if(VALUE_EQUALS(parent.value, getDefaultReturnValue())) return parent.setValue(value);
|
||||
return parent.value;
|
||||
}
|
||||
if(compare < 0) {
|
||||
if(parent.left == null) break;
|
||||
parent = parent.left;
|
||||
@@ -531,6 +555,105 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
#if TYPE_OBJECT
|
||||
validate(key);
|
||||
#endif
|
||||
Node KEY_VALUE_GENERIC_TYPE entry = findNode(key);
|
||||
if(entry == null) {
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, getDefaultReturnValue());
|
||||
#if VALUE_OBJECT
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
#endif
|
||||
put(key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, entry.value);
|
||||
#if VALUE_OBJECT
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
removeNode(entry);
|
||||
return newValue;
|
||||
}
|
||||
#endif
|
||||
entry.value = newValue;
|
||||
return newValue;
|
||||
}
|
||||
|
||||
@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
|
||||
Node KEY_VALUE_GENERIC_TYPE entry = findNode(key);
|
||||
if(entry == null) {
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY(key);
|
||||
#if VALUE_OBJECT
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
#endif
|
||||
put(key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
#if VALUE_OBJECT
|
||||
if(Objects.equals(entry.value, getDefaultReturnValue())) {
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY(key);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
entry.value = newValue;
|
||||
}
|
||||
#endif
|
||||
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
|
||||
Node KEY_VALUE_GENERIC_TYPE entry = findNode(key);
|
||||
if(entry == null) {
|
||||
VALUE_TYPE newValue = valueProvider.VALUE_SUPPLY_GET();
|
||||
#if VALUE_OBJECT
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
#endif
|
||||
put(key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
#if VALUE_OBJECT
|
||||
if(VALUE_EQUALS(entry.value, getDefaultReturnValue())) {
|
||||
VALUE_TYPE newValue = valueProvider.VALUE_SUPPLY_GET();
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
entry.value = newValue;
|
||||
}
|
||||
#endif
|
||||
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
|
||||
Node KEY_VALUE_GENERIC_TYPE entry = findNode(key);
|
||||
#if !VALUE_OBJECT
|
||||
if(entry == null) return getDefaultReturnValue();
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, entry.value);
|
||||
#else
|
||||
if(entry == null || VALUE_EQUALS(entry.value, getDefaultReturnValue())) return getDefaultReturnValue();
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, entry.value);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
removeNode(entry);
|
||||
return newValue;
|
||||
}
|
||||
#endif
|
||||
entry.value = newValue;
|
||||
return newValue;
|
||||
}
|
||||
|
||||
#if !VALUE_OBJECT
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTENonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
#if TYPE_OBJECT
|
||||
validate(key);
|
||||
#endif
|
||||
Node KEY_VALUE_GENERIC_TYPE entry = findNode(key);
|
||||
if(entry == null) {
|
||||
@@ -549,20 +672,20 @@ 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) {
|
||||
public VALUE_TYPE COMPUTE_IF_ABSENTNonDefault(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
#if TYPE_OBJECT
|
||||
validate(key);
|
||||
#endif
|
||||
Node KEY_VALUE_GENERIC_TYPE entry = findNode(key);
|
||||
if(entry == null) {
|
||||
VALUE_TYPE newValue = mappingFunction.GET_VALUE(key);
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY(key);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
put(key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
if(Objects.equals(entry.value, getDefaultReturnValue())) {
|
||||
VALUE_TYPE newValue = mappingFunction.GET_VALUE(key);
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY(key);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
entry.value = newValue;
|
||||
}
|
||||
@@ -570,20 +693,20 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENT(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENTNonDefault(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
|
||||
Objects.requireNonNull(valueProvider);
|
||||
#if TYPE_OBJECT
|
||||
validate(key);
|
||||
#endif
|
||||
Node KEY_VALUE_GENERIC_TYPE entry = findNode(key);
|
||||
if(entry == null) {
|
||||
VALUE_TYPE newValue = valueProvider.VALUE_GET_KEY();
|
||||
VALUE_TYPE newValue = valueProvider.VALUE_SUPPLY_GET();
|
||||
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();
|
||||
VALUE_TYPE newValue = valueProvider.VALUE_SUPPLY_GET();
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
entry.value = newValue;
|
||||
}
|
||||
@@ -591,7 +714,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENTNonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
#if TYPE_OBJECT
|
||||
validate(key);
|
||||
@@ -607,6 +730,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
return newValue;
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public VALUE_TYPE MERGE(KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
@@ -627,7 +751,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
@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)) {
|
||||
for(MAP.Entry KEY_VALUE_GENERIC_TYPE entry : getFastIterable(m)) {
|
||||
KEY_TYPE key = entry.ENTRY_KEY();
|
||||
Node 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());
|
||||
@@ -1201,6 +1325,14 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
action.accept(entry.key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
|
||||
Objects.requireNonNull(action);
|
||||
int index = 0;
|
||||
for(Node KEY_VALUE_GENERIC_TYPE entry = start(), end = end();entry != null && (end == null || (end != previous(entry)));entry = next(entry))
|
||||
action.accept(index++, entry.key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
@@ -1212,7 +1344,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
public boolean matchesAny(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(Node KEY_VALUE_GENERIC_TYPE entry = start(), end = end();entry != null && (end == null || (end != previous(entry)));entry = next(entry))
|
||||
if(filter.TEST_VALUE(entry.key)) return true;
|
||||
if(filter.test(entry.key)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1220,7 +1352,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
public boolean matchesNone(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(Node KEY_VALUE_GENERIC_TYPE entry = start(), end = end();entry != null && (end == null || (end != previous(entry)));entry = next(entry))
|
||||
if(filter.TEST_VALUE(entry.key)) return false;
|
||||
if(filter.test(entry.key)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1228,7 +1360,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
public boolean matchesAll(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(Node KEY_VALUE_GENERIC_TYPE entry = start(), end = end();entry != null && (end == null || (end != previous(entry)));entry = next(entry))
|
||||
if(!filter.TEST_VALUE(entry.key)) return false;
|
||||
if(!filter.test(entry.key)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1254,7 +1386,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public KEY_TYPE reduce(SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
public OPTIONAL KEY_GENERIC_TYPE reduce(SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = EMPTY_KEY_VALUE;
|
||||
boolean empty = true;
|
||||
@@ -1266,15 +1398,15 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
}
|
||||
state = operator.APPLY_KEY_VALUE(state, entry.key);
|
||||
}
|
||||
return state;
|
||||
return empty ? OPTIONAL.empty() : OPTIONAL.GET_OPTIONAL(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
public OPTIONAL KEY_GENERIC_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(Node KEY_VALUE_GENERIC_TYPE entry = start(), end = end();entry != null && (end == null || (end != previous(entry)));entry = next(entry))
|
||||
if(filter.TEST_VALUE(entry.key)) return entry.key;
|
||||
return EMPTY_KEY_VALUE;
|
||||
if(filter.test(entry.key)) return OPTIONAL.GET_OPTIONAL(entry.key);
|
||||
return OPTIONAL.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1282,7 +1414,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
Objects.requireNonNull(filter);
|
||||
int result = 0;
|
||||
for(Node 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++;
|
||||
if(filter.test(entry.key)) result++;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -1712,6 +1844,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
#endif
|
||||
if(!inRange(key)) return getDefaultReturnValue();
|
||||
Node KEY_VALUE_GENERIC_TYPE entry = map.findNode(key);
|
||||
#if VALUE_OBJECT
|
||||
if(entry == null || VALUE_EQUALS(entry.value, getDefaultReturnValue())) return getDefaultReturnValue();
|
||||
VALUE_TYPE newValue = mappingFunction.apply(key, entry.value);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
@@ -1720,6 +1853,11 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
}
|
||||
entry.value = newValue;
|
||||
return newValue;
|
||||
#else
|
||||
if(entry == null) return getDefaultReturnValue();
|
||||
entry.value = mappingFunction.apply(key, entry.value);
|
||||
return entry.value;
|
||||
#endif
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1899,6 +2037,14 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
action.accept(new BasicEntryKV_BRACES(entry.key, entry.value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEachIndexed(IntObjectConsumer<MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
|
||||
Objects.requireNonNull(action);
|
||||
int index = 0;
|
||||
for(Node KEY_VALUE_GENERIC_TYPE entry = subLowest(), last = subHighest();entry != null && (last == null || last != previous(entry));entry = next(entry))
|
||||
action.accept(index++, new BasicEntryKV_BRACES(entry.key, entry.value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, ObjectObjectConsumer<E, MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
|
||||
Objects.requireNonNull(action);
|
||||
@@ -1907,37 +2053,37 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matchesAny(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
public boolean matchesAny(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return false;
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE subEntry = new BasicEntryKV_BRACES();
|
||||
for(Node KEY_VALUE_GENERIC_TYPE entry = subLowest(), last = subHighest();entry != null && (last == null || last != previous(entry));entry = next(entry)) {
|
||||
subEntry.set(entry.key, entry.value);
|
||||
if(filter.getBoolean(subEntry)) return true;
|
||||
if(filter.test(subEntry)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matchesNone(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
public boolean matchesNone(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return true;
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE subEntry = new BasicEntryKV_BRACES();
|
||||
for(Node KEY_VALUE_GENERIC_TYPE entry = subLowest(), last = subHighest();entry != null && (last == null || last != previous(entry));entry = next(entry)) {
|
||||
subEntry.set(entry.key, entry.value);
|
||||
if(filter.getBoolean(subEntry)) return false;
|
||||
if(filter.test(subEntry)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matchesAll(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
public boolean matchesAll(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return true;
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE subEntry = new BasicEntryKV_BRACES();
|
||||
for(Node KEY_VALUE_GENERIC_TYPE entry = subLowest(), last = subHighest();entry != null && (last == null || last != previous(entry));entry = next(entry)) {
|
||||
subEntry.set(entry.key, entry.value);
|
||||
if(!filter.getBoolean(subEntry)) return false;
|
||||
if(!filter.test(subEntry)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -1953,7 +2099,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE reduce(ObjectObjectUnaryOperator<MAP.Entry KEY_VALUE_GENERIC_TYPE, MAP.Entry KEY_VALUE_GENERIC_TYPE> operator) {
|
||||
public Optional<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;
|
||||
@@ -1965,30 +2111,30 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
}
|
||||
state = operator.apply(state, new BasicEntryKV_BRACES(entry.key, entry.value));
|
||||
}
|
||||
return state;
|
||||
return empty ? Optional.empty() : Optional.ofNullable(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
public Optional<MAP.Entry KEY_VALUE_GENERIC_TYPE> findFirst(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return null;
|
||||
if(size() <= 0) return Optional.empty();
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE subEntry = new BasicEntryKV_BRACES();
|
||||
for(Node KEY_VALUE_GENERIC_TYPE entry = subLowest(), last = subHighest();entry != null && (last == null || last != previous(entry));entry = next(entry)) {
|
||||
subEntry.set(entry.key, entry.value);
|
||||
if(filter.getBoolean(subEntry)) return subEntry;
|
||||
if(filter.test(subEntry)) return Optional.ofNullable(subEntry);
|
||||
}
|
||||
return null;
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
public int count(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return 0;
|
||||
int result = 0;
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE subEntry = new BasicEntryKV_BRACES();
|
||||
for(Node KEY_VALUE_GENERIC_TYPE entry = subLowest(), last = subHighest();entry != null && (last == null || last != previous(entry));entry = next(entry)) {
|
||||
subEntry.set(entry.key, entry.value);
|
||||
if(filter.getBoolean(subEntry)) result++;
|
||||
if(filter.test(subEntry)) result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -2031,6 +2177,14 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
action.accept(entry.value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEachIndexed(VALUE_BI_FROM_INT_CONSUMER VALUE_GENERIC_TYPE action) {
|
||||
Objects.requireNonNull(action);
|
||||
int index = 0;
|
||||
for(Node KEY_VALUE_GENERIC_TYPE entry = subLowest(), last = subHighest();entry != null && (last == null || last != previous(entry));entry = next(entry))
|
||||
action.accept(index++, entry.value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, VALUE_BI_FROM_OBJECT_CONSUMER VSV_GENERIC_TYPE<E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
@@ -2042,7 +2196,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
public boolean matchesAny(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(Node KEY_VALUE_GENERIC_TYPE entry = subLowest(), last = subHighest();entry != null && (last == null || last != previous(entry));entry = next(entry))
|
||||
if(filter.VALUE_TEST_VALUE(entry.value)) return true;
|
||||
if(filter.test(entry.value)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -2050,7 +2204,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
public boolean matchesNone(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(Node KEY_VALUE_GENERIC_TYPE entry = subLowest(), last = subHighest();entry != null && (last == null || last != previous(entry));entry = next(entry))
|
||||
if(filter.VALUE_TEST_VALUE(entry.value)) return false;
|
||||
if(filter.test(entry.value)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -2058,7 +2212,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
public boolean matchesAll(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(Node KEY_VALUE_GENERIC_TYPE entry = subLowest(), last = subHighest();entry != null && (last == null || last != previous(entry));entry = next(entry))
|
||||
if(!filter.VALUE_TEST_VALUE(entry.value)) return false;
|
||||
if(!filter.test(entry.value)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -2084,7 +2238,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public VALUE_TYPE reduce(VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
|
||||
public VALUE_OPTIONAL VALUE_GENERIC_TYPE reduce(VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
VALUE_TYPE state = EMPTY_VALUE;
|
||||
boolean empty = true;
|
||||
@@ -2096,15 +2250,15 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
}
|
||||
state = operator.APPLY_VALUE(state, entry.value);
|
||||
}
|
||||
return state;
|
||||
return empty ? VALUE_OPTIONAL.empty() : VALUE_OPTIONAL.GET_OPTIONAL_VALUE(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
||||
public VALUE_OPTIONAL VALUE_GENERIC_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(Node KEY_VALUE_GENERIC_TYPE entry = subLowest(), last = subHighest();entry != null && (last == null || last != previous(entry));entry = next(entry))
|
||||
if(filter.VALUE_TEST_VALUE(entry.value)) return entry.value;
|
||||
return EMPTY_VALUE;
|
||||
if(filter.test(entry.value)) return VALUE_OPTIONAL.GET_OPTIONAL_VALUE(entry.value);
|
||||
return VALUE_OPTIONAL.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -2112,7 +2266,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
Objects.requireNonNull(filter);
|
||||
int result = 0;
|
||||
for(Node KEY_VALUE_GENERIC_TYPE entry = subLowest(), last = subHighest();entry != null && (last == null || last != previous(entry));entry = next(entry))
|
||||
if(filter.VALUE_TEST_VALUE(entry.value)) result++;
|
||||
if(filter.test(entry.value)) result++;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -2379,6 +2533,14 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
action.accept(entry.value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEachIndexed(VALUE_BI_FROM_INT_CONSUMER VALUE_GENERIC_TYPE action) {
|
||||
Objects.requireNonNull(action);
|
||||
int index = 0;
|
||||
for(Node KEY_VALUE_GENERIC_TYPE entry = first;entry != null;entry = entry.next())
|
||||
action.accept(index++, entry.value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, VALUE_BI_FROM_OBJECT_CONSUMER VSV_GENERIC_TYPE<E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
@@ -2390,7 +2552,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
public boolean matchesAny(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(Node KEY_VALUE_GENERIC_TYPE entry = first;entry != null;entry = entry.next())
|
||||
if(filter.VALUE_TEST_VALUE(entry.value)) return true;
|
||||
if(filter.test(entry.value)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -2398,7 +2560,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
public boolean matchesNone(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(Node KEY_VALUE_GENERIC_TYPE entry = first;entry != null;entry = entry.next())
|
||||
if(filter.VALUE_TEST_VALUE(entry.value)) return false;
|
||||
if(filter.test(entry.value)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -2406,7 +2568,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
public boolean matchesAll(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(Node KEY_VALUE_GENERIC_TYPE entry = first;entry != null;entry = entry.next())
|
||||
if(!filter.VALUE_TEST_VALUE(entry.value)) return false;
|
||||
if(!filter.test(entry.value)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -2432,7 +2594,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public VALUE_TYPE reduce(VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
|
||||
public VALUE_OPTIONAL VALUE_GENERIC_TYPE reduce(VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
VALUE_TYPE state = EMPTY_VALUE;
|
||||
boolean empty = true;
|
||||
@@ -2444,15 +2606,15 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
}
|
||||
state = operator.APPLY_VALUE(state, entry.value);
|
||||
}
|
||||
return state;
|
||||
return empty ? VALUE_OPTIONAL.empty() : VALUE_OPTIONAL.GET_OPTIONAL_VALUE(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
||||
public VALUE_OPTIONAL VALUE_GENERIC_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(Node KEY_VALUE_GENERIC_TYPE entry = first;entry != null;entry = entry.next())
|
||||
if(filter.VALUE_TEST_VALUE(entry.value)) return entry.value;
|
||||
return EMPTY_VALUE;
|
||||
if(filter.test(entry.value)) return VALUE_OPTIONAL.GET_OPTIONAL_VALUE(entry.value);
|
||||
return VALUE_OPTIONAL.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -2460,7 +2622,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
Objects.requireNonNull(filter);
|
||||
int result = 0;
|
||||
for(Node KEY_VALUE_GENERIC_TYPE entry = first;entry != null;entry = entry.next())
|
||||
if(filter.VALUE_TEST_VALUE(entry.value)) result++;
|
||||
if(filter.test(entry.value)) result++;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -2536,6 +2698,14 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
action.accept(new BasicEntryKV_BRACES(entry.key, entry.value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEachIndexed(IntObjectConsumer<MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
|
||||
Objects.requireNonNull(action);
|
||||
int index = 0;
|
||||
for(Node KEY_VALUE_GENERIC_TYPE entry = first;entry != null;entry = entry.next())
|
||||
action.accept(index++, new BasicEntryKV_BRACES(entry.key, entry.value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, ObjectObjectConsumer<E, MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
|
||||
Objects.requireNonNull(action);
|
||||
@@ -2544,37 +2714,37 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matchesAny(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
public boolean matchesAny(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return false;
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE subEntry = new BasicEntryKV_BRACES();
|
||||
for(Node KEY_VALUE_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) {
|
||||
subEntry.set(entry.key, entry.value);
|
||||
if(filter.getBoolean(subEntry)) return true;
|
||||
if(filter.test(subEntry)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matchesNone(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
public boolean matchesNone(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return true;
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE subEntry = new BasicEntryKV_BRACES();
|
||||
for(Node KEY_VALUE_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) {
|
||||
subEntry.set(entry.key, entry.value);
|
||||
if(filter.getBoolean(subEntry)) return false;
|
||||
if(filter.test(subEntry)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matchesAll(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
public boolean matchesAll(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return true;
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE subEntry = new BasicEntryKV_BRACES();
|
||||
for(Node KEY_VALUE_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) {
|
||||
subEntry.set(entry.key, entry.value);
|
||||
if(!filter.getBoolean(subEntry)) return false;
|
||||
if(!filter.test(subEntry)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -2590,7 +2760,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE reduce(ObjectObjectUnaryOperator<MAP.Entry KEY_VALUE_GENERIC_TYPE, MAP.Entry KEY_VALUE_GENERIC_TYPE> operator) {
|
||||
public Optional<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;
|
||||
@@ -2602,30 +2772,30 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
}
|
||||
state = operator.apply(state, new BasicEntryKV_BRACES(entry.key, entry.value));
|
||||
}
|
||||
return state;
|
||||
return empty ? Optional.empty() : Optional.ofNullable(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
public Optional<MAP.Entry KEY_VALUE_GENERIC_TYPE> findFirst(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return null;
|
||||
if(size() <= 0) return Optional.empty();
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE subEntry = new BasicEntryKV_BRACES();
|
||||
for(Node KEY_VALUE_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) {
|
||||
subEntry.set(entry.key, entry.value);
|
||||
if(filter.getBoolean(subEntry)) return subEntry;
|
||||
if(filter.test(subEntry)) return Optional.ofNullable(subEntry);
|
||||
}
|
||||
return null;
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
public int count(Predicate<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return 0;
|
||||
int result = 0;
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE subEntry = new BasicEntryKV_BRACES();
|
||||
for(Node KEY_VALUE_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) {
|
||||
subEntry.set(entry.key, entry.value);
|
||||
if(filter.getBoolean(subEntry)) result++;
|
||||
if(filter.test(subEntry)) result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
+162
-6
@@ -10,36 +10,72 @@ import java.util.function.BiConsumer;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
#if VALUE_BOOLEAN && JDK_FUNCTION
|
||||
import java.util.function.PREDICATE;
|
||||
#endif
|
||||
|
||||
#if TYPE_OBJECT
|
||||
#if AVL_TREE_MAP_FEATURE || RB_TREE_MAP_FEATURE
|
||||
import java.util.Comparator;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_COLLECTION;
|
||||
import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
|
||||
#if !VALUE_BOOLEAN || !JDK_FUNCTION
|
||||
import speiger.src.collections.PACKAGE.functions.function.FUNCTION;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||
#if !TYPE_OBJECT && !TYPE_BOOLEAN
|
||||
#if !TYPE_OBJECT && !TYPE_BOOLEAN && SORTED_MAP_FEATURE
|
||||
#if AVL_TREE_MAP_FEATURE || RB_TREE_MAP_FEATURE
|
||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
#endif
|
||||
#endif
|
||||
#if !TYPE_BOOLEAN
|
||||
#if LINKED_CUSTOM_MAP_FEATURE
|
||||
import speiger.src.collections.PACKAGE.maps.impl.customHash.LINKED_CUSTOM_HASH_MAP;
|
||||
#endif
|
||||
#if CUSTOM_MAP_FEATURE
|
||||
import speiger.src.collections.PACKAGE.maps.impl.customHash.CUSTOM_HASH_MAP;
|
||||
#endif
|
||||
#if LINKED_MAP_FEATURE
|
||||
import speiger.src.collections.PACKAGE.maps.impl.hash.LINKED_HASH_MAP;
|
||||
#endif
|
||||
#if MAP_FEATURE
|
||||
import speiger.src.collections.PACKAGE.maps.impl.hash.HASH_MAP;
|
||||
#endif
|
||||
#if IMMUTABLE_MAP_FEATURE
|
||||
import speiger.src.collections.PACKAGE.maps.impl.immutable.IMMUTABLE_HASH_MAP;
|
||||
#endif
|
||||
#if AVL_TREE_MAP_FEATURE
|
||||
import speiger.src.collections.PACKAGE.maps.impl.tree.AVL_TREE_MAP;
|
||||
#endif
|
||||
#if RB_TREE_MAP_FEATURE
|
||||
import speiger.src.collections.PACKAGE.maps.impl.tree.RB_TREE_MAP;
|
||||
#endif
|
||||
#if ARRAY_MAP_FEATURE
|
||||
import speiger.src.collections.PACKAGE.maps.impl.misc.ARRAY_MAP;
|
||||
#endif
|
||||
#if CONCURRENT_MAP_FEATURE
|
||||
import speiger.src.collections.PACKAGE.maps.impl.concurrent.CONCURRENT_HASH_MAP;
|
||||
#endif
|
||||
#if TYPE_OBJECT
|
||||
#if ENUM_MAP_FEATURE
|
||||
import speiger.src.collections.PACKAGE.maps.impl.misc.ENUM_MAP;
|
||||
#endif
|
||||
#if LINKED_ENUM_MAP_FEATURE
|
||||
import speiger.src.collections.PACKAGE.maps.impl.misc.LINKED_ENUM_MAP;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
import speiger.src.collections.objects.collections.ObjectIterable;
|
||||
#if CUSTOM_MAP_FEATURE || LINKED_CUSTOM_MAP_FEATURE
|
||||
import speiger.src.collections.PACKAGE.utils.STRATEGY;
|
||||
#endif
|
||||
#if MAPS_FEATURE
|
||||
import speiger.src.collections.PACKAGE.utils.maps.MAPS;
|
||||
#endif
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.sets.SET;
|
||||
#if !SAME_TYPE
|
||||
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_UNARY_OPERATOR;
|
||||
@@ -102,6 +138,26 @@ public interface MAP KEY_VALUE_GENERIC_TYPE extends Map<CLASS_TYPE, CLASS_VALUE_
|
||||
*/
|
||||
public VALUE_TYPE put(KEY_TYPE key, VALUE_TYPE value);
|
||||
|
||||
/**
|
||||
* A Helper method that allows to put int a MAP.Entry into a map.
|
||||
* @param entry then Entry that should be inserted.
|
||||
* @return the last present value or default return value.
|
||||
*/
|
||||
public default VALUE_TYPE put(Entry KEY_VALUE_GENERIC_TYPE entry) {
|
||||
return put(entry.ENTRY_KEY(), entry.ENTRY_VALUE());
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT || !VALUE_OBJECT
|
||||
/**
|
||||
* A Helper method that allows to put int a Map.Entry into a map.
|
||||
* @param entry then Entry that should be inserted.
|
||||
* @return the last present value or default return value.
|
||||
*/
|
||||
public default CLASS_VALUE_TYPE put(Map.Entry<CLASS_TYPE, CLASS_VALUE_TYPE> entry) {
|
||||
return put(OBJ_TO_KEY(entry.getKey()), OBJ_TO_VALUE(entry.getValue()));
|
||||
}
|
||||
|
||||
#endif
|
||||
/**
|
||||
* Type Specific array method to bulk add elements into a map without creating a wrapper and increasing performances
|
||||
* @param keys the keys that should be added
|
||||
@@ -326,21 +382,26 @@ public interface MAP KEY_VALUE_GENERIC_TYPE extends Map<CLASS_TYPE, CLASS_VALUE_
|
||||
public void REPLACE_VALUES(UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction);
|
||||
/**
|
||||
* A Type Specific compute method to reduce boxing/unboxing
|
||||
* If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null".
|
||||
* A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it.
|
||||
* @param key the key that should be computed
|
||||
* @param mappingFunction the operator that should generate the value
|
||||
* @return the result of the computation
|
||||
*/
|
||||
public VALUE_TYPE COMPUTE(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction);
|
||||
/**
|
||||
* A Type Specific compute method to reduce boxing/unboxing
|
||||
* A Type Specific computeIfAbsent method to reduce boxing/unboxing
|
||||
* If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null".
|
||||
* A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it.
|
||||
* @param key the key that should be computed
|
||||
* @param mappingFunction the operator that should generate the value if not present
|
||||
* @return the result of the computed value or present value
|
||||
*/
|
||||
public VALUE_TYPE COMPUTE_IF_ABSENT(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction);
|
||||
|
||||
/**
|
||||
* A Supplier based computeIfAbsent function to fill the most used usecase of this function
|
||||
* If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null".
|
||||
* A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it.
|
||||
* @param key the key that should be computed
|
||||
* @param valueProvider the value if not present
|
||||
* @return the result of the computed value or present value
|
||||
@@ -348,14 +409,57 @@ public interface MAP KEY_VALUE_GENERIC_TYPE extends Map<CLASS_TYPE, CLASS_VALUE_
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENT(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider);
|
||||
/**
|
||||
* A Type Specific compute method to reduce boxing/unboxing
|
||||
* If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null".
|
||||
* A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it.
|
||||
* @param key the key that should be computed
|
||||
* @param mappingFunction the operator that should generate the value if present
|
||||
* @return the result of the default return value or present value
|
||||
* @note if not present then compute is not executed
|
||||
*/
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction);
|
||||
#if !VALUE_OBJECT
|
||||
/**
|
||||
* A Type Specific compute method to reduce boxing/unboxing
|
||||
* If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null".
|
||||
* A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it.
|
||||
* @param key the key that should be computed
|
||||
* @param mappingFunction the operator that should generate the value
|
||||
* @return the result of the computation
|
||||
*/
|
||||
public VALUE_TYPE COMPUTENonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction);
|
||||
/**
|
||||
* A Type Specific computeIfAbsent method to reduce boxing/unboxing
|
||||
* If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null".
|
||||
* A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it.
|
||||
* @param key the key that should be computed
|
||||
* @param mappingFunction the operator that should generate the value if not present
|
||||
* @return the result of the computed value or present value
|
||||
*/
|
||||
public VALUE_TYPE COMPUTE_IF_ABSENTNonDefault(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction);
|
||||
/**
|
||||
* A Supplier based computeIfAbsent function to fill the most used usecase of this function
|
||||
* If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null".
|
||||
* A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it.
|
||||
* @param key the key that should be computed
|
||||
* @param valueProvider the value if not present
|
||||
* @return the result of the computed value or present value
|
||||
*/
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENTNonDefault(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider);
|
||||
/**
|
||||
* A Type Specific compute method to reduce boxing/unboxing
|
||||
* If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null".
|
||||
* A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it.
|
||||
* @param key the key that should be computed
|
||||
* @param mappingFunction the operator that should generate the value if present
|
||||
* @return the result of the default return value or present value
|
||||
* @note if not present then compute is not executed
|
||||
*/
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENTNonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction);
|
||||
#endif
|
||||
/**
|
||||
* A Type Specific merge method to reduce boxing/unboxing
|
||||
* If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null".
|
||||
* A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it.
|
||||
* @param key the key that should be be searched for
|
||||
* @param value the value that should be merged with
|
||||
* @param mappingFunction the operator that should generate the new Value
|
||||
@@ -365,6 +469,8 @@ public interface MAP KEY_VALUE_GENERIC_TYPE extends Map<CLASS_TYPE, CLASS_VALUE_
|
||||
public VALUE_TYPE MERGE(KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction);
|
||||
/**
|
||||
* A Bulk method for merging Maps.
|
||||
* If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null".
|
||||
* A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it.
|
||||
* @param m the entries that should be bulk added
|
||||
* @param mappingFunction the operator that should generate the new Value
|
||||
* @note if the result matches the default return value then the key is removed from the map
|
||||
@@ -384,13 +490,19 @@ public interface MAP KEY_VALUE_GENERIC_TYPE extends Map<CLASS_TYPE, CLASS_VALUE_
|
||||
return VALUE_TO_OBJ(replace(OBJ_TO_KEY(key), OBJ_TO_VALUE(value)));
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public default VALUE_TYPE APPLY(KEY_TYPE key) {
|
||||
return GET_VALUE(key);
|
||||
}
|
||||
/**
|
||||
* A Type Specific get method to reduce boxing/unboxing
|
||||
* @param key the key that is searched for
|
||||
* @return the searched value or default return value
|
||||
*/
|
||||
@Override
|
||||
public VALUE_TYPE GET_VALUE(KEY_TYPE key);
|
||||
|
||||
#if !TYPE_OBJECT || !VALUE_OBJECT
|
||||
/**
|
||||
* A Type Specific getOrDefault method to reduce boxing/unboxing
|
||||
* @param key the key that is searched for
|
||||
@@ -485,7 +597,7 @@ public interface MAP KEY_VALUE_GENERIC_TYPE extends Map<CLASS_TYPE, CLASS_VALUE_
|
||||
*/
|
||||
public ObjectSet<Entry KEY_VALUE_GENERIC_TYPE> ENTRY_SET();
|
||||
|
||||
#if !TYPE_BOOLEAN
|
||||
#if MAPS_FEATURE
|
||||
/**
|
||||
* Creates a Wrapped Map that is Synchronized
|
||||
* @return a new Map that is synchronized
|
||||
@@ -638,6 +750,7 @@ public interface MAP KEY_VALUE_GENERIC_TYPE extends Map<CLASS_TYPE, CLASS_VALUE_
|
||||
}
|
||||
|
||||
#endif
|
||||
#if MAP_FEATURE
|
||||
/**
|
||||
* Helper function to unify code
|
||||
* @Type(T)
|
||||
@@ -711,6 +824,8 @@ public interface MAP KEY_VALUE_GENERIC_TYPE extends Map<CLASS_TYPE, CLASS_VALUE_
|
||||
return new HASH_MAPKV_BRACES(map);
|
||||
}
|
||||
|
||||
#endif
|
||||
#if LINKED_MAP_FEATURE
|
||||
/**
|
||||
* Helper function to unify code
|
||||
* @Type(T)
|
||||
@@ -784,6 +899,8 @@ public interface MAP KEY_VALUE_GENERIC_TYPE extends Map<CLASS_TYPE, CLASS_VALUE_
|
||||
return new IMMUTABLE_HASH_MAPKV_BRACES(map);
|
||||
}
|
||||
|
||||
#endif
|
||||
#if IMMUTABLE_MAP_FEATURE
|
||||
/**
|
||||
* Helper function to unify code
|
||||
* @param keys the keys that should be inserted
|
||||
@@ -836,7 +953,9 @@ public interface MAP KEY_VALUE_GENERIC_TYPE extends Map<CLASS_TYPE, CLASS_VALUE_
|
||||
return new IMMUTABLE_HASH_MAPKV_BRACES(map);
|
||||
}
|
||||
|
||||
#endif
|
||||
#if TYPE_OBJECT
|
||||
#if ENUM_MAP_FEATURE
|
||||
/**
|
||||
* Helper function to unify code
|
||||
* @param keyType the EnumClass that should be used
|
||||
@@ -904,6 +1023,8 @@ public interface MAP KEY_VALUE_GENERIC_TYPE extends Map<CLASS_TYPE, CLASS_VALUE_
|
||||
return new ENUM_MAPKV_BRACES(map);
|
||||
}
|
||||
|
||||
#endif
|
||||
#if LINKED_ENUM_MAP_FEATURE
|
||||
/**
|
||||
* Helper function to unify code
|
||||
* @param keyType the EnumClass that should be used
|
||||
@@ -970,7 +1091,10 @@ public interface MAP KEY_VALUE_GENERIC_TYPE extends Map<CLASS_TYPE, CLASS_VALUE_
|
||||
public GENERIC_KEY_ENUM_VALUE_BRACES LINKED_ENUM_MAP KEY_VALUE_GENERIC_TYPE linkedEnumMap(MAP KEY_VALUE_GENERIC_TYPE map) {
|
||||
return new LINKED_ENUM_MAPKV_BRACES(map);
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
#if CUSTOM_MAP_FEATURE
|
||||
/**
|
||||
* Helper function to unify code
|
||||
* @param strategy the Hash Controller
|
||||
@@ -1050,6 +1174,8 @@ public interface MAP KEY_VALUE_GENERIC_TYPE extends Map<CLASS_TYPE, CLASS_VALUE_
|
||||
return new CUSTOM_HASH_MAPKV_BRACES(map, strategy);
|
||||
}
|
||||
|
||||
#endif
|
||||
#if LINKED_CUSTOM_MAP_FEATURE
|
||||
/**
|
||||
* Helper function to unify code
|
||||
* @param strategy the Hash Controller
|
||||
@@ -1129,6 +1255,8 @@ public interface MAP KEY_VALUE_GENERIC_TYPE extends Map<CLASS_TYPE, CLASS_VALUE_
|
||||
return new LINKED_CUSTOM_HASH_MAPKV_BRACES(map, strategy);
|
||||
}
|
||||
|
||||
#endif
|
||||
#if ARRAY_MAP_FEATURE
|
||||
/**
|
||||
* Helper function to unify code
|
||||
* @Type(T)
|
||||
@@ -1202,7 +1330,8 @@ public interface MAP KEY_VALUE_GENERIC_TYPE extends Map<CLASS_TYPE, CLASS_VALUE_
|
||||
return new ARRAY_MAPKV_BRACES(map);
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
#if RB_TREE_MAP_FEATURE
|
||||
/**
|
||||
* Helper function to unify code
|
||||
* @Type(T)
|
||||
@@ -1280,6 +1409,8 @@ public interface MAP KEY_VALUE_GENERIC_TYPE extends Map<CLASS_TYPE, CLASS_VALUE_
|
||||
return new RB_TREE_MAPKV_BRACES(map, comp);
|
||||
}
|
||||
|
||||
#endif
|
||||
#if AVL_TREE_MAP_FEATURE
|
||||
/**
|
||||
* Helper function to unify code
|
||||
* @Type(T)
|
||||
@@ -1356,6 +1487,7 @@ public interface MAP KEY_VALUE_GENERIC_TYPE extends Map<CLASS_TYPE, CLASS_VALUE_
|
||||
public GENERIC_KEY_VALUE_BRACES AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE avlTreeMap(Map<? extends CLASS_TYPE, ? extends CLASS_VALUE_TYPE> map, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
return new AVL_TREE_MAPKV_BRACES(map, comp);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1434,7 +1566,11 @@ public interface MAP KEY_VALUE_GENERIC_TYPE extends Map<CLASS_TYPE, CLASS_VALUE_
|
||||
* @return self
|
||||
*/
|
||||
public BuilderCache KEY_VALUE_GENERIC_TYPE putAll(MAP KEY_VALUE_GENERIC_TYPE map) {
|
||||
#if MAPS_FEATURE
|
||||
return putAll(MAPS.fastIterable(map));
|
||||
#else
|
||||
return putAll(map.ENTRY_SET());
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1463,11 +1599,14 @@ public interface MAP KEY_VALUE_GENERIC_TYPE extends Map<CLASS_TYPE, CLASS_VALUE_
|
||||
return this;
|
||||
}
|
||||
|
||||
#if MAP_FEATURE || LINKED_MAP_FEATURE || CUSTOM_MAP_FEATURE || LINKED_CUSTOM_MAP_FEATURE || AVL_TREE_MAP_FEATURE || RB_TREE_MAP_FEATURE || CONCURRENT_MAP_FEATURE
|
||||
private <E extends MAP KEY_VALUE_GENERIC_TYPE> E putElements(E e){
|
||||
e.putAll(keys, values, 0, size);
|
||||
return e;
|
||||
}
|
||||
|
||||
#endif
|
||||
#if MAP_FEATURE
|
||||
/**
|
||||
* Builds the Keys and Values into a Hash Map
|
||||
* @return a HASH_MAP
|
||||
@@ -1476,6 +1615,8 @@ public interface MAP KEY_VALUE_GENERIC_TYPE extends Map<CLASS_TYPE, CLASS_VALUE_
|
||||
return putElements(new HASH_MAPKV_BRACES(size));
|
||||
}
|
||||
|
||||
#endif
|
||||
#if LINKED_MAP_FEATURE
|
||||
/**
|
||||
* Builds the Keys and Values into a Linked Hash Map
|
||||
* @return a LINKED_HASH_MAP
|
||||
@@ -1484,6 +1625,8 @@ public interface MAP KEY_VALUE_GENERIC_TYPE extends Map<CLASS_TYPE, CLASS_VALUE_
|
||||
return putElements(new LINKED_HASH_MAPKV_BRACES(size));
|
||||
}
|
||||
|
||||
#endif
|
||||
#if IMMUTABLE_MAP_FEATURE
|
||||
/**
|
||||
* Builds the Keys and Values into a Immutable Hash Map
|
||||
* @return a IMMUTABLE_HASH_MAP
|
||||
@@ -1492,6 +1635,8 @@ public interface MAP KEY_VALUE_GENERIC_TYPE extends Map<CLASS_TYPE, CLASS_VALUE_
|
||||
return new IMMUTABLE_HASH_MAPKV_BRACES(Arrays.copyOf(keys, size), Arrays.copyOf(values, size));
|
||||
}
|
||||
|
||||
#endif
|
||||
#if CUSTOM_MAP_FEATURE
|
||||
/**
|
||||
* Builds the Keys and Values into a Custom Hash Map
|
||||
* @param strategy the that controls the keys and values
|
||||
@@ -1501,6 +1646,8 @@ public interface MAP KEY_VALUE_GENERIC_TYPE extends Map<CLASS_TYPE, CLASS_VALUE_
|
||||
return putElements(new CUSTOM_HASH_MAPKV_BRACES(size, strategy));
|
||||
}
|
||||
|
||||
#endif
|
||||
#if LINKED_CUSTOM_MAP_FEATURE
|
||||
/**
|
||||
* Builds the Keys and Values into a Linked Custom Hash Map
|
||||
* @param strategy the that controls the keys and values
|
||||
@@ -1510,6 +1657,8 @@ public interface MAP KEY_VALUE_GENERIC_TYPE extends Map<CLASS_TYPE, CLASS_VALUE_
|
||||
return putElements(new LINKED_CUSTOM_HASH_MAPKV_BRACES(size, strategy));
|
||||
}
|
||||
|
||||
#endif
|
||||
#if CONCURRENT_MAP_FEATURE
|
||||
/**
|
||||
* Builds the Keys and Values into a Concurrent Hash Map
|
||||
* @return a CONCURRENT_HASH_MAP
|
||||
@@ -1518,6 +1667,8 @@ public interface MAP KEY_VALUE_GENERIC_TYPE extends Map<CLASS_TYPE, CLASS_VALUE_
|
||||
return putElements(new CONCURRENT_HASH_MAPKV_BRACES(size));
|
||||
}
|
||||
|
||||
#endif
|
||||
#if ARRAY_MAP_FEATURE
|
||||
/**
|
||||
* Builds the Keys and Values into a Array Map
|
||||
* @return a ARRAY_MAP
|
||||
@@ -1526,6 +1677,8 @@ public interface MAP KEY_VALUE_GENERIC_TYPE extends Map<CLASS_TYPE, CLASS_VALUE_
|
||||
return new ARRAY_MAPKV_BRACES(keys, values, size);
|
||||
}
|
||||
|
||||
#endif
|
||||
#if RB_TREE_MAP_FEATURE
|
||||
/**
|
||||
* Builds the Keys and Values into a RedBlack TreeMap
|
||||
* @return a RB_TREE_MAP
|
||||
@@ -1543,6 +1696,8 @@ public interface MAP KEY_VALUE_GENERIC_TYPE extends Map<CLASS_TYPE, CLASS_VALUE_
|
||||
return putElements(new RB_TREE_MAPKV_BRACES(comp));
|
||||
}
|
||||
|
||||
#endif
|
||||
#if AVL_TREE_MAP_FEATURE
|
||||
/**
|
||||
* Builds the Keys and Values into a AVL TreeMap
|
||||
* @return a AVL_TREE_MAP
|
||||
@@ -1559,6 +1714,7 @@ public interface MAP KEY_VALUE_GENERIC_TYPE extends Map<CLASS_TYPE, CLASS_VALUE_
|
||||
public AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE avlTreeMap(COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
return putElements(new AVL_TREE_MAPKV_BRACES(comp));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
}
|
||||
+5
@@ -2,7 +2,9 @@ package speiger.src.collections.PACKAGE.maps.interfaces;
|
||||
|
||||
import java.util.NavigableMap;
|
||||
import speiger.src.collections.PACKAGE.sets.NAVIGABLE_SET;
|
||||
#if MAPS_FEATURE
|
||||
import speiger.src.collections.PACKAGE.utils.maps.MAPS;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* A Type Specific Navigable Map interface with a couple helper methods
|
||||
@@ -37,6 +39,8 @@ public interface NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE extends SORTED_MAP KEY_VAL
|
||||
/** @return a Type Specific Navigable Key Set */
|
||||
@Override
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE keySet();
|
||||
|
||||
#if MAPS_FEATURE
|
||||
/**
|
||||
* Creates a Wrapped NavigableMap that is Synchronized
|
||||
* @return a new NavigableMap that is synchronized
|
||||
@@ -59,6 +63,7 @@ public interface NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE extends SORTED_MAP KEY_VAL
|
||||
*/
|
||||
public default NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE unmodifiable() { return MAPS.unmodifiable(this); }
|
||||
|
||||
#endif
|
||||
#if !TYPE_OBJECT
|
||||
/**
|
||||
* A Type Specific SubMap method to reduce boxing/unboxing
|
||||
|
||||
+72
@@ -1,6 +1,15 @@
|
||||
package speiger.src.collections.PACKAGE.maps.interfaces;
|
||||
|
||||
#if JAVA_VERSION>=21
|
||||
import java.util.Map;
|
||||
import java.util.SequencedMap;
|
||||
|
||||
#endif
|
||||
#if MAPS_FEATURE
|
||||
import speiger.src.collections.PACKAGE.utils.maps.MAPS;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.maps.abstracts.ABSTRACT_MAP;
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ORDERED_COLLECTION;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.sets.ORDERED_SET;
|
||||
#endif
|
||||
@@ -15,7 +24,11 @@ import speiger.src.collections.objects.sets.ObjectOrderedSet;
|
||||
* @Type(T)
|
||||
* @ValueType(V)
|
||||
*/
|
||||
#if JAVA_VERSION>=21
|
||||
public interface ORDERED_MAP KEY_VALUE_GENERIC_TYPE extends MAP KEY_VALUE_GENERIC_TYPE, SequencedMap<CLASS_TYPE, CLASS_VALUE_TYPE>
|
||||
#else
|
||||
public interface ORDERED_MAP KEY_VALUE_GENERIC_TYPE extends MAP KEY_VALUE_GENERIC_TYPE
|
||||
#endif
|
||||
{
|
||||
/**
|
||||
* A customized put method that allows you to insert into the first index.
|
||||
@@ -35,6 +48,26 @@ public interface ORDERED_MAP KEY_VALUE_GENERIC_TYPE extends MAP KEY_VALUE_GENERI
|
||||
*/
|
||||
public VALUE_TYPE putAndMoveToLast(KEY_TYPE key, VALUE_TYPE value);
|
||||
|
||||
/**
|
||||
* A alternative to putAndMoveToFirst.
|
||||
* This method simply puts an entry at the first spot of the Map but only if the entry is missing.
|
||||
* @param key the key that should be inserted
|
||||
* @param value the value that should be inserted
|
||||
* @return the previous present or default return value
|
||||
* @see java.util.Map#put(Object, Object)
|
||||
*/
|
||||
public VALUE_TYPE putFirst(KEY_TYPE key, VALUE_TYPE value);
|
||||
|
||||
/**
|
||||
* A alternative to putAndMoveToLast.
|
||||
* This method simply puts an entry at the last spot of the Map but only if the entry is missing.
|
||||
* @param key the key that should be inserted
|
||||
* @param value the value that should be inserted
|
||||
* @return the previous present or default return value
|
||||
* @see java.util.Map#put(Object, Object)
|
||||
*/
|
||||
public VALUE_TYPE putLast(KEY_TYPE key, VALUE_TYPE value);
|
||||
|
||||
/**
|
||||
* A specific move method to move a given key/value to the first index.
|
||||
* @param key that should be moved to the first index
|
||||
@@ -95,13 +128,35 @@ public interface ORDERED_MAP KEY_VALUE_GENERIC_TYPE extends MAP KEY_VALUE_GENERI
|
||||
*/
|
||||
public VALUE_TYPE LAST_ENTRY_VALUE();
|
||||
|
||||
@Java21
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE firstEntry();
|
||||
@Java21
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE lastEntry();
|
||||
@Java21
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollFirstEntry();
|
||||
@Java21
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollLastEntry();
|
||||
@Override
|
||||
public ORDERED_MAP KEY_VALUE_GENERIC_TYPE copy();
|
||||
@Override
|
||||
public ORDERED_SET KEY_GENERIC_TYPE keySet();
|
||||
@Override
|
||||
public VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE values();
|
||||
@Override
|
||||
public ObjectOrderedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> ENTRY_SET();
|
||||
@Java21
|
||||
public default ORDERED_MAP KEY_VALUE_GENERIC_TYPE reversed() { return new ABSTRACT_MAP.REVERSED_ORDERED_MAPKV_BRACES(this); }
|
||||
|
||||
#if JAVA_VERSION>=21
|
||||
@Override
|
||||
default ORDERED_SET KEY_GENERIC_TYPE sequencedKeySet() { return keySet(); }
|
||||
@Override
|
||||
default VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE sequencedValues() { return values(); }
|
||||
@Override
|
||||
default ObjectOrderedSet<Map.Entry<CLASS_TYPE, CLASS_VALUE_TYPE>> sequencedEntrySet() { return (ObjectOrderedSet<Map.Entry<CLASS_TYPE, CLASS_VALUE_TYPE>>)(Object)ENTRY_SET(); }
|
||||
|
||||
#endif
|
||||
#if MAPS_FEATURE
|
||||
/**
|
||||
* Creates a Wrapped SortedMap that is Synchronized
|
||||
* @return a new SortedMap that is synchronized
|
||||
@@ -127,6 +182,23 @@ public interface ORDERED_MAP KEY_VALUE_GENERIC_TYPE extends MAP KEY_VALUE_GENERI
|
||||
@Override
|
||||
public default ORDERED_MAP KEY_VALUE_GENERIC_TYPE unmodifiable() { return MAPS.unmodifiable(this); }
|
||||
|
||||
#endif
|
||||
#if JAVA_VERSION>=21
|
||||
#if !SAME_TYPE || !TYPE_OBJECT
|
||||
@Override
|
||||
@Deprecated
|
||||
public default CLASS_VALUE_TYPE putFirst(CLASS_TYPE k, CLASS_VALUE_TYPE v) {
|
||||
return putFirst(OBJ_TO_KEY(k), OBJ_TO_VALUE(v));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public default CLASS_VALUE_TYPE putLast(CLASS_TYPE k, CLASS_VALUE_TYPE v) {
|
||||
return putLast(OBJ_TO_KEY(k), OBJ_TO_VALUE(v));
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
/**
|
||||
* Fast Ordered Entry Set that allows for a faster Entry Iterator by recycling the Entry Object and just exchanging 1 internal value
|
||||
* @Type(T)
|
||||
|
||||
+4
@@ -10,7 +10,9 @@ import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_COLLECTION;
|
||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.sets.SORTED_SET;
|
||||
#if MAPS_FEATURE
|
||||
import speiger.src.collections.PACKAGE.utils.maps.MAPS;
|
||||
#endif
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.objects.sets.ObjectSortedSet;
|
||||
#endif
|
||||
@@ -37,6 +39,7 @@ public interface SORTED_MAP KEY_VALUE_GENERIC_TYPE extends SortedMap<CLASS_TYPE,
|
||||
@Override
|
||||
public VALUE_COLLECTION VALUE_GENERIC_TYPE values();
|
||||
|
||||
#if MAPS_FEATURE
|
||||
/**
|
||||
* Creates a Wrapped SortedMap that is Synchronized
|
||||
* @return a new SortedMap that is synchronized
|
||||
@@ -59,6 +62,7 @@ public interface SORTED_MAP KEY_VALUE_GENERIC_TYPE extends SortedMap<CLASS_TYPE,
|
||||
*/
|
||||
public default SORTED_MAP KEY_VALUE_GENERIC_TYPE unmodifiable() { return MAPS.unmodifiable(this); }
|
||||
|
||||
#endif
|
||||
#if !TYPE_OBJECT
|
||||
/**
|
||||
* A Type Specific SubMap method to reduce boxing/unboxing
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
package speiger.src.collections.PACKAGE.misc.pairs;
|
||||
|
||||
#if IMMUTABLE_PAIR
|
||||
import speiger.src.collections.PACKAGE.misc.pairs.impl.IMMUTABLE_PAIR;
|
||||
#endif
|
||||
#if MUTABLE_PAIR
|
||||
import speiger.src.collections.PACKAGE.misc.pairs.impl.MUTABLE_PAIR;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Key Value Pair Interface that allows to reduce boxing/unboxing.
|
||||
* @Type(T)
|
||||
@@ -9,6 +14,7 @@ import speiger.src.collections.PACKAGE.misc.pairs.impl.MUTABLE_PAIR;
|
||||
*/
|
||||
public interface PAIR KEY_VALUE_GENERIC_TYPE
|
||||
{
|
||||
#if IMMUTABLE_PAIR
|
||||
/**
|
||||
* Empty Reference for Immutable Pairs
|
||||
*/
|
||||
@@ -68,6 +74,8 @@ public interface PAIR KEY_VALUE_GENERIC_TYPE
|
||||
return new IMMUTABLE_PAIRKV_BRACES(pair.ENTRY_KEY(), pair.ENTRY_VALUE());
|
||||
}
|
||||
|
||||
#endif
|
||||
#if MUTABLE_PAIR
|
||||
/**
|
||||
* @Type(T)
|
||||
* @ValueType(V)
|
||||
@@ -118,6 +126,7 @@ public interface PAIR KEY_VALUE_GENERIC_TYPE
|
||||
return new MUTABLE_PAIRKV_BRACES(pair.ENTRY_KEY(), pair.ENTRY_VALUE());
|
||||
}
|
||||
|
||||
#endif
|
||||
/**
|
||||
* Sets the Key of the Pair.
|
||||
* @param key the key that should be set.
|
||||
|
||||
+89
-10
@@ -7,15 +7,35 @@ import java.util.function.Consumer;
|
||||
import java.util.function.BiFunction;
|
||||
#endif
|
||||
import java.util.Objects;
|
||||
#if JDK_TYPE
|
||||
import java.util.OPTIONAL;
|
||||
#if SPLIT_ITERATOR_FEATURE && STREAM_FEATURE
|
||||
#if !TYPE_OBJECT
|
||||
import java.util.stream.JAVA_STREAM;
|
||||
#else
|
||||
import java.util.stream.Stream;
|
||||
import java.util.stream.Collector;
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
import java.util.NoSuchElementException;
|
||||
#if JDK_FUNCTION
|
||||
import java.util.function.PREDICATE;
|
||||
#endif
|
||||
|
||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
#if !JDK_TYPE
|
||||
import speiger.src.collections.PACKAGE.functions.OPTIONAL;
|
||||
#endif
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
#endif
|
||||
import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
|
||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||
#if !JDK_FUNCTION
|
||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||
import speiger.src.collections.utils.ITrimmable;
|
||||
|
||||
@@ -93,6 +113,47 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEUE K
|
||||
this(MIN_CAPACITY);
|
||||
}
|
||||
|
||||
#if JDK_TYPE && SPLIT_ITERATOR_FEATURE && STREAM_FEATURE
|
||||
#if TYPE_OBJECT
|
||||
/**
|
||||
* Creates a Collector for a ArrayFIFOQueue
|
||||
* @Type(T)
|
||||
* @return a collector
|
||||
*/
|
||||
public static <T> Collector<T, ARRAY_FIFO_QUEUE<T>, ARRAY_FIFO_QUEUE<T>> toQueue() {
|
||||
return Collector.of(ARRAY_FIFO_QUEUE::new, ARRAY_FIFO_QUEUE::enqueue, ARRAY_FIFO_QUEUE::merge);
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects a Stream to a ArrayFIFOQueue
|
||||
* @Type(T)
|
||||
* @return a queue with the contents of the Stream
|
||||
*/
|
||||
public static <T> ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE toQueue(Stream<T> stream) {
|
||||
return stream.collect(ARRAY_FIFO_QUEUE::new, ARRAY_FIFO_QUEUE::enqueue, ARRAY_FIFO_QUEUE::merge);
|
||||
}
|
||||
|
||||
private ARRAY_FIFO_QUEUE<T> merge(ARRAY_FIFO_QUEUE<T> a) {
|
||||
enqueueAll(a.toArray((T[])new Object[a.size()]));
|
||||
return this;
|
||||
}
|
||||
|
||||
#else
|
||||
/**
|
||||
* Collects a Stream to a ArrayFIFOQueue
|
||||
* @return a queue with the contents of the Stream
|
||||
*/
|
||||
public static ARRAY_FIFO_QUEUE toQueue(JAVA_STREAM stream) {
|
||||
return stream.collect(ARRAY_FIFO_QUEUE::new, ARRAY_FIFO_QUEUE::enqueue, ARRAY_FIFO_QUEUE::merge);
|
||||
}
|
||||
|
||||
private ARRAY_FIFO_QUEUE merge(ARRAY_FIFO_QUEUE a) {
|
||||
enqueueAll(a.TO_ARRAY());
|
||||
return this;
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
@Override
|
||||
public ITERATOR KEY_GENERIC_TYPE iterator() {
|
||||
return new Iter();
|
||||
@@ -162,6 +223,15 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEUE K
|
||||
return index >= array.length ? array[index-array.length] : array[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(KEY_TYPE e) {
|
||||
if(first == last) return false;
|
||||
for(int i = 0,m=size();i<m;i++) {
|
||||
if(e == array[(first + i) % array.length]) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeFirst(KEY_TYPE e) {
|
||||
if(first == last) return false;
|
||||
@@ -257,6 +327,15 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEUE K
|
||||
clearAndTrim(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
|
||||
Objects.requireNonNull(action);
|
||||
if(first == last) return;
|
||||
for(int i = 0,m=size();i<m;i++)
|
||||
action.accept(i, array[(first + i) % array.length]);
|
||||
clearAndTrim(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
@@ -270,7 +349,7 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEUE K
|
||||
public boolean matchesAny(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(int i = 0,m=size();i<m;i++) {
|
||||
if(filter.TEST_VALUE(array[(first + i) % array.length])) return true;
|
||||
if(filter.test(array[(first + i) % array.length])) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -279,7 +358,7 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEUE K
|
||||
public boolean matchesNone(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(int i = 0,m=size();i<m;i++) {
|
||||
if(filter.TEST_VALUE(array[(first + i) % array.length])) return false;
|
||||
if(filter.test(array[(first + i) % array.length])) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -288,23 +367,23 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEUE K
|
||||
public boolean matchesAll(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(int i = 0,m=size();i<m;i++) {
|
||||
if(!filter.TEST_VALUE(array[(first + i) % array.length])) return false;
|
||||
if(!filter.test(array[(first + i) % array.length])) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
public OPTIONAL KEY_GENERIC_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(int i = 0,m=size();i<m;i++) {
|
||||
int index = (first + i) % array.length;
|
||||
if(filter.TEST_VALUE(array[index])) {
|
||||
if(filter.test(array[index])) {
|
||||
KEY_TYPE data = array[index];
|
||||
removeIndex(index);
|
||||
return data;
|
||||
return OPTIONAL.GET_OPTIONAL(data);
|
||||
}
|
||||
}
|
||||
return EMPTY_VALUE;
|
||||
return OPTIONAL.empty();
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@@ -331,7 +410,7 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEUE K
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
public OPTIONAL KEY_GENERIC_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = EMPTY_VALUE;
|
||||
boolean empty = true;
|
||||
@@ -343,7 +422,7 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEUE K
|
||||
}
|
||||
state = operator.APPLY_VALUE(state, array[(first + i) % array.length]);
|
||||
}
|
||||
return state;
|
||||
return empty ? OPTIONAL.empty() : OPTIONAL.GET_OPTIONAL(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -351,7 +430,7 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEUE K
|
||||
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++;
|
||||
if(filter.test(array[(first + i) % array.length])) result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
+90
-10
@@ -8,15 +8,35 @@ import java.util.function.Consumer;
|
||||
import java.util.function.BiFunction;
|
||||
#endif
|
||||
import java.util.Objects;
|
||||
#if JDK_TYPE
|
||||
import java.util.OPTIONAL;
|
||||
#if SPLIT_ITERATOR_FEATURE && STREAM_FEATURE
|
||||
#if !TYPE_OBJECT
|
||||
import java.util.stream.JAVA_STREAM;
|
||||
#else
|
||||
import java.util.stream.Stream;
|
||||
import java.util.stream.Collector;
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#if JDK_FUNCTION
|
||||
import java.util.function.PREDICATE;
|
||||
#endif
|
||||
|
||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
#if !JDK_TYPE
|
||||
import speiger.src.collections.PACKAGE.functions.OPTIONAL;
|
||||
#endif
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
#endif
|
||||
import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
|
||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||
#if !JDK_FUNCTION
|
||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||
import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
||||
import speiger.src.collections.utils.SanityChecks;
|
||||
@@ -184,7 +204,47 @@ public class ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUE
|
||||
queue.size = size;
|
||||
return queue;
|
||||
}
|
||||
#if JDK_TYPE && SPLIT_ITERATOR_FEATURE && STREAM_FEATURE
|
||||
#if TYPE_OBJECT
|
||||
/**
|
||||
* Creates a Collector for a ArrayPriorityQueue
|
||||
* @Type(T)
|
||||
* @return a collector
|
||||
*/
|
||||
public static <T> Collector<T, ARRAY_PRIORITY_QUEUE<T>, ARRAY_PRIORITY_QUEUE<T>> toQueue() {
|
||||
return Collector.of(ARRAY_PRIORITY_QUEUE::new, ARRAY_PRIORITY_QUEUE::enqueue, ARRAY_PRIORITY_QUEUE::merge);
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects a Stream to a ArrayPriorityQueue
|
||||
* @Type(T)
|
||||
* @return a queue with the contents of the Stream
|
||||
*/
|
||||
public static <T> ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE toQueue(Stream<T> stream) {
|
||||
return stream.collect(ARRAY_PRIORITY_QUEUE::new, ARRAY_PRIORITY_QUEUE::enqueue, ARRAY_PRIORITY_QUEUE::merge);
|
||||
}
|
||||
|
||||
private ARRAY_PRIORITY_QUEUE<T> merge(ARRAY_PRIORITY_QUEUE<T> a) {
|
||||
enqueueAll(a.toArray((T[])new Object[a.size()]));
|
||||
return this;
|
||||
}
|
||||
|
||||
#else
|
||||
/**
|
||||
* Collects a Stream to a ArrayPriorityQueue
|
||||
* @return a queue with the contents of the Stream
|
||||
*/
|
||||
public static ARRAY_PRIORITY_QUEUE toQueue(JAVA_STREAM stream) {
|
||||
return stream.collect(ARRAY_PRIORITY_QUEUE::new, ARRAY_PRIORITY_QUEUE::enqueue, ARRAY_PRIORITY_QUEUE::merge);
|
||||
}
|
||||
|
||||
private ARRAY_PRIORITY_QUEUE merge(ARRAY_PRIORITY_QUEUE a) {
|
||||
enqueueAll(a.TO_ARRAY());
|
||||
return this;
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
@Override
|
||||
public void enqueue(KEY_TYPE e) {
|
||||
if(size == array.length) array = Arrays.copyOf(array, (int)Math.max(Math.min((long)array.length + (long)(array.length >> 1), (long)SanityChecks.MAX_ARRAY_SIZE), size+1));
|
||||
@@ -209,12 +269,26 @@ public class ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUE
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE first() {
|
||||
if(isEmpty()) throw new NoSuchElementException();
|
||||
if(firstIndex == -1) findFirstIndex();
|
||||
return array[firstIndex];
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE peek(int index) {
|
||||
if(index < 0 || index >= size) throw new NoSuchElementException();
|
||||
return array[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(KEY_TYPE e) {
|
||||
for(int i = 0;i<size;i++)
|
||||
if(KEY_EQUALS(e, array[i])) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeFirst(KEY_TYPE e) {
|
||||
for(int i = 0;i<size;i++)
|
||||
@@ -263,6 +337,12 @@ public class ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUE
|
||||
for(int i = 0,m=size;i<m;i++) action.accept(dequeue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
|
||||
Objects.requireNonNull(action);
|
||||
for(int i = 0,m=size;i<m;i++) action.accept(i, dequeue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
@@ -273,7 +353,7 @@ public class ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUE
|
||||
public boolean matchesAny(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(int i = 0;i<size;i++) {
|
||||
if(filter.TEST_VALUE(array[i])) return true;
|
||||
if(filter.test(array[i])) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -282,7 +362,7 @@ public class ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUE
|
||||
public boolean matchesNone(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(int i = 0;i<size;i++) {
|
||||
if(filter.TEST_VALUE(array[i])) return false;
|
||||
if(filter.test(array[i])) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -291,7 +371,7 @@ public class ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUE
|
||||
public boolean matchesAll(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(int i = 0;i<size;i++) {
|
||||
if(!filter.TEST_VALUE(array[i])) return false;
|
||||
if(!filter.test(array[i])) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -320,7 +400,7 @@ public class ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUE
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
public OPTIONAL KEY_GENERIC_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = EMPTY_VALUE;
|
||||
boolean empty = true;
|
||||
@@ -332,20 +412,20 @@ public class ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUE
|
||||
}
|
||||
state = operator.APPLY_VALUE(state, array[i]);
|
||||
}
|
||||
return state;
|
||||
return empty ? OPTIONAL.empty() : OPTIONAL.GET_OPTIONAL(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
public OPTIONAL KEY_GENERIC_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(int i = 0;i<size;i++) {
|
||||
if(filter.TEST_VALUE(array[i])) {
|
||||
if(filter.test(array[i])) {
|
||||
KEY_TYPE data = array[i];
|
||||
removeIndex(i);
|
||||
return data;
|
||||
return OPTIONAL.GET_OPTIONAL(data);
|
||||
}
|
||||
}
|
||||
return EMPTY_VALUE;
|
||||
return OPTIONAL.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -353,7 +433,7 @@ public class ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUE
|
||||
Objects.requireNonNull(filter);
|
||||
int result = 0;
|
||||
for(int i = 0;i<size;i++) {
|
||||
if(filter.TEST_VALUE(array[i])) result++;
|
||||
if(filter.test(array[i])) result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
+84
-10
@@ -8,15 +8,35 @@ import java.util.function.Consumer;
|
||||
import java.util.function.BiFunction;
|
||||
#endif
|
||||
import java.util.Objects;
|
||||
#if JDK_TYPE
|
||||
import java.util.OPTIONAL;
|
||||
#if SPLIT_ITERATOR_FEATURE && STREAM_FEATURE
|
||||
#if !TYPE_OBJECT
|
||||
import java.util.stream.JAVA_STREAM;
|
||||
#else
|
||||
import java.util.stream.Stream;
|
||||
import java.util.stream.Collector;
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#if JDK_FUNCTION
|
||||
import java.util.function.PREDICATE;
|
||||
#endif
|
||||
|
||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
#if !JDK_TYPE
|
||||
import speiger.src.collections.PACKAGE.functions.OPTIONAL;
|
||||
#endif
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
#endif
|
||||
import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
|
||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||
#if !JDK_FUNCTION
|
||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||
import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
||||
import speiger.src.collections.utils.SanityChecks;
|
||||
@@ -187,6 +207,47 @@ public class HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEU
|
||||
return queue;
|
||||
}
|
||||
|
||||
#if JDK_TYPE && SPLIT_ITERATOR_FEATURE && STREAM_FEATURE
|
||||
#if TYPE_OBJECT
|
||||
/**
|
||||
* Creates a Collector for a ArrayFIFOQueue
|
||||
* @Type(T)
|
||||
* @return a collector
|
||||
*/
|
||||
public static <T> Collector<T, HEAP_PRIORITY_QUEUE<T>, HEAP_PRIORITY_QUEUE<T>> toQueue() {
|
||||
return Collector.of(HEAP_PRIORITY_QUEUE::new, HEAP_PRIORITY_QUEUE::enqueue, HEAP_PRIORITY_QUEUE::merge);
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects a Stream to a ArrayFIFOQueue
|
||||
* @Type(T)
|
||||
* @return a queue with the contents of the Stream
|
||||
*/
|
||||
public static <T> HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE toQueue(Stream<T> stream) {
|
||||
return stream.collect(HEAP_PRIORITY_QUEUE::new, HEAP_PRIORITY_QUEUE::enqueue, HEAP_PRIORITY_QUEUE::merge);
|
||||
}
|
||||
|
||||
private HEAP_PRIORITY_QUEUE<T> merge(HEAP_PRIORITY_QUEUE<T> a) {
|
||||
enqueueAll(a.toArray((T[])new Object[a.size()]));
|
||||
return this;
|
||||
}
|
||||
|
||||
#else
|
||||
/**
|
||||
* Collects a Stream to a ArrayFIFOQueue
|
||||
* @return a queue with the contents of the Stream
|
||||
*/
|
||||
public static HEAP_PRIORITY_QUEUE toQueue(JAVA_STREAM stream) {
|
||||
return stream.collect(HEAP_PRIORITY_QUEUE::new, HEAP_PRIORITY_QUEUE::enqueue, HEAP_PRIORITY_QUEUE::merge);
|
||||
}
|
||||
|
||||
private HEAP_PRIORITY_QUEUE merge(HEAP_PRIORITY_QUEUE a) {
|
||||
enqueueAll(a.TO_ARRAY());
|
||||
return this;
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
@Override
|
||||
public int size() {
|
||||
return size;
|
||||
@@ -230,6 +291,13 @@ public class HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEU
|
||||
return array[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(KEY_TYPE e) {
|
||||
for(int i = 0;i<size;i++)
|
||||
if(KEY_EQUALS(e, array[i])) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeFirst(KEY_TYPE e) {
|
||||
for(int i = 0;i<size;i++)
|
||||
@@ -250,6 +318,12 @@ public class HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEU
|
||||
for(int i = 0,m=size;i<m;i++) action.accept(dequeue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
|
||||
Objects.requireNonNull(action);
|
||||
for(int i = 0,m=size;i<m;i++) action.accept(i, dequeue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
@@ -260,7 +334,7 @@ public class HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEU
|
||||
public boolean matchesAny(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(int i = 0;i<size;i++) {
|
||||
if(filter.TEST_VALUE(array[i])) return true;
|
||||
if(filter.test(array[i])) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -269,7 +343,7 @@ public class HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEU
|
||||
public boolean matchesNone(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(int i = 0;i<size;i++) {
|
||||
if(filter.TEST_VALUE(array[i])) return false;
|
||||
if(filter.test(array[i])) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -278,7 +352,7 @@ public class HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEU
|
||||
public boolean matchesAll(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(int i = 0;i<size;i++) {
|
||||
if(!filter.TEST_VALUE(array[i])) return false;
|
||||
if(!filter.test(array[i])) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -307,7 +381,7 @@ public class HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEU
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
public OPTIONAL KEY_GENERIC_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = EMPTY_VALUE;
|
||||
boolean empty = true;
|
||||
@@ -319,20 +393,20 @@ public class HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEU
|
||||
}
|
||||
state = operator.APPLY_VALUE(state, array[i]);
|
||||
}
|
||||
return state;
|
||||
return empty ? OPTIONAL.empty() : OPTIONAL.GET_OPTIONAL(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
public OPTIONAL KEY_GENERIC_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(int i = 0;i<size;i++) {
|
||||
if(filter.TEST_VALUE(array[i])) {
|
||||
if(filter.test(array[i])) {
|
||||
KEY_TYPE data = array[i];
|
||||
removeIndex(i);
|
||||
return data;
|
||||
return OPTIONAL.GET_OPTIONAL(data);
|
||||
}
|
||||
}
|
||||
return EMPTY_VALUE;
|
||||
return OPTIONAL.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -340,7 +414,7 @@ public class HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEU
|
||||
Objects.requireNonNull(filter);
|
||||
int result = 0;
|
||||
for(int i = 0;i<size;i++) {
|
||||
if(filter.TEST_VALUE(array[i])) result++;
|
||||
if(filter.test(array[i])) result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
+4
@@ -6,7 +6,9 @@ import java.util.Iterator;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
#if QUEUES_FEATURE
|
||||
import speiger.src.collections.PACKAGE.utils.PRIORITY_QUEUES;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* A Type Speciifc PriorityDeque or Dequeue interface to allow implementations like FIFO queues.
|
||||
@@ -81,6 +83,7 @@ public interface PRIORITY_DEQUEUE KEY_GENERIC_TYPE extends PRIORITY_QUEUE KEY_GE
|
||||
*/
|
||||
public default KEY_TYPE last() { return peek(size()-1); }
|
||||
|
||||
#if QUEUES_FEATURE
|
||||
/**
|
||||
* Creates a Wrapped PriorityDequeue that is Synchronized
|
||||
* @return a new PriorityDequeue that is synchronized
|
||||
@@ -96,6 +99,7 @@ public interface PRIORITY_DEQUEUE KEY_GENERIC_TYPE extends PRIORITY_QUEUE KEY_GE
|
||||
*/
|
||||
public default PRIORITY_DEQUEUE KEY_GENERIC_TYPE synchronizeQueue(Object mutex) { return PRIORITY_QUEUES.synchronize(this, mutex); }
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public PRIORITY_DEQUEUE KEY_GENERIC_TYPE copy();
|
||||
}
|
||||
+16
-5
@@ -4,15 +4,16 @@ package speiger.src.collections.PACKAGE.queues;
|
||||
import java.util.Comparator;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
import speiger.src.collections.ints.functions.function.Int2ObjectFunction;
|
||||
import java.util.function.IntFunction;
|
||||
#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;
|
||||
#if QUEUES_FEATURE
|
||||
import speiger.src.collections.PACKAGE.utils.PRIORITY_QUEUES;
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
@@ -110,6 +111,13 @@ public interface PRIORITY_QUEUE KEY_GENERIC_TYPE extends ITERABLE KEY_GENERIC_TY
|
||||
*/
|
||||
public default KEY_TYPE first() { return peek(0); }
|
||||
|
||||
/**
|
||||
* Method to find out if a element is part of the queue
|
||||
* @param e the element that is searched for
|
||||
* @return true if the element is in the queue
|
||||
*/
|
||||
public boolean contains(KEY_TYPE e);
|
||||
|
||||
/**
|
||||
* Removes the first found element in the queue
|
||||
* @param e the element that should be removed
|
||||
@@ -147,8 +155,9 @@ public interface PRIORITY_QUEUE KEY_GENERIC_TYPE extends ITERABLE KEY_GENERIC_TY
|
||||
* @return draining iterator of the PriorityQueue
|
||||
*/
|
||||
public ITERATOR KEY_GENERIC_TYPE iterator();
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#if QUEUES_FEATURE
|
||||
/**
|
||||
* Creates a Wrapped PriorityQueue that is Synchronized
|
||||
* @return a new PriorityQueue that is synchronized
|
||||
@@ -164,6 +173,7 @@ public interface PRIORITY_QUEUE KEY_GENERIC_TYPE extends ITERABLE KEY_GENERIC_TY
|
||||
*/
|
||||
public default PRIORITY_QUEUE KEY_GENERIC_TYPE synchronizeQueue(Object mutex) { return PRIORITY_QUEUES.synchronize(this, mutex); }
|
||||
|
||||
#endif
|
||||
/**
|
||||
* A method to drop the contents of the Queue without clearing the queue
|
||||
* @Type(E)
|
||||
@@ -182,11 +192,12 @@ public interface PRIORITY_QUEUE KEY_GENERIC_TYPE extends ITERABLE KEY_GENERIC_TY
|
||||
/**
|
||||
* A Helper function that simplifies the process of creating a new Array.
|
||||
* @param action the array creation function
|
||||
* @param <E> the returning arrayType
|
||||
* @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()));
|
||||
default <E> E[] TO_ARRAY(IntFunction<E[]> action) {
|
||||
return TO_ARRAY(action.apply(size()));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
+130
-18
@@ -10,16 +10,36 @@ import java.util.function.BiFunction;
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Objects;
|
||||
#if JDK_TYPE
|
||||
import java.util.OPTIONAL;
|
||||
#if !TYPE_OBJECT
|
||||
import java.util.stream.JAVA_STREAM;
|
||||
#else
|
||||
import java.util.stream.Stream;
|
||||
import java.util.stream.Collector;
|
||||
#endif
|
||||
#endif
|
||||
#if JDK_FUNCTION
|
||||
import java.util.function.PREDICATE;
|
||||
#endif
|
||||
|
||||
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;
|
||||
#endif
|
||||
#if !JDK_TYPE
|
||||
import speiger.src.collections.PACKAGE.functions.OPTIONAL;
|
||||
#endif
|
||||
import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
|
||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||
#if !JDK_FUNCTION
|
||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||
#endif
|
||||
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.objects.utils.ObjectArrays;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.utils.ITERATORS;
|
||||
#endif
|
||||
@@ -200,6 +220,42 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
while(iterator.hasNext()) add(iterator.NEXT());
|
||||
}
|
||||
|
||||
#if JDK_TYPE && SPLIT_ITERATOR_FEATURE && STREAM_FEATURE
|
||||
#if TYPE_OBJECT
|
||||
/**
|
||||
* Creates a Collector for a AVLTreeSet
|
||||
* @Type(T)
|
||||
* @return a collector
|
||||
*/
|
||||
public static <T> Collector<T, AVL_TREE_SET<T>, AVL_TREE_SET<T>> toSet() {
|
||||
return Collector.of(AVL_TREE_SET::new, AVL_TREE_SET::add, AVL_TREE_SET::merge);
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects a Stream to a AVLTreeSet
|
||||
* @Type(T)
|
||||
* @return a set with the contents of the Stream
|
||||
*/
|
||||
public static <T> AVL_TREE_SET KEY_GENERIC_TYPE toSet(Stream<T> stream) {
|
||||
return stream.collect(AVL_TREE_SET::new, AVL_TREE_SET::add, AVL_TREE_SET::merge);
|
||||
}
|
||||
|
||||
private AVL_TREE_SET<T> merge(AVL_TREE_SET<T> a) {
|
||||
addAll(a);
|
||||
return this;
|
||||
}
|
||||
|
||||
#else
|
||||
/**
|
||||
* Collects a Stream to a AVLTreeSet
|
||||
* @return a set with the contents of the Stream
|
||||
*/
|
||||
public static AVL_TREE_SET toSet(JAVA_STREAM stream) {
|
||||
return stream.collect(AVL_TREE_SET::new, AVL_TREE_SET::add, AVL_TREE_SET::addAll);
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public void setDefaultMaxValue(KEY_TYPE value) { defaultMaxNotFound = value; }
|
||||
@@ -353,6 +409,15 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
|
||||
Objects.requireNonNull(action);
|
||||
int index = 0;
|
||||
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) {
|
||||
action.accept(index++, entry.key);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
@@ -364,7 +429,7 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
public boolean matchesAny(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) {
|
||||
if(filter.TEST_VALUE(entry.key)) return true;
|
||||
if(filter.test(entry.key)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -373,7 +438,7 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
public boolean matchesNone(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) {
|
||||
if(filter.TEST_VALUE(entry.key)) return false;
|
||||
if(filter.test(entry.key)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -382,18 +447,18 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
public boolean matchesAll(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) {
|
||||
if(!filter.TEST_VALUE(entry.key)) return false;
|
||||
if(!filter.test(entry.key)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
public OPTIONAL KEY_GENERIC_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) {
|
||||
if(filter.TEST_VALUE(entry.key)) return entry.key;
|
||||
if(filter.test(entry.key)) return OPTIONAL.GET_OPTIONAL(entry.key);
|
||||
}
|
||||
return EMPTY_VALUE;
|
||||
return OPTIONAL.empty();
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@@ -420,7 +485,7 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
public OPTIONAL KEY_GENERIC_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = EMPTY_VALUE;
|
||||
boolean empty = true;
|
||||
@@ -432,7 +497,7 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
}
|
||||
state = operator.APPLY_VALUE(state, entry.key);
|
||||
}
|
||||
return state;
|
||||
return empty ? OPTIONAL.empty() : OPTIONAL.GET_OPTIONAL(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -440,7 +505,7 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
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++;
|
||||
if(filter.test(entry.key)) result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -635,6 +700,44 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
tree = null;
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public KEY_TYPE[] TO_ARRAY(KEY_TYPE[] a) {
|
||||
if(a == null || a.length < size()) a = new KEY_TYPE[size()];
|
||||
int index = 0;
|
||||
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) {
|
||||
a[index++] = entry.key;
|
||||
}
|
||||
if (a.length > size) a[size] = EMPTY_KEY_VALUE;
|
||||
return a;
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
@Deprecated
|
||||
public Object[] toArray() {
|
||||
if(isEmpty()) return ObjectArrays.EMPTY_ARRAY;
|
||||
Object[] obj = new Object[size()];
|
||||
int index = 0;
|
||||
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) {
|
||||
obj[index++] = KEY_TO_OBJ(entry.key);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Primitive
|
||||
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());
|
||||
int index = 0;
|
||||
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) {
|
||||
a[index++] = (E)KEY_TO_OBJ(entry.key);
|
||||
}
|
||||
if (a.length > size) a[size] = null;
|
||||
return a;
|
||||
}
|
||||
|
||||
public AVL_TREE_SET KEY_GENERIC_TYPE copy() {
|
||||
AVL_TREE_SET KEY_GENERIC_TYPE set = new AVL_TREE_SETBRACES();
|
||||
set.size = size;
|
||||
@@ -1192,6 +1295,15 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
|
||||
Objects.requireNonNull(action);
|
||||
int index = 0;
|
||||
for(Entry KEY_GENERIC_TYPE entry = start();entry != null && inRange(entry.key);entry = next(entry)) {
|
||||
action.accept(index++, entry.key);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
@@ -1203,7 +1315,7 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
public boolean matchesAny(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(Entry KEY_GENERIC_TYPE entry = start();entry != null && inRange(entry.key);entry = next(entry)) {
|
||||
if(filter.TEST_VALUE(entry.key)) return true;
|
||||
if(filter.test(entry.key)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -1212,7 +1324,7 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
public boolean matchesNone(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(Entry KEY_GENERIC_TYPE entry = start();entry != null && inRange(entry.key);entry = next(entry)) {
|
||||
if(filter.TEST_VALUE(entry.key)) return false;
|
||||
if(filter.test(entry.key)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -1221,7 +1333,7 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
public boolean matchesAll(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(Entry KEY_GENERIC_TYPE entry = start();entry != null && inRange(entry.key);entry = next(entry)) {
|
||||
if(!filter.TEST_VALUE(entry.key)) return false;
|
||||
if(!filter.test(entry.key)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -1250,7 +1362,7 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
public OPTIONAL KEY_GENERIC_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = EMPTY_VALUE;
|
||||
boolean empty = true;
|
||||
@@ -1262,16 +1374,16 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
}
|
||||
state = operator.APPLY_VALUE(state, entry.key);
|
||||
}
|
||||
return state;
|
||||
return empty ? OPTIONAL.empty() : OPTIONAL.GET_OPTIONAL(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
public OPTIONAL KEY_GENERIC_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(Entry KEY_GENERIC_TYPE entry = start();entry != null && inRange(entry.key);entry = next(entry)) {
|
||||
if(filter.TEST_VALUE(entry.key)) return entry.key;
|
||||
if(filter.test(entry.key)) return OPTIONAL.GET_OPTIONAL(entry.key);
|
||||
}
|
||||
return EMPTY_VALUE;
|
||||
return OPTIONAL.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1279,7 +1391,7 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
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++;
|
||||
if(filter.test(entry.key)) result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import speiger.src.collections.PACKAGE.collections.ABSTRACT_COLLECTION;
|
||||
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
|
||||
/**
|
||||
@@ -47,4 +48,105 @@ public abstract class ABSTRACT_SET KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
#if ORDERED_SET_FEATURE
|
||||
public static class REVERSED_ORDERED_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE implements ORDERED_SET KEY_GENERIC_TYPE {
|
||||
protected ORDERED_SET KEY_GENERIC_TYPE set;
|
||||
|
||||
public REVERSED_ORDERED_SET(ORDERED_SET KEY_GENERIC_TYPE set) {
|
||||
this.set = set;
|
||||
}
|
||||
|
||||
@Override
|
||||
public REVERSED_ORDERED_SET KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public BI_ITERATOR KEY_GENERIC_TYPE iterator(KEY_TYPE fromElement) {
|
||||
return set.iterator(fromElement);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BI_ITERATOR KEY_GENERIC_TYPE iterator() {
|
||||
return set.reverseIterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BI_ITERATOR KEY_GENERIC_TYPE reverseIterator() {
|
||||
return set.iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addFirst(KEY_TYPE o) {
|
||||
set.addLast(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addLast(KEY_TYPE o) {
|
||||
set.addFirst(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
#if !TYPE_OBJECT
|
||||
public boolean remove(KEY_TYPE o) {
|
||||
#else
|
||||
public boolean remove(Object o) {
|
||||
#endif
|
||||
return set.remove(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean add(KEY_TYPE o) {
|
||||
return set.add(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAndMoveToFirst(KEY_TYPE o) {
|
||||
return set.addAndMoveToLast(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAndMoveToLast(KEY_TYPE o) {
|
||||
return set.addAndMoveToFirst(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean moveToFirst(KEY_TYPE o) {
|
||||
return set.moveToLast(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean moveToLast(KEY_TYPE o) {
|
||||
return set.moveToFirst(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE GET_FIRST_KEY() {
|
||||
return set.GET_LAST_KEY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE REMOVE_FIRST_KEY() {
|
||||
return set.REMOVE_LAST_KEY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE GET_LAST_KEY() {
|
||||
return set.GET_FIRST_KEY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE REMOVE_LAST_KEY() {
|
||||
return set.REMOVE_FIRST_KEY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ORDERED_SET KEY_GENERIC_TYPE reversed() {
|
||||
return set;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return set.size();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
+146
-30
@@ -8,16 +8,33 @@ import java.util.function.BiFunction;
|
||||
#endif
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Objects;
|
||||
#if JDK_TYPE
|
||||
import java.util.OPTIONAL;
|
||||
#if !TYPE_OBJECT
|
||||
import java.util.stream.JAVA_STREAM;
|
||||
#else
|
||||
import java.util.stream.Stream;
|
||||
import java.util.stream.Collector;
|
||||
#endif
|
||||
#endif
|
||||
import java.util.Set;
|
||||
#if PRIMITIVES
|
||||
#if JDK_FUNCTION
|
||||
import java.util.function.PREDICATE;
|
||||
#endif
|
||||
#if PRIMITIVES && !JDK_FUNCTION
|
||||
import java.util.function.JAVA_PREDICATE;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
|
||||
#if !JDK_TYPE
|
||||
import speiger.src.collections.PACKAGE.functions.OPTIONAL;
|
||||
#endif
|
||||
import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
|
||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||
#if !JDK_FUNCTION
|
||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
@@ -63,7 +80,7 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
||||
* @param array the array that should be used for set.
|
||||
*/
|
||||
public ARRAY_SET(KEY_TYPE[] array) {
|
||||
this(array, array.length);
|
||||
this(array, 0, array.length);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -77,6 +94,18 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
||||
addAll(array, length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructur using initial Array
|
||||
* @param array the array that should be used for set.
|
||||
* @param offset the starting offset of where the array should be copied from
|
||||
* @param length the amount of elements present within the array
|
||||
* @throws NegativeArraySizeException if the length is negative
|
||||
*/
|
||||
public ARRAY_SET(KEY_TYPE[] array, int offset, int length) {
|
||||
this(length);
|
||||
addAll(array, offset, length);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper constructor that allows to create a Set with exactly the same values as the provided collection.
|
||||
* @param c the elements that should be added to the set.
|
||||
@@ -120,6 +149,42 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
||||
for(ITERATOR KEY_GENERIC_TYPE iter = s.iterator();iter.hasNext();data[size++] = iter.NEXT());
|
||||
}
|
||||
|
||||
#if JDK_TYPE && SPLIT_ITERATOR_FEATURE && STREAM_FEATURE
|
||||
#if TYPE_OBJECT
|
||||
/**
|
||||
* Creates a Collector for a ArraySet
|
||||
* @Type(T)
|
||||
* @return a collector
|
||||
*/
|
||||
public static <T> Collector<T, ARRAY_SET<T>, ARRAY_SET<T>> toList() {
|
||||
return Collector.of(ARRAY_SET::new, ARRAY_SET::add, ARRAY_SET::merge);
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects a Stream to a ArraySet
|
||||
* @Type(T)
|
||||
* @return a set with the contents of the Stream
|
||||
*/
|
||||
public static <T> ARRAY_SET KEY_GENERIC_TYPE toList(Stream<T> stream) {
|
||||
return stream.collect(ARRAY_SET::new, ARRAY_SET::add, ARRAY_SET::merge);
|
||||
}
|
||||
|
||||
private ARRAY_SET<T> merge(ARRAY_SET<T> a) {
|
||||
addAll(a);
|
||||
return this;
|
||||
}
|
||||
|
||||
#else
|
||||
/**
|
||||
* Collects a Stream to a ArraySet
|
||||
* @return a set with the contents of the Stream
|
||||
*/
|
||||
public static ARRAY_SET toList(JAVA_STREAM stream) {
|
||||
return stream.collect(ARRAY_SET::new, ARRAY_SET::add, ARRAY_SET::addAll);
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
@Override
|
||||
public boolean add(KEY_TYPE o) {
|
||||
int index = findIndex(o);
|
||||
@@ -142,6 +207,25 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public void addFirst(KEY_TYPE o) {
|
||||
int index = findIndex(o);
|
||||
if(index == -1) {
|
||||
if(data.length == size) data = Arrays.copyOf(data, size == 0 ? 2 : size * 2);
|
||||
System.arraycopy(data, 0, data, 1, size++);
|
||||
data[0] = o;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addLast(KEY_TYPE o) {
|
||||
int index = findIndex(o);
|
||||
if(index == -1) {
|
||||
if(data.length == size) data = Arrays.copyOf(data, size == 0 ? 2 : size * 2);
|
||||
data[size++] = o;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAndMoveToFirst(KEY_TYPE o) {
|
||||
int index = findIndex(o);
|
||||
@@ -213,13 +297,13 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public KEY_TYPE FIRST_KEY() {
|
||||
public KEY_TYPE GET_FIRST_KEY() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return data[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE LAST_KEY() {
|
||||
public KEY_TYPE GET_LAST_KEY() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return data[size - 1];
|
||||
}
|
||||
@@ -348,7 +432,7 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public KEY_TYPE POLL_FIRST_KEY() {
|
||||
public KEY_TYPE REMOVE_FIRST_KEY() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
KEY_TYPE result = data[0];
|
||||
System.arraycopy(data, 1, data, 0, --size);
|
||||
@@ -359,7 +443,7 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE POLL_LAST_KEY() {
|
||||
public KEY_TYPE REMOVE_LAST_KEY() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
size--;
|
||||
#if TYPE_OBJECT
|
||||
@@ -391,6 +475,12 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
||||
for(int i = 0;i<size;action.accept(data[i++]));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
|
||||
Objects.requireNonNull(action);
|
||||
for(int i = 0;i<size;action.accept(i, data[i++]));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
@@ -402,7 +492,7 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
||||
public boolean matchesAny(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(int i = 0;i<size;i++) {
|
||||
if(filter.TEST_VALUE(data[i])) return true;
|
||||
if(filter.test(data[i])) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -411,7 +501,7 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
||||
public boolean matchesNone(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(int i = 0;i<size;i++) {
|
||||
if(filter.TEST_VALUE(data[i])) return false;
|
||||
if(filter.test(data[i])) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -420,18 +510,18 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
||||
public boolean matchesAll(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(int i = 0;i<size;i++) {
|
||||
if(!filter.TEST_VALUE(data[i])) return false;
|
||||
if(!filter.test(data[i])) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
public OPTIONAL KEY_GENERIC_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(int i = 0;i<size;i++) {
|
||||
if(filter.TEST_VALUE(data[i])) return data[i];
|
||||
if(filter.test(data[i])) return OPTIONAL.GET_OPTIONAL(data[i]);
|
||||
}
|
||||
return EMPTY_VALUE;
|
||||
return OPTIONAL.empty();
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@@ -458,7 +548,7 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
public OPTIONAL KEY_GENERIC_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = EMPTY_VALUE;
|
||||
boolean empty = true;
|
||||
@@ -470,7 +560,7 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
||||
}
|
||||
state = operator.APPLY_VALUE(state, data[i]);
|
||||
}
|
||||
return state;
|
||||
return empty ? OPTIONAL.empty() : OPTIONAL.GET_OPTIONAL(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -478,7 +568,7 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
||||
Objects.requireNonNull(filter);
|
||||
int result = 0;
|
||||
for(int i = 0;i<size;i++) {
|
||||
if(filter.TEST_VALUE(data[i])) result++;
|
||||
if(filter.test(data[i])) result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -499,13 +589,18 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
||||
|
||||
@Override
|
||||
public BI_ITERATOR KEY_GENERIC_TYPE iterator() {
|
||||
return new SetIterator(0);
|
||||
return new SetIterator(true, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BI_ITERATOR KEY_GENERIC_TYPE reverseIterator() {
|
||||
return new SetIterator(false, size);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BI_ITERATOR KEY_GENERIC_TYPE iterator(KEY_TYPE fromElement) {
|
||||
int index = findIndex(fromElement);
|
||||
if(index != -1) return new SetIterator(index);
|
||||
if(index != -1) return new SetIterator(true, index);
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
|
||||
@@ -539,6 +634,7 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
||||
@Override
|
||||
@Deprecated
|
||||
public Object[] toArray() {
|
||||
if(isEmpty()) return ObjectArrays.EMPTY_ARRAY;
|
||||
Object[] obj = new Object[size()];
|
||||
for(int i = 0;i<size();i++)
|
||||
obj[i] = KEY_TO_OBJ(data[i]);
|
||||
@@ -557,45 +653,57 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
||||
}
|
||||
|
||||
private class SetIterator implements LIST_ITERATOR KEY_GENERIC_TYPE {
|
||||
boolean forward;
|
||||
int index;
|
||||
int lastReturned = -1;
|
||||
|
||||
public SetIterator(int index) {
|
||||
public SetIterator(boolean forward, int index) {
|
||||
this.forward = forward;
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return index < size();
|
||||
return forward ? index < size() : index > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE NEXT() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
lastReturned = index;
|
||||
return data[index++];
|
||||
if(forward) {
|
||||
lastReturned = index;
|
||||
return data[index++];
|
||||
}
|
||||
index--;
|
||||
return data[(lastReturned = index)];
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPrevious() {
|
||||
return index > 0;
|
||||
return forward ? index > 0 : index < size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE PREVIOUS() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
--index;
|
||||
return data[(lastReturned = index)];
|
||||
if(forward) {
|
||||
index--;
|
||||
return data[(lastReturned = index)];
|
||||
}
|
||||
lastReturned = index;
|
||||
return data[index++];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int nextIndex() {
|
||||
return index;
|
||||
if(forward) return index;
|
||||
return size - index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int previousIndex() {
|
||||
return index-1;
|
||||
if(forward) return index-1;
|
||||
return (size - index)-1;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -624,15 +732,23 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
||||
@Override
|
||||
public int skip(int amount) {
|
||||
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
||||
return forward ? moveForward(amount) : moveBackwards(amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int back(int amount) {
|
||||
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
||||
return forward ? moveBackwards(amount) : moveForward(amount);
|
||||
}
|
||||
|
||||
private int moveForward(int amount) {
|
||||
int steps = Math.min(amount, size() - index);
|
||||
index += steps;
|
||||
if(steps > 0) lastReturned = Math.min(index-1, size()-1);
|
||||
return steps;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int back(int amount) {
|
||||
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
||||
private int moveBackwards(int amount) {
|
||||
int steps = Math.min(amount, index);
|
||||
index -= steps;
|
||||
if(steps > 0) lastReturned = Math.min(index, size()-1);
|
||||
|
||||
+128
-32
@@ -9,6 +9,12 @@ import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Objects;
|
||||
#if JDK_TYPE
|
||||
import java.util.OPTIONAL;
|
||||
#endif
|
||||
#if JDK_FUNCTION
|
||||
import java.util.function.PREDICATE;
|
||||
#endif
|
||||
|
||||
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||
@@ -16,11 +22,20 @@ import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
#endif
|
||||
#if !JDK_TYPE
|
||||
import speiger.src.collections.PACKAGE.functions.OPTIONAL;
|
||||
#endif
|
||||
import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
|
||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||
#if !JDK_FUNCTION
|
||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||
import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.objects.utils.ObjectArrays;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.utils.ITERATORS;
|
||||
|
||||
import speiger.src.collections.utils.HashUtil;
|
||||
@@ -249,6 +264,10 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
|
||||
@Override
|
||||
public boolean addAll(COLLECTION KEY_GENERIC_TYPE c) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void addFirst(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void addLast(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean addAndMoveToFirst(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean addAndMoveToLast(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@@ -276,22 +295,22 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE FIRST_KEY() {
|
||||
public KEY_TYPE GET_FIRST_KEY() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return keys[firstIndex];
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE POLL_FIRST_KEY() { throw new UnsupportedOperationException(); }
|
||||
public KEY_TYPE REMOVE_FIRST_KEY() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public KEY_TYPE LAST_KEY() {
|
||||
public KEY_TYPE GET_LAST_KEY() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return keys[lastIndex];
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE POLL_LAST_KEY() { throw new UnsupportedOperationException(); }
|
||||
public KEY_TYPE REMOVE_LAST_KEY() { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean remove(Object o) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@@ -323,6 +342,17 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
|
||||
Objects.requireNonNull(action);
|
||||
int count = 0;
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
action.accept(count++, keys[index]);
|
||||
index = (int)links[index];
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
@@ -338,7 +368,7 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
|
||||
Objects.requireNonNull(filter);
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
if(filter.TEST_VALUE(keys[index])) return true;
|
||||
if(filter.test(keys[index])) return true;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return false;
|
||||
@@ -349,7 +379,7 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
|
||||
Objects.requireNonNull(filter);
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
if(filter.TEST_VALUE(keys[index])) return false;
|
||||
if(filter.test(keys[index])) return false;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return true;
|
||||
@@ -360,7 +390,7 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
|
||||
Objects.requireNonNull(filter);
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
if(!filter.TEST_VALUE(keys[index])) return false;
|
||||
if(!filter.test(keys[index])) return false;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return true;
|
||||
@@ -394,7 +424,7 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
public OPTIONAL KEY_GENERIC_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = EMPTY_VALUE;
|
||||
boolean empty = true;
|
||||
@@ -407,18 +437,18 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
|
||||
else state = operator.APPLY_VALUE(state, keys[index]);
|
||||
index = (int)links[index];
|
||||
}
|
||||
return state;
|
||||
return empty ? OPTIONAL.empty() : OPTIONAL.GET_OPTIONAL(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
public OPTIONAL KEY_GENERIC_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];
|
||||
if(filter.test(keys[index])) return OPTIONAL.GET_OPTIONAL(keys[index]);
|
||||
index = (int)links[index];
|
||||
}
|
||||
return EMPTY_VALUE;
|
||||
return OPTIONAL.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -427,7 +457,7 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
|
||||
int result = 0;
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
if(filter.TEST_VALUE(keys[index])) result++;
|
||||
if(filter.test(keys[index])) result++;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return result;
|
||||
@@ -435,7 +465,12 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
|
||||
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE iterator() {
|
||||
return new SetIterator();
|
||||
return new SetIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE reverseIterator() {
|
||||
return new SetIterator(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -443,6 +478,41 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
|
||||
return new SetIterator(fromElement);
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public KEY_TYPE[] TO_ARRAY(KEY_TYPE[] a) {
|
||||
if(a == null || a.length < size()) a = new KEY_TYPE[size()];
|
||||
for(int i = 0, index = firstIndex;index != -1;i++,index = (int)links[index]) {
|
||||
a[i] = keys[index];
|
||||
}
|
||||
if (a.length > size) a[size] = EMPTY_KEY_VALUE;
|
||||
return a;
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
@Deprecated
|
||||
public Object[] toArray() {
|
||||
if(isEmpty()) return ObjectArrays.EMPTY_ARRAY;
|
||||
Object[] obj = new Object[size()];
|
||||
for(int i = 0, index = firstIndex;index != -1;i++,index = (int)links[index]) {
|
||||
obj[i] = KEY_TO_OBJ(keys[index]);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Primitive
|
||||
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());
|
||||
for(int i = 0, index = firstIndex;index != -1;i++,index = (int)links[index]) {
|
||||
a[i] = (E)KEY_TO_OBJ(keys[index]);
|
||||
}
|
||||
if (a.length > size) a[size] = null;
|
||||
return a;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMMUTABLE_HASH_SET KEY_GENERIC_TYPE copy() {
|
||||
IMMUTABLE_HASH_SET KEY_GENERIC_TYPE set = new IMMUTABLE_HASH_SETBRACES();
|
||||
@@ -466,16 +536,20 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
|
||||
}
|
||||
|
||||
private class SetIterator implements LIST_ITERATOR KEY_GENERIC_TYPE {
|
||||
boolean forward;
|
||||
int previous = -1;
|
||||
int next = -1;
|
||||
int current = -1;
|
||||
int index = 0;
|
||||
int index = -1;
|
||||
|
||||
SetIterator() {
|
||||
next = firstIndex;
|
||||
SetIterator(boolean start) {
|
||||
this.forward = start;
|
||||
if(start) next = firstIndex;
|
||||
else previous = lastIndex;
|
||||
}
|
||||
|
||||
SetIterator(KEY_TYPE from) {
|
||||
this.forward = true;
|
||||
if(KEY_EQUALS_NULL(from)) {
|
||||
if(containsNull) {
|
||||
next = (int) links[nullIndex];
|
||||
@@ -504,48 +578,60 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
|
||||
|
||||
@Override
|
||||
public int skip(int amount) {
|
||||
int result = 0;
|
||||
while(next != -1 && result != amount) {
|
||||
current = previous = next;
|
||||
next = (int)(links[current]);
|
||||
result++;
|
||||
}
|
||||
int result = forward ? moveForward(amount) : moveBackwards(amount);
|
||||
if(index >= 0) index+=result;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int back(int amount) {
|
||||
int result = forward ? moveBackwards(amount) : moveForward(amount);
|
||||
if(index >= 0) index-=result;
|
||||
return result;
|
||||
}
|
||||
|
||||
private int moveForward(int amount) {
|
||||
int result = 0;
|
||||
while(next != -1 && result != amount) {
|
||||
current = previous = next;
|
||||
next = (int)(links[current]);
|
||||
result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private int moveBackwards(int amount) {
|
||||
int result = 0;
|
||||
while(previous != -1 && result != amount) {
|
||||
current = next = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
result++;
|
||||
}
|
||||
if(index >= 0) index-=result;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return next != -1;
|
||||
return (forward ? next : previous) != -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPrevious() {
|
||||
return previous != -1;
|
||||
return (forward ? previous : next) != -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int nextIndex() {
|
||||
ensureIndexKnown();
|
||||
return index;
|
||||
if(forward) return index;
|
||||
return size - index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int previousIndex() {
|
||||
ensureIndexKnown();
|
||||
return index - 1;
|
||||
if(forward) return index-1;
|
||||
return (size - index)-1;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -554,8 +640,8 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
|
||||
@Override
|
||||
public KEY_TYPE PREVIOUS() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
current = next = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
if(forward) moveBackwards();
|
||||
else moveForwards();
|
||||
if(index >= 0) index--;
|
||||
return keys[current];
|
||||
}
|
||||
@@ -563,12 +649,22 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
|
||||
@Override
|
||||
public KEY_TYPE NEXT() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
current = previous = next;
|
||||
next = (int)(links[current]);
|
||||
if(forward) moveForwards();
|
||||
else moveBackwards();
|
||||
if(index >= 0) index++;
|
||||
return keys[current];
|
||||
}
|
||||
|
||||
private void moveBackwards() {
|
||||
current = next = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
}
|
||||
|
||||
private void moveForwards() {
|
||||
current = previous = next;
|
||||
next = (int)(links[current]);
|
||||
}
|
||||
|
||||
private void ensureIndexKnown() {
|
||||
if(index == -1) {
|
||||
if(previous == -1) {
|
||||
|
||||
+206
-34
@@ -9,19 +9,38 @@ import java.util.Objects;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
#if JDK_TYPE
|
||||
import java.util.OPTIONAL;
|
||||
#if !TYPE_OBJECT
|
||||
import java.util.stream.JAVA_STREAM;
|
||||
#else
|
||||
import java.util.stream.Stream;
|
||||
import java.util.stream.Collector;
|
||||
#endif
|
||||
#endif
|
||||
#if JDK_FUNCTION
|
||||
import java.util.function.PREDICATE;
|
||||
#endif
|
||||
|
||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
||||
#if !JDK_TYPE
|
||||
import speiger.src.collections.PACKAGE.functions.OPTIONAL;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.utils.ITERATORS;
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
#endif
|
||||
import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
|
||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||
#if !JDK_FUNCTION
|
||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||
#endif
|
||||
import speiger.src.collections.objects.utils.ObjectArrays;
|
||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||
import speiger.src.collections.PACKAGE.utils.STRATEGY;
|
||||
import speiger.src.collections.utils.HashUtil;
|
||||
@@ -228,6 +247,82 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
||||
}
|
||||
|
||||
#endif
|
||||
#if JDK_TYPE && SPLIT_ITERATOR_FEATURE && STREAM_FEATURE
|
||||
#if TYPE_OBJECT
|
||||
/**
|
||||
* Creates a Collector for a LinkedCustomHashSet
|
||||
* @Type(T)
|
||||
* @return a collector
|
||||
*/
|
||||
public static <T> Collector<T, LINKED_CUSTOM_HASH_SET<T>, LINKED_CUSTOM_HASH_SET<T>> toLinkedSet(STRATEGY KEY_SUPER_GENERIC_TYPE strategy) {
|
||||
return Collector.of(() -> new LINKED_CUSTOM_HASH_SET<>(strategy), LINKED_CUSTOM_HASH_SET::add, LINKED_CUSTOM_HASH_SET::merge);
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects a Stream to a LinkedCustomHashSet
|
||||
* @Type(T)
|
||||
* @return a set with the contents of the Stream
|
||||
*/
|
||||
public static <T> LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE toLinkedSet(Stream<T> stream, STRATEGY KEY_SUPER_GENERIC_TYPE strategy) {
|
||||
return stream.collect(() -> new LINKED_CUSTOM_HASH_SET<>(strategy), LINKED_CUSTOM_HASH_SET::add, LINKED_CUSTOM_HASH_SET::merge);
|
||||
}
|
||||
|
||||
private LINKED_CUSTOM_HASH_SET<T> merge(LINKED_CUSTOM_HASH_SET<T> a) {
|
||||
addAll(a);
|
||||
return this;
|
||||
}
|
||||
|
||||
#else
|
||||
/**
|
||||
* Collects a Stream to a LinkedCustomHashSet
|
||||
* @return a set with the contents of the Stream
|
||||
*/
|
||||
public static LINKED_CUSTOM_HASH_SET toList(JAVA_STREAM stream, STRATEGY KEY_SUPER_GENERIC_TYPE strategy) {
|
||||
return stream.collect(() -> new LINKED_CUSTOM_HASH_SET(strategy), LINKED_CUSTOM_HASH_SET::add, LINKED_CUSTOM_HASH_SET::addAll);
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
@Override
|
||||
public void addFirst(KEY_TYPE o) {
|
||||
if(strategy.equals(o, EMPTY_KEY_VALUE)) {
|
||||
if(containsNull) return;
|
||||
containsNull = true;
|
||||
onNodeAdded(nullIndex);
|
||||
moveToFirstIndex(nullIndex);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(strategy.hashCode(o)) & mask;
|
||||
while(!strategy.equals(keys[pos], EMPTY_KEY_VALUE)) {
|
||||
if(strategy.equals(keys[pos], o)) return;
|
||||
pos = ++pos & mask;
|
||||
}
|
||||
keys[pos] = o;
|
||||
onNodeAdded(pos);
|
||||
moveToFirstIndex(pos);
|
||||
}
|
||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addLast(KEY_TYPE o) {
|
||||
if(strategy.equals(o, EMPTY_KEY_VALUE)) {
|
||||
if(containsNull) return;
|
||||
containsNull = true;
|
||||
onNodeAdded(nullIndex);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(strategy.hashCode(o)) & mask;
|
||||
while(!strategy.equals(keys[pos], EMPTY_KEY_VALUE)) {
|
||||
if(strategy.equals(keys[pos], o)) return;
|
||||
pos = ++pos & mask;
|
||||
}
|
||||
keys[pos] = o;
|
||||
onNodeAdded(pos);
|
||||
}
|
||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAndMoveToFirst(KEY_TYPE o) {
|
||||
if(strategy.equals(o, EMPTY_KEY_VALUE)) {
|
||||
@@ -284,7 +379,7 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
||||
|
||||
@Override
|
||||
public boolean moveToFirst(KEY_TYPE o) {
|
||||
if(isEmpty() || strategy.equals(FIRST_KEY(), o)) return false;
|
||||
if(isEmpty() || strategy.equals(GET_FIRST_KEY(), o)) return false;
|
||||
if(strategy.equals(o, EMPTY_KEY_VALUE)) {
|
||||
if(containsNull) {
|
||||
moveToFirstIndex(nullIndex);
|
||||
@@ -306,7 +401,7 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
||||
|
||||
@Override
|
||||
public boolean moveToLast(KEY_TYPE o) {
|
||||
if(isEmpty() || strategy.equals(LAST_KEY(), o)) return false;
|
||||
if(isEmpty() || strategy.equals(GET_LAST_KEY(), o)) return false;
|
||||
if(strategy.equals(o, EMPTY_KEY_VALUE)) {
|
||||
if(containsNull) {
|
||||
moveToLastIndex(nullIndex);
|
||||
@@ -363,13 +458,13 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE FIRST_KEY() {
|
||||
public KEY_TYPE GET_FIRST_KEY() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return keys[firstIndex];
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE POLL_FIRST_KEY() {
|
||||
public KEY_TYPE REMOVE_FIRST_KEY() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
int pos = firstIndex;
|
||||
onNodeRemoved(pos);
|
||||
@@ -385,13 +480,13 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE LAST_KEY() {
|
||||
public KEY_TYPE GET_LAST_KEY() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return keys[lastIndex];
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE POLL_LAST_KEY() {
|
||||
public KEY_TYPE REMOVE_LAST_KEY() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
int pos = lastIndex;
|
||||
onNodeRemoved(pos);
|
||||
@@ -522,6 +617,41 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
||||
containsNull = false;
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public KEY_TYPE[] TO_ARRAY(KEY_TYPE[] a) {
|
||||
if(a == null || a.length < size()) a = new KEY_TYPE[size()];
|
||||
for(int i = 0, index = firstIndex;index != -1;i++,index = (int)links[index]) {
|
||||
a[i] = keys[index];
|
||||
}
|
||||
if (a.length > size) a[size] = EMPTY_KEY_VALUE;
|
||||
return a;
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
@Deprecated
|
||||
public Object[] toArray() {
|
||||
if(isEmpty()) return ObjectArrays.EMPTY_ARRAY;
|
||||
Object[] obj = new Object[size()];
|
||||
for(int i = 0, index = firstIndex;index != -1;i++,index = (int)links[index]) {
|
||||
obj[i] = KEY_TO_OBJ(keys[index]);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Primitive
|
||||
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());
|
||||
for(int i = 0, index = firstIndex;index != -1;i++,index = (int)links[index]) {
|
||||
a[i] = (E)KEY_TO_OBJ(keys[index]);
|
||||
}
|
||||
if (a.length > size) a[size] = null;
|
||||
return a;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) {
|
||||
Objects.requireNonNull(action);
|
||||
@@ -532,6 +662,17 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
|
||||
Objects.requireNonNull(action);
|
||||
int count = 0;
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
action.accept(count++, keys[index]);
|
||||
index = (int)links[index];
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
@@ -547,7 +688,7 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
||||
Objects.requireNonNull(filter);
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
if(filter.TEST_VALUE(keys[index])) return true;
|
||||
if(filter.test(keys[index])) return true;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return false;
|
||||
@@ -558,7 +699,7 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
||||
Objects.requireNonNull(filter);
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
if(filter.TEST_VALUE(keys[index])) return false;
|
||||
if(filter.test(keys[index])) return false;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return true;
|
||||
@@ -569,7 +710,7 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
||||
Objects.requireNonNull(filter);
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
if(!filter.TEST_VALUE(keys[index])) return false;
|
||||
if(!filter.test(keys[index])) return false;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return true;
|
||||
@@ -603,7 +744,7 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
public OPTIONAL KEY_GENERIC_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = EMPTY_VALUE;
|
||||
boolean empty = true;
|
||||
@@ -616,18 +757,18 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
||||
else state = operator.APPLY_VALUE(state, keys[index]);
|
||||
index = (int)links[index];
|
||||
}
|
||||
return state;
|
||||
return empty ? OPTIONAL.empty() : OPTIONAL.GET_OPTIONAL(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
public OPTIONAL KEY_GENERIC_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];
|
||||
if(filter.test(keys[index])) return OPTIONAL.GET_OPTIONAL(keys[index]);
|
||||
index = (int)links[index];
|
||||
}
|
||||
return EMPTY_VALUE;
|
||||
return OPTIONAL.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -636,7 +777,7 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
||||
int result = 0;
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
if(filter.TEST_VALUE(keys[index])) result++;
|
||||
if(filter.test(keys[index])) result++;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return result;
|
||||
@@ -644,7 +785,12 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
||||
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE iterator() {
|
||||
return new SetIterator();
|
||||
return new SetIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE reverseIterator() {
|
||||
return new SetIterator(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -669,16 +815,20 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
||||
}
|
||||
|
||||
private class SetIterator implements LIST_ITERATOR KEY_GENERIC_TYPE {
|
||||
boolean forward;
|
||||
int previous = -1;
|
||||
int next = -1;
|
||||
int current = -1;
|
||||
int index = 0;
|
||||
int index = -1;
|
||||
|
||||
SetIterator() {
|
||||
next = firstIndex;
|
||||
SetIterator(boolean start) {
|
||||
this.forward = start;
|
||||
if(start) next = firstIndex;
|
||||
else previous = lastIndex;
|
||||
}
|
||||
|
||||
SetIterator(KEY_TYPE from) {
|
||||
this.forward = true;
|
||||
if(strategy.equals(from, EMPTY_KEY_VALUE)) {
|
||||
if(containsNull) {
|
||||
next = (int) links[nullIndex];
|
||||
@@ -707,48 +857,60 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return next != -1;
|
||||
return (forward ? next : previous) != -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPrevious() {
|
||||
return previous != -1;
|
||||
return (forward ? previous : next) != -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int skip(int amount) {
|
||||
int result = 0;
|
||||
while(next != -1 && result != amount) {
|
||||
current = previous = next;
|
||||
next = (int)(links[current]);
|
||||
result++;
|
||||
}
|
||||
int result = forward ? moveForward(amount) : moveBackwards(amount);
|
||||
if(index >= 0) index+=result;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int back(int amount) {
|
||||
int result = forward ? moveBackwards(amount) : moveForward(amount);
|
||||
if(index >= 0) index-=result;
|
||||
return result;
|
||||
}
|
||||
|
||||
private int moveForward(int amount) {
|
||||
int result = 0;
|
||||
while(next != -1 && result != amount) {
|
||||
current = previous = next;
|
||||
next = (int)(links[current]);
|
||||
result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private int moveBackwards(int amount) {
|
||||
int result = 0;
|
||||
while(previous != -1 && result != amount) {
|
||||
current = next = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
result++;
|
||||
}
|
||||
if(index >= 0) index-=result;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int nextIndex() {
|
||||
ensureIndexKnown();
|
||||
return index;
|
||||
if(forward) return index;
|
||||
return size - index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int previousIndex() {
|
||||
ensureIndexKnown();
|
||||
return index - 1;
|
||||
if(forward) return index-1;
|
||||
return (size - index)-1;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -797,8 +959,8 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
||||
@Override
|
||||
public KEY_TYPE PREVIOUS() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
current = next = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
if(forward) moveBackwards();
|
||||
else moveForwards();
|
||||
if(index >= 0) index--;
|
||||
return keys[current];
|
||||
}
|
||||
@@ -806,12 +968,22 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
||||
@Override
|
||||
public KEY_TYPE NEXT() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
current = previous = next;
|
||||
next = (int)(links[current]);
|
||||
if(forward) moveForwards();
|
||||
else moveBackwards();
|
||||
if(index >= 0) index++;
|
||||
return keys[current];
|
||||
}
|
||||
|
||||
private void moveBackwards() {
|
||||
current = next = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
}
|
||||
|
||||
private void moveForwards() {
|
||||
current = previous = next;
|
||||
next = (int)(links[current]);
|
||||
}
|
||||
|
||||
private void ensureIndexKnown() {
|
||||
if(index == -1) {
|
||||
if(previous == -1) {
|
||||
|
||||
+206
-34
@@ -5,10 +5,22 @@ import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Objects;
|
||||
#if JDK_TYPE
|
||||
import java.util.OPTIONAL;
|
||||
#if !TYPE_OBJECT
|
||||
import java.util.stream.JAVA_STREAM;
|
||||
#else
|
||||
import java.util.stream.Stream;
|
||||
import java.util.stream.Collector;
|
||||
#endif
|
||||
#endif
|
||||
#if TYPE_OBJECT
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.BiFunction;
|
||||
#endif
|
||||
#if JDK_FUNCTION
|
||||
import java.util.function.PREDICATE;
|
||||
#endif
|
||||
|
||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||
#if !TYPE_OBJECT
|
||||
@@ -18,13 +30,20 @@ import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
#endif
|
||||
#if !JDK_TYPE
|
||||
import speiger.src.collections.PACKAGE.functions.OPTIONAL;
|
||||
#endif
|
||||
import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
|
||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||
#if !JDK_FUNCTION
|
||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||
#endif
|
||||
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;
|
||||
#endif
|
||||
import speiger.src.collections.objects.utils.ObjectArrays;
|
||||
import speiger.src.collections.utils.HashUtil;
|
||||
import speiger.src.collections.utils.SanityChecks;
|
||||
|
||||
@@ -199,6 +218,82 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
||||
}
|
||||
|
||||
#endif
|
||||
#if JDK_TYPE && SPLIT_ITERATOR_FEATURE && STREAM_FEATURE
|
||||
#if TYPE_OBJECT
|
||||
/**
|
||||
* Creates a Collector for a LinkedHashSet
|
||||
* @Type(T)
|
||||
* @return a collector
|
||||
*/
|
||||
public static <T> Collector<T, LINKED_HASH_SET<T>, LINKED_HASH_SET<T>> toLinkedSet() {
|
||||
return Collector.of(LINKED_HASH_SET::new, LINKED_HASH_SET::add, LINKED_HASH_SET::merge);
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects a Stream to a LinkedHashSet
|
||||
* @Type(T)
|
||||
* @return a set with the contents of the Stream
|
||||
*/
|
||||
public static <T> LINKED_HASH_SET KEY_GENERIC_TYPE toLinkedSet(Stream<T> stream) {
|
||||
return stream.collect(LINKED_HASH_SET::new, LINKED_HASH_SET::add, LINKED_HASH_SET::merge);
|
||||
}
|
||||
|
||||
private LINKED_HASH_SET<T> merge(LINKED_HASH_SET<T> a) {
|
||||
addAll(a);
|
||||
return this;
|
||||
}
|
||||
|
||||
#else
|
||||
/**
|
||||
* Collects a Stream to a LinkedHashSet
|
||||
* @return a set with the contents of the Stream
|
||||
*/
|
||||
public static LINKED_HASH_SET toLinkedSet(JAVA_STREAM stream) {
|
||||
return stream.collect(LINKED_HASH_SET::new, LINKED_HASH_SET::add, LINKED_HASH_SET::addAll);
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
@Override
|
||||
public void addFirst(KEY_TYPE o) {
|
||||
if(KEY_EQUALS_NULL(o)) {
|
||||
if(containsNull) return;
|
||||
containsNull = true;
|
||||
onNodeAdded(nullIndex);
|
||||
moveToFirstIndex(nullIndex);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(KEY_TO_HASH(o)) & mask;
|
||||
while(KEY_EQUALS_NOT_NULL(keys[pos])) {
|
||||
if(KEY_EQUALS(keys[pos], o)) return;
|
||||
pos = ++pos & mask;
|
||||
}
|
||||
keys[pos] = o;
|
||||
onNodeAdded(pos);
|
||||
moveToFirstIndex(pos);
|
||||
}
|
||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addLast(KEY_TYPE o) {
|
||||
if(KEY_EQUALS_NULL(o)) {
|
||||
if(containsNull) return;
|
||||
containsNull = true;
|
||||
onNodeAdded(nullIndex);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(KEY_TO_HASH(o)) & mask;
|
||||
while(KEY_EQUALS_NOT_NULL(keys[pos])) {
|
||||
if(KEY_EQUALS(keys[pos], o)) return;
|
||||
pos = ++pos & mask;
|
||||
}
|
||||
keys[pos] = o;
|
||||
onNodeAdded(pos);
|
||||
}
|
||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAndMoveToFirst(KEY_TYPE o) {
|
||||
if(KEY_EQUALS_NULL(o)) {
|
||||
@@ -255,7 +350,7 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
||||
|
||||
@Override
|
||||
public boolean moveToFirst(KEY_TYPE o) {
|
||||
if(isEmpty() || KEY_EQUALS(FIRST_KEY(), o)) return false;
|
||||
if(isEmpty() || KEY_EQUALS(GET_FIRST_KEY(), o)) return false;
|
||||
if(KEY_EQUALS_NULL(o)) {
|
||||
if(containsNull) {
|
||||
moveToFirstIndex(nullIndex);
|
||||
@@ -277,7 +372,7 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
||||
|
||||
@Override
|
||||
public boolean moveToLast(KEY_TYPE o) {
|
||||
if(isEmpty() || KEY_EQUALS(LAST_KEY(), o)) return false;
|
||||
if(isEmpty() || KEY_EQUALS(GET_LAST_KEY(), o)) return false;
|
||||
if(KEY_EQUALS_NULL(o)) {
|
||||
if(containsNull) {
|
||||
moveToLastIndex(nullIndex);
|
||||
@@ -334,13 +429,13 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE FIRST_KEY() {
|
||||
public KEY_TYPE GET_FIRST_KEY() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return keys[firstIndex];
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE POLL_FIRST_KEY() {
|
||||
public KEY_TYPE REMOVE_FIRST_KEY() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
int pos = firstIndex;
|
||||
onNodeRemoved(pos);
|
||||
@@ -356,13 +451,13 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE LAST_KEY() {
|
||||
public KEY_TYPE GET_LAST_KEY() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return keys[lastIndex];
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE POLL_LAST_KEY() {
|
||||
public KEY_TYPE REMOVE_LAST_KEY() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
int pos = lastIndex;
|
||||
onNodeRemoved(pos);
|
||||
@@ -377,6 +472,41 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
||||
return result;
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public KEY_TYPE[] TO_ARRAY(KEY_TYPE[] a) {
|
||||
if(a == null || a.length < size()) a = new KEY_TYPE[size()];
|
||||
for(int i = 0, index = firstIndex;index != -1;i++,index = (int)links[index]) {
|
||||
a[i] = keys[index];
|
||||
}
|
||||
if (a.length > size) a[size] = EMPTY_KEY_VALUE;
|
||||
return a;
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
@Deprecated
|
||||
public Object[] toArray() {
|
||||
if(isEmpty()) return ObjectArrays.EMPTY_ARRAY;
|
||||
Object[] obj = new Object[size()];
|
||||
for(int i = 0, index = firstIndex;index != -1;i++,index = (int)links[index]) {
|
||||
obj[i] = KEY_TO_OBJ(keys[index]);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Primitive
|
||||
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());
|
||||
for(int i = 0, index = firstIndex;index != -1;i++,index = (int)links[index]) {
|
||||
a[i] = (E)KEY_TO_OBJ(keys[index]);
|
||||
}
|
||||
if (a.length > size) a[size] = null;
|
||||
return a;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) {
|
||||
Objects.requireNonNull(action);
|
||||
@@ -387,6 +517,17 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
|
||||
Objects.requireNonNull(action);
|
||||
int count = 0;
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
action.accept(count++, keys[index]);
|
||||
index = (int)links[index];
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
@@ -402,7 +543,7 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
||||
Objects.requireNonNull(filter);
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
if(filter.TEST_VALUE(keys[index])) return true;
|
||||
if(filter.test(keys[index])) return true;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return false;
|
||||
@@ -413,7 +554,7 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
||||
Objects.requireNonNull(filter);
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
if(filter.TEST_VALUE(keys[index])) return false;
|
||||
if(filter.test(keys[index])) return false;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return true;
|
||||
@@ -424,7 +565,7 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
||||
Objects.requireNonNull(filter);
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
if(!filter.TEST_VALUE(keys[index])) return false;
|
||||
if(!filter.test(keys[index])) return false;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return true;
|
||||
@@ -458,7 +599,7 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
public OPTIONAL KEY_GENERIC_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = EMPTY_VALUE;
|
||||
boolean empty = true;
|
||||
@@ -471,18 +612,18 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
||||
else state = operator.APPLY_VALUE(state, keys[index]);
|
||||
index = (int)links[index];
|
||||
}
|
||||
return state;
|
||||
return empty ? OPTIONAL.empty() : OPTIONAL.GET_OPTIONAL(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
public OPTIONAL KEY_GENERIC_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];
|
||||
if(filter.test(keys[index])) return OPTIONAL.GET_OPTIONAL(keys[index]);
|
||||
index = (int)links[index];
|
||||
}
|
||||
return EMPTY_VALUE;
|
||||
return OPTIONAL.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -491,7 +632,7 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
||||
int result = 0;
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
if(filter.TEST_VALUE(keys[index])) result++;
|
||||
if(filter.test(keys[index])) result++;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return result;
|
||||
@@ -615,7 +756,12 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
||||
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE iterator() {
|
||||
return new SetIterator();
|
||||
return new SetIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE reverseIterator() {
|
||||
return new SetIterator(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -640,16 +786,20 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
||||
}
|
||||
|
||||
private class SetIterator implements LIST_ITERATOR KEY_GENERIC_TYPE {
|
||||
boolean forward;
|
||||
int previous = -1;
|
||||
int next = -1;
|
||||
int current = -1;
|
||||
int index = 0;
|
||||
int index = -1;
|
||||
|
||||
SetIterator() {
|
||||
next = firstIndex;
|
||||
SetIterator(boolean start) {
|
||||
this.forward = start;
|
||||
if(start) next = firstIndex;
|
||||
else previous = lastIndex;
|
||||
}
|
||||
|
||||
SetIterator(KEY_TYPE from) {
|
||||
this.forward = true;
|
||||
if(KEY_EQUALS_NULL(from)) {
|
||||
if(containsNull) {
|
||||
next = (int) links[nullIndex];
|
||||
@@ -678,48 +828,60 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
||||
|
||||
@Override
|
||||
public int skip(int amount) {
|
||||
int result = 0;
|
||||
while(next != -1 && result != amount) {
|
||||
current = previous = next;
|
||||
next = (int)(links[current]);
|
||||
result++;
|
||||
}
|
||||
int result = forward ? moveForward(amount) : moveBackwards(amount);
|
||||
if(index >= 0) index+=result;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int back(int amount) {
|
||||
int result = forward ? moveBackwards(amount) : moveForward(amount);
|
||||
if(index >= 0) index-=result;
|
||||
return result;
|
||||
}
|
||||
|
||||
private int moveForward(int amount) {
|
||||
int result = 0;
|
||||
while(next != -1 && result != amount) {
|
||||
current = previous = next;
|
||||
next = (int)(links[current]);
|
||||
result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private int moveBackwards(int amount) {
|
||||
int result = 0;
|
||||
while(previous != -1 && result != amount) {
|
||||
current = next = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
result++;
|
||||
}
|
||||
if(index >= 0) index-=result;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return next != -1;
|
||||
return (forward ? next : previous) != -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPrevious() {
|
||||
return previous != -1;
|
||||
return (forward ? previous : next) != -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int nextIndex() {
|
||||
ensureIndexKnown();
|
||||
return index;
|
||||
if(forward) return index;
|
||||
return size - index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int previousIndex() {
|
||||
ensureIndexKnown();
|
||||
return index - 1;
|
||||
if(forward) return index-1;
|
||||
return (size - index)-1;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -768,8 +930,8 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
||||
@Override
|
||||
public KEY_TYPE PREVIOUS() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
current = next = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
if(forward) moveBackwards();
|
||||
else moveForwards();
|
||||
if(index >= 0) index--;
|
||||
return keys[current];
|
||||
}
|
||||
@@ -777,12 +939,22 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
||||
@Override
|
||||
public KEY_TYPE NEXT() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
current = previous = next;
|
||||
next = (int)(links[current]);
|
||||
if(forward) moveForwards();
|
||||
else moveBackwards();
|
||||
if(index >= 0) index++;
|
||||
return keys[current];
|
||||
}
|
||||
|
||||
private void moveBackwards() {
|
||||
current = next = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
}
|
||||
|
||||
private void moveForwards() {
|
||||
current = previous = next;
|
||||
next = (int)(links[current]);
|
||||
}
|
||||
|
||||
private void ensureIndexKnown() {
|
||||
if(index == -1) {
|
||||
if(previous == -1) {
|
||||
|
||||
+8
-2
@@ -3,9 +3,13 @@ package speiger.src.collections.PACKAGE.sets;
|
||||
import java.util.NavigableSet;
|
||||
|
||||
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
import speiger.src.collections.PACKAGE.collections.SPLIT_ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.utils.SETS;
|
||||
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
||||
#endif
|
||||
#if SETS_FEATURE
|
||||
import speiger.src.collections.PACKAGE.utils.SETS;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* A Type Specific Navigable Set interface with a couple helper methods
|
||||
@@ -119,7 +123,7 @@ public interface NAVIGABLE_SET KEY_GENERIC_TYPE extends NavigableSet<CLASS_TYPE>
|
||||
@Override
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE copy();
|
||||
|
||||
#if !TYPE_BOOLEAN
|
||||
#if SETS_FEATURE
|
||||
/**
|
||||
* Creates a Wrapped NavigableSet that is Synchronized
|
||||
* @return a new NavigableSet that is synchronized
|
||||
@@ -143,6 +147,7 @@ public interface NAVIGABLE_SET KEY_GENERIC_TYPE extends NavigableSet<CLASS_TYPE>
|
||||
public default NAVIGABLE_SET KEY_GENERIC_TYPE unmodifiable() { return SETS.unmodifiable(this); }
|
||||
|
||||
#endif
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
/**
|
||||
* A Type Specific Type Splititerator to reduce boxing/unboxing
|
||||
* @return type specific splititerator
|
||||
@@ -150,6 +155,7 @@ public interface NAVIGABLE_SET KEY_GENERIC_TYPE extends NavigableSet<CLASS_TYPE>
|
||||
@Override
|
||||
default SPLIT_ITERATOR KEY_GENERIC_TYPE spliterator() { return SPLIT_ITERATORS.createSplititerator(this, 0); }
|
||||
|
||||
#endif
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
@Deprecated
|
||||
|
||||
+135
-25
@@ -6,23 +6,40 @@ import java.util.ConcurrentModificationException;
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Objects;
|
||||
#if JDK_TYPE
|
||||
import java.util.OPTIONAL;
|
||||
#if !TYPE_OBJECT
|
||||
import java.util.stream.JAVA_STREAM;
|
||||
#else
|
||||
import java.util.stream.Stream;
|
||||
import java.util.stream.Collector;
|
||||
#endif
|
||||
#endif
|
||||
#if TYPE_OBJECT
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.BiFunction;
|
||||
#endif
|
||||
#if JDK_FUNCTION
|
||||
import java.util.function.PREDICATE;
|
||||
#endif
|
||||
|
||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.lists.ARRAY_LIST;
|
||||
import speiger.src.collections.PACKAGE.lists.LIST;
|
||||
#if !JDK_TYPE
|
||||
import speiger.src.collections.PACKAGE.functions.OPTIONAL;
|
||||
#endif
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.utils.ITERATORS;
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
#endif
|
||||
import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
|
||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||
#if !JDK_FUNCTION
|
||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||
import speiger.src.collections.PACKAGE.utils.STRATEGY;
|
||||
import speiger.src.collections.objects.utils.ObjectArrays;
|
||||
|
||||
import speiger.src.collections.utils.HashUtil;
|
||||
import speiger.src.collections.utils.ITrimmable;
|
||||
@@ -246,6 +263,42 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T
|
||||
while(iterator.hasNext()) add(iterator.NEXT());
|
||||
}
|
||||
|
||||
#endif
|
||||
#if JDK_TYPE && SPLIT_ITERATOR_FEATURE && STREAM_FEATURE
|
||||
#if TYPE_OBJECT
|
||||
/**
|
||||
* Creates a Collector for a CustomHashSet
|
||||
* @Type(T)
|
||||
* @return a collector
|
||||
*/
|
||||
public static <T> Collector<T, CUSTOM_HASH_SET<T>, CUSTOM_HASH_SET<T>> toSet(STRATEGY KEY_SUPER_GENERIC_TYPE strategy) {
|
||||
return Collector.of(() -> new CUSTOM_HASH_SET<>(strategy), CUSTOM_HASH_SET::add, CUSTOM_HASH_SET::merge);
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects a Stream to a CustomHashSet
|
||||
* @Type(T)
|
||||
* @return a set with the contents of the Stream
|
||||
*/
|
||||
public static <T> CUSTOM_HASH_SET KEY_GENERIC_TYPE toSet(Stream<T> stream, STRATEGY KEY_SUPER_GENERIC_TYPE strategy) {
|
||||
return stream.collect(() -> new CUSTOM_HASH_SET<>(strategy), CUSTOM_HASH_SET::add, CUSTOM_HASH_SET::merge);
|
||||
}
|
||||
|
||||
private CUSTOM_HASH_SET<T> merge(CUSTOM_HASH_SET<T> a) {
|
||||
addAll(a);
|
||||
return this;
|
||||
}
|
||||
|
||||
#else
|
||||
/**
|
||||
* Collects a Stream to a CustomHashSet
|
||||
* @return a set with the contents of the Stream
|
||||
*/
|
||||
public static CUSTOM_HASH_SET toSet(JAVA_STREAM stream, STRATEGY KEY_SUPER_GENERIC_TYPE strategy) {
|
||||
return stream.collect(() -> new CUSTOM_HASH_SET(strategy), CUSTOM_HASH_SET::add, CUSTOM_HASH_SET::addAll);
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
/**
|
||||
* Helper getter function to get the current strategy
|
||||
@@ -475,6 +528,44 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T
|
||||
return new SetIterator();
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public KEY_TYPE[] TO_ARRAY(KEY_TYPE[] a) {
|
||||
if(a == null || a.length < size()) a = new KEY_TYPE[size()];
|
||||
if(containsNull) a[0] = EMPTY_KEY_VALUE;
|
||||
for(int i = nullIndex-1, index = containsNull ? 1 : 0;i>=0;i--) {
|
||||
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) a[index++] = keys[i];
|
||||
}
|
||||
if (a.length > size) a[size] = EMPTY_KEY_VALUE;
|
||||
return a;
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
@Deprecated
|
||||
public Object[] toArray() {
|
||||
if(isEmpty()) return ObjectArrays.EMPTY_ARRAY;
|
||||
Object[] obj = new Object[size()];
|
||||
if(containsNull) obj[0] = KEY_TO_OBJ(EMPTY_KEY_VALUE);
|
||||
for(int i = nullIndex-1, index = containsNull ? 1 : 0;i>=0;i--) {
|
||||
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) obj[index++] = KEY_TO_OBJ(keys[i]);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Primitive
|
||||
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(containsNull) a[0] = (E)KEY_TO_OBJ(EMPTY_KEY_VALUE);
|
||||
for(int i = nullIndex-1, index = containsNull ? 1 : 0;i>=0;i--) {
|
||||
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) a[index++] = (E)KEY_TO_OBJ(keys[i]);
|
||||
}
|
||||
if (a.length > size) a[size] = null;
|
||||
return a;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CUSTOM_HASH_SET KEY_GENERIC_TYPE copy() {
|
||||
CUSTOM_HASH_SET KEY_GENERIC_TYPE set = new CUSTOM_HASH_SETBRACES(0, loadFactor, strategy);
|
||||
@@ -503,6 +594,7 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T
|
||||
|
||||
@Override
|
||||
public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) {
|
||||
Objects.requireNonNull(action);
|
||||
if(size() <= 0) return;
|
||||
if(containsNull) action.accept(keys[nullIndex]);
|
||||
for(int i = nullIndex-1;i>=0;i--) {
|
||||
@@ -510,6 +602,16 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
|
||||
Objects.requireNonNull(action);
|
||||
if(size() <= 0) return;
|
||||
if(containsNull) action.accept(0, keys[nullIndex]);
|
||||
for(int i = nullIndex-1, index = containsNull ? 1 : 0;i>=0;i--) {
|
||||
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) action.accept(index++, keys[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
@@ -524,9 +626,9 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T
|
||||
public boolean matchesAny(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return false;
|
||||
if(containsNull && filter.TEST_VALUE(keys[nullIndex])) return true;
|
||||
if(containsNull && filter.test(keys[nullIndex])) return true;
|
||||
for(int i = nullIndex-1;i>=0;i--) {
|
||||
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE) && filter.TEST_VALUE(keys[i])) return true;
|
||||
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE) && filter.test(keys[i])) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -535,9 +637,9 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T
|
||||
public boolean matchesNone(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return true;
|
||||
if(containsNull && filter.TEST_VALUE(keys[nullIndex])) return false;
|
||||
if(containsNull && filter.test(keys[nullIndex])) return false;
|
||||
for(int i = nullIndex-1;i>=0;i--) {
|
||||
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE) && filter.TEST_VALUE(keys[i])) return false;
|
||||
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE) && filter.test(keys[i])) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -546,9 +648,9 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T
|
||||
public boolean matchesAll(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return true;
|
||||
if(containsNull && !filter.TEST_VALUE(keys[nullIndex])) return false;
|
||||
if(containsNull && !filter.test(keys[nullIndex])) return false;
|
||||
for(int i = nullIndex-1;i>=0;i--) {
|
||||
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE) && !filter.TEST_VALUE(keys[i])) return false;
|
||||
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE) && !filter.test(keys[i])) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -581,7 +683,7 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
public OPTIONAL KEY_GENERIC_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = EMPTY_VALUE;
|
||||
boolean empty = true;
|
||||
@@ -598,18 +700,18 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T
|
||||
}
|
||||
state = operator.APPLY_VALUE(state, keys[i]);
|
||||
}
|
||||
return state;
|
||||
return empty ? OPTIONAL.empty() : OPTIONAL.GET_OPTIONAL(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
public OPTIONAL KEY_GENERIC_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return EMPTY_VALUE;
|
||||
if(containsNull && filter.TEST_VALUE(keys[nullIndex])) return keys[nullIndex];
|
||||
if(size() <= 0) return OPTIONAL.empty();
|
||||
if(containsNull && filter.test(keys[nullIndex])) return OPTIONAL.GET_OPTIONAL(keys[nullIndex]);
|
||||
for(int i = nullIndex-1;i>=0;i--) {
|
||||
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE) && filter.TEST_VALUE(keys[i])) return keys[i];
|
||||
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE) && filter.test(keys[i])) return OPTIONAL.GET_OPTIONAL(keys[i]);
|
||||
}
|
||||
return EMPTY_VALUE;
|
||||
return OPTIONAL.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -617,9 +719,9 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return 0;
|
||||
int result = 0;
|
||||
if(containsNull && filter.TEST_VALUE(keys[nullIndex])) result++;
|
||||
if(containsNull && filter.test(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++;
|
||||
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE) && filter.test(keys[i])) result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -630,7 +732,8 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T
|
||||
int lastReturned = -1;
|
||||
int nextIndex = Integer.MIN_VALUE;
|
||||
boolean returnNull = containsNull;
|
||||
LIST KEY_GENERIC_TYPE wrapped = null;
|
||||
KEY_TYPE[] wrapped = null;
|
||||
int wrappedIndex = 0;
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
@@ -642,7 +745,7 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T
|
||||
else {
|
||||
while(true) {
|
||||
if(--pos < 0) {
|
||||
if(wrapped == null || wrapped.size() <= -pos - 1) break;
|
||||
if(wrapped == null || wrappedIndex <= -pos - 1) break;
|
||||
nextIndex = -pos - 1;
|
||||
break;
|
||||
}
|
||||
@@ -662,7 +765,7 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T
|
||||
returnedPos = pos;
|
||||
if(nextIndex < 0){
|
||||
lastReturned = Integer.MAX_VALUE;
|
||||
KEY_TYPE value = wrapped.GET_KEY(nextIndex);
|
||||
KEY_TYPE value = wrapped[nextIndex];
|
||||
nextIndex = Integer.MIN_VALUE;
|
||||
return value;
|
||||
}
|
||||
@@ -680,7 +783,7 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T
|
||||
}
|
||||
else if(returnedPos >= 0) shiftKeys(returnedPos);
|
||||
else {
|
||||
CUSTOM_HASH_SET.this.remove(wrapped.GET_KEY(-returnedPos - 1));
|
||||
CUSTOM_HASH_SET.this.remove(wrapped[-returnedPos - 1]);
|
||||
lastReturned = -1;
|
||||
return;
|
||||
}
|
||||
@@ -702,12 +805,19 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T
|
||||
if(last <= startPos ? (last >= slot || slot > startPos) : (last >= slot && slot > startPos)) break;
|
||||
startPos = ++startPos & mask;
|
||||
}
|
||||
if(startPos < last) {
|
||||
if(wrapped == null) wrapped = new ARRAY_LISTBRACES(2);
|
||||
wrapped.add(keys[startPos]);
|
||||
}
|
||||
if(startPos < last) addWrapper(keys[startPos]);
|
||||
keys[last] = current;
|
||||
}
|
||||
}
|
||||
|
||||
private void addWrapper(KEY_TYPE value) {
|
||||
if(wrapped == null) wrapped = NEW_KEY_ARRAY(2);
|
||||
else if(wrappedIndex >= wrapped.length) {
|
||||
KEY_TYPE[] newArray = NEW_KEY_ARRAY(wrapped.length * 2);
|
||||
System.arraycopy(wrapped, 0, newArray, 0, wrapped.length);
|
||||
wrapped = newArray;
|
||||
}
|
||||
wrapped[wrappedIndex++] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
+135
-25
@@ -6,22 +6,40 @@ import java.util.ConcurrentModificationException;
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Objects;
|
||||
#if JDK_TYPE
|
||||
import java.util.OPTIONAL;
|
||||
#if !TYPE_OBJECT
|
||||
import java.util.stream.JAVA_STREAM;
|
||||
#else
|
||||
import java.util.stream.Stream;
|
||||
import java.util.stream.Collector;
|
||||
#endif
|
||||
#endif
|
||||
#if TYPE_OBJECT
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.BiFunction;
|
||||
#endif
|
||||
#if JDK_FUNCTION
|
||||
import java.util.function.PREDICATE;
|
||||
#endif
|
||||
|
||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.lists.ARRAY_LIST;
|
||||
import speiger.src.collections.PACKAGE.lists.LIST;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.utils.ITERATORS;
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
#endif
|
||||
#if !JDK_TYPE
|
||||
import speiger.src.collections.PACKAGE.functions.OPTIONAL;
|
||||
#endif
|
||||
import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
|
||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||
#if !JDK_FUNCTION
|
||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||
import speiger.src.collections.objects.utils.ObjectArrays;
|
||||
|
||||
import speiger.src.collections.utils.HashUtil;
|
||||
import speiger.src.collections.utils.ITrimmable;
|
||||
import speiger.src.collections.utils.SanityChecks;
|
||||
@@ -212,6 +230,42 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
|
||||
while(iterator.hasNext()) add(iterator.NEXT());
|
||||
}
|
||||
|
||||
#endif
|
||||
#if JDK_TYPE && SPLIT_ITERATOR_FEATURE && STREAM_FEATURE
|
||||
#if TYPE_OBJECT
|
||||
/**
|
||||
* Creates a Collector for a HashSet
|
||||
* @Type(T)
|
||||
* @return a collector
|
||||
*/
|
||||
public static <T> Collector<T, HASH_SET<T>, HASH_SET<T>> toSet() {
|
||||
return Collector.of(HASH_SET::new, HASH_SET::add, HASH_SET::merge);
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects a Stream to a HashSet
|
||||
* @Type(T)
|
||||
* @return a set with the contents of the Stream
|
||||
*/
|
||||
public static <T> HASH_SET KEY_GENERIC_TYPE toSet(Stream<T> stream) {
|
||||
return stream.collect(HASH_SET::new, HASH_SET::add, HASH_SET::merge);
|
||||
}
|
||||
|
||||
private HASH_SET<T> merge(HASH_SET<T> a) {
|
||||
addAll(a);
|
||||
return this;
|
||||
}
|
||||
|
||||
#else
|
||||
/**
|
||||
* Collects a Stream to a HashSet
|
||||
* @return a set with the contents of the Stream
|
||||
*/
|
||||
public static HASH_SET toSet(JAVA_STREAM stream) {
|
||||
return stream.collect(HASH_SET::new, HASH_SET::add, HASH_SET::addAll);
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
@Override
|
||||
public boolean add(KEY_TYPE o) {
|
||||
@@ -364,6 +418,44 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
|
||||
containsNull = false;
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public KEY_TYPE[] TO_ARRAY(KEY_TYPE[] a) {
|
||||
if(a == null || a.length < size()) a = new KEY_TYPE[size()];
|
||||
if(containsNull) a[0] = EMPTY_KEY_VALUE;
|
||||
for(int i = nullIndex-1, index = containsNull ? 1 : 0;i>=0;i--) {
|
||||
if(KEY_EQUALS_NOT_NULL(keys[i])) a[index++] = keys[i];
|
||||
}
|
||||
if (a.length > size) a[size] = EMPTY_KEY_VALUE;
|
||||
return a;
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
@Deprecated
|
||||
public Object[] toArray() {
|
||||
if(isEmpty()) return ObjectArrays.EMPTY_ARRAY;
|
||||
Object[] obj = new Object[size()];
|
||||
if(containsNull) obj[0] = KEY_TO_OBJ(EMPTY_KEY_VALUE);
|
||||
for(int i = nullIndex-1, index = containsNull ? 1 : 0;i>=0;i--) {
|
||||
if(KEY_EQUALS_NOT_NULL(keys[i])) obj[index++] = KEY_TO_OBJ(keys[i]);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Primitive
|
||||
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(containsNull) a[0] = (E)KEY_TO_OBJ(EMPTY_KEY_VALUE);
|
||||
for(int i = nullIndex-1, index = containsNull ? 1 : 0;i>=0;i--) {
|
||||
if(KEY_EQUALS_NOT_NULL(keys[i])) a[index++] = (E)KEY_TO_OBJ(keys[i]);
|
||||
}
|
||||
if (a.length > size) a[size] = null;
|
||||
return a;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) {
|
||||
if(size() <= 0) return;
|
||||
@@ -373,6 +465,16 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
|
||||
Objects.requireNonNull(action);
|
||||
if(size() <= 0) return;
|
||||
if(containsNull) action.accept(0, keys[nullIndex]);
|
||||
for(int i = nullIndex-1, index = containsNull ? 1 : 0;i>=0;i--) {
|
||||
if(KEY_EQUALS_NOT_NULL(keys[i])) action.accept(index++, keys[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
@@ -387,9 +489,9 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
|
||||
public boolean matchesAny(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return false;
|
||||
if(containsNull && filter.TEST_VALUE(keys[nullIndex])) return true;
|
||||
if(containsNull && filter.test(keys[nullIndex])) return true;
|
||||
for(int i = nullIndex-1;i>=0;i--) {
|
||||
if(KEY_EQUALS_NOT_NULL(keys[i]) && filter.TEST_VALUE(keys[i])) return true;
|
||||
if(KEY_EQUALS_NOT_NULL(keys[i]) && filter.test(keys[i])) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -398,9 +500,9 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
|
||||
public boolean matchesNone(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return true;
|
||||
if(containsNull && filter.TEST_VALUE(keys[nullIndex])) return false;
|
||||
if(containsNull && filter.test(keys[nullIndex])) return false;
|
||||
for(int i = nullIndex-1;i>=0;i--) {
|
||||
if(KEY_EQUALS_NOT_NULL(keys[i]) && filter.TEST_VALUE(keys[i])) return false;
|
||||
if(KEY_EQUALS_NOT_NULL(keys[i]) && filter.test(keys[i])) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -409,9 +511,9 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
|
||||
public boolean matchesAll(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return true;
|
||||
if(containsNull && !filter.TEST_VALUE(keys[nullIndex])) return false;
|
||||
if(containsNull && !filter.test(keys[nullIndex])) return false;
|
||||
for(int i = nullIndex-1;i>=0;i--) {
|
||||
if(KEY_EQUALS_NOT_NULL(keys[i]) && !filter.TEST_VALUE(keys[i])) return false;
|
||||
if(KEY_EQUALS_NOT_NULL(keys[i]) && !filter.test(keys[i])) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -444,7 +546,7 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
public OPTIONAL KEY_GENERIC_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = EMPTY_VALUE;
|
||||
boolean empty = true;
|
||||
@@ -461,18 +563,18 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
|
||||
}
|
||||
state = operator.APPLY_VALUE(state, keys[i]);
|
||||
}
|
||||
return state;
|
||||
return empty ? OPTIONAL.empty() : OPTIONAL.GET_OPTIONAL(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
public OPTIONAL KEY_GENERIC_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return EMPTY_VALUE;
|
||||
if(containsNull && filter.TEST_VALUE(keys[nullIndex])) return keys[nullIndex];
|
||||
if(size() <= 0) return OPTIONAL.empty();
|
||||
if(containsNull && filter.test(keys[nullIndex])) return OPTIONAL.GET_OPTIONAL(keys[nullIndex]);
|
||||
for(int i = nullIndex-1;i>=0;i--) {
|
||||
if(KEY_EQUALS_NOT_NULL(keys[i]) && filter.TEST_VALUE(keys[i])) return keys[i];
|
||||
if(KEY_EQUALS_NOT_NULL(keys[i]) && filter.test(keys[i])) return OPTIONAL.GET_OPTIONAL(keys[i]);
|
||||
}
|
||||
return EMPTY_VALUE;
|
||||
return OPTIONAL.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -480,9 +582,9 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return 0;
|
||||
int result = 0;
|
||||
if(containsNull && filter.TEST_VALUE(keys[nullIndex])) result++;
|
||||
if(containsNull && filter.test(keys[nullIndex])) result++;
|
||||
for(int i = nullIndex-1;i>=0;i--) {
|
||||
if(KEY_EQUALS_NOT_NULL(keys[i]) && filter.TEST_VALUE(keys[i])) result++;
|
||||
if(KEY_EQUALS_NOT_NULL(keys[i]) && filter.test(keys[i])) result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -597,7 +699,8 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
|
||||
int lastReturned = -1;
|
||||
int nextIndex = Integer.MIN_VALUE;
|
||||
boolean returnNull = containsNull;
|
||||
LIST KEY_GENERIC_TYPE wrapped = null;
|
||||
KEY_TYPE[] wrapped = null;
|
||||
int wrappedIndex = 0;
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
@@ -610,7 +713,7 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
|
||||
{
|
||||
while(true) {
|
||||
if(--pos < 0) {
|
||||
if(wrapped == null || wrapped.size() <= -pos - 1) break;
|
||||
if(wrapped == null || wrappedIndex <= -pos - 1) break;
|
||||
nextIndex = -pos - 1;
|
||||
break;
|
||||
}
|
||||
@@ -630,7 +733,7 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
|
||||
returnedPos = pos;
|
||||
if(nextIndex < 0){
|
||||
lastReturned = Integer.MAX_VALUE;
|
||||
KEY_TYPE value = wrapped.GET_KEY(nextIndex);
|
||||
KEY_TYPE value = wrapped[nextIndex];
|
||||
nextIndex = Integer.MIN_VALUE;
|
||||
return value;
|
||||
}
|
||||
@@ -648,7 +751,7 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
|
||||
}
|
||||
else if(returnedPos >= 0) shiftKeys(returnedPos);
|
||||
else {
|
||||
HASH_SET.this.remove(wrapped.GET_KEY(-returnedPos - 1));
|
||||
HASH_SET.this.remove(wrapped[-returnedPos - 1]);
|
||||
lastReturned = -1;
|
||||
return;
|
||||
}
|
||||
@@ -670,12 +773,19 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
|
||||
if(last <= startPos ? (last >= slot || slot > startPos) : (last >= slot && slot > startPos)) break;
|
||||
startPos = ++startPos & mask;
|
||||
}
|
||||
if(startPos < last) {
|
||||
if(wrapped == null) wrapped = new ARRAY_LISTBRACES(2);
|
||||
wrapped.add(keys[startPos]);
|
||||
}
|
||||
if(startPos < last) addWrapper(keys[startPos]);
|
||||
keys[last] = current;
|
||||
}
|
||||
}
|
||||
|
||||
private void addWrapper(KEY_TYPE value) {
|
||||
if(wrapped == null) wrapped = NEW_KEY_ARRAY(2);
|
||||
else if(wrappedIndex >= wrapped.length) {
|
||||
KEY_TYPE[] newArray = NEW_KEY_ARRAY(wrapped.length * 2);
|
||||
System.arraycopy(wrapped, 0, newArray, 0, wrapped.length);
|
||||
wrapped = newArray;
|
||||
}
|
||||
wrapped[wrappedIndex++] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
+77
-7
@@ -1,9 +1,19 @@
|
||||
package speiger.src.collections.PACKAGE.sets;
|
||||
|
||||
#if JAVA_VERSION>=21
|
||||
import java.util.SequencedSet;
|
||||
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.collections.ORDERED_COLLECTION;
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
import speiger.src.collections.PACKAGE.collections.SPLIT_ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.utils.SETS;
|
||||
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.sets.ABSTRACT_SET.REVERSED_ORDERED_SET;
|
||||
#if SETS_FEATURE
|
||||
import speiger.src.collections.PACKAGE.utils.SETS;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* A Special Set Interface giving Access to some really usefull functions
|
||||
@@ -13,7 +23,11 @@ import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
||||
*
|
||||
* @Type(T)
|
||||
*/
|
||||
public interface ORDERED_SET KEY_GENERIC_TYPE extends SET KEY_GENERIC_TYPE
|
||||
#if JAVA_VERSION>=21
|
||||
public interface ORDERED_SET KEY_GENERIC_TYPE extends SET KEY_GENERIC_TYPE, ORDERED_COLLECTION KEY_GENERIC_TYPE, SequencedSet<CLASS_TYPE>
|
||||
#else
|
||||
public interface ORDERED_SET KEY_GENERIC_TYPE extends SET KEY_GENERIC_TYPE, ORDERED_COLLECTION KEY_GENERIC_TYPE
|
||||
#endif
|
||||
{
|
||||
/**
|
||||
* A customized add method that allows you to insert into the first index.
|
||||
@@ -50,6 +64,7 @@ public interface ORDERED_SET KEY_GENERIC_TYPE extends SET KEY_GENERIC_TYPE
|
||||
|
||||
@Override
|
||||
public BI_ITERATOR KEY_GENERIC_TYPE iterator();
|
||||
public BI_ITERATOR KEY_GENERIC_TYPE reverseIterator();
|
||||
|
||||
/**
|
||||
* A type Specific Iterator starting from a given key
|
||||
@@ -59,6 +74,7 @@ public interface ORDERED_SET KEY_GENERIC_TYPE extends SET KEY_GENERIC_TYPE
|
||||
*/
|
||||
public BI_ITERATOR KEY_GENERIC_TYPE iterator(KEY_TYPE fromElement);
|
||||
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
/**
|
||||
* A Type Specific Type Splititerator to reduce boxing/unboxing
|
||||
* @return type specific splititerator
|
||||
@@ -66,28 +82,82 @@ public interface ORDERED_SET KEY_GENERIC_TYPE extends SET KEY_GENERIC_TYPE
|
||||
@Override
|
||||
default SPLIT_ITERATOR KEY_GENERIC_TYPE spliterator() { return SPLIT_ITERATORS.createSplititerator(this, 0); }
|
||||
|
||||
#endif
|
||||
/**
|
||||
* A method to get the first element in the set
|
||||
* @return first element in the set
|
||||
*/
|
||||
public KEY_TYPE FIRST_KEY();
|
||||
public KEY_TYPE GET_FIRST_KEY();
|
||||
/**
|
||||
* A method to get and remove the first element in the set
|
||||
* @return first element in the set
|
||||
*/
|
||||
public KEY_TYPE POLL_FIRST_KEY();
|
||||
public KEY_TYPE REMOVE_FIRST_KEY();
|
||||
/**
|
||||
* A method to get the last element in the set
|
||||
* @return last element in the set
|
||||
*/
|
||||
public KEY_TYPE LAST_KEY();
|
||||
public KEY_TYPE GET_LAST_KEY();
|
||||
/**
|
||||
* A method to get and remove the last element in the set
|
||||
* @return last element in the set
|
||||
*/
|
||||
public KEY_TYPE POLL_LAST_KEY();
|
||||
public KEY_TYPE REMOVE_LAST_KEY();
|
||||
|
||||
#if !TYPE_BOOLEAN
|
||||
#if JAVA_VERSION>=21 && !TYPE_OBJECT
|
||||
/** {@inheritDoc}
|
||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||
* @deprecated Please use the corresponding type-specific function instead.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
default void addFirst(CLASS_TYPE e) { addAndMoveToFirst(OBJ_TO_KEY(e)); }
|
||||
|
||||
/** {@inheritDoc}
|
||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||
* @deprecated Please use the corresponding type-specific function instead.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
default void addLast(CLASS_TYPE e) { addAndMoveToLast(OBJ_TO_KEY(e)); }
|
||||
|
||||
/** {@inheritDoc}
|
||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||
* @deprecated Please use the corresponding type-specific function instead.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
default CLASS_TYPE getFirst() { return GET_FIRST_KEY(); }
|
||||
|
||||
/** {@inheritDoc}
|
||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||
* @deprecated Please use the corresponding type-specific function instead.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
default CLASS_TYPE getLast() { return GET_LAST_KEY(); }
|
||||
|
||||
/** {@inheritDoc}
|
||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||
* @deprecated Please use the corresponding type-specific function instead.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
default CLASS_TYPE removeFirst() { return REMOVE_FIRST_KEY(); }
|
||||
|
||||
/** {@inheritDoc}
|
||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||
* @deprecated Please use the corresponding type-specific function instead.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
default CLASS_TYPE removeLast() { return REMOVE_LAST_KEY(); }
|
||||
|
||||
#endif
|
||||
@Java21
|
||||
public default ORDERED_SET KEY_GENERIC_TYPE reversed() { return new REVERSED_ORDERED_SETBRACES(this); }
|
||||
|
||||
#if SETS_FEATURE
|
||||
/**
|
||||
* Creates a Wrapped OrderedSet that is Synchronized
|
||||
* @return a new OrderedSet that is synchronized
|
||||
|
||||
+129
-18
@@ -2,6 +2,15 @@ package speiger.src.collections.PACKAGE.sets;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
#if JDK_TYPE
|
||||
import java.util.OPTIONAL;
|
||||
#if !TYPE_OBJECT
|
||||
import java.util.stream.JAVA_STREAM;
|
||||
#else
|
||||
import java.util.stream.Stream;
|
||||
import java.util.stream.Collector;
|
||||
#endif
|
||||
#endif
|
||||
#if TYPE_OBJECT
|
||||
import java.util.Comparator;
|
||||
import java.util.function.Consumer;
|
||||
@@ -10,16 +19,27 @@ import java.util.function.BiFunction;
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Objects;
|
||||
#if JDK_FUNCTION
|
||||
import java.util.function.PREDICATE;
|
||||
#endif
|
||||
|
||||
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;
|
||||
#endif
|
||||
#if !JDK_TYPE
|
||||
import speiger.src.collections.PACKAGE.functions.OPTIONAL;
|
||||
#endif
|
||||
import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
|
||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||
#if !JDK_FUNCTION
|
||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||
#endif
|
||||
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.objects.utils.ObjectArrays;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.utils.ITERATORS;
|
||||
#endif
|
||||
@@ -200,6 +220,42 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
while(iterator.hasNext()) add(iterator.NEXT());
|
||||
}
|
||||
|
||||
#if JDK_TYPE && SPLIT_ITERATOR_FEATURE && STREAM_FEATURE
|
||||
#if TYPE_OBJECT
|
||||
/**
|
||||
* Creates a Collector for a RBTreeSet
|
||||
* @Type(T)
|
||||
* @return a collector
|
||||
*/
|
||||
public static <T> Collector<T, RB_TREE_SET<T>, RB_TREE_SET<T>> toSet() {
|
||||
return Collector.of(RB_TREE_SET::new, RB_TREE_SET::add, RB_TREE_SET::merge);
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects a Stream to a RBTreeSet
|
||||
* @Type(T)
|
||||
* @return a set with the contents of the Stream
|
||||
*/
|
||||
public static <T> RB_TREE_SET KEY_GENERIC_TYPE toSet(Stream<T> stream) {
|
||||
return stream.collect(RB_TREE_SET::new, RB_TREE_SET::add, RB_TREE_SET::merge);
|
||||
}
|
||||
|
||||
private RB_TREE_SET<T> merge(RB_TREE_SET<T> a) {
|
||||
addAll(a);
|
||||
return this;
|
||||
}
|
||||
|
||||
#else
|
||||
/**
|
||||
* Collects a Stream to a RBTreeSet
|
||||
* @return a set with the contents of the Stream
|
||||
*/
|
||||
public static RB_TREE_SET toSet(JAVA_STREAM stream) {
|
||||
return stream.collect(RB_TREE_SET::new, RB_TREE_SET::add, RB_TREE_SET::addAll);
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public void setDefaultMaxValue(KEY_TYPE value) { defaultMaxNotFound = value; }
|
||||
@@ -353,6 +409,14 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
|
||||
Objects.requireNonNull(action);
|
||||
int index = 0;
|
||||
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next())
|
||||
action.accept(index++, entry.key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
@@ -364,7 +428,7 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
public boolean matchesAny(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) {
|
||||
if(filter.TEST_VALUE(entry.key)) return true;
|
||||
if(filter.test(entry.key)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -373,7 +437,7 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
public boolean matchesNone(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) {
|
||||
if(filter.TEST_VALUE(entry.key)) return false;
|
||||
if(filter.test(entry.key)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -382,7 +446,7 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
public boolean matchesAll(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) {
|
||||
if(!filter.TEST_VALUE(entry.key)) return false;
|
||||
if(!filter.test(entry.key)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -411,7 +475,7 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
public OPTIONAL KEY_GENERIC_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = EMPTY_VALUE;
|
||||
boolean empty = true;
|
||||
@@ -423,16 +487,16 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
}
|
||||
state = operator.APPLY_VALUE(state, entry.key);
|
||||
}
|
||||
return state;
|
||||
return empty ? OPTIONAL.empty() : OPTIONAL.GET_OPTIONAL(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
public OPTIONAL KEY_GENERIC_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) {
|
||||
if(filter.TEST_VALUE(entry.key)) return entry.key;
|
||||
if(filter.test(entry.key)) return OPTIONAL.GET_OPTIONAL(entry.key);
|
||||
}
|
||||
return EMPTY_VALUE;
|
||||
return OPTIONAL.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -440,7 +504,7 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
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++;
|
||||
if(filter.test(entry.key)) result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -637,6 +701,44 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
tree = null;
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public KEY_TYPE[] TO_ARRAY(KEY_TYPE[] a) {
|
||||
if(a == null || a.length < size()) a = new KEY_TYPE[size()];
|
||||
int index = 0;
|
||||
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) {
|
||||
a[index++] = entry.key;
|
||||
}
|
||||
if (a.length > size) a[size] = EMPTY_KEY_VALUE;
|
||||
return a;
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
@Deprecated
|
||||
public Object[] toArray() {
|
||||
if(isEmpty()) return ObjectArrays.EMPTY_ARRAY;
|
||||
Object[] obj = new Object[size()];
|
||||
int index = 0;
|
||||
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) {
|
||||
obj[index++] = KEY_TO_OBJ(entry.key);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Primitive
|
||||
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());
|
||||
int index = 0;
|
||||
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) {
|
||||
a[index++] = (E)KEY_TO_OBJ(entry.key);
|
||||
}
|
||||
if (a.length > size) a[size] = null;
|
||||
return a;
|
||||
}
|
||||
|
||||
public RB_TREE_SET KEY_GENERIC_TYPE copy() {
|
||||
RB_TREE_SET KEY_GENERIC_TYPE set = new RB_TREE_SETBRACES();
|
||||
set.size = size;
|
||||
@@ -1253,6 +1355,15 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
|
||||
Objects.requireNonNull(action);
|
||||
int index = 0;
|
||||
for(Entry KEY_GENERIC_TYPE entry = start();entry != null && inRange(entry.key);entry = next(entry)) {
|
||||
action.accept(index++, entry.key);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
@@ -1264,7 +1375,7 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
public boolean matchesAny(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(Entry KEY_GENERIC_TYPE entry = start();entry != null && inRange(entry.key);entry = next(entry)) {
|
||||
if(filter.TEST_VALUE(entry.key)) return true;
|
||||
if(filter.test(entry.key)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -1273,7 +1384,7 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
public boolean matchesNone(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(Entry KEY_GENERIC_TYPE entry = start();entry != null && inRange(entry.key);entry = next(entry)) {
|
||||
if(filter.TEST_VALUE(entry.key)) return false;
|
||||
if(filter.test(entry.key)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -1282,7 +1393,7 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
public boolean matchesAll(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(Entry KEY_GENERIC_TYPE entry = start();entry != null && inRange(entry.key);entry = next(entry)) {
|
||||
if(!filter.TEST_VALUE(entry.key)) return false;
|
||||
if(!filter.test(entry.key)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -1311,7 +1422,7 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
public OPTIONAL KEY_GENERIC_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = EMPTY_VALUE;
|
||||
boolean empty = true;
|
||||
@@ -1323,16 +1434,16 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
}
|
||||
state = operator.APPLY_VALUE(state, entry.key);
|
||||
}
|
||||
return state;
|
||||
return empty ? OPTIONAL.empty() : OPTIONAL.GET_OPTIONAL(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
public OPTIONAL KEY_GENERIC_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(Entry KEY_GENERIC_TYPE entry = start();entry != null && inRange(entry.key);entry = next(entry)) {
|
||||
if(filter.TEST_VALUE(entry.key)) return entry.key;
|
||||
if(filter.test(entry.key)) return OPTIONAL.GET_OPTIONAL(entry.key);
|
||||
}
|
||||
return EMPTY_VALUE;
|
||||
return OPTIONAL.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1340,7 +1451,7 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
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++;
|
||||
if(filter.test(entry.key)) result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -4,11 +4,13 @@ import java.util.Set;
|
||||
|
||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
import speiger.src.collections.PACKAGE.collections.SPLIT_ITERATOR;
|
||||
#if !TYPE_BOOLEAN
|
||||
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
||||
#endif
|
||||
#if SETS_FEATURE
|
||||
import speiger.src.collections.PACKAGE.utils.SETS;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
||||
|
||||
|
||||
/**
|
||||
@@ -64,7 +66,7 @@ public interface SET KEY_GENERIC_TYPE extends Set<CLASS_TYPE>, COLLECTION KEY_GE
|
||||
public KEY_TYPE addOrGet(KEY_TYPE o);
|
||||
|
||||
#endif
|
||||
#if !TYPE_BOOLEAN
|
||||
#if SETS_FEATURE
|
||||
/**
|
||||
* Creates a Wrapped Set that is Synchronized
|
||||
* @return a new Set that is synchronized
|
||||
@@ -88,10 +90,12 @@ public interface SET KEY_GENERIC_TYPE extends Set<CLASS_TYPE>, COLLECTION KEY_GE
|
||||
public default SET KEY_GENERIC_TYPE unmodifiable() { return SETS.unmodifiable(this); }
|
||||
|
||||
#endif
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
/**
|
||||
* A Type Specific Type Splititerator to reduce boxing/unboxing
|
||||
* @return type specific splititerator
|
||||
*/
|
||||
@Override
|
||||
default SPLIT_ITERATOR KEY_GENERIC_TYPE spliterator() { return SPLIT_ITERATORS.createSplititerator(this, 0); }
|
||||
#endif
|
||||
}
|
||||
@@ -3,14 +3,20 @@ package speiger.src.collections.PACKAGE.sets;
|
||||
import java.util.SortedSet;
|
||||
|
||||
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
import speiger.src.collections.PACKAGE.collections.SPLIT_ITERATOR;
|
||||
#endif
|
||||
#if TYPE_OBJECT
|
||||
import java.util.Comparator;
|
||||
#else
|
||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
#endif
|
||||
#if SETS_FEATURE
|
||||
import speiger.src.collections.PACKAGE.utils.SETS;
|
||||
#endif
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* A Type Specific SortedSet implementation to reduce boxing/unboxing
|
||||
@@ -41,7 +47,7 @@ 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
|
||||
#if SETS_FEATURE
|
||||
/**
|
||||
* Creates a Wrapped SortedSet that is Synchronized
|
||||
* @return a new SortedSet that is synchronized
|
||||
@@ -65,6 +71,7 @@ public interface SORTED_SET KEY_GENERIC_TYPE extends SET KEY_GENERIC_TYPE, Sorte
|
||||
public default SORTED_SET KEY_GENERIC_TYPE unmodifiable() { return SETS.unmodifiable(this); }
|
||||
|
||||
#endif
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
/**
|
||||
* A Type Specific Type Splititerator to reduce boxing/unboxing
|
||||
* @return type specific splititerator
|
||||
@@ -72,6 +79,7 @@ public interface SORTED_SET KEY_GENERIC_TYPE extends SET KEY_GENERIC_TYPE, Sorte
|
||||
@Override
|
||||
default SPLIT_ITERATOR KEY_GENERIC_TYPE spliterator() { return SPLIT_ITERATORS.createSplititerator(this, 0); }
|
||||
|
||||
#endif
|
||||
#if !TYPE_OBJECT
|
||||
/**
|
||||
* A Type Specific SubSet method to reduce boxing/unboxing
|
||||
|
||||
@@ -1,19 +1,23 @@
|
||||
package speiger.src.collections.PACKAGE.utils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Random;
|
||||
#if JAVA_VERSION>=17
|
||||
import java.util.random.RANDOM;
|
||||
#else
|
||||
import java.util.RANDOM;
|
||||
#endif
|
||||
import java.util.concurrent.RecursiveAction;
|
||||
#if !TYPE_OBJECT
|
||||
|
||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
#else
|
||||
import java.util.Comparator;
|
||||
import java.util.function.IntFunction;
|
||||
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.lists.ARRAY_LIST;
|
||||
import speiger.src.collections.PACKAGE.utils.ITERATORS;
|
||||
import speiger.src.collections.utils.SanityChecks;
|
||||
import speiger.src.collections.utils.Swapper;
|
||||
|
||||
/**
|
||||
* A Helper class for Arrays
|
||||
@@ -132,10 +136,41 @@ public class ARRAYS
|
||||
* @return array with all requested elements of the iterator
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES KEY_TYPE[] pour(ITERATOR KEY_GENERIC_TYPE iter, int max) {
|
||||
ARRAY_LIST KEY_GENERIC_TYPE list = new ARRAY_LISTBRACES();
|
||||
COLLECTIONS.CollectionWrapper KEY_GENERIC_TYPE list = COLLECTIONS.wrapper();
|
||||
ITERATORS.pour(iter, list, max);
|
||||
return list.TO_ARRAY(NEW_KEY_ARRAY(list.size()));
|
||||
}
|
||||
|
||||
#if TYPE_OBJECT
|
||||
/**
|
||||
* A Helper function that pours all elements of a iterator into a Array
|
||||
* @param iter the elements that should be gathered.
|
||||
* @ArrayType(T)
|
||||
* @ArrayType(E)
|
||||
* @param action that is creating the Array to be poured into
|
||||
* @return array with all elements of the iterator
|
||||
*/
|
||||
public static <T, E> E[] pour(ITERATOR KEY_GENERIC_TYPE iter, IntFunction<E[]> action) {
|
||||
return pour(iter, Integer.MAX_VALUE, action);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that pours all elements of a iterator into a Array
|
||||
* @param iter the elements that should be gathered.
|
||||
* @param max how many elements should be added
|
||||
* @param action that is creating the Array to be poured into
|
||||
* @ArrayType(T)
|
||||
* @ArrayType(E)
|
||||
* @return array with all requested elements of the iterator
|
||||
*/
|
||||
public static <T, E> E[] pour(ITERATOR KEY_GENERIC_TYPE iter, int max, IntFunction<E[]> action) {
|
||||
COLLECTIONS.CollectionWrapper KEY_GENERIC_TYPE list = COLLECTIONS.wrapper();
|
||||
ITERATORS.pour(iter, list, max);
|
||||
return list.TO_ARRAY(action.apply(list.size()));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Method to validate if the current value is the lowest value in the heap
|
||||
* @param data the current heap.
|
||||
@@ -262,7 +297,7 @@ public class ARRAYS
|
||||
* @ArrayType(T)
|
||||
* @return the provided sorted array
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES KEY_TYPE[] shuffle(KEY_TYPE[] array, Random random) {
|
||||
public static GENERIC_KEY_BRACES KEY_TYPE[] shuffle(KEY_TYPE[] array, RANDOM random) {
|
||||
for(int i = array.length-1; i>=0;i--) {
|
||||
int p = random.nextInt(i + 1);
|
||||
KEY_TYPE t = array[i];
|
||||
@@ -280,7 +315,7 @@ public class ARRAYS
|
||||
* @ArrayType(T)
|
||||
* @return the provided sorted array
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES KEY_TYPE[] shuffle(KEY_TYPE[] array, int length, Random random) {
|
||||
public static GENERIC_KEY_BRACES KEY_TYPE[] shuffle(KEY_TYPE[] array, int length, RANDOM random) {
|
||||
return shuffle(array, 0, length, random);
|
||||
}
|
||||
|
||||
@@ -293,7 +328,7 @@ public class ARRAYS
|
||||
* @ArrayType(T)
|
||||
* @return the provided sorted array
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES KEY_TYPE[] shuffle(KEY_TYPE[] array, int offset, int length, Random random) {
|
||||
public static GENERIC_KEY_BRACES KEY_TYPE[] shuffle(KEY_TYPE[] array, int offset, int length, RANDOM random) {
|
||||
for(int i = length-1; i>=0;i--) {
|
||||
int p = offset + random.nextInt(i + 1);
|
||||
KEY_TYPE t = array[offset+i];
|
||||
@@ -303,6 +338,69 @@ public class ARRAYS
|
||||
return array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple Shuffle method for Arrays.
|
||||
* With a Callback for indirect shuffling
|
||||
* @param array the elements that should be shuffled
|
||||
* @param swapper the callback on the swaps
|
||||
* @ArrayType(T)
|
||||
* @note This uses the SanityChecks#getRandom
|
||||
* @return the provided sorted array
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES KEY_TYPE[] indirectShuffle(KEY_TYPE[] array, Swapper swapper) {
|
||||
return indirectShuffle(array, SanityChecks.getRandom(), swapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple Shuffle method for Arrays.
|
||||
* With a Callback for indirect shuffling
|
||||
* @param array the elements that should be shuffled
|
||||
* @param random the Random Number Generator that should be used for the shuffling
|
||||
* @param swapper the callback on the swaps
|
||||
* @ArrayType(T)
|
||||
* @return the provided sorted array
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES KEY_TYPE[] indirectShuffle(KEY_TYPE[] array, RANDOM random, Swapper swapper) {
|
||||
return indirectShuffle(array, 0, array.length, random, swapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple Shuffle method for Arrays.
|
||||
* With a Callback for indirect shuffling
|
||||
* @param array the elements that should be shuffled
|
||||
* @param length the length of the array
|
||||
* @param random the Random Number Generator that should be used for the shuffling
|
||||
* @param swapper the callback on the swaps
|
||||
* @ArrayType(T)
|
||||
* @return the provided sorted array
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES KEY_TYPE[] indirectShuffle(KEY_TYPE[] array, int length, RANDOM random, Swapper swapper) {
|
||||
return indirectShuffle(array, 0, length, random, swapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple Shuffle method for Arrays.
|
||||
* With a Callback for indirect shuffling
|
||||
* @param array the elements that should be shuffled
|
||||
* @param offset the start array
|
||||
* @param length the length of the array
|
||||
* @param random the Random Number Generator that should be used for the shuffling
|
||||
* @param swapper the callback on the swaps
|
||||
* @ArrayType(T)
|
||||
* @return the provided sorted array
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES KEY_TYPE[] indirectShuffle(KEY_TYPE[] array, int offset, int length, RANDOM random, Swapper swapper) {
|
||||
for(int i = length-1; i>=0;i--) {
|
||||
int j = offset + i;
|
||||
int p = offset + random.nextInt(i + 1);
|
||||
swapper.swap(j, p);
|
||||
KEY_TYPE t = array[j];
|
||||
array[j] = array[p];
|
||||
array[p] = t;
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple Array Reversal method
|
||||
* @param array the Array that should flip
|
||||
@@ -541,6 +639,55 @@ public class ARRAYS
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts the specified range of elements according to the order induced by the specified comparator using Insertion Sort,
|
||||
* On top of that allows to sort other things along with it.
|
||||
* @param array the array that needs to be sorted
|
||||
* @param comp the Comparator that decides the sorting order
|
||||
* @param swapper the callback which elements were swapped
|
||||
* @ArrayType(T)
|
||||
* @return input array
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES KEY_TYPE[] indirectInsertionSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp, Swapper swapper) {
|
||||
indirectInsertionSort(array, 0, array.length, comp, swapper);
|
||||
return array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts the specified range of elements according to the order induced by the specified comparator using Insertion Sort,
|
||||
* On top of that allows to sort other things along with it.
|
||||
* @param array the array that needs to be sorted
|
||||
* @param length the maxmium size of the array to be sorted
|
||||
* @param comp the Comparator that decides the sorting order
|
||||
* @param swapper the callback which elements were swapped
|
||||
* @ArrayType(T)
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES void indirectInsertionSort(KEY_TYPE[] array, int length, COMPARATOR KEY_GENERIC_TYPE comp, Swapper swapper) {
|
||||
indirectInsertionSort(array, 0, length, comp, swapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts the specified range of elements according to the order induced by the specified comparator using Insertion Sort,
|
||||
* On top of that allows to sort other things along with it.
|
||||
* @param array the array that needs to be sorted
|
||||
* @param from where the array should be sorted from
|
||||
* @param to where the array should be sorted to
|
||||
* @param comp the Comparator that decides the sorting order
|
||||
* @param swapper the callback which elements were swapped
|
||||
* @ArrayType(T)
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES void indirectInsertionSort(KEY_TYPE[] array, int from, int to, COMPARATOR KEY_GENERIC_TYPE comp, Swapper swapper) {
|
||||
for (int i = from+1;i<to; i++) {
|
||||
KEY_TYPE current = array[i];
|
||||
int j = i - 1;
|
||||
while(j >= from && comp.compare(current, array[j]) < 0) {
|
||||
swapper.swap(j+1, j);
|
||||
array[j+1] = array[j--];
|
||||
}
|
||||
array[j+1] = current;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts an array according to the natural ascending order using InsertionSort,
|
||||
* @param array the array that needs to be sorted
|
||||
@@ -627,6 +774,60 @@ public class ARRAYS
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts the specified range of elements according to the order induced by the specified comparator using Selection Sort,
|
||||
* On top of that allows to sort other things along with it.
|
||||
* @param array the array that needs to be sorted
|
||||
* @param comp the Comparator that decides the sorting order
|
||||
* @param swapper the callback which elements were swapped
|
||||
* @ArrayType(T)
|
||||
* @return input array
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES KEY_TYPE[] indirectSelectionSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp, Swapper swapper) {
|
||||
indirectSelectionSort(array, 0, array.length, comp, swapper);
|
||||
return array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts the specified range of elements according to the order induced by the specified comparator using Selection Sort,
|
||||
* On top of that allows to sort other things along with it.
|
||||
* @param array the array that needs to be sorted
|
||||
* @param length the maxmium size of the array to be sorted
|
||||
* @param comp the Comparator that decides the sorting order
|
||||
* @param swapper the callback which elements were swapped
|
||||
* @ArrayType(T)
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES void indirectSelectionSort(KEY_TYPE[] array, int length, COMPARATOR KEY_GENERIC_TYPE comp, Swapper swapper) {
|
||||
indirectSelectionSort(array, 0, length, comp, swapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts the specified range of elements according to the order induced by the specified comparator using Selection Sort,
|
||||
* On top of that allows to sort other things along with it.
|
||||
* @param array the array that needs to be sorted
|
||||
* @param from where the array should be sorted from
|
||||
* @param to where the array should be sorted to
|
||||
* @param comp the Comparator that decides the sorting order
|
||||
* @param swapper the callback which elements were swapped
|
||||
* @ArrayType(T)
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES void indirectSelectionSort(KEY_TYPE[] array, int from, int to, COMPARATOR KEY_GENERIC_TYPE comp, Swapper swapper) {
|
||||
for (int i = from; i < to; i++) {
|
||||
KEY_TYPE min = array[i];
|
||||
int minId = i;
|
||||
for(int j = i+1; j < to; j++) {
|
||||
if(comp.compare(array[j], min) < 0) {
|
||||
min = array[j];
|
||||
minId = j;
|
||||
}
|
||||
}
|
||||
swapper.swap(i, minId);
|
||||
KEY_TYPE temp = array[i];
|
||||
array[i] = min;
|
||||
array[minId] = temp;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts an array according to the natural ascending order using Selection Sort,
|
||||
* @param array the array that needs to be sorted
|
||||
@@ -656,7 +857,7 @@ public class ARRAYS
|
||||
* @ArrayType(T)
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES void selectionSort(KEY_TYPE[] array, int from, int to) {
|
||||
for (int i = from; i < to; i++) {
|
||||
for (int i = from,m=to-1; i < m; i++) {
|
||||
KEY_TYPE min = array[i];
|
||||
int minId = i;
|
||||
for(int j = i+1; j < to; j++) {
|
||||
@@ -726,6 +927,72 @@ public class ARRAYS
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts the specified range of elements according to the order induced by the specified comparator using Merge Sort,
|
||||
* On top of that allows to sort other things along with it.
|
||||
* This implementation was copied from <a href="https://github.com/vigna/fastutil">FastUtil</a> with a couple custom optimizations
|
||||
* @param array the array that needs to be sorted
|
||||
* @param comp the Comparator that decides the sorting order
|
||||
* @param swapper the callback which elements were swapped
|
||||
* @ArrayType(T)
|
||||
* @return input array
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES KEY_TYPE[] indirectMergeSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp, Swapper swapper) {
|
||||
indirectMergeSort(array, null, 0, array.length, comp, swapper);
|
||||
return array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts the specified range of elements according to the order induced by the specified comparator using Merge Sort,
|
||||
* On top of that allows to sort other things along with it.
|
||||
* This implementation was copied from <a href="https://github.com/vigna/fastutil">FastUtil</a> with a couple custom optimizations
|
||||
* @param array the array that needs to be sorted
|
||||
* @param length the maxmium size of the array to be sorted
|
||||
* @param comp the Comparator that decides the sorting order
|
||||
* @param swapper the callback which elements were swapped
|
||||
* @ArrayType(T)
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES void indirectMergeSort(KEY_TYPE[] array, int length, COMPARATOR KEY_GENERIC_TYPE comp, Swapper swapper) {
|
||||
indirectMergeSort(array, null, 0, length, comp, swapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts the specified range of elements according to the order induced by the specified comparator using Merge Sort,
|
||||
* On top of that allows to sort other things along with it.
|
||||
* This implementation was copied from <a href="https://github.com/vigna/fastutil">FastUtil</a> with a couple custom optimizations
|
||||
* @param array the array that needs to be sorted
|
||||
* @param supp the auxillary array that is used to simplify the sorting
|
||||
* @param from where the array should be sorted from
|
||||
* @param to where the array should be sorted to
|
||||
* @param comp the Comparator that decides the sorting order
|
||||
* @param swapper the callback which elements were swapped
|
||||
* @ArrayType(T)
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES void indirectMergeSort(KEY_TYPE[] array, KEY_TYPE[] supp, int from, int to, COMPARATOR KEY_GENERIC_TYPE comp, Swapper swapper) {
|
||||
if(to - from < BASE_THRESHOLD) {
|
||||
indirectInsertionSort(array, from, to, comp, swapper);
|
||||
return;
|
||||
}
|
||||
if(supp == null) supp = Arrays.copyOf(array, to);
|
||||
int mid = (from + to) >>> 1;
|
||||
indirectMergeSort(supp, array, from, mid, comp, swapper);
|
||||
indirectMergeSort(supp, array, mid, to, comp, swapper);
|
||||
if(comp.compare(supp[mid - 1], supp[mid]) <= 0)
|
||||
{
|
||||
System.arraycopy(supp, from, array, from, to - from);
|
||||
return;
|
||||
}
|
||||
for(int p = from, q = mid;from < to;from++) {
|
||||
if(q >= to || p < mid && comp.compare(supp[p], supp[q]) < 0) {
|
||||
swapper.swap(from, p);
|
||||
array[from] = supp[p++];
|
||||
continue;
|
||||
}
|
||||
swapper.swap(from, q);
|
||||
array[from] = supp[q++];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts an array according to the natural ascending order using Merge Sort,
|
||||
* This implementation was copied from <a href="https://github.com/vigna/fastutil">FastUtil</a> with a couple custom optimizations
|
||||
@@ -822,6 +1089,56 @@ public class ARRAYS
|
||||
mergeSort(array, supp, from, to, comp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts the specified range of elements according to the order induced by the specified comparator using a Parallel Merge Sort,
|
||||
* On top of that allows to sort other things along with it.
|
||||
* This implementation was copied from <a href="https://github.com/vigna/fastutil">FastUtil</a> with a couple custom optimizations
|
||||
* @param array the array that needs to be sorted
|
||||
* @param comp the Comparator that decides the sorting order
|
||||
* @param swapper the callback which elements were swapped
|
||||
* @note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed
|
||||
* @ArrayType(T)
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES void indirectParallelMergeSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp, Swapper swapper) {
|
||||
indirectParallelMergeSort(array, null, 0, array.length, comp, swapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts the specified range of elements according to the order induced by the specified comparator using Parallel Merge Sort,
|
||||
* On top of that allows to sort other things along with it.
|
||||
* This implementation was copied from <a href="https://github.com/vigna/fastutil">FastUtil</a> with a couple custom optimizations
|
||||
* @param array the array that needs to be sorted
|
||||
* @param length the maxmium size of the array to be sorted
|
||||
* @param swapper the callback which elements were swapped
|
||||
* @param comp the Comparator that decides the sorting order
|
||||
* @note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed
|
||||
* @ArrayType(T)
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES void indirectParallelMergeSort(KEY_TYPE[] array, int length, COMPARATOR KEY_GENERIC_TYPE comp, Swapper swapper) {
|
||||
indirectParallelMergeSort(array, null, 0, length, comp, swapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts the specified range of elements according to the order induced by the specified comparator using Parallel Merge Sort,
|
||||
* On top of that allows to sort other things along with it.
|
||||
* This implementation was copied from <a href="https://github.com/vigna/fastutil">FastUtil</a> with a couple custom optimizations
|
||||
* @param array the array that needs to be sorted
|
||||
* @param supp the auxillary array that is used to simplify the sorting
|
||||
* @param from where the array should be sorted from
|
||||
* @param to where the array should be sorted to
|
||||
* @param comp the Comparator that decides the sorting order
|
||||
* @param swapper the callback which elements were swapped
|
||||
* @note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed
|
||||
* @ArrayType(T)
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES void indirectParallelMergeSort(KEY_TYPE[] array, KEY_TYPE[] supp, int from, int to, COMPARATOR KEY_GENERIC_TYPE comp, Swapper swapper) {
|
||||
if(SanityChecks.canParallelTask() && to - from >= PARALLEL_THRESHOLD) {
|
||||
SanityChecks.invokeTask(new MergeSortActionCompSwapBRACES(array, supp, from, to, comp, swapper));
|
||||
return;
|
||||
}
|
||||
indirectMergeSort(array, supp, from, to, comp, swapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts an array according to the natural ascending order using Parallel Merge Sort,
|
||||
* This implementation was copied from <a href="https://github.com/vigna/fastutil">FastUtil</a> with a couple custom optimizations
|
||||
@@ -1175,6 +1492,73 @@ public class ARRAYS
|
||||
if((length = d - c) > 1) quickSort(array, to - length, to, comp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts the specified range of elements according to the order induced by the specified comparator using Quick Sort,
|
||||
* On top of that allows to sort other things along with it.
|
||||
* This implementation is a custom of <a href="https://github.com/vigna/fastutil">FastUtil</a> quicksort but with a different code structure,
|
||||
* and that sorting Algorithm is based on the tuned quicksort adapted from Jon L. Bentley and M. DouglasMcIlroy, "Engineering a Sort Function", Software: Practice and Experience, 23(11), pages1249−1265, 1993.
|
||||
* @param array the array that needs to be sorted
|
||||
* @param comp the Comparator that decides the sorting order
|
||||
* @param swapper the callback which elements were swapped
|
||||
* @ArrayType(T)
|
||||
* @return input array
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES KEY_TYPE[] indirectQuickSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp, Swapper swapper) {
|
||||
indirectQuickSort(array, 0, array.length, comp, swapper);
|
||||
return array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts the specified range of elements according to the order induced by the specified comparator using Quick Sort,
|
||||
* On top of that allows to sort other things along with it.
|
||||
* This implementation is a custom of <a href="https://github.com/vigna/fastutil">FastUtil</a> quicksort but with a different code structure,
|
||||
* and that sorting Algorithm is based on the tuned quicksort adapted from Jon L. Bentley and M. DouglasMcIlroy, "Engineering a Sort Function", Software: Practice and Experience, 23(11), pages1249−1265, 1993.
|
||||
* @param array the array that needs to be sorted
|
||||
* @param length the maxmium size of the array to be sorted
|
||||
* @param comp the Comparator that decides the sorting order
|
||||
* @param swapper the callback which elements were swapped
|
||||
* @ArrayType(T)
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES void indirectQuickSort(KEY_TYPE[] array, int length, COMPARATOR KEY_GENERIC_TYPE comp, Swapper swapper) {
|
||||
indirectQuickSort(array, 0, length, comp, swapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts the specified range of elements according to the order induced by the specified comparator using Quick Sort,
|
||||
* On top of that allows to sort other things along with it.
|
||||
* This implementation is a custom of <a href="https://github.com/vigna/fastutil">FastUtil</a> quicksort but with a different code structure,
|
||||
* and that sorting Algorithm is based on the tuned quicksort adapted from Jon L. Bentley and M. DouglasMcIlroy, "Engineering a Sort Function", Software: Practice and Experience, 23(11), pages1249−1265, 1993.
|
||||
* @param array the array that needs to be sorted
|
||||
* @param from where the array should be sorted from
|
||||
* @param to where the array should be sorted to
|
||||
* @param comp the Comparator that decides the sorting order
|
||||
* @param swapper the callback which elements were swapped
|
||||
* @ArrayType(T)
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES void indirectQuickSort(KEY_TYPE[] array, int from, int to, COMPARATOR KEY_GENERIC_TYPE comp, Swapper swapper) {
|
||||
int length = to - from;
|
||||
if(length <= 0) return;
|
||||
if(length < BASE_THRESHOLD) {
|
||||
indirectSelectionSort(array, from, to, comp, swapper);
|
||||
return;
|
||||
}
|
||||
KEY_TYPE pivot = array[length > 128 ? subMedium(array, from, from + (length / 2), to - 1, length / 8, comp) : medium(array, from, from + (length / 2), to - 1, comp)];
|
||||
int a = from, b = a, c = to - 1, d = c;
|
||||
for(int compare;;swap(array, b++, c--, swapper)) {
|
||||
for(;b<=c && (compare = comp.compare(array[b], pivot)) <= 0;b++) {
|
||||
if(compare == 0) swap(array, a++, b, swapper);
|
||||
}
|
||||
for(;c>=b && (compare = comp.compare(array[c], pivot)) >= 0;c--) {
|
||||
if(compare == 0) swap(array, c, d--, swapper);
|
||||
}
|
||||
if(b>c) break;
|
||||
}
|
||||
swap(array, from, b, Math.min(a - from, b - a), swapper);
|
||||
swap(array, b, to, Math.min(d - c, to - d - 1), swapper);
|
||||
if((length = b - a) > 1) indirectQuickSort(array, from, from + length, comp, swapper);
|
||||
if((length = d - c) > 1) indirectQuickSort(array, to - length, to, comp, swapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts an array according to the natural ascending order using Quick Sort,
|
||||
* This implementation is a custom of <a href="https://github.com/vigna/fastutil">FastUtil</a> quicksort but with a different code structure,
|
||||
@@ -1279,6 +1663,58 @@ public class ARRAYS
|
||||
quickSort(array, from, to, comp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts the specified range of elements according to the order induced by the specified comparator using Parallel Quick Sort,
|
||||
* On top of that allows to sort other things along with it.
|
||||
* This implementation is a custom of <a href="https://github.com/vigna/fastutil">FastUtil</a> quicksort but with a different code structure,
|
||||
* and that sorting Algorithm is based on the tuned quicksort adapted from Jon L. Bentley and M. DouglasMcIlroy, "Engineering a Sort Function", Software: Practice and Experience, 23(11), pages1249−1265, 1993.
|
||||
* @param array the array that needs to be sorted
|
||||
* @param comp the Comparator that decides the sorting order
|
||||
* @param swapper the callback which elements were swapped
|
||||
* @ArrayType(T)
|
||||
* @note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES void indirectParallelQuickSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp, Swapper swapper) {
|
||||
indirectParallelQuickSort(array, 0, array.length, comp, swapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts the specified range of elements according to the order induced by the specified comparator using Parallel Quick Sort,
|
||||
* On top of that allows to sort other things along with it.
|
||||
* This implementation is a custom of <a href="https://github.com/vigna/fastutil">FastUtil</a> quicksort but with a different code structure,
|
||||
* and that sorting Algorithm is based on the tuned quicksort adapted from Jon L. Bentley and M. DouglasMcIlroy, "Engineering a Sort Function", Software: Practice and Experience, 23(11), pages1249−1265, 1993.
|
||||
* @param array the array that needs to be sorted
|
||||
* @param length the maxmium size of the array to be sorted
|
||||
* @param comp the Comparator that decides the sorting order
|
||||
* @param swapper the callback which elements were swapped
|
||||
* @ArrayType(T)
|
||||
* @note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES void indirectParallelQuickSort(KEY_TYPE[] array, int length, COMPARATOR KEY_GENERIC_TYPE comp, Swapper swapper) {
|
||||
indirectParallelQuickSort(array, 0, length, comp, swapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts the specified range of elements according to the order induced by the specified comparator using Parallel Quick Sort,
|
||||
* On top of that allows to sort other things along with it.
|
||||
* This implementation is a custom of <a href="https://github.com/vigna/fastutil">FastUtil</a> quicksort but with a different code structure,
|
||||
* and that sorting Algorithm is based on the tuned quicksort adapted from Jon L. Bentley and M. DouglasMcIlroy, "Engineering a Sort Function", Software: Practice and Experience, 23(11), pages1249−1265, 1993.
|
||||
* @param array the array that needs to be sorted
|
||||
* @param from where the array should be sorted from
|
||||
* @param to where the array should be sorted to
|
||||
* @param comp the Comparator that decides the sorting order
|
||||
* @param swapper the callback which elements were swapped
|
||||
* @ArrayType(T)
|
||||
* @note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES void indirectParallelQuickSort(KEY_TYPE[] array, int from, int to, COMPARATOR KEY_GENERIC_TYPE comp, Swapper swapper) {
|
||||
if(SanityChecks.canParallelTask() && to - from >= PARALLEL_THRESHOLD) {
|
||||
SanityChecks.invokeTask(new QuickSortActionCompSwapBRACES(array, from, to, comp, swapper));
|
||||
return;
|
||||
}
|
||||
indirectQuickSort(array, from, to, comp, swapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts an array according to the natural ascending order using Parallel Quick Sort,
|
||||
* This implementation is a custom of <a href="https://github.com/vigna/fastutil">FastUtil</a> quicksort but with a different code structure,
|
||||
@@ -1333,6 +1769,18 @@ public class ARRAYS
|
||||
for(int i = 0;i<length;i++,swap(a, from++, to++));
|
||||
}
|
||||
|
||||
static GENERIC_KEY_BRACES void swap(KEY_TYPE[] a, int from, int to, Swapper swapper) {
|
||||
swapper.swap(from, to);
|
||||
KEY_TYPE t = a[from];
|
||||
a[from] = a[to];
|
||||
a[to] = t;
|
||||
}
|
||||
|
||||
static GENERIC_KEY_BRACES void swap(KEY_TYPE[] a, int from, int to, int length, Swapper swapper) {
|
||||
to -= length;
|
||||
for(int i = 0;i<length;i++,swap(a, from++, to++, swapper));
|
||||
}
|
||||
|
||||
static GENERIC_KEY_BRACES int subMedium(KEY_TYPE[] data, int a, int b, int c, int length, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
return medium(data, medium(data, a, a + length, a + (length * 2), comp), medium(data, b - length, b, b + length, comp), medium(data, c - (length * 2), c - length, c, comp), comp);
|
||||
}
|
||||
@@ -1355,16 +1803,14 @@ public class ARRAYS
|
||||
int from;
|
||||
int to;
|
||||
|
||||
QuickSortAction(KEY_TYPE[] array, int from, int to)
|
||||
{
|
||||
QuickSortAction(KEY_TYPE[] array, int from, int to) {
|
||||
this.array = array;
|
||||
this.from = from;
|
||||
this.to = to;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void compute()
|
||||
{
|
||||
protected void compute() {
|
||||
int length = to - from;
|
||||
if(length <= 0) return;
|
||||
if(length < BASE_THRESHOLD) {
|
||||
@@ -1397,8 +1843,7 @@ public class ARRAYS
|
||||
int to;
|
||||
COMPARATOR KEY_GENERIC_TYPE comp;
|
||||
|
||||
QuickSortActionComp(KEY_TYPE[] array, int from, int to, COMPARATOR KEY_GENERIC_TYPE comp)
|
||||
{
|
||||
QuickSortActionComp(KEY_TYPE[] array, int from, int to, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
this.array = array;
|
||||
this.from = from;
|
||||
this.to = to;
|
||||
@@ -1406,8 +1851,7 @@ public class ARRAYS
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void compute()
|
||||
{
|
||||
protected void compute() {
|
||||
int length = to - from;
|
||||
if(length <= 0) return;
|
||||
if(length < BASE_THRESHOLD) {
|
||||
@@ -1433,6 +1877,49 @@ public class ARRAYS
|
||||
}
|
||||
}
|
||||
|
||||
static class QuickSortActionCompSwap KEY_GENERIC_TYPE extends RecursiveAction {
|
||||
private static final long serialVersionUID = 0L;
|
||||
KEY_TYPE[] array;
|
||||
int from;
|
||||
int to;
|
||||
COMPARATOR KEY_GENERIC_TYPE comp;
|
||||
Swapper swapper;
|
||||
|
||||
QuickSortActionCompSwap(KEY_TYPE[] array, int from, int to, COMPARATOR KEY_GENERIC_TYPE comp, Swapper swapper) {
|
||||
this.array = array;
|
||||
this.from = from;
|
||||
this.to = to;
|
||||
this.comp = comp;
|
||||
this.swapper = swapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void compute() {
|
||||
int length = to - from;
|
||||
if(length <= 0) return;
|
||||
if(length < BASE_THRESHOLD) {
|
||||
indirectSelectionSort(array, from, to, comp, swapper);
|
||||
return;
|
||||
}
|
||||
KEY_TYPE pivot = array[length > 128 ? subMedium(array, from, from + (length / 2), to - 1, length / 8, comp) : medium(array, from, from + (length / 2), to - 1, comp)];
|
||||
int a = from, b = a, c = to - 1, d = c;
|
||||
for(int compare;;swap(array, b++, c--, swapper)) {
|
||||
for(;b<=c && (compare = comp.compare(array[b], pivot)) <= 0;b++) {
|
||||
if(compare == 0) swap(array, a++, b, swapper);
|
||||
}
|
||||
for(;c>=b && (compare = comp.compare(array[c], pivot)) >= 0;c--) {
|
||||
if(compare == 0) swap(array, c, d--, swapper);
|
||||
}
|
||||
if(b>c) break;
|
||||
}
|
||||
swap(array, from, b, Math.min(a - from, b - a), swapper);
|
||||
swap(array, b, to, Math.min(d - c, to - d - 1), swapper);
|
||||
if(b - a > 1 && d - c > 1) invokeAll(new QuickSortActionCompSwapBRACES(array, from, from + (b - a), comp, swapper), new QuickSortActionCompSwapBRACES(array, to - (d - c), to, comp, swapper));
|
||||
else if(b - a > 1) new QuickSortActionCompSwapBRACES(array, from, from + (b - a), comp, swapper).invoke();
|
||||
else if(d - c > 1) new QuickSortActionCompSwapBRACES(array, to - (d - c), to, comp, swapper).invoke();
|
||||
}
|
||||
}
|
||||
|
||||
static class MergeSortAction KEY_GENERIC_TYPE extends RecursiveAction {
|
||||
private static final long serialVersionUID = 0L;
|
||||
KEY_TYPE[] array;
|
||||
@@ -1440,8 +1927,7 @@ public class ARRAYS
|
||||
int from;
|
||||
int to;
|
||||
|
||||
MergeSortAction(KEY_TYPE[] array, KEY_TYPE[] supp, int from, int to)
|
||||
{
|
||||
MergeSortAction(KEY_TYPE[] array, KEY_TYPE[] supp, int from, int to) {
|
||||
this.array = array;
|
||||
this.supp = supp;
|
||||
this.from = from;
|
||||
@@ -1449,8 +1935,7 @@ public class ARRAYS
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void compute()
|
||||
{
|
||||
protected void compute() {
|
||||
if(to - from < BASE_THRESHOLD) {
|
||||
insertionSort(array, from, to);
|
||||
return;
|
||||
@@ -1478,8 +1963,7 @@ public class ARRAYS
|
||||
int to;
|
||||
COMPARATOR KEY_GENERIC_TYPE comp;
|
||||
|
||||
MergeSortActionComp(KEY_TYPE[] array, KEY_TYPE[] supp, int from, int to, COMPARATOR KEY_GENERIC_TYPE comp)
|
||||
{
|
||||
MergeSortActionComp(KEY_TYPE[] array, KEY_TYPE[] supp, int from, int to, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
this.array = array;
|
||||
this.supp = supp;
|
||||
this.from = from;
|
||||
@@ -1488,8 +1972,7 @@ public class ARRAYS
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void compute()
|
||||
{
|
||||
protected void compute() {
|
||||
if(to - from < BASE_THRESHOLD) {
|
||||
insertionSort(array, from, to, comp);
|
||||
return;
|
||||
@@ -1509,22 +1992,64 @@ public class ARRAYS
|
||||
}
|
||||
}
|
||||
|
||||
static class MergeSortActionCompSwap KEY_GENERIC_TYPE extends RecursiveAction {
|
||||
private static final long serialVersionUID = 0L;
|
||||
KEY_TYPE[] array;
|
||||
KEY_TYPE[] supp;
|
||||
int from;
|
||||
int to;
|
||||
COMPARATOR KEY_GENERIC_TYPE comp;
|
||||
Swapper swapper;
|
||||
|
||||
MergeSortActionCompSwap(KEY_TYPE[] array, KEY_TYPE[] supp, int from, int to, COMPARATOR KEY_GENERIC_TYPE comp, Swapper swapper) {
|
||||
this.array = array;
|
||||
this.supp = supp;
|
||||
this.from = from;
|
||||
this.to = to;
|
||||
this.comp = comp;
|
||||
this.swapper = swapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void compute() {
|
||||
if(to - from < BASE_THRESHOLD) {
|
||||
indirectInsertionSort(array, from, to, comp, swapper);
|
||||
return;
|
||||
}
|
||||
if(supp == null) supp = Arrays.copyOf(array, to);
|
||||
int mid = (from + to) >>> 1;
|
||||
invokeAll(new MergeSortActionCompSwapBRACES(supp, array, from, mid, comp, swapper), new MergeSortActionCompSwapBRACES(supp, array, mid, to, comp, swapper));
|
||||
if(comp.compare(supp[mid - 1], supp[mid]) <= 0)
|
||||
{
|
||||
System.arraycopy(supp, from, array, from, to - from);
|
||||
return;
|
||||
}
|
||||
for(int p = from, q = mid;from < to;from++) {
|
||||
if(q >= to || p < mid && comp.compare(supp[p], supp[q]) < 0) {
|
||||
swapper.swap(from, p);
|
||||
array[from] = supp[p++];
|
||||
continue;
|
||||
}
|
||||
swapper.swap(from, q);
|
||||
array[from] = supp[q++];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static class MemFreeMergeSortAction KEY_GENERIC_TYPE extends RecursiveAction {
|
||||
private static final long serialVersionUID = 0L;
|
||||
KEY_TYPE[] array;
|
||||
int from;
|
||||
int to;
|
||||
|
||||
MemFreeMergeSortAction(KEY_TYPE[] array, int from, int to)
|
||||
{
|
||||
MemFreeMergeSortAction(KEY_TYPE[] array, int from, int to) {
|
||||
this.array = array;
|
||||
this.from = from;
|
||||
this.to = to;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void compute()
|
||||
{
|
||||
protected void compute() {
|
||||
if(to - from < BASE_THRESHOLD) {
|
||||
insertionSort(array, from, to);
|
||||
return;
|
||||
@@ -1570,8 +2095,7 @@ public class ARRAYS
|
||||
int to;
|
||||
COMPARATOR KEY_GENERIC_TYPE comp;
|
||||
|
||||
MemFreeMergeSortActionComp(KEY_TYPE[] array, int from, int to, COMPARATOR KEY_GENERIC_TYPE comp)
|
||||
{
|
||||
MemFreeMergeSortActionComp(KEY_TYPE[] array, int from, int to, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
this.array = array;
|
||||
this.from = from;
|
||||
this.to = to;
|
||||
@@ -1579,8 +2103,7 @@ public class ARRAYS
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void compute()
|
||||
{
|
||||
protected void compute() {
|
||||
if(to - from < BASE_THRESHOLD) {
|
||||
insertionSort(array, from, to, comp);
|
||||
return;
|
||||
|
||||
+212
-42
@@ -7,40 +7,91 @@ import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.concurrent.locks.LockSupport;
|
||||
import java.util.function.Consumer;
|
||||
#if JDK_TYPE
|
||||
import java.util.OPTIONAL;
|
||||
#else
|
||||
import speiger.src.collections.PACKAGE.functions.OPTIONAL;
|
||||
#endif
|
||||
#if !TYPE_OBJECT
|
||||
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
#else
|
||||
import java.util.function.IntFunction;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.Comparator;
|
||||
|
||||
#iterate
|
||||
#argument MAPPER Predicate ToByteFunction ToShortFunction ToIntFunction ToLongFunction ToFloatFunction ToDoubleFunction
|
||||
#argument BUILDER BooleanAsyncBuilder ByteAsyncBuilder ShortAsyncBuilder IntAsyncBuilder LongAsyncBuilder FloatAsyncBuilder DoubleAsyncBuilder
|
||||
#argument PACKAGE booleans bytes shorts ints longs floats doubles
|
||||
#argument CHECK BOOLEAN_ASYNC_MODULE BYTE_ASYNC_MODULE SHORT_ASYNC_MODULE INT_ASYNC_MODULE LONG_ASYNC_MODULE FLOAT_ASYNC_MODULE DOUBLE_ASYNC_MODULE
|
||||
#if CHECK
|
||||
import speiger.src.collections.objects.functions.function.MAPPER;
|
||||
import speiger.src.collections.PACKAGE.utils.BUILDER;
|
||||
#endif
|
||||
#enditerate
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.collections.ITERABLE;
|
||||
#if OBJECT_ASYNC_MODULE
|
||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.functions.TASK;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||
import speiger.src.collections.PACKAGE.functions.function.TO_OBJECT_FUNCTION;
|
||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||
import speiger.src.collections.PACKAGE.lists.ARRAY_LIST;
|
||||
import speiger.src.collections.PACKAGE.lists.LIST;
|
||||
#if !TYPE_BOOLEAN
|
||||
import speiger.src.collections.PACKAGE.sets.SET;
|
||||
import speiger.src.collections.PACKAGE.sets.LINKED_HASH_SET;
|
||||
#endif
|
||||
#if !TYPE_BOOLEAN
|
||||
#if OBJECT_ASYNC_MODULE
|
||||
import speiger.src.collections.PACKAGE.functions.function.TO_OBJECT_FUNCTION;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||
#if ARRAY_LIST_FEATURE || LINKED_LIST_FEATURE
|
||||
import speiger.src.collections.PACKAGE.lists.LIST;
|
||||
#if ARRAY_LIST_FEATURE
|
||||
import speiger.src.collections.PACKAGE.lists.ARRAY_LIST;
|
||||
#else if LINKED_LIST_FEATURE
|
||||
import speiger.src.collections.PACKAGE.lists.LINKED_LIST;
|
||||
#endif
|
||||
#endif
|
||||
#if !TYPE_BOOLEAN && OBJECT_ASYNC_MODULE
|
||||
#if SET_MODULE
|
||||
#if LINKED_SET_FEATURE || LINKED_CUSTOM_SET_FEATURE || SET_FEATURE || CUSTOM_SET_FEATURE || RB_TREE_SET_FEATURE || AVL_TREE_SET_FEATURE || ARRAY_SET_FEATURE
|
||||
import speiger.src.collections.PACKAGE.sets.SET;
|
||||
#if LINKED_SET_FEATURE
|
||||
import speiger.src.collections.PACKAGE.sets.LINKED_HASH_SET;
|
||||
#else if LINKED_CUSTOM_SET_FEATURE
|
||||
import speiger.src.collections.PACKAGE.sets.LINKED_CUSTOM_HASH_SET;
|
||||
#else if SET_FEATURE
|
||||
import speiger.src.collections.PACKAGE.sets.HASH_SET;
|
||||
#else if CUSTOM_SET_FEATURE
|
||||
import speiger.src.collections.PACKAGE.sets.CUSTOM_HASH_SET;
|
||||
#else if RB_TREE_SET_FEATURE
|
||||
import speiger.src.collections.PACKAGE.sets.RB_TREE_SET;
|
||||
#else if AVL_TREE_SET_FEATURE
|
||||
import speiger.src.collections.PACKAGE.sets.AVL_TREE_SET;
|
||||
#else if ARRAY_SET_FEATURE
|
||||
import speiger.src.collections.PACKAGE.sets.ARRAY_SET;
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#if !TYPE_BOOLEAN && BOOLEAN_ASYNC_MODULE
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.booleans.utils.BooleanAsyncBuilder;
|
||||
#endif
|
||||
import speiger.src.collections.booleans.utils.BooleanAsyncBuilder.BaseBooleanTask;
|
||||
#endif
|
||||
#if !TYPE_OBJECT
|
||||
#if !TYPE_OBJECT && OBJECT_ASYNC_MODULE
|
||||
import speiger.src.collections.objects.utils.ObjectAsyncBuilder;
|
||||
import speiger.src.collections.objects.utils.ObjectAsyncBuilder.BaseObjectTask;
|
||||
#endif
|
||||
#if !TYPE_INT
|
||||
#if !TYPE_INT && INT_ASYNC_MODULE
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.ints.utils.IntAsyncBuilder;
|
||||
#endif
|
||||
import speiger.src.collections.ints.utils.IntAsyncBuilder.BaseIntTask;
|
||||
#endif
|
||||
import speiger.src.collections.utils.ISizeProvider;
|
||||
import speiger.src.collections.utils.SanityChecks;
|
||||
|
||||
/**
|
||||
@@ -113,6 +164,7 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE
|
||||
return new ASYNC_BUILDERBRACES(ITERABLES.wrap(iterable));
|
||||
}
|
||||
|
||||
#if ARRAY_LIST_FEATURE
|
||||
/**
|
||||
* Helper function that automatically wraps a array into a AsyncBuilder since it forces this collections Iterable.
|
||||
* @param values that should be wrapped
|
||||
@@ -123,6 +175,8 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE
|
||||
return new ASYNC_BUILDERBRACES(ARRAY_LIST.wrap(values));
|
||||
}
|
||||
|
||||
#endif
|
||||
#if OBJECT_ASYNC_MODULE
|
||||
/**
|
||||
* Maps the elements to something else
|
||||
* @param mapper the mapping function
|
||||
@@ -154,6 +208,26 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE
|
||||
return new ObjectAsyncBuilder<>(ITERABLES.arrayFlatMap(iterable, mapper));
|
||||
}
|
||||
|
||||
#endif
|
||||
#if TYPE_OBJECT
|
||||
#iterate
|
||||
#argument BUILDER BooleanAsyncBuilder ByteAsyncBuilder ShortAsyncBuilder IntAsyncBuilder LongAsyncBuilder FloatAsyncBuilder DoubleAsyncBuilder
|
||||
#argument MAPPER Predicate ToByteFunction ToShortFunction ToIntFunction ToLongFunction ToFloatFunction ToDoubleFunction
|
||||
#argument TYPE Boolean Byte Short Int Long Float Double
|
||||
#argument CHECK BOOLEAN_ASYNC_MODULE BYTE_ASYNC_MODULE SHORT_ASYNC_MODULE INT_ASYNC_MODULE LONG_ASYNC_MODULE FLOAT_ASYNC_MODULE DOUBLE_ASYNC_MODULE
|
||||
#if CHECK
|
||||
/**
|
||||
* Maps the elements to something else
|
||||
* @param mapper the mapping function
|
||||
* @return a new Builder Object with the mapped Iterable
|
||||
*/
|
||||
public BUILDER mapToTYPE(MAPPER<T> mapper) {
|
||||
return new BUILDER(ITERABLES.mapToTYPE(iterable, mapper));
|
||||
}
|
||||
|
||||
#endif
|
||||
#enditerate
|
||||
#endif
|
||||
/**
|
||||
* Filters out the unwanted elements out of the Iterable
|
||||
* @param filter the elements that should be kept
|
||||
@@ -173,6 +247,16 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Repeats the elements inside of the Iterable
|
||||
* @param repeats the amount of times the elements should be repeated
|
||||
* @return self with a repeater applied
|
||||
*/
|
||||
public ASYNC_BUILDER KEY_GENERIC_TYPE repeat(int repeats) {
|
||||
iterable = ITERABLES.repeat(iterable, repeats);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Limits how many elements are inside of the Iterable
|
||||
* @param limit how many elements should max be iterated through
|
||||
@@ -204,6 +288,7 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE
|
||||
return this;
|
||||
}
|
||||
|
||||
#if OBJECT_ASYNC_MODULE
|
||||
/**
|
||||
* Iterates over the Iterable with a desired action
|
||||
* @param action that should be applied
|
||||
@@ -213,14 +298,14 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE
|
||||
return new ObjectAsyncBuilder<>(new ForEachTask<>(iterable.iterator(), action));
|
||||
}
|
||||
|
||||
#endif
|
||||
/**
|
||||
* Reduces the elements inside of the Iterable down to one element
|
||||
* @param operator that reduces the elements.
|
||||
* @return self with the reduce action applied
|
||||
*/
|
||||
public ASYNC_BUILDER KEY_GENERIC_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
task = new SimpleReduceTaskBRACES(iterable.iterator(), operator);
|
||||
return this;
|
||||
public ObjectAsyncBuilder<OPTIONAL KEY_GENERIC_TYPE> reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
return new ObjectAsyncBuilder<>(new SimpleReduceTaskBRACES(iterable.iterator(), operator));
|
||||
}
|
||||
|
||||
#if TYPE_OBJECT
|
||||
@@ -247,23 +332,66 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE
|
||||
}
|
||||
|
||||
#endif
|
||||
#if OBJECT_ASYNC_MODULE
|
||||
#if TYPE_OBJECT
|
||||
/**
|
||||
* Pours all elements of the Iterable down into a Array.
|
||||
* @param action creates the final array that should be copied into.
|
||||
* @return a new Builder with the ToArray function applied
|
||||
*/
|
||||
public ObjectAsyncBuilder<KEY_TYPE[]> TO_ARRAY(IntFunction<KEY_TYPE[]> action) {
|
||||
return new ObjectAsyncBuilder<>(new ArrayTaskBRACES(iterable, action));
|
||||
}
|
||||
|
||||
#else
|
||||
/**
|
||||
* Pours all elements of the Iterable down into a Array.
|
||||
* @return a new Builder with the ToArray function applied
|
||||
*/
|
||||
public ObjectAsyncBuilder<KEY_TYPE[]> TO_ARRAY() {
|
||||
return new ObjectAsyncBuilder<>(new ArrayTaskBRACES(iterable));
|
||||
}
|
||||
|
||||
#endif
|
||||
#if ARRAY_LIST_FEATURE || LINKED_LIST_FEATURE
|
||||
/**
|
||||
* Pours all elements into a List that can be later
|
||||
* @return a new Builder with the pour function applied
|
||||
*/
|
||||
public ObjectAsyncBuilder<LIST KEY_GENERIC_TYPE> pourAsList() {
|
||||
#if ARRAY_LIST_FEATURE
|
||||
return pour(new ARRAY_LISTBRACES());
|
||||
#else
|
||||
return pour(new LINKED_LISTBRACES());
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !TYPE_BOOLEAN
|
||||
#endif
|
||||
#if !TYPE_BOOLEAN && SET_MODULE
|
||||
#if LINKED_SET_FEATURE || LINKED_CUSTOM_SET_FEATURE || SET_FEATURE || CUSTOM_SET_FEATURE || RB_TREE_SET_FEATURE || AVL_TREE_SET_FEATURE || ARRAY_SET_FEATURE
|
||||
/**
|
||||
* Pours all elements into a Set that can be later
|
||||
* @return a new Builder with the pour function applied
|
||||
*/
|
||||
public ObjectAsyncBuilder<SET KEY_GENERIC_TYPE> pourAsSet() {
|
||||
#if LINKED_SET_FEATURE
|
||||
return pour(new LINKED_HASH_SETBRACES());
|
||||
#else if LINKED_CUSTOM_SET_FEATURE
|
||||
return pour(new LINKED_CUSTOM_HASH_SETBRACES(STRATEGY.normalStrategy()));
|
||||
#else if SET_FEATURE
|
||||
return pour(new HASH_SETBRACES());
|
||||
#else if CUSTOM_SET_FEATURE
|
||||
return pour(new CUSTOM_HASH_SETBRACES(STRATEGY.normalStrategy()));
|
||||
#else if RB_TREE_SET_FEATURE
|
||||
return pour(new RB_Tree_SETBRACES());
|
||||
#else if AVL_TREE_SET_FEATURE
|
||||
return pour(new AVL_Tree_SETBRACES());
|
||||
#else if ARRAY_SET_FEATURE
|
||||
return pour(new ARRAY_SETBRACES());
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
/**
|
||||
* Pours all elements into a collection that can be later
|
||||
@@ -275,6 +403,8 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE
|
||||
return new ObjectAsyncBuilder<>(new CollectTask<>(iterable.iterator(), collection));
|
||||
}
|
||||
|
||||
#endif
|
||||
#if BOOLEAN_ASYNC_MODULE
|
||||
/**
|
||||
* Searches through the elements of the Iterable to find if the desired element is present.
|
||||
* @param filter that decides the desired elements
|
||||
@@ -302,17 +432,18 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE
|
||||
return new BooleanAsyncBuilder(new MatchTaskBRACES(iterable.iterator(), filter, 2));
|
||||
}
|
||||
|
||||
#endif
|
||||
/**
|
||||
* Searches through the elements of the Iterable to find if the desired element.
|
||||
* If not present it will return the default value of the type
|
||||
* @param filter that decides the desired elements
|
||||
* @return self with the findFirst function applied
|
||||
*/
|
||||
public ASYNC_BUILDER KEY_GENERIC_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
task = new FindFirstTaskBRACES(iterable.iterator(), filter);
|
||||
return this;
|
||||
public ObjectAsyncBuilder<OPTIONAL KEY_GENERIC_TYPE> findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
return new ObjectAsyncBuilder<>(new FindFirstTaskBRACES(iterable.iterator(), filter));
|
||||
}
|
||||
|
||||
#if INT_ASYNC_MODULE
|
||||
/**
|
||||
* Counts all desired elements inside the Iterable
|
||||
* @param filter that decides the desired elements
|
||||
@@ -322,6 +453,7 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE
|
||||
return new IntAsyncBuilder(new CountTaskBRACES(iterable.iterator(), filter));
|
||||
}
|
||||
|
||||
#endif
|
||||
/**
|
||||
* Optional way to add a custom executor that runs this offthread task.
|
||||
* Can only be set after the action was decided on.
|
||||
@@ -461,7 +593,7 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE
|
||||
}
|
||||
|
||||
#endif
|
||||
private static class SimpleReduceTask KEY_GENERIC_TYPE extends BASE_TASK KEY_GENERIC_TYPE
|
||||
private static class SimpleReduceTask KEY_GENERIC_TYPE extends BaseObjectTask<OPTIONAL KEY_GENERIC_TYPE>
|
||||
{
|
||||
ITERATOR KEY_GENERIC_TYPE iter;
|
||||
UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator;
|
||||
@@ -471,6 +603,7 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE
|
||||
public SimpleReduceTask(ITERATOR KEY_GENERIC_TYPE iter, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
this.iter = iter;
|
||||
this.operator = operator;
|
||||
this.setResult(OPTIONAL.empty());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -485,7 +618,7 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE
|
||||
}
|
||||
}
|
||||
if(!iter.hasNext()) {
|
||||
setResult(value);
|
||||
setResult(OPTIONAL.GET_OPTIONAL(value));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -502,6 +635,7 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE
|
||||
}
|
||||
}
|
||||
|
||||
#if BOOLEAN_ASYNC_MODULE
|
||||
private static class MatchTask KEY_GENERIC_TYPE extends BaseBooleanTask
|
||||
{
|
||||
ITERATOR KEY_GENERIC_TYPE iter;
|
||||
@@ -520,11 +654,7 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE
|
||||
switch(type) {
|
||||
case 0:
|
||||
while(shouldRun() && iter.hasNext()) {
|
||||
#if TYPE_OBJECT
|
||||
if(filter.getBoolean(iter.NEXT())) {
|
||||
#else
|
||||
if(filter.GET_VALUE(iter.NEXT())) {
|
||||
#endif
|
||||
if(filter.test(iter.NEXT())) {
|
||||
setResult(true);
|
||||
return true;
|
||||
}
|
||||
@@ -532,11 +662,7 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE
|
||||
break;
|
||||
case 1:
|
||||
while(shouldRun() && iter.hasNext()) {
|
||||
#if TYPE_OBJECT
|
||||
if(filter.getBoolean(iter.NEXT())) {
|
||||
#else
|
||||
if(filter.GET_VALUE(iter.NEXT())) {
|
||||
#endif
|
||||
if(filter.test(iter.NEXT())) {
|
||||
setResult(false);
|
||||
return true;
|
||||
}
|
||||
@@ -544,11 +670,7 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE
|
||||
break;
|
||||
case 2:
|
||||
while(shouldRun() && iter.hasNext()) {
|
||||
#if TYPE_OBJECT
|
||||
if(!filter.getBoolean(iter.NEXT())) {
|
||||
#else
|
||||
if(!filter.GET_VALUE(iter.NEXT())) {
|
||||
#endif
|
||||
if(!filter.test(iter.NEXT())) {
|
||||
setResult(false);
|
||||
return true;
|
||||
}
|
||||
@@ -570,7 +692,8 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE
|
||||
}
|
||||
}
|
||||
|
||||
private static class FindFirstTask KEY_GENERIC_TYPE extends BASE_TASK KEY_GENERIC_TYPE
|
||||
#endif
|
||||
private static class FindFirstTask KEY_GENERIC_TYPE extends BaseObjectTask<OPTIONAL KEY_GENERIC_TYPE>
|
||||
{
|
||||
ITERATOR KEY_GENERIC_TYPE iter;
|
||||
PREDICATE KEY_GENERIC_TYPE filter;
|
||||
@@ -578,18 +701,15 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE
|
||||
public FindFirstTask(ITERATOR KEY_GENERIC_TYPE iter, PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
this.iter = iter;
|
||||
this.filter = filter;
|
||||
this.setResult(OPTIONAL.empty());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean execute() throws Exception {
|
||||
while(shouldRun() && iter.hasNext()) {
|
||||
KEY_TYPE entry = iter.NEXT();
|
||||
#if TYPE_OBJECT
|
||||
if(filter.getBoolean(iter.NEXT())) {
|
||||
#else
|
||||
if(filter.GET_VALUE(iter.NEXT())) {
|
||||
#endif
|
||||
setResult(entry);
|
||||
if(filter.test(iter.NEXT())) {
|
||||
setResult(OPTIONAL.GET_OPTIONAL(entry));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -604,6 +724,7 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE
|
||||
}
|
||||
}
|
||||
|
||||
#if INT_ASYNC_MODULE
|
||||
private static class CountTask KEY_GENERIC_TYPE extends BaseIntTask
|
||||
{
|
||||
ITERATOR KEY_GENERIC_TYPE iter;
|
||||
@@ -618,7 +739,7 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE
|
||||
@Override
|
||||
protected boolean execute() throws Exception {
|
||||
while(shouldRun() && iter.hasNext()) {
|
||||
if(filter.TEST_VALUE(iter.NEXT())) {
|
||||
if(filter.test(iter.NEXT())) {
|
||||
counted++;
|
||||
}
|
||||
}
|
||||
@@ -638,6 +759,8 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
#if OBJECT_ASYNC_MODULE
|
||||
private static class CollectTask KSS_GENERIC_TYPE<V, T extends COLLECTION KEY_SPECIAL_GENERIC_TYPE<V>> extends BaseObjectTask<T>
|
||||
{
|
||||
ITERATOR KEY_SPECIAL_GENERIC_TYPE<V> iter;
|
||||
@@ -668,6 +791,52 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE
|
||||
}
|
||||
}
|
||||
|
||||
private static class ArrayTask KEY_GENERIC_TYPE extends BaseObjectTask<KEY_TYPE[]>
|
||||
{
|
||||
ITERATOR KEY_GENERIC_TYPE iter;
|
||||
COLLECTIONS.CollectionWrapper KEY_GENERIC_TYPE wrapper;
|
||||
#if TYPE_OBJECT
|
||||
IntFunction<KEY_TYPE[]> builder;
|
||||
|
||||
public ArrayTask(ITERABLE KEY_GENERIC_TYPE iterable, IntFunction<KEY_TYPE[]> builder) {
|
||||
this.builder = builder;
|
||||
#else
|
||||
|
||||
public ArrayTask(ITERABLE KEY_GENERIC_TYPE iterable) {
|
||||
#endif
|
||||
iter = iterable.iterator();
|
||||
ISizeProvider prov = ISizeProvider.of(iterable);
|
||||
int size = prov == null ? -1 : prov.size();
|
||||
wrapper = size < 0 ? COLLECTIONS.wrapper() : COLLECTIONS.wrapper(size);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean execute() throws Exception {
|
||||
while(shouldRun() && iter.hasNext()) {
|
||||
wrapper.add(iter.NEXT());
|
||||
}
|
||||
if(!iter.hasNext()) {
|
||||
#if TYPE_OBJECT
|
||||
setResult(wrapper.TO_ARRAY(builder));
|
||||
#else
|
||||
setResult(wrapper.TO_ARRAY());
|
||||
#endif
|
||||
wrapper = null;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCompletion() {
|
||||
super.onCompletion();
|
||||
iter = null;
|
||||
#if TYPE_OBJECT
|
||||
builder = null;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
private static class ForEachTask<T> extends BaseObjectTask<Void>
|
||||
{
|
||||
ITERATOR KEY_GENERIC_TYPE iter;
|
||||
@@ -694,6 +863,7 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
/**
|
||||
* Base Task of the Actions that can be performed.
|
||||
* Allows to simplify the actions that get executed.
|
||||
|
||||
+711
-10
@@ -1,26 +1,57 @@
|
||||
package speiger.src.collections.PACKAGE.utils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
#if !TYPE_BOOLEAN
|
||||
import java.util.ConcurrentModificationException;
|
||||
#endif
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Objects;
|
||||
#if JDK_TYPE
|
||||
import java.util.OPTIONAL;
|
||||
#endif
|
||||
#if TYPE_OBJECT
|
||||
import java.util.Comparator;
|
||||
import java.util.function.BiFunction;
|
||||
#endif
|
||||
import java.util.function.Predicate;
|
||||
#if PRIMITIVES
|
||||
#if JDK_FUNCTION && !TYPE_OBJECT
|
||||
import java.util.function.PREDICATE;
|
||||
#endif
|
||||
#if PRIMITIVES && !JDK_FUNCTION
|
||||
import java.util.function.JAVA_PREDICATE;
|
||||
#endif
|
||||
import java.util.function.Consumer;
|
||||
|
||||
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.objects.utils.ObjectArrays;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
||||
#if ORDERED_MAP_FEATURE
|
||||
import speiger.src.collections.PACKAGE.collections.ORDERED_COLLECTION;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
#endif
|
||||
#if !JDK_TYPE
|
||||
import speiger.src.collections.PACKAGE.functions.OPTIONAL;
|
||||
#endif
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.objects.utils.ObjectArrays;
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
#endif
|
||||
#if !JDK_FUNCTION
|
||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||
import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
|
||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||
#if !TYPE_BOOLEAN
|
||||
import speiger.src.collections.utils.HashUtil;
|
||||
#endif
|
||||
import speiger.src.collections.utils.ITrimmable;
|
||||
import speiger.src.collections.utils.SanityChecks;
|
||||
|
||||
/**
|
||||
* A Helper class for Collections
|
||||
*/
|
||||
@@ -54,6 +85,37 @@ public class COLLECTIONS
|
||||
return c instanceof UnmodifiableCollection ? c : new UnmodifiableCollectionBRACES(c);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Immutable Ordered Collection instance based on the instance given.
|
||||
* @param c that should be made immutable/unmodifiable
|
||||
* @Type(T)
|
||||
* @return a unmodifiable Ordered collection wrapper. If the Collection already a unmodifiable wrapper then it just returns itself.
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES ORDERED_COLLECTION KEY_GENERIC_TYPE unmodifiable(ORDERED_COLLECTION KEY_GENERIC_TYPE c) {
|
||||
return c instanceof UnmodifiableOrderedCollection ? c : new UnmodifiableOrderedCollectionBRACES(c);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a synchronized ordered Collection instance based on the instance given.
|
||||
* @param c that should be synchronized
|
||||
* @Type(T)
|
||||
* @return a synchronized ordered collection wrapper. If the Collection already a synchronized wrapper then it just returns itself.
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES ORDERED_COLLECTION KEY_GENERIC_TYPE synchronize(ORDERED_COLLECTION KEY_GENERIC_TYPE c) {
|
||||
return c instanceof SynchronizedOrderedCollection ? c : new SynchronizedOrderedCollectionBRACES(c);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a synchronized ordered Collection instance based on the instance given.
|
||||
* @param c that should be synchronized
|
||||
* @param mutex is the controller of the synchronization block.
|
||||
* @Type(T)
|
||||
* @return a synchronized ordered collection wrapper. If the Collection already a synchronized wrapper then it just returns itself.
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES ORDERED_COLLECTION KEY_GENERIC_TYPE synchronize(ORDERED_COLLECTION KEY_GENERIC_TYPE c, Object mutex) {
|
||||
return c instanceof SynchronizedOrderedCollection ? c : new SynchronizedOrderedCollectionBRACES(c, mutex);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a synchronized Collection instance based on the instance given.
|
||||
* @param c that should be synchronized
|
||||
@@ -75,6 +137,613 @@ public class COLLECTIONS
|
||||
return c instanceof SynchronizedCollection ? c : new SynchronizedCollectionBRACES(c, mutex);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Singleton Collection of a given element
|
||||
* @param element the element that should be converted into a singleton collection
|
||||
* @Type(T)
|
||||
* @return a singletoncollection of the given element
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES COLLECTION KEY_GENERIC_TYPE singleton(KEY_TYPE element) {
|
||||
return new SingletonCollectionBRACES(element);
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal Use mainly. Its a collection wrapper with 0 dependencies for those actions where a collector is needed.
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES CollectionWrapper KEY_GENERIC_TYPE wrapper() {
|
||||
return new CollectionWrapperBRACES();
|
||||
}
|
||||
|
||||
protected static GENERIC_KEY_BRACES CollectionWrapper KEY_GENERIC_TYPE wrapper(int size) {
|
||||
return new CollectionWrapperBRACES(size);
|
||||
}
|
||||
|
||||
#if !TYPE_BOOLEAN
|
||||
protected static GENERIC_KEY_BRACES DistinctCollectionWrapper KEY_GENERIC_TYPE distinctWrapper() {
|
||||
return new DistinctCollectionWrapperBRACES();
|
||||
}
|
||||
|
||||
protected static GENERIC_KEY_BRACES DistinctCollectionWrapper KEY_GENERIC_TYPE distinctWrapper(int size) {
|
||||
return new DistinctCollectionWrapperBRACES(size);
|
||||
}
|
||||
|
||||
#endif
|
||||
protected static class CollectionWrapper KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION KEY_GENERIC_TYPE implements ITrimmable {
|
||||
KEY_TYPE[] elements;
|
||||
int size = 0;
|
||||
|
||||
public CollectionWrapper() {
|
||||
this(10);
|
||||
}
|
||||
|
||||
public CollectionWrapper(int size) {
|
||||
if(size < 0) throw new IllegalStateException("Size has to be 0 or greater");
|
||||
elements = NEW_KEY_ARRAY(size);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean add(KEY_TYPE o) {
|
||||
if(size >= elements.length) elements = Arrays.copyOf(elements, (int)Math.min((long)elements.length + (elements.length >> 1), SanityChecks.MAX_ARRAY_SIZE));
|
||||
elements[size++] = o;
|
||||
return true;
|
||||
}
|
||||
|
||||
public KEY_TYPE GET_KEY(int index) {
|
||||
if(index < 0 || index >= size) throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + size);
|
||||
return elements[index];
|
||||
}
|
||||
|
||||
#if TYPE_OBJECT
|
||||
@Override
|
||||
public boolean remove(Object e) {
|
||||
for(int i = 0;i<size;i++) {
|
||||
if(KEY_EQUALS(elements[i], e)) {
|
||||
removeIndex(i);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
#else
|
||||
@Override
|
||||
public boolean REMOVE_KEY(KEY_TYPE e) {
|
||||
for(int i = 0;i<size;i++) {
|
||||
if(KEY_EQUALS(elements[i], e)) {
|
||||
removeIndex(i);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
#endif
|
||||
private void removeIndex(int index) {
|
||||
if(index < 0 || index >= size) throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + size);
|
||||
size--;
|
||||
if(index != size) System.arraycopy(elements, index+1, elements, index, size - index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITERATOR KEY_GENERIC_TYPE iterator() {
|
||||
return new ITERATOR KEY_GENERIC_TYPE() {
|
||||
int index = 0;
|
||||
int lastReturned = -1;
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return index < size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE NEXT() {
|
||||
int i = index++;
|
||||
return elements[(lastReturned = i)];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
if(lastReturned == -1) throw new IllegalStateException();
|
||||
removeIndex(lastReturned);
|
||||
index = lastReturned;
|
||||
lastReturned = -1;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
#if TYPE_OBJECT
|
||||
for(int i = 0;i<size;elements[i] = null,i++);
|
||||
#endif
|
||||
size = 0;
|
||||
}
|
||||
|
||||
#if TYPE_OBJECT
|
||||
public void sort(Comparator<? super CLASS_TYPE> c) {
|
||||
if(c != null) ARRAYS.stableSort(elements, size, c);
|
||||
else ARRAYS.stableSort(elements, size);
|
||||
}
|
||||
|
||||
public void unstableSort(Comparator<? super CLASS_TYPE> c) {
|
||||
if(c != null) ARRAYS.unstableSort(elements, size, c);
|
||||
else ARRAYS.unstableSort(elements, size);
|
||||
}
|
||||
|
||||
#else
|
||||
public void sort(COMPARATOR c) {
|
||||
if(c != null) ARRAYS.stableSort(elements, size, c);
|
||||
else ARRAYS.stableSort(elements, size);
|
||||
}
|
||||
|
||||
public void unstableSort(COMPARATOR c) {
|
||||
if(c != null) ARRAYS.unstableSort(elements, size, c);
|
||||
else ARRAYS.unstableSort(elements, size);
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) {
|
||||
Objects.requireNonNull(action);
|
||||
for(int i = 0;i<size;i++)
|
||||
action.accept(elements[i]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
for(int i = 0;i<size;i++)
|
||||
action.accept(input, elements[i]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean trim(int size) {
|
||||
if(size > size() || size() == elements.length) return false;
|
||||
int value = Math.max(size, size());
|
||||
elements = value == 0 ? EMPTY_KEY_ARRAY : Arrays.copyOf(elements, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearAndTrim(int size) {
|
||||
if(elements.length <= size) {
|
||||
clear();
|
||||
return;
|
||||
}
|
||||
elements = size == 0 ? EMPTY_KEY_ARRAY : NEW_KEY_ARRAY(size);
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Primitive
|
||||
public Object[] toArray() {
|
||||
Object[] obj = new Object[size];
|
||||
for(int i = 0;i<size;i++)
|
||||
obj[i] = KEY_TO_OBJ(elements[i]);
|
||||
return obj;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Primitive
|
||||
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(elements, 0, a, 0, size);
|
||||
#else
|
||||
for(int i = 0;i<size;i++)
|
||||
a[i] = (E)KEY_TO_OBJ(elements[i]);
|
||||
#endif
|
||||
if (a.length > size) a[size] = null;
|
||||
return a;
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public KEY_TYPE[] TO_ARRAY(KEY_TYPE[] a) {
|
||||
if(a.length < size) a = new KEY_TYPE[size];
|
||||
System.arraycopy(elements, 0, a, 0, size);
|
||||
if (a.length > size) a[size] = EMPTY_KEY_VALUE;
|
||||
return a;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !TYPE_BOOLEAN
|
||||
protected static class DistinctCollectionWrapper KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION KEY_GENERIC_TYPE {
|
||||
KEY_TYPE[] keys;
|
||||
boolean containsNull;
|
||||
int minCapacity;
|
||||
int nullIndex;
|
||||
int maxFill;
|
||||
int mask;
|
||||
int size;
|
||||
|
||||
public DistinctCollectionWrapper() {
|
||||
this(HashUtil.DEFAULT_MIN_CAPACITY);
|
||||
}
|
||||
|
||||
public DistinctCollectionWrapper(int size) {
|
||||
if(minCapacity < 0) throw new IllegalStateException("Minimum Capacity is negative. This is not allowed");
|
||||
minCapacity = nullIndex = HashUtil.arraySize(minCapacity, HashUtil.DEFAULT_LOAD_FACTOR);
|
||||
mask = nullIndex - 1;
|
||||
maxFill = Math.min((int)Math.ceil(nullIndex * HashUtil.DEFAULT_LOAD_FACTOR), nullIndex - 1);
|
||||
keys = NEW_KEY_ARRAY(nullIndex + 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean add(KEY_TYPE o) {
|
||||
if(KEY_EQUALS_NULL(o)) {
|
||||
if(containsNull) return false;
|
||||
containsNull = true;
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(KEY_TO_HASH(o)) & mask;
|
||||
KEY_TYPE current = keys[pos];
|
||||
if(KEY_EQUALS_NOT_NULL(current)) {
|
||||
if(KEY_EQUALS(current, o)) return false;
|
||||
while(KEY_EQUALS_NOT_NULL((current = keys[pos = (++pos & mask)])))
|
||||
if(KEY_EQUALS(current, o)) return false;
|
||||
}
|
||||
keys[pos] = o;
|
||||
}
|
||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, HashUtil.DEFAULT_LOAD_FACTOR));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(Object o) {
|
||||
#if TYPE_OBJECT
|
||||
if(o == null) return containsNull;
|
||||
#else
|
||||
if(o == null) return false;
|
||||
if(o instanceof CLASS_TYPE && KEY_EQUALS(CLASS_TO_KEY(o), EMPTY_KEY_VALUE)) return containsNull;
|
||||
#endif
|
||||
int pos = HashUtil.mix(o.hashCode()) & mask;
|
||||
KEY_TYPE current = keys[pos];
|
||||
if(KEY_EQUALS_NULL(current)) return false;
|
||||
if(EQUALS_KEY_TYPE(current, o)) return true;
|
||||
while(true) {
|
||||
if(KEY_EQUALS_NULL((current = keys[pos = (++pos & mask)]))) return false;
|
||||
else if(EQUALS_KEY_TYPE(current, o)) return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove(Object o) {
|
||||
#if TYPE_OBJECT
|
||||
if(o == null) return (containsNull ? removeNullIndex() : false);
|
||||
#else
|
||||
if(o == null) return false;
|
||||
if(o instanceof CLASS_TYPE && KEY_EQUALS(CLASS_TO_KEY(o), EMPTY_KEY_VALUE)) return (containsNull ? removeNullIndex() : false);
|
||||
#endif
|
||||
int pos = HashUtil.mix(o.hashCode()) & mask;
|
||||
KEY_TYPE current = keys[pos];
|
||||
if(KEY_EQUALS_NULL(current)) return false;
|
||||
if(EQUALS_KEY_TYPE(current, o)) return removeIndex(pos);
|
||||
while(true) {
|
||||
if(KEY_EQUALS_NULL((current = keys[pos = (++pos & mask)]))) return false;
|
||||
else if(EQUALS_KEY_TYPE(current, o)) return removeIndex(pos);
|
||||
}
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public boolean contains(KEY_TYPE o) {
|
||||
if(KEY_EQUALS_NULL(o)) return containsNull;
|
||||
int pos = HashUtil.mix(KEY_TO_HASH(o)) & mask;
|
||||
KEY_TYPE current = keys[pos];
|
||||
if(KEY_EQUALS_NULL(current)) return false;
|
||||
if(KEY_EQUALS(current, o)) return true;
|
||||
while(true) {
|
||||
if(KEY_EQUALS_NULL((current = keys[pos = (++pos & mask)]))) return false;
|
||||
else if(KEY_EQUALS(current, o)) return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean REMOVE_KEY(KEY_TYPE o) {
|
||||
if(KEY_EQUALS_NULL(o)) return containsNull ? removeNullIndex() : false;
|
||||
int pos = HashUtil.mix(KEY_TO_HASH(o)) & mask;
|
||||
KEY_TYPE current = keys[pos];
|
||||
if(KEY_EQUALS_NULL(current)) return false;
|
||||
if(KEY_EQUALS(current, o)) return removeIndex(pos);
|
||||
while(true) {
|
||||
if(KEY_EQUALS_NULL((current = keys[pos = (++pos & mask)]))) return false;
|
||||
else if(KEY_EQUALS(current, o)) return removeIndex(pos);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
protected boolean removeIndex(int pos) {
|
||||
if(pos == nullIndex) return containsNull ? removeNullIndex() : false;
|
||||
keys[pos] = EMPTY_KEY_VALUE;
|
||||
size--;
|
||||
shiftKeys(pos);
|
||||
if(nullIndex > minCapacity && size < maxFill / 4 && nullIndex > HashUtil.DEFAULT_MIN_CAPACITY) rehash(nullIndex / 2);
|
||||
return true;
|
||||
}
|
||||
|
||||
protected boolean removeNullIndex() {
|
||||
containsNull = false;
|
||||
keys[nullIndex] = EMPTY_KEY_VALUE;
|
||||
size--;
|
||||
if(nullIndex > minCapacity && size < maxFill / 4 && nullIndex > HashUtil.DEFAULT_MIN_CAPACITY) rehash(nullIndex / 2);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITERATOR KEY_GENERIC_TYPE iterator() {
|
||||
return new SetIterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) {
|
||||
if(size() <= 0) return;
|
||||
if(containsNull) action.accept(keys[nullIndex]);
|
||||
for(int i = nullIndex-1;i>=0;i--) {
|
||||
if(KEY_EQUALS_NOT_NULL(keys[i])) action.accept(keys[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public DistinctCollectionWrapper KEY_GENERIC_TYPE copy() {
|
||||
DistinctCollectionWrapper KEY_GENERIC_TYPE set = new DistinctCollectionWrapperBRACES(0);
|
||||
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;
|
||||
}
|
||||
|
||||
protected void shiftKeys(int startPos) {
|
||||
int slot, last;
|
||||
KEY_TYPE current;
|
||||
while(true) {
|
||||
startPos = ((last = startPos) + 1) & mask;
|
||||
while(true){
|
||||
if(KEY_EQUALS_NULL((current = keys[startPos]))) {
|
||||
keys[last] = EMPTY_KEY_VALUE;
|
||||
return;
|
||||
}
|
||||
slot = HashUtil.mix(KEY_TO_HASH(current)) & mask;
|
||||
if(last <= startPos ? (last >= slot || slot > startPos) : (last >= slot && slot > startPos)) break;
|
||||
startPos = ++startPos & mask;
|
||||
}
|
||||
keys[last] = current;
|
||||
}
|
||||
}
|
||||
|
||||
protected void rehash(int newSize) {
|
||||
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;
|
||||
}
|
||||
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];
|
||||
}
|
||||
nullIndex = newSize;
|
||||
mask = newMask;
|
||||
maxFill = Math.min((int)Math.ceil(nullIndex * HashUtil.DEFAULT_LOAD_FACTOR), nullIndex - 1);
|
||||
keys = newKeys;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
if(size == 0) return;
|
||||
size = 0;
|
||||
containsNull = false;
|
||||
Arrays.fill(keys, EMPTY_KEY_VALUE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return size;
|
||||
}
|
||||
|
||||
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;
|
||||
KEY_TYPE[] wrapped = null;
|
||||
int wrappedIndex = 0;
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
if(nextIndex == Integer.MIN_VALUE) {
|
||||
if(returnNull) {
|
||||
returnNull = false;
|
||||
nextIndex = nullIndex;
|
||||
}
|
||||
else
|
||||
{
|
||||
while(true) {
|
||||
if(--pos < 0) {
|
||||
if(wrapped == null || wrappedIndex <= -pos - 1) break;
|
||||
nextIndex = -pos - 1;
|
||||
break;
|
||||
}
|
||||
if(KEY_EQUALS_NOT_NULL(keys[pos])){
|
||||
nextIndex = pos;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return nextIndex != Integer.MIN_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE NEXT() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
returnedPos = pos;
|
||||
if(nextIndex < 0){
|
||||
lastReturned = Integer.MAX_VALUE;
|
||||
KEY_TYPE value = wrapped[nextIndex];
|
||||
nextIndex = Integer.MIN_VALUE;
|
||||
return value;
|
||||
}
|
||||
KEY_TYPE value = keys[(lastReturned = nextIndex)];
|
||||
nextIndex = Integer.MIN_VALUE;
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
if(lastReturned == -1) throw new IllegalStateException();
|
||||
if(lastReturned == nullIndex) {
|
||||
containsNull = false;
|
||||
keys[nullIndex] = EMPTY_KEY_VALUE;
|
||||
}
|
||||
else if(returnedPos >= 0) shiftKeys(returnedPos);
|
||||
else {
|
||||
#if TYPE_OBJECT
|
||||
DistinctCollectionWrapper.this.remove(wrapped[-returnedPos - 1]);
|
||||
#else
|
||||
DistinctCollectionWrapper.this.REMOVE_KEY(wrapped[-returnedPos - 1]);
|
||||
#endif
|
||||
lastReturned = -1;
|
||||
return;
|
||||
}
|
||||
size--;
|
||||
lastReturned = -1;
|
||||
}
|
||||
|
||||
private void shiftKeys(int startPos) {
|
||||
int slot, last;
|
||||
KEY_TYPE current;
|
||||
while(true) {
|
||||
startPos = ((last = startPos) + 1) & mask;
|
||||
while(true){
|
||||
if(KEY_EQUALS_NULL((current = keys[startPos]))) {
|
||||
keys[last] = EMPTY_KEY_VALUE;
|
||||
return;
|
||||
}
|
||||
slot = HashUtil.mix(KEY_TO_HASH(current)) & mask;
|
||||
if(last <= startPos ? (last >= slot || slot > startPos) : (last >= slot && slot > startPos)) break;
|
||||
startPos = ++startPos & mask;
|
||||
}
|
||||
if(startPos < last) addWrapper(keys[startPos]);
|
||||
keys[last] = current;
|
||||
}
|
||||
}
|
||||
|
||||
private void addWrapper(KEY_TYPE value) {
|
||||
if(wrapped == null) wrapped = NEW_KEY_ARRAY(2);
|
||||
else if(wrappedIndex >= wrapped.length) {
|
||||
KEY_TYPE[] newArray = NEW_KEY_ARRAY(wrapped.length * 2);
|
||||
System.arraycopy(wrapped, 0, newArray, 0, wrapped.length);
|
||||
wrapped = newArray;
|
||||
}
|
||||
wrapped[wrappedIndex++] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
private static class SingletonCollection KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION KEY_GENERIC_TYPE
|
||||
{
|
||||
KEY_TYPE element;
|
||||
|
||||
SingletonCollection(KEY_TYPE element) {
|
||||
this.element = element;
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public boolean REMOVE_KEY(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
#endif
|
||||
@Override
|
||||
public boolean add(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public ITERATOR KEY_GENERIC_TYPE iterator()
|
||||
{
|
||||
return new ITERATOR KEY_GENERIC_TYPE() {
|
||||
boolean next = true;
|
||||
@Override
|
||||
public boolean hasNext() { return next; }
|
||||
@Override
|
||||
public KEY_TYPE NEXT() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
next = false;
|
||||
return element;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == this)
|
||||
return true;
|
||||
if (!(o instanceof Collection))
|
||||
return false;
|
||||
Collection<?> l = (Collection<?>)o;
|
||||
if(l.size() != size()) return false;
|
||||
Iterator<?> iter = l.iterator();
|
||||
if (iter.hasNext() && !Objects.equals(element, iter.next())) {
|
||||
return false;
|
||||
}
|
||||
return !iter.hasNext();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return KEY_TO_HASH(element);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() { return 1; }
|
||||
|
||||
@Override
|
||||
public SingletonCollection KEY_GENERIC_TYPE copy() { return new SingletonCollectionBRACES(element); }
|
||||
}
|
||||
/**
|
||||
* Synchronized Ordered Collection Wrapper for the synchronizedCollection function
|
||||
* @Type(T)
|
||||
*/
|
||||
public static class SynchronizedOrderedCollection KEY_GENERIC_TYPE extends SynchronizedCollection KEY_GENERIC_TYPE implements ORDERED_COLLECTION KEY_GENERIC_TYPE {
|
||||
ORDERED_COLLECTION KEY_GENERIC_TYPE c;
|
||||
|
||||
SynchronizedOrderedCollection(ORDERED_COLLECTION KEY_GENERIC_TYPE c, Object mutex) {
|
||||
super(c, mutex);
|
||||
this.c = c;
|
||||
}
|
||||
|
||||
SynchronizedOrderedCollection(ORDERED_COLLECTION KEY_GENERIC_TYPE c) {
|
||||
super(c);
|
||||
this.c = c;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ORDERED_COLLECTION KEY_GENERIC_TYPE reversed() { return COLLECTIONS.synchronize(c.reversed(), mutex); }
|
||||
@Override
|
||||
public void addFirst(KEY_TYPE e) { synchronized(mutex) { this.c.addFirst(e); } }
|
||||
@Override
|
||||
public void addLast(KEY_TYPE e) { synchronized(mutex) { this.c.addLast(e); } }
|
||||
@Override
|
||||
public KEY_TYPE GET_FIRST_KEY() { synchronized(mutex) { return this.c.GET_FIRST_KEY(); } }
|
||||
@Override
|
||||
public KEY_TYPE REMOVE_FIRST_KEY() { synchronized(mutex) { return this.c.REMOVE_FIRST_KEY(); } }
|
||||
@Override
|
||||
public KEY_TYPE GET_LAST_KEY() { synchronized(mutex) { return this.c.GET_LAST_KEY(); } }
|
||||
@Override
|
||||
public KEY_TYPE REMOVE_LAST_KEY() { synchronized(mutex) { return this.c.REMOVE_LAST_KEY(); } }
|
||||
}
|
||||
|
||||
/**
|
||||
* Synchronized Collection Wrapper for the synchronizedCollection function
|
||||
* @Type(T)
|
||||
@@ -183,6 +852,8 @@ public class COLLECTIONS
|
||||
@Override
|
||||
public void forEach(Consumer<? super CLASS_TYPE> action) { synchronized(mutex) { c.forEach(action); } }
|
||||
#endif
|
||||
@Override
|
||||
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) { synchronized(mutex) { c.forEachIndexed(action); } }
|
||||
@Override
|
||||
public int hashCode() { synchronized(mutex) { return c.hashCode(); } }
|
||||
@Override
|
||||
@@ -207,13 +878,41 @@ public class COLLECTIONS
|
||||
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); } }
|
||||
public OPTIONAL KEY_GENERIC_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); } }
|
||||
public OPTIONAL KEY_GENERIC_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); } }
|
||||
}
|
||||
|
||||
/**
|
||||
* Unmodifyable Ordered Collection Wrapper for the unmodifyableCollection method
|
||||
* @Type(T)
|
||||
*/
|
||||
public static class UnmodifiableOrderedCollection KEY_GENERIC_TYPE extends UnmodifiableCollection KEY_GENERIC_TYPE implements ORDERED_COLLECTION KEY_GENERIC_TYPE {
|
||||
ORDERED_COLLECTION KEY_GENERIC_TYPE c;
|
||||
|
||||
UnmodifiableOrderedCollection(ORDERED_COLLECTION KEY_GENERIC_TYPE c) {
|
||||
super(c);
|
||||
this.c = c;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ORDERED_COLLECTION KEY_GENERIC_TYPE reversed() { return COLLECTIONS.unmodifiable(c.reversed()); }
|
||||
@Override
|
||||
public void addFirst(KEY_TYPE e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void addLast(KEY_TYPE e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public KEY_TYPE GET_FIRST_KEY() { return c.GET_FIRST_KEY(); }
|
||||
@Override
|
||||
public KEY_TYPE REMOVE_FIRST_KEY() { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public KEY_TYPE GET_LAST_KEY() { return c.GET_LAST_KEY(); }
|
||||
@Override
|
||||
public KEY_TYPE REMOVE_LAST_KEY() { throw new UnsupportedOperationException(); }
|
||||
}
|
||||
|
||||
/**
|
||||
* Unmodifyable Collection Wrapper for the unmodifyableCollection method
|
||||
* @Type(T)
|
||||
@@ -308,6 +1007,8 @@ public class COLLECTIONS
|
||||
@Override
|
||||
public void forEach(Consumer<? super CLASS_TYPE> action) { c.forEach(action); }
|
||||
#endif
|
||||
@Override
|
||||
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) { c.forEachIndexed(action); }
|
||||
@Override
|
||||
public int hashCode() { return c.hashCode(); }
|
||||
@Override
|
||||
@@ -329,9 +1030,9 @@ public class COLLECTIONS
|
||||
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); }
|
||||
public OPTIONAL KEY_GENERIC_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); }
|
||||
public OPTIONAL KEY_GENERIC_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) { return c.findFirst(filter); }
|
||||
@Override
|
||||
public int count(PREDICATE KEY_GENERIC_TYPE filter) { return c.count(filter); }
|
||||
}
|
||||
|
||||
@@ -7,7 +7,9 @@ import speiger.src.collections.utils.IArray;
|
||||
|
||||
/**
|
||||
* Type-Specific Helper class to get the underlying array of array implementations.
|
||||
#if ARRAY_LIST_FEATURE
|
||||
* @see speiger.src.collections.PACKAGE.lists.ARRAY_LIST
|
||||
#endif
|
||||
* @Type(T)
|
||||
*/
|
||||
public interface IARRAY KEY_GENERIC_TYPE extends IArray
|
||||
|
||||
+214
-25
@@ -8,23 +8,44 @@ import java.util.Comparator;
|
||||
#endif
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.function.Consumer;
|
||||
#if JDK_FUNCTION
|
||||
import java.util.function.PREDICATE;
|
||||
#endif
|
||||
|
||||
import speiger.src.collections.PACKAGE.collections.ITERABLE;
|
||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.objects.collections.ObjectIterable;
|
||||
import speiger.src.collections.objects.collections.ObjectIterator;
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
#else
|
||||
#if BOOLEAN_COLLECTION_MODULE
|
||||
import speiger.src.collections.booleans.functions.BooleanConsumer;
|
||||
import speiger.src.collections.booleans.collections.BooleanIterable;
|
||||
import speiger.src.collections.booleans.collections.BooleanIterator;
|
||||
#endif
|
||||
#iterate
|
||||
#argument FILTER_TYPE BYTE_COLLECTION_MODULE SHORT_COLLECTION_MODULE INT_COLLECTION_MODULE LONG_COLLECTION_MODULE FLOAT_COLLECTION_MODULE DOUBLE_COLLECTION_MODULE
|
||||
#argument CONSUMER ByteConsumer ShortConsumer IntConsumer LongConsumer FloatConsumer DoubleConsumer
|
||||
#argument OUTPUT_ITERABLE ByteIterable ShortIterable IntIterable LongIterable FloatIterable DoubleIterable
|
||||
#argument OUTPUT_ITERATOR ByteIterator ShortIterator IntIterator LongIterator FloatIterator DoubleIterator
|
||||
#argument MAPPER ToByteFunction ToShortFunction ToIntFunction ToLongFunction ToFloatFunction ToDoubleFunction
|
||||
#argument PACKAGE bytes shorts ints longs floats doubles
|
||||
#if FILTER_TYPE
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
import speiger.src.collections.objects.functions.function.MAPPER;
|
||||
import speiger.src.collections.PACKAGE.collections.OUTPUT_ITERABLE;
|
||||
import speiger.src.collections.PACKAGE.collections.OUTPUT_ITERATOR;
|
||||
#endif
|
||||
#enditerate
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.lists.LIST;
|
||||
import speiger.src.collections.PACKAGE.lists.ARRAY_LIST;
|
||||
import speiger.src.collections.PACKAGE.functions.function.TO_OBJECT_FUNCTION;
|
||||
#if !JDK_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
|
||||
import speiger.src.collections.utils.ISizeProvider;
|
||||
|
||||
/**
|
||||
* A Helper class for Iterables
|
||||
@@ -55,6 +76,39 @@ public class ITERABLES
|
||||
return new MappedIterable<>(iterable, mapper);
|
||||
}
|
||||
|
||||
#if TYPE_OBJECT
|
||||
#iterate
|
||||
#argument MAPPED_TYPE MappedBoolean MappedByte MappedShort MappedInt MappedLong MappedFloat MappedDouble
|
||||
#argument OUTPUT_ITERABLE BooleanIterable ByteIterable ShortIterable IntIterable LongIterable FloatIterable DoubleIterable
|
||||
#argument MAPPER Predicate ToByteFunction ToShortFunction ToIntFunction ToLongFunction ToFloatFunction ToDoubleFunction
|
||||
#argument DATA_TYPE Boolean Byte Short Int Long Float Double
|
||||
#argument FILTER_TYPE BOOLEAN_COLLECTION_MODULE BYTE_COLLECTION_MODULE SHORT_COLLECTION_MODULE INT_COLLECTION_MODULE LONG_COLLECTION_MODULE FLOAT_COLLECTION_MODULE DOUBLE_COLLECTION_MODULE
|
||||
#if FILTER_TYPE
|
||||
/**
|
||||
* 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)
|
||||
* @return a iterable that is mapped to a new result
|
||||
*/
|
||||
public static <T> OUTPUT_ITERABLE mapToDATA_TYPE(Iterable<? extends CLASS_TYPE> iterable, MAPPER<T> mapper) {
|
||||
return new MAPPED_TYPEIterable<>(wrap(iterable), mapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that maps a 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)
|
||||
* @return a iterable that is mapped to a new result
|
||||
*/
|
||||
public static <T> OUTPUT_ITERABLE mapToDATA_TYPE(ITERABLE KEY_GENERIC_TYPE iterable, MAPPER<T> mapper) {
|
||||
return new MAPPED_TYPEIterable<>(iterable, mapper);
|
||||
}
|
||||
|
||||
#endif
|
||||
#enditerate
|
||||
#endif
|
||||
/**
|
||||
* A Helper function that flatMaps a Java-Iterable into a new Type.
|
||||
* @param iterable the iterable that should be flatMapped
|
||||
@@ -147,6 +201,28 @@ public class ITERABLES
|
||||
return new DistinctIterableBRACES(wrap(iterable));
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that repeats the Iterable a specific amount of times
|
||||
* @param iterable that should be repeated
|
||||
* @param repeats the amount of times the iterable should be repeated
|
||||
* @Type(T)
|
||||
* @return a repeating iterable
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES ITERABLE KEY_GENERIC_TYPE repeat(ITERABLE KEY_GENERIC_TYPE iterable, int repeats) {
|
||||
return new RepeatingIterableBRACES(iterable, repeats);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that repeats the Iterable a specific amount of times from a Java Iterable
|
||||
* @param iterable that should be repeated
|
||||
* @param repeats the amount of times the iterable should be repeated
|
||||
* @Type(T)
|
||||
* @return a repeating iterable
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES ITERABLE KEY_GENERIC_TYPE repeat(Iterable<? extends CLASS_TYPE> iterable, int repeats) {
|
||||
return new RepeatingIterableBRACES(wrap(iterable), repeats);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that hard limits the Iterable to a specific size
|
||||
* @param iterable that should be limited
|
||||
@@ -225,7 +301,7 @@ public class ITERABLES
|
||||
return new WrappedIterableBRACES(iterable);
|
||||
}
|
||||
|
||||
private static class WrappedIterable KEY_GENERIC_TYPE implements ITERABLE KEY_GENERIC_TYPE
|
||||
private static class WrappedIterable KEY_GENERIC_TYPE implements ITERABLE KEY_GENERIC_TYPE, ISizeProvider
|
||||
{
|
||||
Iterable<? extends CLASS_TYPE> iterable;
|
||||
|
||||
@@ -237,6 +313,12 @@ public class ITERABLES
|
||||
return ITERATORS.wrap(iterable.iterator());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
ISizeProvider prov = ISizeProvider.of(iterable);
|
||||
return prov == null ? -1 : prov.size();
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public void forEach(CONSUMER action) {
|
||||
@@ -251,7 +333,48 @@ public class ITERABLES
|
||||
#endif
|
||||
}
|
||||
|
||||
private static class MappedIterable KSS_GENERIC_TYPE<E, T> implements ObjectIterable<T>
|
||||
#if TYPE_OBJECT
|
||||
#iterate
|
||||
#argument CONSUMER BooleanConsumer ByteConsumer ShortConsumer IntConsumer LongConsumer FloatConsumer DoubleConsumer
|
||||
#argument MAPPED_TYPE MappedBoolean MappedByte MappedShort MappedInt MappedLong MappedFloat MappedDouble
|
||||
#argument OUTPUT_ITERABLE BooleanIterable ByteIterable ShortIterable IntIterable LongIterable FloatIterable DoubleIterable
|
||||
#argument OUTPUT_ITERATOR BooleanIterator ByteIterator ShortIterator IntIterator LongIterator FloatIterator DoubleIterator
|
||||
#argument MAPPER Predicate ToByteFunction ToShortFunction ToIntFunction ToLongFunction ToFloatFunction ToDoubleFunction
|
||||
#argument APPLY test applyAsByte applyAsShort applyAsInt applyAsLong applyAsFloat applyAsDouble
|
||||
#argument DATA_TYPE Boolean Byte Short Int Long Float Double
|
||||
#argument FILTER_TYPE BOOLEAN_COLLECTION_MODULE BYTE_COLLECTION_MODULE SHORT_COLLECTION_MODULE INT_COLLECTION_MODULE LONG_COLLECTION_MODULE FLOAT_COLLECTION_MODULE DOUBLE_COLLECTION_MODULE
|
||||
#if FILTER_TYPE
|
||||
private static class MAPPED_TYPEIterable<E> implements OUTPUT_ITERABLE, ISizeProvider
|
||||
{
|
||||
ITERABLE KEY_SPECIAL_GENERIC_TYPE<E> iterable;
|
||||
MAPPER<E> mapper;
|
||||
|
||||
MAPPED_TYPEIterable(ITERABLE<E> iterable, MAPPER<E> mapper) {
|
||||
this.iterable = iterable;
|
||||
this.mapper = mapper;
|
||||
}
|
||||
|
||||
public OUTPUT_ITERATOR iterator() {
|
||||
return ITERATORS.mapToDATA_TYPE(iterable.iterator(), mapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
ISizeProvider prov = ISizeProvider.of(this);
|
||||
return prov == null ? -1 : prov.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEach(CONSUMER action) {
|
||||
Objects.requireNonNull(action);
|
||||
iterable.forEach(E -> action.accept(mapper.APPLY(E)));
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
#enditerate
|
||||
#endif
|
||||
private static class MappedIterable KSS_GENERIC_TYPE<E, T> implements ObjectIterable<T>, ISizeProvider
|
||||
{
|
||||
ITERABLE KEY_SPECIAL_GENERIC_TYPE<E> iterable;
|
||||
TO_OBJECT_FUNCTION KSS_GENERIC_TYPE<E, T> mapper;
|
||||
@@ -265,10 +388,16 @@ public class ITERABLES
|
||||
return ITERATORS.map(iterable.iterator(), mapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
ISizeProvider prov = ISizeProvider.of(this);
|
||||
return prov == null ? -1 : prov.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEach(Consumer<? super T> action) {
|
||||
Objects.requireNonNull(action);
|
||||
iterable.forEach(E -> action.accept(mapper.GET_VALUE(E)));
|
||||
iterable.forEach(E -> action.accept(mapper.apply(E)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -290,7 +419,7 @@ public class ITERABLES
|
||||
@Override
|
||||
public void forEach(Consumer<? super T> action) {
|
||||
Objects.requireNonNull(action);
|
||||
iterable.forEach(E -> mapper.GET_VALUE(E).forEach(action));
|
||||
iterable.forEach(E -> mapper.apply(E).forEach(action));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -314,12 +443,54 @@ public class ITERABLES
|
||||
public void forEach(Consumer<? super T> action) {
|
||||
Objects.requireNonNull(action);
|
||||
iterable.forEach(E -> {
|
||||
T[] array = mapper.GET_VALUE(E);
|
||||
T[] array = mapper.apply(E);
|
||||
for(int i = 0,m=array.length;i<m;action.accept(array[i++]));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private static class RepeatingIterable KEY_GENERIC_TYPE implements ITERABLE KEY_GENERIC_TYPE, ISizeProvider
|
||||
{
|
||||
ITERABLE KEY_GENERIC_TYPE iterable;
|
||||
int repeats;
|
||||
|
||||
public RepeatingIterable(ITERABLE KEY_GENERIC_TYPE iterable, int repeats) {
|
||||
this.iterable = iterable;
|
||||
this.repeats = repeats;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITERATOR KEY_GENERIC_TYPE iterator() {
|
||||
return ITERATORS.repeat(iterable.iterator(), repeats);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
ISizeProvider prov = ISizeProvider.of(iterable);
|
||||
return prov == null ? -1 : prov.size() * (repeats+1);
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public void forEach(CONSUMER action) {
|
||||
Objects.requireNonNull(action);
|
||||
COLLECTION KEY_GENERIC_TYPE repeater = COLLECTIONS.wrapper();
|
||||
iterable.forEach(action.andThen(repeater::add));
|
||||
for(int i = 0;i<repeats;i++)
|
||||
repeater.forEach(action);
|
||||
}
|
||||
#else
|
||||
@Override
|
||||
public void forEach(Consumer<? super CLASS_TYPE> action) {
|
||||
Objects.requireNonNull(action);
|
||||
COLLECTION KEY_GENERIC_TYPE repeater = COLLECTIONS.wrapper();
|
||||
iterable.forEach(T -> {action.accept(T); repeater.add(T);});
|
||||
for(int i = 0;i<repeats;i++)
|
||||
repeater.forEach(action);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
private static class FilteredIterable KEY_GENERIC_TYPE implements ITERABLE KEY_GENERIC_TYPE
|
||||
{
|
||||
ITERABLE KEY_GENERIC_TYPE iterable;
|
||||
@@ -339,17 +510,17 @@ public class ITERABLES
|
||||
@Override
|
||||
public void forEach(CONSUMER action) {
|
||||
Objects.requireNonNull(action);
|
||||
iterable.forEach(T -> { if(!filter.TEST_VALUE(T)) action.accept(T); } );
|
||||
iterable.forEach(T -> { if(!filter.test(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); } );
|
||||
iterable.forEach(T -> { if(!filter.test(T)) action.accept(T); } );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
private static class LimitedIterable KEY_GENERIC_TYPE implements ITERABLE KEY_GENERIC_TYPE
|
||||
private static class LimitedIterable KEY_GENERIC_TYPE implements ITERABLE KEY_GENERIC_TYPE, ISizeProvider
|
||||
{
|
||||
ITERABLE KEY_GENERIC_TYPE iterable;
|
||||
long limit;
|
||||
@@ -364,6 +535,12 @@ public class ITERABLES
|
||||
return ITERATORS.limit(iterable.iterator(), limit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
ISizeProvider prov = ISizeProvider.of(iterable);
|
||||
return prov == null ? -1 : (int)Math.min(prov.size(), limit);
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public void forEach(CONSUMER action) {
|
||||
@@ -388,7 +565,7 @@ public class ITERABLES
|
||||
#endif
|
||||
}
|
||||
|
||||
private static class SortedIterable KEY_GENERIC_TYPE implements ITERABLE KEY_GENERIC_TYPE
|
||||
private static class SortedIterable KEY_GENERIC_TYPE implements ITERABLE KEY_GENERIC_TYPE, ISizeProvider
|
||||
{
|
||||
ITERABLE KEY_GENERIC_TYPE iterable;
|
||||
COMPARATOR KEY_GENERIC_TYPE sorter;
|
||||
@@ -403,23 +580,29 @@ public class ITERABLES
|
||||
return ITERATORS.sorted(iterable.iterator(), sorter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
ISizeProvider prov = ISizeProvider.of(iterable);
|
||||
return prov == null ? -1 : prov.size();
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public void forEach(CONSUMER action) {
|
||||
Objects.requireNonNull(action);
|
||||
LIST KEY_GENERIC_TYPE list = new ARRAY_LISTBRACES();
|
||||
iterable.forEach(list::add);
|
||||
list.unstableSort(sorter);
|
||||
list.forEach(action);
|
||||
COLLECTIONS.CollectionWrapper KEY_GENERIC_TYPE wrapper = COLLECTIONS.wrapper();
|
||||
iterable.forEach(wrapper::add);
|
||||
wrapper.unstableSort(sorter);
|
||||
wrapper.forEach(action);
|
||||
}
|
||||
#else
|
||||
@Override
|
||||
public void forEach(Consumer<? super CLASS_TYPE> action) {
|
||||
Objects.requireNonNull(action);
|
||||
LIST KEY_GENERIC_TYPE list = new ARRAY_LISTBRACES();
|
||||
iterable.forEach(list::add);
|
||||
list.unstableSort(sorter);
|
||||
list.forEach(action);
|
||||
COLLECTIONS.CollectionWrapper KEY_GENERIC_TYPE wrapper = COLLECTIONS.wrapper();
|
||||
iterable.forEach(wrapper::add);
|
||||
wrapper.unstableSort(sorter);
|
||||
wrapper.forEach(action);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -449,20 +632,20 @@ public class ITERABLES
|
||||
action.accept(T);
|
||||
});
|
||||
#else
|
||||
SET KEY_GENERIC_TYPE filtered = new HASH_SETBRACES();
|
||||
COLLECTION KEY_GENERIC_TYPE filtered = COLLECTIONS.distinctWrapper();
|
||||
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();
|
||||
COLLECTION KEY_GENERIC_TYPE filtered = COLLECTIONS.distinctWrapper();
|
||||
iterable.forEach(T -> { if(filtered.add(T)) action.accept(T); });
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
private static class PeekIterable KEY_GENERIC_TYPE implements ITERABLE KEY_GENERIC_TYPE
|
||||
private static class PeekIterable KEY_GENERIC_TYPE implements ITERABLE KEY_GENERIC_TYPE, ISizeProvider
|
||||
{
|
||||
ITERABLE KEY_GENERIC_TYPE iterable;
|
||||
CONSUMER KEY_GENERIC_TYPE action;
|
||||
@@ -477,6 +660,12 @@ public class ITERABLES
|
||||
return ITERATORS.peek(iterable.iterator(), action);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
ISizeProvider prov = ISizeProvider.of(iterable);
|
||||
return prov == null ? -1 : prov.size();
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public void forEach(CONSUMER action) {
|
||||
|
||||
+244
-42
@@ -4,7 +4,10 @@ import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
#if TYPE_OBJECT
|
||||
import java.util.Comparator;
|
||||
import java.util.function.CONSUMER;
|
||||
#endif
|
||||
import java.util.function.Consumer;
|
||||
#if JDK_FUNCTION
|
||||
import java.util.function.PREDICATE;
|
||||
#endif
|
||||
|
||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
@@ -13,18 +16,39 @@ import speiger.src.collections.objects.collections.ObjectIterator;
|
||||
import speiger.src.collections.objects.utils.ObjectIterators;
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
#else
|
||||
#if BOOLEAN_COLLECTION_MODULE
|
||||
import speiger.src.collections.booleans.collections.BooleanIterator;
|
||||
#endif
|
||||
#iterate
|
||||
#argument ITERATOR ByteIterator ShortIterator IntIterator LongIterator FloatIterator DoubleIterator
|
||||
#argument PACKAGE bytes shorts ints longs floats doubles
|
||||
#argument MAPPER ToByteFunction ToShortFunction ToIntFunction ToLongFunction ToFloatFunction ToDoubleFunction
|
||||
#argument FILTER_TYPE BYTE_COLLECTION_MODULE SHORT_COLLECTION_MODULE INT_COLLECTION_MODULE LONG_COLLECTION_MODULE FLOAT_COLLECTION_MODULE DOUBLE_COLLECTION_MODULE
|
||||
#if FILTER_TYPE
|
||||
import speiger.src.collections.objects.functions.function.MAPPER;
|
||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
#endif
|
||||
#enditerate
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.functions.function.TO_OBJECT_FUNCTION;
|
||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||
#if !JDK_FUNCTION
|
||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||
import speiger.src.collections.PACKAGE.lists.ARRAY_LIST;
|
||||
#endif
|
||||
#if ARRAY_LIST_FEATURE || LINKED_LIST_FEATURE
|
||||
import speiger.src.collections.PACKAGE.lists.LIST;
|
||||
#if ARRAY_LIST_FEATURE
|
||||
import speiger.src.collections.PACKAGE.lists.ARRAY_LIST;
|
||||
#else if LINKED_LIST_FEATURE
|
||||
import speiger.src.collections.PACKAGE.lists.LINKED_LIST;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
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
|
||||
import speiger.src.collections.PACKAGE.utils.COLLECTIONS.CollectionWrapper;
|
||||
|
||||
/**
|
||||
* A Helper class for Iterators
|
||||
@@ -41,7 +65,7 @@ public class ITERATORS
|
||||
* @Type(T)
|
||||
* @return an empty iterator
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES EmptyIterator KEY_GENERIC_TYPE empty() {
|
||||
public static GENERIC_KEY_BRACES LIST_ITERATOR KEY_GENERIC_TYPE empty() {
|
||||
#if TYPE_OBJECT
|
||||
return (EmptyIterator<KEY_TYPE>)EMPTY;
|
||||
#else
|
||||
@@ -99,6 +123,7 @@ public class ITERATORS
|
||||
return iterator instanceof UnmodifiableListIterator ? iterator : new UnmodifiableListIteratorBRACES(iterator);
|
||||
}
|
||||
|
||||
#if OBJECT_COLLECTION_MODULE
|
||||
/**
|
||||
* A Helper function that maps a Java-Iterator into a new Type.
|
||||
* @param iterator that should be mapped
|
||||
@@ -123,6 +148,40 @@ public class ITERATORS
|
||||
return new MappedIterator<>(iterator, mapper);
|
||||
}
|
||||
|
||||
#endif
|
||||
#if TYPE_OBJECT
|
||||
#iterate
|
||||
#argument MAPPED_TYPE MappedBoolean MappedByte MappedShort MappedInt MappedLong MappedFloat MappedDouble
|
||||
#argument OUTPUT_ITERATOR BooleanIterator ByteIterator ShortIterator IntIterator LongIterator FloatIterator DoubleIterator
|
||||
#argument MAPPER Predicate ToByteFunction ToShortFunction ToIntFunction ToLongFunction ToFloatFunction ToDoubleFunction
|
||||
#argument DATA_TYPE Boolean Byte Short Int Long Float Double
|
||||
#argument FILTER_TYPE BOOLEAN_COLLECTION_MODULE BYTE_COLLECTION_MODULE SHORT_COLLECTION_MODULE INT_COLLECTION_MODULE LONG_COLLECTION_MODULE FLOAT_COLLECTION_MODULE DOUBLE_COLLECTION_MODULE
|
||||
#if FILTER_TYPE
|
||||
/**
|
||||
* 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)
|
||||
* @return a iterator that is mapped to a new result
|
||||
*/
|
||||
public static <T> OUTPUT_ITERATOR mapToDATA_TYPE(Iterator<? extends CLASS_TYPE> iterator, MAPPER<T> mapper) {
|
||||
return new MAPPED_TYPEIterator<>(wrap(iterator), mapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that maps a Iterator into a new Type.
|
||||
* @param iterator that should be mapped
|
||||
* @param mapper the function that decides what the result turns into.
|
||||
* @Type(T)
|
||||
* @return a iterator that is mapped to a new result
|
||||
*/
|
||||
public static <T> OUTPUT_ITERATOR mapToDATA_TYPE(ITERATOR KEY_GENERIC_TYPE iterator, MAPPER<T> mapper) {
|
||||
return new MAPPED_TYPEIterator<>(iterator, mapper);
|
||||
}
|
||||
|
||||
#endif
|
||||
#enditerate
|
||||
#endif
|
||||
/**
|
||||
* A Helper function that flatMaps a Java-Iterator into a new Type.
|
||||
* @param iterator that should be flatMapped
|
||||
@@ -215,6 +274,48 @@ public class ITERATORS
|
||||
return new DistinctIteratorBRACES(wrap(iterator));
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that repeats the Iterator a specific amount of times
|
||||
* @param iterator that should be repeated
|
||||
* @param repeats the amount of times the iterator should be repeated
|
||||
* @Type(T)
|
||||
* @return a repeating iterator
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES ITERATOR KEY_GENERIC_TYPE repeat(ITERATOR KEY_GENERIC_TYPE iterator, int repeats) {
|
||||
return new RepeatingIteratorBRACES(iterator, repeats);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that repeats the Iterator a specific amount of times from a Java Iterator
|
||||
* @param iterator that should be repeated
|
||||
* @param repeats the amount of times the iterator should be repeated
|
||||
* @Type(T)
|
||||
* @return a repeating iterator
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES ITERATOR KEY_GENERIC_TYPE repeat(Iterator<? extends CLASS_TYPE> iterator, int repeats) {
|
||||
return new RepeatingIteratorBRACES(wrap(iterator), repeats);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that creates a infinitely looping iterator
|
||||
* @param iterator that should be looping infinitely
|
||||
* @Type(T)
|
||||
* @return a infinitely looping iterator
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES ITERATOR KEY_GENERIC_TYPE infinite(ITERATOR KEY_GENERIC_TYPE iterator) {
|
||||
return new InfiniteIteratorBRACES(iterator);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that creates a infinitely looping iterator from a Java Iterator
|
||||
* @param iterator that should be looping infinitely
|
||||
* @Type(T)
|
||||
* @return a infinitely looping iterator
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES ITERATOR KEY_GENERIC_TYPE infinite(Iterator<? extends CLASS_TYPE> iterator) {
|
||||
return new InfiniteIteratorBRACES(wrap(iterator));
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that hard limits the Iterator to a specific size
|
||||
* @param iterator that should be limited
|
||||
@@ -299,7 +400,7 @@ public class ITERATORS
|
||||
* @ArrayType(T)
|
||||
* @return a Iterator that is wrapping a array.
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES ArrayIterator KEY_GENERIC_TYPE wrap(KEY_TYPE... a) {
|
||||
public static GENERIC_KEY_BRACES ITERATOR KEY_GENERIC_TYPE wrap(KEY_TYPE... a) {
|
||||
return wrap(a, 0, a.length);
|
||||
}
|
||||
|
||||
@@ -311,7 +412,7 @@ public class ITERATORS
|
||||
* @ArrayType(T)
|
||||
* @return a Iterator that is wrapping a array.
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES ArrayIterator KEY_GENERIC_TYPE wrap(KEY_TYPE[] a, int start, int end) {
|
||||
public static GENERIC_KEY_BRACES ITERATOR KEY_GENERIC_TYPE wrap(KEY_TYPE[] a, int start, int end) {
|
||||
return new ArrayIteratorBRACES(a, start, end);
|
||||
}
|
||||
|
||||
@@ -446,6 +547,8 @@ public class ITERATORS
|
||||
}
|
||||
|
||||
#endif
|
||||
#if LIST_MODULE
|
||||
#if ARRAY_LIST_FEATURE || LINKED_LIST_FEATURE
|
||||
/**
|
||||
* A Helper function to pours all elements of a Iterator into a List
|
||||
* @param iter the elements that should be poured into list.
|
||||
@@ -464,12 +567,20 @@ public class ITERATORS
|
||||
* @return A list of all requested elements of the Iterator
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES LIST KEY_GENERIC_TYPE pour(ITERATOR KEY_GENERIC_TYPE iter, int max) {
|
||||
#if ARRAY_LIST_FEATURE
|
||||
ARRAY_LIST KEY_GENERIC_TYPE list = new ARRAY_LISTBRACES();
|
||||
#else
|
||||
LINKED_LIST KEY_GENERIC_TYPE list = new LINKED_LISTBRACES();
|
||||
#endif
|
||||
pour(iter, list, max);
|
||||
#if ARRAY_LIST_FEATURE
|
||||
list.trim();
|
||||
#endif
|
||||
return list;
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
/**
|
||||
* A Helper function to pours all elements of a Iterator into a Collection
|
||||
* @param iter the elements that should be poured into list.
|
||||
@@ -729,41 +840,21 @@ public class ITERATORS
|
||||
private static class EmptyIterator KEY_GENERIC_TYPE implements LIST_ITERATOR KEY_GENERIC_TYPE
|
||||
{
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean hasNext() { return false; }
|
||||
@Override
|
||||
public KEY_TYPE NEXT() {
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
|
||||
public KEY_TYPE NEXT() { throw new NoSuchElementException(); }
|
||||
@Override
|
||||
public boolean hasPrevious() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean hasPrevious() { return false; }
|
||||
@Override
|
||||
public KEY_TYPE PREVIOUS() {
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
|
||||
public KEY_TYPE PREVIOUS() { throw new NoSuchElementException(); }
|
||||
@Override
|
||||
public int nextIndex() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int nextIndex() { return 0; }
|
||||
@Override
|
||||
public int previousIndex() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
public int previousIndex() { return -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(); }
|
||||
}
|
||||
@@ -817,7 +908,7 @@ public class ITERATORS
|
||||
|
||||
@Override
|
||||
public T next() {
|
||||
return mapper.GET_VALUE(iterator.NEXT());
|
||||
return mapper.apply(iterator.NEXT());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -826,6 +917,45 @@ public class ITERATORS
|
||||
}
|
||||
}
|
||||
|
||||
#if TYPE_OBJECT
|
||||
#iterate
|
||||
#argument MAPPED_TYPE MappedBoolean MappedByte MappedShort MappedInt MappedLong MappedFloat MappedDouble
|
||||
#argument NEXT_TYPE nextBoolean nextByte nextShort nextInt nextLong nextFloat nextDouble
|
||||
#argument OUTPUT_ITERATOR BooleanIterator ByteIterator ShortIterator IntIterator LongIterator FloatIterator DoubleIterator
|
||||
#argument MAPPER Predicate ToByteFunction ToShortFunction ToIntFunction ToLongFunction ToFloatFunction ToDoubleFunction
|
||||
#argument APPLY test applyAsByte applyAsShort applyAsInt applyAsLong applyAsFloat applyAsDouble
|
||||
#argument DATA_TYPE boolean byte short int long float double
|
||||
#argument FILTER_TYPE BOOLEAN_COLLECTION_MODULE BYTE_COLLECTION_MODULE SHORT_COLLECTION_MODULE INT_COLLECTION_MODULE LONG_COLLECTION_MODULE FLOAT_COLLECTION_MODULE DOUBLE_COLLECTION_MODULE
|
||||
#if FILTER_TYPE
|
||||
private static class MAPPED_TYPEIterator<E> implements OUTPUT_ITERATOR
|
||||
{
|
||||
ITERATOR<E> iterator;
|
||||
MAPPER<E> mapper;
|
||||
|
||||
MAPPED_TYPEIterator(ITERATOR KEY_SPECIAL_GENERIC_TYPE<E> iterator, MAPPER<E> mapper) {
|
||||
this.iterator = iterator;
|
||||
this.mapper = mapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return iterator.hasNext();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DATA_TYPE NEXT_TYPE() {
|
||||
return mapper.APPLY(iterator.NEXT());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int skip(int amount) {
|
||||
return iterator.skip(amount);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
#enditerate
|
||||
#endif
|
||||
private static class FlatMappedIterator KSS_GENERIC_TYPE<E, T,[SPACE]V extends Iterable<T>> implements ObjectIterator<T>
|
||||
{
|
||||
ITERATOR KEY_SPECIAL_GENERIC_TYPE<E> iterator;
|
||||
@@ -843,7 +973,7 @@ public class ITERATORS
|
||||
foundNext = true;
|
||||
while(iterator.hasNext()) {
|
||||
if(last != null && last.hasNext()) return;
|
||||
last = mapper.GET_VALUE(iterator.NEXT()).iterator();
|
||||
last = mapper.apply(iterator.NEXT()).iterator();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -879,7 +1009,7 @@ public class ITERATORS
|
||||
foundNext = true;
|
||||
while(iterator.hasNext()) {
|
||||
if(last != null && last.hasNext()) return;
|
||||
last = ObjectIterators.wrap(mapper.GET_VALUE(iterator.NEXT()));
|
||||
last = ObjectIterators.wrap(mapper.apply(iterator.NEXT()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -898,11 +1028,79 @@ public class ITERATORS
|
||||
}
|
||||
}
|
||||
|
||||
private static class InfiniteIterator KEY_GENERIC_TYPE implements ITERATOR KEY_GENERIC_TYPE
|
||||
{
|
||||
ITERATOR KEY_GENERIC_TYPE iter;
|
||||
CollectionWrapper KEY_GENERIC_TYPE looper = COLLECTIONS.wrapper();
|
||||
int index = 0;
|
||||
|
||||
public InfiniteIterator(ITERATOR KEY_GENERIC_TYPE iter) {
|
||||
this.iter = iter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE NEXT() {
|
||||
if(iter != null) {
|
||||
if(iter.hasNext()) {
|
||||
KEY_TYPE value = iter.NEXT();
|
||||
looper.add(value);
|
||||
return value;
|
||||
}
|
||||
else iter = null;
|
||||
}
|
||||
return looper.GET_KEY((index++) % looper.size());
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public void forEachRemaining(CONSUMER action) { throw new UnsupportedOperationException("This is a instant deadlock, so unsupported"); }
|
||||
#endif
|
||||
public void forEachRemaining(Consumer<? super CLASS_TYPE> action) { throw new UnsupportedOperationException("This is a instant deadlock, so unsupported"); }
|
||||
public <E> void forEachRemaining(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) { throw new UnsupportedOperationException("This is a instant deadlock, so unsupported"); }
|
||||
}
|
||||
|
||||
private static class RepeatingIterator KEY_GENERIC_TYPE implements ITERATOR KEY_GENERIC_TYPE
|
||||
{
|
||||
final int repeats;
|
||||
int index = 0;
|
||||
ITERATOR KEY_GENERIC_TYPE iter;
|
||||
COLLECTION KEY_GENERIC_TYPE repeater = COLLECTIONS.wrapper();
|
||||
|
||||
public RepeatingIterator(ITERATOR KEY_GENERIC_TYPE iter, int repeat) {
|
||||
this.iter = iter;
|
||||
this.repeats = repeat;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
if(iter.hasNext()) return true;
|
||||
if(index < repeats) {
|
||||
index++;
|
||||
iter = repeater.iterator();
|
||||
return iter.hasNext();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE NEXT() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
KEY_TYPE value = iter.NEXT();
|
||||
if(index == 0) repeater.add(value);
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
private static class SortedIterator KEY_GENERIC_TYPE implements ITERATOR KEY_GENERIC_TYPE
|
||||
{
|
||||
ITERATOR KEY_GENERIC_TYPE iterator;
|
||||
COMPARATOR KEY_GENERIC_TYPE sorter;
|
||||
LIST KEY_GENERIC_TYPE sortedElements = null;
|
||||
COLLECTIONS.CollectionWrapper KEY_GENERIC_TYPE sortedElements = null;
|
||||
int index = 0;
|
||||
|
||||
public SortedIterator(ITERATOR KEY_GENERIC_TYPE iterator, COMPARATOR KEY_GENERIC_TYPE sorter) {
|
||||
@@ -914,7 +1112,11 @@ public class ITERATORS
|
||||
public boolean hasNext() {
|
||||
if(sortedElements == null) {
|
||||
boolean hasNext = iterator.hasNext();
|
||||
sortedElements = hasNext ? pour(iterator) : LISTS.empty();
|
||||
if(hasNext) {
|
||||
sortedElements = COLLECTIONS.wrapper();
|
||||
pour(iterator, sortedElements);
|
||||
}
|
||||
else sortedElements = COLLECTIONS.wrapper();
|
||||
if(hasNext) sortedElements.unstableSort(sorter);
|
||||
}
|
||||
return index < sortedElements.size();
|
||||
@@ -933,7 +1135,7 @@ public class ITERATORS
|
||||
#if TYPE_BOOLEAN
|
||||
int filtered;
|
||||
#else
|
||||
SET KEY_GENERIC_TYPE filtered = new HASH_SETBRACES();
|
||||
COLLECTION KEY_GENERIC_TYPE filtered = COLLECTIONS.distinctWrapper();
|
||||
#endif
|
||||
KEY_TYPE lastFound;
|
||||
boolean foundNext = false;
|
||||
@@ -994,7 +1196,7 @@ public class ITERATORS
|
||||
if(foundNext) return;
|
||||
while(iterator.hasNext()) {
|
||||
lastFound = iterator.NEXT();
|
||||
if(filter.TEST_VALUE(lastFound)) {
|
||||
if(filter.test(lastFound)) {
|
||||
foundNext = true;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -2,10 +2,18 @@ package speiger.src.collections.PACKAGE.utils;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
#if IARRAY_FEATURE
|
||||
import java.util.Objects;
|
||||
import java.util.Random;
|
||||
#endif
|
||||
#if JAVA_VERSION>=17
|
||||
import java.util.random.RANDOM;
|
||||
#else
|
||||
import java.util.RANDOM;
|
||||
#endif
|
||||
import java.util.RandomAccess;
|
||||
#if IARRAY_FEATURE || TYPE_OBJECT
|
||||
import java.util.function.Consumer;
|
||||
#endif
|
||||
#if PRIMITIVES
|
||||
import java.nio.JAVA_BUFFER;
|
||||
#endif
|
||||
@@ -16,8 +24,10 @@ import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.lists.ABSTRACT_LIST;
|
||||
import speiger.src.collections.PACKAGE.lists.LIST;
|
||||
#if INT_LIST_MODULE && !TYPE_INT
|
||||
import speiger.src.collections.ints.lists.IntList;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
||||
import speiger.src.collections.utils.SanityChecks;
|
||||
|
||||
/**
|
||||
@@ -35,7 +45,7 @@ public class LISTS
|
||||
* @Type(T)
|
||||
* @return an empty list
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES EmptyList KEY_GENERIC_TYPE empty() {
|
||||
public static GENERIC_KEY_BRACES LIST KEY_GENERIC_TYPE empty() {
|
||||
#if TYPE_OBJECT
|
||||
return (EmptyList<KEY_TYPE>)EMPTY;
|
||||
#else
|
||||
@@ -60,7 +70,11 @@ public class LISTS
|
||||
* @return a synchronized list wrapper. If the list is implementing RandomAccess or IARRAY that is also transferred. If the List already a synchronized wrapper then it just returns itself.
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES LIST KEY_GENERIC_TYPE synchronize(LIST KEY_GENERIC_TYPE l) {
|
||||
#if IARRAY_FEATURE
|
||||
return l instanceof SynchronizedList ? l : (l instanceof IARRAY ? new SynchronizedArrayListBRACES(l) : (l instanceof RandomAccess ? new SynchronizedRandomAccessListBRACES(l) : new SynchronizedListBRACES(l)));
|
||||
#else
|
||||
return l instanceof SynchronizedList ? l : (l instanceof RandomAccess ? new SynchronizedRandomAccessListBRACES(l) : new SynchronizedListBRACES(l));
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -71,7 +85,11 @@ public class LISTS
|
||||
* @return a synchronized list wrapper. If the list is implementing RandomAccess or IARRAY that is also transferred. If the List already a synchronized wrapper then it just returns itself.
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES LIST KEY_GENERIC_TYPE synchronize(LIST KEY_GENERIC_TYPE l, Object mutex) {
|
||||
#if IARRAY_FEATURE
|
||||
return l instanceof SynchronizedList ? l : (l instanceof IARRAY ? new SynchronizedArrayListBRACES(l, mutex) : (l instanceof RandomAccess ? new SynchronizedRandomAccessListBRACES(l, mutex) : new SynchronizedListBRACES(l, mutex)));
|
||||
#else
|
||||
return l instanceof SynchronizedList ? l : (l instanceof RandomAccess ? new SynchronizedRandomAccessListBRACES(l, mutex) : new SynchronizedListBRACES(l, mutex));
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -92,6 +110,7 @@ public class LISTS
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES LIST KEY_GENERIC_TYPE reverse(LIST KEY_GENERIC_TYPE list) {
|
||||
int size = list.size();
|
||||
#if IARRAY_FEATURE
|
||||
if(list instanceof IARRAY) {
|
||||
IARRAY KEY_GENERIC_TYPE array = (IARRAY KEY_GENERIC_TYPE)list;
|
||||
#if TYPE_OBJECT
|
||||
@@ -106,6 +125,7 @@ public class LISTS
|
||||
return list;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
if(list instanceof RandomAccess) {
|
||||
for (int i = 0, mid = size >> 1, j = size - 1; i < mid; i++, j--) {
|
||||
KEY_TYPE t = list.GET_KEY(i);
|
||||
@@ -141,8 +161,9 @@ public class LISTS
|
||||
* @Type(T)
|
||||
* @return the input list
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES LIST KEY_GENERIC_TYPE shuffle(LIST KEY_GENERIC_TYPE list, Random random) {
|
||||
public static GENERIC_KEY_BRACES LIST KEY_GENERIC_TYPE shuffle(LIST KEY_GENERIC_TYPE list, RANDOM random) {
|
||||
int size = list.size();
|
||||
#if IARRAY_FEATURE
|
||||
if(list instanceof IARRAY) {
|
||||
IARRAY KEY_GENERIC_TYPE array = (IARRAY KEY_GENERIC_TYPE)list;
|
||||
#if TYPE_OBJECT
|
||||
@@ -164,7 +185,8 @@ public class LISTS
|
||||
#endif
|
||||
return list;
|
||||
}
|
||||
for(int i = list.size(); i-- != 0;) {
|
||||
#endif
|
||||
for(int i = size; i-- != 0;) {
|
||||
int p = random.nextInt(i + 1);
|
||||
KEY_TYPE t = list.GET_KEY(i);
|
||||
list.set(i, list.GET_KEY(p));
|
||||
@@ -231,6 +253,7 @@ public class LISTS
|
||||
public SingletonList KEY_GENERIC_TYPE copy() { return new SingletonListBRACES(element); }
|
||||
}
|
||||
|
||||
#if IARRAY_FEATURE
|
||||
private static class SynchronizedArrayList KEY_GENERIC_TYPE extends SynchronizedList KEY_GENERIC_TYPE implements IARRAY KEY_GENERIC_TYPE
|
||||
{
|
||||
IARRAY KEY_GENERIC_TYPE l;
|
||||
@@ -271,6 +294,7 @@ public class LISTS
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
private static class SynchronizedRandomAccessList KEY_GENERIC_TYPE extends SynchronizedList KEY_GENERIC_TYPE implements RandomAccess
|
||||
{
|
||||
SynchronizedRandomAccessList(LIST KEY_GENERIC_TYPE l) {
|
||||
@@ -387,11 +411,28 @@ public class LISTS
|
||||
return l.listIterator(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE indexedIterator(int...indecies) {
|
||||
return l.indexedIterator(indecies);
|
||||
}
|
||||
|
||||
#if INT_LIST_MODULE
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE indexedIterator(IntList indecies) {
|
||||
return l.indexedIterator(indecies);
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public LIST KEY_GENERIC_TYPE subList(int from, int to) {
|
||||
return LISTS.synchronize(l.subList(from, to));
|
||||
}
|
||||
|
||||
@Override
|
||||
public LIST KEY_GENERIC_TYPE reversed() {
|
||||
return LISTS.synchronize(l.reversed());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void size(int size) { synchronized(mutex) { l.size(size); } }
|
||||
|
||||
@@ -509,11 +550,28 @@ public class LISTS
|
||||
return ITERATORS.unmodifiable(l.listIterator(index));
|
||||
}
|
||||
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE indexedIterator(int...indecies) {
|
||||
return ITERATORS.unmodifiable(l.indexedIterator(indecies));
|
||||
}
|
||||
|
||||
#if INT_LIST_MODULE
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE indexedIterator(IntList indecies) {
|
||||
return ITERATORS.unmodifiable(l.indexedIterator(indecies));
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public LIST KEY_GENERIC_TYPE subList(int from, int to) {
|
||||
return LISTS.unmodifiable(l.subList(from, to));
|
||||
}
|
||||
|
||||
@Override
|
||||
public LIST KEY_GENERIC_TYPE reversed() {
|
||||
return LISTS.unmodifiable(l.reversed());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void size(int size) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@@ -602,6 +660,18 @@ public class LISTS
|
||||
return ITERATORS.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE indexedIterator(int...indecies) {
|
||||
return ITERATORS.empty();
|
||||
}
|
||||
|
||||
#if INT_LIST_MODULE
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE indexedIterator(IntList indecies) {
|
||||
return ITERATORS.empty();
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public int hashCode() { return 1; }
|
||||
|
||||
@@ -615,6 +685,9 @@ public class LISTS
|
||||
@Override
|
||||
public LIST KEY_GENERIC_TYPE subList(int from, int to) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public LIST KEY_GENERIC_TYPE reversed() { return this; }
|
||||
|
||||
@Override
|
||||
public void size(int size) { throw new UnsupportedOperationException(); }
|
||||
|
||||
|
||||
+30
-2
@@ -4,19 +4,33 @@ package speiger.src.collections.PACKAGE.utils;
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.BiFunction;
|
||||
#endif
|
||||
#if JDK_FUNCTION
|
||||
import java.util.function.PREDICATE;
|
||||
#endif
|
||||
#if JDK_TYPE
|
||||
import java.util.OPTIONAL;
|
||||
#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
|
||||
#if !JDK_TYPE
|
||||
import speiger.src.collections.PACKAGE.functions.OPTIONAL;
|
||||
#endif
|
||||
#if DEQUEUE_FEATURE
|
||||
import speiger.src.collections.PACKAGE.queues.PRIORITY_DEQUEUE;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.queues.PRIORITY_QUEUE;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
#endif
|
||||
#if !JDK_FUNCTION
|
||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||
|
||||
/**
|
||||
@@ -46,6 +60,7 @@ public class PRIORITY_QUEUES
|
||||
return queue instanceof SynchronizedPriorityQueue ? (SynchronizedPriorityQueue KEY_GENERIC_TYPE)queue : new SynchronizedPriorityQueueBRACES(queue, mutex);
|
||||
}
|
||||
|
||||
#if DEQUEUE_FEATURE
|
||||
/**
|
||||
* Returns a synchronized PriorityDequeue instance based on the instance given.
|
||||
* @param dequeue that should be synchronized
|
||||
@@ -67,6 +82,7 @@ public class PRIORITY_QUEUES
|
||||
return dequeue instanceof SynchronizedPriorityDequeue ? (SynchronizedPriorityDequeue KEY_GENERIC_TYPE)dequeue : new SynchronizedPriorityDequeueBRACES(dequeue, mutex);
|
||||
}
|
||||
|
||||
#endif
|
||||
/**
|
||||
* Wrapper class for synchronization
|
||||
* @Type(T)
|
||||
@@ -107,6 +123,8 @@ public class PRIORITY_QUEUES
|
||||
@Override
|
||||
public KEY_TYPE peek(int index) { synchronized(mutex) { return queue.peek(index); } }
|
||||
@Override
|
||||
public boolean contains(KEY_TYPE e) { synchronized(mutex) { return queue.contains(e); } }
|
||||
@Override
|
||||
public boolean removeFirst(KEY_TYPE e) { synchronized(mutex) { return queue.removeFirst(e); } }
|
||||
@Override
|
||||
public boolean removeLast(KEY_TYPE e) { synchronized(mutex) { return queue.removeLast(e); } }
|
||||
@@ -129,11 +147,20 @@ public class PRIORITY_QUEUES
|
||||
@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); } }
|
||||
public OPTIONAL KEY_GENERIC_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) { synchronized(mutex) { return queue.findFirst(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 queue.reduce(identity, operator); } }
|
||||
#else
|
||||
@Override
|
||||
public KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) { synchronized(mutex) { return queue.reduce(identity, operator); } }
|
||||
#endif
|
||||
@Override
|
||||
public OPTIONAL KEY_GENERIC_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) { synchronized(mutex) { return queue.reduce(operator); } }
|
||||
@Override
|
||||
public int count(PREDICATE KEY_GENERIC_TYPE filter) { synchronized(mutex) { return queue.count(filter); } }
|
||||
}
|
||||
|
||||
#if DEQUEUE_FEATURE
|
||||
/**
|
||||
* Wrapper class for synchronization
|
||||
* @Type(T)
|
||||
@@ -166,4 +193,5 @@ public class PRIORITY_QUEUES
|
||||
@Override
|
||||
public PRIORITY_DEQUEUE KEY_GENERIC_TYPE copy() { synchronized(mutex) { return dequeue.copy(); } }
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -2,31 +2,30 @@ package speiger.src.collections.PACKAGE.utils;
|
||||
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Set;
|
||||
#if TYPE_BOOLEAN
|
||||
import speiger.src.collections.booleans.collections.BooleanIterator;
|
||||
import speiger.src.collections.booleans.sets.AbstractBooleanSet;
|
||||
import speiger.src.collections.booleans.sets.BooleanSet;
|
||||
import speiger.src.collections.booleans.utils.BooleanCollections.EmptyCollection;
|
||||
#else
|
||||
#if TYPE_OBJECT
|
||||
#if TYPE_OBJECT && SORTED_SET_FEATURE
|
||||
import java.util.Comparator;
|
||||
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
||||
#if !TYPE_OBJECT
|
||||
#if !TYPE_OBJECT && SORTED_SET_FEATURE
|
||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
#if SORTED_SET_FEATURE
|
||||
import speiger.src.collections.PACKAGE.sets.NAVIGABLE_SET;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.sets.ABSTRACT_SET;
|
||||
import speiger.src.collections.PACKAGE.sets.SET;
|
||||
#if ORDERED_SET_FEATURE
|
||||
import speiger.src.collections.PACKAGE.sets.ORDERED_SET;
|
||||
#endif
|
||||
#if SORTED_SET_FEATURE
|
||||
import speiger.src.collections.PACKAGE.sets.SORTED_SET;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.utils.COLLECTIONS.EmptyCollection;
|
||||
import speiger.src.collections.PACKAGE.utils.COLLECTIONS.SynchronizedCollection;
|
||||
import speiger.src.collections.PACKAGE.utils.COLLECTIONS.UnmodifiableCollection;
|
||||
import speiger.src.collections.utils.ITrimmable;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* A Helper class for sets
|
||||
@@ -51,7 +50,6 @@ public class SETS
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !TYPE_BOOLEAN
|
||||
/**
|
||||
* Creates a Synchronized set while preserving the ITrimmable interface
|
||||
* @param s the set that should be synchronized
|
||||
@@ -75,6 +73,7 @@ public class SETS
|
||||
return s instanceof SynchronizedSet ? s : (s instanceof ITrimmable ? new SynchronizedTrimSetBRACES(s, mutex) : new SynchronizedSetBRACES(s, mutex));
|
||||
}
|
||||
|
||||
#if SORTED_SET_FEATURE
|
||||
/**
|
||||
* Creates a Synchronized SortedSet while preserving the ITrimmable interface
|
||||
* @param s the set that should be synchronized
|
||||
@@ -98,6 +97,8 @@ public class SETS
|
||||
return s instanceof SynchronizedSortedSet ? s : (s instanceof ITrimmable ? new SynchronizedSortedTrimSetBRACES(s, mutex) : new SynchronizedSortedSetBRACES(s, mutex));
|
||||
}
|
||||
|
||||
#endif
|
||||
#if ORDERED_SET_FEATURE
|
||||
/**
|
||||
* Creates a Synchronized OrderedSet while preserving the ITrimmable interface
|
||||
* @param s the set that should be synchronized
|
||||
@@ -121,6 +122,8 @@ public class SETS
|
||||
return s instanceof SynchronizedOrderedSet ? s : (s instanceof ITrimmable ? new SynchronizedOrderedTrimSetBRACES(s, mutex) : new SynchronizedOrderedSetBRACES(s, mutex));
|
||||
}
|
||||
|
||||
#endif
|
||||
#if SORTED_SET_FEATURE
|
||||
/**
|
||||
* Creates a Synchronized NavigableSet while preserving the ITrimmable interface
|
||||
* @param s the set that should be synchronized
|
||||
@@ -144,6 +147,7 @@ public class SETS
|
||||
return s instanceof SynchronizedNavigableSet ? s : (s instanceof ITrimmable ? new SynchronizedNavigableTrimSetBRACES(s, mutex) : new SynchronizedNavigableSetBRACES(s, mutex));
|
||||
}
|
||||
|
||||
#endif
|
||||
/**
|
||||
* Creates Unmodifyable Set wrapper
|
||||
* @param s set that should be made unmodifiable
|
||||
@@ -154,6 +158,7 @@ public class SETS
|
||||
return s instanceof UnmodifiableSet ? s : new UnmodifiableSetBRACES(s);
|
||||
}
|
||||
|
||||
#if SORTED_SET_FEATURE
|
||||
/**
|
||||
* Creates Unmodifyable SortedSet wrapper
|
||||
* @param s sortedSet that should be made unmodifiable
|
||||
@@ -164,6 +169,8 @@ public class SETS
|
||||
return s instanceof UnmodifiableSortedSet ? s : new UnmodifiableSortedSetBRACES(s);
|
||||
}
|
||||
|
||||
#endif
|
||||
#if ORDERED_SET_FEATURE
|
||||
/**
|
||||
* Creates Unmodifyable OrderedSet wrapper
|
||||
* @param s OrderedSet that should be made unmodifiable
|
||||
@@ -174,6 +181,8 @@ public class SETS
|
||||
return s instanceof UnmodifiableOrderedSet ? s : new UnmodifiableOrderedSetBRACES(s);
|
||||
}
|
||||
|
||||
#endif
|
||||
#if SORTED_SET_FEATURE
|
||||
/**
|
||||
* Creates Unmodifyable NavigableSet wrapper
|
||||
* @param s navigableSet that should be made unmodifiable
|
||||
@@ -254,7 +263,7 @@ public class SETS
|
||||
public EmptySet KEY_GENERIC_TYPE copy() { return this; }
|
||||
}
|
||||
|
||||
#if !TYPE_BOOLEAN
|
||||
#if SORTED_SET_FEATURE
|
||||
private static class UnmodifiableNavigableSet KEY_GENERIC_TYPE extends UnmodifiableSortedSet KEY_GENERIC_TYPE implements NAVIGABLE_SET KEY_GENERIC_TYPE
|
||||
{
|
||||
NAVIGABLE_SET KEY_GENERIC_TYPE n;
|
||||
@@ -340,6 +349,8 @@ public class SETS
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) { return SETS.unmodifiable(n.tailSet(fromElement)); }
|
||||
}
|
||||
|
||||
#endif
|
||||
#if ORDERED_SET_FEATURE
|
||||
private static class UnmodifiableOrderedSet KEY_GENERIC_TYPE extends UnmodifiableSet KEY_GENERIC_TYPE implements ORDERED_SET KEY_GENERIC_TYPE
|
||||
{
|
||||
ORDERED_SET KEY_GENERIC_TYPE s;
|
||||
@@ -349,6 +360,10 @@ public class SETS
|
||||
s = c;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addFirst(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void addLast(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean addAndMoveToFirst(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
@@ -360,19 +375,23 @@ public class SETS
|
||||
@Override
|
||||
public BI_ITERATOR KEY_GENERIC_TYPE iterator() { return ITERATORS.unmodifiable(s.iterator()); }
|
||||
@Override
|
||||
public BI_ITERATOR KEY_GENERIC_TYPE reverseIterator() { return ITERATORS.unmodifiable(s.reverseIterator()); }
|
||||
@Override
|
||||
public BI_ITERATOR KEY_GENERIC_TYPE iterator(KEY_TYPE fromElement) { return ITERATORS.unmodifiable(s.iterator(fromElement)); }
|
||||
@Override
|
||||
public ORDERED_SET KEY_GENERIC_TYPE copy() { return s.copy(); }
|
||||
@Override
|
||||
public KEY_TYPE FIRST_KEY() { return s.FIRST_KEY(); }
|
||||
public KEY_TYPE GET_FIRST_KEY() { return s.GET_FIRST_KEY(); }
|
||||
@Override
|
||||
public KEY_TYPE POLL_FIRST_KEY() { throw new UnsupportedOperationException(); }
|
||||
public KEY_TYPE REMOVE_FIRST_KEY() { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public KEY_TYPE LAST_KEY() { return s.LAST_KEY(); }
|
||||
public KEY_TYPE GET_LAST_KEY() { return s.GET_LAST_KEY(); }
|
||||
@Override
|
||||
public KEY_TYPE POLL_LAST_KEY() { throw new UnsupportedOperationException(); }
|
||||
public KEY_TYPE REMOVE_LAST_KEY() { throw new UnsupportedOperationException(); }
|
||||
}
|
||||
|
||||
#endif
|
||||
#if SORTED_SET_FEATURE
|
||||
private static class UnmodifiableSortedSet KEY_GENERIC_TYPE extends UnmodifiableSet KEY_GENERIC_TYPE implements SORTED_SET KEY_GENERIC_TYPE
|
||||
{
|
||||
SORTED_SET KEY_GENERIC_TYPE s;
|
||||
@@ -406,6 +425,7 @@ public class SETS
|
||||
public KEY_TYPE POLL_LAST_KEY() { throw new UnsupportedOperationException(); }
|
||||
}
|
||||
|
||||
#endif
|
||||
/**
|
||||
* Unmodifyable Set wrapper that helps is used with unmodifyableSet function
|
||||
* @Type(T)
|
||||
@@ -434,6 +454,7 @@ public class SETS
|
||||
#endif
|
||||
}
|
||||
|
||||
#if SORTED_SET_FEATURE
|
||||
private static class SynchronizedNavigableTrimSet KEY_GENERIC_TYPE extends SynchronizedNavigableSet KEY_GENERIC_TYPE implements ITrimmable
|
||||
{
|
||||
ITrimmable trim;
|
||||
@@ -597,6 +618,8 @@ public class SETS
|
||||
public KEY_TYPE POLL_LAST_KEY() { synchronized(mutex) { return s.POLL_LAST_KEY(); } }
|
||||
}
|
||||
|
||||
#endif
|
||||
#if ORDERED_SET_FEATURE
|
||||
private static class SynchronizedOrderedTrimSet KEY_GENERIC_TYPE extends SynchronizedOrderedSet KEY_GENERIC_TYPE implements ITrimmable
|
||||
{
|
||||
ITrimmable trim;
|
||||
@@ -632,6 +655,10 @@ public class SETS
|
||||
s = c;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addFirst(KEY_TYPE o) { synchronized(mutex) { s.addFirst(o); } }
|
||||
@Override
|
||||
public void addLast(KEY_TYPE o) { synchronized(mutex) { s.addLast(o); } }
|
||||
@Override
|
||||
public boolean addAndMoveToFirst(KEY_TYPE o) { synchronized(mutex) { return s.addAndMoveToFirst(o); } }
|
||||
@Override
|
||||
@@ -643,19 +670,22 @@ public class SETS
|
||||
@Override
|
||||
public BI_ITERATOR KEY_GENERIC_TYPE iterator() { synchronized(mutex) { return s.iterator(); } }
|
||||
@Override
|
||||
public BI_ITERATOR KEY_GENERIC_TYPE reverseIterator() { synchronized(mutex) { return s.reverseIterator(); } }
|
||||
@Override
|
||||
public BI_ITERATOR KEY_GENERIC_TYPE iterator(KEY_TYPE fromElement) { synchronized(mutex) { return s.iterator(fromElement); } }
|
||||
@Override
|
||||
public ORDERED_SET KEY_GENERIC_TYPE copy() { synchronized(mutex) { return s.copy(); } }
|
||||
@Override
|
||||
public KEY_TYPE FIRST_KEY() { synchronized(mutex) { return s.FIRST_KEY(); } }
|
||||
public KEY_TYPE GET_FIRST_KEY() { synchronized(mutex) { return s.GET_FIRST_KEY(); } }
|
||||
@Override
|
||||
public KEY_TYPE POLL_FIRST_KEY() { synchronized(mutex) { return s.POLL_FIRST_KEY(); } }
|
||||
public KEY_TYPE REMOVE_FIRST_KEY() { synchronized(mutex) { return s.REMOVE_FIRST_KEY(); } }
|
||||
@Override
|
||||
public KEY_TYPE LAST_KEY() { synchronized(mutex) { return s.LAST_KEY(); } }
|
||||
public KEY_TYPE GET_LAST_KEY() { synchronized(mutex) { return s.GET_LAST_KEY(); } }
|
||||
@Override
|
||||
public KEY_TYPE POLL_LAST_KEY() { synchronized(mutex) { return s.POLL_LAST_KEY(); } }
|
||||
public KEY_TYPE REMOVE_LAST_KEY() { synchronized(mutex) { return s.REMOVE_LAST_KEY(); } }
|
||||
}
|
||||
|
||||
#endif
|
||||
private static class SynchronizedTrimSet KEY_GENERIC_TYPE extends SynchronizedSet KEY_GENERIC_TYPE implements ITrimmable
|
||||
{
|
||||
ITrimmable trim;
|
||||
@@ -704,5 +734,4 @@ public class SETS
|
||||
public boolean remove(KEY_TYPE o) { synchronized(mutex) { return s.remove(o); } }
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package speiger.src.collections.PACKAGE.utils;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* A Type Specific Strategy class that allows to give control hashcode generation and equals comparason for maps
|
||||
* @Type(T)
|
||||
@@ -19,6 +21,17 @@ public interface STRATEGY KEY_GENERIC_TYPE
|
||||
public static GENERIC_KEY_BRACES STRATEGY KEY_GENERIC_TYPE identityStrategy() { return (STRATEGY<KEY_TYPE>)IDENTITY; }
|
||||
|
||||
#endif
|
||||
/**
|
||||
* Normal Strategy
|
||||
*/
|
||||
public static final STRATEGY NO_GENERIC_TYPE NORMAL = new NormalStrategyBRACES();
|
||||
|
||||
/**
|
||||
* @Type(T)
|
||||
* @return a Normal Strategy that is behaving exactly like the normal Hash Strategy in the Hash Collections
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES STRATEGY KEY_GENERIC_TYPE normalStrategy() { return (STRATEGY KEY_GENERIC_TYPE)NORMAL; }
|
||||
|
||||
/**
|
||||
* Type Specific HashCode function
|
||||
* @param o the element that the hashcode is requested for (if object may be null)
|
||||
@@ -47,5 +60,18 @@ public interface STRATEGY KEY_GENERIC_TYPE
|
||||
@Override
|
||||
public boolean equals(KEY_TYPE key, KEY_TYPE value) { return key == value; }
|
||||
}
|
||||
|
||||
#endif
|
||||
/**
|
||||
* A Strategy that simulates the normal Hash Collection Behavior if you want to use Hash Control Collections to replace normal ones.
|
||||
* Only real reason to do that is you have to use this and want to get rid of implementations.
|
||||
* @Type(T)
|
||||
*/
|
||||
public static class NormalStrategy KEY_GENERIC_TYPE implements STRATEGY KEY_GENERIC_TYPE
|
||||
{
|
||||
@Override
|
||||
public int hashCode(KEY_TYPE o) { return KEY_TO_HASH(o); }
|
||||
@Override
|
||||
public boolean equals(KEY_TYPE key, KEY_TYPE value) { return EQUALS_KEY_TYPE(key, value); }
|
||||
}
|
||||
}
|
||||
+129
-20
@@ -3,9 +3,9 @@ package speiger.src.collections.PACKAGE.utils.maps;
|
||||
#if !TYPE_BOOLEAN
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
#if TYPE_OBJECT
|
||||
#if TYPE_OBJECT && SORTED_MAP_FEATURE
|
||||
import java.util.Comparator;
|
||||
#else
|
||||
#else if !TYPE_OBJECT
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.BiFunction;
|
||||
#endif
|
||||
@@ -14,45 +14,56 @@ import java.util.function.Consumer;
|
||||
#if !TYPE_OBJECT && !TYPE_BOOLEAN
|
||||
import java.util.function.Function;
|
||||
#endif
|
||||
#if VALUE_BOOLEAN && JDK_TYPE
|
||||
import java.util.function.PREDICATE;
|
||||
#endif
|
||||
|
||||
import speiger.src.collections.objects.collections.ObjectIterable;
|
||||
import speiger.src.collections.objects.collections.ObjectIterator;
|
||||
import speiger.src.collections.objects.sets.ObjectSet;
|
||||
#if !TYPE_BOOLEAN
|
||||
import speiger.src.collections.objects.collections.ObjectBidirectionalIterator;
|
||||
import speiger.src.collections.objects.utils.ObjectIterators;
|
||||
import speiger.src.collections.objects.utils.ObjectSets;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.objects.sets.ObjectOrderedSet;
|
||||
#if SORTED_MAP_FEATURE
|
||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
#endif
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
|
||||
#if !VALUE_BOOLEAN || !JDK_TYPE
|
||||
import speiger.src.collections.PACKAGE.functions.function.FUNCTION;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||
import speiger.src.collections.PACKAGE.maps.abstracts.ABSTRACT_MAP;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.maps.interfaces.MAP;
|
||||
#if !TYPE_BOOLEAN
|
||||
#if SORTED_MAP_FEATURE
|
||||
import speiger.src.collections.PACKAGE.maps.interfaces.NAVIGABLE_MAP;
|
||||
import speiger.src.collections.PACKAGE.maps.interfaces.SORTED_MAP;
|
||||
#endif
|
||||
#if ORDERED_MAP_FEATURE
|
||||
import speiger.src.collections.PACKAGE.maps.interfaces.ORDERED_MAP;
|
||||
#endif
|
||||
#if SORTED_MAP_FEATURE
|
||||
import speiger.src.collections.PACKAGE.sets.NAVIGABLE_SET;
|
||||
import speiger.src.collections.PACKAGE.sets.SORTED_SET;
|
||||
#endif
|
||||
#if ORDERED_MAP_FEATURE
|
||||
import speiger.src.collections.PACKAGE.sets.ORDERED_SET;
|
||||
#endif
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.sets.SET;
|
||||
import speiger.src.collections.PACKAGE.utils.SETS;
|
||||
#endif
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_COLLECTION;
|
||||
#if ORDERED_MAP_FEATURE
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ORDERED_COLLECTION;
|
||||
#endif
|
||||
#if !SAME_TYPE
|
||||
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_UNARY_OPERATOR;
|
||||
#endif
|
||||
import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_SUPPLIER;
|
||||
import speiger.src.collections.VALUE_PACKAGE.utils.VALUE_COLLECTIONS;
|
||||
#if !SAME_TYPE && !VALUE_OBJECT
|
||||
import speiger.src.collections.VALUE_PACKAGE.utils.VALUE_SETS;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/**
|
||||
* A Helper class that provides you with Singleton/Empty/Synchronized/Unmodifyable Maps
|
||||
@@ -123,8 +134,6 @@ public class MAPS
|
||||
else entries.forEach(action);
|
||||
}
|
||||
|
||||
#if !TYPE_BOOLEAN
|
||||
|
||||
/**
|
||||
* Helper function that creates a Helper wrapper to synchronize access into the map.
|
||||
* @param map the map that should be synchronized
|
||||
@@ -147,6 +156,7 @@ public class MAPS
|
||||
*/
|
||||
public static GENERIC_KEY_VALUE_BRACES MAP KEY_VALUE_GENERIC_TYPE synchronize(MAP KEY_VALUE_GENERIC_TYPE map, Object mutex) { return map instanceof SynchronizedMap ? map : new SynchronizedMapKV_BRACES(map, mutex); }
|
||||
|
||||
#if SORTED_MAP_FEATURE
|
||||
/**
|
||||
* Helper function that creates a Helper wrapper to synchronize access into the SortedMap.
|
||||
* @param map the SortedMap that should be synchronized
|
||||
@@ -169,6 +179,8 @@ public class MAPS
|
||||
*/
|
||||
public static GENERIC_KEY_VALUE_BRACES SORTED_MAP KEY_VALUE_GENERIC_TYPE synchronize(SORTED_MAP KEY_VALUE_GENERIC_TYPE map, Object mutex) { return map instanceof SynchronizedSortedMap ? map : new SynchronizedSortedMapKV_BRACES(map, mutex); }
|
||||
|
||||
#endif
|
||||
#if ORDERED_MAP_FEATURE
|
||||
/**
|
||||
* Helper function that creates a Helper wrapper to synchronize access into the OrderedMap.
|
||||
* @param map the OrderedMap that should be synchronized
|
||||
@@ -191,6 +203,8 @@ public class MAPS
|
||||
*/
|
||||
public static GENERIC_KEY_VALUE_BRACES ORDERED_MAP KEY_VALUE_GENERIC_TYPE synchronize(ORDERED_MAP KEY_VALUE_GENERIC_TYPE map, Object mutex) { return map instanceof SynchronizedOrderedMap ? map : new SynchronizedOrderedMapKV_BRACES(map, mutex); }
|
||||
|
||||
#endif
|
||||
#if SORTED_MAP_FEATURE
|
||||
/**
|
||||
* Helper function that creates a Helper wrapper to synchronize access into the NavigableMap.
|
||||
* @param map the NavigableMap that should be synchronized
|
||||
@@ -213,6 +227,7 @@ public class MAPS
|
||||
*/
|
||||
public static GENERIC_KEY_VALUE_BRACES NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE synchronize(NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE map, Object mutex) { return map instanceof SynchronizedNavigableMap ? map : new SynchronizedNavigableMapKV_BRACES(map, mutex); }
|
||||
|
||||
#endif
|
||||
/**
|
||||
* A Helper function that creates a Helper wrapper to only allow Read Access into the Map
|
||||
* @param map the map that should be made Unmodifiable
|
||||
@@ -223,6 +238,7 @@ public class MAPS
|
||||
*/
|
||||
public static GENERIC_KEY_VALUE_BRACES MAP KEY_VALUE_GENERIC_TYPE unmodifiable(MAP KEY_VALUE_GENERIC_TYPE map) { return map instanceof UnmodifyableMap ? map : new UnmodifyableMapKV_BRACES(map); }
|
||||
|
||||
#if ORDERED_MAP_FEATURE
|
||||
/**
|
||||
* A Helper function that creates a Helper wrapper to only allow Read Access into the OrderedMap
|
||||
* @param map the OrderedMap that should be made Unmodifiable
|
||||
@@ -233,6 +249,8 @@ public class MAPS
|
||||
*/
|
||||
public static GENERIC_KEY_VALUE_BRACES ORDERED_MAP KEY_VALUE_GENERIC_TYPE unmodifiable(ORDERED_MAP KEY_VALUE_GENERIC_TYPE map) { return map instanceof UnmodifyableOrderedMap ? map : new UnmodifyableOrderedMapKV_BRACES(map); }
|
||||
|
||||
#endif
|
||||
#if SORTED_MAP_FEATURE
|
||||
/**
|
||||
* A Helper function that creates a Helper wrapper to only allow Read Access into the SortedMap
|
||||
* @param map the SortedMap that should be made Unmodifiable
|
||||
@@ -253,6 +271,7 @@ public class MAPS
|
||||
*/
|
||||
public static GENERIC_KEY_VALUE_BRACES NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE unmodifiable(NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE map) { return map instanceof UnmodifyableNavigableMap ? map : new UnmodifyableNavigableMapKV_BRACES(map); }
|
||||
|
||||
#endif
|
||||
/**
|
||||
* A Helper function that creates a Unmodifyable Entry
|
||||
* @param entry the Entry that should be made unmodifiable
|
||||
@@ -330,6 +349,16 @@ public class MAPS
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR 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(); }
|
||||
#if !VALUE_OBJECT
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTENonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_ABSENTNonDefault(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENTNonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENTNonDefault(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) { throw new UnsupportedOperationException(); }
|
||||
#endif
|
||||
@Override
|
||||
public VALUE_TYPE MERGE(KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
@@ -344,7 +373,7 @@ public class MAPS
|
||||
|
||||
@Override
|
||||
public VALUE_COLLECTION VALUE_GENERIC_TYPE values() {
|
||||
if(values == null) values = VALUE_SETS.singleton(value);
|
||||
if(values == null) values = VALUE_COLLECTIONS.singleton(value);
|
||||
return values;
|
||||
}
|
||||
@Override
|
||||
@@ -392,6 +421,16 @@ public class MAPS
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR 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(); }
|
||||
#if !VALUE_OBJECT
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTENonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_ABSENTNonDefault(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENTNonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENTNonDefault(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) { throw new UnsupportedOperationException(); }
|
||||
#endif
|
||||
@Override
|
||||
public VALUE_TYPE MERGE(KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
@@ -425,6 +464,7 @@ public class MAPS
|
||||
public void set(KEY_TYPE key, VALUE_TYPE value) { throw new UnsupportedOperationException(); }
|
||||
}
|
||||
|
||||
#if SORTED_MAP_FEATURE
|
||||
/**
|
||||
* The Unmodifyable Navigable Map implementation that is sued for the unmodifyableMap function
|
||||
* @Type(T)
|
||||
@@ -496,6 +536,8 @@ public class MAPS
|
||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE copy() { return map.copy(); }
|
||||
}
|
||||
|
||||
#endif
|
||||
#if ORDERED_MAP_FEATURE
|
||||
/**
|
||||
* The Unmodifyable Ordered Map implementation that is sued for the unmodifyableMap function
|
||||
* @Type(T)
|
||||
@@ -514,6 +556,10 @@ public class MAPS
|
||||
@Override
|
||||
public VALUE_TYPE putAndMoveToLast(KEY_TYPE key, VALUE_TYPE value) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE putFirst(KEY_TYPE key, VALUE_TYPE value) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE putLast(KEY_TYPE key, VALUE_TYPE value) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean moveToFirst(KEY_TYPE key) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean moveToLast(KEY_TYPE key) { throw new UnsupportedOperationException(); }
|
||||
@@ -534,13 +580,25 @@ public class MAPS
|
||||
@Override
|
||||
public VALUE_TYPE LAST_ENTRY_VALUE() { return map.LAST_ENTRY_VALUE(); }
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE firstEntry() { return map.firstEntry(); }
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE lastEntry() { return 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 ORDERED_MAP KEY_VALUE_GENERIC_TYPE copy() { return map.copy(); }
|
||||
@Override
|
||||
public ORDERED_SET KEY_GENERIC_TYPE keySet() {
|
||||
if(keys == null) keys = SETS.unmodifiable(map.keySet());
|
||||
return (ORDERED_SET KEY_GENERIC_TYPE)keys;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE values() {
|
||||
if(values == null) values = VALUE_COLLECTIONS.unmodifiable(map.values());
|
||||
return (VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE)values;
|
||||
}
|
||||
@Override
|
||||
public ObjectOrderedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> ENTRY_SET() {
|
||||
if(entrySet == null) entrySet = new UnmodifyableOrderedEntrySetKV_BRACES(map.ENTRY_SET());
|
||||
@@ -548,6 +606,8 @@ public class MAPS
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
#if SORTED_MAP_FEATURE
|
||||
/**
|
||||
* The Unmodifyable Sorted Map implementation that is sued for the unmodifyableMap function
|
||||
* @Type(T)
|
||||
@@ -587,6 +647,7 @@ public class MAPS
|
||||
public SORTED_MAP KEY_VALUE_GENERIC_TYPE copy() { return map.copy(); }
|
||||
}
|
||||
|
||||
#endif
|
||||
/**
|
||||
* The Unmodifyable Map implementation that is sued for the unmodifyableMap function
|
||||
* @Type(T)
|
||||
@@ -637,6 +698,16 @@ public class MAPS
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR 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(); }
|
||||
#if !VALUE_OBJECT
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTENonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_ABSENTNonDefault(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENTNonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENTNonDefault(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) { throw new UnsupportedOperationException(); }
|
||||
#endif
|
||||
@Override
|
||||
public VALUE_TYPE MERGE(KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
@@ -669,7 +740,7 @@ public class MAPS
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#if ORDERED_MAP_FEATURE
|
||||
/**
|
||||
* The Unmodifyable Ordered Set implementation for the Unmodifyable Ordered Map implementation
|
||||
* @Type(T)
|
||||
@@ -684,6 +755,10 @@ public class MAPS
|
||||
set = c;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addFirst(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void addLast(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean addAndMoveToFirst(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
@@ -697,17 +772,20 @@ public class MAPS
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> iterator() { return ObjectIterators.unmodifiable(set.iterator()); }
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> reverseIterator() { return ObjectIterators.unmodifiable(set.reverseIterator()); }
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> iterator(MAP.Entry KEY_VALUE_GENERIC_TYPE fromElement) { return ObjectIterators.unmodifiable(set.iterator(fromElement)); }
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE first() { return set.first(); }
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE getFirst() { return set.getFirst(); }
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollFirst() { throw new UnsupportedOperationException(); }
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE removeFirst() { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE last() { return set.last(); }
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE getLast() { return set.getLast(); }
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollLast() { throw new UnsupportedOperationException(); }
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE removeLast() { throw new UnsupportedOperationException(); }
|
||||
}
|
||||
|
||||
#endif
|
||||
/**
|
||||
* The Unmodifyable Set implementation for the Unmodifyable Map implementation
|
||||
* @Type(T)
|
||||
@@ -741,6 +819,7 @@ public class MAPS
|
||||
|
||||
}
|
||||
|
||||
#if SORTED_MAP_FEATURE
|
||||
/**
|
||||
* The Synchronized Navigable Map implementation used by the synchronizedMap helper function
|
||||
* @Type(T)
|
||||
@@ -859,6 +938,8 @@ public class MAPS
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
#if ORDERED_MAP_FEATURE
|
||||
/**
|
||||
* The Synchronized Ordered Map implementation used by the synchronizedMap helper function
|
||||
* @Type(T)
|
||||
@@ -882,6 +963,10 @@ public class MAPS
|
||||
@Override
|
||||
public VALUE_TYPE putAndMoveToLast(KEY_TYPE key, VALUE_TYPE value) { synchronized(mutex) { return map.putAndMoveToLast(key, value); } }
|
||||
@Override
|
||||
public VALUE_TYPE putFirst(KEY_TYPE key, VALUE_TYPE value) { synchronized(mutex) { return map.putFirst(key, value); } }
|
||||
@Override
|
||||
public VALUE_TYPE putLast(KEY_TYPE key, VALUE_TYPE value) { synchronized(mutex) { return map.putLast(key, value); } }
|
||||
@Override
|
||||
public boolean moveToFirst(KEY_TYPE key) { synchronized(mutex) { return map.moveToFirst(key); } }
|
||||
@Override
|
||||
public boolean moveToLast(KEY_TYPE key) { synchronized(mutex) { return map.moveToLast(key); } }
|
||||
@@ -902,13 +987,25 @@ public class MAPS
|
||||
@Override
|
||||
public VALUE_TYPE LAST_ENTRY_VALUE() { synchronized(mutex) { return map.LAST_ENTRY_VALUE(); } }
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE firstEntry() { synchronized(mutex) { return map.firstEntry(); } }
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE lastEntry() { synchronized(mutex) { return map.lastEntry(); } }
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollFirstEntry() { synchronized(mutex) { return map.pollFirstEntry(); } }
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollLastEntry() { synchronized(mutex) { return map.pollLastEntry(); } }
|
||||
@Override
|
||||
public ORDERED_MAP KEY_VALUE_GENERIC_TYPE copy() { synchronized(mutex) { return map.copy(); } }
|
||||
@Override
|
||||
public ORDERED_SET KEY_GENERIC_TYPE keySet() {
|
||||
if(keys == null) keys = SETS.synchronize(map.keySet(), mutex);
|
||||
return (ORDERED_SET KEY_GENERIC_TYPE)keys;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE values() {
|
||||
if(values == null) values = VALUE_COLLECTIONS.synchronize(map.values(), mutex);
|
||||
return (VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE)values;
|
||||
}
|
||||
@Override
|
||||
public ObjectOrderedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> ENTRY_SET() {
|
||||
if(entrySet == null) entrySet = ObjectSets.synchronize(map.ENTRY_SET(), mutex);
|
||||
@@ -916,6 +1013,8 @@ public class MAPS
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
#if SORTED_MAP_FEATURE
|
||||
/**
|
||||
* The Synchronized Sorted Map implementation used by the synchronizedMap helper function
|
||||
* @Type(T)
|
||||
@@ -977,6 +1076,7 @@ public class MAPS
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
/**
|
||||
* The Synchronized Map implementation used by the synchronizedMap helper function
|
||||
* @Type(T)
|
||||
@@ -1062,6 +1162,16 @@ public class MAPS
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { synchronized(mutex) { return map.COMPUTE_IF_PRESENT(key, mappingFunction); } }
|
||||
@Override
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENT(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) { synchronized(mutex) { return map.SUPPLY_IF_ABSENT(key, valueProvider); } }
|
||||
#if !VALUE_OBJECT
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTENonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { synchronized(mutex) { return map.COMPUTENonDefault(key, mappingFunction); } }
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_ABSENTNonDefault(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) { synchronized(mutex) { return map.COMPUTE_IF_ABSENTNonDefault(key, mappingFunction); } }
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENTNonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { synchronized(mutex) { return map.COMPUTE_IF_PRESENTNonDefault(key, mappingFunction); } }
|
||||
@Override
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENTNonDefault(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) { synchronized(mutex) { return map.SUPPLY_IF_ABSENTNonDefault(key, valueProvider); } }
|
||||
#endif
|
||||
@Override
|
||||
public VALUE_TYPE MERGE(KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) { synchronized(mutex) { return map.MERGE(key, value, mappingFunction); } }
|
||||
@Override
|
||||
@@ -1148,5 +1258,4 @@ public class MAPS
|
||||
public void forEach(BiConsumer<? super CLASS_TYPE, ? super CLASS_VALUE_TYPE> action) { synchronized(mutex) { map.forEach(action); } }
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user