Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8ff1d4f0b5 | ||
|
|
e56e136459 | ||
|
|
4db9c69a54 | ||
|
|
91aabe2096 | ||
|
|
4c565f2cf3 | ||
|
|
720fa44eed | ||
|
|
c46baa10b4 | ||
|
|
29ddc55947 | ||
|
|
2a2d9e8d95 | ||
|
|
49ce7fbfbe | ||
|
|
6afed5e174 | ||
|
|
640a1a8161 | ||
|
|
274d37c4d6 | ||
|
|
a89c812c06 | ||
|
|
867b3b4d9a | ||
|
|
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 | ||
|
|
ddc58ee221 | ||
|
|
8b5e5a75c1 | ||
|
|
c1862e6b05 | ||
|
|
c2c2780967 | ||
|
|
086d933a0d | ||
|
|
1e7da394a1 | ||
|
|
9eb220194f | ||
|
|
0baf141e4b | ||
|
|
569d4f5c86 | ||
|
|
36f24731b0 | ||
|
|
ea5ace0166 | ||
|
|
663809ff27 | ||
|
|
5d6adb5446 | ||
|
|
212ad1ace2 | ||
|
|
707827929a | ||
|
|
27ad01657d | ||
|
|
e7da7acc08 | ||
|
|
72943cb22c | ||
|
|
068cc4a4f7 | ||
|
|
31b34f5de1 | ||
|
|
4bded1af80 | ||
|
|
100c7fe260 | ||
|
|
04f628fcc1 | ||
|
|
5fa26bfbf3 | ||
|
|
4d3eaaf604 | ||
|
|
33ab7c48bf | ||
|
|
1f4784c75e | ||
|
|
ae5a4ea818 | ||
|
|
5d66f7b453 | ||
|
|
12af656150 | ||
|
|
603ff3df0f | ||
|
|
b712981718 | ||
|
|
863d1a1027 | ||
|
|
6287da8efe | ||
|
|
c27e852ccb | ||
|
|
0157765628 | ||
|
|
8689037ceb | ||
|
|
03a8914986 |
@@ -6,12 +6,6 @@
|
|||||||
<attribute name="gradle_used_by_scope" value="main,test"/>
|
<attribute name="gradle_used_by_scope" value="main,test"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</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">
|
<classpathentry kind="src" output="bin/test" path="src/test/java">
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="gradle_scope" value="test"/>
|
<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, 16, 17, 18, 19, 20]
|
||||||
|
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Set up JDK ${{ matrix.jdk }}
|
||||||
|
uses: actions/setup-java@v3
|
||||||
|
with:
|
||||||
|
distribution: 'temurin'
|
||||||
|
java-version: ${{ matrix.jdk }}
|
||||||
|
|
||||||
|
- name: Validate Gradle wrapper
|
||||||
|
uses: gradle/wrapper-validation-action@v1
|
||||||
|
|
||||||
|
- 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@v3
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Set up JDK 11
|
||||||
|
uses: actions/setup-java@v3
|
||||||
|
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@v1.2.4
|
||||||
|
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,38 +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: Generate SourceCode with Gradle
|
|
||||||
run: ./gradlew generateGithubSource
|
|
||||||
- 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@v2
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Set up JDK 11
|
||||||
|
uses: actions/setup-java@v3
|
||||||
|
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
|
||||||
+15
-9
@@ -20,15 +20,21 @@ gradle-app.setting
|
|||||||
/bin/
|
/bin/
|
||||||
/storage/
|
/storage/
|
||||||
#Generated Code
|
#Generated Code
|
||||||
/src/main/java/speiger/src/collections/booleans/*
|
|
||||||
/src/main/java/speiger/src/collections/bytes/*
|
|
||||||
/src/main/java/speiger/src/collections/shorts/*
|
#Generated Tests
|
||||||
/src/main/java/speiger/src/collections/chars/*
|
/src/test/java/speiger/src/testers/booleans/*
|
||||||
/src/main/java/speiger/src/collections/ints/*
|
/src/test/java/speiger/src/testers/bytes/*
|
||||||
/src/main/java/speiger/src/collections/longs/*
|
/src/test/java/speiger/src/testers/shorts/*
|
||||||
/src/main/java/speiger/src/collections/floats/*
|
/src/test/java/speiger/src/testers/chars/*
|
||||||
/src/main/java/speiger/src/collections/doubles/*
|
/src/test/java/speiger/src/testers/ints/*
|
||||||
/src/main/java/speiger/src/collections/objects/*
|
/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
|
#Cache result
|
||||||
/src/builder/resources/speiger/assets/collections/cache.bin
|
/src/builder/resources/speiger/assets/collections/cache.bin
|
||||||
|
/src/builder/resources/speiger/assets/testers/cache.bin
|
||||||
|
/src/builder/resources/speiger/assets/tests/cache.bin
|
||||||
|
|||||||
+279
-174
@@ -1,175 +1,280 @@
|
|||||||
# Changelog of versions
|
# Changelog of versions
|
||||||
|
|
||||||
### Version 0.6.0
|
### Version 0.8.1
|
||||||
- Added: addOrGet for sets.
|
- Added: getFirst/getLast/removeFirst/removeLast to List.class.
|
||||||
- Added: Async API which allows to easily execute Iterables/Collections offthread without the complexity.
|
- Added: Dedicated Set toArray implementations.
|
||||||
- Added: CopyOnWriteArrayList and tests for it
|
- Added: ToArray/pushTop functions to Stack.class.
|
||||||
- Added: Support up to Java17.
|
- 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: Build System now adds module-info if the Running JVM is 9 or higher
|
- Added: List.reversed, which returns a SubList that has all elements in reversed order and also inserts reversed.
|
||||||
- Added: ArrayList.of(Class, size) that allows you to allocate a size right at the creation of the List without having to create a wrapper array.
|
- Added: Iterators.infinite as an option that will create a Infinite Iterator based on the inputed one.
|
||||||
- Added: A ConcurrentHashMap implementation.
|
- Added: List.indexedIterator which allows you to create a iterator with a customized iteration indecies. Useful if you want to transform lists output.
|
||||||
- Fixed: containsValue in the HashMap wouldn't check the nullKey
|
- Added: PriorityQueue.contains is now a function
|
||||||
- Removed: Deprecated functions from SortedMaps/Sets
|
- 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.
|
||||||
### Version 0.5.3
|
- Fixed: Compute functions now perform with primitives more java compliant. Meaning that getDefaultReturnValue function no longer is seen as null.
|
||||||
- Added: OrderedMap/Set
|
- Fixed: Supplier was using the wrong dataType in their function name.
|
||||||
- Added: Deprecation to Functions that are specific to Ordered interfaces in the SortedMap/Set
|
- Updated: SimpleCodeGenerator 1.3.0 is now being used which allows for iterative code support.
|
||||||
- Added: subFrom to Maps which is the counterpart of the addTo method
|
|
||||||
- Added: pourAsList and pourAsSet (booleans excluded for sets) to Iterable
|
### Version 0.8.0
|
||||||
- Fixed: ArrayList.grow had a small bug where it would trigger to early causing performance problems with exact sized collections.
|
- Added: getFirst/getLast/removeFirst/removeLast to Lists
|
||||||
- Fixed: FIFOQueue size constructor had a small bug where it would trigger a array enlargement when all elements were inserted.
|
- Added: Dedicated implementations for toArray into TreeSets
|
||||||
|
- Fixed: forEach methods in Maps now can use "setValue" functions.
|
||||||
### Version 0.5.2
|
|
||||||
- Fixed: Bugs with Queues starting with the wrong size
|
### Version 0.8.0
|
||||||
- Fixed: ArrayGrowth for Queues was +1 instead of +50%
|
- Added: ISizeProvider interface (Optimization Helper)
|
||||||
- Added: Benchmarks with java and FastUtil
|
- 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.
|
||||||
### Version 0.5.1
|
- Added: Functions that have the same type, Int2IntFunction as example, have now a identity function.
|
||||||
- Fixed: Reworked the NavigableSet/Map implementations of RBTree/AVLTree/Array Sets/Maps so they are now deemed stable.
|
- Added: Functions of a BooleanValue have now alwaysTrue/False function.
|
||||||
- Added: Another 150k Unit tests.
|
- Added: ForEachIndexed for all Iterable implementations
|
||||||
- Added: List and Set Unit tests for Integer (or Primitives in this case) to ensure basic stability there. (Now covering all sets and lists)
|
- Added: RandomGenerator support (Java17), though requires self compilation
|
||||||
- Fixed: Bugs with null values for primitive collections.
|
- Added: Optimizations for HashUtils next power of function.
|
||||||
- Removed: ArraySet/Map subSet/subMap implementation was removed.
|
- Added: toArray() now returns a cached empty array if the collection is empty.
|
||||||
|
- Added: toArray function for AsyncBuilder
|
||||||
### Version 0.5.0
|
- Added: Modularization to the library where feature can be disabled as needed. (Requires Self-Compilation)
|
||||||
- Added: 2 Helper functions to find out how many bits are required to store a Number.
|
- Fixed: putIfAbsent now replaces defaultValues
|
||||||
- Added: pour function directly into Iterable which allows to collect all elements in the Iterable directly.
|
- Fixed: OpenHashSet/Map and their Custom Variants no longer rely on List implementations.
|
||||||
- Added: The new ToArray method from Java9 and newer into the library. Using a functional interface. (Just a backport)
|
- Fixed: ObjectCopyOnWriteList.of did create a ObjectArrayList instead of the CopyOnWrite variant.
|
||||||
- Changed: Reworked how the Map Builder functions are created. They are now in a SubClass that moves them out of the way. Less Clutter. (This might break things if that was used before)
|
- Removed: BooleanSet and Maps that start with a Boolean classes since they can not be used anyways.
|
||||||
- Added: Map Builder that allows now to Build Maps like Guava ImmutableMaps can be build. Note: This has a slight performance overhead.
|
- 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
|
||||||
- Added: Unmodifiable and Synchronize wrapper functions direclty into Collection Interfaces. This is mostly a quality of life thing.
|
- Breaking Change: Classes that used PrimitiveCollection functions now default to java functions where applicable, this is to increase compat.
|
||||||
- Added: Unmodifiable and Synchronized Wrapper Collections can now be cloned. They clone the underlying map which doesn't break functionality. (Had a usecase for it)
|
- Breaking Change: Some function classes now get closer to javas terms. (Predicate/UnaryOperator etc)
|
||||||
- Added: A boxed putAll array variant.
|
|
||||||
- Fixed: EnumMaps didn't keep track of their size and now got proper care and implementations as needed. There might be more work required but at least the core functionality is now up to date.
|
### Version 0.7.0
|
||||||
- Added: Tests for the new Stream replace functions to ensure no bugs are left.
|
- Added: Over 11 Million Unit Tests to this library to ensure quality.
|
||||||
- Fixed: Custom HashSet reduce function with a default value was checking incorrectly for present keys.
|
- Added: ArrayList size constructor now throws IllegalStateException if the size parameter is negative
|
||||||
- Added: Guava TestSuit
|
- Added: EnumMap specialized forEach implementation.
|
||||||
- Fixed: HashCode and toString method would crash if the Object Key/Value was null
|
- Added: AbstractMap.remove now delegates to its primitive counterpart.
|
||||||
- Added: AbstractTypeCollection now delegates the contains check to type-specific Collections if it detects it.
|
- Added: ConcurrentHashMap now implements ITrimmable
|
||||||
- Fixed: Map.Entry toString wasn't writing values not like it should do.
|
- Refactor: Removed a lot of disabled code from ArraySet.
|
||||||
- Fixed: Set.hashCode now is the sum of the elements instead of a Unique HashCode based on the elements.
|
- Removed: LinkedList.addAll(index, List) now delegates to LinkedList.addAll(index, Collection) due to no special optimization required.
|
||||||
- Fixed: Added missing NonNull Checks.
|
- Fixed: AbstractList.SubList.get/set/swapRemove didn't calculate their List index Properly
|
||||||
- Fixed: Custom/OpenHashMap.containsValue implementation was wrong.
|
- Fixed: AbstractList.SubList chains now properly if you create SubLists within SubLists.
|
||||||
- Fixed: Custom/OpenHashMap.compute/present/absent now works how it is specified in the Java Documentation
|
- Fixed: AbstractList.Iterator.add now respects Immutable/UnmodifiableLists.
|
||||||
- Fixed: Custom/OpenHashMap.merge/BulkMerge now works how it is specified in the Java Documentation
|
- Fixed: AbstractList.Iterator.skip/back now keep track of the last returned value for remove function to work properly.
|
||||||
- Fixed: Custom/Linked/OpenHashMap.keySet.remove was causing a infinite loop.
|
- Fixed: CopyOnWriteArrayList.extract/removeElements(int, int) does now proper range checks and remove elements properly.
|
||||||
- Fixed: Custom/Linked/OpenHashMap.entrySet.contains was not correctly comparing the entry.
|
- Fixed: CopyOnWriteArrayList.SubList now works properly. (Reimplemented entirely)
|
||||||
- Fixed: Custom/OpenHashMap.mapIterator now no longer crashes in certain cases.
|
- Fixed: CopyOnWriteArrayList.Iterator.previous() was returning the wrong values.
|
||||||
- Added: Custom/LinkedOpenHashMap now takes use of the improved Iterator it has for containsValue
|
- Fixed: CopyOnWriteArrayList.Iterator.skip now skips the right amount of elements and stops where it should.
|
||||||
- Fixed: CustomOpenHashMap.keySet.forEach was basically putting out keys even if they were present
|
- Fixed: LinkedList.first/last/dequeue/dequeueLast now throws NoSuchElementException when empty instead of IllegalStateException.
|
||||||
- Fixed: ImmutableMaps issues thanks to the tests. Roughly the same as the rest of the maps
|
- Fixed: LinkedList had an edge case where the entire reverse iterator would break if the wrong element was removed.
|
||||||
- Fixed: RB/AVLTreeMaps issues. Roughly the same as the rest of the maps
|
- Fixed: LinkedList.extractElement now returns the correct values.
|
||||||
- Fixed: SubLists are now properly implemented.
|
- Fixed: AbstractMap.entrySet().remove(Object) now returns true if defaultReturnValue elements were removed.
|
||||||
- Fixed: HashSet Iterator bugs now fixed... That was Painful.
|
- Fixed: ConcurrentHashMap.remove(Object, Object) checks if the type matches before comparing against null Values.
|
||||||
- Added: Tests for Lists and Sets
|
- Fixed: LinkedHashMap.clearAndTrim() was checking the wrong value for determining the full reset or clearing of a Map.
|
||||||
|
- Fixed: HashMap.trim/clearToTrim() was using the wrong value to determin if something should be done.
|
||||||
### Version 0.4.5
|
- Fixed: HashMap now compares empty values (0) against nullKeys when Object Variants of the type are used.
|
||||||
- Added: removeAll/retainAll(Collection c, Consumer r) which receives all the elements that got deleted from the collection
|
- Fixed: ImmutableMap now compares empty values (0) against nullKeys when Object Variants of the type are used.
|
||||||
- Fixed: Supplier get function wasn't referencing original function.
|
- Fixed: ArrayMap.iterator(key) now throws NoSuchElementException when the element wasn't found.
|
||||||
- Added: addIfPresent/Absent to lists
|
- Fixed: Linked/EnumMap array constructor was creating the wrong size values array.
|
||||||
- Added: distinct, limit and peek iterators
|
- Fixed: LinkedEnumMap.getAndMoveToFirst/Last was moving elements even if the element wasn't present.
|
||||||
- Added: Iterable's can now reduce its contents
|
- Fixed: AVL/RBTreeMap.getFirst/LastKey was not throwing a NoSuchElementException if the map was empty.
|
||||||
- Added: Better ForEach support for IterableWrappers so a Iterator chain is not created
|
- Fixed: Map.Builder wasn't throwing a IllegalStateException when creating a negative size builder.
|
||||||
- Added: SwapRemove to Lists which moves the last element into the desired space to be deleted
|
- Fixed: AVL/RBTreeSet.DecendingSet.subSet(from, fromInclusive, to, toInclusive) was creating a corrupt asending subset.
|
||||||
- Added: More Test cases
|
- Fixed: ArraySet throws now a IllegalStateException when trying to create it with a negative size.
|
||||||
|
- Fixed: ArraySet.addMoveToLast(key) was crashing when a key was already present.
|
||||||
### Version 0.4.4
|
- Fixed: Immutable/LinkedHashSet now keep track of their iteration index properly.
|
||||||
- Fixed: ObjectArrayList.of was causing crashes because of a Poor implementation.
|
- Fixed: LinkedHashSet.moveToFirst/Last(key) would crash if the Set was empty.
|
||||||
- Added: Unsorted HashMaps/Sets now throw Concurrent exceptions if they were modified during a rehash.
|
- Fixed: LinkedHashSet.clearAndTrim() was checking the wrong value for determining the full reset or clearing of a Map.
|
||||||
- Added: Array/Collection version of enqueue and enqueueFirst to PriorityQueues.
|
- Fixed: HashSet.trim/clearToTrim() was using the wrong value to determin if something should be done.
|
||||||
- Added: fillBuffer function into PrimitiveLists which allow to optimize JavaNio buffers if needed.
|
|
||||||
|
|
||||||
### Version 0.4.3
|
### Version 0.6.2
|
||||||
- Added: Wrapper now support the Optimized Lambda replacer functions to improve performance.
|
- Added: Array only sorting function return the inputed array. This was done to allow for static final references to use the method in one go without having to make lambda wrappers. Cleaner code.
|
||||||
- Added: FIFO Queue has now a minimum capacity and that is now checked more consistently.
|
- Added: Iterator Wrappers are now a bit more in Compliance with Java Standards.
|
||||||
|
- Added: AsyncBuilders now Support Array Inputs to create cleaner code.
|
||||||
### Version 0.4.2
|
- Changed: LinkedList.addBulk variable definition was triggering a false positive.
|
||||||
- Added: Lists/Sets/Maps/PriorityQueues are now copy-able. with the new copy() function.
|
- Fixed: TreeMap.subMap().entrySet().remove() wouldn't check primitives properly.
|
||||||
Note: subLists/subMaps/subSets or synchronize/unmodifyable wrappers do not support that function.
|
- Fixed: SortedMap.sub/tail/headMap were looping into themselves.
|
||||||
- Fixed: PriorityQueues didn't implement: hashCode/equals/toString
|
- Fixed: AbstractCollection.retainAll didn't push removed values through the consumer.
|
||||||
|
- Fixed: AbstractCollection.toArray wouldn't reset the last entry if the input array was larger then the elements in the collection.
|
||||||
### Version 0.4.1
|
- Fixed: SubList didn't check for ranges properly or didn't use parent list to validate changes.
|
||||||
- Changed: ForEach with input now provides input, value instead of value, input, this improves the usage of method references greatly
|
- Fixed: ArrayList.addElements didn't check input array fully and used the wrong variable to move the elements around.
|
||||||
- Added: addAll with Array-types in collections.
|
- Fixed: LinkedList.addElements(EmptyInput) would crash.
|
||||||
- Added: Java Iterator/Iterable support for Stream replacing methods
|
- Fixed: LinkedList.swapRemove didn't account for if the removed element was the prelast one.
|
||||||
- Added: Suppliers.
|
- Fixed: LinkedList.removeElements would break the implementation if the list was almost empty and the middle element was removed.
|
||||||
- Added: SupplyIfAbsent. It is ComputeIfAbsent but using suppliers
|
- Fixed: LinkedHashSet.addAndMoveToFirst wouldn't move elements to the first place.
|
||||||
- Added: Count feature into Iterable
|
- Fixed: ArrayList/LinkedList extractElements crashing when 0 or less elements are desired.
|
||||||
- Fixed: A couple bugs with the new StreamReplacing functions in LinkedCollections Iterating to Infinity
|
- Fixed: TreeMap pollFirst/LastKey should return the defaultMin/max value instead of a Empty value.
|
||||||
|
- Fixed: TreeMap keySet implementation was missing the class type implementations to pass keySet tests.
|
||||||
### Version 0.4.0
|
- Fixed: TreeMap.SubMap Iterator (primitive Keys) was crashing because a Null was set on to a primitive.
|
||||||
- Changed: Iterable specific helper functions were moved out of Iterators and moved into Iterables
|
|
||||||
- Added: New Stream replacing functions: findFirst, matchesAny/All/None
|
|
||||||
- Fixed: Compute/ComputeIfAbsent/ComputeIfPresent/Merge/BulkMerge in maps now behave like they should.
|
### Version 0.6.1
|
||||||
- Added: Implementations for New Stream replacing functions.
|
- Fixed: FIFO queue crashing when the last index is before the first index when peek is called.
|
||||||
- Changed: Removed a lot of duplicated forEach implementations
|
- Fixed: FIFO queue only clears the array if it was in use.
|
||||||
- Added: Flat/Mapping functions (to object) are now accessible to primitive maps.
|
- Added: Sorted Method for the stream replacing functions.
|
||||||
- Added: Filter function to Iterators/Iterables (Iterable implements it by default)
|
|
||||||
- Changed: Cleanup of some variables/mappers
|
### Version 0.6.0
|
||||||
- Added/Fixed: AVL/RBTreeMap got reworked and SubMaps work more properly now. Also forEach support got improved a lot
|
- Added: addOrGet for sets.
|
||||||
- Added/Fixed: TreeSubSets (RB/AVL) got their functional implementations improved too.
|
- Added: Async API which allows to easily execute Iterables/Collections offthread without the complexity.
|
||||||
- Added: Pairs are now a thing. In Mutable/Immutable Form
|
- Added: CopyOnWriteArrayList and tests for it
|
||||||
|
- Added: Support up to Java17.
|
||||||
### Version 0.3.6
|
- Added: Build System now adds module-info if the Running JVM is 9 or higher
|
||||||
- Fixed: addAll non Type Specific Lists was causing crashes.
|
- Added: ArrayList.of(Class, size) that allows you to allocate a size right at the creation of the List without having to create a wrapper array.
|
||||||
- Fixed/Changed: clearAndTrim's implementation was all over the place. In some cases causing crash scenarios.
|
- Added: A ConcurrentHashMap implementation.
|
||||||
- Fixed: Wrappers didn't implement toString/equals/hashCode
|
- Fixed: containsValue in the HashMap wouldn't check the nullKey
|
||||||
- Added: Tests for addAll Bug
|
- Removed: Deprecated functions from SortedMaps/Sets
|
||||||
- Changed: Cleaned up CodeStyle as bugs were fixed.
|
|
||||||
|
### Version 0.5.3
|
||||||
### Version 0.3.5
|
- Added: OrderedMap/Set
|
||||||
- Fixed: Simple Code Generator dependency was declared wrong. Its only needed for runtime. Not for Compilation.
|
- Added: Deprecation to Functions that are specific to Ordered interfaces in the SortedMap/Set
|
||||||
- Fixed: ObjectLists Crashed when a null was provided as a Comparator. (Unless the List was Initialized with the ClassType)
|
- Added: subFrom to Maps which is the counterpart of the addTo method
|
||||||
- Fixed: LinkedLists didn't implement add(Object)
|
- Added: pourAsList and pourAsSet (booleans excluded for sets) to Iterable
|
||||||
- Fixed: Object Collections did have the JavaCollections deprecated as the Constructor. This should only be deprecated for Primitives
|
- Fixed: ArrayList.grow had a small bug where it would trigger to early causing performance problems with exact sized collections.
|
||||||
- Added: Tests with 5k Random names for Object sorting.
|
- Fixed: FIFOQueue size constructor had a small bug where it would trigger a array enlargement when all elements were inserted.
|
||||||
- Changed: Object Arrays no longer require a Comparable[] it just assumes now that the elements in the Array are Comparable
|
|
||||||
- Fixed: Dependency to SimpleCodeGenerator should be no longer a thing. Because the resulting library doesn't need it only the builder does.
|
### Version 0.5.2
|
||||||
|
- Fixed: Bugs with Queues starting with the wrong size
|
||||||
### Version 0.3.4
|
- Fixed: ArrayGrowth for Queues was +1 instead of +50%
|
||||||
- Fixed: ArrayLists didn't resize properly if they were empty.
|
- Added: Benchmarks with java and FastUtil
|
||||||
|
|
||||||
|
### Version 0.5.1
|
||||||
### Version 0.3.3
|
- Fixed: Reworked the NavigableSet/Map implementations of RBTree/AVLTree/Array Sets/Maps so they are now deemed stable.
|
||||||
- Added: Flat/Mapping function for Iterables/Iterators to help avoid streams for cleaner looking code
|
- Added: Another 150k Unit tests.
|
||||||
- Fixed: AVLTrees pollFirst/Last is now keeping orders and is fixed
|
- Added: List and Set Unit tests for Integer (or Primitives in this case) to ensure basic stability there. (Now covering all sets and lists)
|
||||||
- Fixed: AbstractCollection bulk adding methods now link to the specialized implementations.
|
- Fixed: Bugs with null values for primitive collections.
|
||||||
- Fixed: A bug with getElements in ArrayList.
|
- Removed: ArraySet/Map subSet/subMap implementation was removed.
|
||||||
- Fixed: PriorityQueue remove/toArray function were renamed so they fit better with other interfaces. (remove => removeFirst and toArray uses a different genericType)
|
|
||||||
- Added: LinkedList which is a List/PriorityDequeue/Stack which allows for more optimized use-cases and reduced boxing/unboxing.
|
### Version 0.5.0
|
||||||
- Added: Tests for LinkedList
|
- Added: 2 Helper functions to find out how many bits are required to store a Number.
|
||||||
|
- Added: pour function directly into Iterable which allows to collect all elements in the Iterable directly.
|
||||||
### Version 0.3.2
|
- Added: The new ToArray method from Java9 and newer into the library. Using a functional interface. (Just a backport)
|
||||||
- Fixed: Map.put wasn't referring to primitive variants.
|
- Changed: Reworked how the Map Builder functions are created. They are now in a SubClass that moves them out of the way. Less Clutter. (This might break things if that was used before)
|
||||||
- Added: ImmutableList.
|
- Added: Map Builder that allows now to Build Maps like Guava ImmutableMaps can be build. Note: This has a slight performance overhead.
|
||||||
- Added: Iterator pour function into a List or Array
|
- Added: Unmodifiable and Synchronize wrapper functions direclty into Collection Interfaces. This is mostly a quality of life thing.
|
||||||
- Changed: Arrays Wrap is now accessible to Objects and now is ? extends TYPE instead of TYPE.
|
- Added: Unmodifiable and Synchronized Wrapper Collections can now be cloned. They clone the underlying map which doesn't break functionality. (Had a usecase for it)
|
||||||
- Added: OpenHashSets now implement foreach and have less overhead.
|
- Added: A boxed putAll array variant.
|
||||||
- Added: ImmutableOpenHashSet that is not editable (is linked by default for fast iteration)
|
- Fixed: EnumMaps didn't keep track of their size and now got proper care and implementations as needed. There might be more work required but at least the core functionality is now up to date.
|
||||||
- Added: CustomOpenHashSets now implement foreach and have less overhead.
|
- Added: Tests for the new Stream replace functions to ensure no bugs are left.
|
||||||
- Added: ImmutableOpenHashMap that is not editable (is linked by default for fast iteration)
|
- Fixed: Custom HashSet reduce function with a default value was checking incorrectly for present keys.
|
||||||
- Added: Maps can now be created through the interface.
|
- Added: Guava TestSuit
|
||||||
- Fixed: Lists.addElements(T...elements) was adding elements at the beginning of a list instead of the end.
|
- Fixed: HashCode and toString method would crash if the Object Key/Value was null
|
||||||
- Fixed: Bugs with the AVLTreeSet. And marked bugs with AVLTreeX that are still present.
|
- Added: AbstractTypeCollection now delegates the contains check to type-specific Collections if it detects it.
|
||||||
|
- Fixed: Map.Entry toString wasn't writing values not like it should do.
|
||||||
### Version 0.3.1
|
- Fixed: Set.hashCode now is the sum of the elements instead of a Unique HashCode based on the elements.
|
||||||
- Fixed: containsKey & containsValue in HashMaps were deprecated for Object Variants.
|
- Fixed: Added missing NonNull Checks.
|
||||||
- Fixed: HashMap wasn't deleting Keys & Values references when removing a Object
|
- Fixed: Custom/OpenHashMap.containsValue implementation was wrong.
|
||||||
- Fixed: AVLTreeMap didn't balance properly.
|
- Fixed: Custom/OpenHashMap.compute/present/absent now works how it is specified in the Java Documentation
|
||||||
- Changed: EnumMap no longer tries to access SharedSecrets since its gone in java11
|
- Fixed: Custom/OpenHashMap.merge/BulkMerge now works how it is specified in the Java Documentation
|
||||||
- Added: HashMaps now implement ITrimmable
|
- Fixed: Custom/Linked/OpenHashMap.keySet.remove was causing a infinite loop.
|
||||||
- Added: AVLTreeSet didn't balance properly
|
- Fixed: Custom/Linked/OpenHashMap.entrySet.contains was not correctly comparing the entry.
|
||||||
- Fixed: HashMaps & LinkedMaps weren't clearing references properly.
|
- Fixed: Custom/OpenHashMap.mapIterator now no longer crashes in certain cases.
|
||||||
|
- Added: Custom/LinkedOpenHashMap now takes use of the improved Iterator it has for containsValue
|
||||||
### Version 0.3.0 (Breaking 0.2.0)
|
- Fixed: CustomOpenHashMap.keySet.forEach was basically putting out keys even if they were present
|
||||||
- Added: Stack.isEmpty was missing
|
- Fixed: ImmutableMaps issues thanks to the tests. Roughly the same as the rest of the maps
|
||||||
- Changed: remove/removeLast/enqueue/enqueueFirst no longer use Type Suffixes
|
- Fixed: RB/AVLTreeMaps issues. Roughly the same as the rest of the maps
|
||||||
- Removed: Suffixes for unmodifiable & synchronize functions.
|
- Fixed: SubLists are now properly implemented.
|
||||||
- Changed: Primitive Stacks no longer depend on the base Stack class. Because seriously not needed.
|
- Fixed: HashSet Iterator bugs now fixed... That was Painful.
|
||||||
- Changed: PriorityQueues no longer extends Object Variant.
|
- Added: Tests for Lists and Sets
|
||||||
- Changed: Maps.get function is no longer using Suffixes unless its absolutely necessary.
|
|
||||||
- Changed: Maps.remove function is no longer using Suffixes unless its absolutely necessary.
|
### Version 0.4.5
|
||||||
- Changed: ObjectList methods are no longer marked Deprecated even so it was for primitive ones.
|
- Added: removeAll/retainAll(Collection c, Consumer r) which receives all the elements that got deleted from the collection
|
||||||
- Added: Shuffle & Reverse Methods.
|
- Fixed: Supplier get function wasn't referencing original function.
|
||||||
- Added: Concat Iterators.
|
- Added: addIfPresent/Absent to lists
|
||||||
|
- Added: distinct, limit and peek iterators
|
||||||
|
- Added: Iterable's can now reduce its contents
|
||||||
|
- Added: Better ForEach support for IterableWrappers so a Iterator chain is not created
|
||||||
|
- Added: SwapRemove to Lists which moves the last element into the desired space to be deleted
|
||||||
|
- Added: More Test cases
|
||||||
|
|
||||||
|
### Version 0.4.4
|
||||||
|
- Fixed: ObjectArrayList.of was causing crashes because of a Poor implementation.
|
||||||
|
- Added: Unsorted HashMaps/Sets now throw Concurrent exceptions if they were modified during a rehash.
|
||||||
|
- Added: Array/Collection version of enqueue and enqueueFirst to PriorityQueues.
|
||||||
|
- Added: fillBuffer function into PrimitiveLists which allow to optimize JavaNio buffers if needed.
|
||||||
|
|
||||||
|
### Version 0.4.3
|
||||||
|
- Added: Wrapper now support the Optimized Lambda replacer functions to improve performance.
|
||||||
|
- Added: FIFO Queue has now a minimum capacity and that is now checked more consistently.
|
||||||
|
|
||||||
|
### Version 0.4.2
|
||||||
|
- Added: Lists/Sets/Maps/PriorityQueues are now copy-able. with the new copy() function.
|
||||||
|
Note: subLists/subMaps/subSets or synchronize/unmodifyable wrappers do not support that function.
|
||||||
|
- Fixed: PriorityQueues didn't implement: hashCode/equals/toString
|
||||||
|
|
||||||
|
### Version 0.4.1
|
||||||
|
- Changed: ForEach with input now provides input, value instead of value, input, this improves the usage of method references greatly
|
||||||
|
- Added: addAll with Array-types in collections.
|
||||||
|
- Added: Java Iterator/Iterable support for Stream replacing methods
|
||||||
|
- Added: Suppliers.
|
||||||
|
- Added: SupplyIfAbsent. It is ComputeIfAbsent but using suppliers
|
||||||
|
- Added: Count feature into Iterable
|
||||||
|
- Fixed: A couple bugs with the new StreamReplacing functions in LinkedCollections Iterating to Infinity
|
||||||
|
|
||||||
|
### Version 0.4.0
|
||||||
|
- Changed: Iterable specific helper functions were moved out of Iterators and moved into Iterables
|
||||||
|
- Added: New Stream replacing functions: findFirst, matchesAny/All/None
|
||||||
|
- Fixed: Compute/ComputeIfAbsent/ComputeIfPresent/Merge/BulkMerge in maps now behave like they should.
|
||||||
|
- Added: Implementations for New Stream replacing functions.
|
||||||
|
- Changed: Removed a lot of duplicated forEach implementations
|
||||||
|
- Added: Flat/Mapping functions (to object) are now accessible to primitive maps.
|
||||||
|
- Added: Filter function to Iterators/Iterables (Iterable implements it by default)
|
||||||
|
- Changed: Cleanup of some variables/mappers
|
||||||
|
- Added/Fixed: AVL/RBTreeMap got reworked and SubMaps work more properly now. Also forEach support got improved a lot
|
||||||
|
- Added/Fixed: TreeSubSets (RB/AVL) got their functional implementations improved too.
|
||||||
|
- Added: Pairs are now a thing. In Mutable/Immutable Form
|
||||||
|
|
||||||
|
### Version 0.3.6
|
||||||
|
- Fixed: addAll non Type Specific Lists was causing crashes.
|
||||||
|
- Fixed/Changed: clearAndTrim's implementation was all over the place. In some cases causing crash scenarios.
|
||||||
|
- Fixed: Wrappers didn't implement toString/equals/hashCode
|
||||||
|
- Added: Tests for addAll Bug
|
||||||
|
- Changed: Cleaned up CodeStyle as bugs were fixed.
|
||||||
|
|
||||||
|
### Version 0.3.5
|
||||||
|
- Fixed: Simple Code Generator dependency was declared wrong. Its only needed for runtime. Not for Compilation.
|
||||||
|
- Fixed: ObjectLists Crashed when a null was provided as a Comparator. (Unless the List was Initialized with the ClassType)
|
||||||
|
- Fixed: LinkedLists didn't implement add(Object)
|
||||||
|
- Fixed: Object Collections did have the JavaCollections deprecated as the Constructor. This should only be deprecated for Primitives
|
||||||
|
- Added: Tests with 5k Random names for Object sorting.
|
||||||
|
- Changed: Object Arrays no longer require a Comparable[] it just assumes now that the elements in the Array are Comparable
|
||||||
|
- Fixed: Dependency to SimpleCodeGenerator should be no longer a thing. Because the resulting library doesn't need it only the builder does.
|
||||||
|
|
||||||
|
### Version 0.3.4
|
||||||
|
- Fixed: ArrayLists didn't resize properly if they were empty.
|
||||||
|
|
||||||
|
|
||||||
|
### Version 0.3.3
|
||||||
|
- Added: Flat/Mapping function for Iterables/Iterators to help avoid streams for cleaner looking code
|
||||||
|
- Fixed: AVLTrees pollFirst/Last is now keeping orders and is fixed
|
||||||
|
- Fixed: AbstractCollection bulk adding methods now link to the specialized implementations.
|
||||||
|
- Fixed: A bug with getElements in ArrayList.
|
||||||
|
- Fixed: PriorityQueue remove/toArray function were renamed so they fit better with other interfaces. (remove => removeFirst and toArray uses a different genericType)
|
||||||
|
- Added: LinkedList which is a List/PriorityDequeue/Stack which allows for more optimized use-cases and reduced boxing/unboxing.
|
||||||
|
- Added: Tests for LinkedList
|
||||||
|
|
||||||
|
### Version 0.3.2
|
||||||
|
- Fixed: Map.put wasn't referring to primitive variants.
|
||||||
|
- Added: ImmutableList.
|
||||||
|
- Added: Iterator pour function into a List or Array
|
||||||
|
- Changed: Arrays Wrap is now accessible to Objects and now is ? extends TYPE instead of TYPE.
|
||||||
|
- Added: OpenHashSets now implement foreach and have less overhead.
|
||||||
|
- Added: ImmutableOpenHashSet that is not editable (is linked by default for fast iteration)
|
||||||
|
- Added: CustomOpenHashSets now implement foreach and have less overhead.
|
||||||
|
- Added: ImmutableOpenHashMap that is not editable (is linked by default for fast iteration)
|
||||||
|
- Added: Maps can now be created through the interface.
|
||||||
|
- Fixed: Lists.addElements(T...elements) was adding elements at the beginning of a list instead of the end.
|
||||||
|
- Fixed: Bugs with the AVLTreeSet. And marked bugs with AVLTreeX that are still present.
|
||||||
|
|
||||||
|
### Version 0.3.1
|
||||||
|
- Fixed: containsKey & containsValue in HashMaps were deprecated for Object Variants.
|
||||||
|
- Fixed: HashMap wasn't deleting Keys & Values references when removing a Object
|
||||||
|
- Fixed: AVLTreeMap didn't balance properly.
|
||||||
|
- Changed: EnumMap no longer tries to access SharedSecrets since its gone in java11
|
||||||
|
- Added: HashMaps now implement ITrimmable
|
||||||
|
- Added: AVLTreeSet didn't balance properly
|
||||||
|
- Fixed: HashMaps & LinkedMaps weren't clearing references properly.
|
||||||
|
|
||||||
|
### Version 0.3.0 (Breaking 0.2.0)
|
||||||
|
- Added: Stack.isEmpty was missing
|
||||||
|
- Changed: remove/removeLast/enqueue/enqueueFirst no longer use Type Suffixes
|
||||||
|
- Removed: Suffixes for unmodifiable & synchronize functions.
|
||||||
|
- Changed: Primitive Stacks no longer depend on the base Stack class. Because seriously not needed.
|
||||||
|
- Changed: PriorityQueues no longer extends Object Variant.
|
||||||
|
- Changed: Maps.get function is no longer using Suffixes unless its absolutely necessary.
|
||||||
|
- Changed: Maps.remove function is no longer using Suffixes unless its absolutely necessary.
|
||||||
|
- Changed: ObjectList methods are no longer marked Deprecated even so it was for primitive ones.
|
||||||
|
- Added: Shuffle & Reverse Methods.
|
||||||
|
- Added: Concat Iterators.
|
||||||
- Added: PriorityQueues
|
- Added: PriorityQueues
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
### Extra Features
|
||||||
|
|
||||||
|
Primitive Collections comes with a few extra features that are disabled by default.
|
||||||
|
These will be enabled as soon they become relevant or never at all.
|
||||||
|
|
||||||
|
But some of these can be already unlocked when the target version changes.
|
||||||
|
|
||||||
|
If you compile the library for yourself you will automatically gain access to said features.
|
||||||
|
|
||||||
|
### Java17 Exclusive Features
|
||||||
|
Java17 has some new features that can sadly not really be back-ported but the library still supports them if it is compiled with java17
|
||||||
|
|
||||||
|
- RandomGenerator: Java17 has added [RandomGenerator.class](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/random/RandomGenerator.html).
|
||||||
|
This allows to use custom random implementations without having to re-implement them yourselves.
|
||||||
|
|
||||||
|
|
||||||
|
### ModuleSettings
|
||||||
|
Primitive Collections is a huge library.
|
||||||
|
But maybe you only use like 5-10 different classes.
|
||||||
|
Normally you would use tools like "Proguard" to get rid of classes that you don't use.
|
||||||
|
But since a lot of classes have dependencies on each other this would only do so much.
|
||||||
|
|
||||||
|
This is where the [ModuleSettings](ModuleSettings.json) come into play.
|
||||||
|
It allows you to turn of implementations as you wish and adjusts the code that everything still works.
|
||||||
|
|
||||||
|
There is 3 layers of control inside of the ModuleSettings.
|
||||||
|
- Modules directly at the top that turn off everything.
|
||||||
|
- Type Specific configurations, where you can for example turn of everything thats "Long" based.
|
||||||
|
- And then there is each type specific module settings.
|
||||||
|
|
||||||
|
Allowing for greater control without having to edit hundreds of lines of code.
|
||||||
|
On top of that:
|
||||||
|
Any Setting that isn't "Present" is counted as "Enabled".
|
||||||
|
So if you want to disable just 1 thing you can keep that 1 thing and delete the rest of the Setting.
|
||||||
|
It will still work as the same.
|
||||||
|
The default settings just come with everything so you can see what is controllable.
|
||||||
|
|
||||||
|
How to compile the Code with the ModuleSettings enabled:
|
||||||
|
```
|
||||||
|
/gradlew.bat generateLimitSource build -x test
|
||||||
|
```
|
||||||
+2624
File diff suppressed because it is too large
Load Diff
@@ -1,10 +1,25 @@
|
|||||||

|

|
||||||
|
[](https://jitpack.io/#Speiger/Primitive-Collections)
|
||||||
|
[](https://opensource.org/licenses/Apache-2.0)
|
||||||
|

|
||||||
|

|
||||||
|

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

|
||||||
# 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.
|
||||||
|
|
||||||
This is a Simple Primitive Collections Library i started as a hobby Project.
|
## Benchmarks
|
||||||
It is based on Java's Collection Library and FastUtil.
|
Benchmarks can be found here: [[Charts]](https://github.com/Speiger/Primitive-Collections-Benchmarks/blob/master/BENCHMARKS-CHARTS.md), [[Tables]](https://github.com/Speiger/Primitive-Collections-Benchmarks/blob/master/BENCHMARKS.md)
|
||||||
But its focus is a different one.
|
|
||||||
|
## Special Features
|
||||||
|
[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:
|
## Main Features:
|
||||||
- ArrayLists / LinkedLists / CopyOnWriteLists
|
- ArrayLists / LinkedLists / CopyOnWriteLists
|
||||||
@@ -15,106 +30,34 @@ But its focus is a different one.
|
|||||||
- ConcurrentHashMaps
|
- ConcurrentHashMaps
|
||||||
- Priority Queues
|
- Priority Queues
|
||||||
- Streams & Functional Queries
|
- Streams & Functional Queries
|
||||||
- SplitIterators
|
- Split/Iterators
|
||||||
- Iterators
|
|
||||||
- Pairs
|
- Pairs
|
||||||
- Unary/Functions
|
- Unary/Functions
|
||||||
- Suppliers
|
- Suppliers
|
||||||
- Bi/Consumers
|
- Bi/Consumers
|
||||||
- AsyncBuilders
|
- AsyncBuilders
|
||||||
|
|
||||||
## Current Level of Stability
|
|
||||||
Since this is a relatively new Library, stability was not perfect and some areas are not perfect yet.
|
|
||||||
Thanks to [ben-manes](https://github.com/ben-manes) we now have Roughly 160k unit test covering Maps/Sets/Lists.
|
|
||||||
These tests cover Javas Collection API completely and ensuring a Stable implementation.
|
|
||||||
These freshly added tests allowed me to squash thousands of issues according to Googles Test Library (Guava-Tests).
|
|
||||||
These will be expanded on as time goes on.
|
|
||||||
|
|
||||||
### Benchmarks
|
|
||||||
Benchmarks can be found here: [Click Me](https://github.com/Speiger/Primitive-Collections-Benchmarks/tree/master)
|
|
||||||
|
|
||||||
## Specialized Functions
|
|
||||||
New Specialized functions that were added to increase performance or reduce allocations or Quality Of life.
|
|
||||||
To highlight things that may be wanted.
|
|
||||||
- Iterable:
|
|
||||||
- map/flatMap/arrayFlatMap: A Light weight version of Stream.map().
|
|
||||||
- findFirst: Allows to find the first element of a Predicated Iterable.
|
|
||||||
- filter: Allows to filter unwanted elements for wrapped Iterable
|
|
||||||
- matchAny/matchNone/matchAll: Allows to find elements in a collection.
|
|
||||||
- count: counts all valid elements in a collection.
|
|
||||||
- forEach: Allows to input a second element into a forEach move allowing for more flexibility for Method References
|
|
||||||
- reduce/limit/peek/distinct: Light Versions of the Stream variant, to reduce Stream usage.
|
|
||||||
- pour: a function that allows to collect all elements within the Collection
|
|
||||||
- Collection:
|
|
||||||
- addAll: addAll array version
|
|
||||||
- containsAny: Allows to test if another collection contains an of the elements of the tested collection.
|
|
||||||
- primitiveStream: Provides access to the closest Java Stream Type.
|
|
||||||
- copy: shallowCopies the collection, used instead of clone because this is better to use.
|
|
||||||
(subCollections not supported for obvious reasons)
|
|
||||||
- toArray: the ToArray function from Java9 and newer that uses a Functional interface and can use a method reference
|
|
||||||
- List:
|
|
||||||
- add/get/removeElements (From FastUtil): Allows to add/get/remove an Array into/from a list. Just with less overhead
|
|
||||||
- extractElements: Allows to remove a Range of elements from the List and get what was removed.
|
|
||||||
- Unstable Sort(From FastUtil): Uses a faster but not stable sort (Quick-Sort as example) to sort the list.
|
|
||||||
- addIfAbsent/Present: adds a element only if absent/present in the list
|
|
||||||
- swapRemove: deletes a desired element and inserts the last element in its place instead of leftshifting elements.
|
|
||||||
- SortedSet:
|
|
||||||
- addAndMoveToFirst/Last (From FastUtil but moved to Interface): Allows to add a element to the first/last position of a sorted set.
|
|
||||||
- moveToFirst/Last: Moves the desired element at the first/last position of the SortedSet.
|
|
||||||
- pollFirst/Last: Allows to poll the first/last element of the set.
|
|
||||||
- Map:
|
|
||||||
- putAll: putAll but in Array form.
|
|
||||||
- putAllIfAbsent: Puts only the elements that are absent.
|
|
||||||
- addTo (Only Primitives Values) (From FastUtil but moved to Interface): allows to add to the value of a given key. If not present it will be added. (Accumulator)
|
|
||||||
- subFrom (Only Primitive Values): allows to subtract from the value of a given key. If value reached getDefaultReturnValue() element will be removed.
|
|
||||||
- addToAll: Same as addTo but bulkVersion.
|
|
||||||
- removeOrDefault: removes a Element and if not present returns the default value instead of the present value.
|
|
||||||
- mergeAll: BulkVersion of Merge function.
|
|
||||||
- supplyIfAbsent: A Supplier based computeIfAbsent
|
|
||||||
- Sorted Map:
|
|
||||||
- addAndMoveToFirst/Last (From FastUtil but moved to Interface): Allows to add a element to the first/last position of a sorted Map.
|
|
||||||
- moveToFirst/Last: Moves the desired element at the first/last position of the Map.
|
|
||||||
- getAndMoveToFirst/Last: gets the element and moves it to the first/last position. Replicating a Optional LinkedHashMap feature.
|
|
||||||
- pollFirst/LastKey: Allows to poll the first/last element.
|
|
||||||
- first/LastValue: Allows to get the first/last value from the Map.
|
|
||||||
|
|
||||||
|
|
||||||
# Notes about Versions
|
# Notes about Versions
|
||||||
Any 0.x.0 version (Minor) can be reason for massive changes including API.
|
Any 0.x.0 version (Minor) can be reason for massive changes including API.
|
||||||
To ensure that problems can be dealt with even if it is breaking the current API.
|
To ensure that problems can be dealt with even if it is breaking the current API.
|
||||||
Any breaking changes will be Documented (once 1.0 is released)
|
|
||||||
|
|
||||||
Also to save space every 0.0.x (Patch) that is 2 Minor Versions behind will be removed.
|
|
||||||
So if 0.5.0 is released every 0.3.x patch will be deleted, except for the last patch for that minor version.
|
|
||||||
|
|
||||||
# How to install
|
# How to install
|
||||||
Using Gradle:
|
Using Jitpack Gradle
|
||||||
```gradle
|
```gradle
|
||||||
repositories {
|
repositories {
|
||||||
maven {
|
maven {
|
||||||
url = "https://maven.speiger.com/repository/main"
|
url = "https://jitpack.io"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
compile 'de.speiger:Primitive-Collections:0.6.0'
|
implementation 'com.github.Speiger:Primitive-Collections:0.9.0'
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
Direct:
|
|
||||||
|
|
||||||
| Version | Jar | Sources | Java Doc |
|
# SourceCode
|
||||||
|--------- |------------------------------------------------------------------------------------------------------------------------------ |-------------------------------------------------------------------------------------------------------------------------------------- |-------------------------------------------------------------------------------------------------------------------------------------- |
|
The generated Sourcecode can be automatically build,
|
||||||
| 0.6.0 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.6.0/Primitive-Collections-0.6.0.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.6.0/Primitive-Collections-0.6.0-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.6.0/Primitive-Collections-0.6.0-javadoc.jar) |
|
but if you want to just browse around in it.
|
||||||
| 0.5.3 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.5.3/Primitive-Collections-0.5.3.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.5.3/Primitive-Collections-0.5.3-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.5.3/Primitive-Collections-0.5.3-javadoc.jar) |
|
Check out the [Debug Branch](https://github.com/Speiger/Primitive-Collections/tree/debug/src/main/java/speiger/src/collections), which has the entire up to date code.
|
||||||
| 0.5.2 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.5.2/Primitive-Collections-0.5.2.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.5.2/Primitive-Collections-0.5.2-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.5.2/Primitive-Collections-0.5.2-javadoc.jar) |
|
|
||||||
| 0.5.1 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.5.1/Primitive-Collections-0.5.1.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.5.1/Primitive-Collections-0.5.1-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.5.1/Primitive-Collections-0.5.1-javadoc.jar) |
|
|
||||||
| 0.5.0 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.5.0/Primitive-Collections-0.5.0.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.5.0/Primitive-Collections-0.5.0-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.5.0/Primitive-Collections-0.5.0-javadoc.jar) |
|
|
||||||
| 0.4.5 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.5/Primitive-Collections-0.4.5.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.5/Primitive-Collections-0.4.5-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.5/Primitive-Collections-0.4.5-javadoc.jar) |
|
|
||||||
| 0.4.4 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.4/Primitive-Collections-0.4.4.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.4/Primitive-Collections-0.4.4-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.4/Primitive-Collections-0.4.4-javadoc.jar) |
|
|
||||||
| 0.4.3 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.3/Primitive-Collections-0.4.3.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.3/Primitive-Collections-0.4.3-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.3/Primitive-Collections-0.4.3-javadoc.jar) |
|
|
||||||
| 0.4.2 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.2/Primitive-Collections-0.4.2.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.2/Primitive-Collections-0.4.2-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.2/Primitive-Collections-0.4.2-javadoc.jar) |
|
|
||||||
| 0.4.1 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.1/Primitive-Collections-0.4.1.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.1/Primitive-Collections-0.4.1-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.1/Primitive-Collections-0.4.1-javadoc.jar) |
|
|
||||||
| 0.4.0 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.0/Primitive-Collections-0.4.0.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.0/Primitive-Collections-0.4.0-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.0/Primitive-Collections-0.4.0-javadoc.jar) |
|
|
||||||
| 0.3.6 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.3.6/Primitive-Collections-0.3.6.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.3.6/Primitive-Collections-0.3.6-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.3.6/Primitive-Collections-0.3.6-javadoc.jar) |
|
|
||||||
|
|
||||||
# Contributing
|
# Contributing
|
||||||
If you want to contribute.
|
If you want to contribute.
|
||||||
@@ -132,11 +75,11 @@ Please if you want to contribute follow the [Rule-Sheet](RuleSheet.md). It keeps
|
|||||||
# How to Build
|
# How to Build
|
||||||
|
|
||||||
The SourceCode can be generated via:
|
The SourceCode can be generated via:
|
||||||
|
```
|
||||||
/gradlew.bat generateSource
|
/gradlew.bat generateSource
|
||||||
|
```
|
||||||
|
|
||||||
to build the jar:
|
to generate SourceCode and build the jar:
|
||||||
|
```
|
||||||
/gradlew.bat build
|
/gradlew.bat build
|
||||||
do not combine the commands because they can not be executed at the same time.
|
```
|
||||||
|
|
||||||
## Current Down Sides (Random order)
|
|
||||||
- Documentation is only present at the lowest level for most cases and needs a typo fixing.
|
|
||||||
|
|||||||
+181
-8
@@ -1,5 +1,6 @@
|
|||||||
plugins {
|
plugins {
|
||||||
id 'java-library'
|
id 'java-library'
|
||||||
|
id "jacoco"
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.withType(JavaCompile) {
|
tasks.withType(JavaCompile) {
|
||||||
@@ -18,7 +19,7 @@ repositories {
|
|||||||
}
|
}
|
||||||
|
|
||||||
archivesBaseName = 'Primitive Collections'
|
archivesBaseName = 'Primitive Collections'
|
||||||
version = '0.6.0';
|
version = '0.9.0';
|
||||||
|
|
||||||
sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = JavaVersion.current();
|
sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = JavaVersion.current();
|
||||||
|
|
||||||
@@ -44,9 +45,11 @@ configurations {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
builderImplementation 'de.speiger:Simple-Code-Generator:1.0.7'
|
builderImplementation 'com.google.code.gson:gson:2.10'
|
||||||
|
builderImplementation 'de.speiger:Simple-Code-Generator:1.3.0'
|
||||||
testImplementation 'junit:junit:4.12'
|
testImplementation 'junit:junit:4.12'
|
||||||
testImplementation 'com.google.guava:guava-testlib:31.0.1-jre'
|
testImplementation 'com.google.guava:guava-testlib:33.6.0-jre'
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
task generateSource(type: JavaExec) {
|
task generateSource(type: JavaExec) {
|
||||||
@@ -61,7 +64,7 @@ task generateGithubSource(type: JavaExec) {
|
|||||||
description = 'Builds the sourcecode for Github Actions'
|
description = 'Builds the sourcecode for Github Actions'
|
||||||
classpath = sourceSets.builder.runtimeClasspath
|
classpath = sourceSets.builder.runtimeClasspath
|
||||||
main = 'speiger.src.builder.PrimitiveCollectionsBuilder'
|
main = 'speiger.src.builder.PrimitiveCollectionsBuilder'
|
||||||
args = ['false', 'true']
|
args = ['silent']
|
||||||
}
|
}
|
||||||
|
|
||||||
task forceGenerateSource(type: JavaExec) {
|
task forceGenerateSource(type: JavaExec) {
|
||||||
@@ -69,19 +72,45 @@ task forceGenerateSource(type: JavaExec) {
|
|||||||
description = 'Builds the sourcecode forceful'
|
description = 'Builds the sourcecode forceful'
|
||||||
classpath = sourceSets.builder.runtimeClasspath
|
classpath = sourceSets.builder.runtimeClasspath
|
||||||
main = 'speiger.src.builder.PrimitiveCollectionsBuilder'
|
main = 'speiger.src.builder.PrimitiveCollectionsBuilder'
|
||||||
args = ['true']
|
args = ['force']
|
||||||
|
}
|
||||||
|
|
||||||
|
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 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']
|
||||||
}
|
}
|
||||||
|
|
||||||
task javadocJar(type: Jar) {
|
task javadocJar(type: Jar) {
|
||||||
from javadoc
|
from javadoc
|
||||||
classifier = 'javadoc'
|
archiveClassifier = 'javadoc'
|
||||||
}
|
}
|
||||||
|
|
||||||
task srcJar(type: Jar) {
|
task srcJar(type: Jar) {
|
||||||
from sourceSets.main.allSource
|
from sourceSets.main.allSource
|
||||||
classifier = 'sources'
|
archiveClassifier = 'sources'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
compileJava.dependsOn generateGithubSource
|
||||||
|
|
||||||
javadoc.failOnError = false
|
javadoc.failOnError = false
|
||||||
javadoc.options.memberLevel = JavadocMemberLevel.PUBLIC
|
javadoc.options.memberLevel = JavadocMemberLevel.PUBLIC
|
||||||
javadoc.options.quiet()
|
javadoc.options.quiet()
|
||||||
@@ -91,8 +120,152 @@ artifacts {
|
|||||||
archives srcJar
|
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 {
|
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 {
|
publishing {
|
||||||
|
|||||||
+402
@@ -0,0 +1,402 @@
|
|||||||
|
## Quality Of Life Features
|
||||||
|
New Specialized functions/classes that were added to increase performance and/or reduce allocations and/or for Quality of life.
|
||||||
|
|
||||||
|
|
||||||
|
# Functions
|
||||||
|
|
||||||
|
Functions that increase performance or are quality of life in their nature.
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>Iterable</summary>
|
||||||
|
<p>
|
||||||
|
|
||||||
|
## Functional Functions
|
||||||
|
|
||||||
|
Java adds themselves a lot of functional functions like,
|
||||||
|
- Stream:
|
||||||
|
- Map/FlatMap
|
||||||
|
- Filter/Distinct/Limit/Sorted
|
||||||
|
- Count/FindFirst/Collect
|
||||||
|
- Peek/ForEach/Reduce
|
||||||
|
- anyMatch/allMatch/NoneMatch
|
||||||
|
|
||||||
|
that allows to process a collection in a functional way.
|
||||||
|
But these require streams which have a lot of Overhead in their nature.
|
||||||
|
|
||||||
|
Luckly Primitive Collections adds replacement functions that provide the same functionality but with minimal overhead.
|
||||||
|
Here are some examples:
|
||||||
|
```java
|
||||||
|
public ObjectIterable<Path> toPath(ObjectIterable<String> iterable) {
|
||||||
|
return iterable.map(Paths::get).filter(Files::exist);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Iterable<Path> toPath(Iterable<String> iterable) {
|
||||||
|
return ObjectIterables.map(iterable, Paths::get).filter(Files::exist);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int sum(IntIterable iterable) {
|
||||||
|
return iterable.reduce(Integer::sum);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## AsyncAPI</summary>
|
||||||
|
|
||||||
|
The AsyncAPI is a Feature that simplifies the processing of Collections on a separate thread.
|
||||||
|
It uses the same concept as Javas Stream API but uses the light weight Functions from Primitive Collections to achieve the same thing.
|
||||||
|
Unlike Javas StreamAPI the AsyncAPI is always singleThreaded and more like Javas CompletableFuture, which you can await or let run Asynchronous.
|
||||||
|
|
||||||
|
The Goal is it to simplify the processing of Collections asynchronous.
|
||||||
|
Especially on tasks which don't have to be finished instantly but can be processed on the side.
|
||||||
|
|
||||||
|
Here is a example of how the API works.
|
||||||
|
```java
|
||||||
|
public void processFiles(ObjectCollection<String> potentialFiles) {
|
||||||
|
potentialFiles.asAsync()
|
||||||
|
.map(Paths::get).filter(Files::exists) //Modifies the collection (Optional)
|
||||||
|
.forEach(Files::delete) //Creates the action (Required)
|
||||||
|
.callback(T -> {}} //Callback on completion, still offthread (Optional)
|
||||||
|
.execute() //Starts the task. (Required)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
</p>
|
||||||
|
</details>
|
||||||
|
<details>
|
||||||
|
<summary>Collection</summary>
|
||||||
|
<p>
|
||||||
|
|
||||||
|
These are functions specific to the Collections interface, stuff that everyone wished it was present to be in the first place.
|
||||||
|
|
||||||
|
## AddAll (Array)
|
||||||
|
Adding Elements to a Collection usually requires either a for loop or a Arrays.wrap().
|
||||||
|
This isn't an issue with Primitive Collections.
|
||||||
|
```java
|
||||||
|
public void addMonths(ObjectCollection<String> months) {
|
||||||
|
months.addAll("January", "February", "March", "April", "May", "June", "July", "August", "September, "October", November", "December");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addElements(ObjectCollection<String> result, String[] elements) {
|
||||||
|
result.addAll(elements, 0, 5); //elements, offset, length
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## containsAny
|
||||||
|
Everyone hates comparing if 2 collections have part of each other included.
|
||||||
|
The solution usually requires for loops and keeping track if things were found or not.
|
||||||
|
And every Java Developer had this issue at least once and wished for a clean solution.
|
||||||
|
```java
|
||||||
|
public boolean hasMonths(ObjectCollection<Month> target, Collection<Month> toFind) {
|
||||||
|
return target.containsAny(toFind);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Copy
|
||||||
|
Collections get copied every now and then. There is only 2 ways that this happens.
|
||||||
|
Javas Clone API or using Constructor that supports collections.
|
||||||
|
Javas Clone API is kinda in a Zombie state, where it is supported or not. Its not really clear if you should use it or not.
|
||||||
|
The Clone CloneNotSupportedException isn't helping either, causing more janky code.
|
||||||
|
While a Constructor can only support so much and testing for every case isn't really viable.
|
||||||
|
|
||||||
|
So the decision was made to straight out not support clone and instead add a copy function which doesn't use a checked exception.
|
||||||
|
It works exactly like the clone function. In a sense where it creates a shallow copy. (SubCollections do not work for obvious reasons)
|
||||||
|
```java
|
||||||
|
public IntCollection copy(IntCollection original) {
|
||||||
|
return original.copy();
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Primitive Streams
|
||||||
|
Since Javas Stream API is still really useful, even at its shortcomings, Primitive Collections provides easy access to it.
|
||||||
|
Generic Streams and the closest Primitive Stream will be provided. So a FloatCollection goes to a DoubleStream.
|
||||||
|
```java
|
||||||
|
public IntStream createStream(IntCollection source) {
|
||||||
|
return source.primitiveStream();
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## RemoveAll/RetainAll with listener
|
||||||
|
Ever wanted use removeAll or retainAll and wanted to know what elements actually got deleted?
|
||||||
|
The usual solution is to create a copy and then apply it to the original and cross reference them.
|
||||||
|
Which leads to really messy code and just hasn't a clean solution.
|
||||||
|
Luckly Primitive Collections got you covered.
|
||||||
|
```java
|
||||||
|
public void removeInvalidFiles(ObjectCollections<Path> files, ObjectCollection<Path> toRemove) {
|
||||||
|
files.removeAll(toRemove, T -> System.out.println(T));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeInvalidFiles(ObjectCollections<Path> files, ObjectCollection<Path> toKeep) {
|
||||||
|
files.retainFiles(toKeep, T -> System.out.println(T));
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## ToArray
|
||||||
|
Primitive Collections supports primitive/generic toArray functions for its Primitive Collections.
|
||||||
|
On top of that the Object side gets a Java9 function ported back to java8, which uses a functional Interface to create the backing array.
|
||||||
|
```java
|
||||||
|
public Integer[] toArray(IntCollection c) {
|
||||||
|
return c.toArray(new Integer[c.size]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int[] toArray(IntCollection c) {
|
||||||
|
return c.toIntArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String[] toArray(ObjectCollection<String> c) {
|
||||||
|
return c.toArray(String::new);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
</p>
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>List</summary>
|
||||||
|
<p>
|
||||||
|
|
||||||
|
These functions are List specific functions, a couple of these are from FastUtil.
|
||||||
|
|
||||||
|
## add/get/remove/extractElements
|
||||||
|
These functions really useful helper functions. 3 of which are copied from FastUtil. (extract is from Primitive Collections)
|
||||||
|
They are basically array forms of addAll, getAll, removeRange and removeAndGetRange. This is the simplest way to describe it.
|
||||||
|
|
||||||
|
Here some example:
|
||||||
|
```java
|
||||||
|
public void addAll(DoubleList list) {
|
||||||
|
list.addElements(0D, 12.2D, 3.5D, 4.2D);
|
||||||
|
}
|
||||||
|
|
||||||
|
public double[] getAll(DoubleList list, int amount) {
|
||||||
|
double[] result = new double[amount];
|
||||||
|
list.getElements(0, result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeRange(FloatList list) {
|
||||||
|
list.removeElements(5, 14);
|
||||||
|
}
|
||||||
|
|
||||||
|
public float[] extractRange(FloatList list) {
|
||||||
|
return list.extractElements(5, 14); //Returns the removed elements
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## addIfPresent/addIfAbsent
|
||||||
|
These two functions are simple helper functions that check internally if a element is present or absent before adding them to the List.
|
||||||
|
Removing the need for a contains or indexOf check every time you want to add a element.
|
||||||
|
While it is of course better to use a set, there is cases where this is still useful.
|
||||||
|
|
||||||
|
```java
|
||||||
|
public void addElements(IntList list, int... numbersToAdd) {
|
||||||
|
for(int e : numbersToAdd) {
|
||||||
|
list.addIfAbsent(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addExisting(ObjectList<String> list, String... textToAdd) {
|
||||||
|
for(String s : textToAdd) {
|
||||||
|
list.addIfPresent(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## SwapRemove
|
||||||
|
Lists when removing a Element shift usually the backing array to the left based to shrink the elements.
|
||||||
|
While that isn't computational expensive with LinkedLists, it is with ArrayLists.
|
||||||
|
Here comes swapRemove into play, which just removes the desired elements and instead of shifting left puts the last element in its place.
|
||||||
|
This reduces the data copying required down to 1 element instead of an array.
|
||||||
|
|
||||||
|
```java
|
||||||
|
public int remove(IntList elements, int indexToRemove) {
|
||||||
|
return elements.swapRemove(indexToRemove);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Unstable Sort (From FastUtil)
|
||||||
|
Unstable Sort uses a Faster but not as stable sorting algorithm to sort the Collection.
|
||||||
|
Stable doesn't mean crashing, but more like that the result isn't exactly perfectly sorted.
|
||||||
|
```java
|
||||||
|
public void sort(List<Month> list, Comparator<Month> sorter) {
|
||||||
|
list.unstableSort(sorter);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
</p>
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>Map</summary>
|
||||||
|
<p>
|
||||||
|
|
||||||
|
These functions are based on the Map interface. Useful functions you really would want.
|
||||||
|
|
||||||
|
## addTo/subFrom
|
||||||
|
addTo (from FastUtil) and subFrom are mathematically functions that either add or subtract from the value of a given key.
|
||||||
|
And if the key isn't present or would result in the default value it will either add or remove the entry from the Map. Given the circumstance.
|
||||||
|
This is a really useful function and I wish FastUtil made it accessible by default but sadly it isn't.
|
||||||
|
To simplify the explanation:
|
||||||
|
- addTo if no element is present puts in the desired number, otherwise it sums up the two values.
|
||||||
|
- subFrom if a element is present subtracts from it, if the element reaches the default value it removes the element from the map. If not present it will be ignored.
|
||||||
|
```java
|
||||||
|
public void addTo(Object2DoubleMap<Month> map, Month key, double averageTrainsRepaired) {
|
||||||
|
map.addTo(key, averageTrainsRepaired);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void subFrom(Long2IntMap map, long key, double amount) {
|
||||||
|
map.subFrom(key, amount);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## addToAll
|
||||||
|
Simple bulk version of the addTo function since sometimes you want to merge 2 maps for summing.
|
||||||
|
Especially if your work is multi-threaded this can become useful.
|
||||||
|
|
||||||
|
```java
|
||||||
|
public void addTo(Object2DoubleMap<Month> map, Object2DoubleMap<Month> trainsRepaired) {
|
||||||
|
map.addToAll(trainsRepaired);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## mergeAll
|
||||||
|
This is a simple bulk version of merge since merging 2 maps is more frequent then people might think and leads to cleaner code too.
|
||||||
|
```java
|
||||||
|
public void merge(Long2ByteMap result, Long2ByteMap toMerge) {
|
||||||
|
result.mergeAll(toMerge);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## putAll (Array)
|
||||||
|
This allows to put keys and values as arrays instead of requiring a WrapperMap to insert the elements.
|
||||||
|
Not as useful as the Collections.addAll variant but still really useful.
|
||||||
|
```java
|
||||||
|
public void putAll(Int2DoubleMap map, int[] keys, double[] values) {
|
||||||
|
map.put(keys, values, 2, 15);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## putAllIfAbsent
|
||||||
|
putAll has this usual quirk where if a element is present it will replace the value, and sometimes this is not wanted.
|
||||||
|
While putIfAbsent exists it has no real mass form and makes iterative solutions really uneasy to use.
|
||||||
|
Here comes the helper function that gets rid of that problem.
|
||||||
|
```java
|
||||||
|
public void merge(Long2ObjectMap<String> regionFiles, Long2ObjectMap<String> toAdd) {
|
||||||
|
regionFiles.putAllIfAbsent(toAdd);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## removeOrDefault
|
||||||
|
getOrDefault is a really useful function that find use cases all the time.
|
||||||
|
Sadly by default there is no variant of removeOrDefault, while it has less cases still could be used every now and then.
|
||||||
|
This function basically tries to remove a element, if it is not present it will just return your desired default.
|
||||||
|
```java
|
||||||
|
public Path removeCache(Long2ObjectMap<Path> caches, long key) {
|
||||||
|
return caches.removeOrDefault(key, Paths.get("nuclearFun"));
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## supplyIfAbsent
|
||||||
|
This one is one of my favorites. computeIfAbsent is a really useful function.
|
||||||
|
But in 90% of the cases I use it the value is a collection.
|
||||||
|
This becomes really annoying since methodReferences are faster/cleaner then Lambdas in my opinion.
|
||||||
|
supplyIfAbsent is basically computeIfAbsent but without a key, perfect for the default constructor of a collection.
|
||||||
|
This is the whole reason it exists.
|
||||||
|
```java
|
||||||
|
public void example(Int2ObjectMap<List<String>> map, Int2ObjectMap<String> toAdd) {
|
||||||
|
for(Entry<String> entry : toAdd.entrySet()) {
|
||||||
|
map.supplyIfAbsent(entry.getKey(), ObjectArrayList::new).add(entry.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
</p>
|
||||||
|
</details>
|
||||||
|
|
||||||
|
# Interfaces
|
||||||
|
|
||||||
|
Interfaces that provide essential or quality of life features.
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>ITrimmable</summary>
|
||||||
|
<p>
|
||||||
|
|
||||||
|
The ITrimmable is Accessor interface that allows you to access a couple helper functions to control the size of your collections.
|
||||||
|
This was created for the constant casting requirement to implementations just to shrink collections which get annoying over time.
|
||||||
|
|
||||||
|
## trim
|
||||||
|
This function basically trims down the backing implementation to use as little memory as required to store the elements in the collection.
|
||||||
|
Optionally a desired minimum size can be provided as of how low it should go at worst.
|
||||||
|
|
||||||
|
## clearAndTrim
|
||||||
|
when you want to reset a Collection completely you have 2 options. Clear it and then call trim, or recreate the collection.
|
||||||
|
clearAndTrim solves this problem by clearing the collection and trimming it in one go, reducing overhead to achieve such a thing.
|
||||||
|
|
||||||
|
</p>
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>IArray</summary>
|
||||||
|
<p>
|
||||||
|
|
||||||
|
IArray is a Accessor interface that provides more access to collections by providing tools to grow your collection as needed.
|
||||||
|
While putAll/addAll try to ensure that you have enough room for your elements, this is not really a solution for all cases.
|
||||||
|
Sometimes you need to ensure the Collection is pre-initialized.
|
||||||
|
IArray grants you that control.
|
||||||
|
|
||||||
|
There is also a type specific that provides you access to the backing array implementation of Lists for faster Iteration but that is a really specific case.
|
||||||
|
|
||||||
|
## ensureCapacity
|
||||||
|
Ensures that your collection has enough storage for the elements you want to insert.
|
||||||
|
|
||||||
|
## elements (ITypeSpecificArray)
|
||||||
|
Allows you access to the backing array of a List which is for people who know what they are doing.
|
||||||
|
There is a lambda version of this function too which makes sure for synchronizedLists that you are the only one accessing the array.
|
||||||
|
|
||||||
|
</p>
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>OrderedMap</summary>
|
||||||
|
<p>
|
||||||
|
|
||||||
|
The OrderedMap is a real edge case interface that was born for a need.
|
||||||
|
FastUtil added functions that were like moveToFirst which were hardcoded to the implementation.
|
||||||
|
They didn't fit into something like a SortedMap because the Set wasn't sorted.
|
||||||
|
So OrderedMap was born, which isn't random but ordered in a specific way that can be changed.
|
||||||
|
|
||||||
|
## getAndMoveToFirst/getAndMoveToLast
|
||||||
|
Returns a desired element and removing it to the first/last spot in the Map. Moving the element that was at its spot after/before it.
|
||||||
|
|
||||||
|
## moveToFirst/moveToLast
|
||||||
|
Moves the element if present to the first/last spot in the Map. Moving the element that was at its spot after/before it.
|
||||||
|
Returns true if the element was actually moved.
|
||||||
|
|
||||||
|
## putAndMoveToFirst/putAndMoveToLast
|
||||||
|
Adds the desired element and moves it to first/last spot in the Map. Moving the element that was at its spot after/before it.
|
||||||
|
|
||||||
|
## firstKey/lastKey (Optional poll)
|
||||||
|
Provides access to the current first/last key of the Map.
|
||||||
|
Optionally can be polled if desired.
|
||||||
|
|
||||||
|
## firstValue/lastValue
|
||||||
|
Provides access to the current first/last value of the Map.
|
||||||
|
|
||||||
|
</p>
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>OrderedSet</summary>
|
||||||
|
<p>
|
||||||
|
|
||||||
|
The OrderedSet is a real edge case interface that was born for a need.
|
||||||
|
FastUtil added functions that were like moveToFirst which were hardcoded to the implementation.
|
||||||
|
They didn't fit into something like a SortedSet because the Set wasn't sorted.
|
||||||
|
So OrderedSet was born, which isn't random but ordered in a specific way that can be changed.
|
||||||
|
|
||||||
|
## addAndMoveToFirst/addAndMoveToLast
|
||||||
|
Adds the desired element and moves it to first/last spot in the Collection. Moving the element that was at its spot after/before it.
|
||||||
|
|
||||||
|
## moveToFirst/moveToLast
|
||||||
|
Moves the element if present to the first/last spot in the Collection. Moving the element that was at its spot after/before it.
|
||||||
|
Returns true if the element was actually moved.
|
||||||
|
|
||||||
|
## first/last (Optional poll)
|
||||||
|
Provides access to the current first/last element of the set.
|
||||||
|
Optionally can be polled if desired.
|
||||||
|
|
||||||
|
</p>
|
||||||
|
</details>
|
||||||
+4
-1
@@ -1 +1,4 @@
|
|||||||
org.gradle.jvmargs=-Xmx3G
|
org.gradle.jvmargs=-Xmx3G
|
||||||
|
|
||||||
|
maxMemory = 2048m
|
||||||
|
testThreads = 4
|
||||||
+5
-5
@@ -1,5 +1,5 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-bin.zip
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
|||||||
@@ -2,6 +2,5 @@ jdk:
|
|||||||
- openjdk9
|
- openjdk9
|
||||||
install:
|
install:
|
||||||
- chmod +x ./gradlew
|
- chmod +x ./gradlew
|
||||||
- ./gradlew generateGithubSource
|
|
||||||
- ./gradlew build publishToMavenLocal
|
- ./gradlew build publishToMavenLocal
|
||||||
|
|
||||||
|
|||||||
@@ -3,15 +3,15 @@ package speiger.src.builder;
|
|||||||
@SuppressWarnings("javadoc")
|
@SuppressWarnings("javadoc")
|
||||||
public enum ClassType
|
public enum ClassType
|
||||||
{
|
{
|
||||||
BOOLEAN("boolean", "Boolean", "Boolean", "booleans", "BOOLEAN", "false"),
|
BOOLEAN("boolean", "Boolean", "Boolean", "booleans", "BOOLEAN", "false", "false"),
|
||||||
BYTE("byte", "Byte", "Byte", "bytes", "BYTE", "(byte)0"),
|
BYTE("byte", "Byte", "Byte", "bytes", "BYTE", "(byte)0", "(byte)-1"),
|
||||||
SHORT("short", "Short", "Short", "shorts", "SHORT", "(short)0"),
|
SHORT("short", "Short", "Short", "shorts", "SHORT", "(short)0", "(short)-1"),
|
||||||
CHAR("char", "Character", "Char", "chars", "CHAR", "(char)0"),
|
CHAR("char", "Character", "Char", "chars", "CHAR", "(char)0", "(char)-1"),
|
||||||
INT("int", "Integer", "Int", "ints", "INT", "0"),
|
INT("int", "Integer", "Int", "ints", "INT", "0", "-1"),
|
||||||
LONG("long", "Long", "Long", "longs", "LONG", "0L"),
|
LONG("long", "Long", "Long", "longs", "LONG", "0L", "-1L"),
|
||||||
FLOAT("float", "Float", "Float", "floats", "FLOAT", "0F"),
|
FLOAT("float", "Float", "Float", "floats", "FLOAT", "0F", "-1F"),
|
||||||
DOUBLE("double", "Double", "Double", "doubles", "DOUBLE", "0D"),
|
DOUBLE("double", "Double", "Double", "doubles", "DOUBLE", "0D", "-1D"),
|
||||||
OBJECT("T", "T", "Object", "objects", "OBJECT", "null");
|
OBJECT("T", "T", "Object", "objects", "OBJECT", "null", "null");
|
||||||
|
|
||||||
String keyType;
|
String keyType;
|
||||||
String classType;
|
String classType;
|
||||||
@@ -19,8 +19,9 @@ public enum ClassType
|
|||||||
String pathType;
|
String pathType;
|
||||||
String capType;
|
String capType;
|
||||||
String emptyValue;
|
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.keyType = keyType;
|
||||||
this.classType = classType;
|
this.classType = classType;
|
||||||
@@ -28,6 +29,7 @@ public enum ClassType
|
|||||||
this.pathType = pathType;
|
this.pathType = pathType;
|
||||||
this.capType = capType;
|
this.capType = capType;
|
||||||
this.emptyValue = emptyValue;
|
this.emptyValue = emptyValue;
|
||||||
|
this.invalidValue = invalidValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getKeyType()
|
public String getKeyType()
|
||||||
@@ -50,6 +52,11 @@ public enum ClassType
|
|||||||
return classType;
|
return classType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getClassPath()
|
||||||
|
{
|
||||||
|
return this == OBJECT ? "Object" : classType;
|
||||||
|
}
|
||||||
|
|
||||||
public String getClassType(boolean value)
|
public String getClassType(boolean value)
|
||||||
{
|
{
|
||||||
return value && this == OBJECT ? "V" : classType;
|
return value && this == OBJECT ? "V" : classType;
|
||||||
@@ -90,6 +97,11 @@ public enum ClassType
|
|||||||
return emptyValue;
|
return emptyValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getInvalidValue()
|
||||||
|
{
|
||||||
|
return invalidValue;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isObject()
|
public boolean isObject()
|
||||||
{
|
{
|
||||||
return this == OBJECT;
|
return this == OBJECT;
|
||||||
@@ -102,7 +114,7 @@ public enum ClassType
|
|||||||
|
|
||||||
public boolean needsCustomJDKType()
|
public boolean needsCustomJDKType()
|
||||||
{
|
{
|
||||||
return this == BYTE || this == SHORT || this == CHAR || this == FLOAT;
|
return this == BOOLEAN || this == BYTE || this == SHORT || this == CHAR || this == FLOAT;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean needsCast()
|
public boolean needsCast()
|
||||||
@@ -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)
|
public String getEquals(boolean not)
|
||||||
{
|
{
|
||||||
switch(this)
|
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()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,265 +1,230 @@
|
|||||||
package speiger.src.builder;
|
package speiger.src.builder;
|
||||||
|
|
||||||
import java.io.BufferedWriter;
|
import java.io.BufferedWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.EnumSet;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Map;
|
||||||
import java.util.StringJoiner;
|
import java.util.Set;
|
||||||
import java.util.function.Consumer;
|
import java.util.StringJoiner;
|
||||||
import java.util.stream.Stream;
|
import java.util.function.Consumer;
|
||||||
|
import java.util.stream.Stream;
|
||||||
import speiger.src.builder.processor.TemplateProcess;
|
|
||||||
import speiger.src.builder.processor.TemplateProcessor;
|
import speiger.src.builder.modules.AsyncModule;
|
||||||
|
import speiger.src.builder.modules.BaseModule;
|
||||||
@SuppressWarnings("javadoc")
|
import speiger.src.builder.modules.CollectionModule;
|
||||||
public class PrimitiveCollectionsBuilder extends TemplateProcessor
|
import speiger.src.builder.modules.FunctionModule;
|
||||||
{
|
import speiger.src.builder.modules.JavaModule;
|
||||||
Map<String, EnumSet<ClassType>> blocked = new HashMap<>();
|
import speiger.src.builder.modules.ListModule;
|
||||||
Map<String, String> nameRemapper = new HashMap<>();
|
import speiger.src.builder.modules.MapModule;
|
||||||
Map<String, String> biRequired = new HashMap<>();
|
import speiger.src.builder.modules.PairModule;
|
||||||
Set<String> enumRequired = new HashSet<>();
|
import speiger.src.builder.modules.PrioQueueModule;
|
||||||
public static final ClassType[] TYPE = ClassType.values();
|
import speiger.src.builder.modules.SetModule;
|
||||||
List<GlobalVariables> variables = new ArrayList<>();
|
import speiger.src.builder.processor.TemplateProcess;
|
||||||
List<GlobalVariables> biVariables = new ArrayList<>();
|
import speiger.src.builder.processor.TemplateProcessor;
|
||||||
List<GlobalVariables> enumVariables = new ArrayList<>();
|
|
||||||
|
@SuppressWarnings("javadoc")
|
||||||
public PrimitiveCollectionsBuilder()
|
public class PrimitiveCollectionsBuilder extends TemplateProcessor
|
||||||
{
|
{
|
||||||
this(false);
|
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.
|
||||||
public PrimitiveCollectionsBuilder(boolean silencedSuccess)
|
private static final int SAVE = 0x4; //if the configuration should be created
|
||||||
{
|
Set<String> globalFlags = new HashSet<>();
|
||||||
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/"));
|
List<ModulePackage> simplePackages = new ArrayList<>();
|
||||||
}
|
List<ModulePackage> biPackages = new ArrayList<>();
|
||||||
|
List<ModulePackage> enumPackages = new ArrayList<>();
|
||||||
public PrimitiveCollectionsBuilder(Path sourceFolder, Path outputFolder, Path dataFolder)
|
Map<String, RequiredType> requirements = new HashMap<>();
|
||||||
{
|
SettingsManager manager = new SettingsManager();
|
||||||
this(false, sourceFolder, outputFolder, dataFolder);
|
int flags;
|
||||||
}
|
|
||||||
|
public PrimitiveCollectionsBuilder() {
|
||||||
public PrimitiveCollectionsBuilder(boolean silencedSuccess, Path sourceFolder, Path outputFolder, Path dataFolder)
|
this(false);
|
||||||
{
|
}
|
||||||
super(silencedSuccess, sourceFolder, outputFolder, dataFolder);
|
|
||||||
}
|
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/"));
|
||||||
@Override
|
}
|
||||||
protected boolean isFileValid(Path fileName)
|
|
||||||
{
|
public PrimitiveCollectionsBuilder(Path sourceFolder, Path outputFolder, Path dataFolder) {
|
||||||
return true;
|
this(false, sourceFolder, outputFolder, dataFolder);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public PrimitiveCollectionsBuilder(boolean silencedSuccess, Path sourceFolder, Path outputFolder, Path dataFolder) {
|
||||||
protected boolean relativePackages()
|
super(silencedSuccess, sourceFolder, outputFolder, dataFolder);
|
||||||
{
|
}
|
||||||
return true;
|
|
||||||
}
|
private PrimitiveCollectionsBuilder setFlags(int flags) {
|
||||||
|
this.flags = flags;
|
||||||
@Override
|
if((flags & ANTI_SAVE) != 0) {
|
||||||
protected boolean debugUnusedMappers()
|
this.flags &= ~SAVE;
|
||||||
{
|
}
|
||||||
return false;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private static PrimitiveCollectionsBuilder createTests(boolean silent, int flags) {
|
||||||
protected void afterFinish()
|
return new PrimitiveCollectionsBuilder(silent,
|
||||||
{
|
Paths.get("src/builder/resources/speiger/assets/tests/templates/"),
|
||||||
if(getVersion() > 8)
|
Paths.get("src/test/java/speiger/src/tests/"),
|
||||||
{
|
Paths.get("src/builder/resources/speiger/assets/tests/")).setFlags(flags | SPECIAL);
|
||||||
Path basePath = Paths.get("src/main/java");
|
}
|
||||||
try(BufferedWriter writer = Files.newBufferedWriter(basePath.resolve("module-info.java")))
|
|
||||||
{
|
private static PrimitiveCollectionsBuilder createTesters(boolean silent, int flags) {
|
||||||
writer.write(getModuleInfo(basePath));
|
return new PrimitiveCollectionsBuilder(silent,
|
||||||
}
|
Paths.get("src/builder/resources/speiger/assets/testers/templates/"),
|
||||||
catch(Exception e)
|
Paths.get("src/test/java/speiger/src/testers/"),
|
||||||
{
|
Paths.get("src/builder/resources/speiger/assets/testers/")).setFlags(flags | SPECIAL);
|
||||||
e.printStackTrace();
|
}
|
||||||
}
|
|
||||||
}
|
@Override
|
||||||
}
|
protected boolean isFileValid(Path fileName) { return true; }
|
||||||
|
@Override
|
||||||
@Override
|
protected boolean relativePackages() { return true; }
|
||||||
protected void init()
|
@Override
|
||||||
{
|
protected boolean debugUnusedMappers() { return false; }
|
||||||
variables.clear();
|
|
||||||
for(ClassType clzType : TYPE)
|
@Override
|
||||||
{
|
protected void afterFinish() {
|
||||||
for(ClassType subType : TYPE)
|
if((flags & SPECIAL) == 0 && getVersion() > 8) {
|
||||||
{
|
Path basePath = Paths.get("src/main/java");
|
||||||
create(clzType, subType);
|
try(BufferedWriter writer = Files.newBufferedWriter(basePath.resolve("module-info.java"))) {
|
||||||
}
|
writer.write(getModuleInfo(basePath));
|
||||||
}
|
}
|
||||||
enumRequired.add("EnumMap");
|
catch(Exception e) { e.printStackTrace(); }
|
||||||
enumRequired.add("LinkedEnumMap");
|
}
|
||||||
biRequired.put("BiConsumer", "");
|
}
|
||||||
biRequired.put("UnaryOperator", "");
|
|
||||||
biRequired.put("Pair", "");
|
public List<BaseModule> createModules() {
|
||||||
biRequired.put("MutablePair", "");
|
List<BaseModule> modules = new ArrayList<>();
|
||||||
biRequired.put("ImmutablePair", "");
|
modules.add(JavaModule.INSTANCE);
|
||||||
addBiClass("Function", "Maps", "Map", "SortedMap", "OrderedMap", "NavigableMap", "ConcurrentMap", "AbstractMap", "ConcurrentOpenHashMap", "ImmutableOpenHashMap", "OpenHashMap", "LinkedOpenHashMap", "OpenCustomHashMap", "LinkedOpenCustomHashMap", "ArrayMap", "RBTreeMap", "AVLTreeMap");
|
modules.add(FunctionModule.INSTANCE);
|
||||||
nameRemapper.put("BiConsumer", "%sConsumer");
|
modules.add(CollectionModule.INSTANCE);
|
||||||
nameRemapper.put("IArray", "I%sArray");
|
modules.add(PrioQueueModule.INSTANCE);
|
||||||
nameRemapper.put("AbstractMap", "Abstract%sMap");
|
modules.add(ListModule.INSTANCE);
|
||||||
nameRemapper.put("AbstractCollection", "Abstract%sCollection");
|
modules.add(SetModule.INSTANCE);
|
||||||
nameRemapper.put("AbstractPriorityQueue", "Abstract%sPriorityQueue");
|
modules.add(MapModule.INSTANCE);
|
||||||
nameRemapper.put("AbstractSet", "Abstract%sSet");
|
modules.add(PairModule.INSTANCE);
|
||||||
nameRemapper.put("AbstractList", "Abstract%sList");
|
modules.add(AsyncModule.INSTANCE);
|
||||||
nameRemapper.put("EnumMap", "Enum2%sMap");
|
return modules;
|
||||||
nameRemapper.put("LinkedEnumMap", "LinkedEnum2%sMap");
|
}
|
||||||
nameRemapper.put("ImmutableList", "Immutable%sList");
|
|
||||||
nameRemapper.put("CopyOnWriteList", "CopyOnWrite%sArrayList");
|
|
||||||
nameRemapper.put("ImmutableOpenHashSet", "Immutable%sOpenHashSet");
|
@Override
|
||||||
nameRemapper.put("ImmutableOpenHashMap", "Immutable%sOpenHashMap");
|
protected void init() {
|
||||||
|
prepPackages();
|
||||||
addBlockage(ClassType.OBJECT, "Consumer", "Comparator", "Stack");
|
//Init Modules here
|
||||||
addBlockage(ClassType.BOOLEAN, "ArraySet", "AVLTreeSet", "RBTreeSet", "SortedSet", "OrderedSet", "NavigableSet", "OpenHashSet", "OpenCustomHashSet", "LinkedOpenHashSet", "LinkedOpenCustomHashSet");
|
addModules(createModules());
|
||||||
addBlockage(ClassType.BOOLEAN, "ConcurrentOpenHashMap", "ImmutableOpenHashMap", "ImmutableOpenHashSet", "SortedMap", "OrderedMap", "NavigableMap", "ConcurrentMap", "OpenHashMap", "LinkedOpenHashMap", "OpenCustomHashMap", "LinkedOpenCustomHashMap", "ArrayMap", "RBTreeMap", "AVLTreeMap");
|
finishPackages();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void create(ClassType mainType, ClassType subType)
|
public void addModules(List<BaseModule> modules) {
|
||||||
{
|
for(int i = 0,m=modules.size();i<m;i++) {
|
||||||
GlobalVariables type = new GlobalVariables(mainType, subType);
|
modules.get(i).setManager(manager);
|
||||||
type.createFlags();
|
}
|
||||||
type.createHelperVariables();
|
manager.resolve();
|
||||||
type.createVariables();
|
for(int i = 0,m=modules.size();i<m;i++) {
|
||||||
type.createPreFunctions();
|
biPackages.forEach(modules.get(i)::init);
|
||||||
type.createClassTypes();
|
}
|
||||||
type.createFunctions();
|
modules.forEach(BaseModule::cleanup);
|
||||||
if(mainType == subType) variables.add(type);
|
}
|
||||||
biVariables.add(type);
|
|
||||||
if(mainType.isObject()) enumVariables.add(type);
|
private void finishPackages() {
|
||||||
}
|
biPackages.forEach(ModulePackage::finish);
|
||||||
|
if((flags & SAVE) != 0) manager.save();
|
||||||
protected void addBiClass(String...classNames)
|
}
|
||||||
{
|
|
||||||
for(String s : classNames)
|
private void prepPackages() {
|
||||||
{
|
if((flags & LOAD) != 0) manager.load();
|
||||||
biRequired.put(s, "2");
|
for(ModulePackage entry : ModulePackage.createPackages(globalFlags)) {
|
||||||
}
|
entry.setRequirements(requirements::put);
|
||||||
}
|
biPackages.add(entry);
|
||||||
|
if(entry.isSame()) simplePackages.add(entry);
|
||||||
protected void addBlockage(ClassType type, String...args)
|
if(entry.isEnumValid()) enumPackages.add(entry);
|
||||||
{
|
}
|
||||||
for(String s : args)
|
}
|
||||||
{
|
|
||||||
EnumSet<ClassType> set = blocked.get(s);
|
@Override
|
||||||
if(set == null)
|
public void createProcesses(String fileName, Consumer<TemplateProcess> process) {
|
||||||
{
|
List<ModulePackage> packages = getPackagesByRequirement(requirements.get(fileName));
|
||||||
set = EnumSet.noneOf(ClassType.class);
|
for(int i = 0,m=packages.size();i<m;i++) {
|
||||||
blocked.put(s, set);
|
packages.get(i).process(fileName, process);
|
||||||
}
|
}
|
||||||
set.add(type);
|
}
|
||||||
}
|
|
||||||
}
|
protected List<ModulePackage> getPackagesByRequirement(RequiredType type) {
|
||||||
|
if(type == null) return simplePackages;
|
||||||
@Override
|
if(type == RequiredType.BI_CLASS) return biPackages;
|
||||||
public void createProcesses(String name, Consumer<TemplateProcess> acceptor)
|
if(type == RequiredType.ENUM) return enumPackages;
|
||||||
{
|
return Collections.emptyList();
|
||||||
String splitter = biRequired.get(name);
|
}
|
||||||
boolean valueRequired = enumRequired.contains(name);
|
|
||||||
List<GlobalVariables> vars = getVariablesByClass(name, splitter != null);
|
private String getModuleInfo(Path basePath) {
|
||||||
EnumSet<ClassType> types = blocked.get(name);
|
StringJoiner joiner = new StringJoiner("\n", "", "\n");
|
||||||
for(int i = 0,m=vars.size();i<m;i++)
|
try(Stream<Path> stream = Files.walk(getOutputFolder())) {
|
||||||
{
|
stream.filter(Files::isDirectory)
|
||||||
GlobalVariables type = vars.get(i);
|
.filter(this::containsFiles)
|
||||||
if(types == null || !types.contains(type.getType()))
|
.map(basePath::relativize)
|
||||||
{
|
.map(Path::toString)
|
||||||
acceptor.accept(type.create(nameRemapper.getOrDefault(name, "%s"+name), splitter, valueRequired));
|
.map(this::sanitize)
|
||||||
}
|
.forEach(T -> joiner.add("\texports "+T+";"));
|
||||||
}
|
}
|
||||||
}
|
catch(Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
protected List<GlobalVariables> getVariablesByClass(String name, boolean bi) {
|
throw new RuntimeException(e);
|
||||||
if(enumRequired.contains(name)) return enumVariables;
|
}
|
||||||
if(bi) return biVariables;
|
StringBuilder builder = new StringBuilder();
|
||||||
return variables;
|
builder.append("/** @author Speiger */\n");
|
||||||
}
|
builder.append("module ").append(sanitize(basePath.relativize(getOutputFolder()).toString())).append(" {\n");
|
||||||
|
builder.append(joiner.toString()).append("}");
|
||||||
private String getModuleInfo(Path basePath) {
|
return builder.toString();
|
||||||
StringJoiner joiner = new StringJoiner("\n", "", "\n");
|
}
|
||||||
try(Stream<Path> stream = Files.walk(getOutputFolder()))
|
|
||||||
{
|
private String sanitize(String input) {
|
||||||
stream.filter(Files::isDirectory)
|
return input.replace("\\", ".").replace("/", ".");
|
||||||
.filter(this::containsFiles)
|
}
|
||||||
.map(basePath::relativize)
|
|
||||||
.map(Path::toString)
|
private boolean containsFiles(Path path) {
|
||||||
.map(this::sanitize)
|
try(Stream<Path> stream = Files.walk(path, 1)) {
|
||||||
.forEach(T -> joiner.add("\texports "+T+";"));
|
return stream.filter(Files::isRegularFile).findFirst().isPresent();
|
||||||
}
|
}
|
||||||
catch(Exception e)
|
catch(Exception e) { e.printStackTrace(); }
|
||||||
{
|
return false;
|
||||||
e.printStackTrace();
|
}
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
private int getVersion() {
|
||||||
StringBuilder builder = new StringBuilder();
|
String version = System.getProperty("java.version");
|
||||||
builder.append("/** @author Speiger */\n");
|
if(version.startsWith("1.")) return Integer.parseInt(version.substring(2, 3));
|
||||||
builder.append("module ").append(sanitize(basePath.relativize(getOutputFolder()).toString())).append(" {\n");
|
int dot = version.indexOf(".");
|
||||||
builder.append(joiner.toString()).append("}");
|
return Integer.parseInt(dot != -1 ? version.substring(0, dot) : version);
|
||||||
return builder.toString();
|
}
|
||||||
}
|
|
||||||
|
public static void main(String...args) {
|
||||||
private String sanitize(String input)
|
try
|
||||||
{
|
{
|
||||||
return input.replace("\\", ".").replace("/", ".");
|
Set<String> flags = new HashSet<>(Arrays.asList(args));
|
||||||
}
|
boolean silent = flags.contains("silent");
|
||||||
|
boolean force = flags.contains("force");
|
||||||
private boolean containsFiles(Path path)
|
boolean tests = flags.contains("tests");
|
||||||
{
|
boolean forceTests = flags.contains("force-tests");
|
||||||
try(Stream<Path> stream = Files.walk(path, 1))
|
boolean load = flags.contains("load");
|
||||||
{
|
boolean save = flags.contains("save");
|
||||||
return stream.filter(Files::isRegularFile).findFirst().isPresent();
|
int flag = (load ? LOAD : 0) | (save ? SAVE : 0);
|
||||||
}
|
new PrimitiveCollectionsBuilder(silent).setFlags(flag).process(force);
|
||||||
catch(Exception e)
|
if(tests) {
|
||||||
{
|
createTests(silent, flag).process(force || forceTests);
|
||||||
e.printStackTrace();
|
createTesters(silent, flag).process(force || forceTests);
|
||||||
}
|
}
|
||||||
return false;
|
}
|
||||||
}
|
catch(InterruptedException | IOException e)
|
||||||
|
{
|
||||||
private int getVersion()
|
e.printStackTrace();
|
||||||
{
|
}
|
||||||
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)
|
|
||||||
{
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
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");
|
||||||
|
}
|
||||||
|
}
|
||||||
+345
-261
@@ -1,262 +1,346 @@
|
|||||||
package speiger.src.collections.PACKAGE.collections;
|
package speiger.src.collections.PACKAGE.collections;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Objects;
|
#if ORDERED_MAP_FEATURE
|
||||||
import java.util.AbstractCollection;
|
import java.util.function.Supplier;
|
||||||
#if TYPE_OBJECT
|
#endif
|
||||||
import java.util.function.Consumer;
|
import java.util.Objects;
|
||||||
#endif
|
import java.util.AbstractCollection;
|
||||||
|
#if TYPE_OBJECT
|
||||||
#if !TYPE_OBJECT
|
import java.util.function.Consumer;
|
||||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
#endif
|
||||||
import speiger.src.collections.PACKAGE.utils.ITERATORS;
|
|
||||||
#endif
|
#if ORDERED_MAP_FEATURE
|
||||||
|
import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
|
||||||
/**
|
#endif
|
||||||
* Abstract Type Specific Collection that reduces boxing/unboxing
|
#if !TYPE_OBJECT
|
||||||
* @Type(T)
|
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||||
*/
|
import speiger.src.collections.PACKAGE.utils.ITERATORS;
|
||||||
public abstract class ABSTRACT_COLLECTION KEY_GENERIC_TYPE extends AbstractCollection<CLASS_TYPE> implements COLLECTION KEY_GENERIC_TYPE
|
import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
||||||
{
|
#endif
|
||||||
@Override
|
|
||||||
public abstract ITERATOR KEY_GENERIC_TYPE iterator();
|
/**
|
||||||
|
* Abstract Type Specific Collection that reduces boxing/unboxing
|
||||||
#if !TYPE_OBJECT
|
* @Type(T)
|
||||||
/** {@inheritDoc}
|
*/
|
||||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
public abstract class ABSTRACT_COLLECTION KEY_GENERIC_TYPE extends AbstractCollection<CLASS_TYPE> implements COLLECTION KEY_GENERIC_TYPE
|
||||||
* @deprecated Please use the corresponding type-specific function instead.
|
{
|
||||||
*/
|
@Override
|
||||||
@Override
|
public abstract ITERATOR KEY_GENERIC_TYPE iterator();
|
||||||
@Deprecated
|
|
||||||
public boolean add(CLASS_TYPE e) { return COLLECTION.super.add(e); }
|
#if !TYPE_OBJECT
|
||||||
|
/** {@inheritDoc}
|
||||||
#endif
|
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||||
@Override
|
* @deprecated Please use the corresponding type-specific function instead.
|
||||||
public boolean addAll(COLLECTION KEY_GENERIC_TYPE c) {
|
*/
|
||||||
boolean modified = false;
|
@Override
|
||||||
for(ITERATOR KEY_GENERIC_TYPE iter = c.iterator();iter.hasNext();modified |= add(iter.NEXT()));
|
@Deprecated
|
||||||
return modified;
|
public boolean add(CLASS_TYPE e) { return COLLECTION.super.add(e); }
|
||||||
}
|
|
||||||
|
#endif
|
||||||
@Override
|
@Override
|
||||||
public COLLECTION KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
public boolean addAll(COLLECTION KEY_GENERIC_TYPE c) {
|
||||||
|
boolean modified = false;
|
||||||
#if !TYPE_OBJECT
|
for(ITERATOR KEY_GENERIC_TYPE iter = c.iterator();iter.hasNext();modified |= add(iter.NEXT()));
|
||||||
/** {@inheritDoc}
|
return modified;
|
||||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
}
|
||||||
* @deprecated Please use the corresponding type-specific function instead.
|
|
||||||
*/
|
@Override
|
||||||
@Override
|
public COLLECTION KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
||||||
@Deprecated
|
|
||||||
public boolean contains(Object e) { return COLLECTION.super.contains(e); }
|
#if !TYPE_OBJECT
|
||||||
|
/** {@inheritDoc}
|
||||||
/**
|
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||||
* A Type-Specific implementation of contains. This implementation iterates over the elements and returns true if the value match.
|
* @deprecated Please use the corresponding type-specific function instead.
|
||||||
* @param e the element that should be searched for.
|
*/
|
||||||
* @return true if the value was found.
|
@Override
|
||||||
*/
|
@Deprecated
|
||||||
@Override
|
public boolean contains(Object e) { return COLLECTION.super.contains(e); }
|
||||||
public boolean contains(KEY_TYPE e) {
|
|
||||||
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) { if(KEY_EQUALS(iter.NEXT(), e)) return true; }
|
/**
|
||||||
return false;
|
* A Type-Specific implementation of contains. This implementation iterates over the elements and returns true if the value match.
|
||||||
}
|
* @param e the element that should be searched for.
|
||||||
|
* @return true if the value was found.
|
||||||
/** {@inheritDoc}
|
*/
|
||||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
@Override
|
||||||
* @deprecated Please use the corresponding type-specific function instead.
|
public boolean contains(KEY_TYPE e) {
|
||||||
*/
|
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) { if(KEY_EQUALS(iter.NEXT(), e)) return true; }
|
||||||
@Override
|
return false;
|
||||||
@Deprecated
|
}
|
||||||
public boolean addAll(Collection<? extends CLASS_TYPE> c)
|
|
||||||
{
|
/** {@inheritDoc}
|
||||||
return c instanceof COLLECTION ? addAll((COLLECTION KEY_GENERIC_TYPE)c) : super.addAll(c);
|
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||||
}
|
* @deprecated Please use the corresponding type-specific function instead.
|
||||||
#endif
|
*/
|
||||||
|
@Override
|
||||||
/**
|
@Deprecated
|
||||||
* A Type-Specific implementation of containsAll. This implementation iterates over all elements and checks all elements are present in the other collection.
|
public boolean addAll(Collection<? extends CLASS_TYPE> c)
|
||||||
* @param c the collection that should be checked if it contains all elements.
|
{
|
||||||
* @return true if all elements were found in the collection
|
return c instanceof COLLECTION ? addAll((COLLECTION KEY_GENERIC_TYPE)c) : super.addAll(c);
|
||||||
* @throws java.lang.NullPointerException if the collection is null
|
}
|
||||||
*/
|
#endif
|
||||||
@Override
|
|
||||||
public boolean containsAll(COLLECTION KEY_GENERIC_TYPE c) {
|
/**
|
||||||
Objects.requireNonNull(c);
|
* A Type-Specific implementation of containsAll. This implementation iterates over all elements and checks all elements are present in the other collection.
|
||||||
if(c.isEmpty()) return true;
|
* @param c the collection that should be checked if it contains all elements.
|
||||||
for(ITERATOR KEY_GENERIC_TYPE iter = c.iterator();iter.hasNext();)
|
* @return true if all elements were found in the collection
|
||||||
if(!contains(iter.NEXT()))
|
* @throws java.lang.NullPointerException if the collection is null
|
||||||
return false;
|
*/
|
||||||
return true;
|
@Override
|
||||||
}
|
public boolean containsAll(COLLECTION KEY_GENERIC_TYPE c) {
|
||||||
|
Objects.requireNonNull(c);
|
||||||
@Override
|
if(c.isEmpty()) return true;
|
||||||
public boolean containsAll(Collection<?> c) {
|
for(ITERATOR KEY_GENERIC_TYPE iter = c.iterator();iter.hasNext();)
|
||||||
Objects.requireNonNull(c);
|
if(!contains(iter.NEXT()))
|
||||||
return c instanceof COLLECTION ? containsAll((COLLECTION KEY_GENERIC_TYPE)c) : super.containsAll(c);
|
return false;
|
||||||
}
|
return true;
|
||||||
|
}
|
||||||
/**
|
|
||||||
* This implementation iterates over the elements of the collection and checks if they are stored in this collection
|
@Override
|
||||||
* @param c the elements that should be checked for
|
public boolean containsAll(Collection<?> c) {
|
||||||
* @return true if any element is in this collection
|
Objects.requireNonNull(c);
|
||||||
* @throws java.lang.NullPointerException if the collection is null
|
return c instanceof COLLECTION ? containsAll((COLLECTION KEY_GENERIC_TYPE)c) : super.containsAll(c);
|
||||||
*/
|
}
|
||||||
@Override
|
|
||||||
@Primitive
|
/**
|
||||||
public boolean containsAny(Collection<?> c) {
|
* This implementation iterates over the elements of the collection and checks if they are stored in this collection
|
||||||
Objects.requireNonNull(c);
|
* @param c the elements that should be checked for
|
||||||
if(c.isEmpty()) return false;
|
* @return true if any element is in this collection
|
||||||
for(Object e : c)
|
* @throws java.lang.NullPointerException if the collection is null
|
||||||
if(contains(e))
|
*/
|
||||||
return true;
|
@Override
|
||||||
return false;
|
@Primitive
|
||||||
}
|
public boolean containsAny(Collection<?> c) {
|
||||||
|
Objects.requireNonNull(c);
|
||||||
/**
|
if(c.isEmpty()) return false;
|
||||||
* This implementation iterates over the elements of the collection and checks if they are stored in this collection.
|
for(Object e : c)
|
||||||
* @param c the elements that should be checked for
|
if(contains(e))
|
||||||
* @return true if any element is in this collection
|
return true;
|
||||||
* @throws java.lang.NullPointerException if the collection is null
|
return false;
|
||||||
*/
|
}
|
||||||
@Override
|
|
||||||
public boolean containsAny(COLLECTION KEY_GENERIC_TYPE c) {
|
/**
|
||||||
Objects.requireNonNull(c);
|
* This implementation iterates over the elements of the collection and checks if they are stored in this collection.
|
||||||
if(c.isEmpty()) return false;
|
* @param c the elements that should be checked for
|
||||||
for(ITERATOR KEY_GENERIC_TYPE iter = c.iterator();iter.hasNext();)
|
* @return true if any element is in this collection
|
||||||
if(contains(iter.NEXT()))
|
* @throws java.lang.NullPointerException if the collection is null
|
||||||
return true;
|
*/
|
||||||
return false;
|
@Override
|
||||||
}
|
public boolean containsAny(COLLECTION KEY_GENERIC_TYPE c) {
|
||||||
|
Objects.requireNonNull(c);
|
||||||
#if !TYPE_OBJECT
|
if(c.isEmpty()) return false;
|
||||||
/** {@inheritDoc}
|
for(ITERATOR KEY_GENERIC_TYPE iter = c.iterator();iter.hasNext();)
|
||||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
if(contains(iter.NEXT()))
|
||||||
* @deprecated Please use the corresponding type-specific function instead.
|
return true;
|
||||||
*/
|
return false;
|
||||||
@Override
|
}
|
||||||
@Deprecated
|
|
||||||
public boolean remove(Object e) { return COLLECTION.super.remove(e); }
|
#if !TYPE_OBJECT
|
||||||
|
/** {@inheritDoc}
|
||||||
/**
|
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||||
* A Type-Specific implementation of remove. This implementation iterates over the elements until it finds the element that is searched for or it runs out of elements.
|
* @deprecated Please use the corresponding type-specific function instead.
|
||||||
* It stops after finding the first element
|
*/
|
||||||
* @param e the element that is searched for
|
@Override
|
||||||
* @return true if the element was found and removed.
|
@Deprecated
|
||||||
*/
|
public boolean remove(Object e) { return COLLECTION.super.remove(e); }
|
||||||
@Override
|
|
||||||
public boolean REMOVE_KEY(KEY_TYPE e) {
|
/**
|
||||||
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
* A Type-Specific implementation of remove. This implementation iterates over the elements until it finds the element that is searched for or it runs out of elements.
|
||||||
if(KEY_EQUALS(iter.NEXT(), e)) {
|
* It stops after finding the first element
|
||||||
iter.remove();
|
* @param e the element that is searched for
|
||||||
return true;
|
* @return true if the element was found and removed.
|
||||||
}
|
*/
|
||||||
}
|
@Override
|
||||||
return false;
|
public boolean REMOVE_KEY(KEY_TYPE e) {
|
||||||
}
|
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
||||||
|
if(KEY_EQUALS(iter.NEXT(), e)) {
|
||||||
#endif
|
iter.remove();
|
||||||
/**
|
return true;
|
||||||
* A Type-Specific implementation of removeAll. This Implementation iterates over all elements and removes them as they were found in the other collection.
|
}
|
||||||
* @param c the elements that should be deleted
|
}
|
||||||
* @return true if the collection was modified.
|
return false;
|
||||||
* @throws java.lang.NullPointerException if the collection is null
|
}
|
||||||
*/
|
|
||||||
@Override
|
#endif
|
||||||
public boolean removeAll(COLLECTION KEY_GENERIC_TYPE c) {
|
/**
|
||||||
Objects.requireNonNull(c);
|
* A Type-Specific implementation of removeAll. This Implementation iterates over all elements and removes them as they were found in the other collection.
|
||||||
if(c.isEmpty()) return false;
|
* @param c the elements that should be deleted
|
||||||
boolean modified = false;
|
* @return true if the collection was modified.
|
||||||
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
* @throws java.lang.NullPointerException if the collection is null
|
||||||
if(c.contains(iter.NEXT())) {
|
*/
|
||||||
iter.remove();
|
@Override
|
||||||
modified = true;
|
public boolean removeAll(COLLECTION KEY_GENERIC_TYPE c) {
|
||||||
}
|
Objects.requireNonNull(c);
|
||||||
}
|
if(c.isEmpty()) return false;
|
||||||
return modified;
|
boolean modified = false;
|
||||||
}
|
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
||||||
|
if(c.contains(iter.NEXT())) {
|
||||||
@Override
|
iter.remove();
|
||||||
public boolean removeAll(COLLECTION KEY_GENERIC_TYPE c, CONSUMER KEY_GENERIC_TYPE r) {
|
modified = true;
|
||||||
Objects.requireNonNull(c);
|
}
|
||||||
if(c.isEmpty()) return false;
|
}
|
||||||
Objects.requireNonNull(r);
|
return modified;
|
||||||
boolean modified = false;
|
}
|
||||||
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
|
||||||
KEY_TYPE e = iter.NEXT();
|
@Override
|
||||||
if(c.contains(e)) {
|
public boolean removeAll(COLLECTION KEY_GENERIC_TYPE c, CONSUMER KEY_GENERIC_TYPE r) {
|
||||||
r.accept(e);
|
Objects.requireNonNull(c);
|
||||||
iter.remove();
|
if(c.isEmpty()) return false;
|
||||||
modified = true;
|
Objects.requireNonNull(r);
|
||||||
}
|
boolean modified = false;
|
||||||
}
|
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
||||||
return modified;
|
KEY_TYPE e = iter.NEXT();
|
||||||
}
|
if(c.contains(e)) {
|
||||||
|
r.accept(e);
|
||||||
/**
|
iter.remove();
|
||||||
* A Type-Specific implementation of retainAll. This Implementation iterates over all elements and removes them as they were not found in the other collection.
|
modified = true;
|
||||||
* @param c the elements that should be kept
|
}
|
||||||
* @return true if the collection was modified.
|
}
|
||||||
* @throws java.lang.NullPointerException if the collection is null
|
return modified;
|
||||||
*/
|
}
|
||||||
@Override
|
|
||||||
public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c) {
|
/**
|
||||||
Objects.requireNonNull(c);
|
* A Type-Specific implementation of retainAll. This Implementation iterates over all elements and removes them as they were not found in the other collection.
|
||||||
if(c.isEmpty()) {
|
* @param c the elements that should be kept
|
||||||
boolean modified = !isEmpty();
|
* @return true if the collection was modified.
|
||||||
clear();
|
* @throws java.lang.NullPointerException if the collection is null
|
||||||
return modified;
|
*/
|
||||||
}
|
@Override
|
||||||
boolean modified = false;
|
public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c) {
|
||||||
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
Objects.requireNonNull(c);
|
||||||
if(!c.contains(iter.NEXT())) {
|
if(c.isEmpty()) {
|
||||||
iter.remove();
|
boolean modified = !isEmpty();
|
||||||
modified = true;
|
clear();
|
||||||
}
|
return modified;
|
||||||
}
|
}
|
||||||
return modified;
|
boolean modified = false;
|
||||||
}
|
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
||||||
|
if(!c.contains(iter.NEXT())) {
|
||||||
@Override
|
iter.remove();
|
||||||
public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c, CONSUMER KEY_GENERIC_TYPE r) {
|
modified = true;
|
||||||
Objects.requireNonNull(c);
|
}
|
||||||
Objects.requireNonNull(r);
|
}
|
||||||
if(c.isEmpty()) {
|
return modified;
|
||||||
boolean modified = !isEmpty();
|
}
|
||||||
forEach(r);
|
|
||||||
clear();
|
@Override
|
||||||
return modified;
|
public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c, CONSUMER KEY_GENERIC_TYPE r) {
|
||||||
}
|
Objects.requireNonNull(c);
|
||||||
boolean modified = false;
|
Objects.requireNonNull(r);
|
||||||
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
if(c.isEmpty()) {
|
||||||
KEY_TYPE e = iter.NEXT();
|
boolean modified = !isEmpty();
|
||||||
if(!c.contains(e)) {
|
forEach(r);
|
||||||
iter.remove();
|
clear();
|
||||||
modified = true;
|
return modified;
|
||||||
}
|
}
|
||||||
}
|
boolean modified = false;
|
||||||
return modified;
|
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
||||||
}
|
KEY_TYPE e = iter.NEXT();
|
||||||
|
if(!c.contains(e)) {
|
||||||
#if !TYPE_OBJECT
|
r.accept(e);
|
||||||
/**
|
iter.remove();
|
||||||
* A Type-Specific implementation of toArray that links to {@link #TO_ARRAY(KEY_TYPE[])} with a newly created array.
|
modified = true;
|
||||||
* @return an array containing all of the elements in this collection
|
}
|
||||||
*/
|
}
|
||||||
@Override
|
return modified;
|
||||||
public KEY_TYPE[] TO_ARRAY() {
|
}
|
||||||
return TO_ARRAY(new KEY_TYPE[size()]);
|
|
||||||
}
|
#if !TYPE_OBJECT
|
||||||
|
/**
|
||||||
/**
|
* A Type-Specific implementation of toArray that links to {@link #TO_ARRAY(KEY_TYPE[])} with a newly created array.
|
||||||
* A Type-Specific implementation of toArray. This implementation iterates over all elements and unwraps them into primitive type.
|
* @return an array containing all of the elements in this collection
|
||||||
* @param a array that the elements should be injected to. If null or to small a new array with the right size is created
|
*/
|
||||||
* @return an array containing all of the elements in this collection
|
@Override
|
||||||
*/
|
public KEY_TYPE[] TO_ARRAY() {
|
||||||
@Override
|
if(isEmpty()) return ARRAYS.EMPTY_ARRAY;
|
||||||
public KEY_TYPE[] TO_ARRAY(KEY_TYPE[] a) {
|
return TO_ARRAY(new KEY_TYPE[size()]);
|
||||||
if(a == null || a.length < size()) a = new KEY_TYPE[size()];
|
}
|
||||||
ITERATORS.unwrap(a, iterator());
|
|
||||||
return a;
|
/**
|
||||||
}
|
* A Type-Specific implementation of toArray. This implementation iterates over all elements and unwraps them into primitive type.
|
||||||
#endif
|
* @param a array that the elements should be injected to. If null or to small a new array with the right size is created
|
||||||
|
* @return an array containing all of the elements in this collection
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE[] TO_ARRAY(KEY_TYPE[] a) {
|
||||||
|
if(a == null || a.length < size()) a = new KEY_TYPE[size()];
|
||||||
|
ITERATORS.unwrap(a, iterator());
|
||||||
|
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
|
||||||
}
|
}
|
||||||
+3
-11
@@ -1,19 +1,11 @@
|
|||||||
package speiger.src.collections.PACKAGE.collections;
|
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.
|
* 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.
|
* Allowing to have a simple Bidirectional Iterator without having to keep track of the Iteration index.
|
||||||
* @Type(T)
|
* @Type(T)
|
||||||
*/
|
*/
|
||||||
public interface BI_ITERATOR KEY_GENERIC_TYPE extends ITERATOR KEY_GENERIC_TYPE
|
public interface BI_ITERATOR KEY_GENERIC_TYPE extends ITERATOR KEY_GENERIC_TYPE
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Returns true if the Iterator has a Previous element
|
* 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();
|
public KEY_TYPE PREVIOUS();
|
||||||
|
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
/** {@inheritDoc}
|
/**
|
||||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||||
* @deprecated Please use the corresponding type-specific function instead.
|
* @deprecated Please use the corresponding type-specific function instead.
|
||||||
|
* @return the Previous element of the iterator.+
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public default CLASS_TYPE previous() {
|
public default CLASS_TYPE previous() {
|
||||||
return KEY_TO_OBJ(PREVIOUS());
|
return KEY_TO_OBJ(PREVIOUS());
|
||||||
@@ -57,7 +49,7 @@ public interface BI_ITERATOR KEY_GENERIC_TYPE extends ITERATOR KEY_GENERIC_TYPE
|
|||||||
public default int back(int amount) {
|
public default int back(int amount) {
|
||||||
if(amount < 0) throw new IllegalStateException("Can't go forward");
|
if(amount < 0) throw new IllegalStateException("Can't go forward");
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for(;i<amount && hasPrevious();previous(),i++);
|
for(;i<amount && hasPrevious();PREVIOUS(),i++);
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+322
-311
@@ -1,312 +1,323 @@
|
|||||||
package speiger.src.collections.PACKAGE.collections;
|
package speiger.src.collections.PACKAGE.collections;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
#if PRIMITIVES
|
#if PRIMITIVES
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.function.JAVA_PREDICATE;
|
import java.util.function.JAVA_PREDICATE;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
import java.util.stream.JAVA_STREAM;
|
#if SPLIT_ITERATOR_FEATURE && STREAM_FEATURE
|
||||||
import java.util.stream.StreamSupport;
|
import java.util.stream.JAVA_STREAM;
|
||||||
#endif
|
import java.util.stream.StreamSupport;
|
||||||
#if TYPE_OBJECT
|
#endif
|
||||||
import java.util.function.Consumer;
|
#endif
|
||||||
import speiger.src.collections.ints.functions.function.Int2ObjectFunction;
|
#if TYPE_OBJECT
|
||||||
#else
|
import java.util.function.Consumer;
|
||||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
import java.util.function.IntFunction;
|
||||||
#endif
|
#else
|
||||||
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||||
import speiger.src.collections.PACKAGE.utils.COLLECTIONS;
|
#endif
|
||||||
import speiger.src.collections.utils.SanityChecks;
|
#if SPLIT_ITERATOR_FEATURE
|
||||||
|
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
||||||
/**
|
#endif
|
||||||
* A Type-Specific {@link Collection} that reduces (un)boxing
|
import speiger.src.collections.PACKAGE.utils.COLLECTIONS;
|
||||||
* @Type(T)
|
import speiger.src.collections.utils.ISizeProvider;
|
||||||
*/
|
import speiger.src.collections.utils.SanityChecks;
|
||||||
public interface COLLECTION KEY_GENERIC_TYPE extends Collection<CLASS_TYPE>, ITERABLE KEY_GENERIC_TYPE
|
|
||||||
{
|
/**
|
||||||
#if !TYPE_OBJECT
|
* A Type-Specific {@link Collection} that reduces (un)boxing
|
||||||
/**
|
* @Type(T)
|
||||||
* A Type-Specific add function to reduce (un)boxing
|
*/
|
||||||
* @param o the element that should be added
|
public interface COLLECTION KEY_GENERIC_TYPE extends Collection<CLASS_TYPE>, ITERABLE KEY_GENERIC_TYPE, ISizeProvider
|
||||||
* @return true if the element was added to the collection
|
{
|
||||||
*/
|
#if !TYPE_OBJECT
|
||||||
public boolean add(KEY_TYPE o);
|
/**
|
||||||
|
* A Type-Specific add function to reduce (un)boxing
|
||||||
#endif
|
* @param o the element that should be added
|
||||||
/**
|
* @return true if the element was added to the collection
|
||||||
* A Type-Specific addAll function to reduce (un)boxing
|
*/
|
||||||
* @param c the collection of elements that should be added
|
public boolean add(KEY_TYPE o);
|
||||||
* @return true if elements were added into the collection
|
|
||||||
*/
|
#endif
|
||||||
public boolean addAll(COLLECTION KEY_GENERIC_TYPE c);
|
/**
|
||||||
|
* A Type-Specific addAll function to reduce (un)boxing
|
||||||
/**
|
* @param c the collection of elements that should be added
|
||||||
* A Type-Specific Array based addAll method to reduce the amount of Wrapping
|
* @return true if elements were added into the collection
|
||||||
* @param e the elements that should be added
|
*/
|
||||||
* @return if the collection was modified
|
public boolean addAll(COLLECTION KEY_GENERIC_TYPE c);
|
||||||
*/
|
|
||||||
public default boolean addAll(KEY_TYPE... e) { return addAll(e, 0, e.length); }
|
/**
|
||||||
|
* A Type-Specific Array based addAll method to reduce the amount of Wrapping
|
||||||
/**
|
* @param e the elements that should be added
|
||||||
* A Type-Specific Array based addAll method to reduce the amount of Wrapping
|
* @return if the collection was modified
|
||||||
* @param e the elements that should be added
|
*/
|
||||||
* @param length how many elements of the array should be added
|
public default boolean addAll(KEY_TYPE... e) { return addAll(e, 0, e.length); }
|
||||||
* @return if the collection was modified
|
|
||||||
*/
|
/**
|
||||||
public default boolean addAll(KEY_TYPE[] e, int length) { return addAll(e, 0, length); }
|
* A Type-Specific Array based addAll method to reduce the amount of Wrapping
|
||||||
|
* @param e the elements that should be added
|
||||||
/**
|
* @param length how many elements of the array should be added
|
||||||
* A Type-Specific Array based addAll method to reduce the amount of Wrapping
|
* @return if the collection was modified
|
||||||
* @param e the elements that should be added
|
*/
|
||||||
* @param offset where to start within the array
|
public default boolean addAll(KEY_TYPE[] e, int length) { return addAll(e, 0, length); }
|
||||||
* @param length how many elements of the array should be added
|
|
||||||
* @return if the collection was modified
|
/**
|
||||||
*/
|
* A Type-Specific Array based addAll method to reduce the amount of Wrapping
|
||||||
public default boolean addAll(KEY_TYPE[] e, int offset, int length) {
|
* @param e the elements that should be added
|
||||||
if(length <= 0) return false;
|
* @param offset where to start within the array
|
||||||
SanityChecks.checkArrayCapacity(e.length, offset, length);
|
* @param length how many elements of the array should be added
|
||||||
boolean added = false;
|
* @return if the collection was modified
|
||||||
for(int i = 0;i<length;i++) {
|
*/
|
||||||
if(add(e[offset+i])) added = true;
|
public default boolean addAll(KEY_TYPE[] e, int offset, int length) {
|
||||||
}
|
if(length <= 0) return false;
|
||||||
return added;
|
SanityChecks.checkArrayCapacity(e.length, offset, length);
|
||||||
}
|
boolean added = false;
|
||||||
|
for(int i = 0;i<length;i++) {
|
||||||
#if !TYPE_OBJECT
|
if(add(e[offset+i])) added = true;
|
||||||
/**
|
}
|
||||||
* A Type-Specific contains function to reduce (un)boxing
|
return added;
|
||||||
* @param o the element that is checked for
|
}
|
||||||
* @return true if the element is found in the collection
|
|
||||||
*/
|
#if !TYPE_OBJECT
|
||||||
public boolean contains(KEY_TYPE o);
|
/**
|
||||||
|
* A Type-Specific contains function to reduce (un)boxing
|
||||||
#endif
|
* @param o the element that is checked for
|
||||||
/**
|
* @return true if the element is found in the collection
|
||||||
* A Type-Specific containsAll function to reduce (un)boxing
|
*/
|
||||||
* @param c the collection of elements that should be tested for
|
public boolean contains(KEY_TYPE o);
|
||||||
* @return true if all the element is found in the collection
|
|
||||||
*/
|
#endif
|
||||||
public boolean containsAll(COLLECTION KEY_GENERIC_TYPE c);
|
/**
|
||||||
|
* A Type-Specific containsAll function to reduce (un)boxing
|
||||||
/**
|
* @param c the collection of elements that should be tested for
|
||||||
* A Type-Specific containsAny function to reduce (un)boxing
|
* @return true if all the element is found in the collection
|
||||||
* @param c the collection of elements that should be tested for
|
*/
|
||||||
* @return true if any element was found
|
public boolean containsAll(COLLECTION KEY_GENERIC_TYPE c);
|
||||||
*/
|
|
||||||
public boolean containsAny(COLLECTION KEY_GENERIC_TYPE c);
|
/**
|
||||||
|
* A Type-Specific containsAny function to reduce (un)boxing
|
||||||
/**
|
* @param c the collection of elements that should be tested for
|
||||||
* Returns true if any element of the Collection is found in the provided collection.
|
* @return true if any element was found
|
||||||
* A Small Optimization function to find out of any element is present when comparing collections and not all of them.
|
*/
|
||||||
* @param c the collection of elements that should be tested for
|
public boolean containsAny(COLLECTION KEY_GENERIC_TYPE c);
|
||||||
* @return true if any element was found.
|
|
||||||
*/
|
/**
|
||||||
@Primitive
|
* Returns true if any element of the Collection is found in the provided collection.
|
||||||
public boolean containsAny(Collection<?> c);
|
* A Small Optimization function to find out of any element is present when comparing collections and not all of them.
|
||||||
|
* @param c the collection of elements that should be tested for
|
||||||
#if !TYPE_OBJECT
|
* @return true if any element was found.
|
||||||
/**
|
*/
|
||||||
* A Type-Specific remove function that reduces (un)boxing.
|
@Primitive
|
||||||
* @param o the element that should be removed
|
public boolean containsAny(Collection<?> c);
|
||||||
* @return true if the element was removed
|
|
||||||
* @see Collection#remove(Object)
|
#if !TYPE_OBJECT
|
||||||
*/
|
/**
|
||||||
public boolean REMOVE_KEY(KEY_TYPE o);
|
* A Type-Specific remove function that reduces (un)boxing.
|
||||||
|
* @param o the element that should be removed
|
||||||
#endif
|
* @return true if the element was removed
|
||||||
/**
|
* @see Collection#remove(Object)
|
||||||
* A Type-Specific removeAll function that reduces (un)boxing.
|
*/
|
||||||
* @param c the collection of elements that should be removed
|
public boolean REMOVE_KEY(KEY_TYPE o);
|
||||||
* @return true if any element was removed
|
|
||||||
* @see Collection#removeAll(Collection)
|
#endif
|
||||||
*/
|
/**
|
||||||
public boolean removeAll(COLLECTION KEY_GENERIC_TYPE c);
|
* A Type-Specific removeAll function that reduces (un)boxing.
|
||||||
|
* @param c the collection of elements that should be removed
|
||||||
/**
|
* @return true if any element was removed
|
||||||
* A Type-Specific removeAll function that reduces (un)boxing.
|
* @see Collection#removeAll(Collection)
|
||||||
* It also notifies the remover of which exact element is going to be removed.
|
*/
|
||||||
* @param c the collection of elements that should be removed
|
public boolean removeAll(COLLECTION KEY_GENERIC_TYPE c);
|
||||||
* @param r elements that got removed
|
|
||||||
* @return true if any element was removed
|
/**
|
||||||
* @see Collection#removeAll(Collection)
|
* A Type-Specific removeAll function that reduces (un)boxing.
|
||||||
*/
|
* It also notifies the remover of which exact element is going to be removed.
|
||||||
public boolean removeAll(COLLECTION KEY_GENERIC_TYPE c, CONSUMER KEY_GENERIC_TYPE r);
|
* @param c the collection of elements that should be removed
|
||||||
|
* @param r elements that got removed
|
||||||
/**
|
* @return true if any element was removed
|
||||||
* A Type-Specific retainAll function that reduces (un)boxing.
|
* @see Collection#removeAll(Collection)
|
||||||
* @param c the collection of elements that should be kept
|
*/
|
||||||
* @return true if any element was removed
|
public boolean removeAll(COLLECTION KEY_GENERIC_TYPE c, CONSUMER KEY_GENERIC_TYPE r);
|
||||||
* @see Collection#retainAll(Collection)
|
|
||||||
*/
|
/**
|
||||||
public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c);
|
* A Type-Specific retainAll function that reduces (un)boxing.
|
||||||
|
* @param c the collection of elements that should be kept
|
||||||
/**
|
* @return true if any element was removed
|
||||||
* A Type-Specific retainAll function that reduces (un)boxing.
|
* @see Collection#retainAll(Collection)
|
||||||
* It also notifies the remover of which exact element is going to be removed.
|
*/
|
||||||
* @param c the collection of elements that should be kept
|
public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c);
|
||||||
* @param r elements that got removed
|
|
||||||
* @return true if any element was removed
|
/**
|
||||||
* @see Collection#retainAll(Collection)
|
* A Type-Specific retainAll function that reduces (un)boxing.
|
||||||
*/
|
* It also notifies the remover of which exact element is going to be removed.
|
||||||
public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c, CONSUMER KEY_GENERIC_TYPE r);
|
* @param c the collection of elements that should be kept
|
||||||
|
* @param r elements that got removed
|
||||||
/**
|
* @return true if any element was removed
|
||||||
* A Helper function to reduce the usage of Streams and allows to collect all elements
|
* @see Collection#retainAll(Collection)
|
||||||
* @param collection that the elements should be inserted to
|
*/
|
||||||
* @param <E> the collection type
|
public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c, CONSUMER KEY_GENERIC_TYPE r);
|
||||||
* @return the input with the desired elements
|
|
||||||
*/
|
/**
|
||||||
default <E extends COLLECTION KEY_GENERIC_TYPE> E pour(E collection) {
|
* A Helper function to reduce the usage of Streams and allows to collect all elements
|
||||||
collection.addAll(this);
|
* @param collection that the elements should be inserted to
|
||||||
return collection;
|
* @param <E> the collection type
|
||||||
}
|
* @return the input with the desired elements
|
||||||
|
*/
|
||||||
/**
|
default <E extends COLLECTION KEY_GENERIC_TYPE> E pour(E collection) {
|
||||||
* A Function that does a shallow clone of the Collection itself.
|
collection.addAll(this);
|
||||||
* This function is more optimized then a copy constructor since the Collection does not have to be unsorted/resorted.
|
return collection;
|
||||||
* It can be compared to Cloneable but with less exception risk
|
}
|
||||||
* @return a Shallow Copy of the collection
|
|
||||||
* @note Wrappers and view collections will not support this feature
|
/**
|
||||||
*/
|
* A Function that does a shallow clone of the Collection itself.
|
||||||
public COLLECTION KEY_GENERIC_TYPE copy();
|
* This function is more optimized then a copy constructor since the Collection does not have to be unsorted/resorted.
|
||||||
|
* It can be compared to Cloneable but with less exception risk
|
||||||
#if TYPE_OBJECT
|
* @return a Shallow Copy of the collection
|
||||||
/**
|
* @note Wrappers and view collections will not support this feature
|
||||||
* A Helper function that simplifies the process of creating a new Array.
|
*/
|
||||||
* @param action the array creation function
|
public COLLECTION KEY_GENERIC_TYPE copy();
|
||||||
* @return an array containing all of the elements in this collection
|
|
||||||
* @see Collection#toArray(Object[])
|
#if TYPE_OBJECT
|
||||||
*/
|
/**
|
||||||
default KEY_TYPE[] TO_ARRAY(Int2ObjectFunction<KEY_TYPE[]> action) {
|
* A Helper function that simplifies the process of creating a new Array.
|
||||||
return TO_ARRAY(action.get(size()));
|
* @param action the array creation function
|
||||||
}
|
* @param <E> the returning arrayType
|
||||||
|
* @return an array containing all of the elements in this collection
|
||||||
#else
|
* @see Collection#toArray(Object[])
|
||||||
/**
|
*/
|
||||||
* A Type-Specific toArray function that delegates to {@link #TO_ARRAY(KEY_TYPE[])} with a newly created array.
|
default <E> E[] TO_ARRAY(IntFunction<E[]> action) {
|
||||||
* @return an array containing all of the elements in this collection
|
return TO_ARRAY(action.apply(size()));
|
||||||
* @see Collection#toArray()
|
}
|
||||||
*/
|
|
||||||
public KEY_TYPE[] TO_ARRAY();
|
#else
|
||||||
|
/**
|
||||||
/**
|
* A Type-Specific toArray function that delegates to {@link #TO_ARRAY(KEY_TYPE[])} with a newly created array.
|
||||||
* A Type-Specific toArray function that reduces (un)boxing.
|
* @return an array containing all of the elements in this collection
|
||||||
* @param a array that the elements should be injected to. If null or to small a new array with the right size is created
|
* @see Collection#toArray()
|
||||||
* @return an array containing all of the elements in this collection
|
*/
|
||||||
* @see Collection#toArray(Object[])
|
public KEY_TYPE[] TO_ARRAY();
|
||||||
*/
|
|
||||||
public KEY_TYPE[] TO_ARRAY(KEY_TYPE[] a);
|
/**
|
||||||
|
* A Type-Specific toArray function that reduces (un)boxing.
|
||||||
#if PRIMITIVES
|
* @param a array that the elements should be injected to. If null or to small a new array with the right size is created
|
||||||
/** {@inheritDoc}
|
* @return an array containing all of the elements in this collection
|
||||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
* @see Collection#toArray(Object[])
|
||||||
* @deprecated Please use the corresponding type-specific function instead.
|
*/
|
||||||
*/
|
public KEY_TYPE[] TO_ARRAY(KEY_TYPE[] a);
|
||||||
@Override
|
|
||||||
@Deprecated
|
#if PRIMITIVES
|
||||||
public default boolean removeIf(Predicate<? super CLASS_TYPE> filter) {
|
/** {@inheritDoc}
|
||||||
Objects.requireNonNull(filter);
|
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||||
#if TYPE_BYTE || TYPE_SHORT || TYPE_CHAR || TYPE_FLOAT
|
* @deprecated Please use the corresponding type-specific function instead.
|
||||||
return remIf(v -> filter.test(KEY_TO_OBJ(SanityChecks.SANITY_CAST(v))));
|
*/
|
||||||
#else
|
@Override
|
||||||
return remIf(v -> filter.test(KEY_TO_OBJ(v)));
|
@Deprecated
|
||||||
#endif
|
public default boolean removeIf(Predicate<? super CLASS_TYPE> filter) {
|
||||||
}
|
Objects.requireNonNull(filter);
|
||||||
|
#if TYPE_BYTE || TYPE_SHORT || TYPE_CHAR || TYPE_FLOAT
|
||||||
/**
|
return remIf(v -> filter.test(KEY_TO_OBJ(SanityChecks.SANITY_CAST(v))));
|
||||||
* A Type-Specific removeIf function to reduce (un)boxing.
|
#else
|
||||||
* <p>Removes elements that were selected by the filter
|
return remIf(v -> filter.test(KEY_TO_OBJ(v)));
|
||||||
* @see Collection#removeIf(Predicate)
|
#endif
|
||||||
* @param filter Filters the elements that should be removed
|
}
|
||||||
* @return true if the collection was modified
|
|
||||||
* @throws java.lang.NullPointerException if filter is null
|
/**
|
||||||
*/
|
* A Type-Specific removeIf function to reduce (un)boxing.
|
||||||
public default boolean remIf(JAVA_PREDICATE filter) {
|
* <p>Removes elements that were selected by the filter
|
||||||
Objects.requireNonNull(filter);
|
* @see Collection#removeIf(Predicate)
|
||||||
boolean removed = false;
|
* @param filter Filters the elements that should be removed
|
||||||
final ITERATOR each = iterator();
|
* @return true if the collection was modified
|
||||||
while (each.hasNext()) {
|
* @throws java.lang.NullPointerException if filter is null
|
||||||
if (filter.test(each.NEXT())) {
|
*/
|
||||||
each.remove();
|
public default boolean remIf(JAVA_PREDICATE filter) {
|
||||||
removed = true;
|
Objects.requireNonNull(filter);
|
||||||
}
|
boolean removed = false;
|
||||||
}
|
final ITERATOR each = iterator();
|
||||||
return removed;
|
while (each.hasNext()) {
|
||||||
}
|
if (filter.test(each.NEXT())) {
|
||||||
|
each.remove();
|
||||||
#endif
|
removed = true;
|
||||||
/** {@inheritDoc}
|
}
|
||||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
}
|
||||||
* @deprecated Please use the corresponding type-specific function instead.
|
return removed;
|
||||||
*/
|
}
|
||||||
@Override
|
|
||||||
@Deprecated
|
#endif
|
||||||
public default boolean add(CLASS_TYPE o) { return add(OBJ_TO_KEY(o)); }
|
/** {@inheritDoc}
|
||||||
|
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||||
/** {@inheritDoc}
|
* @deprecated Please use the corresponding type-specific function instead.
|
||||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
*/
|
||||||
* @deprecated Please use the corresponding type-specific function instead.
|
@Override
|
||||||
*/
|
@Deprecated
|
||||||
@Override
|
public default boolean add(CLASS_TYPE o) { return add(OBJ_TO_KEY(o)); }
|
||||||
@Deprecated
|
|
||||||
public default boolean contains(Object o) { return o != null && contains(CLASS_TO_KEY(o)); }
|
/** {@inheritDoc}
|
||||||
|
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||||
/** {@inheritDoc}
|
* @deprecated Please use the corresponding type-specific function instead.
|
||||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
*/
|
||||||
* @deprecated Please use the corresponding type-specific function instead.
|
@Override
|
||||||
*/
|
@Deprecated
|
||||||
@Override
|
public default boolean contains(Object o) { return o != null && contains(CLASS_TO_KEY(o)); }
|
||||||
@Deprecated
|
|
||||||
public default boolean remove(Object o) { return o != null && REMOVE_KEY(CLASS_TO_KEY(o)); }
|
/** {@inheritDoc}
|
||||||
|
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||||
#endif
|
* @deprecated Please use the corresponding type-specific function instead.
|
||||||
/**
|
*/
|
||||||
* Returns a Type-Specific Iterator to reduce (un)boxing
|
@Override
|
||||||
* @return a iterator of the collection
|
@Deprecated
|
||||||
* @see Collection#iterator()
|
public default boolean remove(Object o) { return o != null && REMOVE_KEY(CLASS_TO_KEY(o)); }
|
||||||
*/
|
|
||||||
@Override
|
#endif
|
||||||
public ITERATOR KEY_GENERIC_TYPE iterator();
|
/**
|
||||||
|
* Returns a Type-Specific Iterator to reduce (un)boxing
|
||||||
/**
|
* @return a iterator of the collection
|
||||||
* Creates a Wrapped Collection that is Synchronized
|
* @see Collection#iterator()
|
||||||
* @return a new Collection that is synchronized
|
*/
|
||||||
* @see COLLECTIONS#synchronize
|
@Override
|
||||||
*/
|
public ITERATOR KEY_GENERIC_TYPE iterator();
|
||||||
public default COLLECTION KEY_GENERIC_TYPE synchronize() { return COLLECTIONS.synchronize(this); }
|
|
||||||
|
/**
|
||||||
/**
|
* Creates a Wrapped Collection that is Synchronized
|
||||||
* Creates a Wrapped Collection that is Synchronized
|
* @return a new Collection that is synchronized
|
||||||
* @param mutex is the controller of the synchronization block
|
* @see COLLECTIONS#synchronize
|
||||||
* @return a new Collection Wrapper that is synchronized
|
*/
|
||||||
* @see COLLECTIONS#synchronize
|
public default COLLECTION KEY_GENERIC_TYPE synchronize() { return COLLECTIONS.synchronize(this); }
|
||||||
*/
|
|
||||||
public default COLLECTION KEY_GENERIC_TYPE synchronize(Object mutex) { return COLLECTIONS.synchronize(this, mutex); }
|
/**
|
||||||
|
* Creates a Wrapped Collection that is Synchronized
|
||||||
/**
|
* @param mutex is the controller of the synchronization block
|
||||||
* Creates a Wrapped Collection that is unmodifiable
|
* @return a new Collection Wrapper that is synchronized
|
||||||
* @return a new Collection Wrapper that is unmodifiable
|
* @see COLLECTIONS#synchronize
|
||||||
* @see COLLECTIONS#unmodifiable
|
*/
|
||||||
*/
|
public default COLLECTION KEY_GENERIC_TYPE synchronize(Object mutex) { return COLLECTIONS.synchronize(this, mutex); }
|
||||||
public default COLLECTION KEY_GENERIC_TYPE unmodifiable() { return COLLECTIONS.unmodifiable(this); }
|
|
||||||
|
/**
|
||||||
#if PRIMITIVES
|
* Creates a Wrapped Collection that is unmodifiable
|
||||||
/**
|
* @return a new Collection Wrapper that is unmodifiable
|
||||||
* Returns a Java-Type-Specific Stream to reduce boxing/unboxing.
|
* @see COLLECTIONS#unmodifiable
|
||||||
* @return a Stream of the closest java type
|
*/
|
||||||
*/
|
public default COLLECTION KEY_GENERIC_TYPE unmodifiable() { return COLLECTIONS.unmodifiable(this); }
|
||||||
default JAVA_STREAM primitiveStream() { return StreamSupport.NEW_STREAM(SPLIT_ITERATORS.createJavaSplititerator(this, 0), false); }
|
|
||||||
|
#if SPLIT_ITERATOR_FEATURE
|
||||||
/**
|
#if PRIMITIVES
|
||||||
* Returns a Java-Type-Specific Parallel Stream to reduce boxing/unboxing.
|
/**
|
||||||
* @return a Stream of the closest java type
|
* Returns a Java-Type-Specific Stream to reduce boxing/unboxing.
|
||||||
*/
|
* @return a Stream of the closest java type
|
||||||
default JAVA_STREAM parallelPrimitiveStream() { return StreamSupport.NEW_STREAM(SPLIT_ITERATORS.createJavaSplititerator(this, 0), true); }
|
*/
|
||||||
#endif
|
default JAVA_STREAM primitiveStream() { return StreamSupport.NEW_STREAM(SPLIT_ITERATORS.createJavaSplititerator(this, 0), false); }
|
||||||
/**
|
|
||||||
* A Type Specific Type Splititerator to reduce boxing/unboxing
|
/**
|
||||||
* @return type specific splititerator
|
* Returns a Java-Type-Specific Parallel Stream to reduce boxing/unboxing.
|
||||||
*/
|
* @return a Stream of the closest java type
|
||||||
@Override
|
*/
|
||||||
default SPLIT_ITERATOR KEY_GENERIC_TYPE spliterator() { return SPLIT_ITERATORS.createSplititerator(this, 0); }
|
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
|
||||||
}
|
}
|
||||||
+495
-319
@@ -1,320 +1,496 @@
|
|||||||
package speiger.src.collections.PACKAGE.collections;
|
package speiger.src.collections.PACKAGE.collections;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
#if !TYPE_OBJECT
|
#if JDK_FUNCTION
|
||||||
|
import java.util.function.PREDICATE;
|
||||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
#endif
|
||||||
import speiger.src.collections.objects.collections.ObjectIterable;
|
#if JDK_TYPE
|
||||||
#else
|
import java.util.OPTIONAL;
|
||||||
import java.util.function.BiFunction;
|
#endif
|
||||||
|
|
||||||
#endif
|
#if !TYPE_OBJECT
|
||||||
import speiger.src.collections.PACKAGE.functions.function.TO_OBJECT_FUNCTION;
|
|
||||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
import speiger.src.collections.objects.collections.ObjectIterable;
|
||||||
import speiger.src.collections.PACKAGE.lists.LIST;
|
#else
|
||||||
import speiger.src.collections.PACKAGE.lists.ARRAY_LIST;
|
import java.util.function.BiFunction;
|
||||||
#if !TYPE_BOOLEAN
|
import java.util.function.IntFunction;
|
||||||
import speiger.src.collections.PACKAGE.sets.SET;
|
import java.util.Comparator;
|
||||||
import speiger.src.collections.PACKAGE.sets.LINKED_HASH_SET;
|
|
||||||
#endif
|
#if BOOLEAN_COLLECTION_MODULE
|
||||||
import speiger.src.collections.PACKAGE.utils.ASYNC_BUILDER;
|
import speiger.src.collections.booleans.collections.BooleanIterable;
|
||||||
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
#endif
|
||||||
import speiger.src.collections.PACKAGE.utils.ITERABLES;
|
#iterate
|
||||||
import speiger.src.collections.PACKAGE.utils.ITERATORS;
|
#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
|
||||||
* A Type-Specific {@link Iterable} that reduces (un)boxing
|
#argument FILTER_TYPE BYTE_COLLECTION_MODULE SHORT_COLLECTION_MODULE INT_COLLECTION_MODULE LONG_COLLECTION_MODULE FLOAT_COLLECTION_MODULE DOUBLE_COLLECTION_MODULE
|
||||||
* @Type(T)
|
#if FILTER_TYPE
|
||||||
*/
|
import speiger.src.collections.objects.functions.function.MAPPER;
|
||||||
public interface ITERABLE KEY_GENERIC_TYPE extends Iterable<CLASS_TYPE>
|
import speiger.src.collections.PACKAGE.collections.OUTPUT_ITERABLE;
|
||||||
{
|
#endif
|
||||||
/**
|
#enditerate
|
||||||
* Returns an iterator over elements of type {@code T}.
|
#endif
|
||||||
*
|
#if !JDK_TYPE
|
||||||
* @return an Iterator.
|
import speiger.src.collections.PACKAGE.functions.OPTIONAL;
|
||||||
*/
|
#endif
|
||||||
@Override
|
import speiger.src.collections.PACKAGE.functions.function.TO_OBJECT_FUNCTION;
|
||||||
ITERATOR KEY_GENERIC_TYPE iterator();
|
import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
|
||||||
|
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||||
#if !TYPE_OBJECT
|
#if !JDK_FUNCTION
|
||||||
/**
|
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||||
* A Type Specific foreach function that reduces (un)boxing
|
#endif
|
||||||
*
|
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||||
* @implSpec
|
#if ARRAY_LIST_FEATURE || LINKED_LIST_FEATURE
|
||||||
* <p>The default implementation behaves as if:
|
import speiger.src.collections.PACKAGE.lists.LIST;
|
||||||
* <pre>{@code
|
#if ARRAY_LIST_FEATURE
|
||||||
* iterator().forEachRemaining(action);
|
import speiger.src.collections.PACKAGE.lists.ARRAY_LIST;
|
||||||
* }</pre>
|
#else
|
||||||
*
|
import speiger.src.collections.PACKAGE.lists.LINKED_LIST;
|
||||||
* @param action The action to be performed for each element
|
#endif
|
||||||
* @throws NullPointerException if the specified action is null
|
#endif
|
||||||
* @see Iterable#forEach(Consumer)
|
#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
|
||||||
default void forEach(CONSUMER action) {
|
import speiger.src.collections.PACKAGE.sets.SET;
|
||||||
Objects.requireNonNull(action);
|
#if LINKED_SET_FEATURE
|
||||||
iterator().forEachRemaining(action);
|
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;
|
||||||
/** {@inheritDoc}
|
#else if SET_FEATURE
|
||||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
import speiger.src.collections.PACKAGE.sets.HASH_SET;
|
||||||
* @deprecated Please use the corresponding type-specific function instead.
|
#else if CUSTOM_SET_FEATURE
|
||||||
*/
|
import speiger.src.collections.PACKAGE.sets.CUSTOM_HASH_SET;
|
||||||
@Deprecated
|
#else if RB_TREE_SET_FEATURE
|
||||||
@Override
|
import speiger.src.collections.PACKAGE.sets.RB_TREE_SET;
|
||||||
default void forEach(Consumer<? super CLASS_TYPE> action) {
|
#else if AVL_TREE_SET_FEATURE
|
||||||
Objects.requireNonNull(action);
|
import speiger.src.collections.PACKAGE.sets.AVL_TREE_SET;
|
||||||
iterator().forEachRemaining(action);
|
#else if ARRAY_SET_FEATURE
|
||||||
}
|
import speiger.src.collections.PACKAGE.sets.ARRAY_SET;
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
/**
|
#endif
|
||||||
* Helper function to reduce Lambda usage and allow for more method references, since these are faster/cleaner.
|
import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
||||||
* @param input the object that should be included
|
#if ASYNC_MODULE
|
||||||
* @param action The action to be performed for each element
|
import speiger.src.collections.PACKAGE.utils.ASYNC_BUILDER;
|
||||||
* @param <E> the generic type of the Object
|
#endif
|
||||||
* @throws java.lang.NullPointerException if the specified action is null
|
#if SPLIT_ITERATOR_FEATURE
|
||||||
*/
|
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
||||||
default <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
#endif
|
||||||
Objects.requireNonNull(action);
|
import speiger.src.collections.PACKAGE.utils.ITERABLES;
|
||||||
iterator().forEachRemaining(input, action);
|
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
|
||||||
* A Type Specific Type Splititerator to reduce boxing/unboxing
|
import speiger.src.collections.utils.ISizeProvider;
|
||||||
* @return type specific splititerator
|
|
||||||
*/
|
/**
|
||||||
@Override
|
* A Type-Specific {@link Iterable} that reduces (un)boxing
|
||||||
default SPLIT_ITERATOR KEY_GENERIC_TYPE spliterator() { return SPLIT_ITERATORS.createUnknownSplititerator(iterator(), 0); }
|
* @Type(T)
|
||||||
|
*/
|
||||||
/**
|
public interface ITERABLE KEY_GENERIC_TYPE extends Iterable<CLASS_TYPE>
|
||||||
* 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.
|
/**
|
||||||
* @see ASYNC_BUILDER
|
* Returns an iterator over elements of type {@code T}.
|
||||||
* @return a AsyncBuilder
|
*
|
||||||
*/
|
* @return an Iterator.
|
||||||
default ASYNC_BUILDER KEY_GENERIC_TYPE asAsync() {
|
*/
|
||||||
return new ASYNC_BUILDERBRACES(this);
|
@Override
|
||||||
}
|
ITERATOR KEY_GENERIC_TYPE iterator();
|
||||||
|
|
||||||
/**
|
#if !TYPE_OBJECT
|
||||||
* A Helper function to reduce the usage of Streams and allows to convert a Iterable to something else.
|
/**
|
||||||
* @param mapper the mapping function
|
* A Type Specific foreach function that reduces (un)boxing
|
||||||
* @param <E> The return type.
|
*
|
||||||
* @return a new Iterable that returns the desired result
|
* @implSpec
|
||||||
*/
|
* <p>The default implementation behaves as if:
|
||||||
default <E> ObjectIterable<E> map(TO_OBJECT_FUNCTION KKS_GENERIC_TYPE<E> mapper) {
|
* <pre>{@code
|
||||||
return ITERABLES.map(this, mapper);
|
* iterator().forEachRemaining(action);
|
||||||
}
|
* }</pre>
|
||||||
|
*
|
||||||
/**
|
* @param action The action to be performed for each element
|
||||||
* A Helper function to reduce the usage of Streams and allows to convert a Iterable to something else.
|
* @throws NullPointerException if the specified action is null
|
||||||
* @param mapper the flatMapping function
|
* @see Iterable#forEach(Consumer)
|
||||||
* @param <V> The return type supplier.
|
*/
|
||||||
* @param <E> The return type.
|
default void forEach(CONSUMER action) {
|
||||||
* @return a new Iterable that returns the desired result
|
Objects.requireNonNull(action);
|
||||||
*/
|
iterator().forEachRemaining(action);
|
||||||
default <E, V extends Iterable<E>> ObjectIterable<E> flatMap(TO_OBJECT_FUNCTION KKS_GENERIC_TYPE<V> mapper) {
|
}
|
||||||
return ITERABLES.flatMap(this, mapper);
|
|
||||||
}
|
/** {@inheritDoc}
|
||||||
|
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||||
/**
|
* @deprecated Please use the corresponding type-specific function instead.
|
||||||
* A Helper function to reduce the usage of Streams and allows to convert a Iterable to something else.
|
*/
|
||||||
* @param mapper the flatMapping function
|
@Deprecated
|
||||||
* @param <E> The return type.
|
@Override
|
||||||
* @return a new Iterable that returns the desired result
|
default void forEach(Consumer<? super CLASS_TYPE> action) {
|
||||||
*/
|
Objects.requireNonNull(action);
|
||||||
default <E> ObjectIterable<E> arrayflatMap(TO_OBJECT_FUNCTION KKS_GENERIC_TYPE<E[]> mapper) {
|
iterator().forEachRemaining(action);
|
||||||
return ITERABLES.arrayFlatMap(this, mapper);
|
}
|
||||||
}
|
|
||||||
|
#endif
|
||||||
/**
|
/**
|
||||||
* A Helper function to reduce the usage of Streams and allows to filter out unwanted elements
|
* A Indexed forEach implementation that allows you to keep track of how many elements were already iterated over.
|
||||||
* @param filter the elements that should be kept.
|
* @param action The action to be performed for each element
|
||||||
* @return a Iterable that filtered out all unwanted elements
|
* @throws java.lang.NullPointerException if the specified action is null
|
||||||
*/
|
*/
|
||||||
default ITERABLE KEY_GENERIC_TYPE filter(PREDICATE KEY_GENERIC_TYPE filter) {
|
public default void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
|
||||||
return ITERABLES.filter(this, filter);
|
Objects.requireNonNull(action);
|
||||||
}
|
int index = 0;
|
||||||
|
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();action.accept(index++, iter.NEXT()));
|
||||||
/**
|
}
|
||||||
* 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
|
/**
|
||||||
*/
|
* Helper function to reduce Lambda usage and allow for more method references, since these are faster/cleaner.
|
||||||
default ITERABLE KEY_GENERIC_TYPE distinct() {
|
* @param input the object that should be included
|
||||||
return ITERABLES.distinct(this);
|
* @param action The action to be performed for each element
|
||||||
}
|
* @param <E> the generic type of the Object
|
||||||
|
* @throws java.lang.NullPointerException if the specified action is null
|
||||||
/**
|
*/
|
||||||
* A Helper function to reduce the usage of Streams and allows to limit the amount of elements
|
default <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
||||||
* @param limit the amount of elements it should be limited to
|
Objects.requireNonNull(action);
|
||||||
* @return a Iterable that is limited in length
|
iterator().forEachRemaining(input, action);
|
||||||
*/
|
}
|
||||||
default ITERABLE KEY_GENERIC_TYPE limit(long limit) {
|
|
||||||
return ITERABLES.limit(this, limit);
|
#if SPLIT_ITERATOR_FEATURE
|
||||||
}
|
/**
|
||||||
|
* A Type Specific Type Splititerator to reduce boxing/unboxing
|
||||||
/**
|
* @return type specific splititerator
|
||||||
* A Helper function to reduce the usage of Streams and allows to preview elements before they are iterated through
|
*/
|
||||||
* @param action the action that should be applied
|
@Override
|
||||||
* @return a Peeked Iterable
|
default SPLIT_ITERATOR KEY_GENERIC_TYPE spliterator() { return SPLIT_ITERATORS.createUnknownSplititerator(iterator(), 0); }
|
||||||
*/
|
|
||||||
default ITERABLE KEY_GENERIC_TYPE peek(CONSUMER KEY_GENERIC_TYPE action) {
|
#endif
|
||||||
return ITERABLES.peek(this, action);
|
#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.
|
||||||
* A Helper function to reduce the usage of Streams and allows to collect all elements
|
* @see ASYNC_BUILDER
|
||||||
* @param collection that the elements should be inserted to
|
* @return a AsyncBuilder
|
||||||
* @param <E> the collection type
|
*/
|
||||||
* @return the input with the desired elements
|
default ASYNC_BUILDER KEY_GENERIC_TYPE asAsync() {
|
||||||
*/
|
return new ASYNC_BUILDERBRACES(this);
|
||||||
default <E extends COLLECTION KEY_GENERIC_TYPE> E pour(E collection) {
|
}
|
||||||
ITERATORS.pour(iterator(), collection);
|
|
||||||
return collection;
|
#endif
|
||||||
}
|
/**
|
||||||
|
* A Helper function to reduce the usage of Streams and allows to convert a Iterable to something else.
|
||||||
/**
|
* @param mapper the mapping function
|
||||||
* A Helper function that reduces the usage of streams and allows to collect all elements as a ArrayList
|
* @param <E> The return type.
|
||||||
* @return a new ArrayList of all elements
|
* @return a new Iterable that returns the desired result
|
||||||
*/
|
*/
|
||||||
default LIST KEY_GENERIC_TYPE pourAsList() {
|
default <E> ObjectIterable<E> map(TO_OBJECT_FUNCTION KKS_GENERIC_TYPE<E> mapper) {
|
||||||
return pour(new ARRAY_LISTBRACES());
|
return ITERABLES.map(this, mapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !TYPE_BOOLEAN
|
#if TYPE_OBJECT
|
||||||
/**
|
#iterate
|
||||||
* A Helper function that reduces the usage of streams and allows to collect all elements as a LinkedHashSet
|
#argument OUTPUT_ITERABLE BooleanIterable ByteIterable ShortIterable IntIterable LongIterable FloatIterable DoubleIterable
|
||||||
* @return a new LinkedHashSet of all elements
|
#argument MAPPER Predicate ToByteFunction ToShortFunction ToIntFunction ToLongFunction ToFloatFunction ToDoubleFunction
|
||||||
*/
|
#argument DATA_TYPE Boolean Byte Short Int Long Float Double
|
||||||
default SET KEY_GENERIC_TYPE pourAsSet() {
|
#argument FILTER_TYPE BOOLEAN_COLLECTION_MODULE BYTE_COLLECTION_MODULE SHORT_COLLECTION_MODULE INT_COLLECTION_MODULE LONG_COLLECTION_MODULE FLOAT_COLLECTION_MODULE DOUBLE_COLLECTION_MODULE
|
||||||
return pour(new LINKED_HASH_SETBRACES());
|
#if FILTER_TYPE
|
||||||
}
|
/**
|
||||||
|
* A Helper function to reduce the usage of Streams and allows to convert a Iterable to something else.
|
||||||
#endif
|
* @param mapper the mapping function
|
||||||
/**
|
* @return a new Iterable that returns the desired result
|
||||||
* Helper function to reduce stream usage that allows to filter for any matches.
|
*/
|
||||||
* @param filter that should be applied
|
default OUTPUT_ITERABLE mapToDATA_TYPE(MAPPER<T> mapper) {
|
||||||
* @return true if any matches were found
|
return ITERABLES.mapToDATA_TYPE(this, mapper);
|
||||||
*/
|
}
|
||||||
default boolean matchesAny(PREDICATE KEY_GENERIC_TYPE filter) {
|
|
||||||
Objects.requireNonNull(filter);
|
#endif
|
||||||
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
#enditerate
|
||||||
if(filter.TEST_VALUE(iter.NEXT())) return true;
|
#endif
|
||||||
}
|
/**
|
||||||
return false;
|
* 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.
|
||||||
* Helper function to reduce stream usage that allows to filter for no matches.
|
* @return a new Iterable that returns the desired result
|
||||||
* @param filter that should be applied
|
* @note does not support TO_ARRAY optimizations.
|
||||||
* @return true if no matches were found
|
*/
|
||||||
*/
|
default <E, V extends Iterable<E>> ObjectIterable<E> flatMap(TO_OBJECT_FUNCTION KKS_GENERIC_TYPE<V> mapper) {
|
||||||
default boolean matchesNone(PREDICATE KEY_GENERIC_TYPE filter) {
|
return ITERABLES.flatMap(this, mapper);
|
||||||
Objects.requireNonNull(filter);
|
}
|
||||||
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
|
||||||
if(filter.TEST_VALUE(iter.NEXT())) return false;
|
/**
|
||||||
}
|
* A Helper function to reduce the usage of Streams and allows to convert a Iterable to something else.
|
||||||
return true;
|
* @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.
|
||||||
* Helper function to reduce stream usage that allows to filter for all matches.
|
*/
|
||||||
* @param filter that should be applied
|
default <E> ObjectIterable<E> arrayflatMap(TO_OBJECT_FUNCTION KKS_GENERIC_TYPE<E[]> mapper) {
|
||||||
* @return true if all matches.
|
return ITERABLES.arrayFlatMap(this, mapper);
|
||||||
*/
|
}
|
||||||
default boolean matchesAll(PREDICATE KEY_GENERIC_TYPE filter) {
|
|
||||||
Objects.requireNonNull(filter);
|
/**
|
||||||
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
* A Helper function to reduce the usage of Streams and allows to filter out unwanted elements
|
||||||
if(!filter.TEST_VALUE(iter.NEXT())) return false;
|
* @param filter the elements that should be kept.
|
||||||
}
|
* @return a Iterable that filtered out all unwanted elements
|
||||||
return true;
|
* @note does not support TO_ARRAY optimizations.
|
||||||
}
|
*/
|
||||||
|
default ITERABLE KEY_GENERIC_TYPE filter(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
/**
|
return ITERABLES.filter(this, filter);
|
||||||
* Helper function to reduce stream usage that allows to filter for the first match.
|
}
|
||||||
* @param filter that should be applied
|
|
||||||
* @return the found value or the null equivalent variant.
|
/**
|
||||||
*/
|
* A Helper function to reduce the usage of Streams and allows to filter out duplicated elements
|
||||||
default KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
* @return a Iterable that filtered out all duplicated elements
|
||||||
Objects.requireNonNull(filter);
|
* @note does not support TO_ARRAY optimizations.
|
||||||
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
*/
|
||||||
KEY_TYPE entry = iter.NEXT();
|
default ITERABLE KEY_GENERIC_TYPE distinct() {
|
||||||
if(filter.TEST_VALUE(entry)) return entry;
|
return ITERABLES.distinct(this);
|
||||||
}
|
}
|
||||||
return EMPTY_VALUE;
|
|
||||||
}
|
/**
|
||||||
|
* A Helper function to reduce the usage of Streams and allows to repeat elements a desired amount of times
|
||||||
#if !TYPE_OBJECT
|
* @param repeats how many times the elements should be repeated
|
||||||
/**
|
* @return a Iterable that is repeating multiple times
|
||||||
* Performs a <a href="package-summary.html#Reduction">reduction</a> on the
|
*/
|
||||||
* elements of this Iterable
|
default ITERABLE KEY_GENERIC_TYPE repeat(int repeats) {
|
||||||
* @param operator the operation that should be applied
|
return ITERABLES.repeat(this, repeats);
|
||||||
* @param identity the start value
|
}
|
||||||
* @return the reduction result, returns identity if nothing was found
|
|
||||||
*/
|
/**
|
||||||
default KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
* A Helper function to reduce the usage of Streams and allows to limit the amount of elements
|
||||||
Objects.requireNonNull(operator);
|
* @param limit the amount of elements it should be limited to
|
||||||
KEY_TYPE state = identity;
|
* @return a Iterable that is limited in length
|
||||||
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
*/
|
||||||
state = operator.APPLY_VALUE(state, iter.NEXT());
|
default ITERABLE KEY_GENERIC_TYPE limit(long limit) {
|
||||||
}
|
return ITERABLES.limit(this, limit);
|
||||||
return state;
|
}
|
||||||
}
|
|
||||||
|
/**
|
||||||
#else
|
* A Helper function to reduce the usage of Streams and allows to sort the elements
|
||||||
/**
|
* @param sorter that sorts the elements.
|
||||||
* Performs a <a href="package-summary.html#Reduction">reduction</a> on the
|
* @return a Iterable that is sorted
|
||||||
* elements of this Iterable
|
*/
|
||||||
* @param operator the operation that should be applied
|
default ITERABLE KEY_GENERIC_TYPE sorted(COMPARATOR KEY_GENERIC_TYPE sorter) {
|
||||||
* @param identity the start value
|
return ITERABLES.sorted(this, sorter);
|
||||||
* @Type(E)
|
}
|
||||||
* @return the reduction result, returns identity if nothing was found
|
|
||||||
*/
|
/**
|
||||||
default <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
|
* A Helper function to reduce the usage of Streams and allows to preview elements before they are iterated through
|
||||||
Objects.requireNonNull(operator);
|
* @param action the action that should be applied
|
||||||
KEY_SPECIAL_TYPE state = identity;
|
* @return a Peeked Iterable
|
||||||
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
*/
|
||||||
state = operator.APPLY_VALUE(state, iter.NEXT());
|
default ITERABLE KEY_GENERIC_TYPE peek(CONSUMER KEY_GENERIC_TYPE action) {
|
||||||
}
|
return ITERABLES.peek(this, action);
|
||||||
return state;
|
}
|
||||||
}
|
|
||||||
|
/**
|
||||||
#endif
|
* A Helper function to reduce the usage of Streams and allows to collect all elements
|
||||||
/**
|
* @param collection that the elements should be inserted to
|
||||||
* Performs a <a href="package-summary.html#Reduction">reduction</a> on the
|
* @param <E> the collection type
|
||||||
* elements of this Iterable
|
* @return the input with the desired elements
|
||||||
* @param operator the operation that should be applied
|
*/
|
||||||
* @return the reduction result, returns null value if nothing was found
|
default <E extends COLLECTION KEY_GENERIC_TYPE> E pour(E collection) {
|
||||||
*/
|
ITERATORS.pour(iterator(), collection);
|
||||||
default KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
return collection;
|
||||||
Objects.requireNonNull(operator);
|
}
|
||||||
KEY_TYPE state = EMPTY_VALUE;
|
|
||||||
boolean empty = true;
|
#if ARRAY_LIST_FEATURE || LINKED_LIST_FEATURE
|
||||||
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
/**
|
||||||
if(empty) {
|
* A Helper function that reduces the usage of streams and allows to collect all elements as a ArrayList
|
||||||
empty = false;
|
* @return a new ArrayList of all elements
|
||||||
state = iter.NEXT();
|
*/
|
||||||
continue;
|
default LIST KEY_GENERIC_TYPE pourAsList() {
|
||||||
}
|
#if ARRAY_LIST_FEATURE
|
||||||
state = operator.APPLY_VALUE(state, iter.NEXT());
|
return pour(new ARRAY_LISTBRACES());
|
||||||
}
|
#else
|
||||||
return state;
|
return pour(new LINKED_LISTBRACES());
|
||||||
}
|
#endif
|
||||||
|
}
|
||||||
/**
|
|
||||||
* Helper function to reduce stream usage that allows to count the valid elements.
|
#endif
|
||||||
* @param filter that should be applied
|
#if !TYPE_BOOLEAN && SET_MODULE
|
||||||
* @return the amount of Valid Elements
|
#if LINKED_SET_FEATURE || LINKED_CUSTOM_SET_FEATURE || SET_FEATURE || CUSTOM_SET_FEATURE || RB_TREE_SET_FEATURE || AVL_TREE_SET_FEATURE || ARRAY_SET_FEATURE
|
||||||
*/
|
/**
|
||||||
default int count(PREDICATE KEY_GENERIC_TYPE filter) {
|
* A Helper function that reduces the usage of streams and allows to collect all elements as a LinkedHashSet
|
||||||
Objects.requireNonNull(filter);
|
* @return a new LinkedHashSet of all elements
|
||||||
int result = 0;
|
*/
|
||||||
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
default SET KEY_GENERIC_TYPE pourAsSet() {
|
||||||
if(filter.TEST_VALUE(iter.NEXT())) result++;
|
#if LINKED_SET_FEATURE
|
||||||
}
|
return pour(new LINKED_HASH_SETBRACES());
|
||||||
return result;
|
#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
|
||||||
|
/**
|
||||||
|
* Helper function to reduce stream usage that allows to filter for any matches.
|
||||||
|
* @param filter that should be applied
|
||||||
|
* @return true if any matches were found
|
||||||
|
*/
|
||||||
|
default boolean matchesAny(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
|
Objects.requireNonNull(filter);
|
||||||
|
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
||||||
|
if(filter.test(iter.NEXT())) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper function to reduce stream usage that allows to filter for no matches.
|
||||||
|
* @param filter that should be applied
|
||||||
|
* @return true if no matches were found
|
||||||
|
*/
|
||||||
|
default boolean matchesNone(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
|
Objects.requireNonNull(filter);
|
||||||
|
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
||||||
|
if(filter.test(iter.NEXT())) return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper function to reduce stream usage that allows to filter for all matches.
|
||||||
|
* @param filter that should be applied
|
||||||
|
* @return true if all matches.
|
||||||
|
*/
|
||||||
|
default boolean matchesAll(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
|
Objects.requireNonNull(filter);
|
||||||
|
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
||||||
|
if(!filter.test(iter.NEXT())) return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper function to reduce stream usage that allows to filter for the first match.
|
||||||
|
* @param filter that should be applied
|
||||||
|
* @return the found value or the null equivalent variant.
|
||||||
|
*/
|
||||||
|
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(entry)) return OPTIONAL.GET_OPTIONAL(entry);
|
||||||
|
}
|
||||||
|
return OPTIONAL.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
/**
|
||||||
|
* Performs a <a href="package-summary.html#Reduction">reduction</a> on the
|
||||||
|
* elements of this Iterable
|
||||||
|
* @param operator the operation that should be applied
|
||||||
|
* @param identity the start value
|
||||||
|
* @return the reduction result, returns identity if nothing was found
|
||||||
|
*/
|
||||||
|
default KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_TYPE state = identity;
|
||||||
|
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
||||||
|
state = operator.APPLY_VALUE(state, iter.NEXT());
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
/**
|
||||||
|
* Performs a <a href="package-summary.html#Reduction">reduction</a> on the
|
||||||
|
* elements of this Iterable
|
||||||
|
* @param operator the operation that should be applied
|
||||||
|
* @param identity the start value
|
||||||
|
* @Type(E)
|
||||||
|
* @return the reduction result, returns identity if nothing was found
|
||||||
|
*/
|
||||||
|
default <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_SPECIAL_TYPE state = identity;
|
||||||
|
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
||||||
|
state = operator.APPLY_VALUE(state, iter.NEXT());
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
/**
|
||||||
|
* Performs a <a href="package-summary.html#Reduction">reduction</a> on the
|
||||||
|
* elements of this Iterable
|
||||||
|
* @param operator the operation that should be applied
|
||||||
|
* @return the reduction result, returns null value if nothing was found
|
||||||
|
*/
|
||||||
|
default OPTIONAL KEY_GENERIC_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_TYPE state = EMPTY_VALUE;
|
||||||
|
boolean empty = true;
|
||||||
|
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
||||||
|
if(empty) {
|
||||||
|
empty = false;
|
||||||
|
state = iter.NEXT();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
state = operator.APPLY_VALUE(state, iter.NEXT());
|
||||||
|
}
|
||||||
|
return empty ? OPTIONAL.empty() : OPTIONAL.GET_OPTIONAL(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper function to reduce stream usage that allows to count the valid elements.
|
||||||
|
* @param filter that should be applied
|
||||||
|
* @return the amount of Valid Elements
|
||||||
|
*/
|
||||||
|
default int count(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
|
Objects.requireNonNull(filter);
|
||||||
|
int result = 0;
|
||||||
|
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
||||||
|
if(filter.test(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;
|
package speiger.src.collections.PACKAGE.collections;
|
||||||
|
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
|
|
||||||
import speiger.src.collections.utils.Stack;
|
import speiger.src.collections.utils.Stack;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -14,6 +16,14 @@ public interface STACK
|
|||||||
*/
|
*/
|
||||||
public void push(KEY_TYPE e);
|
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.
|
* Removes the Object on top of the stack.
|
||||||
* @return the element that is 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() {
|
public default boolean isEmpty() {
|
||||||
return size() == 0;
|
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);
|
||||||
}
|
}
|
||||||
+69
-69
@@ -1,70 +1,70 @@
|
|||||||
package speiger.src.collections.PACKAGE.functions;
|
package speiger.src.collections.PACKAGE.functions;
|
||||||
|
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Type-Specific Class for Comparator to reduce (un)boxing
|
* Type-Specific Class for Comparator to reduce (un)boxing
|
||||||
*/
|
*/
|
||||||
public interface COMPARATOR extends Comparator<CLASS_TYPE>
|
public interface COMPARATOR extends Comparator<CLASS_TYPE>
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Type-Specific compare function to reduce (un)boxing
|
* Type-Specific compare function to reduce (un)boxing
|
||||||
* @param o1 the first object to be compared.
|
* @param o1 the first object to be compared.
|
||||||
* @param o2 the second object to be compared.
|
* @param o2 the second object to be compared.
|
||||||
* @return a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.
|
* @return a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.
|
||||||
* @see Comparator#compare(Object, Object)
|
* @see Comparator#compare(Object, Object)
|
||||||
*/
|
*/
|
||||||
int compare(KEY_TYPE o1, KEY_TYPE o2);
|
int compare(KEY_TYPE o1, KEY_TYPE o2);
|
||||||
|
|
||||||
/** {@inheritDoc}
|
/** {@inheritDoc}
|
||||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||||
* @deprecated Please use the corresponding type-specific function instead.
|
* @deprecated Please use the corresponding type-specific function instead.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
@Deprecated
|
||||||
default int compare(CLASS_TYPE o1, CLASS_TYPE o2) {
|
default int compare(CLASS_TYPE o1, CLASS_TYPE o2) {
|
||||||
return compare(OBJ_TO_KEY(o1), OBJ_TO_KEY(o2));
|
return compare(OBJ_TO_KEY(o1), OBJ_TO_KEY(o2));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Wrapper function to convert a Non-Type-Specific Comparator to a Type-Specific-Comparator
|
* A Wrapper function to convert a Non-Type-Specific Comparator to a Type-Specific-Comparator
|
||||||
* @param c comparator to convert
|
* @param c comparator to convert
|
||||||
* @return the wrapper of the comparator
|
* @return the wrapper of the comparator
|
||||||
* @throws NullPointerException if the comparator is null
|
* @throws NullPointerException if the comparator is null
|
||||||
*/
|
*/
|
||||||
public static COMPARATOR of(Comparator<CLASS_TYPE> c) {
|
public static COMPARATOR of(Comparator<CLASS_TYPE> c) {
|
||||||
Objects.requireNonNull(c);
|
Objects.requireNonNull(c);
|
||||||
return (K, V) -> c.compare(KEY_TO_OBJ(K), KEY_TO_OBJ(V));
|
return (K, V) -> c.compare(KEY_TO_OBJ(K), KEY_TO_OBJ(V));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public default COMPARATOR reversed() {
|
public default COMPARATOR reversed() {
|
||||||
return new Reversed(this);
|
return new Reversed(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Type Specific Reversed Comparator to reduce boxing/unboxing
|
* A Type Specific Reversed Comparator to reduce boxing/unboxing
|
||||||
*/
|
*/
|
||||||
static class Reversed implements COMPARATOR
|
static class Reversed implements COMPARATOR
|
||||||
{
|
{
|
||||||
COMPARATOR original;
|
COMPARATOR original;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* default constructor
|
* default constructor
|
||||||
* @param original that is going to be reversed
|
* @param original that is going to be reversed
|
||||||
*/
|
*/
|
||||||
public Reversed(COMPARATOR original) {
|
public Reversed(COMPARATOR original) {
|
||||||
this.original = original;
|
this.original = original;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int compare(KEY_TYPE o1, KEY_TYPE o2) {
|
public int compare(KEY_TYPE o1, KEY_TYPE o2) {
|
||||||
return original.compare(o2, o1);
|
return original.compare(o2, o1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public COMPARATOR reversed() {
|
public COMPARATOR reversed() {
|
||||||
return original;
|
return original;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+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";
|
||||||
|
}
|
||||||
|
}
|
||||||
+18
-25
@@ -1,26 +1,19 @@
|
|||||||
package speiger.src.collections.PACKAGE.functions;
|
package speiger.src.collections.PACKAGE.functions;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Type-Specific Supplier interface that reduces (un)boxing and allows to merge other consumer types into this interface
|
* Type-Specific Supplier interface that reduces (un)boxing and allows to merge other consumer types into this interface
|
||||||
* @Type(T)
|
* @Type(T)
|
||||||
*/
|
*/
|
||||||
#if TYPE_OBJECT
|
#if TYPE_OBJECT
|
||||||
public interface SUPPLIER KEY_GENERIC_TYPE extends java.util.function.Supplier<KEY_TYPE>
|
public interface SUPPLIER KEY_GENERIC_TYPE extends java.util.function.Supplier<KEY_TYPE>
|
||||||
#else if JDK_TYPE && !TYPE_BOOLEAN
|
#else if JDK_TYPE && !TYPE_BOOLEAN
|
||||||
public interface SUPPLIER KEY_GENERIC_TYPE extends JAVA_SUPPLIER
|
public interface SUPPLIER KEY_GENERIC_TYPE extends JAVA_SUPPLIER
|
||||||
#else
|
#else
|
||||||
public interface SUPPLIER KEY_GENERIC_TYPE
|
public interface SUPPLIER KEY_GENERIC_TYPE
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @return the supplied value
|
* @return the supplied value
|
||||||
*/
|
*/
|
||||||
public KEY_TYPE GET_KEY();
|
public KEY_TYPE SUPPLY_GET();
|
||||||
#if JDK_TYPE && PRIMITIVES
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public default KEY_TYPE GET_JAVA() {
|
|
||||||
return GET_KEY();
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
+91
-91
@@ -1,92 +1,92 @@
|
|||||||
package speiger.src.collections.PACKAGE.functions;
|
package speiger.src.collections.PACKAGE.functions;
|
||||||
|
|
||||||
import java.util.concurrent.RunnableFuture;
|
import java.util.concurrent.RunnableFuture;
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
import java.util.concurrent.CancellationException;
|
import java.util.concurrent.CancellationException;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* A Type Specific Task interface that allows you to keep track of the task that is currently running.<br>
|
* A Type Specific Task interface that allows you to keep track of the task that is currently running.<br>
|
||||||
* It extends Runnable future and supports said functions but also provides quality of life functions like:<br>
|
* It extends Runnable future and supports said functions but also provides quality of life functions like:<br>
|
||||||
*
|
*
|
||||||
* - isSuccesfull: which allows to detect if the task was completed properly and not interrupted or crashed.
|
* - isSuccesfull: which allows to detect if the task was completed properly and not interrupted or crashed.
|
||||||
* - pause/resume: which allows to pause/resume the task at any moment, making it easier to create thread-safe actions.
|
* - pause/resume: which allows to pause/resume the task at any moment, making it easier to create thread-safe actions.
|
||||||
* @Type(T)
|
* @Type(T)
|
||||||
*/
|
*/
|
||||||
public interface TASK KEY_GENERIC_TYPE extends RunnableFuture<CLASS_TYPE> {
|
public interface TASK KEY_GENERIC_TYPE extends RunnableFuture<CLASS_TYPE> {
|
||||||
/**
|
/**
|
||||||
* Helper function to detect if the task is currently paused.
|
* Helper function to detect if the task is currently paused.
|
||||||
* @return true if paused
|
* @return true if paused
|
||||||
*/
|
*/
|
||||||
public boolean isPaused();
|
public boolean isPaused();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pauses the task, which lets the thread finish without completing the task.
|
* Pauses the task, which lets the thread finish without completing the task.
|
||||||
* Tasks are written in the way where they can pause without any issues.
|
* Tasks are written in the way where they can pause without any issues.
|
||||||
* This won't be instant, as this function is applied asynchronous and doesn't check if the thread paused.
|
* This won't be instant, as this function is applied asynchronous and doesn't check if the thread paused.
|
||||||
* So make sure it had the time to pause.
|
* So make sure it had the time to pause.
|
||||||
*/
|
*/
|
||||||
public void pause();
|
public void pause();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pauses the task, which lets the thread finish without completing the task.
|
* Pauses the task, which lets the thread finish without completing the task.
|
||||||
* Tasks are written in the way where they can pause without any issues.
|
* Tasks are written in the way where they can pause without any issues.
|
||||||
* This won't be instant, as this function is applied asynchronous.
|
* This won't be instant, as this function is applied asynchronous.
|
||||||
* It will await the pausing of the task.
|
* It will await the pausing of the task.
|
||||||
*/
|
*/
|
||||||
public void awaitPausing();
|
public void awaitPausing();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Continues the task if it wasn't already completed.
|
* Continues the task if it wasn't already completed.
|
||||||
* This is done by resubmitting the task to the executor provided.
|
* This is done by resubmitting the task to the executor provided.
|
||||||
*/
|
*/
|
||||||
public void resume();
|
public void resume();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Quality of life function that allows to detect if no cancellation/exception was applied to this task and it completed on its own.
|
* Quality of life function that allows to detect if no cancellation/exception was applied to this task and it completed on its own.
|
||||||
* @return true if it was properly completed
|
* @return true if it was properly completed
|
||||||
*/
|
*/
|
||||||
public boolean isSuccessful();
|
public boolean isSuccessful();
|
||||||
|
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
/**
|
/**
|
||||||
* A Type Specific get method that allows to reduce (un)boxing of primtives.
|
* A Type Specific get method that allows to reduce (un)boxing of primtives.
|
||||||
*
|
*
|
||||||
* Waits if necessary for the computation to complete, and then
|
* Waits if necessary for the computation to complete, and then
|
||||||
* retrieves its result.
|
* retrieves its result.
|
||||||
*
|
*
|
||||||
* @return the computed result as primitive
|
* @return the computed result as primitive
|
||||||
* @throws CancellationException if the computation was cancelled
|
* @throws CancellationException if the computation was cancelled
|
||||||
* @throws ExecutionException if the computation threw an exception
|
* @throws ExecutionException if the computation threw an exception
|
||||||
* @throws InterruptedException if the current thread was interrupted
|
* @throws InterruptedException if the current thread was interrupted
|
||||||
* while waiting
|
* while waiting
|
||||||
*/
|
*/
|
||||||
public KEY_TYPE GET_KEY() throws InterruptedException, ExecutionException;
|
public KEY_TYPE GET_KEY() throws InterruptedException, ExecutionException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Waits if necessary for at most the given time for the computation
|
* Waits if necessary for at most the given time for the computation
|
||||||
* to complete, and then retrieves its result, if available.
|
* to complete, and then retrieves its result, if available.
|
||||||
*
|
*
|
||||||
* @param timeout the maximum time to wait
|
* @param timeout the maximum time to wait
|
||||||
* @param unit the time unit of the timeout argument
|
* @param unit the time unit of the timeout argument
|
||||||
* @return the computed result as primitive
|
* @return the computed result as primitive
|
||||||
* @throws CancellationException if the computation was cancelled
|
* @throws CancellationException if the computation was cancelled
|
||||||
* @throws ExecutionException if the computation threw an exception
|
* @throws ExecutionException if the computation threw an exception
|
||||||
* @throws InterruptedException if the current thread was interrupted while waiting
|
* @throws InterruptedException if the current thread was interrupted while waiting
|
||||||
* @throws TimeoutException if the wait timed out
|
* @throws TimeoutException if the wait timed out
|
||||||
*/
|
*/
|
||||||
public KEY_TYPE GET_KEY(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException;
|
public KEY_TYPE GET_KEY(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public default CLASS_TYPE get() throws InterruptedException, ExecutionException { return KEY_TO_OBJ(GET_KEY()); }
|
public default CLASS_TYPE get() throws InterruptedException, ExecutionException { return KEY_TO_OBJ(GET_KEY()); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public default CLASS_TYPE get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { return KEY_TO_OBJ(GET_KEY(timeout, unit)); }
|
public default CLASS_TYPE get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { return KEY_TO_OBJ(GET_KEY(timeout, unit)); }
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
+133
-78
@@ -1,79 +1,134 @@
|
|||||||
package speiger.src.collections.PACKAGE.functions.function;
|
package speiger.src.collections.PACKAGE.functions.function;
|
||||||
|
|
||||||
#if JDK_FUNCTION && VALUE_BOOLEAN
|
#if VALUE_BOOLEAN || SAME_TYPE
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Type Specific Function interface that reduces boxing/unboxing and fills the gaps of interfaces that are missing.
|
* A Type Specific Function interface that reduces boxing/unboxing and fills the gaps of interfaces that are missing.
|
||||||
* @Type(T)
|
* @Type(T)
|
||||||
* @ValueType(V)
|
* @ValueType(V)
|
||||||
*/
|
*/
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
#if JDK_FUNCTION
|
#if JDK_FUNCTION
|
||||||
public interface FUNCTION KEY_VALUE_GENERIC_TYPE extends JAVA_FUNCTION KEY_VALUE_GENERIC_TYPE
|
public interface FUNCTION KEY_VALUE_GENERIC_TYPE extends JAVA_FUNCTION KEY_VALUE_GENERIC_TYPE
|
||||||
#else
|
#else
|
||||||
public interface FUNCTION KEY_VALUE_GENERIC_TYPE
|
public interface FUNCTION KEY_VALUE_GENERIC_TYPE
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Type Specific get function to reduce boxing/unboxing
|
* Type Specific get function to reduce boxing/unboxing
|
||||||
* @param k the value that should be processed
|
* @param k the value that should be processed
|
||||||
* @return the result of the function
|
* @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
|
||||||
#if VALUE_BOOLEAN
|
/**
|
||||||
@Override
|
* Creates a Default function that returns the input provided.
|
||||||
public default VALUE_TYPE test(KEY_TYPE k) { return GET_VALUE(k); }
|
* @Type(T)
|
||||||
|
* @return a input returning function
|
||||||
/**
|
*/
|
||||||
* A Type specific and-function helper function that reduces boxing/unboxing
|
public static GENERIC_KEY_BRACES FUNCTION KEY_SAME_GENERIC_TYPE identity() {
|
||||||
* @param other the other function that should be merged with.
|
return T -> T;
|
||||||
* @return a function that compares values in a and comparason
|
}
|
||||||
*/
|
|
||||||
public default FUNCTION KEY_VALUE_GENERIC_TYPE andType(FUNCTION KEY_VALUE_GENERIC_TYPE other) {
|
/**
|
||||||
Objects.requireNonNull(other);
|
* Returns a composed function that first applies the {@code before}
|
||||||
return T -> GET_VALUE(T) && other.GET_VALUE(T);
|
* 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.
|
||||||
@Override
|
*
|
||||||
@Deprecated
|
* @Type(I)
|
||||||
public default FUNCTION KEY_VALUE_GENERIC_TYPE and(JAVA_FUNCTION KEY_VALUE_SUPER_GENERIC_TYPE other) {
|
* @param before the function that should be used first
|
||||||
Objects.requireNonNull(other);
|
* @return a composed function with a different starting function.
|
||||||
return T -> GET_VALUE(T) && other.test(T);
|
*/
|
||||||
}
|
public default GENERIC_SPECIAL_VALUE_BRACES<I> FUNCTION SV_GENERIC_TYPE<I> compose(FUNCTION SK_GENERIC_TYPE<I> before) {
|
||||||
|
Objects.requireNonNull(before);
|
||||||
@Override
|
return T -> APPLY(before.APPLY(T));
|
||||||
public default FUNCTION KEY_VALUE_GENERIC_TYPE negate() {
|
}
|
||||||
return T -> !GET_VALUE(T);
|
|
||||||
}
|
/**
|
||||||
|
* Returns a composed function that first applies this function to
|
||||||
/**
|
* its input, and then applies the {@code after} function to the result.
|
||||||
* A Type specific or-function helper function that reduces boxing/unboxing
|
* If evaluation of either function throws an exception, it is relayed to
|
||||||
* @param other the other function that should be merged with.
|
* the caller of the composed function.
|
||||||
* @return a function that compares values in a or comparason
|
*
|
||||||
*/
|
* @Type(I)
|
||||||
public default FUNCTION KEY_VALUE_GENERIC_TYPE orType(FUNCTION KEY_VALUE_GENERIC_TYPE other) {
|
* @param after the function that should be used last
|
||||||
Objects.requireNonNull(other);
|
* @return a composed function with a different starting function.
|
||||||
return T -> GET_VALUE(T) || other.GET_VALUE(T);
|
*/
|
||||||
}
|
public default GENERIC_SPECIAL_VALUE_BRACES<I> FUNCTION KS_GENERIC_TYPE<I> andThen(FUNCTION VS_GENERIC_TYPE<I> after) {
|
||||||
|
Objects.requireNonNull(after);
|
||||||
@Override
|
return T -> after.APPLY(APPLY(T));
|
||||||
@Deprecated
|
}
|
||||||
public default FUNCTION KEY_VALUE_GENERIC_TYPE or(JAVA_FUNCTION KEY_VALUE_SUPER_GENERIC_TYPE other) {
|
|
||||||
Objects.requireNonNull(other);
|
#endif
|
||||||
return T -> GET_VALUE(T) || other.test(T);
|
#if VALUE_BOOLEAN
|
||||||
}
|
/**
|
||||||
#else if VALUE_OBJECT
|
* Creates a Always true function that may be useful if you don't need to process information or just want a default.
|
||||||
|
* @Type(T)
|
||||||
@Override
|
* @return a default returning function
|
||||||
public default VALUE_TYPE apply(KEY_TYPE k) { return GET_VALUE(k); }
|
*/
|
||||||
#else
|
public static GENERIC_KEY_BRACES FUNCTION KEY_GENERIC_TYPE alwaysTrue() {
|
||||||
|
return T -> true;
|
||||||
@Override
|
}
|
||||||
public default VALUE_TYPE APPLY_VALUE(KEY_TYPE k) { return GET_VALUE(k); }
|
|
||||||
#endif
|
/**
|
||||||
#endif
|
* 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
|
||||||
|
* @param other the other function that should be merged with.
|
||||||
|
* @return a function that compares values in a and comparason
|
||||||
|
*/
|
||||||
|
public default FUNCTION KEY_VALUE_GENERIC_TYPE andType(FUNCTION KEY_VALUE_GENERIC_TYPE other) {
|
||||||
|
Objects.requireNonNull(other);
|
||||||
|
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 -> 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 -> !APPLY(T);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Type specific or-function helper function that reduces boxing/unboxing
|
||||||
|
* @param other the other function that should be merged with.
|
||||||
|
* @return a function that compares values in a or comparason
|
||||||
|
*/
|
||||||
|
public default FUNCTION KEY_VALUE_GENERIC_TYPE orType(FUNCTION KEY_VALUE_GENERIC_TYPE other) {
|
||||||
|
Objects.requireNonNull(other);
|
||||||
|
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 -> APPLY(T) || other.APPLY(T);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
+336
-18
@@ -1,16 +1,25 @@
|
|||||||
package speiger.src.collections.PACKAGE.lists;
|
package speiger.src.collections.PACKAGE.lists;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.ListIterator;
|
import java.util.ListIterator;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.RandomAccess;
|
||||||
|
|
||||||
import speiger.src.collections.PACKAGE.collections.ABSTRACT_COLLECTION;
|
import speiger.src.collections.PACKAGE.collections.ABSTRACT_COLLECTION;
|
||||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||||
|
#if SPLIT_ITERATOR_FEATURE
|
||||||
import speiger.src.collections.PACKAGE.collections.SPLIT_ITERATOR;
|
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;
|
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
||||||
|
#endif
|
||||||
import speiger.src.collections.utils.SanityChecks;
|
import speiger.src.collections.utils.SanityChecks;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -66,8 +75,7 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
@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);
|
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);
|
return new SubList(this, 0, fromIndex, toIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LIST KEY_GENERIC_TYPE reversed() {
|
||||||
|
return new ReversedList(this);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ITERATOR KEY_GENERIC_TYPE iterator() {
|
public ITERATOR KEY_GENERIC_TYPE iterator() {
|
||||||
return listIterator(0);
|
return listIterator(0);
|
||||||
@@ -230,13 +243,25 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
|||||||
public LIST_ITERATOR KEY_GENERIC_TYPE listIterator() {
|
public LIST_ITERATOR KEY_GENERIC_TYPE listIterator() {
|
||||||
return listIterator(0);
|
return listIterator(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LIST_ITERATOR KEY_GENERIC_TYPE listIterator(int index) {
|
public LIST_ITERATOR KEY_GENERIC_TYPE listIterator(int index) {
|
||||||
if(index < 0 || index > size()) throw new IndexOutOfBoundsException();
|
if(index < 0 || index > size()) throw new IndexOutOfBoundsException();
|
||||||
return new LIST_ITER(index);
|
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
|
@Override
|
||||||
public void size(int size) {
|
public void size(int size) {
|
||||||
while(size > size()) add(EMPTY_KEY_VALUE);
|
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(); }
|
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
|
private class SubList extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||||
{
|
{
|
||||||
final ABSTRACT_LIST KEY_GENERIC_TYPE list;
|
final ABSTRACT_LIST KEY_GENERIC_TYPE list;
|
||||||
@@ -308,14 +465,14 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
|||||||
public KEY_TYPE[] getElements(int from, KEY_TYPE[] a, int offset, int length) {
|
public KEY_TYPE[] getElements(int from, KEY_TYPE[] a, int offset, int length) {
|
||||||
SanityChecks.checkArrayCapacity(size, from, length);
|
SanityChecks.checkArrayCapacity(size, from, length);
|
||||||
SanityChecks.checkArrayCapacity(a.length, offset, length);
|
SanityChecks.checkArrayCapacity(a.length, offset, length);
|
||||||
return list.getElements(from+this.offset, a, offset, length);
|
return list.getElements(from+parentOffset, a, offset, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeElements(int from, int to) {
|
public void removeElements(int from, int to) {
|
||||||
if(to-from <= 0) return;
|
if(to-from <= 0) return;
|
||||||
checkSubRange(from);
|
checkSubRange(from);
|
||||||
checkSubRange(to);
|
checkAddSubRange(to);
|
||||||
list.removeElements(from+parentOffset, to+parentOffset);
|
list.removeElements(from+parentOffset, to+parentOffset);
|
||||||
size -= to - from;
|
size -= to - from;
|
||||||
}
|
}
|
||||||
@@ -324,9 +481,9 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
|||||||
@Override
|
@Override
|
||||||
public <K> K[] extractElements(int from, int to, Class<K> type) {
|
public <K> K[] extractElements(int from, int to, Class<K> type) {
|
||||||
checkSubRange(from);
|
checkSubRange(from);
|
||||||
checkSubRange(to);
|
checkAddSubRange(to);
|
||||||
K[] result = list.extractElements(from+parentOffset, to+parentOffset, type);
|
K[] result = list.extractElements(from+parentOffset, to+parentOffset, type);
|
||||||
size -= to - from;
|
size -= result.length;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -334,9 +491,9 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
|||||||
@Override
|
@Override
|
||||||
public KEY_TYPE[] extractElements(int from, int to) {
|
public KEY_TYPE[] extractElements(int from, int to) {
|
||||||
checkSubRange(from);
|
checkSubRange(from);
|
||||||
checkSubRange(to);
|
checkAddSubRange(to);
|
||||||
KEY_TYPE[] result = list.extractElements(from+parentOffset, to+parentOffset);
|
KEY_TYPE[] result = list.extractElements(from+parentOffset, to+parentOffset);
|
||||||
size -= to - from;
|
size -= result.length;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -344,19 +501,25 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
|||||||
@Override
|
@Override
|
||||||
public KEY_TYPE GET_KEY(int index) {
|
public KEY_TYPE GET_KEY(int index) {
|
||||||
checkSubRange(index);
|
checkSubRange(index);
|
||||||
return list.GET_KEY(offset+index);
|
return list.GET_KEY(parentOffset+index);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE set(int index, KEY_TYPE element) {
|
public KEY_TYPE set(int index, KEY_TYPE element) {
|
||||||
checkSubRange(index);
|
checkSubRange(index);
|
||||||
return list.set(offset+index, element);
|
return list.set(parentOffset+index, element);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE swapRemove(int index) {
|
public KEY_TYPE swapRemove(int index) {
|
||||||
checkSubRange(index);
|
checkSubRange(index);
|
||||||
KEY_TYPE result = list.swapRemove(index+parentOffset);
|
if(index == size-1) {
|
||||||
|
KEY_TYPE result = list.REMOVE(parentOffset+size-1);
|
||||||
|
size--;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
KEY_TYPE result = list.set(index+parentOffset, list.GET_KEY(parentOffset+size-1));
|
||||||
|
list.REMOVE(parentOffset+size-1);
|
||||||
size--;
|
size--;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -373,9 +536,10 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
|||||||
public int size() {
|
public int size() {
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
#if SPLIT_ITERATOR_FEATURE
|
||||||
@Override
|
@Override
|
||||||
public SPLIT_ITERATOR KEY_GENERIC_TYPE spliterator() { return SPLIT_ITERATORS.createSplititerator(this, 16464); }
|
public SPLIT_ITERATOR KEY_GENERIC_TYPE spliterator() { return SPLIT_ITERATORS.createSplititerator(this, 16464); }
|
||||||
|
#endif
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LIST_ITERATOR KEY_GENERIC_TYPE listIterator(int index) {
|
public LIST_ITERATOR KEY_GENERIC_TYPE listIterator(int index) {
|
||||||
@@ -386,7 +550,7 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
|||||||
@Override
|
@Override
|
||||||
public LIST KEY_GENERIC_TYPE subList(int fromIndex, int toIndex) {
|
public LIST KEY_GENERIC_TYPE subList(int fromIndex, int toIndex) {
|
||||||
SanityChecks.checkArrayCapacity(size, fromIndex, toIndex-fromIndex);
|
SanityChecks.checkArrayCapacity(size, fromIndex, toIndex-fromIndex);
|
||||||
return new SubList(list, offset, fromIndex, toIndex);
|
return new SubList(this, offset, fromIndex, toIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void checkSubRange(int index) {
|
protected void checkSubRange(int index) {
|
||||||
@@ -460,15 +624,17 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void add(KEY_TYPE e) {
|
public void add(KEY_TYPE e) {
|
||||||
list.add(index++, e);
|
list.add(index, e);
|
||||||
|
index++;
|
||||||
lastReturned = -1;
|
lastReturned = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int skip(int amount) {
|
public int skip(int amount) {
|
||||||
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
||||||
int steps = Math.min(amount, (list.size() - 1) - index);
|
int steps = Math.min(amount, size() - index);
|
||||||
index += steps;
|
index += steps;
|
||||||
|
if(steps > 0) lastReturned = Math.min(index-1, size()-1);
|
||||||
return steps;
|
return steps;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -477,11 +643,160 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
|||||||
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
||||||
int steps = Math.min(amount, index);
|
int steps = Math.min(amount, index);
|
||||||
index -= steps;
|
index -= steps;
|
||||||
|
if(steps > 0) lastReturned = Math.min(index, size()-1);
|
||||||
return steps;
|
return steps;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#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 {
|
private class LIST_ITER implements LIST_ITERATOR KEY_GENERIC_TYPE {
|
||||||
int index;
|
int index;
|
||||||
int lastReturned = -1;
|
int lastReturned = -1;
|
||||||
@@ -540,15 +855,17 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void add(KEY_TYPE e) {
|
public void add(KEY_TYPE e) {
|
||||||
ABSTRACT_LIST.this.add(index++, e);
|
ABSTRACT_LIST.this.add(index, e);
|
||||||
|
index++;
|
||||||
lastReturned = -1;
|
lastReturned = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int skip(int amount) {
|
public int skip(int amount) {
|
||||||
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
||||||
int steps = Math.min(amount, (size() - 1) - index);
|
int steps = Math.min(amount, size() - index);
|
||||||
index += steps;
|
index += steps;
|
||||||
|
if(steps > 0) lastReturned = Math.min(index-1, size()-1);
|
||||||
return steps;
|
return steps;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -557,6 +874,7 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
|||||||
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
||||||
int steps = Math.min(amount, index);
|
int steps = Math.min(amount, index);
|
||||||
index -= steps;
|
index -= steps;
|
||||||
|
if(steps > 0) lastReturned = Math.max(index, 0);
|
||||||
return steps;
|
return steps;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1255
-1177
File diff suppressed because it is too large
Load Diff
+2243
-1787
File diff suppressed because it is too large
Load Diff
+81
-16
@@ -3,18 +3,40 @@ package speiger.src.collections.PACKAGE.lists;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
#if TYPE_OBJECT
|
#if TYPE_OBJECT
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
#else if !TYPE_BOOLEAN
|
||||||
|
import java.util.stream.JAVA_STREAM;
|
||||||
|
import java.util.stream.StreamSupport;
|
||||||
#endif
|
#endif
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import java.util.Objects;
|
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
|
#if TYPE_OBJECT
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
#endif
|
#endif
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
import java.util.function.UnaryOperator;
|
import java.util.function.UnaryOperator;
|
||||||
|
#if !TYPE_OBJECT && JDK_FUNCTION
|
||||||
|
import java.util.function.PREDICATE;
|
||||||
|
#endif
|
||||||
#if PRIMITIVES
|
#if PRIMITIVES
|
||||||
|
#if !JDK_FUNCTION
|
||||||
import java.util.function.JAVA_PREDICATE;
|
import java.util.function.JAVA_PREDICATE;
|
||||||
|
#endif
|
||||||
|
|
||||||
import java.util.function.JAVA_UNARY_OPERATOR;
|
import java.util.function.JAVA_UNARY_OPERATOR;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -22,19 +44,22 @@ import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
|||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||||
|
#if !JDK_TYPE
|
||||||
|
import speiger.src.collections.PACKAGE.functions.OPTIONAL;
|
||||||
|
#endif
|
||||||
import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
||||||
#endif
|
#endif
|
||||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||||
|
#if !JDK_FUNCTION
|
||||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||||
|
#endif
|
||||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||||
import speiger.src.collections.objects.utils.ObjectArrays;
|
import speiger.src.collections.objects.utils.ObjectArrays;
|
||||||
import speiger.src.collections.PACKAGE.utils.ITERATORS;
|
import speiger.src.collections.PACKAGE.utils.ITERATORS;
|
||||||
#if PRIMITIVES
|
#if SPLIT_ITERATOR_FEATURE
|
||||||
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.collections.SPLIT_ITERATOR;
|
||||||
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
||||||
|
#endif
|
||||||
import speiger.src.collections.utils.SanityChecks;
|
import speiger.src.collections.utils.SanityChecks;
|
||||||
|
|
||||||
#if TYPE_OBJECT
|
#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);
|
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
|
@Override
|
||||||
public boolean add(KEY_TYPE e) { throw new UnsupportedOperationException(); }
|
public boolean add(KEY_TYPE e) { throw new UnsupportedOperationException(); }
|
||||||
@Override
|
@Override
|
||||||
@@ -129,7 +190,8 @@ public class IMMUTABLE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_T
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE[] getElements(int from, KEY_TYPE[] a, int offset, int length) {
|
public KEY_TYPE[] getElements(int from, KEY_TYPE[] a, int offset, int length) {
|
||||||
SanityChecks.checkArrayCapacity(data.length, offset, length);
|
SanityChecks.checkArrayCapacity(a.length, offset, length);
|
||||||
|
SanityChecks.checkArrayCapacity(data.length, from, length);
|
||||||
System.arraycopy(data, from, a, offset, length);
|
System.arraycopy(data, from, a, offset, length);
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
@@ -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) {
|
public boolean matchesAny(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
for(int i = 0,m=data.length;i<m;i++) {
|
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;
|
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) {
|
public boolean matchesNone(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
for(int i = 0,m=data.length;i<m;i++) {
|
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;
|
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) {
|
public boolean matchesAll(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
for(int i = 0,m=data.length;i<m;i++) {
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
public OPTIONAL KEY_GENERIC_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
for(int i = 0,m=data.length;i<m;i++) {
|
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
|
#if !TYPE_OBJECT
|
||||||
@@ -357,7 +419,7 @@ public class IMMUTABLE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_T
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
@Override
|
@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);
|
Objects.requireNonNull(operator);
|
||||||
KEY_TYPE state = EMPTY_VALUE;
|
KEY_TYPE state = EMPTY_VALUE;
|
||||||
boolean empty = true;
|
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]);
|
state = operator.APPLY_VALUE(state, data[i]);
|
||||||
}
|
}
|
||||||
return state;
|
return empty ? OPTIONAL.empty() : OPTIONAL.GET_OPTIONAL(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -377,7 +439,7 @@ public class IMMUTABLE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_T
|
|||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
int result = 0;
|
int result = 0;
|
||||||
for(int i = 0,m=data.length;i<m;i++) {
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -436,6 +498,7 @@ public class IMMUTABLE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_T
|
|||||||
@Override
|
@Override
|
||||||
@Primitive
|
@Primitive
|
||||||
public Object[] toArray() {
|
public Object[] toArray() {
|
||||||
|
if(data.length == 0) return ObjectArrays.EMPTY_ARRAY;
|
||||||
Object[] obj = new Object[data.length];
|
Object[] obj = new Object[data.length];
|
||||||
for(int i = 0,m=data.length;i<m;i++)
|
for(int i = 0,m=data.length;i<m;i++)
|
||||||
obj[i] = KEY_TO_OBJ(data[i]);
|
obj[i] = KEY_TO_OBJ(data[i]);
|
||||||
@@ -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);
|
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.
|
* Returns a Java-Type-Specific Stream to reduce boxing/unboxing.
|
||||||
* @return a Stream of the closest java type
|
* @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
|
@Override
|
||||||
public SPLIT_ITERATOR KEY_GENERIC_TYPE spliterator() { return SPLIT_ITERATORS.createArraySplititerator(data, data.length, 16464); }
|
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 {
|
private class LIST_ITER implements LIST_ITERATOR KEY_GENERIC_TYPE {
|
||||||
int index;
|
int index;
|
||||||
|
|
||||||
@@ -556,7 +621,7 @@ public class IMMUTABLE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_T
|
|||||||
@Override
|
@Override
|
||||||
public int skip(int amount) {
|
public int skip(int amount) {
|
||||||
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
||||||
int steps = Math.min(amount, (size() - 1) - index);
|
int steps = Math.min(amount, size() - index);
|
||||||
index += steps;
|
index += steps;
|
||||||
return steps;
|
return steps;
|
||||||
}
|
}
|
||||||
|
|||||||
+1454
-1327
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
+283
-19
@@ -3,15 +3,31 @@ package speiger.src.collections.PACKAGE.maps.abstracts;
|
|||||||
import java.util.AbstractMap;
|
import java.util.AbstractMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
#if VALUE_BOOLEAN && JDK_FUNCTION
|
||||||
|
import java.util.function.PREDICATE;
|
||||||
|
#endif
|
||||||
|
|
||||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||||
import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
|
import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
|
||||||
|
#if !VALUE_BOOLEAN || !JDK_FUNCTION
|
||||||
import speiger.src.collections.PACKAGE.functions.function.FUNCTION;
|
import speiger.src.collections.PACKAGE.functions.function.FUNCTION;
|
||||||
|
#endif
|
||||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||||
import speiger.src.collections.PACKAGE.maps.interfaces.MAP;
|
import speiger.src.collections.PACKAGE.maps.interfaces.MAP;
|
||||||
|
#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.ABSTRACT_SET;
|
||||||
import speiger.src.collections.PACKAGE.sets.SET;
|
import speiger.src.collections.PACKAGE.sets.SET;
|
||||||
|
#if MAPS_FEATURE
|
||||||
import speiger.src.collections.PACKAGE.utils.maps.MAPS;
|
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_ABSTRACT_COLLECTION;
|
||||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_COLLECTION;
|
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_COLLECTION;
|
||||||
#if !SAME_TYPE
|
#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;
|
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_UNARY_OPERATOR;
|
||||||
#endif
|
#endif
|
||||||
import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_SUPPLIER;
|
import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_SUPPLIER;
|
||||||
|
import speiger.src.collections.objects.collections.ObjectIterable;
|
||||||
#if !TYPE_OBJECT && !VALUE_OBJECT
|
#if !TYPE_OBJECT && !VALUE_OBJECT
|
||||||
import speiger.src.collections.objects.collections.ObjectIterator;
|
import speiger.src.collections.objects.collections.ObjectIterator;
|
||||||
#endif
|
#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
|
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
|
@Override
|
||||||
public VALUE_TYPE getDefaultReturnValue() {
|
public VALUE_TYPE getDefaultReturnValue() {
|
||||||
@@ -47,6 +64,22 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE extends AbstractMap<CL
|
|||||||
return this;
|
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
|
@Override
|
||||||
public MAP KEY_VALUE_GENERIC_TYPE copy() {
|
public MAP KEY_VALUE_GENERIC_TYPE copy() {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
@@ -63,14 +96,14 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE extends AbstractMap<CL
|
|||||||
#if VALUE_PRIMITIVES
|
#if VALUE_PRIMITIVES
|
||||||
@Override
|
@Override
|
||||||
public void addToAll(MAP KEY_VALUE_GENERIC_TYPE m) {
|
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());
|
addTo(entry.ENTRY_KEY(), entry.ENTRY_VALUE());
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@Override
|
@Override
|
||||||
public void putAll(MAP KEY_VALUE_GENERIC_TYPE m) {
|
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();
|
MAP.Entry KEY_VALUE_GENERIC_TYPE entry = iter.next();
|
||||||
put(entry.ENTRY_KEY(), entry.ENTRY_VALUE());
|
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) {
|
public void putAll(CLASS_TYPE[] keys, CLASS_VALUE_TYPE[] values, int offset, int size) {
|
||||||
SanityChecks.checkArrayCapacity(keys.length, offset, size);
|
SanityChecks.checkArrayCapacity(keys.length, offset, size);
|
||||||
SanityChecks.checkArrayCapacity(values.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
|
#endif
|
||||||
@Override
|
@Override
|
||||||
public void putAllIfAbsent(MAP KEY_VALUE_GENERIC_TYPE m) {
|
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());
|
putIfAbsent(entry.ENTRY_KEY(), entry.ENTRY_VALUE());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -161,14 +194,14 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE extends AbstractMap<CL
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void REPLACE_VALUES(MAP KEY_VALUE_GENERIC_TYPE m) {
|
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());
|
replace(entry.ENTRY_KEY(), entry.ENTRY_VALUE());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void REPLACE_VALUES(UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
public void REPLACE_VALUES(UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||||
Objects.requireNonNull(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();
|
MAP.Entry KEY_VALUE_GENERIC_TYPE entry = iter.next();
|
||||||
entry.setValue(mappingFunction.APPLY_VALUE(entry.ENTRY_KEY(), entry.ENTRY_VALUE()));
|
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
|
@Override
|
||||||
public VALUE_TYPE COMPUTE(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
public VALUE_TYPE COMPUTE(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||||
Objects.requireNonNull(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 value = GET_VALUE(key);
|
||||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, value);
|
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, value);
|
||||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||||
@@ -191,11 +314,11 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE extends AbstractMap<CL
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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);
|
Objects.requireNonNull(mappingFunction);
|
||||||
VALUE_TYPE value;
|
VALUE_TYPE value;
|
||||||
if((value = GET_VALUE(key)) == getDefaultReturnValue() || !containsKey(key)) {
|
if((value = GET_VALUE(key)) == getDefaultReturnValue() || !containsKey(key)) {
|
||||||
VALUE_TYPE newValue = mappingFunction.GET_VALUE(key);
|
VALUE_TYPE newValue = mappingFunction.APPLY(key);
|
||||||
if(VALUE_EQUALS_NOT(newValue, getDefaultReturnValue())) {
|
if(VALUE_EQUALS_NOT(newValue, getDefaultReturnValue())) {
|
||||||
put(key, newValue);
|
put(key, newValue);
|
||||||
return newValue;
|
return newValue;
|
||||||
@@ -205,11 +328,11 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE extends AbstractMap<CL
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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);
|
Objects.requireNonNull(valueProvider);
|
||||||
VALUE_TYPE value;
|
VALUE_TYPE value;
|
||||||
if((value = GET_VALUE(key)) == getDefaultReturnValue() || !containsKey(key)) {
|
if((value = GET_VALUE(key)) == getDefaultReturnValue() || !containsKey(key)) {
|
||||||
VALUE_TYPE newValue = valueProvider.VALUE_GET_KEY();
|
VALUE_TYPE newValue = valueProvider.VALUE_SUPPLY_GET();
|
||||||
if(VALUE_EQUALS_NOT(newValue, getDefaultReturnValue())) {
|
if(VALUE_EQUALS_NOT(newValue, getDefaultReturnValue())) {
|
||||||
put(key, newValue);
|
put(key, newValue);
|
||||||
return newValue;
|
return newValue;
|
||||||
@@ -219,7 +342,7 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE extends AbstractMap<CL
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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);
|
Objects.requireNonNull(mappingFunction);
|
||||||
VALUE_TYPE value;
|
VALUE_TYPE value;
|
||||||
if(VALUE_EQUALS_NOT((value = GET_VALUE(key)), getDefaultReturnValue()) || containsKey(key)) {
|
if(VALUE_EQUALS_NOT((value = GET_VALUE(key)), getDefaultReturnValue()) || containsKey(key)) {
|
||||||
@@ -232,7 +355,8 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE extends AbstractMap<CL
|
|||||||
}
|
}
|
||||||
return getDefaultReturnValue();
|
return getDefaultReturnValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE MERGE(KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) {
|
public VALUE_TYPE MERGE(KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) {
|
||||||
Objects.requireNonNull(mappingFunction);
|
Objects.requireNonNull(mappingFunction);
|
||||||
@@ -246,7 +370,7 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE extends AbstractMap<CL
|
|||||||
@Override
|
@Override
|
||||||
public void BULK_MERGE(MAP KEY_VALUE_GENERIC_TYPE m, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) {
|
public void BULK_MERGE(MAP KEY_VALUE_GENERIC_TYPE m, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) {
|
||||||
Objects.requireNonNull(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();
|
KEY_TYPE key = entry.ENTRY_KEY();
|
||||||
VALUE_TYPE oldValue = GET_VALUE(key);
|
VALUE_TYPE oldValue = GET_VALUE(key);
|
||||||
VALUE_TYPE newValue = VALUE_EQUALS(oldValue, getDefaultReturnValue()) ? entry.ENTRY_VALUE() : mappingFunction.APPLY_VALUE(oldValue, entry.ENTRY_VALUE());
|
VALUE_TYPE newValue = VALUE_EQUALS(oldValue, getDefaultReturnValue()) ? entry.ENTRY_VALUE() : mappingFunction.APPLY_VALUE(oldValue, entry.ENTRY_VALUE());
|
||||||
@@ -285,10 +409,20 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE extends AbstractMap<CL
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CLASS_VALUE_TYPE remove(Object key) {
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
return VALUE_TO_OBJ(REMOVE_VALUE((CLASS_TYPE)key));
|
||||||
|
#else
|
||||||
|
return key instanceof CLASS_TYPE ? VALUE_TO_OBJ(REMOVE_VALUE(CLASS_TO_KEY(key))) : VALUE_TO_OBJ(getDefaultReturnValue());
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void forEach(BI_CONSUMER KEY_VALUE_GENERIC_TYPE action) {
|
public void forEach(BI_CONSUMER KEY_VALUE_GENERIC_TYPE action) {
|
||||||
Objects.requireNonNull(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();
|
MAP.Entry KEY_VALUE_GENERIC_TYPE entry = iter.next();
|
||||||
action.accept(entry.ENTRY_KEY(), entry.ENTRY_VALUE());
|
action.accept(entry.ENTRY_KEY(), entry.ENTRY_VALUE());
|
||||||
}
|
}
|
||||||
@@ -306,7 +440,11 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE extends AbstractMap<CL
|
|||||||
#else
|
#else
|
||||||
@Override
|
@Override
|
||||||
public boolean remove(Object o) {
|
public boolean remove(Object o) {
|
||||||
return VALUE_EQUALS_NOT(ABSTRACT_MAP.this.remove(o), getDefaultReturnValue());
|
if(ABSTRACT_MAP.this.containsKey(o)) {
|
||||||
|
ABSTRACT_MAP.this.remove(o);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -318,7 +456,7 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE extends AbstractMap<CL
|
|||||||
@Override
|
@Override
|
||||||
public ITERATOR KEY_GENERIC_TYPE iterator() {
|
public ITERATOR KEY_GENERIC_TYPE iterator() {
|
||||||
return new ITERATOR KEY_GENERIC_TYPE() {
|
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
|
@Override
|
||||||
public boolean hasNext() {
|
public boolean hasNext() {
|
||||||
return iter.hasNext();
|
return iter.hasNext();
|
||||||
@@ -369,7 +507,7 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE extends AbstractMap<CL
|
|||||||
@Override
|
@Override
|
||||||
public VALUE_ITERATOR VALUE_GENERIC_TYPE iterator() {
|
public VALUE_ITERATOR VALUE_GENERIC_TYPE iterator() {
|
||||||
return new VALUE_ITERATOR VALUE_GENERIC_TYPE() {
|
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
|
@Override
|
||||||
public boolean hasNext() {
|
public boolean hasNext() {
|
||||||
return iter.hasNext();
|
return iter.hasNext();
|
||||||
@@ -409,11 +547,137 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE extends AbstractMap<CL
|
|||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
int hash = 0;
|
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();
|
while(iter.hasNext()) hash += iter.next().hashCode();
|
||||||
return hash;
|
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
|
* A Simple Type Specific Entry class to reduce boxing/unboxing
|
||||||
* @Type(T)
|
* @Type(T)
|
||||||
|
|||||||
+2696
-2415
File diff suppressed because it is too large
Load Diff
+1651
-1467
File diff suppressed because it is too large
Load Diff
+1683
-1492
File diff suppressed because it is too large
Load Diff
+1653
-1466
File diff suppressed because it is too large
Load Diff
+1638
-1448
File diff suppressed because it is too large
Load Diff
+1477
-1353
File diff suppressed because it is too large
Load Diff
+1683
-1414
File diff suppressed because it is too large
Load Diff
+860
-717
File diff suppressed because it is too large
Load Diff
+1092
-964
File diff suppressed because it is too large
Load Diff
+1581
File diff suppressed because it is too large
Load Diff
+1572
File diff suppressed because it is too large
Load Diff
+3031
-2760
File diff suppressed because it is too large
Load Diff
+3103
-2823
File diff suppressed because it is too large
Load Diff
+94
-94
@@ -1,95 +1,95 @@
|
|||||||
package speiger.src.collections.PACKAGE.maps.interfaces;
|
package speiger.src.collections.PACKAGE.maps.interfaces;
|
||||||
|
|
||||||
import java.util.concurrent.ConcurrentMap;
|
import java.util.concurrent.ConcurrentMap;
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A type specific ConcurrentMap interface that reduces boxing/unboxing.
|
* A type specific ConcurrentMap interface that reduces boxing/unboxing.
|
||||||
* Since the interface adds nothing new. It is there just for completion sake.
|
* Since the interface adds nothing new. It is there just for completion sake.
|
||||||
* @Type(T)
|
* @Type(T)
|
||||||
* @ValueType(V)
|
* @ValueType(V)
|
||||||
*/
|
*/
|
||||||
public interface CONCURRENT_MAP KEY_VALUE_GENERIC_TYPE extends ConcurrentMap<CLASS_TYPE, CLASS_VALUE_TYPE>, MAP KEY_VALUE_GENERIC_TYPE
|
public interface CONCURRENT_MAP KEY_VALUE_GENERIC_TYPE extends ConcurrentMap<CLASS_TYPE, CLASS_VALUE_TYPE>, MAP KEY_VALUE_GENERIC_TYPE
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
@Primitive
|
@Primitive
|
||||||
public default CLASS_VALUE_TYPE compute(CLASS_TYPE key, BiFunction<? super CLASS_TYPE, ? super CLASS_VALUE_TYPE, ? extends CLASS_VALUE_TYPE> mappingFunction) {
|
public default CLASS_VALUE_TYPE compute(CLASS_TYPE key, BiFunction<? super CLASS_TYPE, ? super CLASS_VALUE_TYPE, ? extends CLASS_VALUE_TYPE> mappingFunction) {
|
||||||
return MAP.super.compute(key, mappingFunction);
|
return MAP.super.compute(key, mappingFunction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Primitive
|
@Primitive
|
||||||
public default CLASS_VALUE_TYPE computeIfAbsent(CLASS_TYPE key, Function<? super CLASS_TYPE, ? extends CLASS_VALUE_TYPE> mappingFunction) {
|
public default CLASS_VALUE_TYPE computeIfAbsent(CLASS_TYPE key, Function<? super CLASS_TYPE, ? extends CLASS_VALUE_TYPE> mappingFunction) {
|
||||||
return MAP.super.computeIfAbsent(key, mappingFunction);
|
return MAP.super.computeIfAbsent(key, mappingFunction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Primitive
|
@Primitive
|
||||||
public default CLASS_VALUE_TYPE computeIfPresent(CLASS_TYPE key, BiFunction<? super CLASS_TYPE, ? super CLASS_VALUE_TYPE, ? extends CLASS_VALUE_TYPE> mappingFunction) {
|
public default CLASS_VALUE_TYPE computeIfPresent(CLASS_TYPE key, BiFunction<? super CLASS_TYPE, ? super CLASS_VALUE_TYPE, ? extends CLASS_VALUE_TYPE> mappingFunction) {
|
||||||
return MAP.super.computeIfPresent(key, mappingFunction);
|
return MAP.super.computeIfPresent(key, mappingFunction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Primitive
|
@Primitive
|
||||||
public default void forEach(BiConsumer<? super CLASS_TYPE, ? super CLASS_VALUE_TYPE> action) {
|
public default void forEach(BiConsumer<? super CLASS_TYPE, ? super CLASS_VALUE_TYPE> action) {
|
||||||
MAP.super.forEach(action);
|
MAP.super.forEach(action);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Primitive
|
@Primitive
|
||||||
public default CLASS_VALUE_TYPE merge(CLASS_TYPE key, CLASS_VALUE_TYPE value, BiFunction<? super CLASS_VALUE_TYPE, ? super CLASS_VALUE_TYPE, ? extends CLASS_VALUE_TYPE> mappingFunction) {
|
public default CLASS_VALUE_TYPE merge(CLASS_TYPE key, CLASS_VALUE_TYPE value, BiFunction<? super CLASS_VALUE_TYPE, ? super CLASS_VALUE_TYPE, ? extends CLASS_VALUE_TYPE> mappingFunction) {
|
||||||
return MAP.super.merge(key, value, mappingFunction);
|
return MAP.super.merge(key, value, mappingFunction);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if TYPE_OBJECT && VALUE_OBJECT
|
#if TYPE_OBJECT && VALUE_OBJECT
|
||||||
@Override
|
@Override
|
||||||
public CLASS_VALUE_TYPE getOrDefault(Object key, CLASS_VALUE_TYPE defaultValue);
|
public CLASS_VALUE_TYPE getOrDefault(Object key, CLASS_VALUE_TYPE defaultValue);
|
||||||
@Override
|
@Override
|
||||||
public CLASS_VALUE_TYPE putIfAbsent(CLASS_TYPE key, CLASS_VALUE_TYPE value);
|
public CLASS_VALUE_TYPE putIfAbsent(CLASS_TYPE key, CLASS_VALUE_TYPE value);
|
||||||
@Override
|
@Override
|
||||||
public boolean remove(Object key, Object value);
|
public boolean remove(Object key, Object value);
|
||||||
@Override
|
@Override
|
||||||
public boolean replace(CLASS_TYPE key, CLASS_VALUE_TYPE oldValue, CLASS_VALUE_TYPE newValue);
|
public boolean replace(CLASS_TYPE key, CLASS_VALUE_TYPE oldValue, CLASS_VALUE_TYPE newValue);
|
||||||
@Override
|
@Override
|
||||||
public CLASS_VALUE_TYPE replace(CLASS_TYPE key, CLASS_VALUE_TYPE value);
|
public CLASS_VALUE_TYPE replace(CLASS_TYPE key, CLASS_VALUE_TYPE value);
|
||||||
|
|
||||||
#else
|
#else
|
||||||
@Primitive
|
@Primitive
|
||||||
@Override
|
@Override
|
||||||
public default CLASS_VALUE_TYPE getOrDefault(Object key, CLASS_VALUE_TYPE defaultValue) {
|
public default CLASS_VALUE_TYPE getOrDefault(Object key, CLASS_VALUE_TYPE defaultValue) {
|
||||||
return MAP.super.getOrDefault(key, defaultValue);
|
return MAP.super.getOrDefault(key, defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Primitive
|
@Primitive
|
||||||
public default CLASS_VALUE_TYPE putIfAbsent(CLASS_TYPE key, CLASS_VALUE_TYPE value) {
|
public default CLASS_VALUE_TYPE putIfAbsent(CLASS_TYPE key, CLASS_VALUE_TYPE value) {
|
||||||
return MAP.super.putIfAbsent(key, value);
|
return MAP.super.putIfAbsent(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public default boolean remove(Object key, Object value) {
|
public default boolean remove(Object key, Object value) {
|
||||||
return MAP.super.remove(key, value);
|
return MAP.super.remove(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public default boolean replace(CLASS_TYPE key, CLASS_VALUE_TYPE oldValue, CLASS_VALUE_TYPE newValue) {
|
public default boolean replace(CLASS_TYPE key, CLASS_VALUE_TYPE oldValue, CLASS_VALUE_TYPE newValue) {
|
||||||
return MAP.super.replace(key, oldValue, newValue);
|
return MAP.super.replace(key, oldValue, newValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public default CLASS_VALUE_TYPE replace(CLASS_TYPE key, CLASS_VALUE_TYPE value) {
|
public default CLASS_VALUE_TYPE replace(CLASS_TYPE key, CLASS_VALUE_TYPE value) {
|
||||||
return MAP.super.replace(key, value);
|
return MAP.super.replace(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public default void replaceAll(BiFunction<? super CLASS_TYPE, ? super CLASS_VALUE_TYPE, ? extends CLASS_VALUE_TYPE> mappingFunction) {
|
public default void replaceAll(BiFunction<? super CLASS_TYPE, ? super CLASS_VALUE_TYPE, ? extends CLASS_VALUE_TYPE> mappingFunction) {
|
||||||
MAP.super.replaceAll(mappingFunction);
|
MAP.super.replaceAll(mappingFunction);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+164
-7
@@ -10,36 +10,72 @@ import java.util.function.BiConsumer;
|
|||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
#if VALUE_BOOLEAN && JDK_FUNCTION
|
||||||
|
import java.util.function.PREDICATE;
|
||||||
|
#endif
|
||||||
|
|
||||||
#if TYPE_OBJECT
|
#if TYPE_OBJECT
|
||||||
|
#if AVL_TREE_MAP_FEATURE || RB_TREE_MAP_FEATURE
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_COLLECTION;
|
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_COLLECTION;
|
||||||
import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
|
import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
|
||||||
|
#if !VALUE_BOOLEAN || !JDK_FUNCTION
|
||||||
import speiger.src.collections.PACKAGE.functions.function.FUNCTION;
|
import speiger.src.collections.PACKAGE.functions.function.FUNCTION;
|
||||||
|
#endif
|
||||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||||
#if !TYPE_OBJECT && !TYPE_BOOLEAN
|
#if !TYPE_OBJECT && !TYPE_BOOLEAN && SORTED_MAP_FEATURE
|
||||||
|
#if AVL_TREE_MAP_FEATURE || RB_TREE_MAP_FEATURE
|
||||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
#if !TYPE_BOOLEAN
|
#if !TYPE_BOOLEAN
|
||||||
|
#if LINKED_CUSTOM_MAP_FEATURE
|
||||||
import speiger.src.collections.PACKAGE.maps.impl.customHash.LINKED_CUSTOM_HASH_MAP;
|
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;
|
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;
|
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;
|
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;
|
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;
|
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;
|
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;
|
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;
|
import speiger.src.collections.PACKAGE.maps.impl.concurrent.CONCURRENT_HASH_MAP;
|
||||||
|
#endif
|
||||||
#if TYPE_OBJECT
|
#if TYPE_OBJECT
|
||||||
|
#if ENUM_MAP_FEATURE
|
||||||
import speiger.src.collections.PACKAGE.maps.impl.misc.ENUM_MAP;
|
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;
|
import speiger.src.collections.PACKAGE.maps.impl.misc.LINKED_ENUM_MAP;
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
import speiger.src.collections.objects.collections.ObjectIterable;
|
import speiger.src.collections.objects.collections.ObjectIterable;
|
||||||
|
#if CUSTOM_MAP_FEATURE || LINKED_CUSTOM_MAP_FEATURE
|
||||||
import speiger.src.collections.PACKAGE.utils.STRATEGY;
|
import speiger.src.collections.PACKAGE.utils.STRATEGY;
|
||||||
|
#endif
|
||||||
|
#if MAPS_FEATURE
|
||||||
import speiger.src.collections.PACKAGE.utils.maps.MAPS;
|
import speiger.src.collections.PACKAGE.utils.maps.MAPS;
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
import speiger.src.collections.PACKAGE.sets.SET;
|
import speiger.src.collections.PACKAGE.sets.SET;
|
||||||
#if !SAME_TYPE
|
#if !SAME_TYPE
|
||||||
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_UNARY_OPERATOR;
|
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);
|
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
|
* 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
|
* @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);
|
public void REPLACE_VALUES(UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction);
|
||||||
/**
|
/**
|
||||||
* A Type Specific compute method to reduce boxing/unboxing
|
* 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 key the key that should be computed
|
||||||
* @param mappingFunction the operator that should generate the value
|
* @param mappingFunction the operator that should generate the value
|
||||||
* @return the result of the computation
|
* @return the result of the computation
|
||||||
*/
|
*/
|
||||||
public VALUE_TYPE COMPUTE(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction);
|
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 key the key that should be computed
|
||||||
* @param mappingFunction the operator that should generate the value if not present
|
* @param mappingFunction the operator that should generate the value if not present
|
||||||
* @return the result of the computed value or present value
|
* @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);
|
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
|
* 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 key the key that should be computed
|
||||||
* @param valueProvider the value if not present
|
* @param valueProvider the value if not present
|
||||||
* @return the result of the computed value or present value
|
* @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);
|
public VALUE_TYPE SUPPLY_IF_ABSENT(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider);
|
||||||
/**
|
/**
|
||||||
* A Type Specific compute method to reduce boxing/unboxing
|
* 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 key the key that should be computed
|
||||||
* @param mappingFunction the operator that should generate the value if present
|
* @param mappingFunction the operator that should generate the value if present
|
||||||
* @return the result of the default return value or present value
|
* @return the result of the default return value or present value
|
||||||
* @note if not present then compute is not executed
|
* @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);
|
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
|
* 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 key the key that should be be searched for
|
||||||
* @param value the value that should be merged with
|
* @param value the value that should be merged with
|
||||||
* @param mappingFunction the operator that should generate the new Value
|
* @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);
|
public VALUE_TYPE MERGE(KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction);
|
||||||
/**
|
/**
|
||||||
* A Bulk method for merging Maps.
|
* 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 m the entries that should be bulk added
|
||||||
* @param mappingFunction the operator that should generate the new Value
|
* @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
|
* @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)));
|
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
|
* A Type Specific get method to reduce boxing/unboxing
|
||||||
* @param key the key that is searched for
|
* @param key the key that is searched for
|
||||||
* @return the searched value or default return value
|
* @return the searched value or default return value
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public VALUE_TYPE GET_VALUE(KEY_TYPE key);
|
public VALUE_TYPE GET_VALUE(KEY_TYPE key);
|
||||||
|
|
||||||
|
#if !TYPE_OBJECT || !VALUE_OBJECT
|
||||||
/**
|
/**
|
||||||
* A Type Specific getOrDefault method to reduce boxing/unboxing
|
* A Type Specific getOrDefault method to reduce boxing/unboxing
|
||||||
* @param key the key that is searched for
|
* @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();
|
public ObjectSet<Entry KEY_VALUE_GENERIC_TYPE> ENTRY_SET();
|
||||||
|
|
||||||
#if !TYPE_BOOLEAN
|
#if MAPS_FEATURE
|
||||||
/**
|
/**
|
||||||
* Creates a Wrapped Map that is Synchronized
|
* Creates a Wrapped Map that is Synchronized
|
||||||
* @return a new Map that is synchronized
|
* @return a new Map that is synchronized
|
||||||
@@ -557,8 +669,8 @@ public interface MAP KEY_VALUE_GENERIC_TYPE extends Map<CLASS_TYPE, CLASS_VALUE_
|
|||||||
*/
|
*/
|
||||||
public KEY_TYPE ENTRY_KEY();
|
public KEY_TYPE ENTRY_KEY();
|
||||||
public default CLASS_TYPE getKey() { return KEY_TO_OBJ(ENTRY_KEY()); }
|
public default CLASS_TYPE getKey() { return KEY_TO_OBJ(ENTRY_KEY()); }
|
||||||
#endif
|
|
||||||
|
|
||||||
|
#endif
|
||||||
#if !VALUE_OBJECT
|
#if !VALUE_OBJECT
|
||||||
/**
|
/**
|
||||||
* Type Specific getValue method that reduces boxing/unboxing
|
* Type Specific getValue method that reduces boxing/unboxing
|
||||||
@@ -638,6 +750,7 @@ public interface MAP KEY_VALUE_GENERIC_TYPE extends Map<CLASS_TYPE, CLASS_VALUE_
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
#if MAP_FEATURE
|
||||||
/**
|
/**
|
||||||
* Helper function to unify code
|
* Helper function to unify code
|
||||||
* @Type(T)
|
* @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);
|
return new HASH_MAPKV_BRACES(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#if LINKED_MAP_FEATURE
|
||||||
/**
|
/**
|
||||||
* Helper function to unify code
|
* Helper function to unify code
|
||||||
* @Type(T)
|
* @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);
|
return new IMMUTABLE_HASH_MAPKV_BRACES(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#if IMMUTABLE_MAP_FEATURE
|
||||||
/**
|
/**
|
||||||
* Helper function to unify code
|
* Helper function to unify code
|
||||||
* @param keys the keys that should be inserted
|
* @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);
|
return new IMMUTABLE_HASH_MAPKV_BRACES(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
#if TYPE_OBJECT
|
#if TYPE_OBJECT
|
||||||
|
#if ENUM_MAP_FEATURE
|
||||||
/**
|
/**
|
||||||
* Helper function to unify code
|
* Helper function to unify code
|
||||||
* @param keyType the EnumClass that should be used
|
* @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);
|
return new ENUM_MAPKV_BRACES(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#if LINKED_ENUM_MAP_FEATURE
|
||||||
/**
|
/**
|
||||||
* Helper function to unify code
|
* Helper function to unify code
|
||||||
* @param keyType the EnumClass that should be used
|
* @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) {
|
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);
|
return new LINKED_ENUM_MAPKV_BRACES(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
#if CUSTOM_MAP_FEATURE
|
||||||
/**
|
/**
|
||||||
* Helper function to unify code
|
* Helper function to unify code
|
||||||
* @param strategy the Hash Controller
|
* @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);
|
return new CUSTOM_HASH_MAPKV_BRACES(map, strategy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#if LINKED_CUSTOM_MAP_FEATURE
|
||||||
/**
|
/**
|
||||||
* Helper function to unify code
|
* Helper function to unify code
|
||||||
* @param strategy the Hash Controller
|
* @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);
|
return new LINKED_CUSTOM_HASH_MAPKV_BRACES(map, strategy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#if ARRAY_MAP_FEATURE
|
||||||
/**
|
/**
|
||||||
* Helper function to unify code
|
* Helper function to unify code
|
||||||
* @Type(T)
|
* @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);
|
return new ARRAY_MAPKV_BRACES(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#if RB_TREE_MAP_FEATURE
|
||||||
/**
|
/**
|
||||||
* Helper function to unify code
|
* Helper function to unify code
|
||||||
* @Type(T)
|
* @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);
|
return new RB_TREE_MAPKV_BRACES(map, comp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#if AVL_TREE_MAP_FEATURE
|
||||||
/**
|
/**
|
||||||
* Helper function to unify code
|
* Helper function to unify code
|
||||||
* @Type(T)
|
* @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) {
|
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);
|
return new AVL_TREE_MAPKV_BRACES(map, comp);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1381,6 +1513,7 @@ public interface MAP KEY_VALUE_GENERIC_TYPE extends Map<CLASS_TYPE, CLASS_VALUE_
|
|||||||
* @param initialSize the requested start capacity
|
* @param initialSize the requested start capacity
|
||||||
*/
|
*/
|
||||||
public BuilderCache(int initialSize) {
|
public BuilderCache(int initialSize) {
|
||||||
|
if(initialSize < 0) throw new IllegalStateException("Minimum Capacity is negative. This is not allowed");
|
||||||
keys = NEW_KEY_ARRAY(initialSize);
|
keys = NEW_KEY_ARRAY(initialSize);
|
||||||
values = NEW_VALUE_ARRAY(initialSize);
|
values = NEW_VALUE_ARRAY(initialSize);
|
||||||
}
|
}
|
||||||
@@ -1433,7 +1566,11 @@ public interface MAP KEY_VALUE_GENERIC_TYPE extends Map<CLASS_TYPE, CLASS_VALUE_
|
|||||||
* @return self
|
* @return self
|
||||||
*/
|
*/
|
||||||
public BuilderCache KEY_VALUE_GENERIC_TYPE putAll(MAP KEY_VALUE_GENERIC_TYPE map) {
|
public BuilderCache KEY_VALUE_GENERIC_TYPE putAll(MAP KEY_VALUE_GENERIC_TYPE map) {
|
||||||
|
#if MAPS_FEATURE
|
||||||
return putAll(MAPS.fastIterable(map));
|
return putAll(MAPS.fastIterable(map));
|
||||||
|
#else
|
||||||
|
return putAll(map.ENTRY_SET());
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1462,11 +1599,14 @@ public interface MAP KEY_VALUE_GENERIC_TYPE extends Map<CLASS_TYPE, CLASS_VALUE_
|
|||||||
return this;
|
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){
|
private <E extends MAP KEY_VALUE_GENERIC_TYPE> E putElements(E e){
|
||||||
e.putAll(keys, values, 0, size);
|
e.putAll(keys, values, 0, size);
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#if MAP_FEATURE
|
||||||
/**
|
/**
|
||||||
* Builds the Keys and Values into a Hash Map
|
* Builds the Keys and Values into a Hash Map
|
||||||
* @return a HASH_MAP
|
* @return a HASH_MAP
|
||||||
@@ -1475,6 +1615,8 @@ public interface MAP KEY_VALUE_GENERIC_TYPE extends Map<CLASS_TYPE, CLASS_VALUE_
|
|||||||
return putElements(new HASH_MAPKV_BRACES(size));
|
return putElements(new HASH_MAPKV_BRACES(size));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#if LINKED_MAP_FEATURE
|
||||||
/**
|
/**
|
||||||
* Builds the Keys and Values into a Linked Hash Map
|
* Builds the Keys and Values into a Linked Hash Map
|
||||||
* @return a LINKED_HASH_MAP
|
* @return a LINKED_HASH_MAP
|
||||||
@@ -1483,6 +1625,8 @@ public interface MAP KEY_VALUE_GENERIC_TYPE extends Map<CLASS_TYPE, CLASS_VALUE_
|
|||||||
return putElements(new LINKED_HASH_MAPKV_BRACES(size));
|
return putElements(new LINKED_HASH_MAPKV_BRACES(size));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#if IMMUTABLE_MAP_FEATURE
|
||||||
/**
|
/**
|
||||||
* Builds the Keys and Values into a Immutable Hash Map
|
* Builds the Keys and Values into a Immutable Hash Map
|
||||||
* @return a IMMUTABLE_HASH_MAP
|
* @return a IMMUTABLE_HASH_MAP
|
||||||
@@ -1491,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));
|
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
|
* Builds the Keys and Values into a Custom Hash Map
|
||||||
* @param strategy the that controls the keys and values
|
* @param strategy the that controls the keys and values
|
||||||
@@ -1500,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));
|
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
|
* Builds the Keys and Values into a Linked Custom Hash Map
|
||||||
* @param strategy the that controls the keys and values
|
* @param strategy the that controls the keys and values
|
||||||
@@ -1509,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));
|
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
|
* Builds the Keys and Values into a Concurrent Hash Map
|
||||||
* @return a CONCURRENT_HASH_MAP
|
* @return a CONCURRENT_HASH_MAP
|
||||||
@@ -1517,6 +1667,8 @@ public interface MAP KEY_VALUE_GENERIC_TYPE extends Map<CLASS_TYPE, CLASS_VALUE_
|
|||||||
return putElements(new CONCURRENT_HASH_MAPKV_BRACES(size));
|
return putElements(new CONCURRENT_HASH_MAPKV_BRACES(size));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#if ARRAY_MAP_FEATURE
|
||||||
/**
|
/**
|
||||||
* Builds the Keys and Values into a Array Map
|
* Builds the Keys and Values into a Array Map
|
||||||
* @return a ARRAY_MAP
|
* @return a ARRAY_MAP
|
||||||
@@ -1525,6 +1677,8 @@ public interface MAP KEY_VALUE_GENERIC_TYPE extends Map<CLASS_TYPE, CLASS_VALUE_
|
|||||||
return new ARRAY_MAPKV_BRACES(keys, values, size);
|
return new ARRAY_MAPKV_BRACES(keys, values, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#if RB_TREE_MAP_FEATURE
|
||||||
/**
|
/**
|
||||||
* Builds the Keys and Values into a RedBlack TreeMap
|
* Builds the Keys and Values into a RedBlack TreeMap
|
||||||
* @return a RB_TREE_MAP
|
* @return a RB_TREE_MAP
|
||||||
@@ -1542,6 +1696,8 @@ public interface MAP KEY_VALUE_GENERIC_TYPE extends Map<CLASS_TYPE, CLASS_VALUE_
|
|||||||
return putElements(new RB_TREE_MAPKV_BRACES(comp));
|
return putElements(new RB_TREE_MAPKV_BRACES(comp));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#if AVL_TREE_MAP_FEATURE
|
||||||
/**
|
/**
|
||||||
* Builds the Keys and Values into a AVL TreeMap
|
* Builds the Keys and Values into a AVL TreeMap
|
||||||
* @return a AVL_TREE_MAP
|
* @return a AVL_TREE_MAP
|
||||||
@@ -1558,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) {
|
public AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE avlTreeMap(COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||||
return putElements(new AVL_TREE_MAPKV_BRACES(comp));
|
return putElements(new AVL_TREE_MAPKV_BRACES(comp));
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
+7
@@ -2,7 +2,9 @@ package speiger.src.collections.PACKAGE.maps.interfaces;
|
|||||||
|
|
||||||
import java.util.NavigableMap;
|
import java.util.NavigableMap;
|
||||||
import speiger.src.collections.PACKAGE.sets.NAVIGABLE_SET;
|
import speiger.src.collections.PACKAGE.sets.NAVIGABLE_SET;
|
||||||
|
#if MAPS_FEATURE
|
||||||
import speiger.src.collections.PACKAGE.utils.maps.MAPS;
|
import speiger.src.collections.PACKAGE.utils.maps.MAPS;
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Type Specific Navigable Map interface with a couple helper methods
|
* A Type Specific Navigable Map interface with a couple helper methods
|
||||||
@@ -34,7 +36,11 @@ public interface NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE extends SORTED_MAP KEY_VAL
|
|||||||
/** @return a Type Specific pollLastEntry */
|
/** @return a Type Specific pollLastEntry */
|
||||||
@Override
|
@Override
|
||||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollLastEntry();
|
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollLastEntry();
|
||||||
|
/** @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
|
* Creates a Wrapped NavigableMap that is Synchronized
|
||||||
* @return a new NavigableMap that is synchronized
|
* @return a new NavigableMap that is synchronized
|
||||||
@@ -57,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); }
|
public default NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE unmodifiable() { return MAPS.unmodifiable(this); }
|
||||||
|
|
||||||
|
#endif
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
/**
|
/**
|
||||||
* A Type Specific SubMap method to reduce boxing/unboxing
|
* A Type Specific SubMap method to reduce boxing/unboxing
|
||||||
|
|||||||
+79
@@ -1,6 +1,18 @@
|
|||||||
package speiger.src.collections.PACKAGE.maps.interfaces;
|
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;
|
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
|
||||||
import speiger.src.collections.objects.collections.ObjectBidirectionalIterator;
|
import speiger.src.collections.objects.collections.ObjectBidirectionalIterator;
|
||||||
import speiger.src.collections.objects.sets.ObjectOrderedSet;
|
import speiger.src.collections.objects.sets.ObjectOrderedSet;
|
||||||
/**
|
/**
|
||||||
@@ -12,7 +24,11 @@ import speiger.src.collections.objects.sets.ObjectOrderedSet;
|
|||||||
* @Type(T)
|
* @Type(T)
|
||||||
* @ValueType(V)
|
* @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
|
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.
|
* A customized put method that allows you to insert into the first index.
|
||||||
@@ -32,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);
|
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.
|
* A specific move method to move a given key/value to the first index.
|
||||||
* @param key that should be moved to the first index
|
* @param key that should be moved to the first index
|
||||||
@@ -92,9 +128,35 @@ public interface ORDERED_MAP KEY_VALUE_GENERIC_TYPE extends MAP KEY_VALUE_GENERI
|
|||||||
*/
|
*/
|
||||||
public VALUE_TYPE LAST_ENTRY_VALUE();
|
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
|
@Override
|
||||||
public ORDERED_MAP KEY_VALUE_GENERIC_TYPE copy();
|
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
|
* Creates a Wrapped SortedMap that is Synchronized
|
||||||
* @return a new SortedMap that is synchronized
|
* @return a new SortedMap that is synchronized
|
||||||
@@ -120,6 +182,23 @@ public interface ORDERED_MAP KEY_VALUE_GENERIC_TYPE extends MAP KEY_VALUE_GENERI
|
|||||||
@Override
|
@Override
|
||||||
public default ORDERED_MAP KEY_VALUE_GENERIC_TYPE unmodifiable() { return MAPS.unmodifiable(this); }
|
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
|
* Fast Ordered Entry Set that allows for a faster Entry Iterator by recycling the Entry Object and just exchanging 1 internal value
|
||||||
* @Type(T)
|
* @Type(T)
|
||||||
|
|||||||
+11
-5
@@ -9,9 +9,13 @@ import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_COLLECTION;
|
|||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||||
#endif
|
#endif
|
||||||
import speiger.src.collections.PACKAGE.sets.SET;
|
import speiger.src.collections.PACKAGE.sets.SORTED_SET;
|
||||||
|
#if MAPS_FEATURE
|
||||||
import speiger.src.collections.PACKAGE.utils.maps.MAPS;
|
import speiger.src.collections.PACKAGE.utils.maps.MAPS;
|
||||||
|
#endif
|
||||||
|
#if !TYPE_OBJECT
|
||||||
import speiger.src.collections.objects.sets.ObjectSortedSet;
|
import speiger.src.collections.objects.sets.ObjectSortedSet;
|
||||||
|
#endif
|
||||||
import speiger.src.collections.objects.collections.ObjectBidirectionalIterator;
|
import speiger.src.collections.objects.collections.ObjectBidirectionalIterator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -31,10 +35,11 @@ public interface SORTED_MAP KEY_VALUE_GENERIC_TYPE extends SortedMap<CLASS_TYPE,
|
|||||||
public SORTED_MAP KEY_VALUE_GENERIC_TYPE copy();
|
public SORTED_MAP KEY_VALUE_GENERIC_TYPE copy();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SET KEY_GENERIC_TYPE keySet();
|
public SORTED_SET KEY_GENERIC_TYPE keySet();
|
||||||
@Override
|
@Override
|
||||||
public VALUE_COLLECTION VALUE_GENERIC_TYPE values();
|
public VALUE_COLLECTION VALUE_GENERIC_TYPE values();
|
||||||
|
|
||||||
|
#if MAPS_FEATURE
|
||||||
/**
|
/**
|
||||||
* Creates a Wrapped SortedMap that is Synchronized
|
* Creates a Wrapped SortedMap that is Synchronized
|
||||||
* @return a new SortedMap that is synchronized
|
* @return a new SortedMap that is synchronized
|
||||||
@@ -57,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); }
|
public default SORTED_MAP KEY_VALUE_GENERIC_TYPE unmodifiable() { return MAPS.unmodifiable(this); }
|
||||||
|
|
||||||
|
#endif
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
/**
|
/**
|
||||||
* A Type Specific SubMap method to reduce boxing/unboxing
|
* A Type Specific SubMap method to reduce boxing/unboxing
|
||||||
@@ -155,11 +161,11 @@ public interface SORTED_MAP KEY_VALUE_GENERIC_TYPE extends SortedMap<CLASS_TYPE,
|
|||||||
public VALUE_TYPE LAST_ENTRY_VALUE();
|
public VALUE_TYPE LAST_ENTRY_VALUE();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public default SORTED_MAP KEY_VALUE_GENERIC_TYPE subMap(CLASS_TYPE fromKey, CLASS_TYPE toKey) { return subMap(OBJ_TO_KEY(fromKey), OBJ_TO_KEY(toKey)); }
|
public SORTED_MAP KEY_VALUE_GENERIC_TYPE subMap(CLASS_TYPE fromKey, CLASS_TYPE toKey);
|
||||||
@Override
|
@Override
|
||||||
public default SORTED_MAP KEY_VALUE_GENERIC_TYPE headMap(CLASS_TYPE toKey) { return headMap(OBJ_TO_KEY(toKey)); }
|
public SORTED_MAP KEY_VALUE_GENERIC_TYPE headMap(CLASS_TYPE toKey);
|
||||||
@Override
|
@Override
|
||||||
public default SORTED_MAP KEY_VALUE_GENERIC_TYPE tailMap(CLASS_TYPE fromKey) { return tailMap(OBJ_TO_KEY(fromKey)); }
|
public SORTED_MAP KEY_VALUE_GENERIC_TYPE tailMap(CLASS_TYPE fromKey);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,7 +1,12 @@
|
|||||||
package speiger.src.collections.PACKAGE.misc.pairs;
|
package speiger.src.collections.PACKAGE.misc.pairs;
|
||||||
|
|
||||||
|
#if IMMUTABLE_PAIR
|
||||||
import speiger.src.collections.PACKAGE.misc.pairs.impl.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;
|
import speiger.src.collections.PACKAGE.misc.pairs.impl.MUTABLE_PAIR;
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Key Value Pair Interface that allows to reduce boxing/unboxing.
|
* Key Value Pair Interface that allows to reduce boxing/unboxing.
|
||||||
* @Type(T)
|
* @Type(T)
|
||||||
@@ -9,6 +14,7 @@ import speiger.src.collections.PACKAGE.misc.pairs.impl.MUTABLE_PAIR;
|
|||||||
*/
|
*/
|
||||||
public interface PAIR KEY_VALUE_GENERIC_TYPE
|
public interface PAIR KEY_VALUE_GENERIC_TYPE
|
||||||
{
|
{
|
||||||
|
#if IMMUTABLE_PAIR
|
||||||
/**
|
/**
|
||||||
* Empty Reference for Immutable Pairs
|
* 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());
|
return new IMMUTABLE_PAIRKV_BRACES(pair.ENTRY_KEY(), pair.ENTRY_VALUE());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#if MUTABLE_PAIR
|
||||||
/**
|
/**
|
||||||
* @Type(T)
|
* @Type(T)
|
||||||
* @ValueType(V)
|
* @ValueType(V)
|
||||||
@@ -118,6 +126,7 @@ public interface PAIR KEY_VALUE_GENERIC_TYPE
|
|||||||
return new MUTABLE_PAIRKV_BRACES(pair.ENTRY_KEY(), pair.ENTRY_VALUE());
|
return new MUTABLE_PAIRKV_BRACES(pair.ENTRY_KEY(), pair.ENTRY_VALUE());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
/**
|
/**
|
||||||
* Sets the Key of the Pair.
|
* Sets the Key of the Pair.
|
||||||
* @param key the key that should be set.
|
* @param key the key that should be set.
|
||||||
|
|||||||
+46
-46
@@ -1,46 +1,46 @@
|
|||||||
package speiger.src.collections.PACKAGE.queues;
|
package speiger.src.collections.PACKAGE.queues;
|
||||||
|
|
||||||
#if TYPE_OBJECT
|
#if TYPE_OBJECT
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
#endif
|
#endif
|
||||||
import java.util.StringJoiner;
|
import java.util.StringJoiner;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper class that implements all the essential methods for the PriorityQueues
|
* Helper class that implements all the essential methods for the PriorityQueues
|
||||||
* @Type(T)
|
* @Type(T)
|
||||||
*/
|
*/
|
||||||
public abstract class ABSTRACT_PRIORITY_QUEUE KEY_GENERIC_TYPE implements PRIORITY_QUEUE KEY_GENERIC_TYPE
|
public abstract class ABSTRACT_PRIORITY_QUEUE KEY_GENERIC_TYPE implements PRIORITY_QUEUE KEY_GENERIC_TYPE
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if(obj instanceof PRIORITY_QUEUE) {
|
if(obj instanceof PRIORITY_QUEUE) {
|
||||||
PRIORITY_QUEUE KEY_GENERIC_TYPE queue = (PRIORITY_QUEUE KEY_GENERIC_TYPE)obj;
|
PRIORITY_QUEUE KEY_GENERIC_TYPE queue = (PRIORITY_QUEUE KEY_GENERIC_TYPE)obj;
|
||||||
if(queue.size() != size()) return false;
|
if(queue.size() != size()) return false;
|
||||||
for(int i = 0,m=size();i<m;i++) {
|
for(int i = 0,m=size();i<m;i++) {
|
||||||
if(KEY_EQUALS_NOT(queue.peek(i), peek(i))) return false;
|
if(KEY_EQUALS_NOT(queue.peek(i), peek(i))) return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
int result = 1;
|
int result = 1;
|
||||||
for (int i = 0,m=size();i<m;i++) {
|
for (int i = 0,m=size();i<m;i++) {
|
||||||
result = 31 * result + KEY_TO_HASH(peek(i));
|
result = 31 * result + KEY_TO_HASH(peek(i));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
if(isEmpty()) return "[]";
|
if(isEmpty()) return "[]";
|
||||||
StringJoiner joiner = new StringJoiner(", ", "[", "]");
|
StringJoiner joiner = new StringJoiner(", ", "[", "]");
|
||||||
for (int i = 0,m=size();i<m;i++) {
|
for (int i = 0,m=size();i<m;i++) {
|
||||||
joiner.add(KEY_TO_STRING(peek(i)));
|
joiner.add(KEY_TO_STRING(peek(i)));
|
||||||
}
|
}
|
||||||
return joiner.toString();
|
return joiner.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+522
-437
@@ -1,438 +1,523 @@
|
|||||||
package speiger.src.collections.PACKAGE.queues;
|
package speiger.src.collections.PACKAGE.queues;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
#if TYPE_OBJECT
|
#if TYPE_OBJECT
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
#endif
|
#endif
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.NoSuchElementException;
|
#if JDK_TYPE
|
||||||
|
import java.util.OPTIONAL;
|
||||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
#if SPLIT_ITERATOR_FEATURE && STREAM_FEATURE
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
import java.util.stream.JAVA_STREAM;
|
||||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
#else
|
||||||
#endif
|
import java.util.stream.Stream;
|
||||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
import java.util.stream.Collector;
|
||||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
#endif
|
||||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
#endif
|
||||||
import speiger.src.collections.utils.ITrimmable;
|
#endif
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
/**
|
#if JDK_FUNCTION
|
||||||
* A Simple First In First Out Priority Queue that is a Good Replacement for a linked list (or ArrayDequeue)
|
import java.util.function.PREDICATE;
|
||||||
* Its specific implementation uses a backing array that grows and shrinks as it is needed.
|
#endif
|
||||||
* @Type(T)
|
|
||||||
*/
|
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||||
public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEUE KEY_GENERIC_TYPE implements PRIORITY_DEQUEUE KEY_GENERIC_TYPE, ITrimmable
|
#if !JDK_TYPE
|
||||||
{
|
import speiger.src.collections.PACKAGE.functions.OPTIONAL;
|
||||||
/** Max Possible ArraySize without the JVM Crashing */
|
#endif
|
||||||
private static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8;
|
#if !TYPE_OBJECT
|
||||||
/** The Minimum Capacity that is allowed */
|
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||||
public static final int MIN_CAPACITY = 4;
|
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||||
/** The Backing array */
|
#endif
|
||||||
protected transient KEY_TYPE[] array;
|
import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
|
||||||
/** The First Index pointer */
|
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||||
protected int first;
|
#if !JDK_FUNCTION
|
||||||
/** The Last Index pointer */
|
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||||
protected int last;
|
#endif
|
||||||
/** The Minimum Capacity of the Queue **/
|
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||||
protected int minCapacity;
|
import speiger.src.collections.utils.ITrimmable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor using a initial array
|
* A Simple First In First Out Priority Queue that is a Good Replacement for a linked list (or ArrayDequeue)
|
||||||
* @param values the Array that should be used
|
* Its specific implementation uses a backing array that grows and shrinks as it is needed.
|
||||||
*/
|
* @Type(T)
|
||||||
public ARRAY_FIFO_QUEUE(KEY_TYPE[] values) {
|
*/
|
||||||
this(values, 0, values.length);
|
public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEUE KEY_GENERIC_TYPE implements PRIORITY_DEQUEUE KEY_GENERIC_TYPE, ITrimmable
|
||||||
}
|
{
|
||||||
|
/** Max Possible ArraySize without the JVM Crashing */
|
||||||
/**
|
private static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8;
|
||||||
* Constructor using a initial array
|
/** The Minimum Capacity that is allowed */
|
||||||
* @param values the Array that should be used
|
public static final int MIN_CAPACITY = 4;
|
||||||
* @param size the amount of elements that are in the initial array
|
/** The Backing array */
|
||||||
* @throws IllegalStateException if values is smaller then size
|
protected transient KEY_TYPE[] array;
|
||||||
*/
|
/** The First Index pointer */
|
||||||
public ARRAY_FIFO_QUEUE(KEY_TYPE[] values, int size) {
|
protected int first;
|
||||||
this(values, 0, size);
|
/** The Last Index pointer */
|
||||||
}
|
protected int last;
|
||||||
|
/** The Minimum Capacity of the Queue **/
|
||||||
/**
|
protected int minCapacity;
|
||||||
* Constructor using a initial array
|
|
||||||
* @param values the Array that should be used
|
/**
|
||||||
* @param offset where to begin in the initial array
|
* Constructor using a initial array
|
||||||
* @param size the amount of elements that are in the initial array
|
* @param values the Array that should be used
|
||||||
* @throws IllegalStateException if values is smaller then size
|
*/
|
||||||
*/
|
public ARRAY_FIFO_QUEUE(KEY_TYPE[] values) {
|
||||||
public ARRAY_FIFO_QUEUE(KEY_TYPE[] values, int offset, int size) {
|
this(values, 0, values.length);
|
||||||
if (values.length < size) throw new IllegalArgumentException("Initial array (" + values.length + ") is smaller then the expected size (" + size + ")");
|
}
|
||||||
if(values.length <= 0) values = NEW_KEY_ARRAY(MIN_CAPACITY);
|
|
||||||
else if(values.length < MIN_CAPACITY) values = Arrays.copyOf(values, MIN_CAPACITY);
|
/**
|
||||||
minCapacity = MIN_CAPACITY;
|
* Constructor using a initial array
|
||||||
array = values;
|
* @param values the Array that should be used
|
||||||
first = offset;
|
* @param size the amount of elements that are in the initial array
|
||||||
last = (offset + size) % array.length;
|
* @throws IllegalStateException if values is smaller then size
|
||||||
if(array.length == size) expand();
|
*/
|
||||||
}
|
public ARRAY_FIFO_QUEUE(KEY_TYPE[] values, int size) {
|
||||||
|
this(values, 0, size);
|
||||||
/**
|
}
|
||||||
* Constructor with a Min Capacity
|
|
||||||
* @param capacity the initial capacity of the backing array
|
/**
|
||||||
* @throws IllegalStateException if the initial size is smaller 0
|
* Constructor using a initial array
|
||||||
*/
|
* @param values the Array that should be used
|
||||||
public ARRAY_FIFO_QUEUE(int capacity) {
|
* @param offset where to begin in the initial array
|
||||||
if (capacity < 0) throw new IllegalArgumentException("Initial capacity (" + capacity + ") is negative");
|
* @param size the amount of elements that are in the initial array
|
||||||
array = NEW_KEY_ARRAY(Math.max(MIN_CAPACITY, capacity+1));
|
* @throws IllegalStateException if values is smaller then size
|
||||||
minCapacity = array.length;
|
*/
|
||||||
}
|
public ARRAY_FIFO_QUEUE(KEY_TYPE[] values, int offset, int size) {
|
||||||
|
if (values.length < size) throw new IllegalArgumentException("Initial array (" + values.length + ") is smaller then the expected size (" + size + ")");
|
||||||
/**
|
if(values.length <= 0) values = NEW_KEY_ARRAY(MIN_CAPACITY);
|
||||||
* Default Construtor
|
else if(values.length < MIN_CAPACITY) values = Arrays.copyOf(values, MIN_CAPACITY);
|
||||||
*/
|
minCapacity = MIN_CAPACITY;
|
||||||
public ARRAY_FIFO_QUEUE() {
|
array = values;
|
||||||
this(MIN_CAPACITY);
|
first = offset;
|
||||||
}
|
last = (offset + size) % array.length;
|
||||||
|
if(array.length == size) expand();
|
||||||
@Override
|
}
|
||||||
public ITERATOR KEY_GENERIC_TYPE iterator() {
|
|
||||||
return new Iter();
|
/**
|
||||||
}
|
* Constructor with a Min Capacity
|
||||||
|
* @param capacity the initial capacity of the backing array
|
||||||
@Override
|
* @throws IllegalStateException if the initial size is smaller 0
|
||||||
public int size() {
|
*/
|
||||||
final int apparentLength = last - first;
|
public ARRAY_FIFO_QUEUE(int capacity) {
|
||||||
return apparentLength >= 0 ? apparentLength : array.length + apparentLength;
|
if (capacity < 0) throw new IllegalArgumentException("Initial capacity (" + capacity + ") is negative");
|
||||||
}
|
array = NEW_KEY_ARRAY(Math.max(MIN_CAPACITY, capacity+1));
|
||||||
|
minCapacity = array.length;
|
||||||
@Override
|
}
|
||||||
public void clear() {
|
|
||||||
#if TYPE_OBJECT
|
/**
|
||||||
Arrays.fill(array, null);
|
* Default Construtor
|
||||||
#endif
|
*/
|
||||||
first = last = 0;
|
public ARRAY_FIFO_QUEUE() {
|
||||||
}
|
this(MIN_CAPACITY);
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public void enqueue(KEY_TYPE e) {
|
#if JDK_TYPE && SPLIT_ITERATOR_FEATURE && STREAM_FEATURE
|
||||||
array[last++] = e;
|
#if TYPE_OBJECT
|
||||||
if(last == array.length) last = 0;
|
/**
|
||||||
if(last == first) expand();
|
* Creates a Collector for a ArrayFIFOQueue
|
||||||
}
|
* @Type(T)
|
||||||
|
* @return a collector
|
||||||
@Override
|
*/
|
||||||
public void enqueueFirst(KEY_TYPE e) {
|
public static <T> Collector<T, ARRAY_FIFO_QUEUE<T>, ARRAY_FIFO_QUEUE<T>> toQueue() {
|
||||||
if(first == 0) first = array.length;
|
return Collector.of(ARRAY_FIFO_QUEUE::new, ARRAY_FIFO_QUEUE::enqueue, ARRAY_FIFO_QUEUE::merge);
|
||||||
array[--first] = e;
|
}
|
||||||
if(first == last) expand();
|
|
||||||
}
|
/**
|
||||||
|
* Collects a Stream to a ArrayFIFOQueue
|
||||||
@Override
|
* @Type(T)
|
||||||
public KEY_TYPE dequeue() {
|
* @return a queue with the contents of the Stream
|
||||||
if(first == last) throw new NoSuchElementException();
|
*/
|
||||||
KEY_TYPE data = array[first];
|
public static <T> ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE toQueue(Stream<T> stream) {
|
||||||
#if TYPE_OBJECT
|
return stream.collect(ARRAY_FIFO_QUEUE::new, ARRAY_FIFO_QUEUE::enqueue, ARRAY_FIFO_QUEUE::merge);
|
||||||
array[first] = null;
|
}
|
||||||
#endif
|
|
||||||
if(++first == array.length) first = 0;
|
private ARRAY_FIFO_QUEUE<T> merge(ARRAY_FIFO_QUEUE<T> a) {
|
||||||
reduce();
|
enqueueAll(a.toArray((T[])new Object[a.size()]));
|
||||||
return data;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
#else
|
||||||
public KEY_TYPE dequeueLast() {
|
/**
|
||||||
if(first == last) throw new NoSuchElementException();
|
* Collects a Stream to a ArrayFIFOQueue
|
||||||
if(last == 0) last = array.length;
|
* @return a queue with the contents of the Stream
|
||||||
KEY_TYPE data = array[--last];
|
*/
|
||||||
#if TYPE_OBJECT
|
public static ARRAY_FIFO_QUEUE toQueue(JAVA_STREAM stream) {
|
||||||
array[last] = null;
|
return stream.collect(ARRAY_FIFO_QUEUE::new, ARRAY_FIFO_QUEUE::enqueue, ARRAY_FIFO_QUEUE::merge);
|
||||||
#endif
|
}
|
||||||
reduce();
|
|
||||||
return data;
|
private ARRAY_FIFO_QUEUE merge(ARRAY_FIFO_QUEUE a) {
|
||||||
}
|
enqueueAll(a.TO_ARRAY());
|
||||||
|
return this;
|
||||||
@Override
|
}
|
||||||
public KEY_TYPE peek(int index) {
|
|
||||||
if(first == last || index < 0 || index > size()) throw new NoSuchElementException();
|
#endif
|
||||||
index += first;
|
#endif
|
||||||
return index > array.length ? array[index-array.length] : array[index];
|
@Override
|
||||||
}
|
public ITERATOR KEY_GENERIC_TYPE iterator() {
|
||||||
|
return new Iter();
|
||||||
@Override
|
}
|
||||||
public boolean removeFirst(KEY_TYPE e) {
|
|
||||||
if(first == last) return false;
|
@Override
|
||||||
for(int i = 0,m=size();i<m;i++) {
|
public int size() {
|
||||||
int index = (first + i) % array.length;
|
final int apparentLength = last - first;
|
||||||
if(e == array[index])
|
return apparentLength >= 0 ? apparentLength : array.length + apparentLength;
|
||||||
return removeIndex(index);
|
}
|
||||||
}
|
|
||||||
return false;
|
@Override
|
||||||
}
|
public void clear() {
|
||||||
|
if(first != last) {
|
||||||
@Override
|
#if TYPE_OBJECT
|
||||||
public boolean removeLast(KEY_TYPE e) {
|
Arrays.fill(array, null);
|
||||||
if(first == last) return false;
|
#endif
|
||||||
for(int i = size()-1;i>=0;i--) {
|
first = last = 0;
|
||||||
int index = (first + i) % array.length;
|
}
|
||||||
if(e == array[index])
|
else if(first != 0) {
|
||||||
return removeIndex(index);
|
first = last = 0;
|
||||||
}
|
}
|
||||||
return false;
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
protected boolean removeIndex(int index) {
|
public void enqueue(KEY_TYPE e) {
|
||||||
if(first >= last ? index < first && index > last : index < first || index > last) return false;
|
array[last++] = e;
|
||||||
if(index == first) {
|
if(last == array.length) last = 0;
|
||||||
#if TYPE_OBJECT
|
if(last == first) expand();
|
||||||
array[first] = null;
|
}
|
||||||
#endif
|
|
||||||
first++;
|
@Override
|
||||||
}
|
public void enqueueFirst(KEY_TYPE e) {
|
||||||
else if(index == last) {
|
if(first == 0) first = array.length;
|
||||||
last--;
|
array[--first] = e;
|
||||||
#if TYPE_OBJECT
|
if(first == last) expand();
|
||||||
array[last] = null;
|
}
|
||||||
#endif
|
|
||||||
}
|
@Override
|
||||||
else if(index > last) {
|
public KEY_TYPE dequeue() {
|
||||||
System.arraycopy(array, first, array, first+1, (index - first));
|
if(first == last) throw new NoSuchElementException();
|
||||||
#if TYPE_OBJECT
|
KEY_TYPE data = array[first];
|
||||||
array[first] = null;
|
#if TYPE_OBJECT
|
||||||
#endif
|
array[first] = null;
|
||||||
first = ++first % array.length;
|
#endif
|
||||||
}
|
if(++first == array.length) first = 0;
|
||||||
else if(index < first) {
|
reduce();
|
||||||
System.arraycopy(array, index+1, array, index, (last - index) - 1);
|
return data;
|
||||||
#if TYPE_OBJECT
|
}
|
||||||
array[last] = null;
|
|
||||||
#endif
|
@Override
|
||||||
if(--last < 0) last += array.length;
|
public KEY_TYPE dequeueLast() {
|
||||||
}
|
if(first == last) throw new NoSuchElementException();
|
||||||
else {
|
if(last == 0) last = array.length;
|
||||||
if(index - first < last - index) {
|
KEY_TYPE data = array[--last];
|
||||||
System.arraycopy(array, first, array, first+1, (index - first));
|
#if TYPE_OBJECT
|
||||||
#if TYPE_OBJECT
|
array[last] = null;
|
||||||
array[first] = null;
|
#endif
|
||||||
#endif
|
reduce();
|
||||||
first = ++first % array.length;
|
return data;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
System.arraycopy(array, index+1, array, index, (last - index) - 1);
|
@Override
|
||||||
#if TYPE_OBJECT
|
public KEY_TYPE peek(int index) {
|
||||||
array[last] = null;
|
if(first == last || index < 0 || index >= size()) throw new NoSuchElementException();
|
||||||
#endif
|
index += first;
|
||||||
if(--last < 0) last += array.length;
|
return index >= array.length ? array[index-array.length] : array[index];
|
||||||
}
|
}
|
||||||
}
|
|
||||||
reduce();
|
@Override
|
||||||
return true;
|
public boolean contains(KEY_TYPE e) {
|
||||||
}
|
if(first == last) return false;
|
||||||
|
for(int i = 0,m=size();i<m;i++) {
|
||||||
@Override
|
if(e == array[(first + i) % array.length]) return true;
|
||||||
public void onChanged() {}
|
}
|
||||||
|
return false;
|
||||||
@Override
|
}
|
||||||
public ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE copy() {
|
|
||||||
ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE queue = new ARRAY_FIFO_QUEUEBRACES();
|
@Override
|
||||||
queue.first = first;
|
public boolean removeFirst(KEY_TYPE e) {
|
||||||
queue.last = last;
|
if(first == last) return false;
|
||||||
queue.minCapacity = minCapacity;
|
for(int i = 0,m=size();i<m;i++) {
|
||||||
queue.array = Arrays.copyOf(array, array.length);
|
int index = (first + i) % array.length;
|
||||||
return queue;
|
if(e == array[index])
|
||||||
}
|
return removeIndex(index);
|
||||||
|
}
|
||||||
@Override
|
return false;
|
||||||
public COMPARATOR KEY_SUPER_GENERIC_TYPE comparator() { return null; }
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) {
|
public boolean removeLast(KEY_TYPE e) {
|
||||||
Objects.requireNonNull(action);
|
if(first == last) return false;
|
||||||
if(first == last) return;
|
for(int i = size()-1;i>=0;i--) {
|
||||||
for(int i = 0,m=size();i<m;i++)
|
int index = (first + i) % array.length;
|
||||||
action.accept(array[(first + i) % array.length]);
|
if(e == array[index])
|
||||||
clearAndTrim(0);
|
return removeIndex(index);
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
@Override
|
}
|
||||||
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
|
||||||
Objects.requireNonNull(action);
|
protected boolean removeIndex(int index) {
|
||||||
if(first == last) return;
|
if(first >= last ? index < first && index > last : index < first || index > last) return false;
|
||||||
for(int i = 0,m=size();i<m;i++)
|
if(index == first) {
|
||||||
action.accept(input, array[(first + i) % array.length]);
|
#if TYPE_OBJECT
|
||||||
clearAndTrim(0);
|
array[first] = null;
|
||||||
}
|
#endif
|
||||||
|
first++;
|
||||||
@Override
|
}
|
||||||
public boolean matchesAny(PREDICATE KEY_GENERIC_TYPE filter) {
|
else if(index == last) {
|
||||||
Objects.requireNonNull(filter);
|
last--;
|
||||||
for(int i = 0,m=size();i<m;i++) {
|
#if TYPE_OBJECT
|
||||||
if(filter.TEST_VALUE(array[(first + i) % array.length])) return true;
|
array[last] = null;
|
||||||
}
|
#endif
|
||||||
return false;
|
}
|
||||||
}
|
else if(index > last) {
|
||||||
|
System.arraycopy(array, first, array, first+1, (index - first));
|
||||||
@Override
|
#if TYPE_OBJECT
|
||||||
public boolean matchesNone(PREDICATE KEY_GENERIC_TYPE filter) {
|
array[first] = null;
|
||||||
Objects.requireNonNull(filter);
|
#endif
|
||||||
for(int i = 0,m=size();i<m;i++) {
|
first = ++first % array.length;
|
||||||
if(filter.TEST_VALUE(array[(first + i) % array.length])) return false;
|
}
|
||||||
}
|
else if(index < first) {
|
||||||
return true;
|
System.arraycopy(array, index+1, array, index, (last - index) - 1);
|
||||||
}
|
#if TYPE_OBJECT
|
||||||
|
array[last] = null;
|
||||||
@Override
|
#endif
|
||||||
public boolean matchesAll(PREDICATE KEY_GENERIC_TYPE filter) {
|
if(--last < 0) last += array.length;
|
||||||
Objects.requireNonNull(filter);
|
}
|
||||||
for(int i = 0,m=size();i<m;i++) {
|
else {
|
||||||
if(!filter.TEST_VALUE(array[(first + i) % array.length])) return false;
|
if(index - first < last - index) {
|
||||||
}
|
System.arraycopy(array, first, array, first+1, (index - first));
|
||||||
return true;
|
#if TYPE_OBJECT
|
||||||
}
|
array[first] = null;
|
||||||
|
#endif
|
||||||
@Override
|
first = ++first % array.length;
|
||||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
}
|
||||||
Objects.requireNonNull(filter);
|
else {
|
||||||
for(int i = 0,m=size();i<m;i++) {
|
System.arraycopy(array, index+1, array, index, (last - index) - 1);
|
||||||
int index = (first + i) % array.length;
|
#if TYPE_OBJECT
|
||||||
if(filter.TEST_VALUE(array[index])) {
|
array[last] = null;
|
||||||
KEY_TYPE data = array[index];
|
#endif
|
||||||
removeIndex(index);
|
if(--last < 0) last += array.length;
|
||||||
return data;
|
}
|
||||||
}
|
}
|
||||||
}
|
reduce();
|
||||||
return EMPTY_VALUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !TYPE_OBJECT
|
@Override
|
||||||
@Override
|
public void onChanged() {}
|
||||||
public KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
|
||||||
Objects.requireNonNull(operator);
|
@Override
|
||||||
KEY_TYPE state = identity;
|
public ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE copy() {
|
||||||
for(int i = 0,m=size();i<m;i++) {
|
ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE queue = new ARRAY_FIFO_QUEUEBRACES();
|
||||||
state = operator.APPLY_VALUE(state, array[(first + i) % array.length]);
|
queue.first = first;
|
||||||
}
|
queue.last = last;
|
||||||
return state;
|
queue.minCapacity = minCapacity;
|
||||||
}
|
queue.array = Arrays.copyOf(array, array.length);
|
||||||
|
return queue;
|
||||||
#else
|
}
|
||||||
@Override
|
|
||||||
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
|
@Override
|
||||||
Objects.requireNonNull(operator);
|
public COMPARATOR KEY_SUPER_GENERIC_TYPE comparator() { return null; }
|
||||||
KEY_SPECIAL_TYPE state = identity;
|
|
||||||
for(int i = 0,m=size();i<m;i++) {
|
@Override
|
||||||
state = operator.APPLY_VALUE(state, array[(first + i) % array.length]);
|
public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) {
|
||||||
}
|
Objects.requireNonNull(action);
|
||||||
return state;
|
if(first == last) return;
|
||||||
}
|
for(int i = 0,m=size();i<m;i++)
|
||||||
|
action.accept(array[(first + i) % array.length]);
|
||||||
#endif
|
clearAndTrim(0);
|
||||||
@Override
|
}
|
||||||
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
|
||||||
Objects.requireNonNull(operator);
|
@Override
|
||||||
KEY_TYPE state = EMPTY_VALUE;
|
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
|
||||||
boolean empty = true;
|
Objects.requireNonNull(action);
|
||||||
for(int i = 0,m=size();i<m;i++) {
|
if(first == last) return;
|
||||||
if(empty) {
|
for(int i = 0,m=size();i<m;i++)
|
||||||
empty = false;
|
action.accept(i, array[(first + i) % array.length]);
|
||||||
state = array[(first + i) % array.length];
|
clearAndTrim(0);
|
||||||
continue;
|
}
|
||||||
}
|
|
||||||
state = operator.APPLY_VALUE(state, array[(first + i) % array.length]);
|
@Override
|
||||||
}
|
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
||||||
return state;
|
Objects.requireNonNull(action);
|
||||||
}
|
if(first == last) return;
|
||||||
|
for(int i = 0,m=size();i<m;i++)
|
||||||
@Override
|
action.accept(input, array[(first + i) % array.length]);
|
||||||
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
|
clearAndTrim(0);
|
||||||
Objects.requireNonNull(filter);
|
}
|
||||||
int result = 0;
|
|
||||||
for(int i = 0,m=size();i<m;i++) {
|
@Override
|
||||||
if(filter.TEST_VALUE(array[(first + i) % array.length])) result++;
|
public boolean matchesAny(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
}
|
Objects.requireNonNull(filter);
|
||||||
return result;
|
for(int i = 0,m=size();i<m;i++) {
|
||||||
}
|
if(filter.test(array[(first + i) % array.length])) return true;
|
||||||
|
}
|
||||||
@Override
|
return false;
|
||||||
public boolean trim(int size) {
|
}
|
||||||
int newSize = Math.max(Math.max(size, size()), minCapacity);
|
|
||||||
if(newSize >= array.length) return false;
|
@Override
|
||||||
KEY_TYPE[] newArray = NEW_KEY_ARRAY(newSize);
|
public boolean matchesNone(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
if(first <= last) System.arraycopy(array, first, newArray, 0, last - first);
|
Objects.requireNonNull(filter);
|
||||||
else {
|
for(int i = 0,m=size();i<m;i++) {
|
||||||
System.arraycopy(array, first, newArray, 0, array.length - first);
|
if(filter.test(array[(first + i) % array.length])) return false;
|
||||||
System.arraycopy(array, 0, newArray, array.length - first, last);
|
}
|
||||||
}
|
return true;
|
||||||
first = 0;
|
}
|
||||||
last = size();
|
|
||||||
array = newArray;
|
@Override
|
||||||
return true;
|
public boolean matchesAll(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
}
|
Objects.requireNonNull(filter);
|
||||||
|
for(int i = 0,m=size();i<m;i++) {
|
||||||
/**
|
if(!filter.test(array[(first + i) % array.length])) return false;
|
||||||
* Trims the collection down to the requested size and clears all elements while doing so
|
}
|
||||||
* @param size the amount of elements that should be allowed
|
return true;
|
||||||
* @note this will enforce minimum size of the collection itself
|
}
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public void clearAndTrim(int size) {
|
public OPTIONAL KEY_GENERIC_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
int newSize = Math.max(minCapacity, size);
|
Objects.requireNonNull(filter);
|
||||||
if(array.length <= newSize) {
|
for(int i = 0,m=size();i<m;i++) {
|
||||||
clear();
|
int index = (first + i) % array.length;
|
||||||
return;
|
if(filter.test(array[index])) {
|
||||||
}
|
KEY_TYPE data = array[index];
|
||||||
first = last = 0;
|
removeIndex(index);
|
||||||
array = NEW_KEY_ARRAY(newSize);
|
return OPTIONAL.GET_OPTIONAL(data);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@Override
|
return OPTIONAL.empty();
|
||||||
public GENERIC_SPECIAL_KEY_BRACES<E> KEY_SPECIAL_TYPE[] TO_ARRAY(KEY_SPECIAL_TYPE[] input) {
|
}
|
||||||
if(input == null || input.length < size()) input = NEW_SPECIAL_KEY_ARRAY(size());
|
|
||||||
if (first <= last) System.arraycopy(array, first, input, 0, last - first);
|
#if !TYPE_OBJECT
|
||||||
else {
|
@Override
|
||||||
System.arraycopy(array, first, input, 0, array.length - first);
|
public KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
System.arraycopy(array, 0, input, array.length - first, last);
|
Objects.requireNonNull(operator);
|
||||||
}
|
KEY_TYPE state = identity;
|
||||||
return input;
|
for(int i = 0,m=size();i<m;i++) {
|
||||||
}
|
state = operator.APPLY_VALUE(state, array[(first + i) % array.length]);
|
||||||
|
}
|
||||||
protected void reduce() {
|
return state;
|
||||||
final int size = size();
|
}
|
||||||
if (array.length > minCapacity && size <= array.length / 4) resize(size, Math.max(array.length / 2, minCapacity));
|
|
||||||
}
|
#else
|
||||||
|
@Override
|
||||||
protected void expand() {
|
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
|
||||||
resize(array.length, (int)Math.min(MAX_ARRAY_SIZE, 2L * array.length));
|
Objects.requireNonNull(operator);
|
||||||
}
|
KEY_SPECIAL_TYPE state = identity;
|
||||||
|
for(int i = 0,m=size();i<m;i++) {
|
||||||
protected final void resize(int oldSize, int newSize) {
|
state = operator.APPLY_VALUE(state, array[(first + i) % array.length]);
|
||||||
KEY_TYPE[] newArray = NEW_KEY_ARRAY(newSize);
|
}
|
||||||
if(first >= last) {
|
return state;
|
||||||
if(oldSize != 0)
|
}
|
||||||
{
|
|
||||||
System.arraycopy(array, first, newArray, 0, array.length - first);
|
#endif
|
||||||
System.arraycopy(array, 0, newArray, array.length - first, last);
|
@Override
|
||||||
}
|
public OPTIONAL KEY_GENERIC_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
}
|
Objects.requireNonNull(operator);
|
||||||
else System.arraycopy(array, first, newArray, 0, last-first);
|
KEY_TYPE state = EMPTY_VALUE;
|
||||||
first = 0;
|
boolean empty = true;
|
||||||
last = oldSize;
|
for(int i = 0,m=size();i<m;i++) {
|
||||||
array = newArray;
|
if(empty) {
|
||||||
}
|
empty = false;
|
||||||
|
state = array[(first + i) % array.length];
|
||||||
private class Iter implements ITERATOR KEY_GENERIC_TYPE
|
continue;
|
||||||
{
|
}
|
||||||
int index = first;
|
state = operator.APPLY_VALUE(state, array[(first + i) % array.length]);
|
||||||
@Override
|
}
|
||||||
public boolean hasNext()
|
return empty ? OPTIONAL.empty() : OPTIONAL.GET_OPTIONAL(state);
|
||||||
{
|
}
|
||||||
return index != last;
|
|
||||||
}
|
@Override
|
||||||
|
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
@Override
|
Objects.requireNonNull(filter);
|
||||||
public KEY_TYPE NEXT() {
|
int result = 0;
|
||||||
KEY_TYPE value = array[index];
|
for(int i = 0,m=size();i<m;i++) {
|
||||||
removeIndex(index);
|
if(filter.test(array[(first + i) % array.length])) result++;
|
||||||
index = ++index % array.length;
|
}
|
||||||
return value;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
|
public boolean trim(int size) {
|
||||||
|
int newSize = Math.max(Math.max(size, size()), minCapacity);
|
||||||
|
if(newSize >= array.length) return false;
|
||||||
|
KEY_TYPE[] newArray = NEW_KEY_ARRAY(newSize);
|
||||||
|
if(first <= last) System.arraycopy(array, first, newArray, 0, last - first);
|
||||||
|
else {
|
||||||
|
System.arraycopy(array, first, newArray, 0, array.length - first);
|
||||||
|
System.arraycopy(array, 0, newArray, array.length - first, last);
|
||||||
|
}
|
||||||
|
first = 0;
|
||||||
|
last = size();
|
||||||
|
array = newArray;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Trims the collection down to the requested size and clears all elements while doing so
|
||||||
|
* @param size the amount of elements that should be allowed
|
||||||
|
* @note this will enforce minimum size of the collection itself
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void clearAndTrim(int size) {
|
||||||
|
int newSize = Math.max(minCapacity, size);
|
||||||
|
if(array.length <= newSize) {
|
||||||
|
clear();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
first = last = 0;
|
||||||
|
array = NEW_KEY_ARRAY(newSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GENERIC_SPECIAL_KEY_BRACES<E> KEY_SPECIAL_TYPE[] TO_ARRAY(KEY_SPECIAL_TYPE[] input) {
|
||||||
|
if(input == null || input.length < size()) input = NEW_SPECIAL_KEY_ARRAY(size());
|
||||||
|
if (first <= last) System.arraycopy(array, first, input, 0, last - first);
|
||||||
|
else {
|
||||||
|
System.arraycopy(array, first, input, 0, array.length - first);
|
||||||
|
System.arraycopy(array, 0, input, array.length - first, last);
|
||||||
|
}
|
||||||
|
return input;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void reduce() {
|
||||||
|
final int size = size();
|
||||||
|
if (array.length > minCapacity && size <= array.length / 4) resize(size, Math.max(array.length / 2, minCapacity));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void expand() {
|
||||||
|
resize(array.length, (int)Math.min(MAX_ARRAY_SIZE, 2L * array.length));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final void resize(int oldSize, int newSize) {
|
||||||
|
KEY_TYPE[] newArray = NEW_KEY_ARRAY(newSize);
|
||||||
|
if(first >= last) {
|
||||||
|
if(oldSize != 0)
|
||||||
|
{
|
||||||
|
System.arraycopy(array, first, newArray, 0, array.length - first);
|
||||||
|
System.arraycopy(array, 0, newArray, array.length - first, last);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else System.arraycopy(array, first, newArray, 0, last-first);
|
||||||
|
first = 0;
|
||||||
|
last = oldSize;
|
||||||
|
array = newArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
private class Iter implements ITERATOR KEY_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
int index = first;
|
||||||
|
@Override
|
||||||
|
public boolean hasNext()
|
||||||
|
{
|
||||||
|
return index != last;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE NEXT() {
|
||||||
|
if(!hasNext()) throw new NoSuchElementException();
|
||||||
|
KEY_TYPE value = array[index];
|
||||||
|
removeIndex(index);
|
||||||
|
index = ++index % array.length;
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+500
-419
@@ -1,420 +1,501 @@
|
|||||||
package speiger.src.collections.PACKAGE.queues;
|
package speiger.src.collections.PACKAGE.queues;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
#if TYPE_OBJECT
|
#if TYPE_OBJECT
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
#endif
|
#endif
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
#if JDK_TYPE
|
||||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
import java.util.OPTIONAL;
|
||||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
#if SPLIT_ITERATOR_FEATURE && STREAM_FEATURE
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
import java.util.stream.JAVA_STREAM;
|
||||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
#else
|
||||||
#endif
|
import java.util.stream.Stream;
|
||||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
import java.util.stream.Collector;
|
||||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
#endif
|
||||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
#endif
|
||||||
import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
#endif
|
||||||
import speiger.src.collections.utils.SanityChecks;
|
#if JDK_FUNCTION
|
||||||
|
import java.util.function.PREDICATE;
|
||||||
/**
|
#endif
|
||||||
* A Array Priority Queue, this is a very unoptimized implementation of the PriorityQueue for very specific usecases.
|
|
||||||
* It allows for duplicated entries and works like {@link java.util.List#indexOf(Object)} search.
|
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||||
* It is highly suggested to use HeapPriorityQueue otherwise, unless you know why you need this specific implementation
|
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||||
* @Type(T)
|
#if !JDK_TYPE
|
||||||
*/
|
import speiger.src.collections.PACKAGE.functions.OPTIONAL;
|
||||||
public class ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEUE KEY_GENERIC_TYPE
|
#endif
|
||||||
{
|
#if !TYPE_OBJECT
|
||||||
/** The Backing Array */
|
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||||
protected transient KEY_TYPE[] array = EMPTY_KEY_ARRAY;
|
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||||
/** The Amount of elements stored within the array */
|
#endif
|
||||||
protected int size;
|
import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
|
||||||
/** The Last known first index pointer */
|
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||||
protected int firstIndex = -1;
|
#if !JDK_FUNCTION
|
||||||
/** The Sorter of the Array */
|
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||||
protected COMPARATOR KEY_SUPER_GENERIC_TYPE comparator;
|
#endif
|
||||||
|
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||||
/**
|
import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
||||||
* Default Constructor
|
import speiger.src.collections.utils.SanityChecks;
|
||||||
*/
|
|
||||||
public ARRAY_PRIORITY_QUEUE() {
|
/**
|
||||||
this(0, null);
|
* A Array Priority Queue, this is a very unoptimized implementation of the PriorityQueue for very specific usecases.
|
||||||
}
|
* It allows for duplicated entries and works like {@link java.util.List#indexOf(Object)} search.
|
||||||
|
* It is highly suggested to use HeapPriorityQueue otherwise, unless you know why you need this specific implementation
|
||||||
/**
|
* @Type(T)
|
||||||
* Constructor using custom sorter
|
*/
|
||||||
* @param comp Comparator to sort the Array. Can be null
|
public class ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEUE KEY_GENERIC_TYPE
|
||||||
*/
|
{
|
||||||
public ARRAY_PRIORITY_QUEUE(COMPARATOR KEY_SUPER_GENERIC_TYPE comp) {
|
/** The Backing Array */
|
||||||
this(0, comp);
|
protected transient KEY_TYPE[] array = EMPTY_KEY_ARRAY;
|
||||||
}
|
/** The Amount of elements stored within the array */
|
||||||
|
protected int size;
|
||||||
/**
|
/** The Last known first index pointer */
|
||||||
* Constructor with a Min Capacity
|
protected int firstIndex = -1;
|
||||||
* @param size the initial capacity of the backing array
|
/** The Sorter of the Array */
|
||||||
* @throws IllegalStateException if the initial size is smaller 0
|
protected COMPARATOR KEY_SUPER_GENERIC_TYPE comparator;
|
||||||
*/
|
|
||||||
public ARRAY_PRIORITY_QUEUE(int size) {
|
/**
|
||||||
this(size, null);
|
* Default Constructor
|
||||||
}
|
*/
|
||||||
|
public ARRAY_PRIORITY_QUEUE() {
|
||||||
/**
|
this(0, null);
|
||||||
* Constructor with a Min Capacity and custom Sorter
|
}
|
||||||
* @param size the initial capacity of the backing array
|
|
||||||
* @param comp Comparator to sort the Array. Can be null
|
/**
|
||||||
* @throws IllegalStateException if the initial size is smaller 0
|
* Constructor using custom sorter
|
||||||
*/
|
* @param comp Comparator to sort the Array. Can be null
|
||||||
public ARRAY_PRIORITY_QUEUE(int size, COMPARATOR KEY_SUPER_GENERIC_TYPE comp) {
|
*/
|
||||||
if(size < 0) throw new IllegalAccessError("Size has to be 0 or positive");
|
public ARRAY_PRIORITY_QUEUE(COMPARATOR KEY_SUPER_GENERIC_TYPE comp) {
|
||||||
if(size > 0) array = NEW_KEY_ARRAY(size);
|
this(0, comp);
|
||||||
comparator = comp;
|
}
|
||||||
}
|
|
||||||
|
/**
|
||||||
/**
|
* Constructor with a Min Capacity
|
||||||
* Constructor using a initial array
|
* @param size the initial capacity of the backing array
|
||||||
* @param array the Array that should be used
|
* @throws IllegalStateException if the initial size is smaller 0
|
||||||
*/
|
*/
|
||||||
public ARRAY_PRIORITY_QUEUE(KEY_TYPE[] array) {
|
public ARRAY_PRIORITY_QUEUE(int size) {
|
||||||
this(array, array.length);
|
this(size, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor using a initial array
|
* Constructor with a Min Capacity and custom Sorter
|
||||||
* @param array the Array that should be used
|
* @param size the initial capacity of the backing array
|
||||||
* @param size the amount of elements found within the array
|
* @param comp Comparator to sort the Array. Can be null
|
||||||
* @throws NegativeArraySizeException if size is smaller then 0
|
* @throws IllegalStateException if the initial size is smaller 0
|
||||||
*/
|
*/
|
||||||
public ARRAY_PRIORITY_QUEUE(KEY_TYPE[] array, int size) {
|
public ARRAY_PRIORITY_QUEUE(int size, COMPARATOR KEY_SUPER_GENERIC_TYPE comp) {
|
||||||
this.array = Arrays.copyOf(array, size);
|
if(size < 0) throw new IllegalAccessError("Size has to be 0 or positive");
|
||||||
this.size = size;
|
if(size > 0) array = NEW_KEY_ARRAY(size);
|
||||||
}
|
comparator = comp;
|
||||||
|
}
|
||||||
/**
|
|
||||||
* Constructor using a initial array and a custom sorter
|
/**
|
||||||
* @param array the Array that should be used
|
* Constructor using a initial array
|
||||||
* @param comp Comparator to sort the Array. Can be null
|
* @param array the Array that should be used
|
||||||
*/
|
*/
|
||||||
public ARRAY_PRIORITY_QUEUE(KEY_TYPE[] array, COMPARATOR KEY_SUPER_GENERIC_TYPE comp) {
|
public ARRAY_PRIORITY_QUEUE(KEY_TYPE[] array) {
|
||||||
this(array, array.length, comp);
|
this(array, array.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor using a initial array and a custom sorter
|
* Constructor using a initial array
|
||||||
* @param array the Array that should be used
|
* @param array the Array that should be used
|
||||||
* @param size the amount of elements found within the array
|
* @param size the amount of elements found within the array
|
||||||
* @param comp Comparator to sort the Array. Can be null
|
* @throws NegativeArraySizeException if size is smaller then 0
|
||||||
* @throws NegativeArraySizeException if size is smaller then 0
|
*/
|
||||||
*/
|
public ARRAY_PRIORITY_QUEUE(KEY_TYPE[] array, int size) {
|
||||||
public ARRAY_PRIORITY_QUEUE(KEY_TYPE[] array, int size, COMPARATOR KEY_SUPER_GENERIC_TYPE comp) {
|
this.array = Arrays.copyOf(array, size);
|
||||||
this.array = Arrays.copyOf(array, size);
|
this.size = size;
|
||||||
this.size = size;
|
}
|
||||||
this.comparator = comp;
|
|
||||||
}
|
/**
|
||||||
|
* Constructor using a initial array and a custom sorter
|
||||||
/**
|
* @param array the Array that should be used
|
||||||
* Constructor using a Collection
|
* @param comp Comparator to sort the Array. Can be null
|
||||||
* @param c the Collection that should be used
|
*/
|
||||||
*/
|
public ARRAY_PRIORITY_QUEUE(KEY_TYPE[] array, COMPARATOR KEY_SUPER_GENERIC_TYPE comp) {
|
||||||
public ARRAY_PRIORITY_QUEUE(COLLECTION KEY_GENERIC_TYPE c) {
|
this(array, array.length, comp);
|
||||||
array = CAST_KEY_ARRAY c.TO_ARRAY();
|
}
|
||||||
size = c.size();
|
|
||||||
}
|
/**
|
||||||
|
* Constructor using a initial array and a custom sorter
|
||||||
/**
|
* @param array the Array that should be used
|
||||||
* Constructor using a Collection and a custom sorter
|
* @param size the amount of elements found within the array
|
||||||
* @param c the Collection that should be used
|
* @param comp Comparator to sort the Array. Can be null
|
||||||
* @param comp Comparator to sort the Array. Can be null
|
* @throws NegativeArraySizeException if size is smaller then 0
|
||||||
*/
|
*/
|
||||||
public ARRAY_PRIORITY_QUEUE(COLLECTION KEY_GENERIC_TYPE c, COMPARATOR KEY_SUPER_GENERIC_TYPE comp) {
|
public ARRAY_PRIORITY_QUEUE(KEY_TYPE[] array, int size, COMPARATOR KEY_SUPER_GENERIC_TYPE comp) {
|
||||||
array = CAST_KEY_ARRAY c.TO_ARRAY();
|
this.array = Arrays.copyOf(array, size);
|
||||||
size = c.size();
|
this.size = size;
|
||||||
comparator = comp;
|
this.comparator = comp;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrapping method to help serialization
|
* Constructor using a Collection
|
||||||
* @param array the array that should be used
|
* @param c the Collection that should be used
|
||||||
* @Type(T)
|
*/
|
||||||
* @return a ArrayPriorityQueue containing the original input array
|
public ARRAY_PRIORITY_QUEUE(COLLECTION KEY_GENERIC_TYPE c) {
|
||||||
*/
|
array = CAST_KEY_ARRAY c.TO_ARRAY();
|
||||||
public static GENERIC_KEY_BRACES ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE wrap(KEY_TYPE[] array) {
|
size = c.size();
|
||||||
return wrap(array, array.length);
|
}
|
||||||
}
|
|
||||||
|
/**
|
||||||
/**
|
* Constructor using a Collection and a custom sorter
|
||||||
* Wrapping method to help serialization
|
* @param c the Collection that should be used
|
||||||
* @param array the array that should be used
|
* @param comp Comparator to sort the Array. Can be null
|
||||||
* @param size the amount of elements within the array
|
*/
|
||||||
* @Type(T)
|
public ARRAY_PRIORITY_QUEUE(COLLECTION KEY_GENERIC_TYPE c, COMPARATOR KEY_SUPER_GENERIC_TYPE comp) {
|
||||||
* @return a ArrayPriorityQueue containing the original input array
|
array = CAST_KEY_ARRAY c.TO_ARRAY();
|
||||||
*/
|
size = c.size();
|
||||||
public static GENERIC_KEY_BRACES ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE wrap(KEY_TYPE[] array, int size) {
|
comparator = comp;
|
||||||
ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE queue = new ARRAY_PRIORITY_QUEUEBRACES();
|
}
|
||||||
queue.array = array;
|
|
||||||
queue.size = size;
|
/**
|
||||||
return queue;
|
* Wrapping method to help serialization
|
||||||
}
|
* @param array the array that should be used
|
||||||
|
* @Type(T)
|
||||||
/**
|
* @return a ArrayPriorityQueue containing the original input array
|
||||||
* Wrapping method to help serialization, using a custom sorter
|
*/
|
||||||
* @param array the array that should be used
|
public static GENERIC_KEY_BRACES ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE wrap(KEY_TYPE[] array) {
|
||||||
* @param comp Comparator to sort the Array. Can be null
|
return wrap(array, array.length);
|
||||||
* @Type(T)
|
}
|
||||||
* @return a ArrayPriorityQueue containing the original input array
|
|
||||||
*/
|
/**
|
||||||
public static GENERIC_KEY_BRACES ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE wrap(KEY_TYPE[] array, COMPARATOR KEY_SUPER_GENERIC_TYPE comp) {
|
* Wrapping method to help serialization
|
||||||
return wrap(array, array.length, comp);
|
* @param array the array that should be used
|
||||||
}
|
* @param size the amount of elements within the array
|
||||||
|
* @Type(T)
|
||||||
/**
|
* @return a ArrayPriorityQueue containing the original input array
|
||||||
* Wrapping method to help serialization, using a custom sorter
|
*/
|
||||||
* @param array the array that should be used
|
public static GENERIC_KEY_BRACES ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE wrap(KEY_TYPE[] array, int size) {
|
||||||
* @param size the amount of elements within the array
|
ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE queue = new ARRAY_PRIORITY_QUEUEBRACES();
|
||||||
* @param comp Comparator to sort the Array. Can be null
|
queue.array = array;
|
||||||
* @Type(T)
|
queue.size = size;
|
||||||
* @return a ArrayPriorityQueue containing the original input array
|
return queue;
|
||||||
*/
|
}
|
||||||
public static GENERIC_KEY_BRACES ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE wrap(KEY_TYPE[] array, int size, COMPARATOR KEY_SUPER_GENERIC_TYPE comp) {
|
|
||||||
ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE queue = new ARRAY_PRIORITY_QUEUEBRACES(comp);
|
/**
|
||||||
queue.array = array;
|
* Wrapping method to help serialization, using a custom sorter
|
||||||
queue.size = size;
|
* @param array the array that should be used
|
||||||
return queue;
|
* @param comp Comparator to sort the Array. Can be null
|
||||||
}
|
* @Type(T)
|
||||||
|
* @return a ArrayPriorityQueue containing the original input array
|
||||||
@Override
|
*/
|
||||||
public void enqueue(KEY_TYPE e) {
|
public static GENERIC_KEY_BRACES ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE wrap(KEY_TYPE[] array, COMPARATOR KEY_SUPER_GENERIC_TYPE comp) {
|
||||||
if(size == array.length) array = Arrays.copyOf(array, (int)Math.max(Math.min((long)array.length + (array.length >> 1), SanityChecks.MAX_ARRAY_SIZE), size+1));
|
return wrap(array, array.length, comp);
|
||||||
if(firstIndex != -1){
|
}
|
||||||
int compare = comparator == null ? COMPAREABLE_TO_KEY(e, array[firstIndex]) : comparator.compare(e, array[firstIndex]);
|
|
||||||
if(compare < 0) firstIndex = size;
|
/**
|
||||||
else if(compare > 0) firstIndex = -1;
|
* Wrapping method to help serialization, using a custom sorter
|
||||||
}
|
* @param array the array that should be used
|
||||||
array[size++] = e;
|
* @param size the amount of elements within the array
|
||||||
}
|
* @param comp Comparator to sort the Array. Can be null
|
||||||
|
* @Type(T)
|
||||||
@Override
|
* @return a ArrayPriorityQueue containing the original input array
|
||||||
public KEY_TYPE dequeue() {
|
*/
|
||||||
if(size <= 0) throw new NoSuchElementException();
|
public static GENERIC_KEY_BRACES ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE wrap(KEY_TYPE[] array, int size, COMPARATOR KEY_SUPER_GENERIC_TYPE comp) {
|
||||||
int index = findFirstIndex();
|
ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE queue = new ARRAY_PRIORITY_QUEUEBRACES(comp);
|
||||||
KEY_TYPE value = array[index];
|
queue.array = array;
|
||||||
if(index != --size) System.arraycopy(array, index+1, array, index, size - index);
|
queue.size = size;
|
||||||
#if TYPE_OBJECT
|
return queue;
|
||||||
array[size] = null;
|
}
|
||||||
#endif
|
#if JDK_TYPE && SPLIT_ITERATOR_FEATURE && STREAM_FEATURE
|
||||||
firstIndex = -1;
|
#if TYPE_OBJECT
|
||||||
return value;
|
/**
|
||||||
}
|
* Creates a Collector for a ArrayPriorityQueue
|
||||||
|
* @Type(T)
|
||||||
@Override
|
* @return a collector
|
||||||
public KEY_TYPE peek(int index) {
|
*/
|
||||||
if(index < 0 || index >= size) throw new NoSuchElementException();
|
public static <T> Collector<T, ARRAY_PRIORITY_QUEUE<T>, ARRAY_PRIORITY_QUEUE<T>> toQueue() {
|
||||||
return array[index];
|
return Collector.of(ARRAY_PRIORITY_QUEUE::new, ARRAY_PRIORITY_QUEUE::enqueue, ARRAY_PRIORITY_QUEUE::merge);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/**
|
||||||
public boolean removeFirst(KEY_TYPE e) {
|
* Collects a Stream to a ArrayPriorityQueue
|
||||||
for(int i = 0;i<size;i++)
|
* @Type(T)
|
||||||
if(KEY_EQUALS(e, array[i])) return removeIndex(i);
|
* @return a queue with the contents of the Stream
|
||||||
return false;
|
*/
|
||||||
}
|
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);
|
||||||
@Override
|
}
|
||||||
public boolean removeLast(KEY_TYPE e) {
|
|
||||||
for(int i = size-1;i>=0;i--)
|
private ARRAY_PRIORITY_QUEUE<T> merge(ARRAY_PRIORITY_QUEUE<T> a) {
|
||||||
if(KEY_EQUALS(e, array[i])) return removeIndex(i);
|
enqueueAll(a.toArray((T[])new Object[a.size()]));
|
||||||
return false;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean removeIndex(int index) {
|
#else
|
||||||
if(index != --size) System.arraycopy(array, index+1, array, index, size - index);
|
/**
|
||||||
#if TYPE_OBJECT
|
* Collects a Stream to a ArrayPriorityQueue
|
||||||
array[size] = null;
|
* @return a queue with the contents of the Stream
|
||||||
#endif
|
*/
|
||||||
if(index == firstIndex) firstIndex = -1;
|
public static ARRAY_PRIORITY_QUEUE toQueue(JAVA_STREAM stream) {
|
||||||
else if(firstIndex != -1 && index >= firstIndex) firstIndex--;
|
return stream.collect(ARRAY_PRIORITY_QUEUE::new, ARRAY_PRIORITY_QUEUE::enqueue, ARRAY_PRIORITY_QUEUE::merge);
|
||||||
return true;
|
}
|
||||||
}
|
|
||||||
|
private ARRAY_PRIORITY_QUEUE merge(ARRAY_PRIORITY_QUEUE a) {
|
||||||
@Override
|
enqueueAll(a.TO_ARRAY());
|
||||||
public void onChanged() {
|
return this;
|
||||||
firstIndex = -1;
|
}
|
||||||
}
|
|
||||||
|
#endif
|
||||||
@Override
|
#endif
|
||||||
public int size() {
|
@Override
|
||||||
return size;
|
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));
|
||||||
|
if(firstIndex != -1){
|
||||||
@Override
|
int compare = comparator == null ? COMPAREABLE_TO_KEY(e, array[firstIndex]) : comparator.compare(e, array[firstIndex]);
|
||||||
public void clear() {
|
if(compare < 0) firstIndex = size;
|
||||||
#if TYPE_OBJECT
|
else if(compare > 0) firstIndex = -1;
|
||||||
Arrays.fill(array, null);
|
}
|
||||||
#endif
|
array[size++] = e;
|
||||||
size = 0;
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
@Override
|
public KEY_TYPE dequeue() {
|
||||||
public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) {
|
if(size <= 0) throw new NoSuchElementException();
|
||||||
Objects.requireNonNull(action);
|
int index = findFirstIndex();
|
||||||
for(int i = 0,m=size;i<m;i++) action.accept(dequeue());
|
KEY_TYPE value = array[index];
|
||||||
}
|
if(index != --size) System.arraycopy(array, index+1, array, index, size - index);
|
||||||
|
#if TYPE_OBJECT
|
||||||
@Override
|
array[size] = null;
|
||||||
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
#endif
|
||||||
Objects.requireNonNull(action);
|
firstIndex = -1;
|
||||||
for(int i = 0,m=size;i<m;i++) action.accept(input, dequeue());
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean matchesAny(PREDICATE KEY_GENERIC_TYPE filter) {
|
public KEY_TYPE first() {
|
||||||
Objects.requireNonNull(filter);
|
if(isEmpty()) throw new NoSuchElementException();
|
||||||
for(int i = 0;i<size;i++) {
|
if(firstIndex == -1) findFirstIndex();
|
||||||
if(filter.TEST_VALUE(array[i])) return true;
|
return array[firstIndex];
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
@Override
|
||||||
|
public KEY_TYPE peek(int index) {
|
||||||
@Override
|
if(index < 0 || index >= size) throw new NoSuchElementException();
|
||||||
public boolean matchesNone(PREDICATE KEY_GENERIC_TYPE filter) {
|
return array[index];
|
||||||
Objects.requireNonNull(filter);
|
}
|
||||||
for(int i = 0;i<size;i++) {
|
|
||||||
if(filter.TEST_VALUE(array[i])) return false;
|
@Override
|
||||||
}
|
public boolean contains(KEY_TYPE e) {
|
||||||
return true;
|
for(int i = 0;i<size;i++)
|
||||||
}
|
if(KEY_EQUALS(e, array[i])) return true;
|
||||||
|
return false;
|
||||||
@Override
|
}
|
||||||
public boolean matchesAll(PREDICATE KEY_GENERIC_TYPE filter) {
|
|
||||||
Objects.requireNonNull(filter);
|
@Override
|
||||||
for(int i = 0;i<size;i++) {
|
public boolean removeFirst(KEY_TYPE e) {
|
||||||
if(!filter.TEST_VALUE(array[i])) return false;
|
for(int i = 0;i<size;i++)
|
||||||
}
|
if(KEY_EQUALS(e, array[i])) return removeIndex(i);
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !TYPE_OBJECT
|
@Override
|
||||||
@Override
|
public boolean removeLast(KEY_TYPE e) {
|
||||||
public KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
for(int i = size-1;i>=0;i--)
|
||||||
Objects.requireNonNull(operator);
|
if(KEY_EQUALS(e, array[i])) return removeIndex(i);
|
||||||
KEY_TYPE state = identity;
|
return false;
|
||||||
for(int i = 0;i<size;i++) {
|
}
|
||||||
state = operator.APPLY_VALUE(state, array[i]);
|
|
||||||
}
|
protected boolean removeIndex(int index) {
|
||||||
return state;
|
if(index != --size) System.arraycopy(array, index+1, array, index, size - index);
|
||||||
}
|
#if TYPE_OBJECT
|
||||||
|
array[size] = null;
|
||||||
#else
|
#endif
|
||||||
@Override
|
if(index == firstIndex) firstIndex = -1;
|
||||||
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
|
else if(firstIndex != -1 && index >= firstIndex) firstIndex--;
|
||||||
Objects.requireNonNull(operator);
|
return true;
|
||||||
KEY_SPECIAL_TYPE state = identity;
|
}
|
||||||
for(int i = 0;i<size;i++) {
|
|
||||||
state = operator.APPLY_VALUE(state, array[i]);
|
@Override
|
||||||
}
|
public void onChanged() {
|
||||||
return state;
|
firstIndex = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
@Override
|
||||||
@Override
|
public int size() {
|
||||||
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
return size;
|
||||||
Objects.requireNonNull(operator);
|
}
|
||||||
KEY_TYPE state = EMPTY_VALUE;
|
|
||||||
boolean empty = true;
|
@Override
|
||||||
for(int i = 0;i<size;i++) {
|
public void clear() {
|
||||||
if(empty) {
|
#if TYPE_OBJECT
|
||||||
empty = false;
|
Arrays.fill(array, null);
|
||||||
state = array[i];
|
#endif
|
||||||
continue;
|
size = 0;
|
||||||
}
|
}
|
||||||
state = operator.APPLY_VALUE(state, array[i]);
|
|
||||||
}
|
@Override
|
||||||
return state;
|
public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) {
|
||||||
}
|
Objects.requireNonNull(action);
|
||||||
|
for(int i = 0,m=size;i<m;i++) action.accept(dequeue());
|
||||||
@Override
|
}
|
||||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
|
||||||
Objects.requireNonNull(filter);
|
@Override
|
||||||
for(int i = 0;i<size;i++) {
|
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
|
||||||
if(filter.TEST_VALUE(array[i])) {
|
Objects.requireNonNull(action);
|
||||||
KEY_TYPE data = array[i];
|
for(int i = 0,m=size;i<m;i++) action.accept(i, dequeue());
|
||||||
removeIndex(i);
|
}
|
||||||
return data;
|
|
||||||
}
|
@Override
|
||||||
}
|
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
||||||
return EMPTY_VALUE;
|
Objects.requireNonNull(action);
|
||||||
}
|
for(int i = 0,m=size;i<m;i++) action.accept(input, dequeue());
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
|
@Override
|
||||||
Objects.requireNonNull(filter);
|
public boolean matchesAny(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
int result = 0;
|
Objects.requireNonNull(filter);
|
||||||
for(int i = 0;i<size;i++) {
|
for(int i = 0;i<size;i++) {
|
||||||
if(filter.TEST_VALUE(array[i])) result++;
|
if(filter.test(array[i])) return true;
|
||||||
}
|
}
|
||||||
return result;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ITERATOR KEY_GENERIC_TYPE iterator() {
|
public boolean matchesNone(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
return new Iter();
|
Objects.requireNonNull(filter);
|
||||||
}
|
for(int i = 0;i<size;i++) {
|
||||||
|
if(filter.test(array[i])) return false;
|
||||||
@Override
|
}
|
||||||
public ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE copy() {
|
return true;
|
||||||
ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE queue = new ARRAY_PRIORITY_QUEUEBRACES();
|
}
|
||||||
queue.firstIndex = firstIndex;
|
|
||||||
queue.size = size;
|
@Override
|
||||||
queue.comparator = comparator;
|
public boolean matchesAll(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
queue.array = Arrays.copyOf(array, array.length);
|
Objects.requireNonNull(filter);
|
||||||
return queue;
|
for(int i = 0;i<size;i++) {
|
||||||
}
|
if(!filter.test(array[i])) return false;
|
||||||
|
}
|
||||||
@Override
|
return true;
|
||||||
public COMPARATOR KEY_SUPER_GENERIC_TYPE comparator() {
|
}
|
||||||
return comparator;
|
|
||||||
}
|
#if !TYPE_OBJECT
|
||||||
|
@Override
|
||||||
@Override
|
public KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
public GENERIC_SPECIAL_KEY_BRACES<E> KEY_SPECIAL_TYPE[] TO_ARRAY(KEY_SPECIAL_TYPE[] input) {
|
Objects.requireNonNull(operator);
|
||||||
if(input == null || input.length < size()) input = NEW_SPECIAL_KEY_ARRAY(size());
|
KEY_TYPE state = identity;
|
||||||
System.arraycopy(array, 0, input, 0, size());
|
for(int i = 0;i<size;i++) {
|
||||||
return input;
|
state = operator.APPLY_VALUE(state, array[i]);
|
||||||
}
|
}
|
||||||
|
return state;
|
||||||
protected int findFirstIndex() {
|
}
|
||||||
if(firstIndex == -1) {
|
|
||||||
int index = size-1;
|
#else
|
||||||
KEY_TYPE value = array[index];
|
@Override
|
||||||
if(comparator == null) {
|
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
|
||||||
for(int i = index;i>=0;i--) {
|
Objects.requireNonNull(operator);
|
||||||
if(COMPAREABLE_TO_KEY(array[i], value) < 0)
|
KEY_SPECIAL_TYPE state = identity;
|
||||||
value = array[index = i];
|
for(int i = 0;i<size;i++) {
|
||||||
}
|
state = operator.APPLY_VALUE(state, array[i]);
|
||||||
}
|
}
|
||||||
else {
|
return state;
|
||||||
for(int i = index;i>=0;i--) {
|
}
|
||||||
if(comparator.compare(array[i], value) < 0)
|
|
||||||
value = array[index = i];
|
#endif
|
||||||
}
|
@Override
|
||||||
}
|
public OPTIONAL KEY_GENERIC_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
firstIndex = index;
|
Objects.requireNonNull(operator);
|
||||||
}
|
KEY_TYPE state = EMPTY_VALUE;
|
||||||
return firstIndex;
|
boolean empty = true;
|
||||||
}
|
for(int i = 0;i<size;i++) {
|
||||||
|
if(empty) {
|
||||||
private class Iter implements ITERATOR KEY_GENERIC_TYPE {
|
empty = false;
|
||||||
@Override
|
state = array[i];
|
||||||
public boolean hasNext() {
|
continue;
|
||||||
return !isEmpty();
|
}
|
||||||
}
|
state = operator.APPLY_VALUE(state, array[i]);
|
||||||
|
}
|
||||||
@Override
|
return empty ? OPTIONAL.empty() : OPTIONAL.GET_OPTIONAL(state);
|
||||||
public KEY_TYPE NEXT() {
|
}
|
||||||
return dequeue();
|
|
||||||
}
|
@Override
|
||||||
}
|
public OPTIONAL KEY_GENERIC_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
|
Objects.requireNonNull(filter);
|
||||||
|
for(int i = 0;i<size;i++) {
|
||||||
|
if(filter.test(array[i])) {
|
||||||
|
KEY_TYPE data = array[i];
|
||||||
|
removeIndex(i);
|
||||||
|
return OPTIONAL.GET_OPTIONAL(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return OPTIONAL.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
|
Objects.requireNonNull(filter);
|
||||||
|
int result = 0;
|
||||||
|
for(int i = 0;i<size;i++) {
|
||||||
|
if(filter.test(array[i])) result++;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ITERATOR KEY_GENERIC_TYPE iterator() {
|
||||||
|
return new Iter();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE copy() {
|
||||||
|
ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE queue = new ARRAY_PRIORITY_QUEUEBRACES();
|
||||||
|
queue.firstIndex = firstIndex;
|
||||||
|
queue.size = size;
|
||||||
|
queue.comparator = comparator;
|
||||||
|
queue.array = Arrays.copyOf(array, array.length);
|
||||||
|
return queue;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public COMPARATOR KEY_SUPER_GENERIC_TYPE comparator() {
|
||||||
|
return comparator;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GENERIC_SPECIAL_KEY_BRACES<E> KEY_SPECIAL_TYPE[] TO_ARRAY(KEY_SPECIAL_TYPE[] input) {
|
||||||
|
if(input == null || input.length < size()) input = NEW_SPECIAL_KEY_ARRAY(size());
|
||||||
|
System.arraycopy(array, 0, input, 0, size());
|
||||||
|
return input;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected int findFirstIndex() {
|
||||||
|
if(firstIndex == -1) {
|
||||||
|
int index = size-1;
|
||||||
|
KEY_TYPE value = array[index];
|
||||||
|
if(comparator == null) {
|
||||||
|
for(int i = index;i>=0;i--) {
|
||||||
|
if(COMPAREABLE_TO_KEY(array[i], value) < 0)
|
||||||
|
value = array[index = i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
for(int i = index;i>=0;i--) {
|
||||||
|
if(comparator.compare(array[i], value) < 0)
|
||||||
|
value = array[index = i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
firstIndex = index;
|
||||||
|
}
|
||||||
|
return firstIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
private class Iter implements ITERATOR KEY_GENERIC_TYPE {
|
||||||
|
@Override
|
||||||
|
public boolean hasNext() {
|
||||||
|
return !isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE NEXT() {
|
||||||
|
if(!hasNext()) throw new NoSuchElementException();
|
||||||
|
return dequeue();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+469
-394
@@ -1,395 +1,470 @@
|
|||||||
package speiger.src.collections.PACKAGE.queues;
|
package speiger.src.collections.PACKAGE.queues;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
#if TYPE_OBJECT
|
#if TYPE_OBJECT
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
#endif
|
#endif
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
#if JDK_TYPE
|
||||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
import java.util.OPTIONAL;
|
||||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
#if SPLIT_ITERATOR_FEATURE && STREAM_FEATURE
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
import java.util.stream.JAVA_STREAM;
|
||||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
#else
|
||||||
#endif
|
import java.util.stream.Stream;
|
||||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
import java.util.stream.Collector;
|
||||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
#endif
|
||||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
#endif
|
||||||
import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
#endif
|
||||||
import speiger.src.collections.utils.SanityChecks;
|
#if JDK_FUNCTION
|
||||||
|
import java.util.function.PREDICATE;
|
||||||
/**
|
#endif
|
||||||
* A Simple Heap base Priority Queue implementation
|
|
||||||
* It is a ArrayBased Alternative to TreeSets that has less object allocations
|
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||||
* @Type(T)
|
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||||
*/
|
#if !JDK_TYPE
|
||||||
public class HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEUE KEY_GENERIC_TYPE
|
import speiger.src.collections.PACKAGE.functions.OPTIONAL;
|
||||||
{
|
#endif
|
||||||
/** The Backing Array */
|
#if !TYPE_OBJECT
|
||||||
protected transient KEY_TYPE[] array = EMPTY_KEY_ARRAY;
|
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||||
/** The Amount of elements stored within the array */
|
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||||
protected int size;
|
#endif
|
||||||
/** The Sorter of the Array */
|
import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
|
||||||
protected COMPARATOR KEY_SUPER_GENERIC_TYPE comparator;
|
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||||
|
#if !JDK_FUNCTION
|
||||||
/**
|
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||||
* Default Constructor
|
#endif
|
||||||
*/
|
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||||
public HEAP_PRIORITY_QUEUE() {
|
import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
||||||
this(0, null);
|
import speiger.src.collections.utils.SanityChecks;
|
||||||
}
|
|
||||||
|
/**
|
||||||
/**
|
* A Simple Heap base Priority Queue implementation
|
||||||
* Constructor using custom sorter
|
* It is a ArrayBased Alternative to TreeSets that has less object allocations
|
||||||
* @param comp Comparator to sort the Array. Can be null
|
* @Type(T)
|
||||||
*/
|
*/
|
||||||
public HEAP_PRIORITY_QUEUE(COMPARATOR KEY_SUPER_GENERIC_TYPE comp) {
|
public class HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEUE KEY_GENERIC_TYPE
|
||||||
this(0, comp);
|
{
|
||||||
}
|
/** The Backing Array */
|
||||||
|
protected transient KEY_TYPE[] array = EMPTY_KEY_ARRAY;
|
||||||
/**
|
/** The Amount of elements stored within the array */
|
||||||
* Constructor with a Min Capacity
|
protected int size;
|
||||||
* @param size the initial capacity of the backing array
|
/** The Sorter of the Array */
|
||||||
* @throws IllegalStateException if the initial size is smaller 0
|
protected COMPARATOR KEY_SUPER_GENERIC_TYPE comparator;
|
||||||
*/
|
|
||||||
public HEAP_PRIORITY_QUEUE(int size) {
|
/**
|
||||||
this(size, null);
|
* Default Constructor
|
||||||
}
|
*/
|
||||||
|
public HEAP_PRIORITY_QUEUE() {
|
||||||
/**
|
this(0, null);
|
||||||
* Constructor with a Min Capacity and custom Sorter
|
}
|
||||||
* @param size the initial capacity of the backing array
|
|
||||||
* @param comp Comparator to sort the Array. Can be null
|
/**
|
||||||
* @throws IllegalStateException if the initial size is smaller 0
|
* Constructor using custom sorter
|
||||||
*/
|
* @param comp Comparator to sort the Array. Can be null
|
||||||
public HEAP_PRIORITY_QUEUE(int size, COMPARATOR KEY_SUPER_GENERIC_TYPE comp) {
|
*/
|
||||||
if(size > 0) array = NEW_KEY_ARRAY(size);
|
public HEAP_PRIORITY_QUEUE(COMPARATOR KEY_SUPER_GENERIC_TYPE comp) {
|
||||||
comparator = comp;
|
this(0, comp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor using a initial array
|
* Constructor with a Min Capacity
|
||||||
* @param array the Array that should be used
|
* @param size the initial capacity of the backing array
|
||||||
*/
|
* @throws IllegalStateException if the initial size is smaller 0
|
||||||
public HEAP_PRIORITY_QUEUE(KEY_TYPE[] array) {
|
*/
|
||||||
this(array, array.length);
|
public HEAP_PRIORITY_QUEUE(int size) {
|
||||||
}
|
this(size, null);
|
||||||
|
}
|
||||||
/**
|
|
||||||
* Constructor using a initial array
|
/**
|
||||||
* @param array the Array that should be used
|
* Constructor with a Min Capacity and custom Sorter
|
||||||
* @param size the amount of elements found within the array
|
* @param size the initial capacity of the backing array
|
||||||
* @throws NegativeArraySizeException if size is smaller then 0
|
* @param comp Comparator to sort the Array. Can be null
|
||||||
*/
|
* @throws IllegalStateException if the initial size is smaller 0
|
||||||
public HEAP_PRIORITY_QUEUE(KEY_TYPE[] array, int size) {
|
*/
|
||||||
this.array = Arrays.copyOf(array, size);
|
public HEAP_PRIORITY_QUEUE(int size, COMPARATOR KEY_SUPER_GENERIC_TYPE comp) {
|
||||||
this.size = size;
|
if(size > 0) array = NEW_KEY_ARRAY(size);
|
||||||
ARRAYS.heapify(array, size, null);
|
comparator = comp;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor using a initial array and a custom sorter
|
* Constructor using a initial array
|
||||||
* @param array the Array that should be used
|
* @param array the Array that should be used
|
||||||
* @param comp Comparator to sort the Array. Can be null
|
*/
|
||||||
*/
|
public HEAP_PRIORITY_QUEUE(KEY_TYPE[] array) {
|
||||||
public HEAP_PRIORITY_QUEUE(KEY_TYPE[] array, COMPARATOR KEY_SUPER_GENERIC_TYPE comp) {
|
this(array, array.length);
|
||||||
this(array, array.length, comp);
|
}
|
||||||
}
|
|
||||||
|
/**
|
||||||
/**
|
* Constructor using a initial array
|
||||||
* Constructor using a initial array and a custom sorter
|
* @param array the Array that should be used
|
||||||
* @param array the Array that should be used
|
* @param size the amount of elements found within the array
|
||||||
* @param size the amount of elements found within the array
|
* @throws NegativeArraySizeException if size is smaller then 0
|
||||||
* @param comp Comparator to sort the Array. Can be null
|
*/
|
||||||
* @throws NegativeArraySizeException if size is smaller then 0
|
public HEAP_PRIORITY_QUEUE(KEY_TYPE[] array, int size) {
|
||||||
*/
|
this.array = Arrays.copyOf(array, size);
|
||||||
public HEAP_PRIORITY_QUEUE(KEY_TYPE[] array, int size, COMPARATOR KEY_SUPER_GENERIC_TYPE comp) {
|
this.size = size;
|
||||||
this.array = Arrays.copyOf(array, size);
|
ARRAYS.heapify(array, size, null);
|
||||||
this.size = size;
|
}
|
||||||
comparator = comp;
|
|
||||||
ARRAYS.heapify(array, size, comp);
|
/**
|
||||||
}
|
* Constructor using a initial array and a custom sorter
|
||||||
|
* @param array the Array that should be used
|
||||||
/**
|
* @param comp Comparator to sort the Array. Can be null
|
||||||
* Constructor using a Collection
|
*/
|
||||||
* @param c the Collection that should be used
|
public HEAP_PRIORITY_QUEUE(KEY_TYPE[] array, COMPARATOR KEY_SUPER_GENERIC_TYPE comp) {
|
||||||
*/
|
this(array, array.length, comp);
|
||||||
public HEAP_PRIORITY_QUEUE(COLLECTION KEY_GENERIC_TYPE c) {
|
}
|
||||||
array = CAST_KEY_ARRAY c.TO_ARRAY();
|
|
||||||
size = c.size();
|
/**
|
||||||
ARRAYS.heapify(array, size, null);
|
* Constructor using a initial array and a custom sorter
|
||||||
}
|
* @param array the Array that should be used
|
||||||
|
* @param size the amount of elements found within the array
|
||||||
/**
|
* @param comp Comparator to sort the Array. Can be null
|
||||||
* Constructor using a Collection and a custom sorter
|
* @throws NegativeArraySizeException if size is smaller then 0
|
||||||
* @param c the Collection that should be used
|
*/
|
||||||
* @param comp Comparator to sort the Array. Can be null
|
public HEAP_PRIORITY_QUEUE(KEY_TYPE[] array, int size, COMPARATOR KEY_SUPER_GENERIC_TYPE comp) {
|
||||||
*/
|
this.array = Arrays.copyOf(array, size);
|
||||||
public HEAP_PRIORITY_QUEUE(COLLECTION KEY_GENERIC_TYPE c, COMPARATOR KEY_SUPER_GENERIC_TYPE comp) {
|
this.size = size;
|
||||||
array = CAST_KEY_ARRAY c.TO_ARRAY();
|
comparator = comp;
|
||||||
size = c.size();
|
ARRAYS.heapify(array, size, comp);
|
||||||
comparator = comp;
|
}
|
||||||
ARRAYS.heapify(array, size, comp);
|
|
||||||
}
|
/**
|
||||||
|
* Constructor using a Collection
|
||||||
/**
|
* @param c the Collection that should be used
|
||||||
* Wrapping method to help serialization
|
*/
|
||||||
* @param array the array that should be used
|
public HEAP_PRIORITY_QUEUE(COLLECTION KEY_GENERIC_TYPE c) {
|
||||||
* @Type(T)
|
array = CAST_KEY_ARRAY c.TO_ARRAY();
|
||||||
* @return a HeapPriorityQueue containing the original input array
|
size = c.size();
|
||||||
*/
|
ARRAYS.heapify(array, size, null);
|
||||||
public static GENERIC_KEY_BRACES HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE wrap(KEY_TYPE[] array) {
|
}
|
||||||
return wrap(array, array.length);
|
|
||||||
}
|
/**
|
||||||
|
* Constructor using a Collection and a custom sorter
|
||||||
/**
|
* @param c the Collection that should be used
|
||||||
* Wrapping method to help serialization
|
* @param comp Comparator to sort the Array. Can be null
|
||||||
* @param array the array that should be used
|
*/
|
||||||
* @param size the amount of elements within the array
|
public HEAP_PRIORITY_QUEUE(COLLECTION KEY_GENERIC_TYPE c, COMPARATOR KEY_SUPER_GENERIC_TYPE comp) {
|
||||||
* @Type(T)
|
array = CAST_KEY_ARRAY c.TO_ARRAY();
|
||||||
* @return a HeapPriorityQueue containing the original input array
|
size = c.size();
|
||||||
*/
|
comparator = comp;
|
||||||
public static GENERIC_KEY_BRACES HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE wrap(KEY_TYPE[] array, int size) {
|
ARRAYS.heapify(array, size, comp);
|
||||||
HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE queue = new HEAP_PRIORITY_QUEUEBRACES();
|
}
|
||||||
queue.array = array;
|
|
||||||
queue.size = size;
|
/**
|
||||||
ARRAYS.heapify(array, size, null);
|
* Wrapping method to help serialization
|
||||||
return queue;
|
* @param array the array that should be used
|
||||||
}
|
* @Type(T)
|
||||||
|
* @return a HeapPriorityQueue containing the original input array
|
||||||
/**
|
*/
|
||||||
* Wrapping method to help serialization, using a custom sorter
|
public static GENERIC_KEY_BRACES HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE wrap(KEY_TYPE[] array) {
|
||||||
* @param array the array that should be used
|
return wrap(array, array.length);
|
||||||
* @param comp Comparator to sort the Array. Can be null
|
}
|
||||||
* @Type(T)
|
|
||||||
* @return a HeapPriorityQueue containing the original input array
|
/**
|
||||||
*/
|
* Wrapping method to help serialization
|
||||||
public static GENERIC_KEY_BRACES HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE wrap(KEY_TYPE[] array, COMPARATOR KEY_SUPER_GENERIC_TYPE comp) {
|
* @param array the array that should be used
|
||||||
return wrap(array, array.length, comp);
|
* @param size the amount of elements within the array
|
||||||
}
|
* @Type(T)
|
||||||
|
* @return a HeapPriorityQueue containing the original input array
|
||||||
/**
|
*/
|
||||||
* Wrapping method to help serialization, using a custom sorter
|
public static GENERIC_KEY_BRACES HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE wrap(KEY_TYPE[] array, int size) {
|
||||||
* @param array the array that should be used
|
HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE queue = new HEAP_PRIORITY_QUEUEBRACES();
|
||||||
* @param size the amount of elements within the array
|
queue.array = array;
|
||||||
* @param comp Comparator to sort the Array. Can be null
|
queue.size = size;
|
||||||
* @Type(T)
|
ARRAYS.heapify(array, size, null);
|
||||||
* @return a HeapPriorityQueue containing the original input array
|
return queue;
|
||||||
*/
|
}
|
||||||
public static GENERIC_KEY_BRACES HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE wrap(KEY_TYPE[] array, int size, COMPARATOR KEY_SUPER_GENERIC_TYPE comp) {
|
|
||||||
HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE queue = new HEAP_PRIORITY_QUEUEBRACES(comp);
|
/**
|
||||||
queue.array = array;
|
* Wrapping method to help serialization, using a custom sorter
|
||||||
queue.size = size;
|
* @param array the array that should be used
|
||||||
ARRAYS.heapify(array, size, comp);
|
* @param comp Comparator to sort the Array. Can be null
|
||||||
return queue;
|
* @Type(T)
|
||||||
}
|
* @return a HeapPriorityQueue containing the original input array
|
||||||
|
*/
|
||||||
@Override
|
public static GENERIC_KEY_BRACES HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE wrap(KEY_TYPE[] array, COMPARATOR KEY_SUPER_GENERIC_TYPE comp) {
|
||||||
public int size() {
|
return wrap(array, array.length, comp);
|
||||||
return size;
|
}
|
||||||
}
|
|
||||||
|
/**
|
||||||
@Override
|
* Wrapping method to help serialization, using a custom sorter
|
||||||
public void clear() {
|
* @param array the array that should be used
|
||||||
#if TYPE_OBJECT
|
* @param size the amount of elements within the array
|
||||||
Arrays.fill(array, null);
|
* @param comp Comparator to sort the Array. Can be null
|
||||||
#endif
|
* @Type(T)
|
||||||
size = 0;
|
* @return a HeapPriorityQueue containing the original input array
|
||||||
}
|
*/
|
||||||
|
public static GENERIC_KEY_BRACES HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE wrap(KEY_TYPE[] array, int size, COMPARATOR KEY_SUPER_GENERIC_TYPE comp) {
|
||||||
@Override
|
HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE queue = new HEAP_PRIORITY_QUEUEBRACES(comp);
|
||||||
public ITERATOR KEY_GENERIC_TYPE iterator() {
|
queue.array = array;
|
||||||
return new Iter();
|
queue.size = size;
|
||||||
}
|
ARRAYS.heapify(array, size, comp);
|
||||||
|
return queue;
|
||||||
@Override
|
}
|
||||||
public void enqueue(KEY_TYPE e) {
|
|
||||||
if(size == array.length) array = Arrays.copyOf(array, (int)Math.max(Math.min((long)array.length + (array.length >> 1), SanityChecks.MAX_ARRAY_SIZE), size+1));
|
#if JDK_TYPE && SPLIT_ITERATOR_FEATURE && STREAM_FEATURE
|
||||||
array[size++] = e;
|
#if TYPE_OBJECT
|
||||||
ARRAYS.shiftUp(array, size-1, comparator);
|
/**
|
||||||
}
|
* Creates a Collector for a ArrayFIFOQueue
|
||||||
|
* @Type(T)
|
||||||
@Override
|
* @return a collector
|
||||||
public KEY_TYPE dequeue() {
|
*/
|
||||||
if(size <= 0) throw new NoSuchElementException();
|
public static <T> Collector<T, HEAP_PRIORITY_QUEUE<T>, HEAP_PRIORITY_QUEUE<T>> toQueue() {
|
||||||
KEY_TYPE value = array[0];
|
return Collector.of(HEAP_PRIORITY_QUEUE::new, HEAP_PRIORITY_QUEUE::enqueue, HEAP_PRIORITY_QUEUE::merge);
|
||||||
array[0] = array[--size];
|
}
|
||||||
#if TYPE_OBJECT
|
|
||||||
array[size] = null;
|
/**
|
||||||
#endif
|
* Collects a Stream to a ArrayFIFOQueue
|
||||||
if(size != 0) ARRAYS.shiftDown(array, size, 0, comparator);
|
* @Type(T)
|
||||||
return value;
|
* @return a queue with the contents of the Stream
|
||||||
}
|
*/
|
||||||
|
public static <T> HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE toQueue(Stream<T> stream) {
|
||||||
@Override
|
return stream.collect(HEAP_PRIORITY_QUEUE::new, HEAP_PRIORITY_QUEUE::enqueue, HEAP_PRIORITY_QUEUE::merge);
|
||||||
public KEY_TYPE peek(int index) {
|
}
|
||||||
if(index < 0 || index >= size) throw new NoSuchElementException();
|
|
||||||
return array[index];
|
private HEAP_PRIORITY_QUEUE<T> merge(HEAP_PRIORITY_QUEUE<T> a) {
|
||||||
}
|
enqueueAll(a.toArray((T[])new Object[a.size()]));
|
||||||
|
return this;
|
||||||
@Override
|
}
|
||||||
public boolean removeFirst(KEY_TYPE e) {
|
|
||||||
for(int i = 0;i<size;i++)
|
#else
|
||||||
if(KEY_EQUALS(e, array[i])) return removeIndex(i);
|
/**
|
||||||
return false;
|
* Collects a Stream to a ArrayFIFOQueue
|
||||||
}
|
* @return a queue with the contents of the Stream
|
||||||
|
*/
|
||||||
@Override
|
public static HEAP_PRIORITY_QUEUE toQueue(JAVA_STREAM stream) {
|
||||||
public boolean removeLast(KEY_TYPE e) {
|
return stream.collect(HEAP_PRIORITY_QUEUE::new, HEAP_PRIORITY_QUEUE::enqueue, HEAP_PRIORITY_QUEUE::merge);
|
||||||
for(int i = size-1;i>=0;i--)
|
}
|
||||||
if(KEY_EQUALS(e, array[i])) return removeIndex(i);
|
|
||||||
return false;
|
private HEAP_PRIORITY_QUEUE merge(HEAP_PRIORITY_QUEUE a) {
|
||||||
}
|
enqueueAll(a.TO_ARRAY());
|
||||||
|
return this;
|
||||||
@Override
|
}
|
||||||
public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) {
|
|
||||||
Objects.requireNonNull(action);
|
#endif
|
||||||
for(int i = 0,m=size;i<m;i++) action.accept(dequeue());
|
#endif
|
||||||
}
|
@Override
|
||||||
|
public int size() {
|
||||||
@Override
|
return size;
|
||||||
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
}
|
||||||
Objects.requireNonNull(action);
|
|
||||||
for(int i = 0,m=size;i<m;i++) action.accept(input, dequeue());
|
@Override
|
||||||
}
|
public void clear() {
|
||||||
|
#if TYPE_OBJECT
|
||||||
@Override
|
Arrays.fill(array, null);
|
||||||
public boolean matchesAny(PREDICATE KEY_GENERIC_TYPE filter) {
|
#endif
|
||||||
Objects.requireNonNull(filter);
|
size = 0;
|
||||||
for(int i = 0;i<size;i++) {
|
}
|
||||||
if(filter.TEST_VALUE(array[i])) return true;
|
|
||||||
}
|
@Override
|
||||||
return false;
|
public ITERATOR KEY_GENERIC_TYPE iterator() {
|
||||||
}
|
return new Iter();
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public boolean matchesNone(PREDICATE KEY_GENERIC_TYPE filter) {
|
@Override
|
||||||
Objects.requireNonNull(filter);
|
public void enqueue(KEY_TYPE e) {
|
||||||
for(int i = 0;i<size;i++) {
|
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));
|
||||||
if(filter.TEST_VALUE(array[i])) return false;
|
array[size++] = e;
|
||||||
}
|
ARRAYS.shiftUp(array, size-1, comparator);
|
||||||
return true;
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
@Override
|
public KEY_TYPE dequeue() {
|
||||||
public boolean matchesAll(PREDICATE KEY_GENERIC_TYPE filter) {
|
if(size <= 0) throw new NoSuchElementException();
|
||||||
Objects.requireNonNull(filter);
|
KEY_TYPE value = array[0];
|
||||||
for(int i = 0;i<size;i++) {
|
array[0] = array[--size];
|
||||||
if(!filter.TEST_VALUE(array[i])) return false;
|
#if TYPE_OBJECT
|
||||||
}
|
array[size] = null;
|
||||||
return true;
|
#endif
|
||||||
}
|
if(size != 0) ARRAYS.shiftDown(array, size, 0, comparator);
|
||||||
|
return value;
|
||||||
#if !TYPE_OBJECT
|
}
|
||||||
@Override
|
|
||||||
public KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
@Override
|
||||||
Objects.requireNonNull(operator);
|
public KEY_TYPE peek(int index) {
|
||||||
KEY_TYPE state = identity;
|
if(index < 0 || index >= size) throw new NoSuchElementException();
|
||||||
for(int i = 0;i<size;i++) {
|
return array[index];
|
||||||
state = operator.APPLY_VALUE(state, array[i]);
|
}
|
||||||
}
|
|
||||||
return state;
|
@Override
|
||||||
}
|
public boolean contains(KEY_TYPE e) {
|
||||||
|
for(int i = 0;i<size;i++)
|
||||||
#else
|
if(KEY_EQUALS(e, array[i])) return true;
|
||||||
@Override
|
return false;
|
||||||
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
|
}
|
||||||
Objects.requireNonNull(operator);
|
|
||||||
KEY_SPECIAL_TYPE state = identity;
|
@Override
|
||||||
for(int i = 0;i<size;i++) {
|
public boolean removeFirst(KEY_TYPE e) {
|
||||||
state = operator.APPLY_VALUE(state, array[i]);
|
for(int i = 0;i<size;i++)
|
||||||
}
|
if(KEY_EQUALS(e, array[i])) return removeIndex(i);
|
||||||
return state;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
@Override
|
||||||
@Override
|
public boolean removeLast(KEY_TYPE e) {
|
||||||
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
for(int i = size-1;i>=0;i--)
|
||||||
Objects.requireNonNull(operator);
|
if(KEY_EQUALS(e, array[i])) return removeIndex(i);
|
||||||
KEY_TYPE state = EMPTY_VALUE;
|
return false;
|
||||||
boolean empty = true;
|
}
|
||||||
for(int i = 0;i<size;i++) {
|
|
||||||
if(empty) {
|
@Override
|
||||||
empty = false;
|
public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) {
|
||||||
state = array[i];
|
Objects.requireNonNull(action);
|
||||||
continue;
|
for(int i = 0,m=size;i<m;i++) action.accept(dequeue());
|
||||||
}
|
}
|
||||||
state = operator.APPLY_VALUE(state, array[i]);
|
|
||||||
}
|
@Override
|
||||||
return state;
|
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 KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
|
||||||
Objects.requireNonNull(filter);
|
@Override
|
||||||
for(int i = 0;i<size;i++) {
|
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
||||||
if(filter.TEST_VALUE(array[i])) {
|
Objects.requireNonNull(action);
|
||||||
KEY_TYPE data = array[i];
|
for(int i = 0,m=size;i<m;i++) action.accept(input, dequeue());
|
||||||
removeIndex(i);
|
}
|
||||||
return data;
|
|
||||||
}
|
@Override
|
||||||
}
|
public boolean matchesAny(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
return EMPTY_VALUE;
|
Objects.requireNonNull(filter);
|
||||||
}
|
for(int i = 0;i<size;i++) {
|
||||||
|
if(filter.test(array[i])) return true;
|
||||||
@Override
|
}
|
||||||
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
|
return false;
|
||||||
Objects.requireNonNull(filter);
|
}
|
||||||
int result = 0;
|
|
||||||
for(int i = 0;i<size;i++) {
|
@Override
|
||||||
if(filter.TEST_VALUE(array[i])) result++;
|
public boolean matchesNone(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
}
|
Objects.requireNonNull(filter);
|
||||||
return result;
|
for(int i = 0;i<size;i++) {
|
||||||
}
|
if(filter.test(array[i])) return false;
|
||||||
|
}
|
||||||
protected boolean removeIndex(int index) {
|
return true;
|
||||||
array[index] = array[--size];
|
}
|
||||||
#if TYPE_OBJECT
|
|
||||||
array[size] = null;
|
@Override
|
||||||
#endif
|
public boolean matchesAll(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
if(size != index) ARRAYS.shiftDown(array, size, index, comparator);
|
Objects.requireNonNull(filter);
|
||||||
return true;
|
for(int i = 0;i<size;i++) {
|
||||||
}
|
if(!filter.test(array[i])) return false;
|
||||||
|
}
|
||||||
@Override
|
return true;
|
||||||
public void onChanged() {
|
}
|
||||||
if(size <= 0) return;
|
|
||||||
ARRAYS.shiftDown(array, size, 0, comparator);
|
#if !TYPE_OBJECT
|
||||||
}
|
@Override
|
||||||
|
public KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
@Override
|
Objects.requireNonNull(operator);
|
||||||
public HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE copy() {
|
KEY_TYPE state = identity;
|
||||||
HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE queue = new HEAP_PRIORITY_QUEUEBRACES();
|
for(int i = 0;i<size;i++) {
|
||||||
queue.size = size;
|
state = operator.APPLY_VALUE(state, array[i]);
|
||||||
queue.comparator = comparator;
|
}
|
||||||
queue.array = Arrays.copyOf(array, array.length);
|
return state;
|
||||||
return queue;
|
}
|
||||||
}
|
|
||||||
|
#else
|
||||||
@Override
|
@Override
|
||||||
public COMPARATOR KEY_SUPER_GENERIC_TYPE comparator() {
|
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
|
||||||
return comparator;
|
Objects.requireNonNull(operator);
|
||||||
}
|
KEY_SPECIAL_TYPE state = identity;
|
||||||
|
for(int i = 0;i<size;i++) {
|
||||||
@Override
|
state = operator.APPLY_VALUE(state, array[i]);
|
||||||
public GENERIC_SPECIAL_KEY_BRACES<E> KEY_SPECIAL_TYPE[] TO_ARRAY(KEY_SPECIAL_TYPE[] input) {
|
}
|
||||||
if(input == null || input.length < size()) input = NEW_SPECIAL_KEY_ARRAY(size());
|
return state;
|
||||||
System.arraycopy(array, 0, input, 0, size());
|
}
|
||||||
return input;
|
|
||||||
}
|
#endif
|
||||||
|
@Override
|
||||||
private class Iter implements ITERATOR KEY_GENERIC_TYPE {
|
public OPTIONAL KEY_GENERIC_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
@Override
|
Objects.requireNonNull(operator);
|
||||||
public boolean hasNext() {
|
KEY_TYPE state = EMPTY_VALUE;
|
||||||
return !isEmpty();
|
boolean empty = true;
|
||||||
}
|
for(int i = 0;i<size;i++) {
|
||||||
|
if(empty) {
|
||||||
@Override
|
empty = false;
|
||||||
public KEY_TYPE NEXT() {
|
state = array[i];
|
||||||
return dequeue();
|
continue;
|
||||||
}
|
}
|
||||||
}
|
state = operator.APPLY_VALUE(state, array[i]);
|
||||||
|
}
|
||||||
|
return empty ? OPTIONAL.empty() : OPTIONAL.GET_OPTIONAL(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OPTIONAL KEY_GENERIC_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
|
Objects.requireNonNull(filter);
|
||||||
|
for(int i = 0;i<size;i++) {
|
||||||
|
if(filter.test(array[i])) {
|
||||||
|
KEY_TYPE data = array[i];
|
||||||
|
removeIndex(i);
|
||||||
|
return OPTIONAL.GET_OPTIONAL(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return OPTIONAL.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
|
Objects.requireNonNull(filter);
|
||||||
|
int result = 0;
|
||||||
|
for(int i = 0;i<size;i++) {
|
||||||
|
if(filter.test(array[i])) result++;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean removeIndex(int index) {
|
||||||
|
array[index] = array[--size];
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
array[size] = null;
|
||||||
|
#endif
|
||||||
|
if(size != index) ARRAYS.shiftDown(array, size, index, comparator);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onChanged() {
|
||||||
|
if(size <= 0) return;
|
||||||
|
ARRAYS.shiftDown(array, size, 0, comparator);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE copy() {
|
||||||
|
HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE queue = new HEAP_PRIORITY_QUEUEBRACES();
|
||||||
|
queue.size = size;
|
||||||
|
queue.comparator = comparator;
|
||||||
|
queue.array = Arrays.copyOf(array, array.length);
|
||||||
|
return queue;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public COMPARATOR KEY_SUPER_GENERIC_TYPE comparator() {
|
||||||
|
return comparator;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GENERIC_SPECIAL_KEY_BRACES<E> KEY_SPECIAL_TYPE[] TO_ARRAY(KEY_SPECIAL_TYPE[] input) {
|
||||||
|
if(input == null || input.length < size()) input = NEW_SPECIAL_KEY_ARRAY(size());
|
||||||
|
System.arraycopy(array, 0, input, 0, size());
|
||||||
|
return input;
|
||||||
|
}
|
||||||
|
|
||||||
|
private class Iter implements ITERATOR KEY_GENERIC_TYPE {
|
||||||
|
@Override
|
||||||
|
public boolean hasNext() {
|
||||||
|
return !isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE NEXT() {
|
||||||
|
if(!hasNext()) throw new NoSuchElementException();
|
||||||
|
return dequeue();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+4
@@ -6,7 +6,9 @@ import java.util.Iterator;
|
|||||||
#endif
|
#endif
|
||||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||||
|
#if QUEUES_FEATURE
|
||||||
import speiger.src.collections.PACKAGE.utils.PRIORITY_QUEUES;
|
import speiger.src.collections.PACKAGE.utils.PRIORITY_QUEUES;
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Type Speciifc PriorityDeque or Dequeue interface to allow implementations like FIFO queues.
|
* 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); }
|
public default KEY_TYPE last() { return peek(size()-1); }
|
||||||
|
|
||||||
|
#if QUEUES_FEATURE
|
||||||
/**
|
/**
|
||||||
* Creates a Wrapped PriorityDequeue that is Synchronized
|
* Creates a Wrapped PriorityDequeue that is Synchronized
|
||||||
* @return a new 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); }
|
public default PRIORITY_DEQUEUE KEY_GENERIC_TYPE synchronizeQueue(Object mutex) { return PRIORITY_QUEUES.synchronize(this, mutex); }
|
||||||
|
|
||||||
|
#endif
|
||||||
@Override
|
@Override
|
||||||
public PRIORITY_DEQUEUE KEY_GENERIC_TYPE copy();
|
public PRIORITY_DEQUEUE KEY_GENERIC_TYPE copy();
|
||||||
}
|
}
|
||||||
+202
-191
@@ -1,192 +1,203 @@
|
|||||||
package speiger.src.collections.PACKAGE.queues;
|
package speiger.src.collections.PACKAGE.queues;
|
||||||
|
|
||||||
#if TYPE_OBJECT
|
#if TYPE_OBJECT
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.function.IntFunction;
|
||||||
import speiger.src.collections.ints.functions.function.Int2ObjectFunction;
|
#else
|
||||||
#else
|
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
#endif
|
||||||
#endif
|
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
import speiger.src.collections.PACKAGE.collections.ITERABLE;
|
||||||
import speiger.src.collections.PACKAGE.collections.ITERABLE;
|
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
#if QUEUES_FEATURE
|
||||||
import speiger.src.collections.PACKAGE.utils.PRIORITY_QUEUES;
|
import speiger.src.collections.PACKAGE.utils.PRIORITY_QUEUES;
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
|
||||||
* A Simple PriorityQueue (or Queue) interface that provides with the nessesary functions to interact with it, without cluttering with the Collection interface.
|
/**
|
||||||
* @Type(T)
|
* A Simple PriorityQueue (or Queue) interface that provides with the nessesary functions to interact with it, without cluttering with the Collection interface.
|
||||||
*/
|
* @Type(T)
|
||||||
public interface PRIORITY_QUEUE KEY_GENERIC_TYPE extends ITERABLE KEY_GENERIC_TYPE
|
*/
|
||||||
{
|
public interface PRIORITY_QUEUE KEY_GENERIC_TYPE extends ITERABLE KEY_GENERIC_TYPE
|
||||||
/**
|
{
|
||||||
* @return true if the PriorityQueue is empty
|
/**
|
||||||
*/
|
* @return true if the PriorityQueue is empty
|
||||||
public default boolean isEmpty() { return size() <= 0; }
|
*/
|
||||||
/**
|
public default boolean isEmpty() { return size() <= 0; }
|
||||||
* @return the amount of elements that are stored in the PriorityQueue
|
/**
|
||||||
*/
|
* @return the amount of elements that are stored in the PriorityQueue
|
||||||
public int size();
|
*/
|
||||||
/**
|
public int size();
|
||||||
* clears all elements within the PriorityQueue,
|
/**
|
||||||
* this does not resize the backing arrays
|
* clears all elements within the PriorityQueue,
|
||||||
*/
|
* this does not resize the backing arrays
|
||||||
public void clear();
|
*/
|
||||||
|
public void clear();
|
||||||
/**
|
|
||||||
* Method to insert a element into the PriorityQueue
|
/**
|
||||||
* @param e the element that should be inserted
|
* Method to insert a element into the PriorityQueue
|
||||||
*/
|
* @param e the element that should be inserted
|
||||||
public void enqueue(KEY_TYPE e);
|
*/
|
||||||
|
public void enqueue(KEY_TYPE e);
|
||||||
/**
|
|
||||||
* Method to mass insert elements into the PriorityQueue
|
/**
|
||||||
* @param e the elements that should be inserted
|
* Method to mass insert elements into the PriorityQueue
|
||||||
*/
|
* @param e the elements that should be inserted
|
||||||
public default void enqueueAll(KEY_TYPE... e) {
|
*/
|
||||||
enqueueAll(e, 0, e.length);
|
public default void enqueueAll(KEY_TYPE... e) {
|
||||||
}
|
enqueueAll(e, 0, e.length);
|
||||||
|
}
|
||||||
/**
|
|
||||||
* Method to mass insert elements into the PriorityQueue
|
/**
|
||||||
* @param e the elements that should be inserted
|
* Method to mass insert elements into the PriorityQueue
|
||||||
* @param length the amount of elements that should be inserted
|
* @param e the elements that should be inserted
|
||||||
*/
|
* @param length the amount of elements that should be inserted
|
||||||
public default void enqueueAll(KEY_TYPE[] e, int length) {
|
*/
|
||||||
enqueueAll(e, 0, length);
|
public default void enqueueAll(KEY_TYPE[] e, int length) {
|
||||||
}
|
enqueueAll(e, 0, length);
|
||||||
|
}
|
||||||
/**
|
|
||||||
* Method to mass insert elements into the PriorityQueue
|
/**
|
||||||
* @param e the elements that should be inserted
|
* Method to mass insert elements into the PriorityQueue
|
||||||
* @param offset the offset where in the array should be started
|
* @param e the elements that should be inserted
|
||||||
* @param length the amount of elements that should be inserted
|
* @param offset the offset where in the array should be started
|
||||||
*/
|
* @param length the amount of elements that should be inserted
|
||||||
public default void enqueueAll(KEY_TYPE[] e, int offset, int length) {
|
*/
|
||||||
for(int i = 0;i<length;i++)
|
public default void enqueueAll(KEY_TYPE[] e, int offset, int length) {
|
||||||
enqueue(e[i+offset]);
|
for(int i = 0;i<length;i++)
|
||||||
}
|
enqueue(e[i+offset]);
|
||||||
|
}
|
||||||
/**
|
|
||||||
* Method to mass insert elements into the PriorityQueue
|
/**
|
||||||
* @param c the elements that should be inserted from the Collection
|
* Method to mass insert elements into the PriorityQueue
|
||||||
*/
|
* @param c the elements that should be inserted from the Collection
|
||||||
public default void enqueueAll(COLLECTION KEY_GENERIC_TYPE c) {
|
*/
|
||||||
for(ITERATOR KEY_GENERIC_TYPE iter = c.iterator();iter.hasNext();)
|
public default void enqueueAll(COLLECTION KEY_GENERIC_TYPE c) {
|
||||||
enqueue(iter.NEXT());
|
for(ITERATOR KEY_GENERIC_TYPE iter = c.iterator();iter.hasNext();)
|
||||||
}
|
enqueue(iter.NEXT());
|
||||||
|
}
|
||||||
#if TYPE_OBJECT
|
|
||||||
/**
|
#if TYPE_OBJECT
|
||||||
* Method to mass insert elements into the PriorityQueue
|
/**
|
||||||
* This method exists to add support for Java Collections to make it more useable
|
* Method to mass insert elements into the PriorityQueue
|
||||||
* @param c the elements that should be inserted from the Collection
|
* This method exists to add support for Java Collections to make it more useable
|
||||||
*/
|
* @param c the elements that should be inserted from the Collection
|
||||||
public default void enqueueAll(Collection<? extends CLASS_TYPE> c) {
|
*/
|
||||||
for(Iterator<? extends CLASS_TYPE> iter = c.iterator();iter.hasNext();)
|
public default void enqueueAll(Collection<? extends CLASS_TYPE> c) {
|
||||||
enqueue(iter.next());
|
for(Iterator<? extends CLASS_TYPE> iter = c.iterator();iter.hasNext();)
|
||||||
}
|
enqueue(iter.next());
|
||||||
|
}
|
||||||
#endif
|
|
||||||
|
#endif
|
||||||
/**
|
|
||||||
* Method to extract a element from the PriorityQueue
|
/**
|
||||||
* @return a element from the Queue
|
* Method to extract a element from the PriorityQueue
|
||||||
* @throws java.util.NoSuchElementException if no element is present
|
* @return a element from the Queue
|
||||||
*/
|
* @throws java.util.NoSuchElementException if no element is present
|
||||||
public KEY_TYPE dequeue();
|
*/
|
||||||
|
public KEY_TYPE dequeue();
|
||||||
/**
|
|
||||||
* Peeking function to see whats inside the queue.
|
/**
|
||||||
* @param index of the element that is requested to be viewed.
|
* Peeking function to see whats inside the queue.
|
||||||
* @return the element that is requested
|
* @param index of the element that is requested to be viewed.
|
||||||
*/
|
* @return the element that is requested
|
||||||
public KEY_TYPE peek(int index);
|
*/
|
||||||
/**
|
public KEY_TYPE peek(int index);
|
||||||
* Shows the element that is to be returned next
|
/**
|
||||||
* @return the first element in the Queue
|
* Shows the element that is to be returned next
|
||||||
*/
|
* @return the first element in the Queue
|
||||||
public default KEY_TYPE first() { return peek(0); }
|
*/
|
||||||
|
public default KEY_TYPE first() { return peek(0); }
|
||||||
/**
|
|
||||||
* Removes the first found element in the queue
|
/**
|
||||||
* @param e the element that should be removed
|
* Method to find out if a element is part of the queue
|
||||||
* @return if a searched element was removed
|
* @param e the element that is searched for
|
||||||
*/
|
* @return true if the element is in the queue
|
||||||
public boolean removeFirst(KEY_TYPE e);
|
*/
|
||||||
/**
|
public boolean contains(KEY_TYPE e);
|
||||||
* Removes the last found element in the queue
|
|
||||||
* @param e the element that should be removed
|
/**
|
||||||
* @return if a searched element was removed
|
* Removes the first found element in the queue
|
||||||
*/
|
* @param e the element that should be removed
|
||||||
public boolean removeLast(KEY_TYPE e);
|
* @return if a searched element was removed
|
||||||
|
*/
|
||||||
/**
|
public boolean removeFirst(KEY_TYPE e);
|
||||||
* Allows to notify the Queue to be revalidate its data
|
/**
|
||||||
*/
|
* Removes the last found element in the queue
|
||||||
public void onChanged();
|
* @param e the element that should be removed
|
||||||
|
* @return if a searched element was removed
|
||||||
/**
|
*/
|
||||||
* A Function that does a shallow clone of the PriorityQueue itself.
|
public boolean removeLast(KEY_TYPE e);
|
||||||
* This function is more optimized then a copy constructor since the PriorityQueue does not have to be unsorted/resorted.
|
|
||||||
* It can be compared to Cloneable but with less exception risk
|
/**
|
||||||
* @return a Shallow Copy of the PriorityQueue
|
* Allows to notify the Queue to be revalidate its data
|
||||||
* @note Wrappers and view PriorityQueues will not support this feature
|
*/
|
||||||
*/
|
public void onChanged();
|
||||||
public PRIORITY_QUEUE KEY_GENERIC_TYPE copy();
|
|
||||||
|
/**
|
||||||
/**
|
* A Function that does a shallow clone of the PriorityQueue itself.
|
||||||
* @return the sorter of the Queue, can be null
|
* This function is more optimized then a copy constructor since the PriorityQueue does not have to be unsorted/resorted.
|
||||||
*/
|
* It can be compared to Cloneable but with less exception risk
|
||||||
public COMPARATOR KEY_SUPER_GENERIC_TYPE comparator();
|
* @return a Shallow Copy of the PriorityQueue
|
||||||
|
* @note Wrappers and view PriorityQueues will not support this feature
|
||||||
#if TYPE_OBJECT
|
*/
|
||||||
/**
|
public PRIORITY_QUEUE KEY_GENERIC_TYPE copy();
|
||||||
* @return draining iterator of the PriorityQueue
|
|
||||||
*/
|
/**
|
||||||
public ITERATOR KEY_GENERIC_TYPE iterator();
|
* @return the sorter of the Queue, can be null
|
||||||
#endif
|
*/
|
||||||
|
public COMPARATOR KEY_SUPER_GENERIC_TYPE comparator();
|
||||||
/**
|
|
||||||
* Creates a Wrapped PriorityQueue that is Synchronized
|
#if TYPE_OBJECT
|
||||||
* @return a new PriorityQueue that is synchronized
|
/**
|
||||||
* @see PRIORITY_QUEUES#synchronize
|
* @return draining iterator of the PriorityQueue
|
||||||
*/
|
*/
|
||||||
public default PRIORITY_QUEUE KEY_GENERIC_TYPE synchronizeQueue() { return PRIORITY_QUEUES.synchronize(this); }
|
public ITERATOR KEY_GENERIC_TYPE iterator();
|
||||||
|
|
||||||
/**
|
#endif
|
||||||
* Creates a Wrapped PriorityQueue that is Synchronized
|
#if QUEUES_FEATURE
|
||||||
* @param mutex is the controller of the synchronization block
|
/**
|
||||||
* @return a new PriorityQueue Wrapper that is synchronized
|
* Creates a Wrapped PriorityQueue that is Synchronized
|
||||||
* @see PRIORITY_QUEUES#synchronize
|
* @return a new PriorityQueue that is synchronized
|
||||||
*/
|
* @see PRIORITY_QUEUES#synchronize
|
||||||
public default PRIORITY_QUEUE KEY_GENERIC_TYPE synchronizeQueue(Object mutex) { return PRIORITY_QUEUES.synchronize(this, mutex); }
|
*/
|
||||||
|
public default PRIORITY_QUEUE KEY_GENERIC_TYPE synchronizeQueue() { return PRIORITY_QUEUES.synchronize(this); }
|
||||||
/**
|
|
||||||
* A method to drop the contents of the Queue without clearing the queue
|
/**
|
||||||
* @Type(E)
|
* Creates a Wrapped PriorityQueue that is Synchronized
|
||||||
* @return the contents of the queue into a seperate array.
|
* @param mutex is the controller of the synchronization block
|
||||||
*/
|
* @return a new PriorityQueue Wrapper that is synchronized
|
||||||
public default GENERIC_SPECIAL_KEY_BRACES<E> KEY_SPECIAL_TYPE[] TO_ARRAY() { return TO_ARRAY(NEW_SPECIAL_KEY_ARRAY(size())); }
|
* @see PRIORITY_QUEUES#synchronize
|
||||||
/**
|
*/
|
||||||
* A method to drop the contents of the Queue without clearing the queue
|
public default PRIORITY_QUEUE KEY_GENERIC_TYPE synchronizeQueue(Object mutex) { return PRIORITY_QUEUES.synchronize(this, mutex); }
|
||||||
* @param input where the elements should be inserted to. If it does not fit then it creates a new appropiatly created array
|
|
||||||
* @Type(E)
|
#endif
|
||||||
* @return the contents of the queue into a seperate array.
|
/**
|
||||||
* @note if the Type is generic then a Object Array is created instead of a Type Array
|
* A method to drop the contents of the Queue without clearing the queue
|
||||||
*/
|
* @Type(E)
|
||||||
public GENERIC_SPECIAL_KEY_BRACES<E> KEY_SPECIAL_TYPE[] TO_ARRAY(KEY_SPECIAL_TYPE[] input);
|
* @return the contents of the queue into a seperate array.
|
||||||
#if TYPE_OBJECT
|
*/
|
||||||
/**
|
public default GENERIC_SPECIAL_KEY_BRACES<E> KEY_SPECIAL_TYPE[] TO_ARRAY() { return TO_ARRAY(NEW_SPECIAL_KEY_ARRAY(size())); }
|
||||||
* A Helper function that simplifies the process of creating a new Array.
|
/**
|
||||||
* @param action the array creation function
|
* A method to drop the contents of the Queue without clearing the queue
|
||||||
* @return an array containing all of the elements in this collection
|
* @param input where the elements should be inserted to. If it does not fit then it creates a new appropiatly created array
|
||||||
* @see Collection#toArray(Object[])
|
* @Type(E)
|
||||||
*/
|
* @return the contents of the queue into a seperate array.
|
||||||
default KEY_TYPE[] TO_ARRAY(Int2ObjectFunction<KEY_TYPE[]> action) {
|
* @note if the Type is generic then a Object Array is created instead of a Type Array
|
||||||
return TO_ARRAY(action.get(size()));
|
*/
|
||||||
}
|
public GENERIC_SPECIAL_KEY_BRACES<E> KEY_SPECIAL_TYPE[] TO_ARRAY(KEY_SPECIAL_TYPE[] input);
|
||||||
#endif
|
#if TYPE_OBJECT
|
||||||
|
/**
|
||||||
|
* 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 <E> E[] TO_ARRAY(IntFunction<E[]> action) {
|
||||||
|
return TO_ARRAY(action.apply(size()));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
+1716
-1590
File diff suppressed because it is too large
Load Diff
+152
-50
@@ -1,50 +1,152 @@
|
|||||||
package speiger.src.collections.PACKAGE.sets;
|
package speiger.src.collections.PACKAGE.sets;
|
||||||
|
|
||||||
#if TYPE_OBJECT
|
#if TYPE_OBJECT
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
#endif
|
#endif
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import speiger.src.collections.PACKAGE.collections.ABSTRACT_COLLECTION;
|
import speiger.src.collections.PACKAGE.collections.ABSTRACT_COLLECTION;
|
||||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
||||||
|
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||||
/**
|
|
||||||
* Abstract Type Specific Set that reduces boxing/unboxing
|
/**
|
||||||
* @Type(T)
|
* Abstract Type Specific Set that reduces boxing/unboxing
|
||||||
*/
|
* @Type(T)
|
||||||
public abstract class ABSTRACT_SET KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION KEY_GENERIC_TYPE implements SET KEY_GENERIC_TYPE
|
*/
|
||||||
{
|
public abstract class ABSTRACT_SET KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION KEY_GENERIC_TYPE implements SET KEY_GENERIC_TYPE
|
||||||
#if TYPE_OBJECT
|
{
|
||||||
@Override
|
#if TYPE_OBJECT
|
||||||
public KEY_TYPE addOrGet(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
@Override
|
||||||
|
public KEY_TYPE addOrGet(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||||
#endif
|
|
||||||
@Override
|
#endif
|
||||||
public abstract ITERATOR KEY_GENERIC_TYPE iterator();
|
@Override
|
||||||
@Override
|
public abstract ITERATOR KEY_GENERIC_TYPE iterator();
|
||||||
public ABSTRACT_SET KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
@Override
|
||||||
|
public ABSTRACT_SET KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
@Override
|
||||||
int hashCode = 0;
|
public int hashCode() {
|
||||||
ITERATOR KEY_GENERIC_TYPE i = iterator();
|
int hashCode = 0;
|
||||||
while(i.hasNext())
|
ITERATOR KEY_GENERIC_TYPE i = iterator();
|
||||||
hashCode += KEY_TO_HASH(i.NEXT());
|
while(i.hasNext())
|
||||||
return hashCode;
|
hashCode += KEY_TO_HASH(i.NEXT());
|
||||||
}
|
return hashCode;
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
@Override
|
||||||
if (o == this)
|
public boolean equals(Object o) {
|
||||||
return true;
|
if (o == this)
|
||||||
if (!(o instanceof Set))
|
return true;
|
||||||
return false;
|
if (!(o instanceof Set))
|
||||||
Set<?> l = (Set<?>)o;
|
return false;
|
||||||
if(l.size() != size()) return false;
|
Set<?> l = (Set<?>)o;
|
||||||
try {
|
if(l.size() != size()) return false;
|
||||||
return containsAll(l);
|
try {
|
||||||
} catch (ClassCastException | NullPointerException unused) {
|
return containsAll(l);
|
||||||
return false;
|
} catch (ClassCastException | NullPointerException unused) {
|
||||||
}
|
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
|
||||||
|
}
|
||||||
|
|||||||
+150
-372
@@ -8,16 +8,33 @@ import java.util.function.BiFunction;
|
|||||||
#endif
|
#endif
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import java.util.Objects;
|
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;
|
import java.util.Set;
|
||||||
#if PRIMITIVES
|
#if JDK_FUNCTION
|
||||||
|
import java.util.function.PREDICATE;
|
||||||
|
#endif
|
||||||
|
#if PRIMITIVES && !JDK_FUNCTION
|
||||||
import java.util.function.JAVA_PREDICATE;
|
import java.util.function.JAVA_PREDICATE;
|
||||||
#endif
|
#endif
|
||||||
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
||||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||||
|
#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;
|
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||||
|
#if !JDK_FUNCTION
|
||||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||||
|
#endif
|
||||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||||
@@ -54,6 +71,7 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
|||||||
* @throws NegativeArraySizeException if the capacity is negative
|
* @throws NegativeArraySizeException if the capacity is negative
|
||||||
*/
|
*/
|
||||||
public ARRAY_SET(int capacity) {
|
public ARRAY_SET(int capacity) {
|
||||||
|
if(capacity < 0) throw new IllegalStateException("Size has to be 0 or greater");
|
||||||
data = NEW_KEY_ARRAY(capacity);
|
data = NEW_KEY_ARRAY(capacity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,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.
|
* @param array the array that should be used for set.
|
||||||
*/
|
*/
|
||||||
public ARRAY_SET(KEY_TYPE[] array) {
|
public ARRAY_SET(KEY_TYPE[] array) {
|
||||||
this(array, array.length);
|
this(array, 0, array.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -76,6 +94,18 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
|||||||
addAll(array, length);
|
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.
|
* 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.
|
* @param c the elements that should be added to the set.
|
||||||
@@ -119,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());
|
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
|
@Override
|
||||||
public boolean add(KEY_TYPE o) {
|
public boolean add(KEY_TYPE o) {
|
||||||
int index = findIndex(o);
|
int index = findIndex(o);
|
||||||
@@ -141,6 +207,25 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#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
|
@Override
|
||||||
public boolean addAndMoveToFirst(KEY_TYPE o) {
|
public boolean addAndMoveToFirst(KEY_TYPE o) {
|
||||||
int index = findIndex(o);
|
int index = findIndex(o);
|
||||||
@@ -168,7 +253,7 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
|||||||
}
|
}
|
||||||
else if(index != size - 1) {
|
else if(index != size - 1) {
|
||||||
o = data[index];
|
o = data[index];
|
||||||
System.arraycopy(data, index+1, data, index, size - index);
|
System.arraycopy(data, index+1, data, index, size - index - 1);
|
||||||
data[size-1] = o;
|
data[size-1] = o;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -212,13 +297,13 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE FIRST_KEY() {
|
public KEY_TYPE GET_FIRST_KEY() {
|
||||||
if(size == 0) throw new NoSuchElementException();
|
if(size == 0) throw new NoSuchElementException();
|
||||||
return data[0];
|
return data[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE LAST_KEY() {
|
public KEY_TYPE GET_LAST_KEY() {
|
||||||
if(size == 0) throw new NoSuchElementException();
|
if(size == 0) throw new NoSuchElementException();
|
||||||
return data[size - 1];
|
return data[size - 1];
|
||||||
}
|
}
|
||||||
@@ -347,7 +432,7 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE POLL_FIRST_KEY() {
|
public KEY_TYPE REMOVE_FIRST_KEY() {
|
||||||
if(size == 0) throw new NoSuchElementException();
|
if(size == 0) throw new NoSuchElementException();
|
||||||
KEY_TYPE result = data[0];
|
KEY_TYPE result = data[0];
|
||||||
System.arraycopy(data, 1, data, 0, --size);
|
System.arraycopy(data, 1, data, 0, --size);
|
||||||
@@ -358,7 +443,7 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE POLL_LAST_KEY() {
|
public KEY_TYPE REMOVE_LAST_KEY() {
|
||||||
if(size == 0) throw new NoSuchElementException();
|
if(size == 0) throw new NoSuchElementException();
|
||||||
size--;
|
size--;
|
||||||
#if TYPE_OBJECT
|
#if TYPE_OBJECT
|
||||||
@@ -390,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++]));
|
for(int i = 0;i<size;action.accept(data[i++]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
|
||||||
|
Objects.requireNonNull(action);
|
||||||
|
for(int i = 0;i<size;action.accept(i, data[i++]));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
||||||
Objects.requireNonNull(action);
|
Objects.requireNonNull(action);
|
||||||
@@ -401,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) {
|
public boolean matchesAny(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
for(int i = 0;i<size;i++) {
|
for(int i = 0;i<size;i++) {
|
||||||
if(filter.TEST_VALUE(data[i])) return true;
|
if(filter.test(data[i])) return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -410,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) {
|
public boolean matchesNone(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
for(int i = 0;i<size;i++) {
|
for(int i = 0;i<size;i++) {
|
||||||
if(filter.TEST_VALUE(data[i])) return false;
|
if(filter.test(data[i])) return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -419,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) {
|
public boolean matchesAll(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
for(int i = 0;i<size;i++) {
|
for(int i = 0;i<size;i++) {
|
||||||
if(!filter.TEST_VALUE(data[i])) return false;
|
if(!filter.test(data[i])) return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
public OPTIONAL KEY_GENERIC_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
for(int i = 0;i<size;i++) {
|
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
|
#if !TYPE_OBJECT
|
||||||
@@ -457,7 +548,7 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
@Override
|
@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);
|
Objects.requireNonNull(operator);
|
||||||
KEY_TYPE state = EMPTY_VALUE;
|
KEY_TYPE state = EMPTY_VALUE;
|
||||||
boolean empty = true;
|
boolean empty = true;
|
||||||
@@ -469,7 +560,7 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
|||||||
}
|
}
|
||||||
state = operator.APPLY_VALUE(state, data[i]);
|
state = operator.APPLY_VALUE(state, data[i]);
|
||||||
}
|
}
|
||||||
return state;
|
return empty ? OPTIONAL.empty() : OPTIONAL.GET_OPTIONAL(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -477,7 +568,7 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
|||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
int result = 0;
|
int result = 0;
|
||||||
for(int i = 0;i<size;i++) {
|
for(int i = 0;i<size;i++) {
|
||||||
if(filter.TEST_VALUE(data[i])) result++;
|
if(filter.test(data[i])) result++;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -498,13 +589,18 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BI_ITERATOR KEY_GENERIC_TYPE iterator() {
|
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
|
@Override
|
||||||
public BI_ITERATOR KEY_GENERIC_TYPE iterator(KEY_TYPE fromElement) {
|
public BI_ITERATOR KEY_GENERIC_TYPE iterator(KEY_TYPE fromElement) {
|
||||||
int index = findIndex(fromElement);
|
int index = findIndex(fromElement);
|
||||||
if(index != -1) return new SetIterator(index);
|
if(index != -1) return new SetIterator(true, index);
|
||||||
throw new NoSuchElementException();
|
throw new NoSuchElementException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -538,6 +634,7 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
|||||||
@Override
|
@Override
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public Object[] toArray() {
|
public Object[] toArray() {
|
||||||
|
if(isEmpty()) return ObjectArrays.EMPTY_ARRAY;
|
||||||
Object[] obj = new Object[size()];
|
Object[] obj = new Object[size()];
|
||||||
for(int i = 0;i<size();i++)
|
for(int i = 0;i<size();i++)
|
||||||
obj[i] = KEY_TO_OBJ(data[i]);
|
obj[i] = KEY_TO_OBJ(data[i]);
|
||||||
@@ -554,388 +651,59 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
|||||||
if (a.length > size) a[size] = null;
|
if (a.length > size) a[size] = null;
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disabled until a Proper Implementation can be thought out or it is decided that the interface is thrown out.
|
|
||||||
// private class SubSet extends ABSTRACT_SET KEY_GENERIC_TYPE implements SORTED_SET KEY_GENERIC_TYPE {
|
|
||||||
// int offset;
|
|
||||||
// int length;
|
|
||||||
//
|
|
||||||
// SubSet(int offset, int length) {
|
|
||||||
// this.offset = offset;
|
|
||||||
// this.length = length;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// int end() { return offset+length; }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public boolean add(KEY_TYPE o) {
|
|
||||||
// int index = findIndex(o);
|
|
||||||
// if(index == -1) {
|
|
||||||
// if(data.length == size) data = Arrays.copyOf(data, size == 0 ? 2 : size * 2);
|
|
||||||
// if(end() != size) System.arraycopy(data, end(), data, end()+1, size-(offset+length));
|
|
||||||
// data[end()] = o;
|
|
||||||
// size++;
|
|
||||||
// length++;
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public boolean addAndMoveToFirst(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, offset, data, offset+1, size-offset);
|
|
||||||
// data[offset] = o;
|
|
||||||
// size++;
|
|
||||||
// length++;
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
// else if(index != 0) {
|
|
||||||
// o = data[index];
|
|
||||||
// System.arraycopy(data, offset, data, offset+1, index-offset);
|
|
||||||
// data[offset] = o;
|
|
||||||
// }
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public boolean addAndMoveToLast(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, end()+1, data, end(), size-end());
|
|
||||||
// data[end()] = o;
|
|
||||||
// size++;
|
|
||||||
// length++;
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
// else if(index != 0) {
|
|
||||||
// o = data[index];
|
|
||||||
// System.arraycopy(data, offset+1, data, offset, index-offset);
|
|
||||||
// data[offset+length] = o;
|
|
||||||
// }
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public boolean moveToFirst(KEY_TYPE o) {
|
|
||||||
// int index = findIndex(o);
|
|
||||||
// if(index > offset) {
|
|
||||||
// o = data[index];
|
|
||||||
// System.arraycopy(data, offset, data, offset+1, index-offset);
|
|
||||||
// data[offset] = o;
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public boolean moveToLast(KEY_TYPE o) {
|
|
||||||
// int index = findIndex(o);
|
|
||||||
// if(index != -1 && index < end()-1) {
|
|
||||||
// o = data[index];
|
|
||||||
// System.arraycopy(data, index+1, data, index, end()-index-1);
|
|
||||||
// data[end()-1] = o;
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//#if !TYPE_OBJECT
|
|
||||||
// @Override
|
|
||||||
// public boolean contains(KEY_TYPE e) {
|
|
||||||
// return findIndex(e) != -1;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//#endif
|
|
||||||
// @Override
|
|
||||||
// public boolean contains(Object e) {
|
|
||||||
// return findIndex(e) != -1;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public KEY_TYPE FIRST_KEY() {
|
|
||||||
// if(length == 0) throw new NoSuchElementException();
|
|
||||||
// return data[offset];
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public KEY_TYPE LAST_KEY() {
|
|
||||||
// if(length == 0) throw new NoSuchElementException();
|
|
||||||
// return data[end()-1];
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//#if !TYPE_OBJECT
|
|
||||||
// @Override
|
|
||||||
// public boolean remove(KEY_TYPE o) {
|
|
||||||
// int index = findIndex(o);
|
|
||||||
// if(index != -1) {
|
|
||||||
// size--;
|
|
||||||
// length--;
|
|
||||||
// if(index != size) System.arraycopy(data, index+1, data, index, size - index);
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//#endif
|
|
||||||
// @Override
|
|
||||||
// public boolean remove(Object o) {
|
|
||||||
// int index = findIndex(o);
|
|
||||||
// if(index != -1) {
|
|
||||||
// size--;
|
|
||||||
// length--;
|
|
||||||
// if(index != size) System.arraycopy(data, index+1, data, index, size - index);
|
|
||||||
//#if TYPE_OBJECT
|
|
||||||
// data[size] = EMPTY_KEY_VALUE;
|
|
||||||
//#endif
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public KEY_TYPE POLL_FIRST_KEY() {
|
|
||||||
// if(length == 0) throw new NoSuchElementException();
|
|
||||||
// size--;
|
|
||||||
// length--;
|
|
||||||
// KEY_TYPE result = data[offset];
|
|
||||||
// System.arraycopy(data, offset+1, data, offset, size-offset);
|
|
||||||
//#if TYPE_OBJECT
|
|
||||||
// data[size] = EMPTY_KEY_VALUE;
|
|
||||||
//#endif
|
|
||||||
// return result;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public KEY_TYPE POLL_LAST_KEY() {
|
|
||||||
// if(length == 0) throw new NoSuchElementException();
|
|
||||||
// KEY_TYPE result = data[offset+length];
|
|
||||||
// size--;
|
|
||||||
// length--;
|
|
||||||
// System.arraycopy(data, end()+1, data, end(), size-end());
|
|
||||||
//#if TYPE_OBJECT
|
|
||||||
// data[size] = EMPTY_KEY_VALUE;
|
|
||||||
//#endif
|
|
||||||
// return result;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public COMPARATOR KEY_GENERIC_TYPE comparator() {
|
|
||||||
// return null;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public BI_ITERATOR KEY_GENERIC_TYPE iterator() {
|
|
||||||
// return new SetIterator(offset);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public BI_ITERATOR KEY_GENERIC_TYPE iterator(KEY_TYPE fromElement) {
|
|
||||||
// int index = findIndex(fromElement);
|
|
||||||
// if(index != -1) return new SetIterator(index);
|
|
||||||
// throw new NoSuchElementException();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public SubSet copy() { throw new UnsupportedOperationException(); }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public SORTED_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) {
|
|
||||||
// int fromIndex = findIndex(fromElement);
|
|
||||||
// int toIndex = findIndex(toElement);
|
|
||||||
// if(fromIndex == -1 || toIndex == -1) throw new NoSuchElementException();
|
|
||||||
// return new SubSet(fromIndex, toIndex - fromIndex + 1);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public SORTED_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement) {
|
|
||||||
// int toIndex = findIndex(toElement);
|
|
||||||
// if(toIndex == -1) throw new NoSuchElementException();
|
|
||||||
// return new SubSet(0, toIndex+1);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public SORTED_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) {
|
|
||||||
// int fromIndex = findIndex(fromElement);
|
|
||||||
// if(fromIndex == -1) throw new NoSuchElementException();
|
|
||||||
// return new SubSet(fromIndex, size - fromIndex);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public int size() {
|
|
||||||
// return length;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//#if !TYPE_OBJECT
|
|
||||||
// @Override
|
|
||||||
// public KEY_TYPE[] TO_ARRAY(KEY_TYPE[] a) {
|
|
||||||
// if(a == null || a.length < size()) return Arrays.copyOfRange(data, offset, end());
|
|
||||||
// System.arraycopy(data, offset, a, 0, size());
|
|
||||||
// return a;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//#endif
|
|
||||||
// @Override
|
|
||||||
// @Deprecated
|
|
||||||
// public Object[] toArray() {
|
|
||||||
// Object[] obj = new Object[size()];
|
|
||||||
// for(int i = 0;i<size();i++)
|
|
||||||
// obj[i] = KEY_TO_OBJ(data[offset+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());
|
|
||||||
// for(int i = 0;i<size();i++)
|
|
||||||
// a[i] = (E)KEY_TO_OBJ(data[offset+i]);
|
|
||||||
// return a;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//#if !TYPE_OBJECT
|
|
||||||
// protected int findIndex(KEY_TYPE o) {
|
|
||||||
// for(int i = length-1;i>=0;i--)
|
|
||||||
// if(KEY_EQUALS(data[offset+i], o)) return i + offset;
|
|
||||||
// return -1;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//#endif
|
|
||||||
// protected int findIndex(Object o) {
|
|
||||||
// for(int i = length-1;i>=0;i--)
|
|
||||||
// if(EQUALS_KEY_TYPE(data[offset+i], o)) return i + offset;
|
|
||||||
// return -1;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// private class SetIterator implements LIST_ITERATOR KEY_GENERIC_TYPE {
|
|
||||||
// int index;
|
|
||||||
// int lastReturned = -1;
|
|
||||||
//
|
|
||||||
// public SetIterator(int index) {
|
|
||||||
// this.index = index;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public boolean hasNext() {
|
|
||||||
// return index < size();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public KEY_TYPE NEXT() {
|
|
||||||
// if(!hasNext()) throw new NoSuchElementException();
|
|
||||||
// lastReturned = index;
|
|
||||||
// return data[index++];
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public boolean hasPrevious() {
|
|
||||||
// return index > 0;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public KEY_TYPE PREVIOUS() {
|
|
||||||
// if(!hasPrevious()) throw new NoSuchElementException();
|
|
||||||
// lastReturned = index;
|
|
||||||
// return data[index--];
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public int nextIndex() {
|
|
||||||
// return index;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public int previousIndex() {
|
|
||||||
// return index-1;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void remove() {
|
|
||||||
// if(lastReturned == -1)
|
|
||||||
// throw new IllegalStateException();
|
|
||||||
// SubSet.this.remove(data[lastReturned]);
|
|
||||||
// if(lastReturned < index)
|
|
||||||
// index--;
|
|
||||||
// lastReturned = -1;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// #if TYPE_OBJECT
|
|
||||||
// @Override
|
|
||||||
// public void set(Object e) { throw new UnsupportedOperationException(); }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void add(Object e) { throw new UnsupportedOperationException(); }
|
|
||||||
//
|
|
||||||
// #else
|
|
||||||
// @Override
|
|
||||||
// public void set(KEY_TYPE e) { throw new UnsupportedOperationException(); }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void add(KEY_TYPE e) { throw new UnsupportedOperationException(); }
|
|
||||||
//
|
|
||||||
// #endif
|
|
||||||
// @Override
|
|
||||||
// public int skip(int amount) {
|
|
||||||
// if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
|
||||||
// int steps = Math.min(amount, (size() - 1) - index);
|
|
||||||
// index += steps;
|
|
||||||
// return steps;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public int back(int amount) {
|
|
||||||
// if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
|
||||||
// int steps = Math.min(amount, index);
|
|
||||||
// index -= steps;
|
|
||||||
// return steps;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
private class SetIterator implements LIST_ITERATOR KEY_GENERIC_TYPE {
|
private class SetIterator implements LIST_ITERATOR KEY_GENERIC_TYPE {
|
||||||
|
boolean forward;
|
||||||
int index;
|
int index;
|
||||||
int lastReturned = -1;
|
int lastReturned = -1;
|
||||||
|
|
||||||
public SetIterator(int index) {
|
public SetIterator(boolean forward, int index) {
|
||||||
|
this.forward = forward;
|
||||||
this.index = index;
|
this.index = index;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasNext() {
|
public boolean hasNext() {
|
||||||
return index < size();
|
return forward ? index < size() : index > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE NEXT() {
|
public KEY_TYPE NEXT() {
|
||||||
if(!hasNext()) throw new NoSuchElementException();
|
if(!hasNext()) throw new NoSuchElementException();
|
||||||
lastReturned = index;
|
if(forward) {
|
||||||
return data[index++];
|
lastReturned = index;
|
||||||
|
return data[index++];
|
||||||
|
}
|
||||||
|
index--;
|
||||||
|
return data[(lastReturned = index)];
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasPrevious() {
|
public boolean hasPrevious() {
|
||||||
return index > 0;
|
return forward ? index > 0 : index < size();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE PREVIOUS() {
|
public KEY_TYPE PREVIOUS() {
|
||||||
if(!hasPrevious()) throw new NoSuchElementException();
|
if(!hasPrevious()) throw new NoSuchElementException();
|
||||||
|
if(forward) {
|
||||||
|
index--;
|
||||||
|
return data[(lastReturned = index)];
|
||||||
|
}
|
||||||
lastReturned = index;
|
lastReturned = index;
|
||||||
return data[index--];
|
return data[index++];
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int nextIndex() {
|
public int nextIndex() {
|
||||||
return index;
|
if(forward) return index;
|
||||||
|
return size - index;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int previousIndex() {
|
public int previousIndex() {
|
||||||
return index-1;
|
if(forward) return index-1;
|
||||||
|
return (size - index)-1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -964,16 +732,26 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
|||||||
@Override
|
@Override
|
||||||
public int skip(int amount) {
|
public int skip(int amount) {
|
||||||
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
||||||
int steps = Math.min(amount, (size() - 1) - index);
|
return forward ? moveForward(amount) : moveBackwards(amount);
|
||||||
index += steps;
|
|
||||||
return steps;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int back(int amount) {
|
public int back(int amount) {
|
||||||
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int moveBackwards(int amount) {
|
||||||
int steps = Math.min(amount, index);
|
int steps = Math.min(amount, index);
|
||||||
index -= steps;
|
index -= steps;
|
||||||
|
if(steps > 0) lastReturned = Math.min(index, size()-1);
|
||||||
return steps;
|
return steps;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+696
-578
File diff suppressed because it is too large
Load Diff
+1016
-822
File diff suppressed because it is too large
Load Diff
+987
-793
File diff suppressed because it is too large
Load Diff
+8
-2
@@ -3,9 +3,13 @@ package speiger.src.collections.PACKAGE.sets;
|
|||||||
import java.util.NavigableSet;
|
import java.util.NavigableSet;
|
||||||
|
|
||||||
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
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.collections.SPLIT_ITERATOR;
|
||||||
import speiger.src.collections.PACKAGE.utils.SETS;
|
|
||||||
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
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
|
* 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
|
@Override
|
||||||
public NAVIGABLE_SET KEY_GENERIC_TYPE copy();
|
public NAVIGABLE_SET KEY_GENERIC_TYPE copy();
|
||||||
|
|
||||||
#if !TYPE_BOOLEAN
|
#if SETS_FEATURE
|
||||||
/**
|
/**
|
||||||
* Creates a Wrapped NavigableSet that is Synchronized
|
* Creates a Wrapped NavigableSet that is Synchronized
|
||||||
* @return a new 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); }
|
public default NAVIGABLE_SET KEY_GENERIC_TYPE unmodifiable() { return SETS.unmodifiable(this); }
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
#if SPLIT_ITERATOR_FEATURE
|
||||||
/**
|
/**
|
||||||
* A Type Specific Type Splititerator to reduce boxing/unboxing
|
* A Type Specific Type Splititerator to reduce boxing/unboxing
|
||||||
* @return type specific splititerator
|
* @return type specific splititerator
|
||||||
@@ -150,6 +155,7 @@ public interface NAVIGABLE_SET KEY_GENERIC_TYPE extends NavigableSet<CLASS_TYPE>
|
|||||||
@Override
|
@Override
|
||||||
default SPLIT_ITERATOR KEY_GENERIC_TYPE spliterator() { return SPLIT_ITERATORS.createSplititerator(this, 0); }
|
default SPLIT_ITERATOR KEY_GENERIC_TYPE spliterator() { return SPLIT_ITERATORS.createSplititerator(this, 0); }
|
||||||
|
|
||||||
|
#endif
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
@Deprecated
|
||||||
|
|||||||
+822
-712
File diff suppressed because it is too large
Load Diff
+790
-680
File diff suppressed because it is too large
Load Diff
+77
-7
@@ -1,9 +1,19 @@
|
|||||||
package speiger.src.collections.PACKAGE.sets;
|
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.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.collections.SPLIT_ITERATOR;
|
||||||
import speiger.src.collections.PACKAGE.utils.SETS;
|
|
||||||
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
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
|
* 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)
|
* @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.
|
* 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
|
@Override
|
||||||
public BI_ITERATOR KEY_GENERIC_TYPE iterator();
|
public BI_ITERATOR KEY_GENERIC_TYPE iterator();
|
||||||
|
public BI_ITERATOR KEY_GENERIC_TYPE reverseIterator();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A type Specific Iterator starting from a given key
|
* 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);
|
public BI_ITERATOR KEY_GENERIC_TYPE iterator(KEY_TYPE fromElement);
|
||||||
|
|
||||||
|
#if SPLIT_ITERATOR_FEATURE
|
||||||
/**
|
/**
|
||||||
* A Type Specific Type Splititerator to reduce boxing/unboxing
|
* A Type Specific Type Splititerator to reduce boxing/unboxing
|
||||||
* @return type specific splititerator
|
* @return type specific splititerator
|
||||||
@@ -66,28 +82,82 @@ public interface ORDERED_SET KEY_GENERIC_TYPE extends SET KEY_GENERIC_TYPE
|
|||||||
@Override
|
@Override
|
||||||
default SPLIT_ITERATOR KEY_GENERIC_TYPE spliterator() { return SPLIT_ITERATORS.createSplititerator(this, 0); }
|
default SPLIT_ITERATOR KEY_GENERIC_TYPE spliterator() { return SPLIT_ITERATORS.createSplititerator(this, 0); }
|
||||||
|
|
||||||
|
#endif
|
||||||
/**
|
/**
|
||||||
* A method to get the first element in the set
|
* A method to get the first element in the set
|
||||||
* @return 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
|
* A method to get and remove the first element in the set
|
||||||
* @return 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
|
* A method to get the last element in the set
|
||||||
* @return 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
|
* A method to get and remove the last element in the set
|
||||||
* @return 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
|
* Creates a Wrapped OrderedSet that is Synchronized
|
||||||
* @return a new OrderedSet that is synchronized
|
* @return a new OrderedSet that is synchronized
|
||||||
|
|||||||
+1781
-1656
File diff suppressed because it is too large
Load Diff
@@ -4,11 +4,13 @@ import java.util.Set;
|
|||||||
|
|
||||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||||
|
#if SPLIT_ITERATOR_FEATURE
|
||||||
import speiger.src.collections.PACKAGE.collections.SPLIT_ITERATOR;
|
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;
|
import speiger.src.collections.PACKAGE.utils.SETS;
|
||||||
#endif
|
#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);
|
public KEY_TYPE addOrGet(KEY_TYPE o);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
#if !TYPE_BOOLEAN
|
#if SETS_FEATURE
|
||||||
/**
|
/**
|
||||||
* Creates a Wrapped Set that is Synchronized
|
* Creates a Wrapped Set that is Synchronized
|
||||||
* @return a new 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); }
|
public default SET KEY_GENERIC_TYPE unmodifiable() { return SETS.unmodifiable(this); }
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
#if SPLIT_ITERATOR_FEATURE
|
||||||
/**
|
/**
|
||||||
* A Type Specific Type Splititerator to reduce boxing/unboxing
|
* A Type Specific Type Splititerator to reduce boxing/unboxing
|
||||||
* @return type specific splititerator
|
* @return type specific splititerator
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
default SPLIT_ITERATOR KEY_GENERIC_TYPE spliterator() { return SPLIT_ITERATORS.createSplititerator(this, 0); }
|
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 java.util.SortedSet;
|
||||||
|
|
||||||
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
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.collections.SPLIT_ITERATOR;
|
||||||
|
#endif
|
||||||
#if TYPE_OBJECT
|
#if TYPE_OBJECT
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
#else
|
#else
|
||||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||||
#endif
|
#endif
|
||||||
|
#if SETS_FEATURE
|
||||||
import speiger.src.collections.PACKAGE.utils.SETS;
|
import speiger.src.collections.PACKAGE.utils.SETS;
|
||||||
|
#endif
|
||||||
|
#if SPLIT_ITERATOR_FEATURE
|
||||||
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Type Specific SortedSet implementation to reduce boxing/unboxing
|
* 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);
|
public BI_ITERATOR KEY_GENERIC_TYPE iterator(KEY_TYPE fromElement);
|
||||||
|
|
||||||
#if !TYPE_BOOLEAN
|
#if SETS_FEATURE
|
||||||
/**
|
/**
|
||||||
* Creates a Wrapped SortedSet that is Synchronized
|
* Creates a Wrapped SortedSet that is Synchronized
|
||||||
* @return a new 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); }
|
public default SORTED_SET KEY_GENERIC_TYPE unmodifiable() { return SETS.unmodifiable(this); }
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
#if SPLIT_ITERATOR_FEATURE
|
||||||
/**
|
/**
|
||||||
* A Type Specific Type Splititerator to reduce boxing/unboxing
|
* A Type Specific Type Splititerator to reduce boxing/unboxing
|
||||||
* @return type specific splititerator
|
* @return type specific splititerator
|
||||||
@@ -72,6 +79,7 @@ public interface SORTED_SET KEY_GENERIC_TYPE extends SET KEY_GENERIC_TYPE, Sorte
|
|||||||
@Override
|
@Override
|
||||||
default SPLIT_ITERATOR KEY_GENERIC_TYPE spliterator() { return SPLIT_ITERATORS.createSplititerator(this, 0); }
|
default SPLIT_ITERATOR KEY_GENERIC_TYPE spliterator() { return SPLIT_ITERATORS.createSplititerator(this, 0); }
|
||||||
|
|
||||||
|
#endif
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
/**
|
/**
|
||||||
* A Type Specific SubSet method to reduce boxing/unboxing
|
* A Type Specific SubSet method to reduce boxing/unboxing
|
||||||
|
|||||||
+2144
-1595
File diff suppressed because it is too large
Load Diff
+235
-43
@@ -7,39 +7,91 @@ import java.util.concurrent.TimeUnit;
|
|||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
import java.util.concurrent.locks.LockSupport;
|
import java.util.concurrent.locks.LockSupport;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
#if JDK_TYPE
|
||||||
|
import java.util.OPTIONAL;
|
||||||
|
#else
|
||||||
|
import speiger.src.collections.PACKAGE.functions.OPTIONAL;
|
||||||
|
#endif
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
|
|
||||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||||
|
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||||
#else
|
#else
|
||||||
|
import java.util.function.IntFunction;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
|
import java.util.Comparator;
|
||||||
|
|
||||||
|
#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
|
#endif
|
||||||
import speiger.src.collections.PACKAGE.collections.ITERABLE;
|
import speiger.src.collections.PACKAGE.collections.ITERABLE;
|
||||||
|
#if OBJECT_ASYNC_MODULE
|
||||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||||
|
#endif
|
||||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||||
import speiger.src.collections.PACKAGE.functions.TASK;
|
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.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
|
#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;
|
import speiger.src.collections.booleans.utils.BooleanAsyncBuilder;
|
||||||
|
#endif
|
||||||
import speiger.src.collections.booleans.utils.BooleanAsyncBuilder.BaseBooleanTask;
|
import speiger.src.collections.booleans.utils.BooleanAsyncBuilder.BaseBooleanTask;
|
||||||
#endif
|
#endif
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT && OBJECT_ASYNC_MODULE
|
||||||
import speiger.src.collections.objects.utils.ObjectAsyncBuilder;
|
import speiger.src.collections.objects.utils.ObjectAsyncBuilder;
|
||||||
import speiger.src.collections.objects.utils.ObjectAsyncBuilder.BaseObjectTask;
|
import speiger.src.collections.objects.utils.ObjectAsyncBuilder.BaseObjectTask;
|
||||||
#endif
|
#endif
|
||||||
#if !TYPE_INT
|
#if !TYPE_INT && INT_ASYNC_MODULE
|
||||||
|
#if !TYPE_OBJECT
|
||||||
import speiger.src.collections.ints.utils.IntAsyncBuilder;
|
import speiger.src.collections.ints.utils.IntAsyncBuilder;
|
||||||
|
#endif
|
||||||
import speiger.src.collections.ints.utils.IntAsyncBuilder.BaseIntTask;
|
import speiger.src.collections.ints.utils.IntAsyncBuilder.BaseIntTask;
|
||||||
#endif
|
#endif
|
||||||
|
import speiger.src.collections.utils.ISizeProvider;
|
||||||
import speiger.src.collections.utils.SanityChecks;
|
import speiger.src.collections.utils.SanityChecks;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -112,6 +164,19 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE
|
|||||||
return new ASYNC_BUILDERBRACES(ITERABLES.wrap(iterable));
|
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
|
||||||
|
* @Type(T)
|
||||||
|
* @return a AsyncBuilder with the values wrapped
|
||||||
|
*/
|
||||||
|
public static GENERIC_KEY_BRACES ASYNC_BUILDER KEY_GENERIC_TYPE of(KEY_TYPE...values) {
|
||||||
|
return new ASYNC_BUILDERBRACES(ARRAY_LIST.wrap(values));
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#if OBJECT_ASYNC_MODULE
|
||||||
/**
|
/**
|
||||||
* Maps the elements to something else
|
* Maps the elements to something else
|
||||||
* @param mapper the mapping function
|
* @param mapper the mapping function
|
||||||
@@ -143,6 +208,26 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE
|
|||||||
return new ObjectAsyncBuilder<>(ITERABLES.arrayFlatMap(iterable, mapper));
|
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
|
* Filters out the unwanted elements out of the Iterable
|
||||||
* @param filter the elements that should be kept
|
* @param filter the elements that should be kept
|
||||||
@@ -162,6 +247,16 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE
|
|||||||
return this;
|
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
|
* Limits how many elements are inside of the Iterable
|
||||||
* @param limit how many elements should max be iterated through
|
* @param limit how many elements should max be iterated through
|
||||||
@@ -172,6 +267,17 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sorts the elements inside of the Iterable.
|
||||||
|
* This operation is heavily hurting performance because it rebuilds the entire iterator and then sorts it, and this will affect the pausing feature.
|
||||||
|
* @param sorter that sorts the elements.
|
||||||
|
* @return self with a sorter applied
|
||||||
|
*/
|
||||||
|
public ASYNC_BUILDER KEY_GENERIC_TYPE sorted(COMPARATOR KEY_GENERIC_TYPE sorter) {
|
||||||
|
iterable = ITERABLES.sorted(iterable, sorter);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows to preview elements before they are processed
|
* Allows to preview elements before they are processed
|
||||||
* @param action the action that should be applied
|
* @param action the action that should be applied
|
||||||
@@ -182,6 +288,7 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if OBJECT_ASYNC_MODULE
|
||||||
/**
|
/**
|
||||||
* Iterates over the Iterable with a desired action
|
* Iterates over the Iterable with a desired action
|
||||||
* @param action that should be applied
|
* @param action that should be applied
|
||||||
@@ -191,14 +298,14 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE
|
|||||||
return new ObjectAsyncBuilder<>(new ForEachTask<>(iterable.iterator(), action));
|
return new ObjectAsyncBuilder<>(new ForEachTask<>(iterable.iterator(), action));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
/**
|
/**
|
||||||
* Reduces the elements inside of the Iterable down to one element
|
* Reduces the elements inside of the Iterable down to one element
|
||||||
* @param operator that reduces the elements.
|
* @param operator that reduces the elements.
|
||||||
* @return self with the reduce action applied
|
* @return self with the reduce action applied
|
||||||
*/
|
*/
|
||||||
public ASYNC_BUILDER KEY_GENERIC_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
public ObjectAsyncBuilder<OPTIONAL KEY_GENERIC_TYPE> reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
task = new SimpleReduceTaskBRACES(iterable.iterator(), operator);
|
return new ObjectAsyncBuilder<>(new SimpleReduceTaskBRACES(iterable.iterator(), operator));
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if TYPE_OBJECT
|
#if TYPE_OBJECT
|
||||||
@@ -225,23 +332,66 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#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
|
* Pours all elements into a List that can be later
|
||||||
* @return a new Builder with the pour function applied
|
* @return a new Builder with the pour function applied
|
||||||
*/
|
*/
|
||||||
public ObjectAsyncBuilder<LIST KEY_GENERIC_TYPE> pourAsList() {
|
public ObjectAsyncBuilder<LIST KEY_GENERIC_TYPE> pourAsList() {
|
||||||
|
#if ARRAY_LIST_FEATURE
|
||||||
return pour(new ARRAY_LISTBRACES());
|
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
|
* Pours all elements into a Set that can be later
|
||||||
* @return a new Builder with the pour function applied
|
* @return a new Builder with the pour function applied
|
||||||
*/
|
*/
|
||||||
public ObjectAsyncBuilder<SET KEY_GENERIC_TYPE> pourAsSet() {
|
public ObjectAsyncBuilder<SET KEY_GENERIC_TYPE> pourAsSet() {
|
||||||
|
#if LINKED_SET_FEATURE
|
||||||
return pour(new LINKED_HASH_SETBRACES());
|
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
|
#endif
|
||||||
/**
|
/**
|
||||||
* Pours all elements into a collection that can be later
|
* Pours all elements into a collection that can be later
|
||||||
@@ -253,6 +403,8 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE
|
|||||||
return new ObjectAsyncBuilder<>(new CollectTask<>(iterable.iterator(), collection));
|
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.
|
* Searches through the elements of the Iterable to find if the desired element is present.
|
||||||
* @param filter that decides the desired elements
|
* @param filter that decides the desired elements
|
||||||
@@ -280,17 +432,18 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE
|
|||||||
return new BooleanAsyncBuilder(new MatchTaskBRACES(iterable.iterator(), filter, 2));
|
return new BooleanAsyncBuilder(new MatchTaskBRACES(iterable.iterator(), filter, 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
/**
|
/**
|
||||||
* Searches through the elements of the Iterable to find if the desired element.
|
* 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
|
* If not present it will return the default value of the type
|
||||||
* @param filter that decides the desired elements
|
* @param filter that decides the desired elements
|
||||||
* @return self with the findFirst function applied
|
* @return self with the findFirst function applied
|
||||||
*/
|
*/
|
||||||
public ASYNC_BUILDER KEY_GENERIC_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
public ObjectAsyncBuilder<OPTIONAL KEY_GENERIC_TYPE> findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
task = new FindFirstTaskBRACES(iterable.iterator(), filter);
|
return new ObjectAsyncBuilder<>(new FindFirstTaskBRACES(iterable.iterator(), filter));
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if INT_ASYNC_MODULE
|
||||||
/**
|
/**
|
||||||
* Counts all desired elements inside the Iterable
|
* Counts all desired elements inside the Iterable
|
||||||
* @param filter that decides the desired elements
|
* @param filter that decides the desired elements
|
||||||
@@ -300,6 +453,7 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE
|
|||||||
return new IntAsyncBuilder(new CountTaskBRACES(iterable.iterator(), filter));
|
return new IntAsyncBuilder(new CountTaskBRACES(iterable.iterator(), filter));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
/**
|
/**
|
||||||
* Optional way to add a custom executor that runs this offthread task.
|
* Optional way to add a custom executor that runs this offthread task.
|
||||||
* Can only be set after the action was decided on.
|
* Can only be set after the action was decided on.
|
||||||
@@ -439,7 +593,7 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#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;
|
ITERATOR KEY_GENERIC_TYPE iter;
|
||||||
UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator;
|
UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator;
|
||||||
@@ -449,6 +603,7 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE
|
|||||||
public SimpleReduceTask(ITERATOR KEY_GENERIC_TYPE iter, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
public SimpleReduceTask(ITERATOR KEY_GENERIC_TYPE iter, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
this.iter = iter;
|
this.iter = iter;
|
||||||
this.operator = operator;
|
this.operator = operator;
|
||||||
|
this.setResult(OPTIONAL.empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -463,7 +618,7 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!iter.hasNext()) {
|
if(!iter.hasNext()) {
|
||||||
setResult(value);
|
setResult(OPTIONAL.GET_OPTIONAL(value));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -480,6 +635,7 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if BOOLEAN_ASYNC_MODULE
|
||||||
private static class MatchTask KEY_GENERIC_TYPE extends BaseBooleanTask
|
private static class MatchTask KEY_GENERIC_TYPE extends BaseBooleanTask
|
||||||
{
|
{
|
||||||
ITERATOR KEY_GENERIC_TYPE iter;
|
ITERATOR KEY_GENERIC_TYPE iter;
|
||||||
@@ -498,11 +654,7 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE
|
|||||||
switch(type) {
|
switch(type) {
|
||||||
case 0:
|
case 0:
|
||||||
while(shouldRun() && iter.hasNext()) {
|
while(shouldRun() && iter.hasNext()) {
|
||||||
#if TYPE_OBJECT
|
if(filter.test(iter.NEXT())) {
|
||||||
if(filter.getBoolean(iter.NEXT())) {
|
|
||||||
#else
|
|
||||||
if(filter.GET_VALUE(iter.NEXT())) {
|
|
||||||
#endif
|
|
||||||
setResult(true);
|
setResult(true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -510,11 +662,7 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE
|
|||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
while(shouldRun() && iter.hasNext()) {
|
while(shouldRun() && iter.hasNext()) {
|
||||||
#if TYPE_OBJECT
|
if(filter.test(iter.NEXT())) {
|
||||||
if(filter.getBoolean(iter.NEXT())) {
|
|
||||||
#else
|
|
||||||
if(filter.GET_VALUE(iter.NEXT())) {
|
|
||||||
#endif
|
|
||||||
setResult(false);
|
setResult(false);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -522,11 +670,7 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE
|
|||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
while(shouldRun() && iter.hasNext()) {
|
while(shouldRun() && iter.hasNext()) {
|
||||||
#if TYPE_OBJECT
|
if(!filter.test(iter.NEXT())) {
|
||||||
if(!filter.getBoolean(iter.NEXT())) {
|
|
||||||
#else
|
|
||||||
if(!filter.GET_VALUE(iter.NEXT())) {
|
|
||||||
#endif
|
|
||||||
setResult(false);
|
setResult(false);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -548,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;
|
ITERATOR KEY_GENERIC_TYPE iter;
|
||||||
PREDICATE KEY_GENERIC_TYPE filter;
|
PREDICATE KEY_GENERIC_TYPE filter;
|
||||||
@@ -556,18 +701,15 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE
|
|||||||
public FindFirstTask(ITERATOR KEY_GENERIC_TYPE iter, PREDICATE KEY_GENERIC_TYPE filter) {
|
public FindFirstTask(ITERATOR KEY_GENERIC_TYPE iter, PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
this.iter = iter;
|
this.iter = iter;
|
||||||
this.filter = filter;
|
this.filter = filter;
|
||||||
|
this.setResult(OPTIONAL.empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean execute() throws Exception {
|
protected boolean execute() throws Exception {
|
||||||
while(shouldRun() && iter.hasNext()) {
|
while(shouldRun() && iter.hasNext()) {
|
||||||
KEY_TYPE entry = iter.NEXT();
|
KEY_TYPE entry = iter.NEXT();
|
||||||
#if TYPE_OBJECT
|
if(filter.test(iter.NEXT())) {
|
||||||
if(filter.getBoolean(iter.NEXT())) {
|
setResult(OPTIONAL.GET_OPTIONAL(entry));
|
||||||
#else
|
|
||||||
if(filter.GET_VALUE(iter.NEXT())) {
|
|
||||||
#endif
|
|
||||||
setResult(entry);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -582,6 +724,7 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if INT_ASYNC_MODULE
|
||||||
private static class CountTask KEY_GENERIC_TYPE extends BaseIntTask
|
private static class CountTask KEY_GENERIC_TYPE extends BaseIntTask
|
||||||
{
|
{
|
||||||
ITERATOR KEY_GENERIC_TYPE iter;
|
ITERATOR KEY_GENERIC_TYPE iter;
|
||||||
@@ -596,7 +739,7 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE
|
|||||||
@Override
|
@Override
|
||||||
protected boolean execute() throws Exception {
|
protected boolean execute() throws Exception {
|
||||||
while(shouldRun() && iter.hasNext()) {
|
while(shouldRun() && iter.hasNext()) {
|
||||||
if(filter.TEST_VALUE(iter.NEXT())) {
|
if(filter.test(iter.NEXT())) {
|
||||||
counted++;
|
counted++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -616,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>
|
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;
|
ITERATOR KEY_SPECIAL_GENERIC_TYPE<V> iter;
|
||||||
@@ -646,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>
|
private static class ForEachTask<T> extends BaseObjectTask<Void>
|
||||||
{
|
{
|
||||||
ITERATOR KEY_GENERIC_TYPE iter;
|
ITERATOR KEY_GENERIC_TYPE iter;
|
||||||
@@ -672,6 +863,7 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
/**
|
/**
|
||||||
* Base Task of the Actions that can be performed.
|
* Base Task of the Actions that can be performed.
|
||||||
* Allows to simplify the actions that get executed.
|
* Allows to simplify the actions that get executed.
|
||||||
|
|||||||
+1139
-421
File diff suppressed because it is too large
Load Diff
@@ -7,7 +7,9 @@ import speiger.src.collections.utils.IArray;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Type-Specific Helper class to get the underlying array of array implementations.
|
* Type-Specific Helper class to get the underlying array of array implementations.
|
||||||
|
#if ARRAY_LIST_FEATURE
|
||||||
* @see speiger.src.collections.PACKAGE.lists.ARRAY_LIST
|
* @see speiger.src.collections.PACKAGE.lists.ARRAY_LIST
|
||||||
|
#endif
|
||||||
* @Type(T)
|
* @Type(T)
|
||||||
*/
|
*/
|
||||||
public interface IARRAY KEY_GENERIC_TYPE extends IArray
|
public interface IARRAY KEY_GENERIC_TYPE extends IArray
|
||||||
|
|||||||
+681
-427
File diff suppressed because it is too large
Load Diff
+1265
-1007
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user